Solved

Knowing when a button is highlighted (but not clicked)

Posted on 1998-12-08
7
233 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
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 

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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

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…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
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.

776 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