May 05, 2024, 07:45:34 PM

News:

IonicWind Snippit Manager 2.xx Released!  Install it on a memory stick and take it with you!  With or without IWBasic!


SETFOCUS won't set

Started by Jerry Muelver, February 26, 2008, 06:31:11 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Jerry Muelver

February 26, 2008, 06:31:11 AM Last Edit: February 26, 2008, 06:32:42 AM by Jerry Muelver
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?

Haim

Two controls with the same ID ??

Jerry Muelver

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.

Ionic Wind Support Team

Somewhere in the deep recesses of MSDN I seem to remember that Windows sets focus to the first control in the list.
Ionic Wind Support Team

Jerry Muelver

February 26, 2008, 09:07:51 AM #4 Last Edit: February 26, 2008, 09:49:08 AM by Jerry Muelver
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.  ::)

Ionic Wind Support Team

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.
Ionic Wind Support Team