Solved

Knowing when a button is highlighted (but not clicked)

Posted on 1998-12-08
7
242 Views
Last Modified: 2010-04-02
This is a good one.  I have a button on a dialog; naturally, It gets clicked, but when its not clicked, the focus HAS to stay on a different control.  The problem:  if you click on a button in Windows and move the mouse off the button and release mouse, the focus STAYS on the button.  Even if the button is not in the Z order.  

I'm using VC++ 6.0 and MFC.  I've tried overriding OnLButtonUp on the dialog (actually its a formview), but apparently the message never leaves the button.  How can I let the formview know the button "stole" the focus so I can reset the focus back to a different control?
0
Comment
Question by:dpt081598
  • 3
  • 2
  • 2
7 Comments
 
LVL 22

Expert Comment

by:nietod
ID: 1179606
You need to handle the OnLButtonUp for the button window, not the dialog window.
0
 

Author Comment

by:dpt081598
ID: 1179607
Does that mean I have to derive a new CButton?
0
 
LVL 22

Expert Comment

by:nietod
ID: 1179608
I don't use MFC but I suspect that is probably the best way to handle it.  I think there are also other places to make the the "hook", but I suspect this would be best.
0
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

 

Author Comment

by:dpt081598
ID: 1179609
I've derived a new CButton and I've been able to handle the OnLButtonUp within my new object.  I'm not sure of the best way to handle this, so I'm sending a user defined message to the parent window.  The message isn't reaching the message handler in my view.  Any ideas?
0
 
LVL 22

Expert Comment

by:nietod
ID: 1179610
Can you post your code?
0
 
LVL 8

Expert Comment

by:Answers2000
ID: 1179611
Re: the above - if the keyboard is used to activate the button you won't get an OnLButtonUp message

Why not set the button to BS_NOTIFY style.  That way the containing view/dialogs gets notifications for a variety of button events, including everything you need (e.g. when button gains focus, is clicked etc.)

Additionally with MFC, the button notifications are reflected to the button iteself.  

Remember, if you use the reflection, to use ON_CONTROL_REFLECT_EX if you want the containing dialog/view to also receive the notification messages also
0
 
LVL 8

Accepted Solution

by:
Answers2000 earned 50 total points
ID: 1179612
Re: the above - if the keyboard is used to activate the button you won't get an OnLButtonUp message

Why not set the button to BS_NOTIFY style.  That way the containing view/dialogs gets notifications for a variety of button events, including everything you need
(e.g. when button gains focus, is clicked etc.)

Additionally with MFC, the button notifications are reflected to the button iteself.  

Remember, if you use the reflection, to use ON_CONTROL_REFLECT_EX if you want the containing dialog/view to also receive the notification messages also
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying 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

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…
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…
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.

856 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