Announcement

Collapse
No announcement yet.

DDT & Listbox

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

  • Bern Ertl
    replied
    Borge, thanks for the tip! Trying to unravel the mysteries of the Windows API equates and message from the Win32api.INC, PowerBASIC manual & another (C based) Windows book I have is very frustrating. I don't have the Win32api.HLP file (yet). I'm off to download....


    Bernard Ertl

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

    Leave a comment:


  • Borje Hagsten
    replied
    Maybe you would be better off by using a ListView control instead?
    It handles columns in a much better way, sort of like a semi-grid,
    if you like. Can even do grid lines. Several samples available in
    the source code section.

    Hmm, logical units.. yeah, well, okay - my mistake, probably..

    Anyway, second parameter, lParam, for LB_SETHORIZONTALEXTENT has
    no meaning, should be zero. Do you have win32api.hlp? If not, I
    suggest you download it from PB's file area and then, in the PB
    editor, under Options - General - Win 32 help file, you can browse
    and set the path to it. Once this is done, you simply have to
    double-click on an API call or message in the PB editor to open
    up the related help file section for it. Very handy.


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

    Leave a comment:


  • Bern Ertl
    replied
    Well I tried your code Borge and I'm pleased to report that I have a functioning horizontal scrollbar in my listbox.

    GetTxtExtent returns pixels which is just what is required for :
    CONTROL SEND hdlg, %ID_LIST, %LB_SETHORIZONTALEXTENT, 400, 0

    Off to the next stumbling block (challenge)...

    Bernard Ertl

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

    Leave a comment:


  • Bern Ertl
    replied
    Borge, thanks a million for the examples.

    I see now that the %LBS_MULTICOLUMN property won't help me in my immediate need. That was designed for use with the display of columns where all the data is the same type. In effect, Windows is wrapping one long column of data into multiple columns as needed, right?

    Does the second parameter (o) to :
    CONTROL SEND hdlg, %ID_LIST, %LB_SETHORIZONTALEXTENT, 400, 0

    have any meaning? Your function GetTxtExtent looks to be exactly what I was looking for - thanks! But you confused me with your comments:

    'The following returns the physical extent of a string of text
    'in in logical units (use DIALOG UNITS.. to convert to pixels):

    What does GetTxtExtent return, DIALOG UNITS or pixels?

    Bernard Ertl



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

    Leave a comment:


  • Borje Hagsten
    replied
    When you use %LBS_MULTICOLUMN, items a added in column order, from
    top to bottom of listbox, then on to next column. Following samples
    may help you (for first sample, listbox must be created with
    %LBS_MULTICOLUMN style):

    'Set column width to 100 pixels
    Code:
    CONTROL SEND hDlg, %ID_LIST, %LB_SETCOLUMNWIDTH, 100, 0
    'Set listbox scroll width to 400 pixels (if listbox physical width
    'is smaller than that, horizontal scrollbar will be shown:
    Code:
    CONTROL SEND hdlg, %ID_LIST, %LB_SETHORIZONTALEXTENT, 400, 0
    'The following returns the physical extent of a string of text
    in in logical units (use DIALOG UNITS.. to convert to pixels):
    Code:
    FUNCTION GetTxtExtent(BYVAL hWnd AS LONG, BYVAL txt AS STRING, TxHeight AS LONG) AS LONG
      LOCAL hDc AS LONG, lpSize AS SIZEL
     
      hDc = GetDc(hWnd)
      CALL GetTextExtentPoint32(hDc, BYVAL STRPTR(txt), LEN(txt), lpSize)
      ReleaseDC hWnd, hDc
     
      TxHeight  = lpSize.cy 'TxHeight is declared BYREF and will contain ("return) text height
      FUNCTION  = lpSize.cx 'the function returns the textwidth
    END FUNCTION
    'And finally, for listbox with LBS_USETABSTOPS style: (negative
    'values makes text right aligned against tab - good for numbers).
    'This sets 3 tab stops, first right-aligned at 50 dialog units,
    'second left-aligned at 50+54 dlg units and last right-aligned at
    '50+54+200 dlg units (use GetDialogBaseUnits to convert to pixels,
    'if you like that better). Have fun..
    Code:
      LOCAL tbs() AS LONG: REDIM tbs(2)
      tbs(0) = -50: tbs(1) = 54: tbs(2) = -200
      CALL SendMessage(hWnd, %LB_SETTABSTOPS, 3, VARPTR(tbs(0)))

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


    [This message has been edited by Borje Hagsten (edited January 21, 2001).]

    Leave a comment:


  • Bern Ertl
    replied
    Now we're getting somewhere! Thanks everyone.

    Please bear with me for a few more 'newbie' questions:

    1) If I use %LBS_MULTICOLUMN & %LB_SETCOLUMNWIDTH, do I need to do anything special in formatting the strings for the listbox for it to work? Ie. how do I specify the columns? Or does the %LB_SETCOLUMNWIDTH determine the column sizes (in pixels or dialog units?) like tab settings? Does it change the formatting of the listbox strings or merely determine the amount of space that is scrolled with each movement right or left?

    2) Could someone provide a small example of how to call GetTextExtentPoint32() & GetDC() in context of a DDT listbox? How do I release the DC once I'm done?

    Thanks again.

    Bernard Ertl

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


    [This message has been edited by Bern Ertl (edited January 21, 2001).]

    Leave a comment:


  • Eric Pearson
    replied
    Fred and Lance --

    You're right, I forgot about that one. LB_SETHORIZONTALEXTENT is so hard to use "correctly" that I put it out of my mind.

    Bern --

    Keep in mind that when Lance says "the longest entry in the listbox" he isn't talking about the entry with the largest number of characters. Using the default font, capital W is the widest character and lower case i is the narrowest, so WW is much wider than iii. To do it right you need to check the GetTextExtentPoint32 of every entry in the listbox, and use the longest one.

    -- Eric

    ------------------
    Perfect Sync: Perfect Sync Development Tools
    Email: mailto:[email protected][email protected]</A>



    [This message has been edited by Eric Pearson (edited January 21, 2001).]

    Leave a comment:


  • Lance Edmonds
    replied
    Fred has the best answer here... please note that the %LB_SETHORIZONTALEXTENT message uses pixels to determine the scrollable width of the listbox. The easiest way to calculate the width is to base it upon the longest entry in the listbox, and call GetTextExtentPoint32(). However, you first need to get the DC of the control using GetDC(), and you must release the DC afterward.




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

    Leave a comment:


  • Fred Oxenby
    replied
    To enable horizontal scrolling use:
    Control Send hDlg&,%LISTBOX,%LB_SETHORIZONTALEXTENT,ScrollInPixel&,0)


    ------------------
    Fred
    mailto:[email protected][email protected]</A>
    http://www.oxenby.se



    [This message has been edited by Fred Oxenby (edited January 20, 2001).]

    Leave a comment:


  • Eric Pearson
    replied
    Bern --

    From CONTROL ADD LISTBOX in the Help File...

    %LBS_MULTICOLUMN Specifies a listbox that has multiple columns and can be scrolled horizontally. Use a %LB_SETCOLUMNWIDTH message to set the column width.

    -- Eric


    ------------------
    Perfect Sync: Perfect Sync Development Tools
    Email: mailto:[email protected][email protected]ectsync.com</A>

    [This message has been edited by Eric Pearson (edited January 20, 2001).]

    Leave a comment:


  • Bern Ertl
    replied
    Eric, how are multiple columns defined for a DDT listbox?

    My text strings are currently using TABs to create columns, but I don't think this is what you meant.

    Bernard Ertl

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

    Leave a comment:


  • Eric Pearson
    replied
    This isn't a DDT issue... A standard Windows Listbox's horizontal scroll bar is used to move from column to column. Take a look at any Windows program's Open File dialog with lots of files and you'll see what I mean. If your Listbox only has one column, the horizontal scroll bar is useless.

    -- Eric


    ------------------
    Perfect Sync: Perfect Sync Development Tools
    Email: mailto:[email protected][email protected]</A>



    [This message has been edited by Eric Pearson (edited January 20, 2001).]

    Leave a comment:


  • Bern Ertl
    started a topic DDT & Listbox

    DDT & Listbox

    I need help again.

    I've defined a listbox for a dialog using:

    CONTROL ADD LISTBOX, hDlg&, %_IDUNITS, , 10, 15, 145, 90, %WS_TABSTOP OR %LBS_DISABLENOSCROLL OR %LBS_USETABSTOPS OR %LBS_NOTIFY OR %WS_VSCROLL OR %WS_BORDER OR %WS_HSCROLL

    and I use the LISTBOX ADD statements to add my text strings. My text strings are longer than the width of the listbox, but the horizontal scrollbar which is displayed does not allow any scrolling. It's as if it were disabled. How do I get it to work?

    Bernard Ertl


    ------------------
Working...
X