Announcement

Collapse
No announcement yet.

SetFocus/KillFocus

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

  • SetFocus/KillFocus

    This works as I expect. After running the app, clicking on another window changes the caption to "Lost Focus". Then, clicking on this app the caption changes to "Got Focus"

    Code:
    #Include "Win32API.inc"
    Global hDlg As Dword
    Function PBMain() As Long
       Dialog New Pixels, 0, "PowerBASIC",300,300,400,50, %WS_OverlappedWindow To hDlg
    '   Control add graphic, hDlg, 500,"",0,0,200,50
    '   Control add Button, hDlg, 600, "Push", 0,0,50,30
    '   Control Add TextBox, hDlg, 700, "Text", 0,0,100,30      
       Dialog Show Modal hDlg Call DlgProc
    End Function
    CallBack Function DlgProc() As Long
       Select Case Cb.Msg
          Case %WM_SetFocus  : Dialog Set Text hDlg, "Got Focus"
          Case %WM_KillFocus : Dialog Set Text hDlg, "Lost Focus"
       End Select
    End Function
    But when I uncomment any of the controls (Text, Button, Graphic) in the code, WM_SetFocus and WM_KillFocus are not received by the Dialog. Is that what should happen?

  • #2
    WM_SETFOCUS message is sent to a window after it has gained the keyboard focus.

    If there is a control on the dialog that can accept keyboard focus, the message is sent to the Message Proc for that control (not to DlgProc).
    You can see that if you subclass the control.
    Rgds, Dave

    Comment


    • #3
      You may like to do something like this instead
      '
      Code:
      FUNCTION PBMAIN() AS LONG
         LOCAL hDLg AS DWORD
         DIALOG NEW PIXELS, 0, "PowerBASIC",300,300,400,50, %WS_OVERLAPPEDWINDOW TO hDlg
         CONTROL ADD GRAPHIC, hDlg, 500,"",0,0,200,50
         CONTROL ADD BUTTON, hDlg, 600, "Push", 0,0,50,30
         CONTROL ADD TEXTBOX, hDlg, 700, "Text", 0,0,100,30
         DIALOG SHOW MODAL hDlg CALL DlgProc
      END FUNCTION
      CALLBACK FUNCTION DlgProc() AS LONG
         SELECT CASE CB.MSG
            CASE %WM_NCACTIVATE
                IF CB.WPARAM = 0 THEN '
                    DIALOG SET TEXT CB.HNDL, "Lost Focus"
                ELSE
                    DIALOG SET TEXT CB.HNDL, "Got Focus"
                END IF
         END SELECT
      END FUNCTION
      '

      Comment


      • #4
        PBForms Template code..
        Code:
            Case %WM_NCActivate
              Static hWndSaveFocus As Dword
              If IsFalse CB.wParam Then
                hWndSaveFocus = GetFocus()
              ElseIf hWndSaveFocus Then
                SetFocus(hWndSaveFocus)
                hWndSaveFocus = 0
              End If
        Rgds, Dave

        Comment


        • #5
          Howdy, Stuart and Dave!

          Thanks! WM_NCActivate does the trick.

          Code:
          Case %WM_NCActivate
             Dialog Set Text hDlg, "EZfree  v" + $Ver + IIf$(Cb.WParam=0,"","    +++++++++++++++")
          My EZFree low vision users cannot see well enough to tell that the app caption is "grayed" out. So having something else in the caption (long string of letters) might suffice for them to know if the app is available for using app-specific keyboard shortcuts.

          Better yet would be for EZFree to also change one of its large icons to indicate that the app is active. Yep, I think I like that idea and will incorporate both in my next release.

          Comment

          Working...
          X