win32: the tooltip isn't showed :(

i have read these thread: http://www.cplusplus.com/forum/windows/60609/
i have subclassed the controls. i builded the button without ID.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
HWND CreateToolTip(HWND hwndTool, HINSTANCE hInst, HWND hDlg, PTSTR pszText) 
{



    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);


   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;
}

heres how i use it:
1
2
3
4
5
lbltest.MouseClick=[]() //lambda for testing
    {
        tooltip_mess=CreateToolTip(0, hinstance, ActivatedForm , (char*)"Tooltip message");
        //MessageBox(NULL,"hey", "hello", MB_OK);
    };

but the tooltip isn't showed :(
what i'm doing wrong?
Last edited on
Texan40 i'm on that link without sucess :(
1
2
3
4
5
6
7
8
9
10
11
12
13
14
void tooltip(HWND hwndOwner,string text)
{
    
    HWND hwnd = CreateWindowEx(WS_EX_TOPMOST,TOOLTIPS_CLASS,NULL, WS_VISIBLE,
                      CW_USEDEFAULT, CW_USEDEFAULT,CW_USEDEFAULT, CW_USEDEFAULT, HWND_DESKTOP, NULL, (HINSTANCE)GetModuleHandle(NULL), NULL);

    TOOLINFO toolInfo = { 0 };
    toolInfo.uFlags=TTF_CENTERTIP | TTF_ABSOLUTE | TTF_IDISHWND;
    toolInfo.cbSize = sizeof(toolInfo);
    toolInfo.hwnd=hwndOwner;
    toolInfo.lpszText ="hello world";
    SendMessage(hwnd, TTM_ADDTOOL, 0, (LPARAM)&toolInfo);
    SendMessage(hwnd, TTM_ACTIVATE, 0, (LPARAM)&toolInfo);
}

isn't showed :(
Last edited on
Yeah, I think that example is missing something. I compiled this one and it worked:

http://www.alsprogrammingresource.com/tooltips.html
Texan40 did i need activate the WM_NOTIFY message? a window style or something?(i never used it)
In the working example looks like he is capturing the TTN_NEEDTEXT notification to assign the tooltip text based on which control ID it is calling.
finally works, but by some reason a need activate it :(
see how i create it:
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
HWND CreateToolTip(HWND hwndTool, string text)
{

	/*INITCOMMONCONTROLSEX icc;

	icc.dwSize = sizeof(INITCOMMONCONTROLSEX);
	icc.dwICC = ICC_BAR_CLASSES | ICC_TAB_CLASSES | ICC_WIN95_CLASSES;

	InitCommonControlsEx(&icc);*/
	if (text=="")
	{
		return FALSE;
	}
	// Get the window of the tool.
	//HWND hwndTool = GetDlgItem(hDlg, toolID);

	// Create the tooltip. g_hInst is the global instance handle.
	HWND hwndTip = CreateWindowEx(0, TOOLTIPS_CLASS, NULL,
		WS_POPUP | TTS_ALWAYSTIP | TTS_BALLOON,
		CW_USEDEFAULT, CW_USEDEFAULT,
		CW_USEDEFAULT, CW_USEDEFAULT,
		GetParent(hwndTool), NULL,
		hinstance, NULL);

	if (!hwndTool || !hwndTip)
	{
	    MessageBox(NULL, "Couldn't create the ToolTip control.", "Error", MB_OK);
		return (HWND)NULL;
	}

	// Associate the tooltip with the tool.
	TOOLINFO toolInfo = { 0 };
	toolInfo.cbSize = TTTOOLINFOA_V1_SIZE;
	toolInfo.hwnd = GetParent(hwndTool);
	toolInfo.uFlags = TTF_IDISHWND | TTF_SUBCLASS;
	toolInfo.uId = (UINT_PTR)hwndTool;
	toolInfo.lpszText =(LPSTR) text.c_str();

	if (SendMessage(hwndTip, TTM_ACTIVATE, TRUE, 0)) //Will add the Tool Tip on Control
    {
		int err = GetLastError();
		MessageBox(NULL,to_string(GetLastError()).c_str(), "Error", MB_OK);

	}
	if (!SendMessage(hwndTip, TTM_ADDTOOL, 0, (LPARAM)&toolInfo)) //Will add the Tool Tip on Control
    {
		int err = GetLastError();
		MessageBox(NULL,to_string(GetLastError()).c_str(), "Error", MB_OK);

	}

	return hwndTip;
}

somewhere on code:
HWND tootip= CreateToolTip( btnButton , "hello");
if i pressed button the tooltip works fine, if i pressed again, it wont. seems the click activates\disable the tooltip :(
the code works fine. my problem is with 1 or 2 functions that have some memory leaks. i don't get errors, just what i see.
thanks for all Texan40
Topic archived. No new replies allowed.