Announcement

Collapse
No announcement yet.

Resizing Dialog Window, Controls do not resize.

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

  • Resizing Dialog Window, Controls do not resize.

    So far, I have been specifying dialogs and controls in pixels. I can resize a dialog with style parameters enabling that.. The controls do not resize at all. Of course they are spec'd in pixels. If I defined the dialog and controls in dialog units, would the
    controls resize? If not, then do I need to monitor resizing in the dialog callback, recalculate the control dimensions and inform the each of the controls? Or is there a better way? As a side note, DDT is really great. Amazing.

  • #2
    I wrote a resizing engine that you might want to leverage... look here...

    http://forum.powerbasic.com/forum/us...g-size-changes

    <b>George W. Bleck</b>
    <img src='http://www.blecktech.com/myemail.gif'>

    Comment


    • #3
      PowerBasic does not currently support automatic resizing of controls. PB'ers either depend upon the resizing engines of the third party tools they use (FireFly, Phoenix, EZGUI) or write their own resizing engine. Search the forums for examples of code which resizes controls.
      Chris Boss
      Computer Workshop
      Developer of "EZGUI"
      http://cwsof.com
      http://twitter.com/EZGUIProGuy

      Comment


      • #4
        Hi Stan,
        Either in pixel or dialog unit, the technique is to monitor the dialog size change in the window callback function. The OS will send a WM_SIZE message that give the new dialog size.

        Pierre
        Code:
        #COMPILE EXE '#Win 8.04#
        #DIM ALL
        #INCLUDE "Win32Api.inc"
         
        $AppName = "WM_SIZE"
         
        GLOBAL hDlg AS DWORD
         
        %Label1   = 101
        %Button1  = 201
        %Button2  = 202
        %Textbox1 = 301
        '______________________________________________________________________________
         
        CALLBACK FUNCTION DlgProc
         LOCAL ClientSizeX  AS LONG
         LOCAL ClientSizeY  AS LONG
         LOCAL ButtonWidth  AS LONG
         LOCAL ButtonHeight AS LONG
         LOCAL ButtonMargin AS LONG
         
         SELECT CASE CBMSG
         
           CASE %WM_SIZE 'New dialog size is available.
             'This is called on every window resize steps and always called when program starts.
         
             'CBWPARAM contain resizing requested: SIZE_MAXHIDE, SIZE_MAXIMIZED, SIZE_MAXSHOW, SIZE_MINIMIZED, and SIZE_RESTORED
             'LO(WORD, CBLPARAM) is client area width  in pixel.
             'HI(WORD, CBLPARAM) is client area height in pixel.
             IF CBWPARAM <> %SIZE_MINIMIZED THEN 'Program is not iconized to the taskbar
               ClientSizeX = LO(WORD, CBLPARAM) 'See also DIALOG PIXELS TO UNITS if you want DU
               ClientSizeY = HI(WORD, CBLPARAM)
         
               SetWindowPos(GetDlgItem(hDlg, %Textbox1), 0, 0, 0, ClientSizeX - 20, 20, %SWP_NOZORDER OR %SWP_NOMOVE) 'Resize but SWP_NOMOVE
         
               ButtonMargin = ClientSizeX / 6
               ButtonWidth  = (ClientSizeX - ButtonMargin * 3) / 2
               ButtonHeight = ClientSizeY - 70
               SetWindowPos(GetDlgItem(hDlg, %Button1), 0, ButtonMargin, 60, ButtonWidth, ButtonHeight, %SWP_NOZORDER) 'Resize and move
               SetWindowPos(GetDlgItem(hDlg, %Button2), 0, ButtonMargin + ButtonWidth + ButtonMargin, 60, _            'Resize and move
                                                           ButtonWidth, ButtonHeight, %SWP_NOZORDER)
               'See also MoveWindow() as a SetWindowPos substitute
             END IF
         
          END SELECT
         
        END FUNCTION
        '______________________________________________________________________________
         
        FUNCTION PBMAIN()
         LOCAL hIconBig   AS DWORD
         LOCAL hIconSmall AS DWORD
         
         DIALOG FONT "Segoe UI", 9
         DIALOG NEW %HWND_DESKTOP, $AppName, , , 200, 60, _
         %WS_CAPTION OR %WS_MINIMIZEBOX OR %WS_MAXIMIZEBOX OR %WS_SYSMENU OR %WS_THICKFRAME, 0 TO hDlg
         
         ExtractIconEx("Shell32.dll", 27, BYVAL VARPTR(hIconBig), BYVAL VARPTR(hIconSmall), 1) '(File, IconId, hIconBig, hIconSmall, IconCount)
         SetClassLong(hDlg, %GCL_HICONSM, hIconSmall) 'Set an icon
         SetClassLong(hDlg, %GCL_HICON, hIconBig) 'Set an icon
         
         CONTROL ADD LABEL, hDlg, %Label1, "Label1", 5, 5, 60, 8
         CONTROL ADD TEXTBOX, hDlg, %Textbox1, "Textbox1", 5, 15, 60, 12
         CONTROL ADD BUTTON, hDlg, %Button1, "Button1", 5, 35, 35, 15
         CONTROL ADD BUTTON, hDlg, %Button2, "Button2", 5, 55, 35, 15
         DIALOG SHOW MODAL hDlg CALL DlgProc
         
         DestroyIcon(hIconSmall)
         DestroyIcon(hIconBig)
         
        END FUNCTION
        '______________________________________________________________________________
        '

        Comment


        • #5
          Pixels dialog like above, but with DDT CONTROL SET SIZE, and CONTROL SET LOC

          Pierre
          Code:
          #COMPILE EXE '#Win 8.04#
          #DIM ALL
          #INCLUDE "Win32Api.inc"
           
          $AppName = "WM_SIZE"
           
          GLOBAL hDlg AS DWORD
           
          %Label1   = 101
          %Button1  = 201
          %Button2  = 202
          %Textbox1 = 301
          '______________________________________________________________________________
           
          CALLBACK FUNCTION DlgProc
           LOCAL ClientSizeX  AS LONG
           LOCAL ClientSizeY  AS LONG
           LOCAL ButtonWidth  AS LONG
           LOCAL ButtonHeight AS LONG
           LOCAL ButtonMargin AS LONG
           
           SELECT CASE CBMSG
           
             CASE %WM_SIZE 'New dialog size is available.
               'This is called on every window resize steps and always called when program starts.
           
               'CBWPARAM contain resizing requested: SIZE_MAXHIDE, SIZE_MAXIMIZED, SIZE_MAXSHOW, SIZE_MINIMIZED, and SIZE_RESTORED
               'LO(WORD, CBLPARAM) is client area width  in pixel.
               'HI(WORD, CBLPARAM) is client area height in pixel.
               IF CBWPARAM <> %SIZE_MINIMIZED THEN 'Program is not iconized to the taskbar
                 ClientSizeX = LO(WORD, CBLPARAM) 'See also DIALOG PIXELS TO UNITS if you want DU
                 ClientSizeY = HI(WORD, CBLPARAM)
           
                 CONTROL SET SIZE hDlg, %Textbox1, ClientSizeX - 20, 20
                 CONTROL SET LOC hDlg, %Textbox1, 5, 25
           
                 ButtonMargin = ClientSizeX / 6
                 ButtonWidth  = (ClientSizeX - ButtonMargin * 3) / 2
                 ButtonHeight = ClientSizeY - 70
                 CONTROL SET SIZE hDlg, %Button1, ButtonWidth, ButtonHeight
                 CONTROL SET LOC hDlg, %Button1, ButtonMargin, 60
                 CONTROL SET SIZE hDlg, %Button2, ButtonWidth, ButtonHeight
                 CONTROL SET LOC hDlg, %Button2, ButtonMargin + ButtonWidth + ButtonMargin, 60
           
               END IF
           
            END SELECT
           
          END FUNCTION
          '______________________________________________________________________________
           
          FUNCTION PBMAIN()
           LOCAL hIconBig   AS DWORD
           LOCAL hIconSmall AS DWORD
           
           DIALOG FONT "Segoe UI", 9
           DIALOG NEW PIXELS, %HWND_DESKTOP, $AppName, , , 400, 160, _
           %WS_CAPTION OR %WS_MINIMIZEBOX OR %WS_MAXIMIZEBOX OR %WS_SYSMENU OR %WS_THICKFRAME, 0 TO hDlg
           
           ExtractIconEx("Shell32.dll", 27, BYVAL VARPTR(hIconBig), BYVAL VARPTR(hIconSmall), 1) '(File, IconId, hIconBig, hIconSmall, IconCount)
           SetClassLong(hDlg, %GCL_HICONSM, hIconSmall) 'Set an icon
           SetClassLong(hDlg, %GCL_HICON, hIconBig) 'Set an icon
           
           CONTROL ADD LABEL, hDlg, %Label1, "Label1", 5, 5, 60, 12
           CONTROL ADD TEXTBOX, hDlg, %Textbox1, "Textbox1", 5, 25, 60, 12
           CONTROL ADD BUTTON, hDlg, %Button1, "Button1", 5, 35, 35, 15
           CONTROL ADD BUTTON, hDlg, %Button2, "Button2", 5, 55, 35, 15
           DIALOG SHOW MODAL hDlg CALL DlgProc
           
           DestroyIcon(hIconSmall)
           DestroyIcon(hIconBig)
           
          END FUNCTION
          '______________________________________________________________________________
          '

          Comment


          • #6
            Stan,
            Every app I write uses the same approach as shown in the DDT code example below. I create a ResizeWindows function that is called whenever the dialog %WM_Size message is received. I resize/relocate all controls from within that function. Most apps I write have a small number of controls, making the ResizeWindows function easy to write, so I've rarely felt the need for a resizing engine.



            Code:
            'Compilable Example:
            #Compile Exe
            #Dim All
            %IDC_TextBoxA = 500 : %IDC_TextBoxB = 501
            #Include "Win32api.inc"
            Global hDlg As Dword
            Function PBMain()
               Dialog New Pixels, 0, "Resize Example",300,300,250,100, %WS_OverlappedWindow To hDlg
               Control Add TextBox, hDlg, %IDC_TextBoxA, "BoxA",  10, 10, 200,100
               Control Add TextBox, hDlg, %IDC_TextBoxB, "BoxB",  10, 10, 200,100
               Dialog Show Modal hDlg Call DlgProc()
            End Function
            
            CallBack Function DlgProc() As Long
               Select Case Cb.Msg
                  Case %WM_Size : ResizeWindow
               End Select
            End Function
            
            Sub ResizeWindow
               Local w,h As Long
               Dialog Get Client hDlg To w,h
               Control Set Size hDlg, %IDC_TextBoxA, w/2-15,h-20
               Control Set Loc hDlg, %IDC_TextBoxB, w/2+5,10
               Control Set Size hDlg, %IDC_TextBoxB, w/2-15,h-20
            End Su
            Last edited by Gary Beene; 8 Apr 2016, 12:58 AM.

            Comment


            • #7
              Thank you for the responses. It rather stagers my mind, that to ask a question here, and get responses with demo code performing the resize. Copy, paste, compile and then see it work. Taken the time to go through each response, see what is happening in the code. Got it. Thanks again. DDT is slick.

              Comment

              Working...
              X