写一个简单的列表框,minigui的
时间: 2024-02-26 10:58:15 浏览: 93
好的,以下是一个简单的 MiniGUI 窗口程序,其中包含一个列表框:
```c
#include <stdio.h>
#include "minigui.h"
static const char* items[] = {
"Item 1",
"Item 2",
"Item 3",
"Item 4",
"Item 5",
};
static int WinProc(HWND hWnd, int message, WPARAM wParam, LPARAM lParam)
{
switch (message) {
case MSG_CREATE:
CreateListBox(hWnd, IDC_LISTBOX, WS_CHILD | WS_VISIBLE | WS_VSCROLL,
10, 10, 200, 100, items, sizeof(items)/sizeof(char*));
break;
case MSG_COMMAND:
if (LOWORD(wParam) == IDC_LISTBOX && HIWORD(wParam) == LBN_SELCHANGE) {
int index = SendMessage(hWnd, LB_GETCURSEL, IDC_LISTBOX, 0);
printf("Selected item index: %d\n", index);
}
break;
case MSG_CLOSE:
DestroyAllControls(hWnd);
DestroyMainWindow(hWnd);
PostQuitMessage(hWnd);
return 0;
}
return DefaultMainWinProc(hWnd, message, wParam, lParam);
}
int MiniGUIMain(int argc, const char* argv[])
{
MSG Msg;
HWND hMainWnd;
if (RegisterMainWindowClass() == -1) {
return -1;
}
hMainWnd = CreateMainWindow("MiniGUI Listbox Demo", WS_CAPTION | WS_BORDER,
0, 0, 220, 150, NULL, NULL, argv[0]);
if (hMainWnd == HWND_INVALID) {
return -1;
}
ShowWindow(hMainWnd, SW_SHOWNORMAL);
while (GetMessage(&Msg, hMainWnd)) {
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
return 0;
}
```
这个程序创建了一个主窗口,包含了一个列表框。列表框中包含了一个字符串数组,用于显示列表项内容。当用户选择列表项时,程序会输出所选项的索引到控制台窗口中。
阅读全文