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?
Two controls with the same ID ??
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.
Somewhere in the deep recesses of MSDN I seem to remember that Windows sets focus to the first control in the list.
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. ::)
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.