I need help on adding tooltips to controls

This is a discussion on I need help on adding tooltips to controls within the Windows Programming forums, part of the Platform Specific Boards category; Hi, im using DEV-CPP 4.9.7.0 (MingW32 2.0, GCC 3.2) to (try to) develop C + Win32API programs. Things were going ...

  1. #1
    Registered User
    Join Date
    Nov 2002
    Posts
    42

    I need help on adding tooltips to controls

    Hi, im using DEV-CPP 4.9.7.0 (MingW32 2.0, GCC 3.2) to (try to) develop C + Win32API programs. Things were going OK until i started trying to add TOOLTIPS for each controls of my app, i just cant make it work, couldnt also find a good example anywhere.

    Maybe i should just post the code so that you can all have a good laugh at me

    Code:
    /* Part of main.h*/ 
    ...
    HWND name_s1;
    HWND tip_s1;
    TOOLINFO toolInfo;
    ...
    /* Part of main.c */
    ...
    /*This hole thing is inside a WM_CREATE case: */
          
          /*This is the control im trying to add a tooltip */ 
          name_s1 = CreateWindow (TEXT ("edit"), TEXT(strname_s1), 
          WS_CHILD | WS_VISIBLE | WS_TABSTOP | WS_BORDER,
            25, 50, 109, 15, mainWindow, (HMENU) 201, ((LPCREATESTRUCT) lParam)->hInstance, NULL) ; 
          
          toolInfo.cbSize = sizeof(toolInfo);             /* Noy much to say :) */ 
          toolInfo.uFlags = TTF_IDISHWND | TTF_SUBCLASS;  /* The styles */
          toolInfo.hwnd = mainWindow;                     /* The Main Window HWND */
          toolInfo.uId = (unsigned int) 201;              /* The ID of the Control im adding the tooltip (name_s1) */
          toolInfo.lpszText = "Some useful info";         /*The tooltip text */
          
          
    
          tip_s1 = CreateWindowEx(WS_EX_TOPMOST, TOOLTIPS_CLASS, NULL,
                                WS_POPUP | TTS_NOPREFIX | TTS_ALWAYSTIP,
                                CW_USEDEFAULT, CW_USEDEFAULT,
                                CW_USEDEFAULT, CW_USEDEFAULT,
                                mainWindow, NULL, ((LPCREATESTRUCT) lParam)->hInstance,
                                NULL);
    
          SendMessage(tip_s1, TTM_ACTIVATE, TRUE, 0);   
          SendMessage(name_s1, TTM_ADDTOOL, 0, (LPARAM) (LPTOOLINFO) &toolInfo);   
    ...
    I got -lcomctl32 and -user32.lib in my Linker Options. The rest of the app is working ok, GCC outputs no warn or error (even using -Wall).
    Can you help me?

  2. #2
    Registered User
    Join Date
    Nov 2002
    Posts
    42
    I forgot to mention, my app uses TABS, created at wm_create too. Maybe thats what is interfering with the tooltips stuff?

    Code:
    /* At WM_CREATE: */
    hwndTab = CreateWindow(WC_TABCONTROL, "", 
          WS_CHILD | WS_CLIPSIBLINGS | WS_VISIBLE, 
          3, 3, 358, 390, mainWindow, (HMENU) 10, ((LPCREATESTRUCT) lParam)->hInstance,  NULL); 
          
          tci.mask=TCIF_TEXT; 
          tci.iImage=-1; 
          tci.pszText = "Status:"; 
          TabCtrl_InsertItem(hwndTab,0,&tci); 
          tci.pszText = "Config:"; 
          TabCtrl_InsertItem(hwndTab,1,&tci); 
          tci.pszText = "Info:"; 
          TabCtrl_InsertItem(hwndTab,2,&tci); 
    
    /* and later... */ 
    
    case WM_NOTIFY:   /* To process a tab change */      
          nmptr=(LPNMHDR)lParam; 
          switch(nmptr->code) {
            case TCN_SELCHANGE:  
              tabnumber = TabCtrl_GetCurSel((HWND)nmptr->hwndFrom); 
              switch(tabnumber) {
                case 0:
                showStatusTab();
                break;
                
                case 1:
                showConfigTab();
                break;
                
                case 2:
                showInfoTab();
                break;
              }
            default:                                           
              return DefWindowProc (mainWindow, messages, wParam, lParam);
              return 0;
           }
    Im starting to check the rest of my code because each and every example of tooltips i found on the net look very equal to my code, so the bug must be elsewhere. Please if you got any ideas on that, let me know
    Thank you!

  3. #3
    Registered User
    Join Date
    Dec 2002
    Posts
    119
    This may not be your problem, but make sure the common controls DLL is loaded with a call to
    Code:
    InitCommonControls(); // no params
    -Futura
    If you speak or are learning Spanish, check out this Spanish and English Dictionary, it is a handy online resource.
    What happens is not as important as how you react to what happens. -Thaddeus Golas

  4. #4
    Registered User
    Join Date
    Nov 2002
    Posts
    42
    Hey Codulation, thanks for your reply and happy new year

    Yep, i already got InitCommonControls() in my code, common controls header included and common controls lib linked, this is getting very frustrating

    I also tried (dont really know exactly why) using InitCommonControlsEx(&ccex) but the result is the same, no tooltips.

  5. #5
    Registered User
    Join Date
    Dec 2002
    Posts
    35
    Dev-Cpp needs full path to LIBs and also rest of included files(not relative) and also needs extension for lib, here it is '.a'.

    Try to add this lib via,

    project options -> Click Add Library or Project(button)

    I also tried (dont really know exactly why) using InitCommonControlsEx(&ccex) but the result is the
    same, no tooltips.
    that API for ensure that comctl32.lib is invoked.(At least I know so)

    Good Luck
    Last edited by fizisyen; 01-03-2003 at 02:44 PM.

  6. #6
    Registered User
    Join Date
    Nov 2002
    Posts
    42
    >>fizisyen
    Hey, thanks for answering
    That was not the problem, im aware of the things you said about the path to libs, etc.
    Im really getting mad at all this, cant believe tooltips would be so hard to create.

    I have decided to create a very small example with only one control to see if i can make the tooltip work and i cant!!!

    Please, give it a try, see what you think of it. Im a little retarded, maybe youll all spot what im doing wrong...

    Thank you!

    /* This is that dev-cpp basic C+win32 app example, plus one edit control and the tooltip control */
    /* It runs ok, no errors, but i cant see no tooltip */
    /* Remember to use -lcomctl32 at the "Linker Options" */

    Code:
    --------------main.h---------- 
    #include <windows.h> 
    #include <commctrl.h> 
    
    HWND hwndMain; 
    TOOLINFO toolInfo; 
    HINSTANCE hThisInstance; 
    HWND name_s1; 
    HWND hwndTool; 
    ---------End of main.h-------- 
    
    ---------------main.c--------- 
    #include "main.h" 
    
    
    /* Declare Windows procedure */ 
    LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM); 
    
    /* Make the class name into a global variable */ 
    char szClassName[ ] = "WindowsApp"; 
    
    
    int WINAPI 
    WinMain (HINSTANCE hThisInstance, 
    HINSTANCE hPrevInstance, 
    LPSTR lpszArgument, 
    int nFunsterStil) 
    
    { 
    MSG messages; /* Here messages to the application are saved */ 
    WNDCLASSEX wincl; /* Data structure for the windowclass */ 
    
    /* The Window structure */ 
    wincl.hInstance = hThisInstance; 
    wincl.lpszClassName = szClassName; 
    wincl.lpfnWndProc = WindowProcedure; /* This function is called by windows */ 
    wincl.style = CS_DBLCLKS; /* Catch double-clicks */ 
    wincl.cbSize = sizeof (WNDCLASSEX); 
    
    /* Use default icon and mouse-pointer */ 
    wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION); 
    wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION); 
    wincl.hCursor = LoadCursor (NULL, IDC_ARROW); 
    wincl.lpszMenuName = NULL; /* No menu */ 
    wincl.cbClsExtra = 0; /* No extra bytes after the window class */ 
    wincl.cbWndExtra = 0; /* structure or the window instance */ 
    /* Use Windows's default color as the background of the window */ 
    wincl.hbrBackground = (HBRUSH) COLOR_BACKGROUND; 
    
    /* Register the window class, and if it fails quit the program */ 
    if (!RegisterClassEx (&wincl)) 
    return 0; 
    
    /* The class is registered, let's create the program*/ 
    hwndMain = CreateWindow ( 
    szClassName, /* Classname */ 
    "Windows App", /* Title Text */ 
    WS_OVERLAPPEDWINDOW, /* default window */ 
    CW_USEDEFAULT, /* Windows decides the position */ 
    CW_USEDEFAULT, /* where the window ends up on the screen */ 
    544, /* The programs width */ 
    375, /* and height in pixels */ 
    HWND_DESKTOP, /* The window is a child-window to desktop */ 
    NULL, /* No menu */ 
    hThisInstance, /* Program Instance handler */ 
    NULL /* No Window Creation data */ 
    ); 
    
    /* Make the window visible on the screen */ 
    ShowWindow (hwndMain, nFunsterStil); 
    InitCommonControls(); 
    /* Run the message loop. It will run until GetMessage() returns 0 */ 
    while (GetMessage (&messages, NULL, 0, 0)) 
    { 
    /* Translate virtual-key messages into character messages */ 
    TranslateMessage(&messages); 
    /* Send message to WindowProcedure */ 
    DispatchMessage(&messages); 
    } 
    
    /* The program return-value is 0 - The value that PostQuitMessage() gave */ 
    return messages.wParam; 
    } 
    
    
    /* This function is called by the Windows function DispatchMessage() */ 
    
    LRESULT CALLBACK 
    WindowProcedure (HWND hwndMain, UINT message, WPARAM wParam, LPARAM lParam) 
    { 
    switch (message) /* handle the messages */ 
    { 
    case WM_CREATE: 
    
    hwndTool = CreateWindow(TOOLTIPS_CLASS, NULL, WS_POPUP | TTS_ALWAYSTIP, 
    CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, 
    hwndMain, (HMENU) 100, hThisInstance, NULL); 
    
    name_s1 = CreateWindow (TEXT ("edit"), NULL, 
    WS_CHILD | WS_VISIBLE | WS_TABSTOP | WS_BORDER, 
    25, 50, 109, 15, hwndMain, (HMENU) 200, hThisInstance, NULL) ; 
    
    toolInfo.cbSize = sizeof(TOOLINFO); /* Not much to say */ 
    toolInfo.uFlags = TTF_SUBCLASS; /* The Styles */ 
    toolInfo.hwnd = hwndMain; /* My Main Window HWND */ 
    toolInfo.hinst = hThisInstance; 
    toolInfo.uId = 200; /* This is the ID of the control the tooltip should be associated with (name_s1) */ 
    toolInfo.lpszText = "I hope this text ever shows up"; /* The tooltip text */ 
    
    SendMessage(hwndTool, TTM_ADDTOOL, 0, (LPARAM)&toolInfo); 
    SendMessage(hwndTool, TTM_ACTIVATE, TRUE, 0); 
    return 0; 
    
    case WM_DESTROY: 
    PostQuitMessage (0); /* send a WM_QUIT to the message queue */ 
    break; 
    default: /* for messages that we don't deal with */ 
    return DefWindowProc (hwndMain, message, wParam, lParam); 
    } 
    
    return 0; 
    } 
    ---------End of main.c--------

  7. #7
    Registered User
    Join Date
    Dec 2002
    Posts
    35
    Here is my solution,

    Hope works in your system too.

    Good Luck
    Attached Files Attached Files
    Want to learn? Then try to teach...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Dynamic adding of Controls
    By WDT in forum C# Programming
    Replies: 5
    Last Post: 04-22-2009, 07:59 AM
  2. ListView controls - Adding items .. What the beep?
    By IceDane in forum Windows Programming
    Replies: 7
    Last Post: 04-08-2008, 12:07 PM
  3. SVN Import Causes Crash
    By Tonto in forum Tech Board
    Replies: 6
    Last Post: 11-01-2006, 02:44 PM
  4. confused about adding controls to main window
    By terracota in forum Windows Programming
    Replies: 4
    Last Post: 11-24-2004, 11:35 AM
  5. Adding Default values to controls in Dialog boxes
    By juhigarg in forum C++ Programming
    Replies: 3
    Last Post: 11-06-2001, 11:44 PM

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