C Board  

Go Back   C Board > General Programming Boards > C++ Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 06-23-2008, 05:57 AM   #1
Registered User
 
Join Date: Jun 2008
Posts: 1
threads and gui - how to?

hi,
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;
                }



        }
}
this part is called by a thread when a button is clicked and runs
until exitevent is set
;

Code:
void TForm1::write(AnsiString inp)
{
      Edit1->Text += inp+"\n";
}
and code to modify gui
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   Reply With Quote
Old 06-24-2008, 02:45 PM   #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   Reply With Quote
Old 06-24-2008, 03:00 PM   #3
Mysterious C++ User
 
Elysia's Avatar
 
Join Date: Oct 2007
Posts: 14,785
Quote:
Originally Posted by Percey View Post
...but I know in visual basic there's a property called CheckForIllegalCrossThreadCalls (there's a mouthful), that you can set to true/false...
No such thing in C++.

Quote:
You could try that if you are using MVC++...
Problem is that the OP is using Borland stuff, which is Borland only and will not work with other compilers.
(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:
Originally Posted by cpjust
If C++ is 2 steps forward from C, then I'd say Java is 1 step forward and 2 steps back.
Elysia is offline   Reply With Quote
Old 06-24-2008, 03:03 PM   #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   Reply With Quote
Old 06-24-2008, 04:53 PM   #5
Super Moderator
 
Bubba's Avatar
 
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   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

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


All times are GMT -6. The time now is 11:58 PM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22