• C

Implementing tooltips using win32 API

Could anybody provide me with a step-by-step explanation of how I can implement tooltips
(eg for picture buttons, but also for an edit control, etc). The explanation must assume using
the Win32 API.
hgeAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

SlartiCommented:
Can you use MFC? It will be a lot simpler...
0
vsinhaCommented:
Posting the question in the windows programming section may get you better/faster responses
0
_ZaphodCommented:
Have a timer with a delay of, say, one second.
Every time it ticks, get the cursor position (GetCursorPos), and check which control the cursor is on. Set some global or static variable to a value associated with the control - its ID, handle or some other value you decide on. If the cursor isn't on any control, set it to a null value. Each time the timer ticks, check if the current position of the cursor is on the same control as in the previous time. If so, display a tooltip. The best way to do this would be using a small window of its own right, borderless that cannot be sized, which will have a timer of a few seconds, which, when elapsed, will close the window, and the main window will close the tooltip if the cursor has gone over another control. So the best would probably be to use just one window for the tooltip, never destroying it, just showing, moving and hiding it as necessary.
That's all :)
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
monstro281Commented:
I didn't see a concise solution:  here is mine.
void CreateToolTip(HWND& hWnd_Tip, HWND& hwndMain, HINSTANCE& hInstMain, HWND& hWnd_Tool,std::string toolTipText, TOOLINFO& toolInfo )
{
 
// hWnd_Tip: handle to tooltip window
// hwndMain: handle to parent of tool
// hInstMain: app Instance
// hWnd_Tool: handle to Tool for which tooltip is applied
// toolInfo:  TOOLINFO structure, intialize before calling this function, i.e. "TOOLINFO toolInfo = { 0 };"
 
	hWnd_Tip = CreateWindowEx(NULL, TOOLTIPS_CLASS, NULL,
					        WS_POPUP | TTS_NOPREFIX | TTS_ALWAYSTIP,
							CW_USEDEFAULT, CW_USEDEFAULT,
							CW_USEDEFAULT, CW_USEDEFAULT,
							hWndMain, NULL, hInstMain,
							NULL);
 
	SetWindowPos(hWnd_Tip, HWND_TOPMOST,0, 0, 0, 0,
				SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);
 
	    // Associate the ToolTip with the tool.
    toolInfo.cbSize = sizeof(toolInfo);
    toolInfo.hwnd = hWndMain;
    toolInfo.uFlags = TTF_IDISHWND | TTF_SUBCLASS;
    toolInfo.uId = (UINT_PTR) hWnd_Tool;
    toolInfo.lpszText = (LPSTR)  toolTipText.c_str();
    SendMessage(hWnd_Tip, TTM_ADDTOOL, 0, (LPARAM)&toolInfo);
}

Open in new window

0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.