-
August 13th, 2015, 04:23 PM
#1
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
-
August 14th, 2015, 07:05 AM
#2
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.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|