TIP: Click on subject to list as thread! ANSI
echo: os2prog
to: Graeme Geldenhuys
from: Darin McBride
date: 1996-07-14 12:43:16
subject: Dropdown List Box info needed...

GG> Hello All!

 GG> I am fairly new to OS/2 PM programming, and was 
 GG> wondering if someone could help shedd some light on 
 GG> this subject for me.

I haven't done _any_ PM programming, but I'll take a shot at it.  I *have*
done what you want to do under Windows, and the API's aren't drastically
different.

 GG> I created an array with 3 values in it..
 GG> CHAR szSource[3][15] = {"Compact
Disk","Tape","Radio"};

 GG> I then sent this info to a dropdown list box with the following commands..

 GG>   for(i=0;i<3;i++)
 GG>     WinSendDlgItemMsg (hWnd, IDC_SOURCE, LM_INSERTITEM, (MPARAM)LIT_END,
 GG>        szSource[i]);

Sure... although OS/2 has a "function" to do the function call for you:

LONG WinInsertLboxItem(HWND hwndLbox, LONG index, PSZ psz)

So, your code becomes:

HWND hwndLbox = WinWindowFromID(hWnd, IDC_SOURCE);
for (i=0; i<3; ++i)
  WinInsertLboxItem(hwndLbox, LIT_END, szSource[i]);

IMO, this is a little cleaner.  YMMV.

 GG> This worked fine as far as I know...  If I now click on 
 GG> the downarrow next to the list box, it displays the 
 GG> three options to me.  If I done it the correct way, I 
 GG> got no idea...  :-)

Yes, it works fine.  :-)

 GG> Well, my problem now is, I don't know how to find out 
 GG> what option the user has selected from the list.  How 
 GG> do I get that info from the program...?

Assuming you still have hwndLbox from above, try:

int nChoiceSelected = WinQueryLboxSelectedItem(hwndLbox);

This will be 0-2, LIT_NONE (if nothing is selected), or LIT_ERROR (if an
error occurred).

If it is LIT_ERROR, WinGetLastError will return PMERR_INVALID_HWND (0x1001).

A better choice may be to get the text from the dropdown, unless you want
the number anyway.

int nLengthOfSelectedText = WinQueryDlgItemTextLength(hWnd, IDC_SOURCE);
         or               = WinQueryWindowTextLen(hwndLbox);
char* pszSelectedString = malloc((nLengthOfSelectedText+1) * sizeof(char));
WinQueryDlgItemText(hWnd, IDC_SOURCE, nLengthOfSelectedText, pszSelectedString)
/* or */
WinQueryWindowText(hwndLbox, nLengthOfSelectedText, pszSelectedString);

 GG> Also when I open the dialog box, it doesn't display an 
 GG> initial value in the list box, you must always click on 
 GG> the downarrow first to see the options, before it 
 GG> displays anything.  How can I overcome that, so that it 
 GG> displays the first option in the array as default when 
 GG> I open the dialog.

Surprisingly, I cannot find a WinSetLboxSelectedItem function/macro.  :-/ 
However, you probably want to:

WinSetDlgItemText(hWnd, IDC_SOURCE, szSource[nDefaultItem]);

or

WinSetWindowText(hwndLbox, szSource[nDefaultItem]);

Hope this helps, Graeme.  :-)  No warranty - I don't write PM (yet).  :-)


--- Maximus/2 3.01
* Origin: Tanktalus' Tower BBS (PVT) (1:342/708)
SEEN-BY: 50/99 270/101 620/243 625/100 711/401 409 410 413 430 808 809 934
SEEN-BY: 711/955 712/407 515 517 624 628 713/888 800/1
@PATH: 342/5015 61 3615/50 396/1 270/101 712/515 711/808 934

SOURCE: echomail via fidonet.ozzmosis.com

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.