1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
|
/** List Box **/
#define _win32_IE 0x300
#include <windows.h>
#include <commctrl.h>
#include <string>
#define MAX_LIST 20
#define IDC_LISTBOX 1
typedef struct tagMOBS
{
WCHAR szMonsters[MAX_LIST];
} MOBS;
MOBS argMobs[] =
{
{L"Andariel"},{L"Duriel"},{L"Mephisto"},{L"Diablo"},{L"Baal"},
{L"Izual"},{L"Contess"},{L"The Summoner"},{L"Nihlathak"},{L"Bartuc the Bloody"}
};
HINSTANCE hInst;
HWND InitListBox(HWND hwnd)
{
HWND hListBox;
hListBox = CreateWindowW(L"LISTBOX", NULL, WS_CHILD | WS_VISIBLE | WS_BORDER | WS_VSCROLL,
15, 15, 200, 250, hwnd, (HMENU)IDC_LISTBOX, hInst, NULL);
for(int i = 0; i < ARRAYSIZE(argMobs); i++)
{
int pos = (int)SendMessage(hListBox, LB_ADDSTRING, 0, (LPARAM)argMobs[i].szMonsters);
SendMessage(hListBox, LB_SETITEMDATA, pos, (LPARAM)i);
}
SetFocus(hListBox);
return (hListBox);
}
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
{
switch(msg)
{
case WM_CREATE:
{
InitListBox(hwnd);
break;
}
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProcW(hwnd, msg, wp, lp);
}
return 0;
}
int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPevInst, LPSTR args, int nCmdShow)
{
InitCommonControls();
HWND hwnd;
WNDCLASSW wc = {0};
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hbrBackground = (HBRUSH)COLOR_WINDOW;
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wc.hInstance = hInst;
wc.lpfnWndProc = WndProc;
wc.lpszClassName = L"myWindowClass";
wc.lpszMenuName = NULL;
wc.style = CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS;
if(!RegisterClassW(&wc))
return -1;
hwnd = CreateWindowW(L"myWindowClass", L"List Box", WS_OVERLAPPEDWINDOW,
350, 130, 700, 500, NULL, NULL, NULL, NULL);
ShowWindow(hwnd, nCmdShow);
UpdateWindow(hwnd);
MSG msg = {0};
while(GetMessage(&msg, NULL, 0, 0) > 0)
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return 0;
}
| |