Q1 CButton without focus 
Author Message
 Q1 CButton without focus

Is it possible to have a CButton object which does not focus when
pressed, I mean that the handlers for the buttons are called just the
same, I'm not speaking about DISABLED.  I am speaking about the user,
clicking on it (running the handler) but not having that 'windows
rectangle' on it, which shows its the last thing presses.

Clear enough ?


Sent via Deja.com http://www.*-*-*.com/
Before you buy.

Mon, 01 Jul 2002 03:00:00 GMT  
 Q1 CButton without focus
How about handling the WM_SETFOCUS (OnSetFocus) and changing the focus back to
the window that just lost it?

Mon, 01 Jul 2002 03:00:00 GMT  
 Q1 CButton without focus
NOte that you can't really do this in the straightforward manner you
would expect, for example,

void CMyButton::OnSetFocus(CWnd * oldwnd)
    SetFocus(oldwnd); // your app dies here!

doesn't work because you can't change focus on the OnSetFocus handler.
Furthermore, if you did change the focus, you couldn't click it at
all. Instead, subclass the button, and do the following

void CMyButton::OnSetFocus(CWnd * oldwnd)
     savedFocus = oldwnd;

void CMyButton::ResetFocus()

void CMyDialog::OnButtonClicked()
    //.. do button thing

Now, this is almost what you want. If you tab into the button, you'll
get the focus rect painted, and while you're clicking the mouse,
you'll get the focus rect. If this is also unacceptable, you'll need
to do ownerdraw, and just not draw the focus rect. Note that if you
tab into the control, it will still HAVE the focus (that is, typeing
space bar will click the button), but the user won't know the button
has focus. You might also consider removing the WS_TABSTOP style, but
then your app can only be used via the mouse since there is no way to
get to the control via the keyboard.


On Thu, 13 Jan 2000 15:42:22 -0600, Scot T Brennecke


>How about handling the WM_SETFOCUS (OnSetFocus) and changing the focus back to
>the window that just lost it?

Joseph M. Newcomer [MVP]

Web: http://www3.pgh.net/~newcomer
MVP Tips: http://www3.pgh.net/~newcomer/mvp_tips.htm

Mon, 01 Jul 2002 03:00:00 GMT  
 [ 3 post ] 

 Relevant Pages 

1. CButton that does not gain focus?

2. Detecting keypress when the focus is on CButton

3. CButton: focus and default

4. Show a form without focus

5. Using a Control Without Setting Focus

6. Send keys without focus

7. How to write in a windows without focus

8. Changing/Retrieving the focus for child windows without a mouse in MFC

9. Creating MDI child windows without focus

10. how to edit custom list-control items without having the window focused

11. launching an EXE from my program, BUT without focus changes

12. Using a Control Without Setting Focus


Powered by phpBB® Forum Software