![]() |
| | #1 |
| Registered User Join Date: Jun 2008
Posts: 1
| threads and gui - how to? i am new to c++ (used to program in java and c#) for several days i have been trying to change gui from a thread, i searched all the internet but couldnt find anything related, i am using Borland c++ builder 6, here is my code hope you ll find a solution Code: DWORD WINAPI TForm1::m_check(LPVOID param)
{
DWORD status;
HANDLE m_con[2];
m_con[0] = report;
m_con[1] = hExitEvent;
while(true)
{
status = WaitForMultipleObjects(2,m_con,FALSE,INFINITE);
Sleep(10); //do not use processor 100%
switch(status)
{
case WAIT_OBJECT_0:
Form1->write(message);
break;
case WAIT_OBJECT_0 +1:
return NULL;//exit
case WAIT_FAILED:
Form1->write("wait failed");
break;
default:
Form1->write("fail");
break;
}
}
}
until exitevent is set ; Code: void TForm1::write(AnsiString inp)
{
Edit1->Text += inp+"\n";
}
this all code doesnt gives an error but it doesnt changes anything on gui when i put a break point on Edit->Text as i see text is changed but it doesnt appears at gui |
| phenixa is offline | |
| | #2 |
| Registered User Join Date: Jun 2008
Posts: 4
| I'm a pretty bad C++ programmer (where pretty = horribly) but I know in visual basic there's a property called CheckForIllegalCrossThreadCalls (there's a mouthful), that you can set to true/false, I'm pretty sure the code would be frowned upon, but I have used it before. You could try that if you are using MVC++... |
| Percey is offline | |
| | #3 | |||
| Mysterious C++ User Join Date: Oct 2007
Posts: 14,785
| Quote:
Quote:
(And I assume the poor amount of replies is also related to the fact that the OP uses Borland.)
__________________ Using: Microsoft Windows™ 7 Professional (x64), Microsoft Visual Studio™ 2008 Team System I dedicated my life to helping others. This is only a small sample of what they said: "Thanks Elysia. You're a programming master! How the hell do you know every thing?" Quoted... at least once. Quote:
| |||
| Elysia is offline | |
| | #4 |
| 3735928559 Join Date: Mar 2008
Posts: 693
| try: Code: void TForm1::setText(AnsiString inp)
{
TForm1::editText = inp;
}
void TForm1::write()
{
Edit1->Text = editText;
}
Code: DWORD WINAPI TForm1::m_check(LPVOID param)
{
DWORD status;
HANDLE m_con[2];
m_con[0] = report;
m_con[1] = hExitEvent;
while(true)
{
status = WaitForMultipleObjects(2,m_con,FALSE,INFINITE);
Sleep(10); //do not use processor 100%
switch(status)
{
case WAIT_OBJECT_0:
Form1->setText(message);
Synchronize(Form1->write);
break;
case WAIT_OBJECT_0 +1:
return NULL;//exit
case WAIT_FAILED:
Form1->setText("wait failed");
Synchronize(Form1->write);
break;
default:
Form1->setText("fail");
Synchronize(Form1->write);
break;
}
}
}
Last edited by m37h0d; 06-24-2008 at 03:05 PM. |
| m37h0d is offline | |
| | #5 |
| Super Moderator Join Date: Aug 2001
Posts: 7,819
| Regardless of compiler a simple windows kernel synchronization object will work.
__________________ If you aim at everything you will hit something but you won't know what it is. |
| Bubba is offline | |
![]() |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Communicating with threads | cloudy | Windows Programming | 5 | 12-26-2007 10:57 AM |
| using several wget-s in separate threads | _izua_ | C++ Programming | 5 | 10-18-2007 03:14 PM |
| Basic GUI and odd thread error | woofer | C++ Programming | 8 | 09-21-2006 09:26 AM |
| Console App w/ Threads and Events? | sean | C# Programming | 1 | 07-02-2004 12:16 AM |
| Gui? | Waldo2k2 | A Brief History of Cprogramming.com | 2 | 07-30-2002 05:32 AM |