Announcement

Collapse
No announcement yet.

Button focus rectangle

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

  • Button focus rectangle

    When creating a modal dialog and setting focus to the desired button, either Yes or No, some machines don't also put the focus rectangle as a dotted line around the button caption. From an earlier post I gather that if I want to make sure the focus rectangle shows on a classic button, I'll need the following code. Just want to verify or be corrected.
    Pb 7.04
    Code:
              CONTROL SET FOCUS YesNoMsgBox&, 3
              CONTROL SEND YesNoMsgBox&, 3, %WM_UPDATEUISTATE, MAKLNG( %UIS_CLEAR, %UISF_HIDEFOCUS), 0
    Bob Mechler

  • #2
    can you post compilable example?

    Sometimes its just a matter of the order of the events fired, and 1 firing before the other, but will not happen until you click, and by then you cant see it
    Engineer's Motto: If it aint broke take it apart and fix it

    "If at 1st you don't succeed... call it version 1.0"

    "Half of Programming is coding"....."The other 90% is DEBUGGING"

    "Document my code????" .... "WHYYY??? do you think they call it CODE? "

    Comment


    • #3
      some machines don't also put the focus rectangle as a dotted line around the button caption
      Win2k and above. Optional settiing:
      Display Properties/Appearance/Effects - "Hide underlined letters for keyboard navigation until I press the Alt key".

      On by default, this setting also affects the appearance of focus cues.

      The setting is overcome by %WM_UPDATEUISTATE - 'MAKLNG( %UIS_CLEAR, %UISF_HIDEACCEL Or %UISF_HIDEFOCUS )' param turns Off both the 'hide keyboard accelerators' and 'hide focus' styles.
      Rgds, Dave

      Comment


      • #4
        Dave,

        Thanks for the confirmation and the additional parameter for button keyboard accelerators.

        Bob Mechler

        Comment


        • #5
          The setting is overcome by %WM_UPDATEUISTATE - 'MAKLNG( %UIS_CLEAR, %UISF_HIDEACCEL Or %UISF_HIDEFOCUS )' param turns Off both the 'hide keyboard accelerators' and 'hide focus' styles
          Now that is a very interesting and potentially quite useful little info nugget.
          Michael Mattias
          Tal Systems (retired)
          Port Washington WI USA
          [email protected]
          http://www.talsystems.com

          Comment


          • #6
            Bob, Dave,

            I checked the box "Hide underlined letters for keyboard navigation until I press the alt-key"
            but nothing seems to change? The box stays checked after running my program below?
            Code:
                DEFLNG A-Z
                FUNCTION WINMAIN (BYVAL hCurInstance  AS LONG, _
                                  BYVAL hPrevInstance AS LONG, _
                                  BYVAL lpszCmdLine   AS ASCIIZ PTR, _
                                  BYVAL nCmdShow      AS LONG) EXPORT AS LONG
                                  LOCAL Day AS STRING
                 Day = PARSE$(DayofTheWeek,1)'ADDED TO GET DAY OF WEEK
            
                 opersy = TRIM$(OSversion())   ' returns strOS
                 '? "opersy= "+opersy ' shows "VISTA" 7-11-2007 ON LAPTOP, shows "XP" on Dell 1-1-'
                 '2009
                 IF opersy = "XP" OR opersy = "ME" OR opersy = "NT 3.51" _
                    OR opersy = "NT 4.0" OR opersy = "2000" OR opersy = "2003" THEN
                  ' From Forum - Bob Melcher
                  ' Win2k and above. Optional settiing:
                  ' Display Properties/Appearance/Effects - "Hide underlined letters for keyboard 
                  ' navigation
                  ' until I press the Alt key".
                  ' On by default, this setting also affects the appearance of focus cues.
                  ' The setting is overcome by %WM_UPDATEUISTATE - 
                  'MAKLNG( %UIS_CLEAR, %UISF_HIDEACCEL Or %UISF_HIDEFOCUS )
                  ' param turns Off both the 'hide keyboard accelerators' and 'hide focus' styles.
                  '__________________
                  'Rgds, Dave
            
                  YesNoMsgBox& = MSGBOX("Press [Alt] key to un-hide underlined letters for keyboard"+$CRLF+$CRLF _
                  +"navigation.", %MB_YESNO OR %MB_TASKMODAL, "Used with My Address Programs")
                  CONTROL SET FOCUS YesNoMsgBox&, 3
                  CONTROL SEND YesNoMsgBox&, 3, %WM_UPDATEUISTATE, MAKLNG( %UIS_CLEAR, %UISF_HIDEFOCUS OR %UISF_HIDEFOCUS), 0
                 END IF
                 END FUNCTION
            What am I doing wrong?
            Last edited by BRENT GARDNER; 1 Jan 2009, 01:32 PM.

            Comment


            • #7
              deleted
              Last edited by Gösta H. Lovgren-2; 1 Jan 2009, 08:54 PM. Reason: no longer relevant
              It's a pretty day. I hope you enjoy it.

              Gösta

              JWAM: (Quit Smoking): http://www.SwedesDock.com/smoking
              LDN - A Miracle Drug: http://www.SwedesDock.com/LDN/

              Comment


              • #8
                Brent,

                I couldn't get your code to compile. Also the code snippet I posted was from a modal dialog built to function as a generic special look messagebox.

                YesNoMsgbx& is the handle to the dialog. I don't think this method would work with a standard MSGBOX since MSGBOX doesn't return the handle but the response of which button was clicked.

                Below is a little more of the code, at least the context. It takes the global V_YNDEF and defines which should be the default button with focus and a focus rectangle. For this post, I didn't think the subclassing code and the callback procedure were needed. You could test it by taking it out of the SUB
                and setting V_YNDEF& as 1 to get 'Yes' as the default or V_YNDEF& = 2 to get 'No' as the default.
                V_YNMSG$ is just the text string to break up and place in the recessed label.
                ALT_ERMSG_DEPTH can be set if messagebox doesn't look good enough.
                CUST_ERMSG_DEPTH is another possible setting.
                V_YNSIZ just establishes a minimum width for the recessed message label
                MAC_WINPOS is just a macro I wrote to always center the message box in the center of the parent window even if the parent is on a second monitor.

                In the subclass code (not shown) I trap the return key, Alt Y and Alt N and do further processing. By doing this, the user can't by accident press a key that may not be what they wanted. The default key is always the harmless or highly preferred choice.

                I also disable the parent window until the message box is dealt with. If the messagebox is minimized, I hide the parent window and restore it when the messagebox is returned to normal. I do this in case the message is something requiring our attention and the customer wants to go on and do something else.

                Code:
                      SUB YesNoMsgbx
                        DIM hOld AS DWORD
                
                        ALT_ERMSG_DEPTH = 0
                        ERMSG_DEPTH = (LEN(V_YNMSG$) / 35) * 10 + 10
                        IF ERMSG_DEPTH < 10 THEN ERMSG_DEPTH = 10
                        IF INSTR(V_YNMSG$,CHR$(10)) > 0 THEN
                          ALT_ERMSG_DEPTH = PARSECOUNT(V_YNMSG$,$LF) * 8
                        END IF
                        IF ALT_ERMSG_DEPTH > ERMSG_DEPTH THEN
                          ERMSG_DEPTH = ALT_ERMSG_DEPTH
                        END IF
                        IF CUST_ERMSG_DEPTH > 0 THEN
                          ERMSG_DEPTH = CUST_ERMSG_DEPTH
                          CUST_ERMSG_DEPTH = 0 'reset
                        END IF
                        IF V_YNSIZ < 150 THEN V_YNSIZ = 150
                        DIALOG DISABLE hdlg
                        DIALOG NEW 0,"User option",,,V_YNSIZ ,ERMSG_DEPTH + 50, %WS_SYSMENU,0 TO YesNoMsgBox&
                        MAC_WINPOS(YesNoMsgBox&)
                        CONTROL ADD LABEL,YesNoMsgBox&,10,V_YNMSG$,10,10,V_YNSIZ - 20,ERMSG_DEPTH,%SS_CENTER,%WS_EX_LEFT OR %WS_EX_STATICEDGE
                        CONTROL SEND YesNoMsgBox&, 10, %WM_SETFONT, hFontText, %True
                        IF V_YNDEF = 1 THEN
                          CONTROL ADD BUTTON,YesNoMsgBox&,2,"&Yes",V_YNSIZ/2 - 50,ERMSG_DEPTH + 13,40,14,%BS_CENTER OR %BS_VCENTER,%WS_EX_LEFT
                          hOld = SetWindowLong(GetDlgItem(YesNoMsgBox&,2), %GWL_WNDPROC, CODEPTR(SCYesNo)) ' sub-classing the control here
                          CONTROL SET USER    YesNoMsgBox&, 2, 8, hOld                                          ' original handle for killing SC'd control
                          CONTROL ADD BUTTON,YesNoMsgBox&,3,"&No",V_YNSIZ/2 + 10,ERMSG_DEPTH + 13,40,14,%BS_CENTER OR %BS_VCENTER,%WS_EX_LEFT
                          hOld = SetWindowLong(GetDlgItem(YesNoMsgBox&,3), %GWL_WNDPROC, CODEPTR(SCYesNo)) ' sub-classing the control here
                          CONTROL SET USER    YesNoMsgBox&, 3, 8, hOld                                          ' original handle for killing SC'd control
                          CONTROL SEND YesNoMsgBox&, 2, %WM_SETFONT, hFontText, %True
                          CONTROL SEND YesNoMsgBox&, 3, %WM_SETFONT, hFontText, %True
                          [b]CONTROL SET FOCUS YesNoMsgBox&, 2
                          CONTROL SEND YesNoMsgBox&, 2, %WM_UPDATEUISTATE, MAKLNG( %UIS_CLEAR, %UISF_HIDEFOCUS), 0[/b]
                        ELSEIF V_YNDEF = 2 THEN
                          CONTROL ADD BUTTON,YesNoMsgBox&,2,"&Yes",V_YNSIZ/2 - 50,ERMSG_DEPTH + 13,40,14,%BS_CENTER OR %BS_VCENTER,%WS_EX_LEFT
                          hOld = SetWindowLong(GetDlgItem(YesNoMsgBox&,2), %GWL_WNDPROC, CODEPTR(SCYesNo)) ' sub-classing the control here
                          CONTROL SET USER    YesNoMsgBox&, 2, 8, hOld                                          ' original handle for killing SC'd control
                          CONTROL ADD BUTTON,YesNoMsgBox&,3,"&No",V_YNSIZ/2 + 10,ERMSG_DEPTH + 13,40,14,%BS_CENTER OR %BS_VCENTER,%WS_EX_LEFT
                          hOld = SetWindowLong(GetDlgItem(YesNoMsgBox&,3), %GWL_WNDPROC, CODEPTR(SCYesNo)) ' sub-classing the control here
                          CONTROL SET USER    YesNoMsgBox&, 3, 8, hOld                                          ' original handle for killing SC'd control
                          CONTROL SEND YesNoMsgBox&, 2, %WM_SETFONT, hFontText, %True
                          CONTROL SEND YesNoMsgBox&, 3, %WM_SETFONT, hFontText, %True
                          [b]CONTROL SET FOCUS YesNoMsgBox&, 3
                          CONTROL SEND YesNoMsgBox&, 3, %WM_UPDATEUISTATE, MAKLNG( %UIS_CLEAR, %UISF_HIDEFOCUS), 0[/b]
                        END IF
                        DIALOG SHOW MODAL YesNoMsgBox&  CALL YesNoMsgbxproc
                        SetForeGroundWindow hdlg
                        V_YNSIZ = 150
                        DIALOG ENABLE hdlg
                      END SUB
                Last edited by BOB MECHLER; 1 Jan 2009, 06:06 PM. Reason: More info

                Comment


                • #9
                  Brent,
                  I checked the box "Hide underlined letters for keyboard navigation until I press the alt-key"
                  but nothing seems to change?
                  An application sends the WM_UPDATEUISTATE message to change the user interface (UI) state for the specified window and all its child windows.
                  It doesn't change the system wide setting - I'm sure that could be done by a different API function, but wouldn't be very polite
                  Rgds, Dave

                  Comment


                  • #10
                    Dave Biggs,

                    Good point! Didn't think that far ahead.

                    Bob,

                    In my main dialog that starts my program, just before the call to the callback, I inserted the following
                    code:
                    Code:
                          REM DIALOG DISABLE hDlg
                          CONTROL SET FOCUS hDlg, 3 
                          CONTROL SEND hDlg, 3, %WM_UPDATEUISTATE, MAKLNG( %UIS_CLEAR, %UISF_HIDEACCEL OR %UISF_HIDEFOCUS), 0
                          CONTROL SET FOCUS hDlg, 4 
                          CONTROL SEND hDlg, 4, %WM_UPDATEUISTATE, MAKLNG( %UIS_CLEAR, %UISF_HIDEACCEL OR %UISF_HIDEFOCUS), 0
                          CONTROL SET FOCUS hDlg, 5 
                          CONTROL SEND hDlg, 5, %WM_UPDATEUISTATE, MAKLNG( %UIS_CLEAR, %UISF_HIDEACCEL OR %UISF_HIDEFOCUS), 0
                          CONTROL SET FOCUS hDlg, 6 
                          CONTROL SEND hDlg, 6, %WM_UPDATEUISTATE, MAKLNG( %UIS_CLEAR, %UISF_HIDEACCEL OR %UISF_HIDEFOCUS), 0
                          CONTROL SET FOCUS hDlg, 7 
                          CONTROL SEND hDlg, 7, %WM_UPDATEUISTATE, MAKLNG( %UIS_CLEAR, %UISF_HIDEACCEL OR %UISF_HIDEFOCUS), 0
                          REM DIALOG ENABLE hDlg
                    
                     ' Start up our GUI, and run until the user quits
                         DIALOG SHOW MODAL hDlg, CALL AddressCallBack TO Result
                    It works for the buttons above, but I have some 25 buttons, do I need to do this for each one? Or is
                    there a better way?

                    Thanks!

                    Comment


                    • #11
                      Brent,

                      It's not required to first set focus on a control for %WM_UPDATEUISTATE to work.
                      Also you can apply it to the whole dialog (and all it's child controls), either just before DIALOG SHOW.. or in %WM_INITDIALOG.
                      Here's a quick sample dialog.
                      Code:
                      #PBForms Created V1.51
                      #Compile Exe
                      #Dim All
                       
                      #PBForms Begin Includes 
                      #If Not %Def(%WINAPI)
                        #Include "WIN32API.INC"
                      #EndIf
                      #PBForms End Includes
                       
                      #PBForms Begin Constants 
                      %IDD_DIALOG1 =  101
                      %BTN_BUTTON1 = 1001
                      %BTN_BUTTON2 = 1002
                      %BTN_BUTTON3 = 1003
                      %BTN_BUTTON4 = 1004
                      %BTN_BUTTON5 = 1005
                      %BTN_BUTTON6 = 1006
                      %BTN_BUTTON7 = 1007
                      %BTN_CuesOn  = 1008
                      %BTN_CuesOff = 1009
                      %BTN_Focus   = 1010
                      #PBForms End Constants
                       
                      Declare CallBack Function ShowDIALOG1Proc()
                      Declare Function ShowDIALOG1(ByVal hParent As Dword) As Long
                      #PBForms Declarations
                       
                      Function PBMain()
                        ShowDIALOG1 %HWND_DESKTOP
                      End Function
                       
                      CallBack Function ShowDIALOG1Proc()
                       
                        Select Case As Long CbMsg
                          Case %WM_INITDIALOG
                            Dialog Send CbHndl, %WM_CHANGEUISTATE, MakLng(%UIS_CLEAR, %UISF_HIDEFOCUS Or %UISF_HIDEACCEL), 0
                            Control Set Focus CbHndl, %BTN_CuesOff
                       
                          Case %WM_NCACTIVATE
                            Static hWndSaveFocus As Dword
                            If IsFalse CbWParam Then
                              hWndSaveFocus = GetFocus()
                            ElseIf hWndSaveFocus Then
                              SetFocus(hWndSaveFocus)
                              hWndSaveFocus = 0
                            End If
                       
                          Case %WM_COMMAND
                            Select Case As Long CbCtl
                              Case %BTN_BUTTON1
                                If CbCtlMsg = %BN_CLICKED Or CbCtlMsg = 1 Then
                                  MsgBox "%BTN_BUTTON1=" + Format$(%BTN_BUTTON1), %MB_TASKMODAL
                                End If
                       
                              Case %BTN_BUTTON2
                                If CbCtlMsg = %BN_CLICKED Or CbCtlMsg = 1 Then
                                  MsgBox "%BTN_BUTTON2=" + Format$(%BTN_BUTTON2), %MB_TASKMODAL
                                End If
                       
                              Case %BTN_BUTTON3
                                If CbCtlMsg = %BN_CLICKED Or CbCtlMsg = 1 Then
                                  MsgBox "%BTN_BUTTON3=" + Format$(%BTN_BUTTON3), %MB_TASKMODAL
                                End If
                       
                              Case %BTN_BUTTON4
                                If CbCtlMsg = %BN_CLICKED Or CbCtlMsg = 1 Then
                                  MsgBox "%BTN_BUTTON4=" + Format$(%BTN_BUTTON4), %MB_TASKMODAL
                                End If
                       
                              Case %BTN_BUTTON5
                                If CbCtlMsg = %BN_CLICKED Or CbCtlMsg = 1 Then
                                  MsgBox "%BTN_BUTTON5=" + Format$(%BTN_BUTTON5), %MB_TASKMODAL
                                End If
                       
                              Case %BTN_BUTTON6
                                If CbCtlMsg = %BN_CLICKED Or CbCtlMsg = 1 Then
                                  MsgBox "%BTN_BUTTON6=" + Format$(%BTN_BUTTON6), %MB_TASKMODAL
                                End If
                       
                              Case %BTN_BUTTON7
                                If CbCtlMsg = %BN_CLICKED Or CbCtlMsg = 1 Then
                                  MsgBox "%BTN_BUTTON7=" + Format$(%BTN_BUTTON7), %MB_TASKMODAL
                                End If
                       
                              Case %BTN_CuesOn
                                If CbCtlMsg = %BN_CLICKED Or CbCtlMsg = 1 Then
                                  Dialog Send CbHndl, %WM_CHANGEUISTATE, MakLng(%UIS_CLEAR, %UISF_HIDEFOCUS Or %UISF_HIDEACCEL), 0
                                  Dialog ReDraw CbHndl
                                End If 
                       
                              Case %BTN_CuesOff
                                If CbCtlMsg = %BN_CLICKED Or CbCtlMsg = 1 Then
                                  Dialog Send CbHndl, %WM_CHANGEUISTATE, MakLng(%UIS_SET, %UISF_HIDEFOCUS Or %UISF_HIDEACCEL), 0
                                  Dialog ReDraw CbHndl
                                End If 
                       
                              Case %BTN_Focus
                                If CbCtlMsg = %BN_CLICKED Or CbCtlMsg = 1 Then
                                  Control Set Focus CbHndl, %BTN_Button1 + Rnd(0, 6)
                                End If          
                       
                            End Select
                        End Select
                      End Function
                       
                      Function ShowDIALOG1(ByVal hParent As Dword) As Long
                        Local lRslt As Long
                       
                      #PBForms Begin Dialog %IDD_DIALOG1->->
                        Local hDlg  As Dword
                       
                        Dialog New hParent, "Fun with Focus", 233, 200, 201, 121, %WS_POPUP Or %WS_BORDER Or %WS_DLGFRAME Or _
                          %WS_CAPTION Or %WS_SYSMENU Or %WS_CLIPSIBLINGS Or %WS_VISIBLE Or %DS_MODALFRAME Or %DS_CENTER Or _
                          %DS_3DLOOK Or %DS_NOFAILCREATE Or %DS_SETFONT, %WS_EX_CONTROLPARENT Or %WS_EX_LEFT Or _
                          %WS_EX_LTRREADING Or %WS_EX_RIGHTSCROLLBAR, To hDlg
                        Control Add Button, hDlg, %BTN_BUTTON1, "Button&1", 5, 5, 50, 15
                        Control Add Button, hDlg, %BTN_BUTTON2, "Button&2", 5, 20, 50, 15
                        Control Add Button, hDlg, %BTN_BUTTON3, "Button&3", 5, 35, 50, 15
                        Control Add Button, hDlg, %BTN_BUTTON4, "Button&4", 5, 50, 50, 15
                        Control Add Button, hDlg, %BTN_BUTTON5, "Button&5", 5, 65, 50, 15
                        Control Add Button, hDlg, %BTN_BUTTON6, "Button&6", 5, 80, 50, 15
                        Control Add Button, hDlg, %BTN_BUTTON7, "Button&7", 5, 95, 50, 15
                        Control Add Button, hDlg, %BTN_CuesOn, "Cues O&n", 110, 15, 50, 15
                        Control Add Button, hDlg, %BTN_CuesOff, "Cues Of&f", 110, 50, 50, 15
                        Control Add Button, hDlg, %BTN_Focus, "&ShiftFocus", 110, 85, 50, 15
                      #PBForms End Dialog
                       
                        Dialog Show Modal hDlg, Call ShowDIALOG1Proc To lRslt
                       
                      #PBForms Begin CleanUp %IDD_DIALOG1
                      #PBForms End CleanUp
                       
                        Function = lRslt
                      End Function
                      Last edited by Dave Biggs; 2 Jan 2009, 10:40 AM.
                      Rgds, Dave

                      Comment


                      • #12
                        Dave,

                        Thanks for continuing to make additional points. I can now place this command in my WM_INITDIALOG and have it affect all the child controls from what you are saying. Big timesaver.

                        Thanks,

                        Bob Mechler

                        Comment


                        • #13
                          Dave,

                          Great information - Thanks! Now all I have to do is add below under the
                          CASE %WM_INITDIALOG and all buttons are as they should be if the box at
                          rgt-clk desktop > properties > appearance > effects "Hide underlined letters
                          for keyboard navigation until I press the Alt-key" was unchecked.
                          Code:
                             CASE %WM_INITDIALOG
                             
                             IF opersy = "XP" OR opersy = "ME" OR opersy = "NT 3.51" _
                                   OR opersy = "NT 4.0" OR opersy = "2000" OR opersy = "2003" THEN
                                 DIALOG SEND CBHNDL, %WM_CHANGEUISTATE, _
                                  MAKLNG(%UIS_CLEAR, %UISF_HIDEFOCUS OR %UISF_HIDEACCEL), 0
                                  DIALOG REDRAW CBHNDL
                             END IF
                          Many Thanks,

                          Brent

                          Comment


                          • #14
                            Are the Dialog redraws required? They tend to make the dialog flicker don't they?

                            Bob Mechler

                            Comment


                            • #15
                              In my program, it does not seem to matter if I use the redraw or not.

                              Forgot in Vista how to find the checkbox that says "Hide underlined letters
                              for keyboard navigation until I press the Alt-Key"? In XP: right click on
                              desktop > properties > appearance > effects.

                              Anyone know how to manually change in Vista?

                              Comment


                              • #16
                                Dialog Redraws aren't really required - I was experimenting as I noticed that the dotted rectangle indicating focus remained visible when using the hot key to operate the CuesOff button. This code is better..
                                Code:
                                        Case %BTN_CuesOff
                                          If CbCtlMsg = %BN_CLICKED Or CbCtlMsg = 1 Then
                                            Dialog Send CbHndl, %WM_UPDATEUISTATE, MakLng(%UIS_SET, %UISF_HIDEFOCUS Or %UISF_HIDEACCEL), 0
                                            Control Redraw CbHndl, GetDlgCtrlId(GetFocus)
                                          End If
                                Rgds, Dave

                                Comment


                                • #17
                                  I wanted to clean up some of the oddball behaviours that I was seeing In my test code which sometimes ended up with a missmatch between which Button had focus and which Button (if any) had a modifed (heavier) Border.
                                  That lead me to experiment with using %WM_NEXTDLGCTL instead of Set Focus. You might want to check it out as well.
                                  See this modified sample code.
                                  Code:
                                  #PBForms Created V1.51
                                  #Compile Exe
                                  #Dim All
                                   
                                  #PBForms Begin Includes 
                                  #If Not %Def(%WINAPI)
                                    #Include "WIN32API.INC"
                                  #EndIf
                                  #PBForms End Includes
                                  '#RESOURCE "XPTheme.pbr"
                                   
                                  #PBForms Begin Constants 
                                  %IDOK        =    1
                                  %IDD_DIALOG1 =  101
                                  %BTN_BUTTON1 = 1001
                                  %BTN_BUTTON2 = 1002
                                  %BTN_BUTTON3 = 1003
                                  %BTN_BUTTON4 = 1004
                                  %BTN_BUTTON5 = 1005
                                  %BTN_BUTTON6 = 1006
                                  %BTN_BUTTON7 = 1007
                                  %BTN_CuesOn  = 1008
                                  %BTN_CuesOff = 1009
                                  %BTN_Focus   = 1010
                                  #PBForms End Constants
                                   
                                  Declare CallBack Function ShowDIALOG1Proc()
                                  Declare Function ShowDIALOG1(ByVal hParent As Dword) As Long
                                  #PBForms Declarations
                                   
                                  Function PBMain()
                                    ShowDIALOG1 %HWND_DESKTOP
                                  End Function
                                   
                                  CallBack Function ShowDIALOG1Proc()
                                   
                                    Select Case As Long CbMsg
                                      Case %WM_INITDIALOG
                                        Dialog Send CbHndl, %WM_CHANGEUISTATE, MakLng(%UIS_CLEAR, %UISF_HIDEFOCUS Or %UISF_HIDEACCEL), 0
                                        Control Set Focus CbHndl, %BTN_CuesOff
                                   
                                      Case %WM_NCACTIVATE
                                        Static hWndSaveFocus As Dword
                                        If IsFalse CbWParam Then
                                          hWndSaveFocus = GetFocus()
                                        ElseIf hWndSaveFocus Then
                                          SetFocus(hWndSaveFocus)
                                          hWndSaveFocus = 0
                                        End If
                                   
                                      Case %WM_COMMAND
                                        Select Case As Long CbCtl
                                          Case %BTN_BUTTON1
                                            If CbCtlMsg = %BN_CLICKED Or CbCtlMsg = 1 Then
                                              MsgBox "%BTN_BUTTON1=" + Format$(%BTN_BUTTON1), %MB_TASKMODAL
                                            End If
                                   
                                          Case %BTN_BUTTON2
                                            If CbCtlMsg = %BN_CLICKED Or CbCtlMsg = 1 Then
                                              MsgBox "%BTN_BUTTON2=" + Format$(%BTN_BUTTON2), %MB_TASKMODAL
                                            End If
                                   
                                          Case %BTN_BUTTON3
                                            If CbCtlMsg = %BN_CLICKED Or CbCtlMsg = 1 Then
                                              MsgBox "%BTN_BUTTON3=" + Format$(%BTN_BUTTON3), %MB_TASKMODAL
                                            End If
                                   
                                          Case %BTN_BUTTON4
                                            If CbCtlMsg = %BN_CLICKED Or CbCtlMsg = 1 Then
                                              MsgBox "%BTN_BUTTON4=" + Format$(%BTN_BUTTON4), %MB_TASKMODAL
                                            End If
                                   
                                          Case %BTN_BUTTON5
                                            If CbCtlMsg = %BN_CLICKED Or CbCtlMsg = 1 Then
                                              MsgBox "%BTN_BUTTON5=" + Format$(%BTN_BUTTON5), %MB_TASKMODAL
                                            End If
                                   
                                          Case %BTN_BUTTON6
                                            If CbCtlMsg = %BN_CLICKED Or CbCtlMsg = 1 Then
                                              MsgBox "%BTN_BUTTON6=" + Format$(%BTN_BUTTON6), %MB_TASKMODAL
                                            End If
                                   
                                          Case %BTN_BUTTON7
                                            If CbCtlMsg = %BN_CLICKED Or CbCtlMsg = 1 Then
                                              MsgBox "%BTN_BUTTON7=" + Format$(%BTN_BUTTON7), %MB_TASKMODAL
                                            End If
                                   
                                          Case %IDOK
                                            If CbCtlMsg = %BN_CLICKED Or CbCtlMsg = 1 Then
                                              MsgBox "%IDOK=" + Format$(%IDOK), %MB_TASKMODAL
                                            End If
                                   
                                          Case %BTN_CuesOn
                                            If CbCtlMsg = %BN_CLICKED Or CbCtlMsg = 1 Then
                                              Dialog Send CbHndl, %WM_CHANGEUISTATE, MakLng(%UIS_CLEAR, %UISF_HIDEFOCUS Or %UISF_HIDEACCEL), 0
                                            End If 
                                   
                                          Case %BTN_CuesOff
                                            If CbCtlMsg = %BN_CLICKED Or CbCtlMsg = 1 Then
                                              Dialog Send CbHndl, %WM_CHANGEUISTATE, MakLng(%UIS_SET, %UISF_HIDEFOCUS Or %UISF_HIDEACCEL), 0
                                              Control ReDraw CbHndl, GetDlgCtrlId(GetFocus)
                                            End If 
                                   
                                          Case %BTN_Focus
                                            If CbCtlMsg = %BN_CLICKED Or CbCtlMsg = 1 Then
                                              SendMessage CbHndl, %WM_NEXTDLGCTL, GetDlgItem(CbHndl, %BTN_Button1 + Rnd(0, 6)), 1
                                            End If           
                                   
                                        End Select
                                    End Select
                                  End Function
                                   
                                  Function ShowDIALOG1(ByVal hParent As Dword) As Long
                                    Local lRslt As Long
                                   
                                  #PBForms Begin Dialog %IDD_DIALOG1->->
                                    Local hDlg  As Dword
                                    Dialog New hParent, "Fun with Focus", 233, 200, 201, 121, %WS_POPUP Or %WS_BORDER Or %WS_DLGFRAME Or _
                                      %WS_CAPTION Or %WS_SYSMENU Or %WS_CLIPSIBLINGS Or %WS_VISIBLE Or %DS_MODALFRAME Or %DS_CENTER Or _
                                      %DS_3DLOOK Or %DS_NOFAILCREATE Or %DS_SETFONT, %WS_EX_CONTROLPARENT Or %WS_EX_LEFT Or _
                                      %WS_EX_LTRREADING Or %WS_EX_RIGHTSCROLLBAR, To hDlg
                                    Control Add Button, hDlg, %BTN_BUTTON1, "Button&1", 5, 5, 50, 15
                                    Control Add Button, hDlg, %BTN_BUTTON2, "Button&2", 5, 20, 50, 15
                                    Control Add Button, hDlg, %BTN_BUTTON3, "Button&3", 5, 35, 50, 15
                                    Control Add Button, hDlg, %BTN_BUTTON4, "Button&4", 5, 50, 50, 15
                                    Control Add Button, hDlg, %BTN_BUTTON5, "Button&5", 5, 65, 50, 15
                                    Control Add Button, hDlg, %BTN_BUTTON6, "Button&6", 5, 80, 50, 15
                                    Control Add Button, hDlg, %BTN_BUTTON7, "Button&7", 5, 95, 50, 15
                                    Control Add Button, hDlg, %BTN_CuesOn, "Cues O&n", 110, 5, 50, 15
                                    Control Add Button, hDlg, %BTN_CuesOff, "Cues Of&f", 110, 35, 50, 15
                                    Control Add Button, hDlg, %BTN_Focus, "&ShiftFocus", 110, 65, 50, 15
                                    Control Add Button, hDlg, %IDOK, "OK", 110, 95, 50, 15, %WS_CHILD Or %WS_VISIBLE Or %WS_TABSTOP Or _
                                      %BS_TEXT Or %BS_DEFPUSHBUTTON Or %BS_PUSHBUTTON Or %BS_CENTER Or %BS_VCENTER, %WS_EX_LEFT Or _
                                      %WS_EX_LTRREADING
                                    Dialog  Send        hDlg, %DM_SETDEFID, %IDOK, 0
                                  #PBForms End Dialog
                                   
                                    Dialog Show Modal hDlg, Call ShowDIALOG1Proc To lRslt
                                   
                                  #PBForms Begin CleanUp %IDD_DIALOG1
                                  #PBForms End CleanUp
                                   
                                    Function = lRslt
                                  End Function
                                  Notes:
                                  %WM_NEXTDLGCTL gives the target Button %BS_DEFPUSHBUTTON Style (activated by both space Bar And Return key) - this may rob your Dialog of the default %IDOK response you expect.
                                  Tab / Arrow keys restore hiden focus cues but not keyboard cues.
                                  %UISF_ACTIVE doesn't seem to do anything for buttons (even when themed)?
                                  Rgds, Dave

                                  Comment


                                  • #18
                                    Strange? In Windows Vista, code does not seem to work?

                                    With Vista, is there a way to disable the "Hide underline letters for keyboard navigation until I press the Alt key" feature like you could with Windows XP?


                                    1. In Control Panel, Open the Ease of Access.
                                    2. Click "Make the Keyboard easier to use".
                                    3. Click "Make it easier to use keyboard shortcuts"
                                    4. Check box "Underline keyboard shortcuts and access
                                    keys".

                                    When box is checked, program keys work like expected, but if box is unchecked, your UPDATEIUSTATE OR CHANGEIUSTATE does not seem to work?

                                    Your code does work, but You must right click on your program icon on your desktop > properties > compatibility > check the box "Run this program in compatibility mode for Windows XP (service pack 2).
                                    Last edited by BRENT GARDNER; 3 Jan 2009, 11:17 AM.

                                    Comment


                                    • #19
                                      Brent,

                                      I don't have access to Vista so can't experiment but in XP it's similar.

                                      If the keyboard indicators (and focus cues) are already being displayed because the display properties > appearance > effects "Hide underlined letters for keyboard navigation until I press the Alt-key" is unchecked, the sample program will not hide them.

                                      Am I correct in undestanding that, in Vista, you need to use XP compatibility to get the sample to work when "Underline keyboard shortcuts and access keys" is checked?
                                      Rgds, Dave

                                      Comment


                                      • #20
                                        Dave,

                                        Sorry for not responding sooner, had other things to take care of. You said:

                                        "Am I correct in undestanding that, in Vista, you need to use XP compatibility to get the sample to work when "Underline keyboard shortcuts and access keys" is checked?"

                                        No, I think the default must be when box is UNCHECKED.
                                        Then you must run the sample in XP compatibility mode.

                                        With your expertise, is there a way to programically run sample in XP mode?

                                        Thanks,

                                        Brent
                                        Last edited by BRENT GARDNER; 5 Jan 2009, 06:47 AM.

                                        Comment

                                        Working...
                                        X