*   >> läser Utbildning artiklar >> science >> programming

Skapa Combo Boxes

används inte (ställ in den till NULL). Den lParam är av typen LPCTSTR och är en pekare till nollterminerade sträng som ska läggas till. Returvärdet är nollbaserade indexet till strängen i listrutan i kombinationsrutan. Om ett fel inträffar, är returvärdet CB_ERR. Om tillräckligt utrymme finns för att lagra den nya strängen, är det CB_ERRSPACE.

Här är ett exempel program för att skapa en enkel listrutan: #include using namespace std; LResult ÅTER MainWndProc (HWND hwnd, UINT uMsg, WPARAM wParam, lParam lParam) {switch (uMsg) {default: tillbaka DefWindowProc (hwnd, uMsg, wParam, lParam); } Återvända 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", "Huvudfönstret", 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örsta strängen."; const char * str2 = "den andra strängen."; const char * str3 = "den tredje strängen.

"; const char * str4 = "den fjärde strängen."; const char * str5 = "den femte strängen."; 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) {//hantera felet och eventuellt avsluta programmet} else {TranslateMessage (& msg); DispatchMessage (& msg); }} Återvända msg.

wParam; } Du kan använda följande kommando vid kommandotolken för att kompilera koden: g ++ wincb.cpp -mwindows -o wincb.exe Du kan lägga till rullningslister med hjälp av Windows stilar, WS_VSCROLL och /

Page   <<  [1] [2] [3] >>
Copyright © 2008 - 2016 läser Utbildning artiklar,https://utbildning.nmjjxx.com All rights reserved.