Announcement

Collapse
No announcement yet.

fitting a listbox to a dialog DDT

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

  • fitting a listbox to a dialog DDT

    This might turn out to be further evidence that I should not work after 10 pm, but what the...

    How do you exactly fit a listbox to a dialog? just declaring it as the same size as the dialog client does not seem enough, as this listbox drawn on a red dialog shows (V8 or V9) :

    Code:
    'fitting a listbox to a dialog
    #compile exe
    #dim all
    '#include once "WIN32API.INC" ' required for PBWin v8
    callback function CB
    end function
    '-----------------------
    function pbmain () as long
        local hDlgLB as dword
        local i, lresult, n, X, Y, W, H as long
        
        X = 200: Y = 200: w = 100: H = 100
    
        dialog new pixels, 0, "", X, Y, W, H,_
               %ws_visible or %ws_popup or %ws_child or _
               %ws_border or %ws_ex_toolwindow or _
               %ws_ex_topmost or %ws_ex_controlparent to hdlgLB
        dialog set color hdlglb, -1, %red
        dialog get client hDlgLB to W, H
        control add listbox, hDlglb, 100,, _
                0, 0, W , H, _
                %ws_child or %ws_visible or %ws_vscroll or %ws_hscroll or _
                %lbs_notify or %lbs_hasstrings or %lbs_disablenoscroll,
                
        for i = 65 to 75
            listbox add hDlgLB, 100, string$(10, i)
        next
        dialog show modeless hdlglb call CB to lresult
        do
            dialog doevents 2 to n
        loop until n = 0
    end function

  • #2
    See the LBS_NOINTEGRALHEIGHT style explanation in your Windows' reference material.

    If you don't use that Windows (and presumably DDT) resize the listbox vertically so you never have a partial row showing.
    Michael Mattias
    Tal Systems (retired)
    Port Washington WI USA
    [email protected]
    http://www.talsystems.com

    Comment


    • #3
      Thank you!

      Comment


      • #4
        And don't I recall reading something about a style which lets the H/W values define the client area, rather than the dialog size? If so, then your H/W variables could be used to size the listbox without having additional code to look up the client size.
        Last edited by Gary Beene; 3 Feb 2009, 06:34 PM.

        Comment


        • #5
          And don't I recall reading something about a style which lets the H/W values define the client area
          If you are speaking about the creation of a new window (a dialog is a window)....

          That is a DDT-style coding only thing. Using SDK-style coding, the H/W specified in the CreateWindowEx or a dialog template are always the outer dimensions of the window and the client area will be what's left after caption and borders are subtracted.

          Windows does provide facilities to calculate the outer H/W required given a desired client size and window style, but the creation parameters themselves must be the outer dimensions.

          MCM
          Michael Mattias
          Tal Systems (retired)
          Port Washington WI USA
          [email protected]
          http://www.talsystems.com

          Comment


          • #6
            Chris, This seems to work fine:
            Code:
            '    Dialog Get Client hDlgLB To W, H '<<<< not needed
                Control Add ListBox, hDlglb, 100,, _
                        0, 0, W , H + 20, _
            =========================================
            When someone does something good,
            applaud! You will make two people happy.
            Samuel Goldwyn
            =========================================
            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


            • #7
              AdjustWindowRect Function
              --------------------------------------------------------------------------------
              The AdjustWindowRect function calculates the required size of the window rectangle, based on the desired client-rectangle size. The window rectangle can then be passed to the CreateWindow function to create a window whose client area is the desired size.

              To specify an extended window style, use the AdjustWindowRectEx function.

              Syntax
              Code:
              BOOL AdjustWindowRect(          LPRECT lpRect,
                  DWORD dwStyle,
                  BOOL bMenu
              Code:
                 LET     Listbox_Rect =  desired LB rect 
                 AdjustWindowRect   Listbox_Rect, dialog_style, bmenu 
                 DIALOG NEW  [PIXELS]   _ 
                       Listbox_rect.nTop, _ 
                      Listbox_rect.nLeft, _ 
                      Listbox_rect.nRight-Listbox_rect.nleft + 1, _
                       Listbox_rect.nBottom-Listbox_rect.nTop + 1, _
                      rest_of_params 
              
                 CONTROL ADD LISTBOX  (desired size) 
                 DIALOG SHOW....

              MCM
              Last edited by Michael Mattias; 4 Feb 2009, 10:04 AM.
              Michael Mattias
              Tal Systems (retired)
              Port Washington WI USA
              [email protected]
              http://www.talsystems.com

              Comment

              Working...
              X