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

    [RESOLVED] WM_CREATE and HWND issue

    Code:
    case WM_CREATE:
    		if (hwnd == childwindowHandle)
    		{
    			
    			x = TRUE;
    			
    		}
    x is never set to true.

    This is a child window. This case is in the message switch for the child window's message procedure. There are multiple children of the same class. The child windows are created drawn and functional. This logic exactly works in other cases such as WM_PAINT and WM_LBUTTONDOWN and other logic making referencing the parameter hwnd also has no problems.

    Why for WM_CREATE, when in the documentation it states that WM_CREATE is called after window creation but before window visibility, does hwnd not evaluate to the handle of the created window?




    Thank you guys, First post ^_^
    -Kev

    PS. I don't have permission to create tags on this forum but there's no WM_CREATE tab!

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: WM_CREATE and HWND issue

    Quote Originally Posted by int Kev View Post
    Code:
    case WM_CREATE:
    		if (hwnd == childwindowHandle)
    		{
    			x = TRUE;
    		}
    x is never set to true.
    Did you check whether this code is executed?
    Victor Nijegorodov

  3. #3
    Join Date
    Aug 2015
    Posts
    6

    Re: WM_CREATE and HWND issue

    Quote Originally Posted by VictorN View Post
    Did you check whether this code is executed?
    This was me checking! Thank you for replying victor, but I'm not sure what you mean. How else can I check for code execution? Should a WM_CREATE msg not be sent to my window procedure upon window creation? And should, too, the code within it's case not then execute?

  4. #4
    Join Date
    Aug 2015
    Posts
    6

    Re: WM_CREATE and HWND issue

    Other code formerly in this WM_CREATE case executed just fine. Just not if checking the window handle.

  5. #5
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: WM_CREATE and HWND issue

    Quote Originally Posted by int Kev View Post
    This was me checking! Thank you for replying victor, but I'm not sure what you mean.
    just set a breakpoint at the line with
    Code:
    case WM_CREATE:
    and start debugging (F5)...
    Then press F10 to step through the code and look at the debugger ("auto" or "watch") window to see the values of the variables.
    Victor Nijegorodov

  6. #6
    Join Date
    Aug 2015
    Posts
    6

    Re: WM_CREATE and HWND issue

    What a useful tool! What appears to be happening is that, although the window was created with
    childwindowHandle = CreatewindowEx(... etc, assignment happens after any functions on the right finish.
    The CreateWindowEx() function runs, a WM_CREATE message is sent and processed, all before the variable childwindowHandle ever gets an assignment, and so, of course hwnd != childwindowHandle.
    Victor, this has clarified many things. Thank you.
    I've more to figure out, but as far as I'm concerned, thread resolved.

  7. #7
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: WM_CREATE and HWND issue

    Quote Originally Posted by int Kev View Post
    ...
    Victor, this has clarified many things. Thank you.
    I've more to figure out, but as far as I'm concerned, thread resolved.
    You are welcome!
    And now you can use the Thread Tools (the button on the toolbar above the posts to Mark Thread Resolved.
    Victor Nijegorodov

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

    Re: WM_CREATE and HWND issue

    that code makes no sense...

    this message is sent to the CHILD window after the window is actually created. so hwnd is that of the newly created child window.
    however, your application has no yet had an opportunity to actually know what the new window handle is, because that's exactly what createwindow is for, to inform you that the OS made a window and "here's the new handle for it"

    so how would childwindowHandle possibly have the right value if this is the first opportunity (other than hooking) your app gets to know about the new handle.

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