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
Solved

how to detect hover over button

Posted on 2013-06-03
4
496 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 33

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 33

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 33

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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

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 will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
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.

840 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