Is it bad form to cast this way?
in WndProc of child:
Code:
case WM_SHOWWINDOW:
if (hwnd == childHandle)
{
SendMessage(GetParent(hwnd), WM_APP, (WPARAM)hwnd, lParam);
}
in WndProc of Parent:
Code:
case WM_APP:
if ((HWND)wParam == childHandle)
{
MessageBoxA(0, "Message sent from Child 1", "Parent's WndProc", 0);
}
I'm sending a custom message from the wndproc of child window class in another source file to it's parent. Multiple children of different types will be sending this message to the parent.
Is it bad form or dangerous to cast the hwnd to type wparam, send the message, and then cast wparam to type hwnd to compare the re-casted wparam to a specific window handle?
Do I risk data loss between the types? Should I use lparam instead? Is there a safer approach?
Thanks guys! Post number 2 :P
-Kev
Re: Is it bad form to cast this way?
as long as the type you cast to as an intermediary has enough bits... casting from X to Y and back is safe.
WPARAM and HWND are both 32bit (or 64bit on Win64) so that conversion is safe.