Solved

how to detect hover over button

Posted on 2013-06-03
4
498 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 34

Accepted Solution

by:
sarabande earned 500 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 34

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 34

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
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.

717 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