CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Aug 2015
    Posts
    6

    Question 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

  2. #2
    Join Date
    Apr 2000
    Location
    Belgium (Europe)
    Posts
    4,626

    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
  •  





Click Here to Expand Forum to Full Width

Featured