LISTBOX TAB PROBLEM SOLVED
- Posted by "Bernard W. Ryan" <bwryan at PCOM.NET> Jul 07, 1999
- 524 views
-------------------------- tablist.exw ------------------------------------ -- -- TABS will not function unless the style constant LBS_USETABSTOPS = #80 -- is included in the list box discription at number 8 and 9 in -- david cuny's win32lib.ew defines. Until david gets a chance to added it -- you can do a temporary change at : -- #8: unsorted list box -- #9: sorted list box -- -- WS_BORDER, -- list box discription at #8 and #9 -- #80, -- <----- add this here -- WS_TABSTOP} ) -- -- This will turn on the DEFAULT TAB STOPS and allow you to change them. -- -- Be sure you READ all of this message before trying to use TABS -- -- WHY DON'T MY FONTS LINE UP IN A LIST BOX WHEN I CHANGE FONTS ??? -- -- ANSWER : -- -- The LIST BOX used in windows is measured in DIALOG BOX UNITS. -- -- A DIALOG BOX UNIT is = to one-fourth of the CURRENT DIALOG BOX BASE UNIT -- The dialog box base units are computed based on the height and width of -- the dialog box base units, in pixels using the height and width of -- the CURRENT SYSTEM FONT. -- -- The GetDialogBaseUnits function can be used to get the CURRENT DIALOG -- BOX BASE UNIT. -- -- One horizontal dialog box unit is equal to one-fourth of the current -- dialog box base width unit. -- A vertical dialog box unit is equal to one-eighth of the current height -- unit of the CURRENT DIALOG BOX BASE UNIT. -- -- THE DEFAULT TAB STOP IS SET EVERY 32 horizontal DIALOG UNITS -- THE PIXTEL DISTANCE = (32*horzbaseunits)/4 -- -- So pixel distances vary from font to font changing the current base unit -- driving us nuts trying figure out how to line up the fields. -- -- The only way you can line things up is to use TAB STOPS for the fields. -- That is why you have to understand what dialog units are and when your -- setting TABS you are NOT USING COLUMN NUMBERS. -- -- There are two ways to figure out where to set the tab stops. -- 1: Use GetDialogBaseUnits function to get the current base unit and -- calculate where the tab stops need to be. -- 2: Use the trial and error or eyeball method to tweek them where you -- want them to be. This is ok now that you understand that your NOT -- dealing with COLUMN numbers but DIALOG UNITS. -- -- But if your program is using constant changes of fonts in the list box -- you got to use the first method and alot of extra code and also you got -- to deal with column labels that need to be moved around. -- -- Hee, hee, guess which method I used. -- -- In the example below you will have to have the LBS_USETABSTOPS -- style constant enabled as explained above. -- You have to send a message to your listbox to tell it how to set the tab -- stops. -- -- sendMessage(ListHandle,LB_SETTABSTOPS,NumberOfTabStops,TabArrayAddress) -- with the following parameters. -- -- If the NumberOfTabStop parameter is zero and the TabArrayAddress -- parameter is 0 (NULL), the default tab stop is set to two dialog box -- units. If NumberOfTabStop is 1, the list box will have tab stops -- separated by the distance specified by TabArrayAddress ( a single number -- value is used here not a pointer to an array. If TabArrayAddress points -- to more than a single value ( in other word a pointer to a array ), a -- tab stop will be set for each value in TabArrayAddress, up to the number -- specified by NumberOfTabStop. -- This example WORKS and shows you how to set tabs in a list box -- I used the list box example out of david cuny's win32lib -- and modified it to show you how to use tabs in a listbox. -- Bernie include win32lib.ew without warning constant Win = create( Window, "List", 0, Default, Default, 600, 220, 0 ), List1 = create( List, "", Win, 10, 10, 520, 140, 0 ), Button1 = create( PushButton, "FONT...", Win, 10, 150, 60, 32, 0 ) constant LB_SETTABSTOPS = #192 -- used to send list box message sequence myListTabs atom ctr procedure SetListTabStops( atom ListHandle, sequence TabStops ) atom NumberOfTabStops atom TabArrayAddress -- address of integer array of TAB stops atom pokeAt atom ret sequence bytes -- Build and array of integers in memory to pass to windows -- allot bytes for each tab stop element to build a 32 bit tab array TabArrayAddress = allocate( length( TabStops ) * 4 ) -- start poking at tab array address pokeAt = TabArrayAddress -- poke the values into the tab array address for i = 1 to length( TabStops ) do -- convert Euphoria tab stop integer number to machine byte integer bytes = int_to_bytes( TabStops[i] ) -- poke into tab array in memory poke( pokeAt, bytes ) -- go to the next pokeAt = pokeAt + 4 end for NumberOfTabStops = length( TabStops ) -- calulates the number of tab stops -- send a windows message to the list box to set tab stops ret = sendMessage( ListHandle, LB_SETTABSTOPS, NumberOfTabStops, TabArrayAddress) free(TabArrayAddress) end procedure procedure onLoad_Win() -- Notice the \t tab character in the strings, text will left justify, -- on coloumn, note a space in front of single digit numbers. -- Labels would have to be displayed on the edge above the listbox -- columns because there is no way to combine the labels with list -- strings. -- Build the list using Derek Brown's football information addItem( List1, "QB\t 2\tBryant\t50\t17\t93\t84\t15\t32\t13" ) addItem( List1, "QB\t 4\tAlston\t57\t18\t87\t85\t17\t29\t33" ) addItem( List1, "QB\t11\tSpringer\t43\t19\t81\t84\t41\t38\t23" ) addItem( List1, "T\t59\tLeavitt\t23\t90\t13\t11\t13\t13\t86" ) addItem( List1, "T\t64\tByars\t18\t87\t12\t14\t10\t15\t84" ) addItem( List1, "T\t71\tHouse\t19\t71\t15\t15\t15\t11\t93" ) addItem( List1, "T\t74\tMcKellar\t12\t81\t15\t14\t11\t10\t84" ) addItem( List1, "T\t65\tJennings\t16\t80\t11\t13\t13\t12\t84" ) addItem( List1, "T\t50\tBass\t20\t90\t11\t12\t12\t13\t73" ) addItem( List1, "G\t61\tBlackwell\t20\t81\t12\t14\t10\t11\t94" ) end procedure ctr = 0 procedure onClick_Button1() integer index object result -- change the font if ctr != 0 then setFont( List1,"Times New Roman", 10, Bold+Italic ) ctr = 0 elsif ctr = 0 then setFont( List1,"Comic Sans MS Bold", 15, Bold+Italic ) ctr = ctr + 1 end if end procedure onClick[ Button1 ] = routine_id( "onClick_Button1" ) onOpen[ Win ] = routine_id( "onLoad_Win" ) -- This is where I want to put the TAB stops -- !!! NOTE ** THESE ARE NOT COLUMN NUMBERS !!!!! -- read above myListTabs = { 20,35,90,110,130,150,170,190,210,230 } -- Set the stops SetListTabStops(List1, myListTabs) -- Start up the window WinMain( Win ) ----------------------- end of tablist.exw --------------------------------