CTRL_ICONVIEW
数据结构
图标项
typedef struct _IVITEMINFO
{
int nItem; // 图标项的索引值
PBITMAP bmp; // 图标项的图标
const char *label; // 图标项的标签文字
DWORD addData; // 图标项的附加信息
DWORD dwFlags; // 保留
} IVITEMINFO
消息
添加图标项:IVITEMINFO ivii; HANDLE hIconItem = SendMessage (hIconView, IVM_ADDITEM, 0, (LPARAM)&ivii);
设置图标项长宽:int width; int height; SendMessage (hIconView, IVM_SETITEMSIZE, width, height);
清空图标项:IVM_RESETCONTENT
删除图标项:IVM_DELITEM
设置图标项的绘制函数: IVM_SETITEMDRAW
设置滚动窗口的宽度:IVM_SETCONTWIDTH
设置滚动窗口的高度:IVM_SETCONTHEIGHT
设置图标项相关操作的一些回调函数:IVM_SETITEMOPS
获取图标型控件的边缘范围值:IVM_GETMARGINS
设置图标型控件的边缘范围值:IVM_SETMARGINS
获取图标型控件的左、上、右、下边缘值:IVM_GETLEFTMARGIN、IVM_GETTOPMARGIN、IVM_GETRIGHTMARGIN 和 IVM_GETBOTTOMMARGIN
获取内容区域的宽度和高度、可视区域的宽度和高度:IVM_GETCONTWIDTH、IVM_GETCONTHEIGHT、IVM_GETVISIBLEWIDTH 和 IVM_GETVISIBLEHEIGHT
设置滚动窗口的内容区域的大小:IVM_SETCONTRANGE
获取内容区域的当前位置值:IVM_GETCONTENTX 和 IVM_GETCONTENTY
设置内容区域的当前位置值,也就是在可视区域中移动内容区域到某个指定位置:IVM_SETCONTPOS
获取和设置控件的当前高亮图标项:IVM_GETCURSEL 和 IVM_SETCURSEL
选择一个列表项,被选中的项将高亮显示:IVM_SELECTITEM
显示一个图标项:IVM_SHOWITEM
选中一个图标项并使之可见:IVM_CHOOSEITEM,是 IVM_SELECTITEM 和 IVM_SHOWITEM消息的组合
设置图标项的初始操作:IVM_SETITEMINIT
设置图标项的销毁操作:IVM_SETITEMDESTROY
设置图标项的比较函数:IVM_SETITEMCMP
使内容区域中的某个位置点成为可见:IVM_MAKEPOSVISIBLE:对应 SVM_MAKEPOSVISIBLE
获取滚动窗口的当前水平和垂直滚动值(点击滚动条箭头的滚动范围大小):IVM_GETHSCROLLVAL 和 IVM_GETVSCROLLVAL
获取滚动窗口的当前水平和垂直页滚动值(翻页操作时的滚动范围大小):IVM_GETHSCROLLPAGEVAL 和 IVM_GETVSCROLLPAGEVAL
设置滚动窗口的水平和(或者)垂直滚动值:IVM_SETSCROLLVAL
设置滚动窗口的水平和(或者)垂直页滚动值:IVM_SETSCROLLPAGEVAL
对图标项进行一次性的排序:IVM_SORTITEMS
获取当前图标项的数量:IVM_GETITEMCOUNT
获取当前图标项的附加信息:IVM_GETITEMADDDATA
设置当前图标项的附加信息:IVM_SETITEMADDDATA
刷新一个图标项区域:IVM_REFRESHITEM
获取第一个可见的图标:IVM_GETFIRSTVISIBLEITEM
通知
LVN_SELCHANGE:当前高亮图表项发生改变
LVN_CLICKED:用户点击图标项
mg-samples的图标型控件示例
1 #include <stdio.h> 2 #include <stdlib.h> 3 #include <string.h> 4 #include <sys/stat.h> 5 #include <sys/types.h> 6 7 #include <minigui/common.h> 8 #include <minigui/minigui.h> 9 #include <minigui/gdi.h> 10 #include <minigui/window.h> 11 #include <minigui/control.h> 12 13 #define add "Add" 14 #define delete_ "Delete" 15 #define my_friends "My Friends" 16 17 #define IDC_ICONVIEW 100 18 #define IDC_BT 200 19 #define IDC_BT2 300 20 #define IDC_BT3 400 21 #define IDC_BT4 500 22 23 #define IDC_ADD 600 24 #define IDC_DELETE 601 25 26 static HWND hIconView; 27 28 static BITMAP myicons [12]; 29 30 static const char* iconfiles[12] = 31 { 32 "./res/acroread.png", 33 "./res/icons.png", 34 "./res/looknfeel.png", 35 "./res/package_games.png", 36 "./res/tux.png", 37 "./res/xemacs.png", 38 "./res/gimp.png", 39 "./res/kpilot.png", 40 "./res/multimedia.png", 41 "./res/realplayer.png", 42 "./res/usb.png", 43 "./res/xmms.png" 44 }; 45 46 static const char *iconlabels[12] = 47 { 48 "acroread", 49 "icons", 50 "looknfeel", 51 "games", 52 "tux", 53 "xemacs", 54 "gimp", 55 "kpilot", 56 "multimedia", 57 "realplayer", 58 "usb", 59 "xmms" 60 }; 61 62 #if 0 63 static void myDrawItem (HWND hWnd, GHANDLE hsvi, HDC hdc, RECT *rcDraw) 64 { 65 const PBITMAP pbmp = (PBITMAP)iconview_get_item_bitmap (hsvi); 66 const char *label = (const char*)iconview_get_item_label (hsvi); 67 68 SetBkMode (hdc, BM_TRANSPARENT); 69 SetTextColor (hdc, PIXEL_black); 70 71 if (iconview_is_item_hilight(hWnd, hsvi)) { 72 SetBrushColor (hdc, PIXEL_blue); 73 } 74 else { 75 SetBrushColor (hdc, PIXEL_lightwhite); 76 } 77 FillBox (hdc, rcDraw->left, rcDraw->top, RECTWP(rcDraw), RECTHP(rcDraw)); 78 SetBkColor (hdc, PIXEL_blue); 79 80 if (label) { 81 RECT rcTxt = *rcDraw; 82 rcTxt.top = rcTxt.bottom - GetWindowFont (hWnd)->size * 2; 83 rcTxt.left = rcTxt.left - (GetWindowFont (hWnd)->size) + 2; 84 85 DrawText (hdc, label, -1, &rcTxt, DT_SINGLELINE | DT_CENTER | DT_VCENTER); 86 } 87 FillBoxWithBitmap (hdc, rcDraw->left, rcDraw->top, 0, 0, pbmp); 88 } 89 #endif 90 91 static int 92 BookProc (HWND hDlg, int message, WPARAM wParam, LPARAM lParam) 93 { 94 switch (message) 95 { 96 97 case MSG_INITDIALOG: 98 { 99 IVITEMINFO ivii; 100 static int i = 0, j = 0; 101 102 hIconView = GetDlgItem (hDlg, IDC_ICONVIEW); 103 SetWindowBkColor (hIconView, PIXEL_lightwhite); 104 SendMessage (hIconView, IVM_SETITEMSIZE, 55, 65); 105 106 for (i = 0; i < TABLESIZE(myicons); i++) { 107 memset (&ivii, 0, sizeof(IVITEMINFO)); 108 ivii.bmp = &myicons[i]; 109 ivii.nItem = 12 * j + i; 110 ivii.label = iconlabels[i]; 111 ivii.addData = (DWORD)iconlabels[i]; 112 SendMessage (hIconView, IVM_ADDITEM, 0, (LPARAM)&ivii); 113 } 114 115 break; 116 } 117 118 case MSG_COMMAND: 119 { 120 int id = LOWORD (wParam); 121 int code = HIWORD (wParam); 122 123 switch (id) { 124 case IDC_ICONVIEW: 125 if (code == IVN_CLICKED) { 126 int sel; 127 sel = SendMessage (hIconView, IVM_GETCURSEL, 0, 0); 128 } 129 break; 130 case IDC_ADD: 131 { 132 IVITEMINFO ivii; 133 char buff [10]; 134 int idx; 135 int count = SendMessage (hIconView, IVM_GETITEMCOUNT, 0, 0); 136 137 sprintf (buff, "NewIcon%i", count); 138 memset (&ivii, 0, sizeof (IVITEMINFO)); 139 ivii.bmp = &myicons [0]; 140 ivii.nItem = count; 141 ivii.label = buff; 142 ivii.addData = (DWORD)"NewIcon"; 143 144 idx = SendMessage (hIconView, IVM_ADDITEM, 0, (LPARAM)&ivii); 145 SendMessage (hIconView, IVM_SETCURSEL, idx, 1); 146 break; 147 } 148 149 case IDC_DELETE: 150 { 151 int sel = SendMessage (hIconView, IVM_GETCURSEL, 0, 0); 152 int count = SendMessage (hIconView, IVM_GETITEMCOUNT, 0, 0); 153 char *label = NULL; 154 155 if (sel >= 0){ 156 label = (char *) SendMessage (hIconView, IVM_GETITEMADDDATA, sel, 0); 157 SendMessage (hIconView, IVM_DELITEM, sel, 0); 158 if (sel == count - 1) 159 sel --; 160 SendMessage (hIconView, IVM_SETCURSEL, sel, 1); 161 } 162 break; 163 } 164 165 } /* end command switch */ 166 break; 167 } 168 169 case MSG_KEYDOWN: 170 if (wParam == SCANCODE_REMOVE) { 171 int cursel = SendMessage (hIconView, IVM_GETCURSEL, 0, 0); 172 173 if (cursel >= 0){ 174 SendMessage (hIconView, IVM_DELITEM, cursel, 0); 175 SendMessage (hIconView, IVM_SETCURSEL, cursel, 0); 176 } 177 } 178 break; 179 180 case MSG_CLOSE: 181 { 182 EndDialog (hDlg, 0); 183 return 0; 184 } 185 186 } /* end switch */ 187 188 return DefaultDialogProc (hDlg, message, wParam, lParam); 189 } 190 191 static CTRLDATA CtrlBook[] = 192 { 193 { 194 CTRL_ICONVIEW, 195 WS_BORDER | WS_CHILD | WS_VISIBLE | WS_VSCROLL | WS_HSCROLL, 196 10, 10, 200, 300, 197 IDC_ICONVIEW, 198 "", 199 0 200 }, 201 { 202 CTRL_BUTTON, 203 WS_CHILD | WS_VISIBLE | BS_DEFPUSHBUTTON | WS_TABSTOP, 204 35, 330, 50, 30, 205 IDC_ADD, 206 add, 207 0 208 }, 209 { 210 CTRL_BUTTON, 211 WS_CHILD | WS_VISIBLE | WS_TABSTOP | BS_PUSHBUTTON, 212 145, 330, 50, 30, 213 IDC_DELETE, 214 delete_, 215 0 216 } 217 }; 218 219 static DLGTEMPLATE DlgIcon = 220 { 221 WS_BORDER | WS_CAPTION, 222 WS_EX_NONE, 223 0, 0, 230, 400, 224 my_friends, 225 0, 0, 226 TABLESIZE(CtrlBook), CtrlBook, 227 0 228 }; 229 230 int MiniGUIMain (int argc, const char* argv[]) 231 { 232 int i; 233 234 #ifdef _MGRM_PROCESSES 235 JoinLayer(NAME_DEF_LAYER , "iconview" , 0 , 0); 236 #endif 237 238 for (i=0; i<TABLESIZE(myicons); i++) { 239 LoadBitmap (HDC_SCREEN, &myicons[i], iconfiles[i]); 240 } 241 242 243 DialogBoxIndirectParam (&DlgIcon, HWND_DESKTOP, BookProc, 0L); 244 245 return 0; 246 } 247 248 #ifdef _MGRM_THREADS 249 #include <minigui/dti.c> 250 #endif