一、数据结构1、CreateMainWindow函数参数:PMAINWINCREATEpCreateInfo结构体MAINWINCREATE定义了被创建的窗口的位置、标题、类型等基本参数。实际上包含了创建窗口的UI风格和窗口处理函数两方面的内容。PMAINWINCREATE为指向该结构体的指针。typedefstruct_MAINWINCREATE{DWORDdwStyle;//主窗口的类型DWORDdwExStyle;//主窗口的扩展类型constchar*spCaption;//主窗口的标题HMENUhMenu;//主窗口菜单句柄HCURSORhCursor;//主窗口光标句柄HICONhIcon;//主窗口图标句柄HWNDhHosting;//主窗口的托管窗口Thehostingmainwindowint(*MainWindowProc)(HWND,int,WPARAM,LPARAM);//窗口回调函数intlx,ty,rx,by;//主窗口在屏幕坐标中的位置intiBkColor;//主窗口颜色的像素值DWORDdwAddData;//私有数据ThefirstprivatedataassociatedwiththemainwindowDWORDdwReserved;//没有用到}MAINWINCREATE;typedefMAINWINCREATE*PMAINWINCREATE;2、MAINWIN结构体:主窗口的详细信息由该结构体给出typedefstruct_MAINWIN{/**ThesefieldsaresimiliarwithCONTROLstruct.*/shortDataType;//thedatatype.shortWinType;//thewindowtype.intleft,top;//thepositionandsizeofmainwindow.intright,bottom;intcl,ct;//thepositionandsizeofclientarea.intcr,cb;DWORDdwStyle;//thestylesofmainwindow.DWORDdwExStyle;//theextendedstylesofmainwindow.intiBkColor;//thebackgroundcolor.HMENUhMenu;//handleofmenu.HACCELhAccel;//handleofacceleratortable.HCURSORhCursor;//handleofcursor.HICONhIcon;//handleoficon.HMENUhSysMenu;//handleofsystemmenu.PLOGFONTpLogFont;//pointertologicalfont.HDCprivCDC;//theprivateclientDC.INVRGNInvRgn;//theinvalidregionofthismainwindow.PGCRINFOpGCRInfo;//pointertoglobalclipregioninfostruct.PZORDERNODEpZOrderNode;PCARETINFOpCaretInfo;//pointertosystemcaretinfostruct.DWORDdwAddData;//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;//messagequeuestatesPQMSGpFirstNotifyMsg;//headofthenotifymessagequeuePQMSGpLastNotifyMsg;//tailofthenotifymessagequeueIDLEHANDLEROnIdle;//IdlehandlerMSG*msg;/*postmessagebuffer*/intlen;/*bufferlen*/intreadpos,writepos;/*positionsforreadingandwriting*/intFirstTimerSlot;/*thefirsttimerslottobechecked*/DWORDTimerMask;/*timerslotsmask*/intloop_depth;/*messageloopdepth,fordialogboxes.*/};二、函数流程1、init_desktop_winstaticvoidinit_desktop_win(void){staticMAINWINsg_desktop_win;//静态量PMAINWINpDesktopWin;pDesktopWin=&sg_desktop_win;//作为默认的DesktoppDesktopWin-pMessages=__mg_dsk_msg_queue;//自己的消息队列,其他窗口发送的SendMessage将消息压入该队列[luther.gliethttp]pDesktopWin-MainWindowProc=DesktopWinProc;//桌面默认回调处理函数pDesktopWin-DataType=TYPE_HWND;pDesktopWin-WinType=TYPE_ROOTWIN;pDesktopWin-pLogFont=NULL;pDesktopWin-spCaption=THEDESKTOPWINDOW;pDesktopWin-pGCRInfo=&sg_ScrGCRInfo;pDesktopWin-pMainWin=pDesktopWin;__mg_hwnd_desktop=(HWND)pDesktopWin;//登记到desktop的全局量中//window.h//#defineHWND_DESKTOP__mg_hwnd_desktop__mg_dsk_win=pDesktopWin;}2、main函数intmain(void){puts(!!!HelloWorld!!!);/*prints!!!HelloWorld!!!*/inti=0;if(InitGUI()!=0){return1;}//MyMiniGUIMain();MSGMsg;HWNDhMainWnd;MAINWINCREATECreateInfo;//设置主窗口风格,把主窗口设置为初始可见,具有边框和标题栏CreateInfo.dwStyle=WS_VISIBLE|WS_BORDER|WS_CAPTION;CreateInfo.dwExStyle=WS_EX_NONE;//设置主窗口的扩展风格,该窗口没有扩展风格CreateInfo.spCaption=hello;//设置主窗口的标题为helloCreateInfo.hMenu=0;//设置主窗口的主菜单,该窗口没有主菜单CreateInfo.hCursor=GetSystemCursor(0);//设置主窗口的光标为系统缺省光标CreateInfo.hIcon=0;//设置主窗口的图标,该窗口没有图标//设置主窗口的窗口过程函数为HelloWinProc,所有发往该窗口的消息由该函数处理CreateInfo.MainWindowProc=HelloWinProc;CreateInfo.lx=0;//设置主窗口的坐标CreateInfo.ty=0;CreateInfo.rx=600;CreateInfo.by=600;CreateInfo.iBkColor=COLOR_lightwhite;//设置主窗口的背景颜色为白色,预定义CreateInfo.dwAddData=0;//设置主窗口的附加数据,该窗口没有附加数据CreateInfo.hHosting=HWND_DESKTOP;//设置主窗口的托管窗口为桌面窗口hMainWnd=CreateMainWindow(&CreateInfo);if(hMainWnd==HWND_INVALID)return-1;//SW_SHOWNORMAL正常显示,并且显示在桌面顶层ShowWindow(hMainWnd,SW_SHOWNORMAL);//GetMessage(&Msg,hMainWnd)第二个参数为窗口句柄,用于表示从哪个窗口的消息队列中获取消息while(GetMessage(&Msg,hMainWnd)){if(getIdle()==5)break;//把击键消息转换为MES_CHAR消息,然后直接发送到窗口处理函数TranslateMessage(&Msg);//调用主窗口的窗口过程函数对发往该主窗口的消息进行处理DispatchMessage(&Msg);i++;if(i==50)break;}sleep(10);//MainWindowThreadCleanup(hMainWnd);returnEXIT_SUCCESS;}3、CreateMainWindow函数HWNDGUIAPICreateMainWindow(PMAINWINCREATEpCreateInfo){PMAINWINpWin;//指针if(pCreateInfo==NULL)//判断函数参数是否为空,若