*   >> Læs Uddannelse artikler >> science >> programming

Oprettelse af en liste Box

tilstrækkelig plads til at gemme den nye streng, er returværdien LB_ERRSPACE. Disse slags afkast værdier er identifikatorer til konstanter. Her er et eksempel program til at oprette en liste boks: #include bruge namespace std; LRESULT tilbagekald MainWndProc (HWND HWND, UINT uMsg, wParam wParam, lParam lParam) {switch (uMsg) {standard: returnere DefWindowProc (HWND, uMsg, wParam, lParam); } Returnere 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); hvis (hwndMain!) return false; ShowWindow (hwndMain, SW_SHOW); UpdateWindow (hwndMain); const char * str1 = "den første streng.

"; const char * str2 = "den anden streng."; const char * str3 = "den tredje streng."; const char * str4 = "den fjerde streng."; const char * str5 = "den femte streng."; HWND hwndLst; hwndLst = CreateWindowEx (0, "listefeltet", NULL, WS_CHILD, 100, 100, 100, 150, hwndMain, (HMENU) 1, hInstance, NULL); ShowWindow (hwndLst, SW_SHOW); UpdateWindow (hwndLst); SendMessage (hwndLst, LB_ADDSTRING, NULL, (lParam) str1); SendMessage (hwndLst, LB_ADDSTRING, NULL, (lParam) str2); SendMessage (hwndLst, LB_ADDSTRING, NULL, (lParam) str3); SendMessage (hwndLst, LB_ADDSTRING, NULL, (lParam) str4); SendMessage (hwndLst, LB_ADDSTRING, NULL, (lParam) str5); MSG msg; BOOL BRET; mens ((Bret = GetMessage (& msg, hwndMain, 0, 0)) = 0!) {if (Bret == -1) {//håndtere fejlen og eventuelt afslutte programmet} else {TranslateMessage (& msg); DispatchMessage (& msg); }} Tilbage msg.

wParam; } Du kan bruge følgende kommando ved kommandoprompten for at kompilere koden: g ++ winlst.cpp -mwindows -o winlst.exe Listen kasse skabt af ovenstående kode er en enkelt-valgliste kassen. Du kan ikke have mere end ét element valgt (markeret). Du kan tilføje scrollbars hjælp af Windows stilarter, WS_VSCROLL og /eller WS_HSCROLL (se senere). Oprettelse af Multiple-Selection List Box For at oprette en enkelt

Page   <<  [1] [2] [3] >>
Copyright © 2008 - 2016 Læs Uddannelse artikler,https://uddannelse.nmjjxx.com All rights reserved.