Solved

Knowing when a button is highlighted (but not clicked)

Posted on 1998-12-08
7
225 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
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…

920 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now