Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Knowing when a button is highlighted (but not clicked)

Posted on 1998-12-08
7
Medium Priority
?
272 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
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!

 

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 100 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: 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

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
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 difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
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.
Suggested Courses

926 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