Announcement

Collapse
No announcement yet.

Button font size changes at window resize

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

  • Button font size changes at window resize

    Hi all,
    I have a main dialog. This is resizable and the controls on the dialog
    are also resized, that is, their size and/or their location.
    I do this by deleting the controls when resizing and creating them again.
    I first used relocating them and resizing them but this left garbage on my
    dialog window. Killing and recreating the controls does the job but I have
    another problem now:
    From this dialog, I open a second dialog by pressing
    a button. When closing the second window something strange happens: when
    When resizing the main window, the font of the buttons on the main window changes.
    When I resize the main window without first opening the second window, nothing
    abnormal happens.. I have stripped down my code to the minimum, still showing
    the problem. Anybody have any idea?
    Kind regards
    Eddy
    Code:
    #COMPILE EXE
    #REGISTER NONE
    #DIM ALL
    
    #INCLUDE "win32api.inc"
    #INCLUDE "commctrl.inc"
    
    GLOBAL hMain&    ' Dialog handle
    GLOBAL hST&
    GLOBAL MinDialogHeight      AS LONG
    GLOBAL MinDialogWidth       AS LONG
    
    %EXITBUTTON         = 102
    %SETTINGSBUTTON     = 106
    %ST_DONEBUTTON           = 218
    
    DECLARE FUNCTION PBMAIN_Settings AS LONG
    
    DECLARE SUB ShowDialog_Main(BYVAL hParent&)
    DECLARE CALLBACK FUNCTION DLGPROC_Main
    DECLARE SUB ShowDialog_ST(BYVAL hParent&)
    DECLARE CALLBACK FUNCTION DLGPROC_ST
    ' Main
    DECLARE CALLBACK FUNCTION CBF_EXITBUTTON()
    DECLARE CALLBACK FUNCTION CBF_SETTINGSBUTTON()
    ' Settings
    DECLARE CALLBACK FUNCTION CBF_ST_DONEBUTTON()
    
    FUNCTION PBMAIN
        MinDialogHeight = 100
        MinDialogWidth  = 224
        ShowDialog_Main 0
    END FUNCTION
    
    FUNCTION PBMAIN_Settings AS LONG
        ShowDialog_ST 0
    END FUNCTION
    
    SUB ShowDialog_Main(BYVAL hParent&)
        DIALOG NEW hParent&, "Click 'Settings', click 'Done', then resize window.. and watch button font change..:-(", 0, 0,  390,  60, %WS_OVERLAPPEDWINDOW OR %DS_CENTER, 0 TO hMain&
    
        CONTROL ADD "Button", hMain&,  %EXITBUTTON,  "Exit", 3, 160, 40, 15, _
            %WS_CHILD OR %WS_VISIBLE OR %BS_PUSHBUTTON OR %WS_TABSTOP
        CONTROL ADD "Button", hMain&,  %SETTINGSBUTTON,  "Settings", 3, 143, 40, 15, _
            %WS_CHILD OR %WS_VISIBLE OR %BS_PUSHBUTTON OR %WS_TABSTOP
        DIALOG SHOW MODAL hMain& , CALL DLGPROC_Main
    END SUB
    
    SUB ResizeMainDialog
        DIM x AS LONG, y AS LONG
            DIALOG GET SIZE hMain TO x, y
            IF y < MinDialogHeight THEN y = MinDialogHeight
            IF x < MinDialogWidth  THEN x = MinDialogWidth
            DIALOG SET SIZE hMain&, x, y
            DIALOG GET CLIENT hMain TO x, y
    
            CONTROL KILL hMain&,  %EXITBUTTON
            CONTROL ADD "Button", hMain&,  %EXITBUTTON,  "Exit", 3, y-17, 40, 15, _
            %WS_CHILD OR %WS_VISIBLE OR %BS_PUSHBUTTON OR %WS_TABSTOP CALL CBF_EXITBUTTON
    
            CONTROL KILL hMain&, %SETTINGSBUTTON
            CONTROL ADD "Button", hMain&,  %SETTINGSBUTTON,  "Settings", 3, y-34, 40, 15, _
            %WS_CHILD OR %WS_VISIBLE OR %BS_PUSHBUTTON OR %WS_TABSTOP CALL CBF_SETTINGSBUTTON
    END SUB
    
    SUB ShowDialog_ST(BYVAL hParent&)
        DIALOG NEW hParent&, "Settings", 0, 0,  219,  167, 0, 0 TO hST&
        CONTROL ADD "Button", hST&,  %ST_DONEBUTTON,  "Done", 80, 149, 53, 15, _
            %WS_CHILD OR %WS_VISIBLE OR %BS_PUSHBUTTON OR %WS_TABSTOP CALL CBF_ST_DONEBUTTON
        DIALOG SHOW MODAL hST& , CALL DLGPROC_ST
    END SUB
    
    CALLBACK FUNCTION DLGPROC_Main
        SELECT CASE CBMSG
            CASE %WM_SIZE
                ResizeMainDialog
        END SELECT
    END FUNCTION
    
    CALLBACK FUNCTION DLGPROC_ST
    END FUNCTION
    
    CALLBACK FUNCTION CBF_EXITBUTTON
        IF CBCTLMSG=%BN_CLICKED THEN DIALOG END hMain
    END FUNCTION
    
    CALLBACK FUNCTION CBF_SETTINGSBUTTON
        IF CBCTLMSG=%BN_CLICKED THEN PBMAIN_Settings
    END FUNCTION
    
    CALLBACK FUNCTION CBF_ST_DONEBUTTON
        IF CBCTLMSG=%BN_CLICKED THEN DIALOG END hST
    END FUNCTION

    ------------------
    [email protected]
    Eddy

  • #2
    Eddy:

    Compiled your code on a Win98SE machine... works fine here. Followed your steps exactly, no difference
    in the button fonts after the resize. Tried everything I could to make it happen... just kept working
    as expected. Have you tried it on more than one PC?

    Timm
    mailto:[email protected]
    Tsunami Record Manager

    Comment


    • #3
      No problem on my Windows 98SE


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

      Comment


      • #4
        Eddy,

        I tried on my Win98SE and no font change? But going back to your origional
        code that just repositions your controls instead of destroy&create, try adding
        the window style %WS_CLIPCHILDREN to your parent window and that should solve
        your repaint problems, use the API calls MoveWindow() or SetWindowPos().
        I also had a similar problem in the past, but was due to a memory leak,
        I forgot to destroy a font that I created, dumb Eh!

        Also, what did you test this on, Win95?

        Regards,
        Jules


        [This message has been edited by Jules Marchildon (edited August 17, 2001).]
        Best regards
        Jules
        www.rpmarchildon.com

        Comment


        • #5
          I can duplicate the font problem in Win2K. I've referred this to R&D for investigation. Thanks!

          However, I have to agree with Jules - there are much better ways to handle resizable dialogs & windows.

          Either just move and resize the actual control, or use a 3rd-party resizing library (such as my own
          RESIZE32 library). If you would like to check out a fully functional demo - just email me privately
          at mailto:[email protected][email protected]</A> and I'll send you a copy to play with!


          ------------------
          Lance
          PowerBASIC Support
          mailto:[email protected][email protected]</A>
          Lance
          mailto:[email protected]

          Comment


          • #6
            Hello all,
            Thanks for your replies. I have this problem on a Win2K pc. Didn't test it on a
            Win9X system, but it is not the first time that I encountered different behavior
            of a program on different Windows systems. Should have mentioned that I was running
            it on Win2K...
            Hopefully PB's R&D can find a cure...
            Jules, thanks for your suggestion about the repositioning of controls!
            I'm going to try that. I started out on using DDT's control resizing and
            relocating commands. Basically they worked but it left garbage on the screen after
            resizing. After some trial and error, the best I could come up with was killing and
            recreating the controls. Not very elegant, I admit. I'll try your suggestions though.
            Kind regards
            Eddy


            ------------------
            [email protected]

            [This message has been edited by Eddy Van Esch (edited August 18, 2001).]
            Eddy

            Comment


            • #7
              Hi folks,
              did some more testing...
              In stead of destroying and recreating the windows I went back to relocating and resizing
              the controls...
              Tried Jules' tips (WS_CLIPCHILDREN and API's MoveWindow).. Didn't work, I stil get the
              garbage when resizing..:-((
              However, when I switch off Win2K's setting "Show window contents while dragging",
              everything is OK...(no garbage on the screen). This is actually the Win98 setting because
              Win98 doesn't show the window contents while resizing if I'm not mistaking... That's why the
              Win98 users don't have the garbage problem.
              So, right now, I have a few options:
              1) Make sure the resizing works well (killing and recreating the controls) but this
              means I get the 'font size' problem...
              2) In stead of killing and recreating, I use the relocating and resizing method, which creates
              the garbage on my screen.. UNLESS I ask every Win2K user that uses this program to disable
              the "Show window contents while dragging" on his pc...
              I hate this... could be because it's late and I'm tired....
              Kind regards
              Eddy



              ------------------
              [email protected]

              [This message has been edited by Eddy Van Esch (edited August 18, 2001).]
              Eddy

              Comment


              • #8
                Hmmm...

                I wish I had Win2k, or maybe not... Anyway, sounds like the main dialogs
                window needs to be forced to repaint each time you resize it. Try forcing
                a repaint by adding these two lines after your repositioning code;

                Call InvalidateRect( hWnd, ByVal %NULL, %TRUE )
                Call UpdateWindow( hWnd )

                ... where "hWnd" is the handle to the Main dialog window.

                And to add to Lance's plug, I have his Resize32 control, it easy to use, does an
                excellent job for me, works both on the SDK and DDT style coding and allows me to
                think less about the grunt part of programming and more on creativity.


                Regards,
                Jules
                Best regards
                Jules
                www.rpmarchildon.com

                Comment


                • #9
                  Thanks for the kind words, Jules! Quite a few people have emailed and are now evaluating demos.

                  Regards,
                  Lance
                  Lance
                  mailto:[email protected]

                  Comment


                  • #10
                    Originally posted by Jules Marchildon:
                    Try forcing a repaint by adding these two lines after your repositioning code;
                    Call InvalidateRect( hWnd, ByVal %NULL, %TRUE )
                    Call UpdateWindow( hWnd )
                    ... where "hWnd" is the handle to the Main dialog window
                    Jules,
                    Your suggestion was the right one!! Thanks!!!! I first tried an 'InvalidateRect' of the
                    main dialog. This did not work, but I noticed that it were in fact the controls
                    that were 'garbaged' and not the main window itself. So, I did an 'InvalideRect'
                    of the controls in stead of the window and now it worked!!! I didn't have to add
                    the 'UpdateWindow'.
                    So, now I can relocate and resize the controls instead of destroying and recreating them.
                    This way I don't encounter the font size 'bug' anymore, but the fact remains that it
                    is an abnormal behaviour so if somebody finds a cure for the font size bug...
                    The adapted code of the above program now looks something like this:
                    Code:
                    #COMPILE EXE
                    #REGISTER NONE
                    #DIM ALL
                    #INCLUDE "win32api.inc"
                    #INCLUDE "commctrl.inc"
                    GLOBAL hMain&    ' Dialog handle
                    GLOBAL hST&
                    GLOBAL MinDialogHeight      AS LONG
                    GLOBAL MinDialogWidth       AS LONG
                    
                    %EXITBUTTON         = 102
                    %SETTINGSBUTTON     = 106
                    %ST_DONEBUTTON           = 218
                    
                    DECLARE FUNCTION PBMAIN_Settings AS LONG
                    
                    DECLARE SUB ShowDialog_Main(BYVAL hParent&)
                    DECLARE CALLBACK FUNCTION DLGPROC_Main
                    DECLARE SUB ShowDialog_ST(BYVAL hParent&)
                    DECLARE CALLBACK FUNCTION DLGPROC_ST
                    ' Main
                    DECLARE CALLBACK FUNCTION CBF_EXITBUTTON()
                    DECLARE CALLBACK FUNCTION CBF_SETTINGSBUTTON()
                    ' Settings
                    DECLARE CALLBACK FUNCTION CBF_ST_DONEBUTTON()
                    
                    FUNCTION PBMAIN
                        MinDialogHeight = 100
                        MinDialogWidth  = 224
                        ShowDialog_Main 0
                    END FUNCTION
                    
                    FUNCTION PBMAIN_Settings AS LONG
                        ShowDialog_ST 0
                    END FUNCTION
                    
                    SUB ShowDialog_Main(BYVAL hParent&)
                        DIALOG NEW hParent&, "Resize this window. No more garbage now...", 0, 0,  390,  60, %WS_OVERLAPPEDWINDOW OR %DS_CENTER, 0 TO hMain&
                    
                        CONTROL ADD "Button", hMain&,  %EXITBUTTON,  "Exit", 3, 160, 40, 15, _
                            %WS_CHILD OR %WS_VISIBLE OR %BS_PUSHBUTTON OR %WS_TABSTOP CALL CBF_EXITBUTTON
                                                                                                            
                        CONTROL ADD "Button", hMain&,  %SETTINGSBUTTON,  "Settings", 3, 143, 40, 15, _
                            %WS_CHILD OR %WS_VISIBLE OR %BS_PUSHBUTTON OR %WS_TABSTOP CALL CBF_SETTINGSBUTTON
                        DIALOG SHOW MODAL hMain& , CALL DLGPROC_Main
                    END SUB
                    
                    SUB ResizeMainDialog
                        DIM x AS LONG, y AS LONG, hCtl AS LONG
                            DIALOG GET SIZE hMain TO x, y
                            IF y < MinDialogHeight THEN y = MinDialogHeight
                            IF x < MinDialogWidth  THEN x = MinDialogWidth
                            DIALOG SET SIZE hMain&, x, y
                            DIALOG GET CLIENT hMain TO x, y
                    
                            CONTROL SET LOC hMain&, %EXITBUTTON, 3, y-17
                            CONTROL HANDLE hMain&,  %EXITBUTTON TO hCtl
                            InvalidateRect hCtl, BYVAL %NULL, %True
                    
                            CONTROL SET LOC hMain&, %SETTINGSBUTTON, 3, y-34
                            CONTROL HANDLE hMain&,  %SETTINGSBUTTON TO hCtl
                            InvalidateRect hCtl, BYVAL %NULL, %True
                    END SUB
                    
                    SUB ShowDialog_ST(BYVAL hParent&)
                        DIALOG NEW hParent&, "Settings", 0, 0,  219,  167, 0, 0 TO hST&
                        CONTROL ADD "Button", hST&,  %ST_DONEBUTTON,  "Done", 80, 149, 53, 15, _
                            %WS_CHILD OR %WS_VISIBLE OR %BS_PUSHBUTTON OR %WS_TABSTOP CALL CBF_ST_DONEBUTTON
                        DIALOG SHOW MODAL hST& , CALL DLGPROC_ST
                    END SUB
                    
                    CALLBACK FUNCTION DLGPROC_Main
                        SELECT CASE CBMSG
                            CASE %WM_SIZE
                                ResizeMainDialog
                        END SELECT
                    END FUNCTION
                    
                    CALLBACK FUNCTION DLGPROC_ST
                    END FUNCTION
                    
                    CALLBACK FUNCTION CBF_EXITBUTTON
                        IF CBCTLMSG=%BN_CLICKED THEN DIALOG END hMain
                    END FUNCTION
                    
                    CALLBACK FUNCTION CBF_SETTINGSBUTTON
                        IF CBCTLMSG=%BN_CLICKED THEN PBMAIN_Settings
                    END FUNCTION
                    
                    CALLBACK FUNCTION CBF_ST_DONEBUTTON
                        IF CBCTLMSG=%BN_CLICKED THEN DIALOG END hST
                    END FUNCTION


                    ------------------
                    [email protected]
                    Eddy

                    Comment


                    • #11
                      Eddy,

                      I realize your problem is solved, but you might consider using
                      a toolbar on resizable dialogs. They have a much cleaner look...



                      ------------------
                      Bernard Ertl
                      Bernard Ertl
                      InterPlan Systems

                      Comment


                      • #12
                        Just wondering why the "CONTROL SET LOC statement" does not repaint the control for you.
                        Something like MoveWindow() that allows you to set the repaint flag? (Or does it?)

                        Jules

                        Best regards
                        Jules
                        www.rpmarchildon.com

                        Comment


                        • #13
                          Originally posted by Bern Ertl:
                          ..but you might consider using a toolbar on resizable dialogs. They have a much cleaner look...
                          Bern,
                          do you mean a toolbar in stead of the different buttons on my dialog?
                          Yes, you could have a point there, but I'm still in the process of learning
                          the ins and outs of PB and Windows in particular. So, one day I'll start using
                          toolbars, but thanks for the tip!
                          Jules,
                          Your first suggestion regarding this problem of mine was to use 'MoveWindow' I believe. I tried
                          it, but I still had the infamous 'garbage' problem. So after MoveWindow you also have
                          to repaint the window, or the controls in this case..
                          Kind regards
                          Eddy



                          ------------------
                          [email protected]
                          Eddy

                          Comment


                          • #14
                            Eddy,

                            Yes, that is what I meant. If you search the Forum, you should
                            find several excellent examples for using a toolbar.



                            ------------------
                            Bernard Ertl
                            Bernard Ertl
                            InterPlan Systems

                            Comment


                            • #15
                              To set the minimum size of the window, I removed the following lines in the
                              resizing routine:
                              Code:
                                      DIALOG GET SIZE hMain TO x, y
                                      IF y < MinDialogHeight THEN y = MinDialogHeight
                                      IF x < MinDialogWidth  THEN x = MinDialogWidth
                                      DIALOG SET SIZE hMain&, x, y
                              ... and I used the WM_GETMINMAXINFO in stead.. I'm learning something new
                              everyday..
                              Kind regards
                              Eddy


                              ------------------
                              [email protected]
                              Eddy

                              Comment

                              Working...
                              X