Solved

Knowing when a button is highlighted (but not clicked)

Posted on 1998-12-08
7
217 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
Comment Utility
You need to handle the OnLButtonUp for the button window, not the dialog window.
0
 

Author Comment

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

Expert Comment

by:nietod
Comment Utility
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Author Comment

by:dpt081598
Comment Utility
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
Comment Utility
Can you post your code?
0
 
LVL 8

Expert Comment

by:Answers2000
Comment Utility
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
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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…
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 clear a vector as well as how to detect empty vectors in C++.

763 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

10 Experts available now in Live!

Get 1:1 Help Now