资源描述:
《Windows程序设计课件第四章.ppt》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、第四讲Windows窗口程序基础主讲:何军2011-秋季学期1RefreshingWin32API简介进程控制API2OutlineWindows窗口基本知识窗口程序——“HelloWorld”Windows的消息驱动实例剖析31.Windows窗口基本知识41.1GUI什么是GUI?GraphicalUserInterface(图形化用户界面)5窗口的基本组成62.窗口“HelloWorld”72.1创建Win32工程82.2窗口程序结构WinMain注册窗口类创建主窗口,并进行必要初始化工作开始消息循环WndProc92.
2、3窗口程序中的重要函数WinMain函数什么是APIENTRY?intAPIENTRYWinMain(HINSTANCEhInstance,HINSTANCEhPrevInstance,LPTSTRlpCmdLine,intnCmdShow)10#ifdef_MAC#defineCALLBACKPASCAL#defineWINAPICDECL#defineWINAPIVCDECL#defineAPIENTRYWINAPI#defineAPIPRIVATECDECL#ifdef_68K_#definePASCAL__pascal
3、#else#definePASCAL#endif#elif(_MSC_VER>=800)
4、
5、defined(_STDCALL_SUPPORTED)#defineCALLBACK__stdcall#defineWINAPI__stdcall#defineWINAPIV__cdecl#defineAPIENTRYWINAPI#defineAPIPRIVATE__stdcall#definePASCAL__stdcall#else#defineCALLBACK#defineWINAPI#defineWINAPIV#defineAPI
6、ENTRYWINAPI#defineAPIPRIVATE#definePASCALpascal#endif112.3窗口程序中的重要函数RegisterClassEx函数ATOMMyRegisterClass(HINSTANCEhInstance){WNDCLASSEXwcex;wcex.cbSize=sizeof(WNDCLASSEX);wcex.style=CS_HREDRAW
7、CS_VREDRAW;wcex.lpfnWndProc=WndProc;wcex.cbClsExtra=0;wcex.cbWndExtra=0;w
8、cex.hInstance=hInstance;wcex.hIcon=LoadIcon(hInstance,MAKEINTRESOURCE(IDI_WIN32HELLO));wcex.hCursor=LoadCursor(NULL,IDC_ARROW);wcex.hbrBackground=(HBRUSH)(COLOR_WINDOW+1);wcex.lpszMenuName=MAKEINTRESOURCE(IDC_WIN32HELLO);wcex.lpszClassName=szWindowClass;wcex.hIconSm
9、=LoadIcon(wcex.hInstance,MAKEINTRESOURCE(IDI_SMALL));returnRegisterClassEx(&wcex);}122.3窗口程序中的重要函数WndProc函数LRESULTCALLBACKWndProc(HWNDhWnd,UINTmessage,WPARAMwParam,LPARAMlParam){PAINTSTRUCTps;HDChdc;switch(message){caseWM_PAINT:hdc=BeginPaint(hWnd,&ps);//TODO:Addany
10、drawingcodehere...::TextOut(hdc,10,20,”HelloWorld”);EndPaint(hWnd,&ps);break;caseWM_DESTROY:PostQuitMessage(0);break;default:returnDefWindowProc(hWnd,message,wParam,lParam);}return0;}13WinMain中的消息循环2.3窗口程序中的重要函数//Mainmessageloop:while(GetMessage(&msg,NULL,0,0)){if(!
11、TranslateAccelerator(msg.hwnd,hAccelTable,&msg)){TranslateMessage(&msg);DispatchMessage(&msg);}}142.4两个问题?WinMain函数中的消息循环是死循环吗?在程序中没有看到Wnd