Skip to main content
GameDev.net gamedev.net
🔒 Locked

List Boxes

Started by xg0blin May 12, 2003 at 6:25 PM 0 replies 350+ views
Original Post
xg0blin
xg0blin
I''m was going to use MFC, but I decided to use Win32 for now, although I''d like to learn how to hand-code MFC, I don''t like using the appwizard much. I have a new problem now. I''ve done lots of opengl apps, but I never used controls other than buttons and such. With this source code:
  
#include <windows.h>

#define WINWIDTH 500
#define WINHEIGHT 700

LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
{
	HWND hMainWnd, IdentStatic, IdentEdit, CanStatic, CanList;
	WNDCLASSEX wcex;
	MSG msg;

	wcex.cbClsExtra = 0;
	wcex.cbSize = sizeof(WNDCLASSEX);
	wcex.cbWndExtra = 0;
	wcex.hbrBackground = (HBRUSH)COLOR_BACKGROUND;
	wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
	wcex.hIcon = LoadIcon(NULL, IDI_APPLICATION);
	wcex.hIconSm = NULL;
	wcex.hInstance = hInstance;
	wcex.lpfnWndProc = WndProc;
	wcex.lpszClassName = "InlandMainWnd";
	wcex.lpszMenuName = NULL;
	wcex.style = CS_VREDRAW|CS_HREDRAW;

	RegisterClassEx(&wcex);

	hMainWnd = CreateWindow("InlandMainWnd", "Inland Services - Main Viewer", WS_OVERLAPPEDWINDOW,
		                    CW_USEDEFAULT, CW_USEDEFAULT, WINWIDTH, WINHEIGHT, NULL, NULL, hInstance, NULL);
	IdentStatic = CreateWindow("STATIC", "Indentifier:", WS_CHILD|WS_VISIBLE, 30, 30, 75, 18,
							   hMainWnd, NULL, hInstance, NULL);
	IdentEdit = CreateWindow("EDIT", " ", WS_CHILD|WS_VISIBLE, 110, 30, 350, 18, 
		                     hMainWnd, NULL, hInstance, NULL);
	CanStatic = CreateWindow("STATIC", "Can Size:", WS_CHILD|WS_VISIBLE, 30, 50, 75, 18,  hMainWnd, 
		                     NULL, hInstance, NULL);
	CanList = CreateWindow("LISTBOX", "60 Gallon", WS_CHILD|WS_VISIBLE, 110, 50, 100, 18, hMainWnd,
		                   NULL, hInstance, NULL);
	if(!hMainWnd)
		MessageBox(NULL, "Create Window Failed", "ERROR", MB_OK);
	
	ShowWindow(hMainWnd, nShowCmd);
	UpdateWindow(hMainWnd);

	while(true)
	{
		if(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
		{	
			if(msg.message == WM_QUIT)
				break;

			TranslateMessage(&msg);
			DispatchMessage(&msg);
		}
	}
	
	return EXIT_SUCCESS;
}

LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
	switch(uMsg)
	{
		case WM_QUIT:
		case WM_DESTROY:
			PostQuitMessage(0);
			break;
		case WM_KEYDOWN:
			switch(wParam)
			{
				case VK_ESCAPE:
					PostQuitMessage(0);
			}
			break;
	}
	return DefWindowProc(hWnd, uMsg, wParam, lParam);
}
  
How would I go about adding options to my listbox, and getting the output when it returns what they picked. Thank you in advance.
ChaosEngine
ChaosEngine
well you''d make your life a lot easier with mfc, but if you want to use win32

LB_ADDSTRING Message

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

An application sends an LB_ADDSTRING message to add a string to a list box. If the list box does not have the LBS_SORT style, the string is added to the end of the list. Otherwise, the string is inserted into the list and the list is sorted.

Syntax


To send this message, call the SendMessage function as follows.
lResult = SendMessage( // returns LRESULT in lResult (HWND) hWndControl, // handle to destination control (UINT) LB_ADDSTRING, // message ID (WPARAM) wParam, // = (WPARAM) () wParam; (LPARAM) lParam // = (LPARAM) () lParam; );
Parameters

wParam
This parameter is not used.
lParam
Pointer to the null-terminated string that is to be added.
If you create the list box with an owner-drawn style but without the LBS_HASSTRINGS style, this parameter is stored as item data instead of the string to which it would otherwise point. You can send the LB_GETITEMDATA and LB_SETITEMDATA messages to retrieve or modify the item data.

Return Value

The return value is the zero-based index of the string in the list box. If an error occurs, the return value is LB_ERR. If there is insufficient space to store the new string, the return value is LB_ERRSPACE.

and

LB_GETCURSEL Message

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

Send an LB_GETCURSEL message to retrieve the index of the currently selected item, if any, in a single-selection list box.

Syntax


To send this message, call the SendMessage function as follows.
lResult = SendMessage( // returns LRESULT in lResult (HWND) hWndControl, // handle to destination control (UINT) LB_GETCURSEL, // message ID (WPARAM) wParam, // = (WPARAM) () wParam; (LPARAM) lParam // = (LPARAM) () lParam; );
Parameters

wParam
Not used; must be zero.
lParam
Not used; must be zero.
Return Value

In a single-selection list box, the return value is the zero-based index of the currently selected item. If there is no selection, the return value is LB_ERR.







"That''s not a bug, it''s a feature!"
--me
if you think programming is like sex, you probably haven't done much of either.-------------- - capn_midnight

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.