一、相关结构体和变量
重要的uCGUI系统全局变量
- NextDrawWin 下一个需要重绘的窗口句柄
- WM__NumWindows 系统当前的总共窗口总数
- WM__NumInvalidWindows 系统当前无效的窗口总数,这些窗口都需要重绘的
- WM__FirstWin 系统第一个窗口的句柄,默认的就是桌面窗口,桌面窗口的句柄就是1。在创建桌面窗口的时候,会将桌面窗口的句柄,付给该全局变量,该动作发生在函数_AddToLinList中。
与桌面窗口相关的全局变量
- WM__ahDesktopWin[i] 保存桌面窗口的句柄
- WM__aBkColor[i] 保存桌面窗口的背景色
Attention:之所以用数组保存,是因为uCGUI支持多层显示。
二、uCGUI窗口初始化过程
/*********************************************************************** WM_Init*/void WM_Init(void) { if (!_IsInited) { //只初始化一次 NextDrawWin = WM__FirstWin = WM_HWIN_NULL; //下一个需要重绘的窗体为空 GUI_Context.WM__pUserClipRect = NULL; //用户裁剪区为空 WM__NumWindows = WM__NumInvalidWindows =0; //所有窗体的个数和无效窗体数都为0 /* Make sure we have at least one window. This greatly simplifies the drawing routines as they do not have to check if the window is valid. */ #if GUI_NUM_LAYERS == 1 WM__ahDesktopWin[0] = WM_CreateWindow(0, 0, GUI_XMAX, GUI_YMAX, WM_CF_SHOW, cbBackWin, 0); //创建一个桌面窗体 WM__aBkColor[0] = GUI_INVALID_COLOR; //设置桌面的背景颜色为无效的背景颜色 WM_InvalidateWindow(WM__ahDesktopWin[0]); //使一个窗口无效,这样这个窗口就会重绘 #else { int i; for (i = 0; i < GUI_NUM_LAYERS; i++) { WM__ahDesktopWin[i] = WM_CreateWindowAsChild(0, 0, GUI_XMAX, GUI_YMAX, WM_UNATTACHED, WM_CF_SHOW, cbBackWin, 0); WM__aBkColor[i] = GUI_INVALID_COLOR; WM_InvalidateWindow(WM__ahDesktopWin[i]); /* Required because a desktop window has no parent. */ } } #endif /* Register the critical handles ... Note: This could be moved into the module setting the Window handle */ WM__AddCriticalHandle(&WM__CHWinModal); WM__AddCriticalHandle(&WM__CHWinLast); #if GUI_SUPPORT_MOUSE WM__AddCriticalHandle(&WM__CHWinMouseOver); #endif WM_SelectWindow(WM__ahDesktopWin[0]); //选中桌面窗口作为活动窗口 WM_Activate(); //激活视窗管理器 _IsInited =1; //只初始化一次 }}