窗口管理结构体
/* 窗体管理结构体 共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)
窗口创建的过程分析
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; }
时间: 2024-10-29 07:58:36