Solved

Implementing tooltips using win32 API

Posted on 1998-05-08
4
773 Views
Last Modified: 2012-06-21
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.
0
Comment
Question by:hge
4 Comments
 
LVL 2

Expert Comment

by:Slarti
ID: 1250652
Can you use MFC? It will be a lot simpler...
0
 
LVL 1

Expert Comment

by:vsinha
ID: 1250653
Posting the question in the windows programming section may get you better/faster responses
0
 
LVL 1

Accepted Solution

by:
_Zaphod earned 70 total points
ID: 1250654
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
 

Expert Comment

by:monstro281
ID: 22293919
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

Featured Post

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Picking random number 8 175
C#, VS15, StructLayout 1 121
First character of input string truncated with scanf 3 94
delete-remove 14 62
Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use nested-loops in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.

919 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now