Re: Setfocus / killfocus on cbutton
On 3 Dez., 20:35, Joseph M. Newcomer <newco...@flounder.com> wrote:
See below...
On Fri, 3 Dec 2010 08:33:52 -0800 (PST), mfc <mfcp...@googlemail.com> wro=
te:
On 3 Dez., 16:58, Joseph M. Newcomer <newco...@flounder.com> wrote:
Generally, I don't worry about adding OnClick handlers; most of them h=
ave the body
updateControls();
and updateControls understands how to deal with all kinds of factors, =
including
enable/disable, show/hide, interactions with other controls, etc., so =
there is no
complexity at all; updateControls() will simply do whatever is correct=
, each time, all the
time.
joe
On Fri, 3 Dec 2010 07:41:32 -0800 (PST), mfc <mfcp...@googlemail.com> =
wrote:
On 2 Dez., 23:50, Joseph M. Newcomer <newco...@flounder.com> wrote:
I once had this problem with disabling radio buttons. What you have=
to do is consider one
of two approaches: in the OnBnClickedBntPatvalueR rourinte, ask if =
the control you are
about to disable has the focus, and if it does, GetNextDlgTabItem a=
nd SetFocus to it;
alternatively, the disable handler in the button moves the focus to=
the next control.
joe
On Thu, 2 Dec 2010 11:17:48 -0800 (PST), mfc <mfcp...@googlemail.co=
m> wrote:
the second question is: if I have a CImageButton button with this
onclick-handler:
void CPortPage::OnBnClickedBtnPatvalueR()
{
m_Btn.EnableWindow(FALSE);
}
If I click on this button (with the mouse or with the spacebar) th=
e
button will be disabled, but no other button in my dialog will get=
the
focus. So I`m no longer able to jump from one button to the next
button by using the TAB key....
Which method can I use to acchieve this?
Joseph M. Newcomer [MVP]
email: newco...@flounder.com
Web:http://www.flounder.com
MVP Tips:http://www.flounder.com/mvp_tips.htm
Thank you for the hint with GetNextDlgTabItem() - it`s working.
According to the cbutton classes; I think the best would be to
integrate the spincontrol-button mode in the Cimagetextbutton class
and add a small method where I can activate or not activate the
spincontrol mode.
If you have many buttons installed on your dialog ("<<" and ">>" whic=
h
increase/decrease the value of a specific cstatic field), each button
will need a OnButtonClick eventhandler (and these buttons do not have
identical names).
Is there a better solution instead of adding all these onclick
eventhandlers in the dialog class? Maybe is it possible to add the
OnClick-handler of these buttons to the specific button-class of thes=
e
buttons? Or is this a bad design?
best regards
Hans
Joseph M. Newcomer [MVP]
email: newco...@flounder.com
Web:http://www.flounder.com
MVP Tips:http://www.flounder.com/mvp_tips.htm-Zitierten Text ausblende=
n -
- Zitierten Text anzeigen -
and how is this updatecontrols method called if a user clicks on a
button? Or do you call the updatecontrol method from the
onbuttonclick-handler?
****
I said I don't worry about adding OnClick handlers. I didn't say I did=
n't add them, only
that adding them doesn't bother me in the slightest, because all they do =
is call
updateControls(). Note that if you are ever going to enable/disable or=
show/hide
controls, you must do it from only ONE function, which is solely responsi=
ble for all
enabling/disabling showing/hiding. This is the only way to make it man=
ageable. I came up
with this solution after a client sent me a first-order disaster (back in=
the early 90s)
in which there were 23 locations that had code to enable/disable show/hid=
e controls, using
six different algorithms. I consolidated it into one place (the code w=
as truly
unmaintainable!)
If I got the slightest bit concerned about the number of handlers, I migh=
t set all my
buttons into a single range of numbers and add a single ON_CONTROL_RANGE =
handler, but that
takes more work than I care for. But the only thing the ON_CONTROL_RAN=
GE handler would do
would be to call updateControls(). See my essay on dialog control managem=
ent on my MVP
Tips site.
joe
Joseph M. Newcomer [MVP]
email: newco...@flounder.com
Web:http://www.flounder.com
MVP Tips:http://www.flounder.com/mvp_tips.htm- Zitierten Text ausblenden =
-
- Zitierten Text anzeigen -
Alright now I understand your approach. I`ve installed one public
method in my cbutton class (SetParams) which gets all required
specific values in the OnInitDialog().
m_MyButtonL.SetParams(&m_StatCtrl, CImageTextButton::DECREASE,
minvalue, maxvalue);
m_MyButtonR.SetParams(&m_StatCtrl, CImageTextButton::INCREASE,
minvalue, maxvalue);
These two buttons will increase/decrease the value of a specifc
cstatic field (in this example - m_StatCtrl ). Minvalue / maxvalue
will be either a static definition (located in a specific header file)
or the start / end number of a CString in the string table.
Dependent from the value of the cstatic field, it is possible that
some other controls in the dialog should be disable/enabled. For
example if you click on button1, UpdateControls() for button1 will be
called where I change the value of the specific cstatic field. Now
according to this change, it could be possible that for example
button2 and button3 should be disabled.
Is there a better solution than this:
1) including all depending button controls to this call in the
OnInitDialog() (sometimes up to six other controls affected by the
spcific button)
m_Button1.SetParams(&m_StatCtrl, CImageTextButton::INCREASE, minvalue,
maxvalue, &m_Button2, &m_Button3);
How can I add these controls to one member-variable of the button
class? - using a clist (m_list.Add(m_Button2) and so on.... ?
2) check in the m_Button1.UpdateControl() if other controls are
depended from this button and call their UpdateControls() methods??
void CImageButton::UpdateControls()
{
//change the value of the specific cstatic field
//check if other controls affected by this control - if so call
their Updatecontrol() method
Invalidate();
}
3) in the end of their UpdateControls() method call Invalidate() to
draw these buttons again
best regards
Hans