📄 listview.c
字号:
/*** $Id: listview.c,v 1.18 2005/01/06 08:12:16 limei Exp $**** listview.c: Sample program for MiniGUI Programming Guide** Usage of LISTVIEW control.**** Copyright (C) 2004 Feynman Software.**** License: GPL*/#include <stdio.h>#include <stdlib.h>#include <string.h>#include <sys/stat.h>#include <sys/types.h>#include <minigui/common.h>#include <minigui/minigui.h>#include <minigui/gdi.h>#include <minigui/window.h>#include <minigui/control.h>#include <minigui/mgext.h>#define IDC_LISTVIEW 10#define IDC_CTRL1 20#define IDC_CTRL2 30#define SUB_NUM 3static char * caption [] ={#ifdef _LANG_ZHCN "姓名", "语文", "数学", "英语"#else "Name", "Chinese", "Math", "English"#endif};#define COL_NR TABLESIZE(caption)static char *classes [] ={#ifdef _LANG_ZHCN "1班", "2班", "3班"#else "Grade 1", "Grade 2", "Grade 3"#endif};typedef struct _SCORE{ char *name; int scr[SUB_NUM];} SCORE;static SCORE scores[] ={#ifdef _LANG_ZHCN {"小明", {81, 96, 75}}, {"小强", {98, 62, 84}}, {"小亮", {79, 88, 89}}, {"小力", {79, 88, 89}},#else {"Tom", {81, 96, 75}}, {"Jack", {98, 62, 84}}, {"Merry", {79, 88, 89}}, {"Bob", {79, 88, 89}},#endif};#define SCORE_NUM TABLESIZE(scores)static GHANDLE add_class_item (HWND hlist, PLVITEM lvItem, GHANDLE classent){ LVSUBITEM subdata; GHANDLE item = SendMessage (hlist, LVM_ADDITEM, classent, (LPARAM)lvItem); subdata.nItem = lvItem->nItem; subdata.subItem = 0; subdata.pszText = classes[lvItem->nItem];; subdata.nTextColor = 0; subdata.flags = 0; subdata.image = 0; SendMessage (hlist, LVM_SETSUBITEM, item, (LPARAM) & subdata); return item;}static GHANDLE add_score_item (HWND hlist, PLVITEM lvItem, GHANDLE classent){ char buff[20]; LVSUBITEM subdata; GHANDLE item = SendMessage (hlist, LVM_ADDITEM, classent, (LPARAM)lvItem); int i = lvItem->nItem; int j; subdata.flags = 0; subdata.image = 0; subdata.nItem = lvItem->nItem; for (j = 0; j < 4; j ++) { subdata.subItem = j; if (j == 0) { subdata.pszText = scores[i].name; subdata.nTextColor = 0; } else { sprintf (buff, "%d", scores[i].scr[j-1]); subdata.pszText = buff; if (scores[i].scr[j-1] > 90) subdata.nTextColor = PIXEL_red; else subdata.nTextColor = 0; } SendMessage (hlist, LVM_SETSUBITEM, item, (LPARAM) & subdata); } return item;}static intScoreProc (HWND hDlg, int message, WPARAM wParam, LPARAM lParam){ HWND hListView; hListView = GetDlgItem (hDlg, IDC_LISTVIEW); switch (message) { case MSG_INITDIALOG: { int i, j; LVITEM item; LVCOLUMN lvcol; GHANDLE hitem; for (i = 0; i < COL_NR; i++) { lvcol.nCols = i; lvcol.pszHeadText = caption[i]; lvcol.width = 120; lvcol.pfnCompare = NULL; lvcol.colFlags = 0; SendMessage (hListView, LVM_ADDCOLUMN, 0, (LPARAM) &lvcol); } item.nItemHeight = 25; SendMessage (hListView, MSG_FREEZECTRL, TRUE, 0); hitem = 0; for (i = 0; i < 3; i++) { item.nItem = i; hitem = add_class_item (hListView, &item, 0); for (j = 0; j < SCORE_NUM; j++) { item.nItem = j; add_score_item (hListView, &item, hitem); } } SendMessage (hListView, MSG_FREEZECTRL, FALSE, 0); break; } case MSG_COMMAND: { int id = LOWORD (wParam); int i, j; if (id == IDC_CTRL2) { float average = 0; char buff[20]; for (i = 0; i < SCORE_NUM; i++) { for (j = 0; j < SUB_NUM; j++) { average += scores[i].scr[j]; } } average = average / (SCORE_NUM * SUB_NUM); sprintf (buff, "%4.1f", average); SendDlgItemMessage (hDlg, IDC_CTRL1, MSG_SETTEXT, 0, (LPARAM)buff); } break; } case MSG_CLOSE: { EndDialog (hDlg, 0); break; } } return DefaultDialogProc (hDlg, message, wParam, lParam);}static CTRLDATA CtrlScore[] ={ { "button", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, 80, 260, 110, 40, IDC_CTRL2,#ifdef _LANG_ZHCN "求总平均分",#else "Everage score",#endif 0 }, { "edit", WS_CHILD | WS_VISIBLE | WS_BORDER, 10, 260, 50, 20, IDC_CTRL1, "", 0 }, { "listview", WS_BORDER | WS_CHILD | WS_VISIBLE | WS_VSCROLL | WS_HSCROLL | LVS_TREEVIEW, 10, 10, 320, 220, IDC_LISTVIEW, "score table", 0 },};static DLGTEMPLATE DlgScore ={ WS_BORDER | WS_CAPTION, WS_EX_NONE, 0, 0, 480, 340,#ifdef _LANG_ZHCN "求平均分",#else "Getting the average score",#endif 0, 0, 0, NULL, 0};int MiniGUIMain (int argc, const char* argv[]){#ifdef _LITE_VERSION SetDesktopRect(0, 0, 1024, 768);#endif if (!InitMiniGUIExt()) { return 2; } DlgScore.controls = CtrlScore; DlgScore.controlnr = TABLESIZE(CtrlScore); DialogBoxIndirectParam (&DlgScore, HWND_DESKTOP, ScoreProc, 0L); MiniGUIExtCleanUp (); return 0;}#ifndef _LITE_VERSION#include <minigui/dti.c>#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -