emWin使用资料收集(一) ----- emWin 2天速成实例教程008_IconView图标控件使用方法
备注:(1)打开工程目录下的"Exe\GUISimulationDebug.exe"即可看到效果。(2)看完教程000~005就基本会用emWin做项目,其他章节可以需要时再参考。
(1)使用GUIBuilder V5.30创建如下页面并保存为C文件FramewinDLG.c,然后添加到脱机模拟仿真平台CodeBlocks的emwin工程:
(2)用BmpCvt.exe(可在”软件/资料下载”栏目下载)将48×48的图标PNG文件转成C文件并添加到CodeBlocks工程:
(3)在生成的FramewinDLG.c文件中需要更改图标的大小为64×64:
(4)在WM_INIT_DIALOG消息中(窗口初始化时程序跑到这里)添加ICONVIEW控件的初始化代码:
......
hItem = WM_GetDialogItem(pMsg->hWin, ID_ICONVIEW_0);
ICONVIEW_SetIconAlign(hItem, ICONVIEW_IA_TOP);
ICONVIEW_SetTextColor(hItem, ICONVIEW_CI_UNSEL, GUI_BLUE);
ICONVIEW_SetTextColor(hItem, ICONVIEW_CI_SEL, GUI_GREEN);
ICONVIEW_SetFrame(hItem, GUI_COORD_X, 0);//设置图标到IconView边框的间距
ICONVIEW_SetFrame(hItem, GUI_COORD_Y, 0);
ICONVIEW_SetSpace(hItem, GUI_COORD_X, (280-64*4)/3);//设置图标和图标之间的间距
ICONVIEW_SetSpace(hItem, GUI_COORD_Y, (140-64*2)/1);
ICONVIEW_SetFont(hItem, GUI_FONT_16_1);
ICONVIEW_AddBitmapItem(hItem, &bm01, "neqee");//添加图标项
ICONVIEW_AddBitmapItem(hItem, &bm02, "SOS");
ICONVIEW_AddBitmapItem(hItem, &bm03, "Phone");
ICONVIEW_AddBitmapItem(hItem, &bm04, "Camera");
ICONVIEW_AddBitmapItem(hItem, &bm05, "Email");
ICONVIEW_AddBitmapItem(hItem, &bm06, "NoteBook");
ICONVIEW_AddBitmapItem(hItem, &bm07, "JTV");
ICONVIEW_AddBitmapItem(hItem, &bm08, "Dollar");
......
(5) WM_NOTIFY_PARENT消息中(操作屏幕时程序跑到这里)添加点击IconView提示程序:
switch(ICONVIEW_GetSel(WM_GetDialogItem(pMsg->hWin,ID_ICONVIEW_0)))
{
case 0:TEXT_SetText(WM_GetDialogItem(pMsg->hWin, ID_TEXT_0), "neqee");break;
case 1:TEXT_SetText(WM_GetDialogItem(pMsg->hWin, ID_TEXT_0), "SOS");break;
case 2:TEXT_SetText(WM_GetDialogItem(pMsg->hWin, ID_TEXT_0), "Phone");break;
case 3:TEXT_SetText(WM_GetDialogItem(pMsg->hWin, ID_TEXT_0), "Camera");break;
case 4:TEXT_SetText(WM_GetDialogItem(pMsg->hWin, ID_TEXT_0), "Email");break;
case 5:TEXT_SetText(WM_GetDialogItem(pMsg->hWin, ID_TEXT_0), "NoteBook");break;
case 6:TEXT_SetText(WM_GetDialogItem(pMsg->hWin, ID_TEXT_0), "JTV"); break;
case 7:TEXT_SetText(WM_GetDialogItem(pMsg->hWin, ID_TEXT_0), "Dollar");break;
//case8: TEXT_SetText(WM_GetDialogItem(pMsg->hWin, ID_TEXT_0),"Jobbet"); break;
}
(5)编译运行: