Announcement

Collapse
No announcement yet.

DDT engine and WM_SETFOCUS..

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • DDT engine and WM_SETFOCUS..

    In DDT, when dialog loses and then gains focus again, focus seems
    to be set to default button no matter how we do. Wrote a sample
    to show problem. Focus is set to textbox on startup. Switch to
    another program and back again, textbox has lost focus to button.
    Trying to intercept dialog's WM_SETFOCUS has no effect. This only
    happens in DDT, not if dialog is created SDK way. What's up, and
    how can it be "fixed"?

    I know one can use %BM_SETSTYLE and %BS_DEFPUSHBUTTON to change
    default button, but how can one set another type of control to be
    "default" - in DDT, since the engine seems to override %WM_SETFOCUS
    calls in dialog Callback and do stuff after it's handled?

    Code:
    '¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
    #COMPILE EXE
    #INCLUDE "WIN32API.INC"
    DECLARE CALLBACK FUNCTION DlgProc() AS LONG
     
    '¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
    ' Main callback
    '¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
    CALLBACK FUNCTION DlgProc() AS LONG
      SELECT CASE CBMSG
         CASE %WM_INITDIALOG
            SetFocus GetDlgItem(CBHNDL, 20) '<- This works fine
     
         CASE %WM_COMMAND
            IF CBCTL = 11 THEN DIALOG END CBHNDL, 1 '<- Exit
     
         CASE %WM_SETFOCUS
            SetFocus GetDlgItem(CBHNDL, 20) '<- This don't, in DDT
     
      END SELECT
     
    END FUNCTION
     
    '¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
    ' Create dialog and controls, etc
    '¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
    FUNCTION PBMAIN () AS LONG
      LOCAL hDlg AS LONG
     
      DIALOG NEW 0, "Focus test ",,, 130, 106, %WS_SYSMENU, 0 TO hDlg
      CONTROL ADD BUTTON, hDlg,  10, "Ok",      10, 10,  50, 14
      CONTROL ADD BUTTON, hDlg,  11,  "E&xit",  60, 10,  50, 14
      CONTROL ADD TEXTBOX, hDlg, 20, "",        0,  30, 126, 60, _
                           %ES_WANTRETURN OR %ES_MULTILINE, %WS_EX_CLIENTEDGE
     
      DIALOG SHOW MODAL hDlg CALL DlgProc
    END FUNCTION
    ------------------


    [This message has been edited by Borje Hagsten (edited January 09, 2001).]

  • #2
    Borje,

    I have a 'simple' way to do this. I insert a couple lines

    to check if the widow is in foreground. If it isn't, it sets

    a flag: "NotForeGround". The next time it checks and the

    dialog is foreground it sets focus to desired control and

    resets the flag: "NotForeGround"...

    Here are the API & CONTROL's...

    GLOBAL HandleNumber as long
    GLOBAL NotForeGround AS LONG
    GLOBAL WindowName AS ASCIIZ * 10
    GLOBAL WIndowNumber AS LONG

    At start of program, before main DO/LOOP:

    WindowName = "MyProgram"
    WindowNumber = FindWindow("",WindowName)

    Then in the main DO/LOOP stick this in:

    Code:
      '
      '
      HandleNumber = GetForeGroundWindow
      If HandleNumber = WindowNumber THEN
        IF NotForeGround THEN CONTROL SET FOCUS hDLG, %CONTROL
      ELSE
        NotForeGround = 0
      END IF
      '
      '
    Thanks,

    P.

    ------------------

    Comment


    • #3
      Borje --
      If I understood you correctly, you want to reset focus, when your form receives focus.
      If so, you should redirect focus in WM_NCACTIVATE.
      Code:
         #Compile Exe
         #Register None
         #Include "WIN32API.INC"
      
         CallBack Function DlgProc() As Long
            Select Case CbMsg
               Case %WM_COMMAND: If CbCtl = 11 Then Dialog End CbHndl, 1
               Case %WM_NCACTIVATE: SetFocus GetDlgItem(CbHndl, 20)
            End Select
         End Function
      
         Function PbMain () As Long
            Local hDlg As Long
            Dialog New 0, "Focus test ",,, 130, 106, %WS_SYSMENU, 0 To hDlg
            Control Add Button, hDlg, 10, "Ok", 10, 10, 50, 14
            Control Add Button, hDlg, 11, "E&xit", 60, 10, 50, 14
            Control Add TextBox, hDlg, 20, "", 0, 30, 126, 60, %ES_WANTRETURN Or %ES_MULTILINE, %WS_EX_CLIENTEDGE
            Dialog Show Modal hDlg Call DlgProc
         End Function
      [This message has been edited by Semen Matusovski (edited January 09, 2001).]

      Comment


      • #4
        Thank you, fellows. Pat Rick, you tip has been added to my drawers
        for future needs. Very useful for modeless DDT dialogs - thanks
        a lot! Semen's tip is better for modal dialogs, though.

        Semen, you are genious, as usual. Forgot about %WM_NCACTIVATE.
        Following fixes problem:
        Code:
             CASE %WM_NCACTIVATE
                IF CBWPARAM THEN SetFocus GetDlgItem(CBHNDL, 20) '<- This works

        ------------------

        Comment

        Working...
        X