資源描述:
《孫鑫c++學(xué)習(xí)總結(jié)》由會(huì)員上傳分享,免費(fèi)在線閱讀,更多相關(guān)內(nèi)容在教育資源-天天文庫。
1、首先聲明這份總結(jié)的作者絕對不是我內(nèi)功=算法+數(shù)據(jù)結(jié)構(gòu)+編譯原理+操作系統(tǒng)原理+軟件工程+英文一:Windows程序運(yùn)行原理及程序編寫流程(創(chuàng)建窗口?;卣{(diào)函數(shù)方法1intWINAPIWinMain(//主函數(shù)HINSTANCEhInstance,//handletocurrentinstanceHINSTANCEhPrevInstance,//handletopreviousinstanceLPSTRlpCmdLine,//commandlineintnCmdShow//showstate)WNDCLASSwndc
2、ls;//創(chuàng)建一個(gè)窗口對象wndcls.cbClsExtra=0;//窗口類附加字節(jié),為該類窗口所共享。通常0。wndcls.cbWndExtra=0;//窗口附加字節(jié)。通常設(shè)為0。wndcls.hbrBackground=(HBRUSH)GetStockObject(BLACK_BRUSH);//背景wndcls.hCursor=LoadCursor(NULL,IDC_CROSS);/光標(biāo)wndcls.hIcon=LoadIcon(NULL,IDI_ERROR);//位圖(圖標(biāo))wndcls.hInstance
3、=hInstance;//當(dāng)前應(yīng)用程序事例句柄。wndcls.lpfnWndProc=WinSunProc;//窗口過程函數(shù)(回調(diào)函數(shù))wndcls.lpszClassName="Weixin2003";//窗口名//類的名字wndcls.lpszMenuName=NULL;//菜單名wndcls.style=CS_HREDRAW
4、CS_VREDRAW;//窗口的類型RegisterClass(&wndcls);//注冊窗口HWNDhwnd;hwnd=CreateWindow("Weixin2003","北京",
5、WS_OVERLAPPEDWINDOW,0,0,600,400,NULL,NULL,hInstance,NULL);//定義窗口句柄并創(chuàng)建窗口ShowWindow(hwnd,SW_SHOWNORMAL);//顯示窗口UpdateWindow(hwnd);//更新窗口MSGmsg;//定義消息對象/*做消息循環(huán)*/while(GetMessage(&msg,//接收消息的窗口句柄。//從消息隊(duì)列中取出一條消息NULL,//消息標(biāo)識(shí)。0,0))//做消息循環(huán){TranslateMessage(&msg);//進(jìn)行消息
6、(如鍵盤消息)轉(zhuǎn)換DispatchMessage(&msg);/分派消息到窗口的回調(diào)函數(shù)處理,}return0;}//回調(diào)函數(shù)原形為LRESULTCALLBACKWindowProc();LRESULTCALLBACKWinSunProc(//對消息的響應(yīng)函數(shù)(回調(diào)函數(shù))HWNDhwnd,//handletowindowUINTuMsg,//messageidentifierWPARAMwParam,//firstmessageparameterLPARAMlParam//secondmessageparamet
7、er){switch(uMsg){caseWM_CHAR:break;caseWM_LBUTTONDOWN:MessageBox(hwnd,"mouseclicked","weixin",0);HDChdc;hdc=GetDC(hwnd);TextOut(hdc,0,50,"計(jì)算機(jī)編程語言培訓(xùn)",strlen("計(jì)算機(jī)編程語言培訓(xùn)"));ReleaseDC(hwnd,hdc);break;caseWM_PAINT:HDChDC;PAINTSTRUCTps;hDC=BeginPaint(hwnd,&ps);Text
8、Out(hDC,0,0,"維新培訓(xùn)",strlen("維新培訓(xùn)"));EndPaint(hwnd,&ps);break;caseWM_CLOSE:if(IDYES==MessageBox(hwnd,"是否真的結(jié)束?","weixin",MB_YESNO)){DestroyWindow(hwnd);}break;caseWM_DESTROY:PostQuitMessage(0);break;default:returnDefWindowProc(hwnd,uMsg,wParam,lParam);}總結(jié):創(chuàng)建一個(gè)完整
9、的窗口需要經(jīng)過下面四個(gè)操作步驟:一,設(shè)計(jì)一個(gè)窗口類;如:WNDCLASSwndcls;二,注冊窗口類;如:RegisterClass(&wndcls);三,創(chuàng)建窗口;如:CreateWindow(),CreateWindowEX();四,顯示及更新窗口。如:ShowWindow(),UpdateWindow();二:VC++掌握的基礎(chǔ)①使用VC編程除了良好的C基礎(chǔ)外還需要