文档详情

第00讲 一个win32工程应用程序实例.doc

发布:2017-05-06约2.38千字共7页下载文档
文本预览下载声明
完整的一个win32工程应用程序实例 #include Windows.h #include stdio.h LRESULT CALLBACK WinTestProc( //这里WindowProc是个代号名字。 HWND hwnd, // handle to window UINT uMsg, // message identifier WPARAM wParam, // first message parameter LPARAM lParam // second message parameter ); int WINAPI WinMain( HINSTANCE hInstance, // 当前运行实例句柄 HINSTANCE hPrevInstance, // 先前平行实例句柄,若没有则为空NULL。 LPSTR lpCmdLine, // 命令行参数argc,argv,在windows应用程序中一般有系统赋值。 int nCmdShow // show state ) { WNDCLASS wndcls; wndcls.cbClsExtra=0; wndcls.cbWndExtra=0; wndcls.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH); wndcls.hCursor=LoadCursor(NULL,IDC_CROSS); wndcls.hIcon=LoadIcon(NULL,IDI_ERROR); wndcls.hInstance=hInstance; wndcls.lpfnWndProc=WinTestProc; wndcls.lpszClassName=软件工程; wndcls.lpszMenuName=NULL; wndcls.style=CS_HREDRAW | CS_VREDRAW; RegisterClass(wndcls); HWND hwnd; hwnd=CreateWindow(软件工程, 江西农业大学,WS_OVERLAPPEDWINDOW,0,0,600,400,NULL,NULL,hInstance,NULL); //不要最大化按钮 WS_OVERLAPPEDWINDOW ~WS_MAXIMIZEBOX ShowWindow(hwnd,SW_SHOWNORMAL); UpdateWindow(hwnd); MSG msg; while(GetMessage(msg,NULL,0,0)) //从消息队列中取出一条消息 { TranslateMessage(msg); //进行消息(如键盘消息)转换 DispatchMessage(msg); //分派消息到窗口的回调函数处理,(OS调用窗口回调函数进行处理)。 } } LRESULT CALLBACK WinTestProc( HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { switch(uMsg) { case WM_CHAR: char szChar[20]; sprintf(szChar, char is %d,wParam); MessageBox(hwnd,szChar, 键盘按键,0); break; case WM_LBUTTONDOWN: MessageBox(hwnd, 鼠标单击, 测试鼠标消息,0); HDC hdc; hdc=GetDC(hwnd); TextOut(hdc,0,50, Visual C++,strlen( Visual C++ )); ReleaseDC(hwnd,hdc); break; case WM_PAINT: HDC hDC; PAINTSTRUCT ps; hDC=BeginPaint(hwnd,ps); TextOut(hDC,0,0, 江西农业大学,strlen(江西农业大学)); EndPaint(hwnd,ps); break; case WM_CLOSE: if(IDYES==MessageBox(hwnd, 是否真的结束?, 结束按钮,MB_YESNO)) DestroyWindow(hwnd);
显示全部
相似文档