资源描述:
《第00讲 一个win32工程应用程序实例》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、完整的一个win32工程应用程序实例#include#includeLRESULTCALLBACKWinTestProc(//这里WindowProc是个代号名字。HWNDhwnd,//handletowindowUINTuMsg,//messageidentifierWPARAMwParam,//firstmessageparameterLPARAMlParam//secondmessageparameter);intWINAPIWinMain(HINSTANCEhInstance,//
2、当前运行实例句柄HINSTANCEhPrevInstance,//先前平行实例句柄,若没有则为空NULL。LPSTRlpCmdLine,//命令行参数argc,argv,在windows应用程序中一般有系统赋值。intnCmdShow//showstate){WNDCLASSwndcls;wndcls.cbClsExtra=0;wndcls.cbWndExtra=0;wndcls.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH);wndcls.hCursor=LoadCursor
3、(NULL,IDC_CROSS);wndcls.hIcon=LoadIcon(NULL,IDI_ERROR);wndcls.hInstance=hInstance;wndcls.lpfnWndProc=WinTestProc;wndcls.lpszClassName="软件工程";wndcls.lpszMenuName=NULL;wndcls.style=CS_HREDRAW
4、CS_VREDRAW;RegisterClass(&wndcls);HWNDhwnd;hwnd=CreateWindow("软件工程","江西农业大学",
5、WS_OVERLAPPEDWINDOW,0,0,600,400,NULL,NULL,hInstance,NULL);//不要最大化按钮WS_OVERLAPPEDWINDOW&~WS_MAXIMIZEBOXShowWindow(hwnd,SW_SHOWNORMAL);UpdateWindow(hwnd);MSGmsg;while(GetMessage(&msg,NULL,0,0))//从消息队列中取出一条消息{TranslateMessage(&msg);//进行消息(如键盘消息)转换DispatchMessage(&msg);/
6、/分派消息到窗口的回调函数处理,(OS调用窗口回调函数进行处理)。}}LRESULTCALLBACKWinTestProc(HWNDhwnd,UINTuMsg,WPARAMwParam,LPARAMlParam){switch(uMsg){caseWM_CHAR:charszChar[20];sprintf(szChar,"charis%d",wParam);MessageBox(hwnd,szChar,"键盘按键",0);break;caseWM_LBUTTONDOWN:MessageBox(hwnd,"鼠标单击","测试鼠标
7、消息",0);HDChdc;hdc=GetDC(hwnd);TextOut(hdc,0,50,"VisualC++",strlen("VisualC++"));ReleaseDC(hwnd,hdc);break;caseWM_PAINT:HDChDC;PAINTSTRUCTps;hDC=BeginPaint(hwnd,&ps);TextOut(hDC,0,0,"江西农业大学",strlen("江西农业大学"));EndPaint(hwnd,&ps);break;caseWM_CLOSE:if(IDYES==MessageBox(
8、hwnd,"是否真的结束?","结束按钮",MB_YESNO))DestroyWindow(hwnd);break;caseWM_DESTROY:PostQuitMessage(0);break;default:returnDefWindowProc(hwnd,uMsg,wParam,lParam);}//switch结束return0;}//过程回调函数结束错误2errorC2664:“CreateWindowExW”:不能将参数2从“constchar[9]”转换为“LPCWSTR”c:documentsandsettin
9、gsadministrator桌面winmainwinmainwinmain.cpp36