文章目录
- 4,想显示成
- 最后的demo
仿真器中
1,格子状显示
把下面这句注释掉,就可能会这么显示
WM_SetCreateFlags(WM_CF_MEMDEV);
2,显示一副灰度图
很有可能你是这么写的
也就是
hMemDev = GUI_MEMDEV_CreateFixed(0, 0, 200, 200, GUI_MEMDEV_HASTRANS, GUI_MEMDEV_APILIST_32, GUI_COLOR_CONV_8888);
3,
它的调用位置
WM_SetCreateFlags(WM_CF_MEMDEV);
这样调用
WM_SetCreateFlags(WM_CF_MEMDEV);
/ / 初始化 emWin
GUI_Init();
显示
调用方式二:
// 初始化 emWin
GUI_Init();
// 初始化窗口管理
WM_SetCreateFlags(WM_CF_MEMDEV);
啥都没显示
总结就是先调用
WM_SetCreateFlags(WM_CF_MEMDEV);
再调用
GUI_Init();
但是能别调用就别调用
4,想显示成
把 WM_SetCreateFlags(WM_CF_MEMDEV); 注释掉就好了。
但是这又不是我想要的
最后的demo
显示的图像。
一点一点的分析吧,,,必须要知道每个函数的意思,而且有的函数跟自己的理解不一样。
源码:
#include "GUI.h"
#include "WM.h"
// 子窗口回调函数
static void _cbChildWindow(WM_MESSAGE* pMsg) {
GUI_MEMDEV_Handle hMemDev;
switch (pMsg->MsgId) {
case WM_PAINT:
//设置颜色并绘制矩形
int x = WM_GetWindowOrgX(pMsg->hWin);//这里是相对屏幕坐标
int y = WM_GetWindowOrgY(pMsg->hWin);//这里是相对屏幕的坐标
int w = WM_GetWindowSizeX(pMsg->hWin);
int h = WM_GetWindowSizeY(pMsg->hWin);
GUI_RECT Rect0;
WM_GetClientRect(&Rect0);//这里是相对父类的坐标(0,0,79,79)
GUI_RECT Rect1;
WM_GetWindowRect(&Rect1); //这里是相对屏幕的坐标(40,40,119,119)
GUI_RECT Rect2;
WM_GetInsideRect(&Rect2);//这里得到的是父类相对他父类的坐标,(0,0,249,249)
GUI_SetColor(GUI_WHITE);
GUI_FillRect(Rect2.x0, Rect2.y0, Rect2.x1, Rect2.y1);
//printf("Child Rect: x0=%d, y0=%d, x1=%d, y1=%d\n", Rect2.x0, Rect2.y0, Rect2.x1, Rect2.y1);
// 创建一个 80x120 的内存设备
hMemDev = GUI_MEMDEV_CreateFixed(0, 0, 80, 120, GUI_MEMDEV_NOTRANS, GUI_MEMDEV_APILIST_32, GUICC_8888);
GUI_MEMDEV_Select(hMemDev);
GUI_SetBkColor(GUI_RED);
//GUI_SetBkColor(GUI_TRANSPARENT);
GUI_Clear();
// 在内存设备中绘制内容
GUI_SetColor(GUI_BLUE);
GUI_FillRect(0, 0, 20, 50);
GUI_SetColor(GUI_GREEN);
// GUI_SetFont(&GUI_Font13_ASCII);
GUI_DispStringHCenterAt("Child", 40, 35);
GUI_MEMDEV_Handle hMemDev2 = GUI_MEMDEV_CreateFixed(90, 10, 80, 120, GUI_MEMDEV_NOTRANS, GUI_MEMDEV_APILIST_32, GUICC_8888);
// 取消选择内存设备并将其内容复制到屏幕
GUI_MEMDEV_Select(0);
//GUI_MEMDEV_CopyToLCD(hMemDev);
GUI_MEMDEV_Write(hMemDev);
GUI_MEMDEV_Write(hMemDev2);
// 删除内存设备
GUI_MEMDEV_Delete(hMemDev);
break;
default:
WM_DefaultProc(pMsg);
break;
}
}
// 父窗口回调函数
static void _cbParentWindow(WM_MESSAGE* pMsg) {
WM_HWIN hChildWin;
GUI_MEMDEV_Handle hMemDev;
switch (pMsg->MsgId) {
case WM_CREATE:
// 创建子窗口,大小为 80x80,位于 (60, 60)
// hChildWin = WM_CreateWindowAsChild(60, 60, 80, 80, pMsg->hWin, WM_CF_SHOW, _cbChildWindow, 0);
hChildWin = WM_CreateWindowAsChild(10, 10, 80, 80, pMsg->hWin, WM_CF_SHOW | WM_CF_HASTRANS, _cbChildWindow, 0);
break;
case WM_PAINT:
GUI_RECT Rect0;
WM_GetClientRect(&Rect0);//这里是相对父类的坐标 (0,0,249,249)
GUI_RECT Rect1;
WM_GetWindowRect(&Rect1); //这里是相对屏幕的坐标 (30,30,279,279)
GUI_RECT Rect2;
WM_GetInsideRect(&Rect2);//这里得到的是父类的相对坐标,(0,0,249,249)
// 创建一个 200x200 的内存设备
hMemDev = GUI_MEMDEV_CreateFixed(0, 0, 200, 220, GUI_MEMDEV_NOTRANS, GUI_MEMDEV_APILIST_32, GUI_COLOR_CONV_8888);
//hMemDev = GUI_MEMDEV_CreateFixed(0, 0, 200, 200, GUI_MEMDEV_NOTRANS, GUI_MEMDEV_APILIST_16, GUI_COLOR_CONV_565);
//hMemDev = GUI_MEMDEV_Create(0, 0, 200, 200);
// hMemDev = GUI_MEMDEV_CreateFixed(0, 0, 200, 200, 0, GUI_MEMDEV_APILIST_32, GUI_COLOR_CONV_8888);
//hMemDev = GUI_MEMDEV_CreateFixed(0, 0, 200, 200, GUI_MEMDEV_HASTRANS, GUI_MEMDEV_APILIST_32, GUI_COLOR_CONV_8888);
GUI_MEMDEV_Select(hMemDev);
GUI_SetBkColor(GUI_DARKRED);
GUI_Clear();
// 在内存设备中绘制内容
GUI_SetColor(GUI_GREEN);
GUI_FillRect(0, 0, 200, 200);
//GUI_SetColor(GUI_BLACK);
GUI_SetColor(GUI_WHITE);
// GUI_SetFont(&GUI_Font13_ASCII);
GUI_DispStringHCenterAt("Parent", 100, 90);
// 取消选择内存设备并将其内容复制到屏幕
GUI_MEMDEV_Select(0);
GUI_RECT Rect;
WM_GetInsideRect(&Rect);
GUI_SetColor(GUI_ORANGE);
GUI_FillRect(Rect.x0, Rect.y0, Rect.x1, Rect.y1);
//GUI_MEMDEV_CopyToLCD(hMemDev);
GUI_MEMDEV_Write(hMemDev);
// 删除内存设备
GUI_MEMDEV_Delete(hMemDev);
break;
default:
WM_DefaultProc(pMsg);
break;
}
}
void MainTask(void) {
WM_HWIN hParentWin;
// 初始化窗口管理
//WM_SetCreateFlags(WM_CF_MEMDEV);
#if GUI_WINSUPPORT
// WM_MULTIBUF_Enable(1);
#endif
// 初始化 emWin
GUI_Init();
// 创建父窗口,大小为 200x200,位于 (30, 30)
hParentWin = WM_CreateWindow(30, 30, 250, 250, WM_CF_SHOW , _cbParentWindow, 0);
//WM_CreateWindowAsChild(10, 10, 80, 80, hParentWin, WM_CF_SHOW| WM_CF_HASTRANS, _cbChildWindow, 0);
//WM_InvalidateWindow(hParentWin);
GUI_Exec();
// GUI 主循环
while (1) {
GUI_Delay(100);
}
}