Tool-tip does not appear, going crazy again

Jan 31, 2012 at 5:48pm
O.K. I must admit that with the help of a lot of users I accumulated a lot of C++ knowledge. Now, I have this problem. I am trying to create a tooltip for a button that I have created. It just doesn't appear when I move the mouse over the button.

The code is something like this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54

//This function taken from http://msdn.microsoft.com/en-us/library/windows/desktop/hh298368(v=vs.85).aspx
HWND CreateToolTip(int toolID, HINSTANCE hInst, HWND hDlg, PTSTR pszText) {
    if (!toolID || !hDlg || !pszText) {
        return FALSE;
    }

    HWND hwndTool = GetDlgItem(hDlg, toolID);

    HWND hwndTip = CreateWindowEx(NULL, TOOLTIPS_CLASS, NULL,
                              WS_POPUP |TTS_ALWAYSTIP | TTS_BALLOON,
                              CW_USEDEFAULT, CW_USEDEFAULT,
                              CW_USEDEFAULT, CW_USEDEFAULT,
                              hDlg, NULL,
                              hInst, NULL);

   if (!hwndTool || !hwndTip) {
       return (HWND)NULL;
   }

   TOOLINFO toolInfo;
   toolInfo.cbSize = sizeof(toolInfo);
   toolInfo.hwnd = hDlg;
   toolInfo.uFlags = TTF_IDISHWND | TTF_SUBCLASS;
   toolInfo.uId = (UINT_PTR)hwndTool;
   toolInfo.lpszText = pszText;
   SendMessage(hwndTip, TTM_ADDTOOL, 0, (LPARAM)&toolInfo);

   return hwndTip;
}

HWND mybutton, tooltip_mess;

int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR lpCmd, int nCmd) {
     //Well, this code is not important
}

LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam){
    switch (message) {
        case WM_CREATE:
            mybutton = CreateWindowEx(
                       WS_EX_CLIENTEDGE,
                       "BUTTON",
                       "My Button",
                       WS_VISIBLE|WS_CHILD,
                       10, 10, 100, 24, 
                       hWnd,
                       (HMENU)MY_BUTTON_ID,
                       hInstance,
                       NULL);
            tooltip_mess = CreateToolTip(TOOLTIP_ID, hInstance, mybutton , (char*)"Tooltip message");
        break;
    }
}


So, the tooltip handler is created. Even so, I don't see it when the mouse lays over the button. It uses the same instance, the controls IDs are correct. I don't understand what am I missing.
Last edited on Jan 31, 2012 at 5:51pm
Jan 31, 2012 at 7:38pm
You have missunderstood the msdn example so you are using some wrong parameters in the wrong place.
I'll post a correction shortly.

And here it is - you are passing the wromg parameters to the CreateToolTip function.
In the Wndproc, you should have
tooltip_mess = CreateToolTip(MY_BUTTON_ID, hInstance, hWnd, (char*)"Tooltip message");
Last edited on Jan 31, 2012 at 7:50pm
Topic archived. No new replies allowed.