Hello all,
The very short MFC dialog-based app I'm testing is shown below - I'm having issues with the message map of my user-defined message.
Code:
#define IDM_MYMESSAGE (WM_USER + 1)
#include <afxwin.h>
#include "resource.h"
class CMainDialog : public CDialog {
public:
//Constructor
CMainDialog(int nIDDialog) : CDialog(nIDDialog) {}
//Declare handler for user-defined message
afx_msg LRESULT OnMyMessage(LPARAM lParam = 0, WPARAM wParam = 0);
DECLARE_MESSAGE_MAP()
};
class CTestApp : public CWinApp {
public:
//Override base class initialization
virtual BOOL InitInstance();
};
//Map the user-defined message to its handler
BEGIN_MESSAGE_MAP(CMainDialog,CDialog)
ON_MESSAGE(IDM_MYMESSAGE,OnMyMessage)
END_MESSAGE_MAP()
//Define a simple user-defined message handler
LRESULT CMainDialog::OnMyMessage(LPARAM lParam, WPARAM wParam) {
MessageBox("My message!");
return 0;
}
//Initialize the app
BOOL CTestApp::InitInstance() {
//Create dialog from template, use as main window
CMainDialog dialog(IDD_DIALOG1);
m_pMainWnd = &dialog;
//Show the dialog and wait for return
UINT_PTR result = dialog.DoModal();
return FALSE;
}
//Create application instance
CTestApp theApp;
And I get the following error:
Code:
error C2440: 'static_cast' : cannot convert from 'LRESULT (__thiscall CMainDialog::* )(LPARAM,WPARAM)' to 'LRESULT (__thiscall CWnd::* )(WPARAM,LPARAM)'
None of the functions with this name in scope match the target type
I also tried using "&CMainDialog::OnMyMessage" in the message map, but that didn't work, either. I'm fairly new to MFC, and I'm not quite sure what the error message is actually saying. It looks like it wants an object derived from CWnd and I'm guessing since my CMainDialog is derived from CDialog and not directly from CWnd, that maybe that has something to do with it?
In straight Win32 since a BOOL CALLBACK is used instead of LRESULT CALLBACK for dialogs, I also thought that may be part of the issue? But I couldn't find any documentation indicating that to be the case for MFC...
I hope this is just one of those obvious things that I'm looking too hard at. Any help is appreciated.
Edit: I also tried getting rid of the default values in the OnMyMessage() function, but still no change.