Re: MFC and User Defined objects
I would add a member CWnd *p_UIWnd; to the object and assign it to a UI
window when the object is created. Then you could do something like:
p_UIWnd->PostMessage() when you want to update the window. You will have to
create your own message based off of WM_APP to do this and put in a handler.
in .h file:
LRESULT OnServerStateChange(WPARAM wParam, LPARAM lParam);
#define WM_UPDATE_SERVER_STATE (WM_APP + 1)
in .cpp file message handler section:
ON_MESSAGE(WM_UPDATE_SERVER_STATE, OnServerStateChange)
LRESULT CMainFrame::OnServerStateChange(WPARAM wParam, LPARAM lParam)
{
// Do something with information
return 0L;
}
From thread code:
p_UIWnd->PostMessage(WM_UPDATE_SERVER_STATE,0,0L);
HTH,
Tom
"one-trick-pony" <worldofpain.aamir@gmail.com> wrote in message
news:1173808536.856153.253810@q40g2000cwq.googlegroups.com...
Greetings,
I am trying to PostMessage from a user defined generic class/object in
MFC Dialog based application to Dialog/main window. I don't know how
to do that. I am utilizing worker threads. A thread instantiates an
object(from user defined generic class) and utilizes newly created
object. What user defined object code does is actually launch a
process, for sake for argument lets say, Windows Notepad.exe using
CreateProcess. As long as that process is running, I want to
PostMessage that updates a progress bar on Main GUI dialog. I can do
it if I embed the code right into my application by writing the code
directly into it or declare, define and use member function of Dialog/
main program itself. But I want to learn new material by incorporting
a user defined class and then interacting with main application code.
To recap:
MFC Dialog based Main application exectues-> It launches a thread. ->
Thread uses user defined generic class to instantiate a new object. -
New Object should run and should PostMessage to Main window to
update progress bar.
Again, I don't know how to do this. How to tell newly created object
from user defined class, which is running within a Worker Thread, to
successfully post message to main GUI? I know that Worker threads are
not allowed to interact with GUI objects.
Any good software engineering solution will be greatly appreciated. I
thank you.