Announcement

Collapse
No announcement yet.

How to set button focus rectangle

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

  • How to set button focus rectangle

    Up till now "Control Set Focus hdlg,ctrlid" used with a button doesn't mark the button with the dashed rectangle that you get if you use the arrow keys to move to the button.

    With a dialog with two buttons and I want the button last in the tab order to have the dashed rectangle I just issue a key_bd event %VK_RIGHT. To make the first button have the rectangle I issue a key_bd %VK_RIGHT and then a d key_bd %VK_LEFT. This, I'm finding out works 98% of the time. The other times neither button has the dashed rectangle.

    Is there another way to get the button to show with the dashed rectangle indicating it has the focus?

    Bob Mechler

  • #2
    DrawFocusRect?
    Michael Mattias
    Tal Systems (retired)
    Port Washington WI USA
    [email protected]
    http://www.talsystems.com

    Comment


    • #3
      DrawFocusRect sounds like what I want.

      The following works but isn't quite as obvious.

      CONTROL SEND errdlg&,3,%BM_SETSTYLE,%BS_DEFPUSHBUTTON,0
      CONTROL SET FOCUS errdlg&, 3

      BOB MECHLER

      Comment


      • #4
        MSDN: WM_UPDATEUISTATE

        Sample usage (only available Windows 2000 or later):

        Code:
        #PBFORMS CREATED V1.51
        '-----------------------------------------------------------------------------------------------------------------
        ' The first line in this file is a PB/Forms metastatement.
        ' It should ALWAYS be the first line of the file. Other
        ' PB/Forms metastatements are placed at the beginning and
        ' end of "Named Blocks" of code that should be edited
        ' with PBForms only. Do not manually edit or delete these
        ' metastatements or PB/Forms will not be able to reread
        ' the file correctly.  See the PB/Forms documentation for
        ' more information.
        ' Named blocks begin like this:    #PBFORMS BEGIN ...
        ' Named blocks end like this:      #PBFORMS END ...
        ' Other PB/Forms metastatements such as:
        '     #PBFORMS DECLARATIONS
        ' are used by PB/Forms to insert additional code.
        ' Feel free to make changes anywhere else in the file.
        '-----------------------------------------------------------------------------------------------------------------
        
        #COMPILE EXE
        #DIM ALL
        
        '-----------------------------------------------------------------------------------------------------------------
        '   ** Includes **
        '-----------------------------------------------------------------------------------------------------------------
        #PBFORMS BEGIN INCLUDES
        #IF NOT %DEF(%WINAPI)
            #INCLUDE "WIN32API.INC"
        #ENDIF
        #PBFORMS END INCLUDES
        '-----------------------------------------------------------------------------------------------------------------
        
        '-----------------------------------------------------------------------------------------------------------------
        '   ** Constants **
        '-----------------------------------------------------------------------------------------------------------------
        #PBFORMS BEGIN CONSTANTS
        %IDD_DIALOG1 =  101
        %IDC_BUTTON1 = 1001
        %IDC_BUTTON2 = 1002
        #PBFORMS END CONSTANTS
        '-----------------------------------------------------------------------------------------------------------------
        
        '-----------------------------------------------------------------------------------------------------------------
        '   ** Declarations **
        '-----------------------------------------------------------------------------------------------------------------
        DECLARE CALLBACK FUNCTION ShowDIALOG1Proc()
        DECLARE FUNCTION ShowDIALOG1(BYVAL hParent AS DWORD) AS LONG
        #PBFORMS DECLARATIONS
        '-----------------------------------------------------------------------------------------------------------------
        DECLARE FUNCTION IsWin2K() AS LONG
        '-----------------------------------------------------------------------------------------------------------------
        '   ** Main Application Entry Point **
        '-----------------------------------------------------------------------------------------------------------------
        FUNCTION PBMAIN()
            ShowDIALOG1 %HWND_DESKTOP
        END FUNCTION
        '-----------------------------------------------------------------------------------------------------------------
        
        '-----------------------------------------------------------------------------------------------------------------
        '   ** CallBacks **
        '-----------------------------------------------------------------------------------------------------------------
        CALLBACK FUNCTION ShowDIALOG1Proc()
        
            SELECT CASE AS LONG CBMSG
                CASE %WM_INITDIALOG
                    ' Initialization handler
        
                CASE %WM_NCACTIVATE
                    STATIC hWndSaveFocus AS DWORD
                    IF ISFALSE CBWPARAM THEN
                        ' Save control focus
                        hWndSaveFocus = GetFocus()
                    ELSEIF hWndSaveFocus THEN
                        ' Restore control focus
                        SetFocus(hWndSaveFocus)
                        hWndSaveFocus = 0
                    END IF
        
                CASE %WM_COMMAND
                    ' Process control notifications
                    SELECT CASE AS LONG CBCTL
                        CASE %IDC_BUTTON1
                            IF CBCTLMSG = %BN_CLICKED OR CBCTLMSG = 1 THEN
                                MSGBOX "%IDC_BUTTON1=" + FORMAT$(%IDC_BUTTON1), %MB_TASKMODAL
                            END IF
        
                        CASE %IDC_BUTTON2
                            IF CBCTLMSG = %BN_CLICKED OR CBCTLMSG = 1 THEN
                                MSGBOX "%IDC_BUTTON2=" + FORMAT$(%IDC_BUTTON2), %MB_TASKMODAL
                            END IF
        
                    END SELECT
            END SELECT
        END FUNCTION
        '-----------------------------------------------------------------------------------------------------------------
        
        '-----------------------------------------------------------------------------------------------------------------
        '   ** Dialogs **
        '-----------------------------------------------------------------------------------------------------------------
        FUNCTION ShowDIALOG1(BYVAL hParent AS DWORD) AS LONG
            LOCAL lRslt AS LONG
            LOCAL Win2KOrLater AS LONG
        
        #PBFORMS BEGIN DIALOG %IDD_DIALOG1->->
            LOCAL hDlg  AS DWORD
        
            DIALOG NEW hParent, "Dialog1", 70, 70, 201, 121, TO hDlg
            CONTROL ADD BUTTON, hDlg, %IDC_BUTTON1, "Button1", 5, 5, 50, 15
            CONTROL ADD BUTTON, hDlg, %IDC_BUTTON2, "Button2", 5, 20, 50, 15
        #PBFORMS END DIALOG
        
            Win2KOrLater = IsWin2K()
            
            IF Win2KOrLater THEN
                CONTROL SEND hDlg, %IDC_BUTTON1, %WM_UPDATEUISTATE, MAK(LONG, %UIS_CLEAR, %UISF_HIDEFOCUS), 0
                CONTROL SEND hDlg, %IDC_BUTTON2, %WM_UPDATEUISTATE, MAK(LONG, %UIS_CLEAR, %UISF_HIDEFOCUS), 0
            END IF
        
            DIALOG SHOW MODAL hDlg, CALL ShowDIALOG1Proc TO lRslt
        
        #PBFORMS BEGIN CLEANUP %IDD_DIALOG1
        #PBFORMS END CLEANUP
        
            FUNCTION = lRslt
        END FUNCTION
        '-----------------------------------------------------------------------------------------------------------------
        FUNCTION IsWin2K() AS LONG
        
            LOCAL vi AS OSVERSIONINFO
        
            vi.dwOsVersionInfoSize = SIZEOF(vi)
            GetVersionEx vi
        
            FUNCTION = ((vi.dwPlatformId = %VER_PLATFORM_WIN32_NT) AND (vi.dwMajorVersion >= 5))
        
        END FUNCTION
        '-----------------------------------------------------------------------------------------------------------------
        Adam Drake
        PowerBASIC

        Comment


        • #5
          Slight correction at MAKLNG but it is what I was looking for. Thanks.

          Code:
                        CONTROL SEND errdlg&,3, %WM_UPDATEUISTATE, MAKLNG( %UIS_CLEAR, %UISF_HIDEFOCUS), 0
          Bob Mechler

          Comment


          • #6
            If you have PBWIN8/CC4 or later, that is the new syntax.
            Adam Drake
            PowerBASIC

            Comment


            • #7
              Understood, I was using 7.04.

              Bob Mechler

              Comment


              • #8
                I'll be sure to clarify the version next time I post something that uses newer syntax...
                Adam Drake
                PowerBASIC

                Comment

                Working...
                X