• Welcome to Valhalla Legends Archive.
 

Creating tooltips for buttons

Started by Okee, November 16, 2004, 08:36 PM

Previous topic - Next topic

Okee

Hi,

I've been trying to create tooltips for a standard button I have on my win32 form. I created the button using CreateWindowEx. On msdn.microsoft.com I have found a few interesting items regarding tooltips. I've been trying to use the tooltip controls provided.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/commctls/tooltip/reflist.asp

I'm not getting any errors as far as visual c++ 6 compiler is concerned, but the tooltip isn't appearing. I've created a function that, as well as I can tell, should be showing a tooltip when called. Here is my function:


void CreateMyTooltip (HWND hwnd)
{
                 
    INITCOMMONCONTROLSEX iccex;
    HWND hwndTT;                 

    TOOLINFO ti;
    unsigned int uid = 0;       
    char strTT[30] = "Halleluja!";
    LPTSTR lptstr = strTT;
    RECT rect;                 

    iccex.dwICC = ICC_WIN95_CLASSES;
    iccex.dwSize = sizeof(INITCOMMONCONTROLSEX);
    InitCommonControlsEx(&iccex);

    hwndTT = CreateWindowEx(WS_EX_TOPMOST,
        TOOLTIPS_CLASS,
        NULL,
        WS_POPUP | TTS_NOPREFIX | TTS_ALWAYSTIP,
        CW_USEDEFAULT,
        CW_USEDEFAULT,
        CW_USEDEFAULT,
        CW_USEDEFAULT,
        hwnd,
        NULL,
        hinstMain,
        NULL
        );

    SetWindowPos(hwndTT,
        HWND_TOPMOST,
        0,
        0,
        0,
        0,
        SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);

    GetClientRect (hwnd, &rect);

    ti.cbSize = sizeof(TOOLINFO);
    ti.uFlags = TTF_SUBCLASS;
    ti.hwnd = hwnd;
    ti.hinst = hinstMain;
    ti.uId = uid;
    ti.lpszText = lptstr;

    ti.rect.left = rect.left;   
    ti.rect.top = rect.top;
    ti.rect.right = rect.right;
    ti.rect.bottom = rect.bottom;

    SendMessage(hwndTT, TTM_ADDTOOL, 0, (LPARAM) (LPTOOLINFO) &ti);
SendMessage(hwndTT, TTM_ACTIVATE, TRUE, 0);

}


Now, I call this function from within my window process function:
LRESULT CALLBACK WndProc(HWND hWnd,
UINT uMsg,
WPARAM wParam,
LPARAM lParam)


Like so..

case WM_COMMAND:
{
CreateMyTooltip(hWnd);
}break;


All I found to include as far as header files was the common controls header. Like I said, no compiler errors and no program crashes. My knowledge of C++ ettiquite (sp?) is poor, but I'm trying.

On msdn, I also found some other information on tooltips at http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/commctls/tooltip/usingtooltips.asp but it looked to be relitively the same info.

Anyone have this 'my tooltip wont show up' problem before? Or anyone know of any way I can get a tooltip to popup when I put my mouse over my button? I know I have it for when I click it right now, I was going to work towards getting it when the mouse moves over the button.

Thanks in advance.

EDIT:

Sorry, I forgot to add what I was getting at with my C++ ettiquite comment. In that window process function I create my button in the WM_CREATE event. My HWND declare and initialization all reside within that case wm_create statement - I call my tooltip function from within another statement (wm_command). Now, I can pretty much tell thats one of my problems because the hwnd im passing to the function cant possibly be the hwnd of my button but I just cant put my finger on how to do this. Its just not clicking.

MyndFyre

You were close on "etiquette," just backwards on which part had one "t" and which had two.

An observation: you're receiving and processing the WM_COMMAND message.  That is only when you click a button, is it not?

I wonder if a tooltip inherently disappears when you click.  Or, if you're just not clicking your button and therefore not getting your tool tip?

(Unfortunately I'm not at home to test my theory).

Anyway, hope this helps. :)
QuoteEvery generation of humans believed it had all the answers it needed, except for a few mysteries they assumed would be solved at any moment. And they all believed their ancestors were simplistic and deluded. What are the odds that you are the first generation of humans who will understand reality?

After 3 years, it's on the horizon.  The new JinxBot, and BN#, the managed Battle.net Client library.

Quote from: chyea on January 16, 2009, 05:05 PM
You've just located global warming.

Kp

When things don't work, get in the habit of adding error checking code.  Make sure that the CreateWindowEx call for the tooltip occurs and produces a valid HWND.  If it fails, check GetLastError().  Same with other functions.  Not all the functions will produce an error code, but if one is being set, it may give you some hints about why it isn't working.
[19:20:23] (BotNet) <[vL]Kp> Any idiot can make a bot with CSB, and many do!

Okee

Yeah, I checked. It does create a valid hWnd.

Even if clicking removes the tooltip, which i didnt think about, wouldnt it still popup if i hit space bar to envoke wm_command? how are tooltips set for lets say, listviews and such in those battle.net bots.

Zakath

The method I use in my listview is, unfortunately, completely different. Listviews support a message called LVN_GETINFOTIP, which is passed to the parent in a WM_NOTIFY. There is, as far as I know, no analagous message for other controls.
Quote from: iago on February 02, 2005, 03:07 PM
Yes, you can't have everybody...contributing to the main source repository.  That would be stupid and create chaos.

Opensource projects...would be dumb.