Solved

how to detect hover over button

Posted on 2013-06-03
4
492 Views
Last Modified: 2013-06-04
I have a button , IDC_BUTTON, and i would like to be notified if it has Been hovered over for 5 second or more.

Could someone show me an example of how i would  thuthis?

Thank you!
0
Comment
Question by:edvinson
  • 3
4 Comments
 
LVL 32

Accepted Solution

by:
sarabande earned 500 total points
Comment Utility
if using mfc you would use the CMFCTooltipCtrl.

if not using mfc you need to create a new window with window class "TOOLTIPS_CLASSW" and then associate it to the button with code like the following:

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

HWND hwnd_tip = CreateWindowExW(0, TOOLTIPS_CLASSW, NULL, 
  WS_POPUP | TTS_NOPREFIX | TTS_ALWAYSTIP, 
  CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
  NULL, NULL, hinst, NULL
);
SetWindowPos(hwnd_tip, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);

TOOLINFOW ti;
memset(&ti, 0, sizeof(TOOLINFOW));
ti.cbSize = sizeof(TOOLINFOW);
ti.hwnd = hwnd_main;
ti.uId = (UINT) hwnd_control;
ti.uFlags = TTF_IDISHWND | TTF_SUBCLASS;
ti.lpszText = L"This tip is shown correctly, including unicode characters.";
SendMessageW(hwnd_tip, TTM_ADDTOOLW, 0, (LPARAM) &ti);

Open in new window


if using multibyte characterset you would remove W suffix, for example use SendMessage instead of SendMessageW.

in t.uId you would store the window handle of the button control. the message TTM_ADDTOOL then would make the association of the button with the tooltip.
0
 
LVL 32

Expert Comment

by:sarabande
Comment Utility
if using mfc you could check some SAMPLES project. see

http://msdn.microsoft.com/en-us/library/cc165840(v=VS.90).aspx

Sara
0
 
LVL 1

Author Comment

by:edvinson
Comment Utility
I'm not using MfC, does your code example work in a dialog based app?
0
 
LVL 32

Expert Comment

by:sarabande
Comment Utility
i have not tested the code but found in a forum where they said it was working code. in my expertise it looks ok.

if that is true, it will work with dialogs as well as with any other (parent) window. if you created the dialog form from resources you can get the window handle of the button by calling GetDlgItem(hwndDlg, IDC_BUTTON);

additionally you may make the dialog window parent of the tooltip window by passing the window handle of the dialog with CreateWindowEx call when the tooltip window was created. however, that should be optional.

Sara
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

763 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

14 Experts available now in Live!

Get 1:1 Help Now