|
Prev: Good MFC Book
Next: accessing a library
From: Tom Sherren on 22 Apr 2008 18:21 Using Visual Studio 2003. In a dialog (CDialog), I want to initially disable the OK button until the user selects an item in a list box on that dialog. When an item is selected I want to enable the OK button and give it focus (so that the button has a bold outline showing that it has focus). What I get is: The OK button is initially disabled (greyed out). There is no initial selection in the list box. When a selection is made in the list box, the OK button is enabled but it does not visually seem to have focus. When a *second* selection is made in the list box, the OK button is given focus. I do the following: dialog data (set up using "Add Variable"): CListBox cListBox; CButton cOK; in OnInitDialog(): cOK.EnableWindow(FALSE): in OnLbnSelchangecListBox() -- when the list box selection changes: cOK.EnableWindow(TRUE); cOK.SetFocus(); What am I doing wrong? Thanks
From: David Ching on 22 Apr 2008 18:56 "Tom Sherren" <no.address(a)sorry.com.zzz> wrote in message news:fuloe4$16mh$1(a)si05.rsvl.unisys.com... > Using Visual Studio 2003. > > In a dialog (CDialog), I want to initially disable the OK button until the > user selects an item in a list box on that dialog. When an item is > selected I > want to enable the OK button and give it focus (so that the button has a > bold > outline showing that it has focus). > > What I get is: The OK button is initially disabled (greyed out). There > is no > initial selection in the list box. When a selection is made in the list > box, > the OK button is enabled but it does not visually seem to have focus. When > a > *second* selection is made in the list box, the OK button is given focus. > > I do the following: > > dialog data (set up using "Add Variable"): > > CListBox cListBox; > CButton cOK; > > in OnInitDialog(): > > cOK.EnableWindow(FALSE): > > in OnLbnSelchangecListBox() -- when the list box selection changes: > > cOK.EnableWindow(TRUE); > cOK.SetFocus(); > > What am I doing wrong? > I don't know, but FYI if the OK button is the default button, you don't need to set the focus to it in order for it to click when you press the Enter key. -- David
From: Joseph M. Newcomer on 22 Apr 2008 23:01 The change in focus is gratuitous. The <enter> key will work, so you don't need to change the focus, and users will find that changing the selection changing the focus will be VERY annoying...suppose I change the selection and want to change the selection again? Note that physically-handicapped users might change the selection by using the arrow keys, and this interface will be a complete and total disaster for them. Since there is no need to change the focus to the OK button, there is no need to do this at all. joe On Tue, 22 Apr 2008 22:21:56 GMT, no.address(a)sorry.com.zzz (Tom Sherren) wrote: >Using Visual Studio 2003. > >In a dialog (CDialog), I want to initially disable the OK button until the >user selects an item in a list box on that dialog. When an item is selected I >want to enable the OK button and give it focus (so that the button has a bold >outline showing that it has focus). > >What I get is: The OK button is initially disabled (greyed out). There is no >initial selection in the list box. When a selection is made in the list box, >the OK button is enabled but it does not visually seem to have focus. When a >*second* selection is made in the list box, the OK button is given focus. > >I do the following: > >dialog data (set up using "Add Variable"): > > CListBox cListBox; > CButton cOK; > >in OnInitDialog(): > > cOK.EnableWindow(FALSE): > >in OnLbnSelchangecListBox() -- when the list box selection changes: > > cOK.EnableWindow(TRUE); > cOK.SetFocus(); > >What am I doing wrong? > >Thanks > Joseph M. Newcomer [MVP] email: newcomer(a)flounder.com Web: http://www.flounder.com MVP Tips: http://www.flounder.com/mvp_tips.htm
From: Tom Sherren on 23 Apr 2008 16:18 In article <w2uPj.68$506.62(a)newssvr27.news.prodigy.net>, "David Ching" <dc(a)remove-this.dcsoft.com> wrote: >"Tom Sherren" <no.address(a)sorry.com.zzz> wrote in message >news:fuloe4$16mh$1(a)si05.rsvl.unisys.com... >> Using Visual Studio 2003. >> >> In a dialog (CDialog), I want to initially disable the OK button until the >> user selects an item in a list box on that dialog. When an item is >> selected I >> want to enable the OK button and give it focus (so that the button has a >> bold >> outline showing that it has focus). >> >> What I get is: The OK button is initially disabled (greyed out). There >> is no >> initial selection in the list box. When a selection is made in the list >> box, >> the OK button is enabled but it does not visually seem to have focus. When >> a >> *second* selection is made in the list box, the OK button is given focus. >> >> I do the following: >> >> dialog data (set up using "Add Variable"): >> >> CListBox cListBox; >> CButton cOK; >> >> in OnInitDialog(): >> >> cOK.EnableWindow(FALSE): >> >> in OnLbnSelchangecListBox() -- when the list box selection changes: >> >> cOK.EnableWindow(TRUE); >> cOK.SetFocus(); >> >> What am I doing wrong? >> > >I don't know, but FYI if the OK button is the default button, you don't need >to set the focus to it in order for it to click when you press the Enter >key. > >-- David > > Thanks. I checked and the OK button is indeed the default button. I would like the OK button to have the outside border that indicates the control has focus. Most dialogs work this way by default, but I started out disabling the control in OnInitDialog() and now I can't get the border to return on the first call to SetFocus(). On the second and subsequent calls the border appears. Tom
From: Tom Sherren on 23 Apr 2008 16:36
In article <sf9t04ha1gnho5oar79i1fq41ophqeo0fl(a)4ax.com>, Joseph M. Newcomer <newcomer(a)flounder.com> wrote: >The change in focus is gratuitous. The <enter> key will work, so you don't > need to change >the focus, and users will find that changing the selection changing the focus > will be VERY >annoying...suppose I change the selection and want to change the selection > again? Note >that physically-handicapped users might change the selection by using the arrow > keys, and >this interface will be a complete and total disaster for them. > >Since there is no need to change the focus to the OK button, there is no need > to do this >at all. > joe I see your point. If the user wanted to chage the selection, they would have to click the list box once just to give it focus. Tnx, Tom |