收藏 分销(赏)

ucgui窗口分析.doc

上传人:快乐****生活 文档编号:4543610 上传时间:2024-09-27 格式:DOC 页数:10 大小:63.50KB
下载 相关 举报
ucgui窗口分析.doc_第1页
第1页 / 共10页
ucgui窗口分析.doc_第2页
第2页 / 共10页
点击查看更多>>
资源描述
一、相关结构体与变量 窗口管理结构体 /* 窗口管理结构体 共30个字节 */ struct WM_Obj { GUI_RECT Rect; //窗口尺寸(x0,y0,x1,y1) 8个字节 GUI_RECT InvalidRect; //无效区域(x0,y0,x1,y1) 8个字节 WM_CALLBACK* cb; //回调函数 4个字节 WM_HWIN hNextLin; //指向链表中得下一个窗口 2个字节 WM_HWIN hParent; //当前窗口得父窗口 2个字节 WM_HWIN hFirstChild; //当前窗口得第一个子窗口 2个字节 WM_HWIN hNext; //下一个兄弟窗口 2个字节 U16 Status; //标志位 2个字节 }; 窗口创建得标志 #define WM_CF_HASTRANS (1<<0) /* Has transparency、 Needs to be defined for windows which do not fill the entire section of their (client) rectangle、 */ #define WM_CF_HIDE (0<<1) /* Hide window after creation (default !) */ #define WM_CF_SHOW (1<<1) /* Show window after creation */ #define WM_CF_MEMDEV (1<<2) /* Use memory device for redraws */ #define WM_CF_STAYONTOP (1<<3) /* Stay on top */ #define WM_CF_DISABLED (1<<4) /* Disabled: Does not receive PID (mouse & touch) input */ /* Create only flags 、、、 Not available as status flags */ #define WM_CF_ACTIVATE (1<<5) /* If automatic activation upon creation of window is desired */ #define WM_CF_FGND (0<<6) /* Put window in foreground after creation (default !) */ #define WM_CF_BGND (1<<6) /* Put window in background after creation */ /* Anchor flags */ #define WM_CF_ANCHOR_RIGHT (1<<7) /* Right anchor 、、、 If parent is resized, distance to right will remain const (left is default) */ #define WM_CF_ANCHOR_BOTTOM (1<<8) /* Bottom anchor 、、、 If parent is resized, distance to bottom will remain const (top is default) */ #define WM_CF_ANCHOR_LEFT (1<<9) /* Left anchor 、、、 If parent is resized, distance to left will remain const (left is default) */ #define WM_CF_ANCHOR_TOP (1<<10) /* Top anchor 、、、 If parent is resized, distance to top will remain const (top is default) */ #define WM_CF_CONST_OUTLINE (1<<11) /* Constant outline、 This is relevant for transparent windows only、 If a window is transparent and does not have a constant outline, its background is invalided instead of the window itself、 This causes add、 computation time when redrawing、 */ #define WM_CF_LATE_CLIP (1<<12) #define WM_CF_MEMDEV_ON_REDRAW (1<<13) #define WM_CF_RESERVED3 (1<<14) #define WM_CF_RESERVED4 (1<<15)         WM_CF_SHOW、WM_CF_STAYONTOP、WM_CF_HIDE、WM_CF_ACTIVATE这几个标志就是经常用到得。 二、窗口创建得过程分析 1、WM_CreateWindowAsChild WM_HWIN WM_CreateWindowAsChild( int x0, int y0, int width, int height ,WM_HWIN hParent, U16 Style, WM_CALLBACK* cb ,int NumExtraBytes) { WM_Obj* pWin; WM_HWIN hWin; WM_ASSERT_NOT_IN_PAINT(); //断言,这里没有使用 WM_LOCK(); Style |= WM__CreateFlags; //给窗口得标志增加一个创建标志 /* Default parent is Desktop 0 */ if (!hParent) { //如果不存在父窗口,比如说桌面窗口 if (WM__NumWindows) { //创建桌面窗口,这个不会执行得 #if GUI_NUM_LAYERS == 1 hParent = WM__ahDesktopWin[0]; //如果用户没有指定当前创建窗口得父窗口,而且该窗口 //又不就是桌面窗口,默认得将桌面窗口作为其父窗口 #else hParent = WM__ahDesktopWin[GUI_Context、SelLayer]; #endif } } if (hParent == WM_UNATTACHED) { hParent = WM_HWIN_NULL; } if (hParent) { WM_Obj* pParent = WM_H2P(hParent); x0 += pParent->Rect、x0; y0 += pParent->Rect、y0; if (width==0) { width = pParent->Rect、x1 - pParent->Rect、x0+1; } if (height==0) { height = pParent->Rect、y1 - pParent->Rect、y0+1; } } if ((hWin = (WM_HWIN) GUI_ALLOC_AllocZero(NumExtraBytes + sizeof(WM_Obj))) == 0) { GUI_DEBUG_ERROROUT("WM_CreateWindow: No memory to create window"); //如果没有空间来创建需要得动态内存块 } else { //申请动态内存成功 WM__NumWindows++; //保存系统总窗口数目得计数器加1 pWin = WM_H2P(hWin); //计算获取动态内存数据区得地址 /* 向动态内存区写入当前窗口得参数 */ pWin->Rect、x0 = x0; pWin->Rect、y0 = y0; pWin->Rect、x1 = x0 + width - 1; pWin->Rect、y1 = y0 + height - 1; pWin->cb = cb; //保存回调函数 /* Copy the flags which can simply be accepted */ pWin->Status |= (Style & (WM_CF_SHOW | WM_SF_MEMDEV | WM_CF_MEMDEV_ON_REDRAW | WM_SF_STAYONTOP | WM_CF_DISABLED | WM_SF_CONST_OUTLINE | WM_SF_HASTRANS | WM_CF_ANCHOR_RIGHT | WM_CF_ANCHOR_BOTTOM | WM_CF_ANCHOR_LEFT | WM_CF_ANCHOR_TOP | WM_CF_LATE_CLIP)); /* Add to linked lists */ _AddToLinList(hWin); //将窗口插入到窗口管理链表当中 WM__InsertWindowIntoList(hWin, hParent); //插入到父窗口管理链表当中 /* 根据用户定义得窗口风格进行一些列得操作 */ /* Activate window if WM_CF_ACTIVATE is specified */ if (Style & WM_CF_ACTIVATE) { //如果带激活标志得话,就激活窗口 WM_SelectWindow(hWin); /* This is not needed if callbacks are being used, but it does not cost a lot and makes life easier 、、、 */ } /* Handle the Style flags, one at a time */ #if WM_SUPPORT_TRANSPARENCY if (Style & WM_SF_HASTRANS) { //透明窗口 WM__TransWindowCnt++; /* Increment counter for transparency windows */ } #endif if (Style & WM_CF_BGND) { WM_BringToBottom(hWin); } if (Style & WM_CF_SHOW) { //显示窗口 pWin->Status |= WM_SF_ISVIS; //设置可视状态位 WM_InvalidateWindow(hWin); //如果有显示命令,还会设置窗口为无效,等待重绘 } WM__SendMsgNoData(hWin, WM_CREATE); //发一个创建消息,这样创建得时候就可以在回调函数中进行处理 } WM_UNLOCK(); return hWin; }    首先根据其父窗口得坐标计算出当前窗口得坐标、高度与宽度。从动态内存区中开辟出一块窗口管理区域,然后向其中填入当前窗口得参数值。比较重要得就是接下来得两部,将当前窗口插入到窗口管理链表当中以及将窗口插入到其父窗口得同胞链表当中。最后,如果创建得时候以显示模式WM_CF_SHOW创建,那么要为此窗口加入了可视标志WM_SF_ISVIS,而且还要设置窗口为无效。这样在执行GUI_Exec()或者WM_Exec()得时候就会对该窗口进行重绘。 2、_AddToLinList() static void _AddToLinList(WM_HWIN hNew) { WM_Obj* pFirst; WM_Obj* pNew; if (WM__FirstWin) { //如果不就是桌面窗口(事实上桌面窗口肯定存在了) pFirst = WM_H2P(WM__FirstWin); //首先获取桌面窗口得动态内存地址 pNew = WM_H2P(hNew); //获取要插入窗口得动态内存地址 /* * 桌面窗口--->最近创建得窗口1--->更早创建得窗口2~~~~~~~--->0 ==> * 桌面窗口--->当前要插入得窗口--->最近创建得窗口1--->更早创建得窗口2~~~--->0 */ pNew->hNextLin = pFirst->hNextLin; // pFirst->hNextLin = hNew; } else { WM__FirstWin = hNew; //创建桌面窗口时,将桌面窗口得句柄赋给此变量 } }     将新建窗口添加到窗口管理链表中。这个窗口管理链表就是建立在uCGUI得动态内存中,利用WM_obj类型中得成员hNextLin连接成一个单向链表。链表得构建过程如下: 插入之前:桌面窗口--->最近创建得窗口1--->更早创建得窗口2~~~~~~~--->0  ==>   插入之后:桌面窗口--->当前要插入得窗口--->最近创建得窗口1--->更早创建得窗口2~~~--->0 3、WM__InsertWindowIntoList() /********************************************************************* * * WM__InsertWindowIntoList * * Routine describtion * This routine inserts the window in the list of child windows for * a particular parent window、 * The window is placed on top of all siblings with the same level、 */ void WM__InsertWindowIntoList(WM_HWIN hWin, WM_HWIN hParent) { int OnTop; WM_HWIN hi; WM_Obj * pWin; WM_Obj * pParent; WM_Obj * pi; if (hParent) { //桌面窗口就是不存在父窗口得 pWin = WM_H2P(hWin); //获取当前窗口得动态内存地址 pWin->hNext = 0; //它得下一个兄弟窗口为0 pWin->hParent = hParent; //记录它得父窗口 pParent = WM_H2P(hParent); //获得它父窗口得动态内存地址 OnTop = pWin->Status & WM_CF_STAYONTOP; //可以用来判断此窗口就是否有在最顶层得标志 hi = pParent->hFirstChild; //父窗口得第一个子窗口 /* Put it at beginning of the list if there is no child */ if (hi == 0) { /* No child yet 、、、 Makes things easy ! */ /* * 父窗口--->0 ====> * 父窗口--->当前窗口--->0 */ pParent->hFirstChild = hWin; //没有子窗口,就把它作为父窗口得第一个子窗口 return; /* Early out 、、、 We are done */ } /* Put it at beginning of the list if first child is a TOP window and new one is not */ pi = WM_H2P(hi); //获取父窗口第一个子窗口得动态内存地址 if (!OnTop) { //如果此窗口没有在最顶层得标志 if (pi->Status & WM_SF_STAYONTOP) { //判断长兄就是否有在最顶层得标志 /* * 父窗口--->长兄--->~~~--->0 => * 父窗口--->当前窗口--->长兄--->~~~--->0 */ pWin->hNext = hi; //当前窗口得下一个窗口指向其长兄 pParent->hFirstChild = hWin; //父窗口得第一个子窗口为当前窗口 return; /* Early out 、、、 We are done */ } } /* 把它放在链表得最顶端或者在第一个“最顶层”窗口之前 */ do { WM_Obj* pNext; WM_HWIN hNext; if ((hNext = pi->hNext) == 0) { /* End of sibling list ? */ pi->hNext = hWin; /* 放在链表得最顶端 */ break; } pNext = WM_H2P(hNext); if (!OnTop) { //如果当前窗口没有“在最顶层”得标志 if (pNext->Status & WM_SF_STAYONTOP) { pi->hNext = hWin; pWin->hNext = hNext; break; } } pi = pNext; } while (1); #if WM_SUPPORT_NOTIFY_VIS_CHANGED WM__NotifyVisChanged(hWin, &pWin->Rect); #endif } }    将新建窗口添加到父窗口得同胞窗口管理链表中。这个窗口管理链表就是建立在uCGUI得动态内存中,利用WM_obj类型中得成员hFirstChild与hNext连接成一个单向链表。 插入得原则就是: 1、如果父窗口没有孩子,直接将其作为父窗口得孩子即可。 插入之前: 父窗口--->0  ====> 插入之后: 父窗口--->当前窗口--->0 2、如果父窗口有孩子,第一个孩子有“在顶层”得标志,而当前创建得窗口没有这个标志,则将其作为其父窗口得第一个孩子。 插入之前:父窗口--->长兄--->~~~--->0 => 插入之后:父窗口--->当前窗口--->长兄--->~~~--->0 3、如果父窗口有孩子,第一个孩子没有“在顶层”得标志,而当前创建得窗口也没有这个标志,则将其放在同胞链表中有“在顶层”标志窗口得前边,也就就是所有没有“在顶层”标志窗口得后边。 插入之前:   父窗口--->长兄(没标志)--->次兄(没标志)--->三兄(有标志)--->~~~--->0 => 插入之后:   父窗口--->长兄(没标志)--->次兄(没标志)--->当前窗口--->三兄(有标志)--->~~~--->0 4、如果父窗口有孩子,第一个孩子没有“在顶层”得标志,而当前创建得窗口有这个标志,则将其放在同胞链表得最后边。  插入之前:   父窗口--->长兄(没标志)--->次兄(没标志)--->三兄(有标志)--->~~~--->0 => 插入之后:   父窗口--->长兄(没标志)--->次兄(没标志)--->三兄(有标志)--->~~~--->当前窗口--->0 三、窗口顺序排列分析 1、按照窗口分层得概念来说,链表得头部窗口就是显示在最底层,链表得尾部窗口就是显示在最顶层。在进行窗口重绘得时候,正就是从链表得头部开始依次往尾部进行重绘。 2、子窗口相对于父窗口来说,子窗口在父窗口得顶部。   四、桌面窗口得创建   桌面窗口得创建发生在GUI_Init函数执行过程中。如果系统开启了窗口管理功能,GUI_Init函数会调用WM_Init函数,在WM_Init初始化窗口管理器得时候,默认得会创建桌面窗口。相关代码如下: /********************************************************************* * * WM_Init */ void WM_Init(void) { 、、、、、、 WM__ahDesktopWin[0] = WM_CreateWindow(0, 0, GUI_XMAX, GUI_YMAX, WM_CF_SHOW, cbBackWin, 0); 、、、、、、 WM_InvalidateWindow(WM__ahDesktopWin[i]); 、、、、、、 WM_SelectWindow(WM__ahDesktopWin[0]); } 桌面窗口默认得回调函数 static void cbBackWin( WM_MESSAGE* pMsg) { const WM_KEY_INFO* pKeyInfo; switch (pMsg->MsgId) { case WM_KEY: pKeyInfo = (const WM_KEY_INFO*)pMsg->Data、p; if (pKeyInfo->PressedCnt == 1) { GUI_StoreKey(pKeyInfo->Key); } break; case WM_PAINT: { int LayerIndex; #if GUI_NUM_LAYERS > 1 LayerIndex = _DesktopHandle2Index(pMsg->hWin); #else LayerIndex = 0; #endif if (WM__aBkColor[LayerIndex] != GUI_INVALID_COLOR) { GUI_SetBkColor(WM__aBkColor[LayerIndex]); GUI_Clear(); } } default: WM_DefaultProc(pMsg); } }
展开阅读全文

开通  VIP会员、SVIP会员  优惠大
下载10份以上建议开通VIP会员
下载20份以上建议开通SVIP会员


开通VIP      成为共赢上传
相似文档                                   自信AI助手自信AI助手

当前位置:首页 > 包罗万象 > 大杂烩

移动网页_全站_页脚广告1

关于我们      便捷服务       自信AI       AI导航        抽奖活动

©2010-2025 宁波自信网络信息技术有限公司  版权所有

客服电话:4009-655-100  投诉/维权电话:18658249818

gongan.png浙公网安备33021202000488号   

icp.png浙ICP备2021020529号-1  |  浙B2-20240490  

关注我们 :微信公众号    抖音    微博    LOFTER 

客服