MFC: Problem using CWnd::SendMessage
-
Hello all, I'm presently learning how to use my own message handlers in my MFC application. I read this article: Windows Message Handling - Part 2 here: http://www.codeproject.com/dialog/messagehandling2.asp. I have a problem with one line of code; when I need to get the CWnd* to send the message. In my case, I want to send the message to my main view based on CFormView when I'm in another dialog or class. Here's how I was trying to do it: pMyMainView = CWnd::FindWindow(_T("CMyMainView"),NULL); pMyMainView->SendMessage(WM_MYMESSAGE,0,0); But FindWindow don't find my CMyMainView, so I can't send the message. I tried "this->SendMessage(WM_MYMESSAGE,0,0);" in my CMyMainView.cpp to verify my message handler and it's working. It must be so simple! But I started coding in C++ and MFC only 1 month ago. :-) Thanks, Dave
-
Hello all, I'm presently learning how to use my own message handlers in my MFC application. I read this article: Windows Message Handling - Part 2 here: http://www.codeproject.com/dialog/messagehandling2.asp. I have a problem with one line of code; when I need to get the CWnd* to send the message. In my case, I want to send the message to my main view based on CFormView when I'm in another dialog or class. Here's how I was trying to do it: pMyMainView = CWnd::FindWindow(_T("CMyMainView"),NULL); pMyMainView->SendMessage(WM_MYMESSAGE,0,0); But FindWindow don't find my CMyMainView, so I can't send the message. I tried "this->SendMessage(WM_MYMESSAGE,0,0);" in my CMyMainView.cpp to verify my message handler and it's working. It must be so simple! But I started coding in C++ and MFC only 1 month ago. :-) Thanks, Dave
I'm not sure what you mean by "my main view". To get the application's main window, use
AfxGetMainWnd()
. To get the dialog's parent window, useGetParent()
. Hope this helps. /ravi My new year's resolution: 2048 x 1536 Home | Articles | Freeware | Music ravib@ravib.com -
I'm not sure what you mean by "my main view". To get the application's main window, use
AfxGetMainWnd()
. To get the dialog's parent window, useGetParent()
. Hope this helps. /ravi My new year's resolution: 2048 x 1536 Home | Articles | Freeware | Music ravib@ravib.com