Cannot for the life of me get win32 tooltips working

This is a discussion on Cannot for the life of me get win32 tooltips working within the Windows Programming forums, part of the Platform Specific Boards category; Code: void CreateToolTipForRect(HWND hwndParent) { INITCOMMONCONTROLSEX ic; ic.dwSize = sizeof(INITCOMMONCONTROLSEX); ic.dwICC = ICC_TAB_CLASSES; InitCommonControlsEx(&ic); // Create a ToolTip. HWND hwndTT ...

  1. #1
    Registered User
    Join Date
    Jul 2005
    Posts
    22

    Cannot for the life of me get win32 tooltips working

    Code:
    void CreateToolTipForRect(HWND hwndParent)
    {
    	INITCOMMONCONTROLSEX ic;
     ic.dwSize = sizeof(INITCOMMONCONTROLSEX);
     ic.dwICC = ICC_TAB_CLASSES;
     InitCommonControlsEx(&ic);
    
        // Create a ToolTip.
        HWND hwndTT = CreateWindowEx(WS_EX_TOPMOST,
            TOOLTIPS_CLASS, NULL,
            WS_POPUP | TTS_NOPREFIX | TTS_ALWAYSTIP,		
            CW_USEDEFAULT, CW_USEDEFAULT,
            CW_USEDEFAULT, CW_USEDEFAULT,
            hwndParent, NULL, hInst,NULL);
    
        SetWindowPos(hwndTT, HWND_TOPMOST,
            0, 0, 0, 0,
            SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);
    
        // Set up "tool" information.
        // In this case, the "tool" is the entire parent window.
        TOOLINFO ti = { 0 };
        ti.cbSize = sizeof(TOOLINFO);
        ti.uFlags = TTF_SUBCLASS;
        ti.hwnd = hwndParent;
        ti.hinst = hInst;
        ti.lpszText = TEXT("This is your ToolTip string.");;
        GetClientRect (hwndParent, &ti.rect);
    
        // Associate the ToolTip with the "tool" window.
        SendMessage(hwndTT, TTM_ADDTOOL, 0, (LPARAM) (LPTOOLINFO) &ti);	
    	SendMessage(hwndTT, TTM_ACTIVATE, true, NULL);
    }
    That function is directly from msdn. I pass it my main hwnd after I create the main window. Yet no tooltips ever appear. I feel like there's some message I'm not handling/sending but I haven't been able to figure out what.

  2. #2
    Registered User
    Join Date
    Mar 2005
    Location
    Mountaintop, Pa
    Posts
    1,059
    Code:
    #pragma comment(lib, "user32.lib")
    #pragma comment(lib, "comctl32.lib")
    
    #include <windows.h>
    #include <commctrl.h>
    
    LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
    void CreateToolTipForRect(HWND hwndParent);
    
    HINSTANCE hInst;
    
    int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,
    			LPSTR lpCmdLine, int nCmdShow )
    {
      MSG  msg ;    
      WNDCLASS wc = {0};
      wc.lpszClassName = "Tooltip" ;
      wc.hInstance     = hInstance ;
      wc.hbrBackground = GetSysColorBrush(COLOR_3DFACE);
      wc.lpfnWndProc   = WndProc ;
      wc.hCursor       = LoadCursor(0, IDC_ARROW);
    
      hInst = hInstance;
      
      RegisterClass(&wc);
      CreateWindow( wc.lpszClassName, "Tooltip",
                    WS_OVERLAPPEDWINDOW | WS_VISIBLE,
                    100, 100, 200, 150, 0, 0, hInstance, 0);  
    
      while( GetMessage(&msg, NULL, 0, 0)) {
        TranslateMessage(&msg);
        DispatchMessage(&msg);
      }
      return (int) msg.wParam;
    }
    
    LRESULT CALLBACK WndProc( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam )
    {
      switch(msg)  
      {
        case WM_CREATE:
    	     CreateToolTipForRect(hwnd);
            break;
        case WM_DESTROY:
            PostQuitMessage(0);
            break;
      }
      return DefWindowProc(hwnd, msg, wParam, lParam);
    }
    
    void CreateToolTipForRect(HWND hwndParent)
    {
    	INITCOMMONCONTROLSEX ic;
     ic.dwSize = sizeof(INITCOMMONCONTROLSEX);
     ic.dwICC = ICC_TAB_CLASSES;
     InitCommonControlsEx(&ic);
        // Create a ToolTip.
        HWND hwndTT = CreateWindowEx(WS_EX_TOPMOST,
            TOOLTIPS_CLASS, NULL,
            WS_POPUP | TTS_NOPREFIX | TTS_ALWAYSTIP,		
            CW_USEDEFAULT, CW_USEDEFAULT,
            CW_USEDEFAULT, CW_USEDEFAULT,
            hwndParent, NULL, hInst,NULL);
        SetWindowPos(hwndTT, HWND_TOPMOST,
            0, 0, 0, 0,
            SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);
        // Set up "tool" information.
        // In this case, the "tool" is the entire parent window.
        TOOLINFO ti = { 0 };
        ti.cbSize = sizeof(TOOLINFO);
        ti.uFlags = TTF_SUBCLASS;
        ti.hwnd = hwndParent;
        ti.hinst = hInst;
        ti.lpszText = TEXT("This is your ToolTip string.");;
        GetClientRect (hwndParent, &ti.rect);
        // Associate the ToolTip with the "tool" window.
        SendMessage(hwndTT, TTM_ADDTOOL, 0, (LPARAM) (LPTOOLINFO) &ti);	
    	SendMessage(hwndTT, TTM_ACTIVATE, true, NULL);
    }

  3. #3
    Registered User
    Join Date
    Jul 2005
    Posts
    22
    Still no tooltip.

  4. #4
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,856
    Shouldn't the hInst be NULL?

    I think if the hInst is valid, the lpszText member is used as a resource ID (for a string in the exe).

    Check the returns.
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  5. #5
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,546
    Tooltips can be tricky. But there are 3rd party implementations that can take care of that.
    But you failed to mention if you're writing C or C++?
    I know of one particular implementation I use, but it's C++.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  6. #6
    Registered User
    Join Date
    Jun 2008
    Posts
    161
    I'd be interested to know how to get them working properly in C/API. I know I tried and failed a while back working from the MSDN example.

  7. #7
    Registered User
    Join Date
    Mar 2007
    Posts
    142
    I think there are two kinds of tooltips. One are connected to other controls and others are related to arbitrary rectangles. If I remember correctly, I quickly gave up when I tried these second type tooltips, so now I use only tooltips attached to other controls.

    Anyway, Raymond Chen had several articles about quirks with tooltips. They should help you:
    - Coding in-place tooltips
    - Using custom-draw in tooltips to adjust the font
    - Multiplexing multiple tools into one in a tooltip
    - Generating tooltip text dynamically
    - Why can't I display a tooltip for a disabled window?

  8. #8
    Registered User
    Join Date
    Apr 2007
    Posts
    137
    Quote Originally Posted by Viper187 View Post
    I'd be interested to know how to get them working properly in C/API. I know I tried and failed a while back working from the MSDN example.
    Tooltips work obviously fine in C & Win32 api.
    All C PSDK samples work perfectly, even those which are 13 years old..
    Their source code in comctl32.dll is in pure C code in v5 and in C++ in v6.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Win32 API or Win32 SDK?
    By jverkoey in forum A Brief History of Cprogramming.com
    Replies: 2
    Last Post: 07-20-2005, 03:26 PM
  2. The Meaning of Life: A Trick Question?
    By chix/w/guns in forum A Brief History of Cprogramming.com
    Replies: 14
    Last Post: 07-12-2004, 07:53 PM
  3. My Win32 Program isn't working?
    By Alphacentric666 in forum Windows Programming
    Replies: 2
    Last Post: 11-30-2002, 11:22 PM
  4. Win32 Not working???
    By grmoo in forum C++ Programming
    Replies: 0
    Last Post: 09-11-2002, 07:20 AM
  5. OLE Clipboard :: Win32 API vs. MFC
    By kuphryn in forum Windows Programming
    Replies: 3
    Last Post: 08-11-2002, 05:57 PM

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