HWND g_hList;
LRESULT CALLBACK WndProc(HWND hWnd,UINT iMessage,WPARAM wParam,LPARAM lParam)
{
static HWND s_hList;
switch (iMessage) {
case WM_CREATE: {
s_hList = CreateWindow(TEXT("listbox"), NULL, WS_CHILD | WS_VISIBLE | WS_BORDER |
LBS_NOTIFY, 10, 10, 100, 200, hWnd, (HMENU)ID_LISTBOX, g_hInst, NULL);
for (int i=0; i<5; i++) { SendMessage(s_hList, LB_ADDSTRING, 0, (LPARAM)Items[i]); }
}
return 0;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
case WM_COMMAND:
switch (LOWORD(wParam)) {
case ID_LISTBOX:
switch (HIWORD(wParam)) {
case LBN_SELCHANGE: {
TCHAR str[128];
int i = SendMessage(s_hList, LB_GETCURSEL, 0, 0);
SendMessage(s_hList, LB_GETTEXT, i, (LPARAM)str);
SetWindowText(hWnd, str);
}
break;
}
}
return 0;
}
return (DefWindowProc(hWnd, iMessage, wParam, lParam));
}
static const CString out_string[] = {
_T("..."),
_T("...")
};
for (int nIndex=0; nIndex < sizeof(out_string) / sizeof(CString); nIndex++)
::SendMessage(m_hWnd, LB_ADDSTRING, 0, (LPARAM)(LPCTSTR)out_string[nIndex]);