Her er et eksempel program for å lage en enkel liste boks: # include bruker namespace std; LRESULT RING TILBAKE MainWndProc (HWND hwnd, UINT uMsg, wParam wParam, lParam lParam) {switch (uMsg) {standard: returnere DefWindowProc (hwnd, uMsg, wParam, lParam); } Return 0; } Int WinAPI winmain (hInstance hInstance, hInstance hPrevInstance, LPSTR lpCmdLine, int nCmdShow) {WNDCLASSEX wcx; wcx.cbSize = sizeof (wcx); wcx.style = CS_HREDRAW | CS_VREDRAW; wcx.lpfnWndProc = MainWndProc; wcx.cbClsExtra = 0; wcx.cbWndExtra = 0; wcx.hInstance = hInstance; wcx.hIcon = NULL; wcx.
hCursor = LoadCursor (NULL, IDC_ARROW); wcx.hbrBackground = (HBRUSH) (COLOR_BACKGROUND + 1); wcx.lpszMenuName = NULL; wcx.lpszClassName = "MainWClass"; wcx.hIconSm = NULL; RegisterClassEx (& wcx); HWND hwndMain; hwndMain = CreateWindowEx (0, "MainWClass", "hovedvinduet", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInstance, NULL); if (hwndMain!) return false; Showwindow (hwndMain, SW_SHOW); UpdateWindow (hwndMain); const char * str1 = "den første strengen."; const char * str2 = "den andre strengen."; const char * str3 = "den tredje strengen.
"; const char * str4 = "fjerde streng."; const char * str5 = "den femte streng."; HWND hwndCb; hwndCb = CreateWindowEx (0, "COMBOBOX", NULL, WS_CHILD | CBS_SIMPLE, 100, 100, 100, 150, hwndMain, (HMENU) 1, hInstance, NULL); Showwindow (hwndCb, SW_SHOW); UpdateWindow (hwndCb); Sendmessage (hwndCb, CB_ADDSTRING, NULL, (lParam) str1); Sendmessage (hwndCb, CB_ADDSTRING, NULL, (lParam) str2); Sendmessage (hwndCb, CB_ADDSTRING, NULL, (lParam) str3); Sendmessage (hwndCb, CB_ADDSTRING, NULL, (lParam) str4); Sendmessage (hwndCb, CB_ADDSTRING, NULL, (lParam) str5); MSG msg; BOOL BRET; while ((Bret = GetMessage (& msg, hwndMain, 0, 0)) = 0) {if (Bret == -1) {//håndtere feil og muligens avslutte programmet} else {TranslateMessage (& msg); DispatchMessage (& msg); }} Returnere msg.
wParam; } Du kan bruke følgende kommando ved ledeteksten for å kompilere koden: g ++ wincb.cpp -mwindows -o wincb.exe Du kan legge rullefelt ved hjelp av Windows stiler, WS_VSCROLL og /eller WS_HSCROLL (se senere). Opprette en Drop Down kombinas