I’m trying to hook into the OnSysCommand function but I’m getting a confusing error.
In the header, I am declaring the function like:
afx_msg void OnSysCommand(UINT nID, LPARAM lParam );
And in the cpp the code is:
BEGIN_MESSAGE_MAP(CMFCTest1App, CWinAppEx)
ON_COMMAND(ID_APP_ABOUT, &CMFCTest1App::OnAppAbout)
// Standard file based document commands
ON_COMMAND(ID_FILE_NEW, &CWinAppEx::OnFileNew)
ON_COMMAND(ID_FILE_OPEN, &CWinAppEx::OnFileOpen)
ON_WM_SYSCOMMAND()
END_MESSAGE_MAP()
void CMFCTest1App::OnSysCommand(UINT nID, LPARAM lParam )
{
AfxMessageBox(L"System command recieved");
}
When compiling I get the following error message:
1> MFCTest1.cpp
1>c:\users\dell3\documents\visual studio 2010\projects\mfctest1\mfctest1\mfctest1.cpp(43): error C2440: 'static_cast' : cannot convert from 'void (__thiscall CMFCTest1App::* )(UINT,LPARAM)' to 'void (__thiscall CWnd::* )(UINT,LPARAM)'
1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
1>
1>Build FAILED.
The same thing happens when I try to hook into the OnClose function. Any suggestions would be much appreciated. Thanks.
Move the handlers out of your app class and into your window or frame class.
These messages are meant to be handled in a window class (derived from
CWnd) and not in your app class (derived fromCWinApp).