IonicWind Software

IWBasic => GUI Central => Topic started by: Jerry Muelver on February 26, 2008, 06:31:11 AM

Title: SETFOCUS won't set
Post by: Jerry Muelver on February 26, 2008, 06:31:11 AM
Here's the definition:
CREATEDIALOG d1,0,0,408,100,0x80C80080,0,"Create New Page",&d1_handler
CONTROL d1,@STATIC,"Name for new page:",10,4,220,19,0x5000010B,1
CONTROL d1,@EDIT,"",12,24,377,21,0x50800000,2
CONTROL d1,@SYSBUTTON,"Create new page",33,60,141,22,0x50000001,3
CONTROL d1,@SYSBUTTON,"Cancel",179,60,141,22,0x50000000,4

Here's the SUB called from a menu choice, the handler for the dialog:

SUB doNewPageDialog
DEF show AS INT
if d1<>0 then return
show = DOMODAL d1,win
RETURN
ENDSUB

SUB d1_handler
SELECT @MESSAGE
    CASE @IDCONTROL
        SELECT @CONTROLID
            CASE 3
                seltext = GETCONTROLTEXT(d1,2)
                CLOSEDIALOG d1,@IDOK
    CASE 4
seltext = ""
CLOSEDIALOG d1
        ENDSELECT
    CASE @IDINITDIALOG
        CENTERWINDOW d1
SETFOCUS d1,2
ENDSELECT
RETURN
ENDSUB

Problem is, focus does not get set. When the dialog pops up, you have to move the cursor into the edit control by yourself, before you can type anything in the control. What am I missing?
Title: Re: SETFOCUS won't set
Post by: Haim on February 26, 2008, 07:09:24 AM
Two controls with the same ID ??
Title: Re: SETFOCUS won't set
Post by: Jerry Muelver on February 26, 2008, 07:11:48 AM
OTOH, going to SHOWDIALOG instead, with the SETFOCUS coming after the dialog is shown, seems to work:

SUB doNewPageDialog
DEF show AS INT
if d1<>0 then return
SHOWDIALOG d1,win
SETFOCUS d1,2
RETURN
ENDSUB

Thanks to Alyce for the suggestion.
Title: Re: SETFOCUS won't set
Post by: Ionic Wind Support Team on February 26, 2008, 08:53:45 AM
Somewhere in the deep recesses of MSDN I seem to remember that Windows sets focus to the first control in the list.
Title: Re: SETFOCUS won't set
Post by: Jerry Muelver on February 26, 2008, 09:07:51 AM
Thanks, Paul. That's worth experimenting....  ;)

(Edit) Yup. that seems to be the deal. Changed the editbox to #1 on the dialog, and moved it up to the first control created in the CREATEDIALOG declaration, and I get focus on the editbox when I show the dialog. Don't need no steenkin' SETFOCUS, even.  ::)
Title: Re: SETFOCUS won't set
Post by: Ionic Wind Support Team on February 26, 2008, 09:26:42 PM
That was easy.  Much easier than explaining why it works the way it does in Emergence.  Technically you are allowed to set focus to your own control, but only if you return FALSE from the dialogs handling of WM_INITDALOG.   

Since I didn't want to force people to set focus to a control for every dialog created the code returns TRUE reguardless of your handlers return value.  I may change that in the future to automatically determine if you have used SETFOCUS during the processing of @IDINITDIALOG and allow the internal handler to return FALSE.

Paul.