threads and gui - how to?

This is a discussion on threads and gui - how to? within the C++ Programming forums, part of the General Programming Boards category; hi, i am new to c++ (used to program in java and c#) for several days i have been trying ...

  1. #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

  2. #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++...

  3. #3
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Posts
    22,918
    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++.

    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.)
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  4. #4
    3735928559
    Join Date
    Mar 2008
    Location
    RTP
    Posts
    839
    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 04:05 PM.

  5. #5
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,598
    Regardless of compiler a simple windows kernel synchronization object will work.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Communicating with threads
    By cloudy in forum Windows Programming
    Replies: 5
    Last Post: 12-26-2007, 10:57 AM
  2. using several wget-s in separate threads
    By _izua_ in forum C++ Programming
    Replies: 5
    Last Post: 10-18-2007, 04:14 PM
  3. Basic GUI and odd thread error
    By woofer in forum C++ Programming
    Replies: 8
    Last Post: 09-21-2006, 10:26 AM
  4. Console App w/ Threads and Events?
    By sean in forum C# Programming
    Replies: 1
    Last Post: 07-02-2004, 01:16 AM
  5. Gui?
    By Waldo2k2 in forum A Brief History of Cprogramming.com
    Replies: 2
    Last Post: 07-30-2002, 06:32 AM

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