[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

how to detect hover over button

Posted on 2013-06-03
4
Medium Priority
?
522 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 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

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…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
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 learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

834 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