FindWindowEx() fails with ToolTip class

This is a discussion on FindWindowEx() fails with ToolTip class within the Windows Programming forums, part of the Platform Specific Boards category; FindWindowEx() is failing silently when I ask it to find the handle of my toolTip window. Here is my toolTip ...

  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,893
    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, 05:30 AM
  3. Creating a database
    By Shamino in forum Game Programming
    Replies: 19
    Last Post: 06-10-2007, 02:09 PM
  4. class method inside cout fails
    By atapi103 in forum C++ Programming
    Replies: 2
    Last Post: 08-25-2003, 12:35 AM
  5. Abstract class problem
    By VanJay011379 in forum C++ Programming
    Replies: 9
    Last Post: 07-31-2002, 02:30 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21