minigui代码分析文档格式.docx
《minigui代码分析文档格式.docx》由会员分享,可在线阅读,更多相关《minigui代码分析文档格式.docx(53页珍藏版)》请在冰豆网上搜索。
PMAINWINCREATEpCreateInfo
结构体MAINWINCREATE定义了被创建的窗口的位置、标题、类型等基本参数。
实际上包含了创建窗口的UI风格和窗口处理函数两方面的内容。
PMAINWINCREATE为指向该结构体的指针。
typedefstruct_MAINWINCREATE
{
DWORDdwStyle;
//主窗口的类型
DWORDdwExStyle;
//主窗口的扩展类型
constchar*spCaption;
//主窗口的标题
HMENUhMenu;
//主窗口菜单句柄
HCURSORhCursor;
//主窗口光标句柄
HICONhIcon;
//主窗口图标句柄
HWNDhHosting;
//主窗口的托管窗口Thehostingmainwindow
int(*MainWindowProc)(HWND,int,WPARAM,LPARAM);
//窗口回调函数
intlx,ty,rx,by;
//主窗口在屏幕坐标中的位置
intiBkColor;
//主窗口颜色的像素值
DWORDdwAddData;
//私有数据Thefirstprivatedataassociatedwiththemainwindow
DWORDdwReserved;
//没有用到
}MAINWINCREATE;
typedefMAINWINCREATE*PMAINWINCREATE;
2、MAINWIN结构体:
主窗口的详细信息由该结构体给出
typedefstruct_MAINWIN
/*
*ThesefieldsaresimiliarwithCONTROLstruct.
*/
shortDataType;
//thedatatype.
shortWinType;
//thewindowtype.
intleft,top;
//thepositionandsizeofmainwindow.
intright,bottom;
intcl,ct;
//thepositionandsizeofclientarea.
intcr,cb;
//thestylesofmainwindow.
//theextendedstylesofmainwindow.
//thebackgroundcolor.
//handleofmenu.
HACCELhAccel;
//handleofacceleratortable.
//handleofcursor.
//handleoficon.
HMENUhSysMenu;
//handleofsystemmenu.
PLOGFONTpLogFont;
//pointertologicalfont.
HDCprivCDC;
//theprivateclientDC.
INVRGNInvRgn;
//theinvalidregionofthismainwindow.
PGCRINFOpGCRInfo;
//pointertoglobalclipregioninfostruct.
PZORDERNODEpZOrderNode;
PCARETINFOpCaretInfo;
//pointertosystemcaretinfostruct.
//theadditionaldata.
DWORDdwAddData2;
//thesecondaddtionaldata.
int(*MainWindowProc)(HWND,int,WPARAM,LPARAM);
//theaddressofmainwindowprocedure.
char*spCaption;
//thecaptionofmainwindow.
intid;
//theidentifierofmainwindow.
SCROLLBARINFOvscroll;
//theverticalscrollbarinformation.
SCROLLBARINFOhscroll;
//thehorizitalscrollbarinformation.
struct_MAINWIN*pMainWin;
//themainwindowthatcontainsthiswindow.
//formainwindow,alwaysbeitself.
HWNDhParent;
//theparentofthiswindow.
//formainwindow,alwaysbeHWND_DESKTOP.
*Childwindows.
HWNDhFirstChild;
//thehandleoffirstchildwindow.
HWNDhActiveChild;
//thecurrentlyactivechildwindow.
HWNDhOldUnderPointer;
//theoldchildwindowunderpointer.
HWNDhPrimitive;
//thepremitivechildofmouseevent.
NOTIFPROCNotifProc;
//thenotificationcallbackprocedure.
*windowelementdata.
struct_wnd_element_data*wed;
*MainWindowhosting.
*Thefollowingmembersareonlyimplementedformainwindow.
struct_MAINWIN*pHosting;
//thehostingmainwindow.
struct_MAINWIN*pFirstHosted;
//thefirsthostedmainwindow.
struct_MAINWIN*pNextHosted;
//thenexthostedmainwindow.
PMSGQUEUEpMessages;
//themessagequeue.
GCRINFOGCRInfo;
//theglobalclipregioninfostruct.
//putheretoavoidinvokingmallocfunction.
}MAINWIN;
3、MSGQUEUE消息队列
struct_MSGQUEUE
DWORDdwState;
//messagequeuestates
PQMSGpFirstNotifyMsg;
//headofthenotifymessagequeue
PQMSGpLastNotifyMsg;
//tailofthenotifymessagequeue
IDLEHANDLEROnIdle;
//Idlehandler
MSG*msg;
/*postmessagebuffer*/
intlen;
/*bufferlen*/
intreadpos,writepos;
/*positionsforreadingandwriting*/
intFirstTimerSlot;
/*thefirsttimerslottobechecked*/
DWORDTimerMask;
/*timerslotsmask*/
intloop_depth;
/*messageloopdepth,fordialogboxes.*/
};
2、CreateMainWindow函数流程
1、判断传入的参数pCreateInfo是否为空
CaseNULL:
若参数为空,返回HWND_INVALID
CaseNOTNULL:
若参数不为空,继续执行2
2、为PMAINWIN类型的pWin分配内存空间,并判断pWin是否为空
分配空间失败,返回HWND_INVALID
分配空间成功,继续执行3
3、是否定义_LITE_VERSION:
3.a没有定义_LITE_VERSION,代表minigui的运行模式为MiniGui-Threads
设置pWin的成员pWin->
pMessages和pWin->
pHosting
3.b定义了_LITE_VERSION,代表minigui的运行模式为非MiniGui-Threads
4、设置pWin的成员:
pWin->
pMainWin=pWin;
hParent=0;
pFirstHosted=NULL;
pNextHosted=NULL;
DataType=TYPE_HWND;
WinType=TYPE_MAINWIN;
#ifndef_LITE_VERSION
th=pthread_self();
#endif
hFirstChild=0;
hActiveChild=0;
hOldUnderPointer=0;
hPrimitive=0;
NotifProc=NULL;
dwStyle=pCreateInfo->
dwStyle;
dwExStyle=pC