?
Solved

how to detect hover over button

Posted on 2013-06-03
4
Medium Priority
?
505 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 
LVL 35

Accepted Solution

by:
sarabande earned 2000 total points
ID: 39218139
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 35

Expert Comment

by:sarabande
ID: 39218147
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
ID: 39218456
I'm not using MfC, does your code example work in a dialog based app?
0
 
LVL 35

Expert Comment

by:sarabande
ID: 39218551
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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
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.

801 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