Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Beginner
14 Views

Sending messages to the main window from a subroutine

I am writing a windows application where the main window has an edit box as a child control. This edit box has the handle hMsg. In response to a user clicking on a menu item, the MainWndProc function calls a subroutine. This subroutine performs a number of tasks, each requiring significant cpu time (on the order of 30 seconds). I want the subroutine to write text into the edit box of the main window, stating which task it is currently working on so that the user can follow the progress in real time.

In my first attempt to accomplish this, I passed the subroutine the handle hMsg to the edit box. In the subroutine, before starting a task, I set a character variable msg to the desired message and then call SetWindowText(hMsg, msg). Apparently, this only puts the requested change to the edit box into the message queue; the new text is not displayed until after the subroutine terminates a few minutes after it is called. Thus, the user cannot follow the real-time progress of the subroutine. Is there a way to have the edit box in the main window updated by the subroutine as the subroutine performs each of its several tasks?

Thanks,

Steve J

0 Kudos
1 Reply
Highlighted
New Contributor III
14 Views

You should start your subroutine in separate thread. Then will be main thread of your application able to response to messages.

At the end of execution of your subroutine you send message to your application that it's work is finished.

0 Kudos