Thread: FindWindowEx() fails with ToolTip class

  1. #1
    Registered Abuser
    Join Date
    Jun 2006
    Location
    Toronto
    Posts
    591

    FindWindowEx() fails with ToolTip class

    FindWindowEx() is failing silently when I ask it to find the handle of my toolTip window. Here is my toolTip generation code:
    Code:
    HWND createTooltip(HWND hwnd){
        INITCOMMONCONTROLSEX iccex;
        /* INITIALIZE COMMON CONTROLS */
        iccex.dwICC = ICC_WIN95_CLASSES;
        iccex.dwSize = sizeof(INITCOMMONCONTROLSEX);
        InitCommonControlsEx(&iccex);
    
        HWND hwndTT = CreateWindowEx(WS_EX_TOPMOST, TOOLTIPS_CLASS, NULL,
                                     WS_POPUP | TTS_NOPREFIX | TTS_ALWAYSTIP,
                                     CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
                                     hwnd, NULL, GetModuleHandle(NULL), NULL);
    
        SetWindowPos(hwndTT, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);
    
        return hwndTT;
    }
    And here is my code calling FindWindowEx:
    Code:
    HWND hTT = FindWindowEx(hwnd, NULL, TOOLTIPS_CLASS, NULL);
    My parent window handle (hwnd) is the same handle I supplied during the ToolTip's creation; but despite this,
    FindWindowEx returns NULL and sets GetLastError to 0; where, according to microsoft's defintion here, it should be returning the handle to my ToolTip window. Exactly why does it refuse to do this?

  2. #2
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    Your tooltip is an owned window, rather than a child window (child windows have the WS_CHILD style).

    I don't know of any neat way of iterating owned windows of a particular window but you could try iterating all top-level windows (using EnumWindows or FindWindowEx) and checking if they are owned by your target window (using GetWindow with GW_OWNER).

    Typically, you would just store the window handle.

  3. #3
    Registered Abuser
    Join Date
    Jun 2006
    Location
    Toronto
    Posts
    591
    Hey thanks anony! I've been running into a lot of these problems between child vs owned windows lately (i.e GetParent() vs GetWindow())...
    The EnumWindows solution sounds good, I think I'll go with that. But when you say store the window handle, you mean globally?

  4. #4
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    Globally or as the member of a class that is globally available, or at least everywhere you need it. Point is, the HWND should be available where you need it, and you should never have to search for your own windows.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Class design problem
    By h3ro in forum C++ Programming
    Replies: 10
    Last Post: 12-19-2008, 09:10 AM
  2. Specializing class
    By Elysia in forum C++ Programming
    Replies: 6
    Last Post: 09-28-2008, 04:30 AM
  3. Creating a database
    By Shamino in forum Game Programming
    Replies: 19
    Last Post: 06-10-2007, 01:09 PM
  4. class method inside cout fails
    By atapi103 in forum C++ Programming
    Replies: 2
    Last Post: 08-24-2003, 11:35 PM