In my c++ code, I define a message to inform other class to do some action. The code is like below:
In mainFrm.h:
...
afx_msg LRESULT OnHandleDialog(WPARAM wParam, LPARAM lParam);
...
In mainFrm.cpp
LRESULT CMainFrame::OnHandleDialog(WPARAM wParam, LPARAM lParam)
{
switch (wParam)
{
case Define::myCondition:
{
myFunction->doSomethingHere(static_cast<bool>(lParam)); //there is warning C4800: 'LPARAM' : forcing value to bool 'true' or 'false' (performance warning)
return 0;
}
}
return 0;
}
BEGIN_MESSAGE_MAP(CMainFrame, CMDIFrameWnd)
...
ON_MESSAGE(WM_DEFINED_DIALOG, OnHandleDialog) //My Message Mapping here
....
END_MESSAGE_MAP()
In another file, MyCode.h
void sendDefinedMsg(DWORD_PTR wParam, DWORD_PTR data = 0)
{
pNotifyWnd->PostMessage(WM_DEFINED_DIALOG, wParam, data);
}
In another file, Mycode.cpp
sendDefinedMsg( myCondition, false);
....
sendDefinedMsg( myCondition, true);
....
So, you can see in the above code, I want to get the message parameter here:
myFunction->doSomethingHere(static_cast<bool>(lParam));
The issue is: whatever I cast the LPARAM lParam
to, using static_cast<bool>
or reinterpret_cast<bool>
, or (bool)
. All of them give me a warning:
warning C4800: 'LPARAM' : forcing value to bool 'true' or 'false' (performance warning)
So my question is: How should I cast lParam
to my original passed parameter true
/false
?