List box:
Type and style of the list box
Win32 API provides two types of list boxes: 1, single selection (default) 2, can be multiple selected. In the radio list box, the user can only select one at the same time. In the multi-selection list box, the user can select a number. Create a multi-selection list box, you want to specify the LBS_MULTIPLESEL or LBS_EXTENDEDSEL style.
Win32 API provides a style of another list box, and those styles include: whether list box items need to be sorted, do they need multiple columns, etc. The size and style of the list box are typically defined in the application's resources.
Message of the list box
The message of the list box is included in WM_COMMAND, and the LOWORD (WPARAM) is a list box identifier, and it is a specific message in HiWord (WPARAM). Some messages are processed by Windows, some messages should be processed by program, such messages include:
LBN_DBLCLK / / Double click on one of the list boxes
LBN_ERRSPACE / / list box cannot assign enough memory to implement one requirement
LBN_KILLFOCUS / / list box lost keyboard focus
LBN_SELCANCEL / / Cancel to a certain item
The LBN_SELCHANGE / / The selected items are changed in the list box.
LBN_SETFOCUS / / list box Get the keyboard focus
Messages sent to the list box with SendMessage or SenddlgiteMmessage include
LB_ADDFILE / / Use the DLGDIRLIST function to add a file into the directory list box and return to the index
LB_ADDString // Add String to List Box Returns Index
LB_DELETESTRING / / Remove a string from the list box Back to the list box remaining menu
LB_DIR / / Add a file name list, return the last addition of the index of the file name
LB_FINDSTRING / / Returns the first index matching the specified string
LB_FINDSTRINGEXACT / / Returns an index with a specified prefix
LB_GETANCHORINDEX / / Returns the index of the item last selected item
LB_GETCARETINDEX / / Returns an index with a rectangular focus
LB_GETCOUNT / / Return to the number of items in the list box
LB_GETCURSEL / / Returns the index of the currently selected item
LB_gethorizontalExtent // Return the scrollable width of the list box (unit: pixel)
LB_GETITEMDATA / / Return and gives 32-bit values associated with given
LB_GETITEMHEIGHT / / Returns the height of a certain item in the list box (unit: pixel)
LB_GETITEMRECT / / Review of the client area of the list item
LB_GETLOCALE / / Get zone information, high country code, low language identifier
LB_getsel // Returns the list item to select the status
LB_GetselCount // Returns the number of selected list items
LB_GetSeliteMs // Create an index array of selected items, returns the number of selected items
LB_GETTEXT / / String and string length associated with the given item
LB_GETTEXTLEN // Return and give a string length (unit: character)
LB_GettopIndex // Returns the index of the first visible item in the list box
LB_INITSTORAGE / / Assign memory for the specified number of items and related strings
LB_INSERTSTRING / / Inserted in the list box Insert strings
LB_ItemFromPoint // Get indexes with the most recent items in the specified point
LB_RESETCONTENT / / Remove all items LB_SELECTSTRING // from the list box Select the first string matching the given prefix
LB_SELITEMRANGE / / Select an entry within a given range
LB_setanchorIndex // Set the final selected table item into a specified entry
LB_SETCARETINDEX / / Setting Rectangular Focus to Specified Entries
LB_setColumnWidth // Set the width of the column (unit: pixel)
LB_SETCOUNT // Setup item number
LB_SETCURSEL / / Select the list item given
LB_SETHORIZONTALEXTENT / / Sets the scroll width of the list box (unit: pixel)
LB_SETITEMHIEGHT // Setup entry height (unit: utensil)
LB_SETLOCALE / / Setting area, return to the current area
LB_setsel // Select a group in the multi-selection list box
The LB_SettopIndex // scroll list allows the specified item to display
Create a simple list box:
The following list presentation creates a list box in the dialog box, fill in the list item with the athlete name, when the athlete is selected, the corresponding information is displayed in the dialog box.
The style lbs_standard of the list box is LBS_SORT, LBS_NOTIFY, WS_VSCROLL, and WS_BORDER. Processing the initialization list box when the dialog is connected to the WM_INITDIALOG message, in order to display each name in the list box, send LB_ADDString to the list box.
#define buffer max_path
#define namelength 15
#define positionLENGTH 20
#define teamsize 15
Typedef struct
{
TCHAR TCHNAME [NameLength];
TCHAR TCHPSITION [POSITIONLENGTH];
Int ngamesplayed;
INT NINNINGSPLAYED;
Double Xbattingaverage;
Tchar tchfoodname [nameLength];
} Player;
Player roster [] =
{
{"Alan", "Center Field", 17, 56, .375, "cannelloni"},
{"Colin", "Pitcher", 26, 96, .456, "lefse"}
{"Cindy", "SECOND BASE", 13, 58, .207, "tequila"}
{"Dave", "First Base", 28, 138, .508, "suds"}
{"DAVID", "Center Field", 18, 101, .612, "bok choy"}
{"Jack", "Pitcher", 27, 110, .542, "animal crackers"}
{"Julie", "Right Field", 22, 101, .509, "Mashed Potatoes"}
{"Karen", "SECOND BASE", 26, 140, .238, "pez"},
{"Kathie", "Left Field", 26, 127, .353, "baba ganouj"}, {"matt", "shortstop", 24, 112, .579, "oats"}
{"Miriam", "Right Field", 24, 112, .393, "zotz"}
{"Pete", "shortstop", 26, 90, .608, "beet"},
{"Sth", "Center Field", 20, 76, .407, "Otter Pop"},
{"Suzanna", "Catcher", 16, 53, .286, "toast"},
{"Wendy", "Third Base", 25, 154, .493, "ham"},
}
Bool apientry dlgteamproc
HWND HDLG, // Dialog Handle
Uint message, // message
Uint wparam, // message-specific information
Long lparam) // message-specific information
{
TCHAR TCHBUFFER [BUFFER];
Int Nitem;
INT I;
HWND HWNDLIST;
Switch (Message)
{
Case WM_INITDIALOG:
{
HWndList = getdlgitem (HDLG, IDL_Softball);
// Initialize the list box (with the athlete name).
For (i = 0; i { SendMessage (hwndlist, lb_addstring, 0, (LParam) Roster [i] .tchname); SendMessage (HWndList, LB_SETITEMDATA, I, (LPARAM) i); } Setfocus (hwndlist); Return False; } Case WM_COMMAND: Switch (loword (wparam)) { Case id1_softball: Switch (HiWord (WPARAM)) { Case LBN_Selchange: // Show the selected Player's Statistics. HWndList = getdlgitem (HDLG, IDL_Softball); NITEM = SendMessage (hwndlist, lb_getcursl, 0, 0); i = sendMessage (hwndlist, lb_getitemdata, NIITEM, 0); Setdlgitemtext (HDLG, IDS_POS, Roster [i] .tchposition; Setdlgitemtext (HDLG, IDS_GAME, _itoa (roster [i] .ngamesplayed, TCHBUFFER, 10)); Setdlgitemtext (HDLG, IDS_INN, _itoa (roster [i] .ninningsplayed, TCHBUFFER, 10)); Setdlgitemtext (HDLG, IDS_BA, _GCVT (Roster [i] .Xbattingaverage, 3, tchbuffer); Setdlgitemtext (HDLG, IDS_FOOD, ROSTER [i] .tchfoodname); Return True; } Break; Case IDOK: Case IDCANCEL: // deStroy the dialog box. EndDialog (HDLG, TRUE); Return True; DEFAULT: Return False; } DEFAULT: Return False; } } If you have any comments, please email: y_h_zhang@sohu.com