Announcement

Collapse
No announcement yet.

PBForms and dialog font selection

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

  • PBForms and dialog font selection

    In PBForms 1.51 it is possible to specify a dialog font. This then appears to serve as the default font for any controls added to the dialog. No problem.

    However, although the code generated includes (for example)
    Code:
        hFont1 = PBFormsMakeFont("Courier", 15, 700, %FALSE, %TRUE, %FALSE, %ANSI_CHARSET)
        DIALOG  SEND hDlg, %WM_SETFONT, hFont1, 0
    the font in the dialog title remains unchanged. I'm using the default styles, which include %DS_SETFONT. Is this correct?

  • #2
    The font used in the captions of top-level windows, dialogs and controls with the WS_CAPTION
    style is not set by the WM_SETFONT message. DS_SETFONT is used by the dialog box manager to
    create a logical font from the FONTINFOEX structure using CreateFontIndirect. The dialog box
    manager eventually sends a WM_SETFONT message to all controls on the dialog with the handle
    of the font they should use for painting.

    The caption font is a system setting. See the SystemParametersInfo(SPI_GETNONCLIENTMETRICS) function.
    However, form designers should not fool around with system settings such as caption, menu and statusbar fonts.
    Actually, they should not be changing system settings.
    Last edited by Dominic Mitchell; 30 Dec 2007, 08:36 PM.
    Dominic Mitchell
    Phoenix Visual Designer
    http://www.phnxthunder.com

    Comment


    • #3
      Originally posted by Dominic Mitchell View Post
      The font used in the captions of top-level windows, dialogs and controls with the WS_CAPTION
      style is not set by the WM_SETFONT message. .... The dialog box
      manager eventually sends a WM_SETFONT message to all controls on the dialog....
      Thanks for the explanation, Dominic. But do you mean that the WM_SETFONT message sent to the dialog is "cascaded" to the controls on that dialog? When is "eventually"? So what is the point of sending WM_SETFONT to the dialog?, as in this generated code:

      Code:
      #PBFORMS CREATED V1.51
      #COMPILE EXE
      #DIM ALL
      
      #PBFORMS BEGIN INCLUDES 
      #IF NOT %DEF(%WINAPI)
          #INCLUDE "WIN32API.INC"
      #ENDIF
      #INCLUDE "PBForms.INC"
      #PBFORMS END INCLUDES
      
      #PBFORMS BEGIN CONSTANTS 
      %IDD_DIALOG1  =  101
      %IDC_LABEL1   = 1001
      %IDC_LISTBOX1 = 1002
      #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
      
              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
      
                  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
          LOCAL hFont1 AS DWORD
      
          DIALOG NEW hParent, "Dialog1", 71, 85, 200, 267, %WS_POPUP OR %WS_BORDER OR %WS_DLGFRAME OR %WS_SYSMENU OR %WS_CLIPSIBLINGS _
              OR %WS_VISIBLE OR %DS_MODALFRAME 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 LABEL,   hDlg, %IDC_LABEL1, "Label1", 50, 20, 85, 20, %WS_CHILD OR %WS_VISIBLE OR %SS_LEFT OR %SS_NOTIFY OR _
              %SS_SUNKEN, %WS_EX_LEFT OR %WS_EX_LTRREADING
          CONTROL ADD LISTBOX, hDlg, %IDC_LISTBOX1, , 20, 65, 150, 160
      
          hFont1 = PBFormsMakeFont("MS Sans Serif", 18, 400, %FALSE, %FALSE, %FALSE, %ANSI_CHARSET)
      
          DIALOG  SEND hDlg, %WM_SETFONT, hFont1, 0
      #PBFORMS END DIALOG
      
          DIALOG SHOW MODAL hDlg, CALL ShowDIALOG1Proc TO lRslt
      
      #PBFORMS BEGIN CLEANUP %IDD_DIALOG1
          DeleteObject hFont1
      #PBFORMS END CLEANUP
      
          FUNCTION = lRslt
      END FUNCTION
      Originally posted by Dominic Mitchell View Post
      However, form designers should not fool around ....
      They just don't know when to leave it out do they?

      Comment


      • #4
        But do you mean that the WM_SETFONT message sent to the dialog is "cascaded" to the controls on that dialog?
        No.

        That is why this code, if it is generated by PBForms, is rather odd.
        Code:
            hFont1 = PBFormsMakeFont("MS Sans Serif", 18, 400, %FALSE, %FALSE, %FALSE, %ANSI_CHARSET)
        
            DIALOG  SEND hDlg, %WM_SETFONT, hFont1, 0
        When is "eventually"?
        After the dialog box manager creates all the controls defined in each DLGITEMTEMPLATE structure
        (DLGITEMTEMPLATEEX if DLGTEMPLATEEX was used), it creates the font and sends a WM_SETFONT message
        to each control.
        You can see this behaviour in action in DDT by doing this
        (Note the placement of the DIALOG FONT statement)
        Code:
            DIALOG FONT "Times New Roman", 18
            
            DIALOG NEW hParent, "Dialog1", 71, 85, 200, 267, %WS_POPUP OR %WS_BORDER OR %WS_DLGFRAME OR %WS_SYSMENU OR %WS_CLIPSIBLINGS _
                OR %WS_VISIBLE OR %DS_MODALFRAME OR %DS_3DLOOK OR %DS_NOFAILCREATE, %WS_EX_CONTROLPARENT OR %WS_EX_LEFT _
                OR %WS_EX_LTRREADING OR %WS_EX_RIGHTSCROLLBAR OR %DS_SETFONT, TO hDlg
        So what is the point of sending WM_SETFONT to the dialog?, as in this generated code:
        Beats the living daylights out of me. Sending WM_SETFONT to the dialog does nothing.
        You either have to send a WM_SETFONT message to each control on the dialog or use a
        DIALOG FONT statement before the DIALOG NEW statement. But the two are not equivalent.

        By the way, the dialog box manager uses the font to scale the dialog. Therefore, the DIALOG FONT
        statement causes any dialog created after it is used to be scaled.
        Dominic Mitchell
        Phoenix Visual Designer
        http://www.phnxthunder.com

        Comment


        • #5
          Thanks, Dominic.

          Using DIALOG FONT before DIALOG NEW appears to scale the controls & dialog client area to the new font size, which becomes the default font for the controls. The dialog title is not scaled.

          the PBForms help says:
          Code:
          Font Name and Font Size	
          The Font settings are adjusted through the FONT button on the Properties dialog,
          which brings up a standard font-selection dialog.  If the default font is not used, 
          PowerBASIC Forms automatically generates code to create the font chosen and embeds
           it all directly into the resulting DDT code.
          I've asked support if it's a bug in PBforms and look forward to their reply.
          Last edited by Chris Holbrook; 31 Dec 2007, 08:29 AM.

          Comment


          • #6
            PB support reply

            It is not a bug.

            from Jeff Daniels, PB Support

            Hi Chris,

            1. PBFormsCreateFont in the PBForms.inc calls CreateFontIndirect and returns the handle to the font.
            2. DIALOG SEND hDlg, %WM_SETFONT, hFont1, 0 sends a WM_SETFONT message to the dialog

            These statements set the font for the dialog and this affects the font used by child controls of this parent dialog, so this is not a bug.

            Sincerely,
            Jeff Daniels
            PowerBASIC Staff

            Comment


            • #7
              Not only is not a bug, but a feature than I, and probably others, requested several years ago.
              Forum: http://www.jose.it-berater.org/smfforum/index.php

              Comment


              • #8
                Then could you explain to me why none of the controls in this modified version of the
                code post by Chris are using a bold 14 point font?

                Code:
                #PBFORMS CREATED V1.51
                #COMPILE EXE
                #DIM ALL
                
                #PBFORMS BEGIN INCLUDES
                #IF NOT %DEF(%WINAPI)
                    #INCLUDE "WIN32API.INC"
                #ENDIF
                #INCLUDE "PBForms.INC"
                #PBFORMS END INCLUDES
                
                #PBFORMS BEGIN CONSTANTS
                %IDD_DIALOG1  =  101
                %IDC_LABEL1   = 1001
                %IDC_BUTTON1  = 1003
                %IDC_LABEL2   = 1004
                %IDC_TEXTBOX1 = 1006
                %IDC_TEXTBOX2 = 1007
                %IDC_TEXTBOX3 = 1008
                %IDC_LABEL3   = 1009
                #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
                
                        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
                
                        CASE %WM_DESTROY
                
                    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
                    LOCAL hFont1 AS DWORD
                
                    DIALOG NEW hParent, "PBFORMS QUESTION RE. CONTROL ADD LABEL", 7, 47, 536, 370, %WS_POPUP OR %WS_BORDER OR %WS_DLGFRAME 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 LABEL,   hDlg, %IDC_LABEL1, "Label1", 95, 5, 85, 20, %WS_CHILD OR %WS_VISIBLE OR %SS_LEFT OR %SS_NOTIFY OR _
                        %SS_SUNKEN OR %SS_NOTIFY, %WS_EX_LEFT OR %WS_EX_LTRREADING 
                    CONTROL ADD BUTTON,  hDlg, %IDC_BUTTON1, "Press me to disable LABEL1", 55, 30, 160, 15
                    CONTROL ADD LABEL,   hDlg, %IDC_LABEL2, "This is what the PBWin8.04 help says:", 260, 5, 135, 15
                    CONTROL ADD TEXTBOX, hDlg, %IDC_TEXTBOX1, "", 260, 20, 265, 95, %WS_CHILD OR %WS_VISIBLE OR %WS_TABSTOP OR %ES_LEFT OR _
                        %ES_MULTILINE OR %ES_READONLY OR %ES_WANTRETURN, %WS_EX_CLIENTEDGE OR %WS_EX_LEFT OR %WS_EX_LTRREADING OR _
                        %WS_EX_RIGHTSCROLLBAR
                    CONTROL ADD TEXTBOX, hDlg, %IDC_TEXTBOX2, "TextBox1", 5, 50, 240, 120, %WS_CHILD OR %WS_VISIBLE OR %WS_TABSTOP OR %WS_HSCROLL _
                        OR %WS_VSCROLL OR %ES_LEFT OR %ES_MULTILINE OR %ES_AUTOHSCROLL OR %ES_AUTOVSCROLL, %WS_EX_CLIENTEDGE OR %WS_EX_LEFT OR _
                        %WS_EX_LTRREADING OR %WS_EX_RIGHTSCROLLBAR
                    CONTROL ADD TEXTBOX, hDlg, %IDC_TEXTBOX3, "TextBox3", 5, 175, 525, 180, %WS_CHILD OR %WS_VISIBLE OR %WS_TABSTOP OR _
                        %WS_HSCROLL OR %WS_VSCROLL OR %ES_LEFT OR %ES_MULTILINE OR %ES_AUTOHSCROLL OR %ES_AUTOVSCROLL, %WS_EX_CLIENTEDGE OR _
                        %WS_EX_LEFT OR %WS_EX_LTRREADING OR %WS_EX_RIGHTSCROLLBAR
                    CONTROL ADD LABEL,   hDlg, %IDC_LABEL3, "This is the program code", 390, 160, 135, 15
                
                    hFont1 = PBFormsMakeFont("MS Sans Serif", 14, 400, %FALSE, %TRUE, %FALSE, %ANSI_CHARSET)
                    
                     DIALOG SEND hDlg, %WM_SETFONT, hFont1, 0 
                     
                #PBFORMS END DIALOG
                
                    DIALOG SHOW MODAL hDlg, CALL ShowDIALOG1Proc TO lRslt
                
                #PBFORMS BEGIN CLEANUP %IDD_DIALOG1
                    DeleteObject hFont1
                #PBFORMS END CLEANUP
                
                    FUNCTION = lRslt
                END FUNCTION
                Dominic Mitchell
                Phoenix Visual Designer
                http://www.phnxthunder.com

                Comment


                • #9
                  Sorry, I think that I have mixed things. The feature I requested was DIALOG FONT.
                  Forum: http://www.jose.it-berater.org/smfforum/index.php

                  Comment


                  • #10
                    DIALOG FONT works.

                    Unless the compiler is doing something special when it sees WM_SETFONT being sent to a dialog, I don't see how the following statement could be correct.
                    These statements set the font for the dialog and this affects the font used by child controls of this parent dialog, so this is not a bug.
                    Dominic Mitchell
                    Phoenix Visual Designer
                    http://www.phnxthunder.com

                    Comment

                    Working...
                    X