CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Jun 2008
    Posts
    13

    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
    Join Date
    Nov 2003
    Location
    Belgium
    Posts
    8,150

    Re: threads and gui - how to?

    I don't know much about borland C++, but you should probably not be calling methods directly on your GUI objects. Try to use PostMessage or Sendmessage to send messages to your GUI.
    Marc Gregoire - NuonSoft (http://www.nuonsoft.com)
    My Blog
    Wallpaper Cycler 3.5.0.97

    Author of Professional C++, 4th Edition by Wiley/Wrox (includes C++17 features)
    ISBN: 978-1-119-42130-6
    [ http://www.facebook.com/professionalcpp ]

  3. #3
    Join Date
    Jun 2008
    Posts
    13

    Re: threads and gui - how to?

    Edit1->Text EQUALS NOT PLUS EQUALS
    that was all about
    Edit1->Text = mssage;
    and it was okay
    and thanks for reply Marc G

  4. #4
    Join Date
    Nov 2003
    Location
    Belgium
    Posts
    8,150

    Re: threads and gui - how to?

    Yes, but still, you will have to make sure that the borland form objects are thread safe before you start calling methods on it.
    Marc Gregoire - NuonSoft (http://www.nuonsoft.com)
    My Blog
    Wallpaper Cycler 3.5.0.97

    Author of Professional C++, 4th Edition by Wiley/Wrox (includes C++17 features)
    ISBN: 978-1-119-42130-6
    [ http://www.facebook.com/professionalcpp ]

  5. #5
    Join Date
    Jun 2008
    Posts
    13

    Re: threads and gui - how to?

    you are right,
    as i said i am new to borland,
    i didn't have a problem so far,
    hope, it is thread safe as u said,
    i ll search for it..

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured