-
November 27th, 2008, 12:56 PM
#1
Tooltip
Is there anything wrong in this piece of code?
Code:
void CreateToolTip(HWND hwndParent, RECT rectTip, LPWSTR lpTipString){
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);
TOOLINFO ti = { 0 };
ti.cbSize = sizeof(TOOLINFO);
ti.uFlags = TTF_SUBCLASS|TTF_IDISHWND;
ti.hwnd = hwndParent;
ti.hinst = hInst;
ti.lpszText = lpTipString;
ti.rect = rectTip;
SendMessage(hwndTT, TTM_ADDTOOL, 0, (LPARAM) (LPTOOLINFO) &ti);
}
I call this function in my WM_CREATE / WM_INITDIALOG, but I never see a tooltip if
the mouse hovers the rect. I do call InitCommonControlsEx() before.
?
-
November 28th, 2008, 12:44 PM
#2
Re: Tooltip
At first glance:
1. Get rid of SetWindowPos().
2. Replace the CreateWindowEx with a normal CreateWindow - no TopMost.
3. Set the ID in the TOOLINFO struct.
4. Don't forget to activate the tooltips.
Code:
SendMessage(hwndTT, TTM_ACTIVATE, TRUE, 0);
5. If you are using any sort of wrapper (MFC, .NET, ATL), don't forget to enable tooltips on the parent window.
-Erik
-
November 28th, 2008, 03:15 PM
#3
Re: Tooltip
Use CreateWindowEx. Using CreateWindow may render tooltips inoperable in older versions of windows.
You can use CreateWindow, but to be on the safe side add WS_EX_TOOLWINDOW extended style. You do not have to use WS_EX_TOPMOST but using it should not do any harm.
You can indeed get rid of SetWindowPos call but it is irrelevant.
Fill TOOLINFO properly. This is a cause of your problem. If you are adding rectangle as a tool, you cannot use TTF_IDISHWND flag. If you add more rectangles, than you would have to assign ID that is unique for each rectangle. I your case it is 0.
In conclusion, removing TTF_IDISHWND flag is a fix you need.
Code:
TOOLINFO ti = {0};
ti.cbSize = sizeof(TOOLINFO);
ti.uFlags = TTF_SUBCLASS;//|TTF_IDISHWND;
ti.hwnd = hwndParent;
ti.hinst = hInst;
ti.lpszText = lpTipString;
ti.rect = rectTip;
SendMessage(hwndTT, TTM_ADDTOOL, 0, (LPARAM)&ti);
You do not have to activate tooltips, since they are created as active. Use TTM_ACTIVATE to disable/enable tooltips if needed later in the code.
There are only 10 types of people in the world:
Those who understand binary and those who do not.
-
November 28th, 2008, 11:50 PM
#4
Re: Tooltip
Thanks for the answers, I adapted my the code but still, no tooltip is showing up.
It looks like this now:
Code:
case WM_INITDIALOG:{
...
InitCommonControls();
CreateToolTip(hWnd, rectStatus, L"Test", TT_TEST);
...
I tried InitCommonControlsEx() also, but I don't think that is the problem.
TT_TEST is defined as 20001.
rectStatus is defined global as RECT rectStatus = {70, 310, 480, 350}; which is a rectangle
within my dialog client window.
Code:
void CreateToolTip(HWND hwndParent, RECT rectTip, LPWSTR lpTipString, UINT uId){
HWND hwndTT = CreateWindowEx(WS_EX_TOPMOST|WS_EX_TOOLWINDOW,
TOOLTIPS_CLASS, NULL,
WS_POPUP | TTS_NOPREFIX | TTS_ALWAYSTIP,
CW_USEDEFAULT, CW_USEDEFAULT,
CW_USEDEFAULT, CW_USEDEFAULT,
hwndParent, NULL, hInst,NULL);
TOOLINFO ti = { 0 };
ti.cbSize = sizeof(TOOLINFO);
ti.uFlags = TTF_SUBCLASS;
ti.hwnd = hwndParent;
ti.hinst = hInst;
ti.lpszText = lpTipString;
ti.rect = rectTip;
ti.uId = uId;
SendMessage(hwndTT, TTM_ADDTOOL, 0, (LPARAM) (LPTOOLINFO) &ti);
}
I don't get a tooltip when I hover the mouse over rectTip.
-
November 29th, 2008, 09:32 AM
#5
Re: Tooltip
Something must be wrong with your rectangle coordinates.
Just for a test initialize it to 0, 0, 200, 100. This will allow you to test left upper corner area.
If you still have problems, post your code. I always test my solution before posting and it works for me.
There are only 10 types of people in the world:
Those who understand binary and those who do not.
-
November 30th, 2008, 04:57 AM
#6
Re: Tooltip
I'm pretty much helpless on that too.
The rectangle is ok, I'm drawing it with FillRect().
I'm using exactly the code I posted, I Just changed the InitCommonControls() with InitCommonControlsEx() with almost every flag.
Well, It also does not work when I setup a tooltip for any control in my dialog. Just nothing happens. Other applications on my machine can create tooltips so it must be something on my code or environment.
I'm compiling a win32 api application, written in C. Using MSVS 2008.
Help
-
November 30th, 2008, 07:41 AM
#7
Re: Tooltip
It has nothing to do with Rectangle coordinates.
See Google Groups where the reason why it dosn't work has been explained hundreds of times...
-
November 30th, 2008, 07:59 AM
#8
Re: Tooltip
Great comment.
Are you kidding me? Just paste a link to whatever you mean if you know for sure what
the problem is about.
-
November 30th, 2008, 11:25 AM
#9
Re: Tooltip
Originally Posted by me earlier
If you still have problems, post your code.
As I said it works for me. Tested on Vista and XP.
From the code snippet you have posted, I do not see any reason for failure. I am not able to determine what is wrong without seeing code for entire application.
Maybe something you do in a main loop prevents working?
Last edited by JohnCz; November 30th, 2008 at 11:30 AM.
There are only 10 types of people in the world:
Those who understand binary and those who do not.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|