howto Post Message
-
okay working with a dialog app. I have a little worker thread doing stuff and then I want to update the dialog. So here is what I am doing... #define UWM_UPDATEGRAPH (WM_APP + 1) //{{AFX_MSG_MAP(CVC_ExampleDlg) ... ON_MESSAGE(UWM_UPDATEGRAPH, OnUpdateGraph) ... //}}AFX_MSG_MAP // I ignore both params LRESULT CVC_ExampleDlg::OnUpdateGraph(WPARAM, LPARAM) {...} now to post this message I thought I wanted to write PostMessage(UWM_UPDATEGRAPH, 0, 0); however it is asking for an additional parameter of the HWND. So here is my question, did I define my message wrong or do how is the best way to get the HWND
-
okay working with a dialog app. I have a little worker thread doing stuff and then I want to update the dialog. So here is what I am doing... #define UWM_UPDATEGRAPH (WM_APP + 1) //{{AFX_MSG_MAP(CVC_ExampleDlg) ... ON_MESSAGE(UWM_UPDATEGRAPH, OnUpdateGraph) ... //}}AFX_MSG_MAP // I ignore both params LRESULT CVC_ExampleDlg::OnUpdateGraph(WPARAM, LPARAM) {...} now to post this message I thought I wanted to write PostMessage(UWM_UPDATEGRAPH, 0, 0); however it is asking for an additional parameter of the HWND. So here is my question, did I define my message wrong or do how is the best way to get the HWND
The first argument to PostMessage should be the handle of the window to which you want to post the message. You can retrieve it from the CDialog by calling GetSafeHwnd() on it.
Cédric Moonen Software developer
Charting control [v1.4] OpenGL game tutorial in C++ -
okay working with a dialog app. I have a little worker thread doing stuff and then I want to update the dialog. So here is what I am doing... #define UWM_UPDATEGRAPH (WM_APP + 1) //{{AFX_MSG_MAP(CVC_ExampleDlg) ... ON_MESSAGE(UWM_UPDATEGRAPH, OnUpdateGraph) ... //}}AFX_MSG_MAP // I ignore both params LRESULT CVC_ExampleDlg::OnUpdateGraph(WPARAM, LPARAM) {...} now to post this message I thought I wanted to write PostMessage(UWM_UPDATEGRAPH, 0, 0); however it is asking for an additional parameter of the HWND. So here is my question, did I define my message wrong or do how is the best way to get the HWND
PostMessage
function [^] takes four parameters, indeed. I.e. did you realize the thread procedure is NOT a method (a instance one) of your dialog class? :)If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles] -
okay working with a dialog app. I have a little worker thread doing stuff and then I want to update the dialog. So here is what I am doing... #define UWM_UPDATEGRAPH (WM_APP + 1) //{{AFX_MSG_MAP(CVC_ExampleDlg) ... ON_MESSAGE(UWM_UPDATEGRAPH, OnUpdateGraph) ... //}}AFX_MSG_MAP // I ignore both params LRESULT CVC_ExampleDlg::OnUpdateGraph(WPARAM, LPARAM) {...} now to post this message I thought I wanted to write PostMessage(UWM_UPDATEGRAPH, 0, 0); however it is asking for an additional parameter of the HWND. So here is my question, did I define my message wrong or do how is the best way to get the HWND
If you're starting your thread from within the dialog you want to update, pass the hwnd of the dialog as the LPARAM if you use MFC (AfxBeginThread) - then you can use that in your PostMessage. If you don't use MFC, you can pass it as arglist or lpParmeter depending on how you start your thread. You can use GetSafeHwnd() in your dialog to get the hWnd to pass. Inside the thread, cast that parameter to an hWnd and you've got it. Hope that helps.
Karl - WK5M PP-ASEL-IA (N43CS) PGP Key: 0xDB02E193 PGP Key Fingerprint: 8F06 5A2E 2735 892B 821C 871A 0411 94EA DB02 E193
-
The first argument to PostMessage should be the handle of the window to which you want to post the message. You can retrieve it from the CDialog by calling GetSafeHwnd() on it.
Cédric Moonen Software developer
Charting control [v1.4] OpenGL game tutorial in C++Cedric Moonen wrote:
The first argument to PostMessage should be the handle of the window to which you want to post the message. You can retrieve it from the CDialog by calling GetSafeHwnd() on it.
CDialog
is derived fromCWnd
which has aPostMessage
method with the following signature:BOOL CWnd::PostMessage(UINT message, WPARAM wParam, LPARAM lParam)
Depending on the specifics calling Win32's
::PostMessage
function may not be the best way to go about things.Steve
-
Cedric Moonen wrote:
The first argument to PostMessage should be the handle of the window to which you want to post the message. You can retrieve it from the CDialog by calling GetSafeHwnd() on it.
CDialog
is derived fromCWnd
which has aPostMessage
method with the following signature:BOOL CWnd::PostMessage(UINT message, WPARAM wParam, LPARAM lParam)
Depending on the specifics calling Win32's
::PostMessage
function may not be the best way to go about things.Steve
Stephen Hewitt wrote:
Depending on the specifics calling Win32's ::PostMessage function may not be the best way to go about things.
What do you mean ? If the thread runs outside the dialog class, you have to use ::PostMessage to deliver the message to the correct window. I don't see what you mean in fact, could you elaborate ?
Cédric Moonen Software developer
Charting control [v1.4] OpenGL game tutorial in C++ -
Stephen Hewitt wrote:
Depending on the specifics calling Win32's ::PostMessage function may not be the best way to go about things.
What do you mean ? If the thread runs outside the dialog class, you have to use ::PostMessage to deliver the message to the correct window. I don't see what you mean in fact, could you elaborate ?
Cédric Moonen Software developer
Charting control [v1.4] OpenGL game tutorial in C++He’s using MFC and wants to post a message to a CDialog derived class. If the worker thread has access to this class then he can use CDialog::PostMessage. An example:
CDialog theDialog;
void CalledFromOtherThread()
{
theDialog.PostMessage(WM_APP, 0, 0);
}Steve
-
okay working with a dialog app. I have a little worker thread doing stuff and then I want to update the dialog. So here is what I am doing... #define UWM_UPDATEGRAPH (WM_APP + 1) //{{AFX_MSG_MAP(CVC_ExampleDlg) ... ON_MESSAGE(UWM_UPDATEGRAPH, OnUpdateGraph) ... //}}AFX_MSG_MAP // I ignore both params LRESULT CVC_ExampleDlg::OnUpdateGraph(WPARAM, LPARAM) {...} now to post this message I thought I wanted to write PostMessage(UWM_UPDATEGRAPH, 0, 0); however it is asking for an additional parameter of the HWND. So here is my question, did I define my message wrong or do how is the best way to get the HWND
you can also you the application object memeber variable m_hWnd!
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
Never mind - my own stupidity is the source of every "problem" - Mixturecheers, Alok Gupta VC Forum Q&A :- I/IV Support CRY- Child Relief and You/xml>