minigui滑动列表
时间: 2023-08-15 08:03:18 浏览: 213
MiniGUI中的滑动列表可以通过使用LISTVIEW控件来实现。以下是一个简单的示例代码:
```c
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "resource.h"
static HWND hMainWnd;
static HWND hListView;
static HINSTANCE hInstance;
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
{
MSG msg;
WNDCLASS wc;
hInstance = hInst;
memset(&wc, 0, sizeof(wc));
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc = WndProc;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_MAIN_ICON));
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
wc.lpszClassName = "MainWindowClass";
RegisterClass(&wc);
hMainWnd = CreateWindow("MainWindowClass", "ListView Sample",
WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT,
400, 300, NULL, NULL, hInstance, NULL);
if (!hMainWnd) {
return FALSE;
}
ShowWindow(hMainWnd, nShowCmd);
UpdateWindow(hMainWnd);
while (GetMessage(&msg, NULL, 0, 0)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message) {
case WM_CREATE:
hListView = CreateWindow(MGUI_LISTVIEW, "", WS_VISIBLE | WS_CHILD | WS_BORDER | LVS_REPORT,
10, 10, 360, 240, hWnd, (HMENU)1, hInstance, NULL);
ListView_SetExtendedListViewStyle(hListView, LVS_EX_GRIDLINES | LVS_EX_FULLROWSELECT);
ListView_InsertColumn(hListView, 0, "Name", LVCFMT_LEFT, 100, 0);
ListView_InsertColumn(hListView, 1, "Age", LVCFMT_LEFT, 100, 1);
ListView_InsertItem(hListView, 0, "Tom", 0);
ListView_SetItemText(hListView, 0, 1, "25");
ListView_InsertItem(hListView, 1, "Jerry", 1);
ListView_SetItemText(hListView, 1, 1, "30");
ListView_InsertItem(hListView, 2, "Mickey", 2);
ListView_SetItemText(hListView, 2, 1, "20");
ListView_InsertItem(hListView, 3, "Donald", 3);
ListView_SetItemText(hListView, 3, 1, "35");
ListView_InsertItem(hListView, 4, "Daisy", 4);
ListView_SetItemText(hListView, 4, 1, "28");
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}
```
在这个例子中,我们使用`CreateWindow()`函数创建了一个LISTVIEW控件,并在其中插入了5个项。我们使用`ListView_InsertColumn()`函数来插入列,使用`ListView_InsertItem()`函数来插入项,使用`ListView_SetItemText()`函数来设置项中的文本。`ListView_SetExtendedListViewStyle()`函数用于设置LISTVIEW控件的样式。
在MiniGUI中,LISTVIEW控件支持滚动和拖拽操作,因此可以很容易地实现滑动列表的效果。
阅读全文