May 07, 2024, 10:06:19 AM

News:

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


SetControlNotify behaviour in a Dialog vs a Window

Started by Jim Scott, March 24, 2007, 01:55:34 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Jim Scott

I've got a dialog in my code that has a bunch of edit controls, buttons, and drop-down combo controls.  The layout of the dialog is roughly as shown below;

[Done Button]

[Edit Control 1]     [Button 1]     [Drop-Down 1]
[Edit Control 2]     [Button 2]     [Drop-Down 2]
.
.
.
[Edit Control 20]   [Button 20]   [Drop-Down 20]

I'm trying to make it so that when my user presses the Enter key Focus goes on to the next Edit Control and when the Tab is pressed focus goes from left to right, then down and then left to right.  The tabbing portion works with my dialog without doing anything special. I'm having problems with the Enter key however.

Here's a single edit control and single button dialog that illustrates my problem;

CONST BUTTON_1 = 1
CONST EDIT_2 = 2
DIALOG d1
CREATEDIALOG d1,0,0,300,202,0x80C80080,0,"Caption",&d1_handler
CONTROL d1,@BUTTON,"Button1",30,15,70,20,0x50000000,BUTTON_1
CONTROL d1,@EDIT,"Edit1",30,59,70,20,0x50800000,EDIT_2

OpenConsole
doModal d1
SUB d1_handler
SELECT @MESSAGE
CASE @IDINITDIALOG
CENTERWINDOW d1
SETCONTROLNOTIFY(d1,Edit_2,1,1)
/* Initialize any controls here */
CASE @IDCLOSEWINDOW
CLOSEDIALOG d1,@IDOK
CASE @IDCONTROL
SELECT @CONTROLID
CASE BUTTON_1
IF @NOTIFYCODE = 0
Print "Button Pressed"
ENDIF
CASE EDIT_2
Print "NotifyCode = ", @NotifyCode
                SELECT @NOTIFYCODE
                    CASE @ENENTERKEY
                        MESSAGEBOX d1,GetControlText(d1,Edit_2),"Enter Pressed!"
                        SetFocus d1,Edit_2
                    CASE @ENTABKEY
                        MESSAGEBOX d1,"Tab key pressed","Info"
                        SetFocus d1,Edit_2
                ENDSELECT
ENDSELECT
ENDSELECT
RETURN
ENDSUB



When I do the same thing with a Window, instead of a Dialog, I can capture the Enter key and make it do what I want.  I just can't seem to capture the Enter key with this dialog.  Any suggestions?
Jim Scott

GJ

Hi Jim,

I use a default button, and then use a routine to determine which control has focus ( sure there are better ways ), and hope
someone else is posting the right code, so i can improve my progs  ;D

CONST BUTTON_1 = 1
CONST EDIT_2 = 2
CONST EDIT_3 = 3

int INFOCUS
DIALOG d1
CREATEDIALOG d1,0,0,300,202,0x80C80080,0,"Caption",&d1_handler
CONTROL d1,@BUTTON,"Button1",30,15,70,20,0x50000000,BUTTON_1
CONTROL d1,@EDIT,"Edit1",30,59,70,20,0x50800000,EDIT_2
CONTROL d1,@EDIT,"Edit2",30,99,70,20,0x50800000,EDIT_3

CONTROL d1,@SYSButton,"Button2",870, 19,31,18,0x40080001,999: 'default button invisible
OpenConsole
doModal d1
SUB d1_handler
SELECT @MESSAGE
CASE @IDINITDIALOG
CENTERWINDOW d1
SETCONTROLNOTIFY(d1,Edit_2,1,1)
/* Initialize any controls here */
CASE @IDCLOSEWINDOW
CLOSEDIALOG d1,@IDOK

CASE @IDCONTROL

     IF @CONTROLID = 999
     ' dummy button om enter toets af te vangen 
        IF GETKEYSTATE(13) <> 0 
          SELECT infocus
             CASE 2 
              SETFOCUS d1,EDIT_3 
             CASE 3
              SETFOCUS d1,EDIT_2 
          ENDSELECT 
        ENDIF 
     endif

SELECT @CONTROLID

CASE BUTTON_1
           infocus=1
IF @NOTIFYCODE = 0
Print "Button Pressed"
ENDIF
CASE EDIT_2
            infocus=2
Print "NotifyCode = ", @NotifyCode
                SELECT @NOTIFYCODE
                    CASE @ENENTERKEY
                        MESSAGEBOX d1,GetControlText(d1,Edit_2),"Enter Pressed!"
                        SetFocus d1,Edit_2
                    CASE @ENTABKEY
                        MESSAGEBOX d1,"Tab key pressed","Info"
                        SetFocus d1,Edit_2
                ENDSELECT
CASE EDIT_3
            infocus=3
Print "NotifyCode = ", @NotifyCode
                SELECT @NOTIFYCODE
                    CASE @ENENTERKEY
                        MESSAGEBOX d1,GetControlText(d1,Edit_2),"Enter Pressed!"
                        SetFocus d1,Edit_3
                    CASE @ENTABKEY
                        MESSAGEBOX d1,"Tab key pressed","Info"
                        SetFocus d1,Edit_3
                ENDSELECT

ENDSELECT
ENDSELECT
RETURN
ENDSUB



Gertjan (GJ)

Jim Scott

That seems to work, Thanks.  I'd still like to know why mine doesn't work as written.  It would teach me a little about the differences between Dialogs and Windows me thinks.  I'm still learning.   Maybe I need to sign up at Ionic Wind U.

Good little trick you figured out.  Thanks again.

Jim Scott
Jim Scott

SnarlingSheep

I don't believe that dialogs pass on the enter or escape key messages, instead they go right to the default button/window close messages.

Allan

Use WM_NEXTDLGCTL   with the SENDMESSAGE function

Jim Scott

Here's a way to do it without creating an invisible default button.  I don't know that it's better than your way (which I thought was very cleaver), but it is just another way.  I haven't yet tried Allan's suggestion.

CONST BUTTON_1 = 100
CONST EDIT_1 = 1
CONST EDIT_2 = 2

int INFOCUS
DIALOG d1
CREATEDIALOG d1,0,0,300,202,0x80C80080,0,"Caption",&d1_handler
CONTROL d1,@BUTTON,"Button1",30,15,70,20,0x50000000,BUTTON_1
CONTROL d1,@EDIT,"Edit1",30,59,70,20,0x50800000,EDIT_1
CONTROL d1,@EDIT,"Edit2",30,99,70,20,0x50800000,EDIT_2

OpenConsole
doModal d1
SUB d1_handler
SELECT @MESSAGE
CASE @IDINITDIALOG
CENTERWINDOW d1
InFocus = 1
CASE @IDCLOSEWINDOW
CLOSEDIALOG d1,@IDOK
CASE @IDCONTROL
If @NOTIFYCODE = 0 and @CONTROLID < 3 Then
Print "ControlId = 999"
@ControlId = 999
EndIf
SELECT @CONTROLID
Case 999
InFocus = InFocus + 1
If InFocus > 2 Then InFocus = 1
SetFocus(d1,InFocus)
CASE BUTTON_1
IF @NOTIFYCODE = 0
Print "Button Pressed"
ENDIF
CASE EDIT_1
InFocus = 1
Print "Edit 2 Has Focus"
CASE EDIT_2
InFocus = 2
Print "Edit 3 Has Focus"
ENDSELECT
ENDSELECT
RETURN
ENDSUB


Jim Scott
Jim Scott

Allan

Search the Win32API Help file for NEXTDLGCTL and one of the entries shows 3 methods of using the ENTER key to go to next Control.

1. By COMMAND as you are doing
2. SubClassing
3. Superclassing

SetFocus seems the simplest to use in BASIC. 

Jim Scott

Thanks Allan,

These are the sorts of things I hope to learn at Ionic Wind University.  I'm still uncomfortable with SubClassing, and haven't yet heard of SuperClassing.  Still so much to learn.  Paul's got his work cut out for himself.  So many students at very different levels of education.  Let's wish him well, and help him help us, eh?

Jim Scott
Jim Scott

Allan

Hi Jim

Subclassing looks hard but once you understand it  then it is no harder than the other things you learn.
There are just so many varieties of ways to learn and use it.

Yeah, Paul is lucky with such an opportunity. When you get up in years those opportunities seem to disappear and you end up having to work for yourself. Not as good as a regular pay check.

I learnt much from Paul with IBPro, which I still use, and am sure you will get a lot from the training he is offering.

Best of luck
Allan

JoaoAfonso

Good evening.
There must be other way to do it... If in spite of ENTER or TAB key, I want to check any other key (in a dialog, I mean)?
I remember doing something one day, using hook commands, but I guess it can exist a "cleaner" way of doing it.
Thanks in advance
JoÃÆ'ƒÂÃ,£o Afonso
Viriato
-----------------
Iberia MUD
www.iberiamud.com
iberiamud.com:5900