Re: Setfocus / killfocus on cbutton
On 2 Dez., 18:49, Joseph M. Newcomer <newco...@flounder.com> wrote:
Not sure I really understand the question.
Yes, it is possible to change the focus from one button to another, using=
APIs to move to
the next tab item in the dialog, for example. This is the API that the TA=
B key calls to
change the focus.
It is normal for a mouse click to move the focus. In fact, I'm not sur=
e how it is
possible to defeat this. What are you basing your assertion on? If =
you are relying on
the state you see as the result of your OnDrawItem code, then you have th=
e question about
whether or not you are actually drawing the right thing, which is a diffe=
rent question
than whether or not you have changed the focus. If you change the focu=
s, the button
should redraw, so your drawitem handler should be called once for the but=
ton you just left
and once for the button you just moved into (assuming both are your owner=
-draw buttons). I
love owner-draw buttons, and not once have I had a problem with this.
Unfortunately, your question does not make it clear if the focus changes =
or not, or if the
*image* of focus is drawn properly. Example: having clicked the button=
with the mouse,
try hitting the space bar. If the button you just clicked into activat=
es again, then
indeed it has the focus; if it doesn't look like it has the focus, your d=
rawing code is
wrong. OTOH, if you hit the space bar and the PREVIOUS button activate=
s, then IT had the
focus, and your drawing code is correct, but focus in fact did not change=
.. You will need
to indicate which of these actually occurs before we can begin to guess w=
hat might be
happening.
thanks for your answer. Unfortunately I was very unclear with my
question: and I missed an important point which I`ve figured out now.
I`ve one class derrived from Cbutton which is called CImageTextButton.
This class has the DrawItems method installed and so on. Moreover I`ve
another class derrived from this class (CImageTextButton) which is
called CSpinCtrlButton. I`ve installed this class for all buttons
which change the cstatic fields.
In this class is only a OnLButtonDown() handler installed. All
CSpinCtrlButtons will increase / decrease the values of the cstatic
fields; the CImageTextButton will open further dialogs when they get
hit by the mouse or by the spacebar. Therefore I made another subclass
from my imagebuttonclass. And in this situation the focus will be only
properly set if I add a SetFocus() call in the OnLButtonDown() method.
My CImageTextButton class didn`t have any OnLButtonDown() method
installed.
class CSpinCtrlButton :
public CImageTextButton
{
public:
CSpinCtrlButton(void);
virtual ~CSpinCtrlButton(void);
enum ChangeValue
{
DECREASE = 0, //erniedrigen
INCREASE = 1, //erh=F6hen
};
void SetValues(CImageStatic *pStatField, BOOL change, UINT min, UINT
max);
protected:
CImageStatic *m_pField; //static field which is affected by the
spinbuttons
UINT m_Min; //min value of the cstatic field
UINT m_Max; //max value of the cstatic field
BOOL m_Change; //increase/decrease value
BOOL m_BtnSpinCtrlMode;
protected:
virtual BOOL PreTranslateMessage(MSG* pMsg);
afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
DECLARE_MESSAGE_MAP()
};
best regards
Hans