第一个Windows程序
2013-12-17 21:50
330 查看
#include <windows.h> #include <stdio.h> LRESULT CALLBACK winhehepro( HWND hwnd, // handle to window UINT uMsg, // message identifier WPARAM wParam, // first message parameter LPARAM lParam // second message parameter ); int WINAPI WinMain( HINSTANCE hInstance, // handle to current instance HINSTANCE hPrevInstance, // handle to previous instance LPSTR lpCmdLine, // pointer to command line int nCmdShow // show state of window ) { WNDCLASS wndcls; wndcls.cbClsExtra=0; wndcls.cbWndExtra=0; wndcls.hbrBackground=(HBRUSH)GetStockObject(BLACK_BRUSH); wndcls.hCursor=LoadCursor(NULL,IDC_CROSS); wndcls.hIcon=LoadIcon(NULL,IDI_ERROR); wndcls.hInstance=hInstance; wndcls.lpfnWndProc=winhehepro; wndcls.lpszClassName="hehe"; wndcls.lpszMenuName=NULL; wndcls.style=CS_HREDRAW|CS_VREDRAW; RegisterClass(&wndcls); HWND hwnd;//创建窗口 hwnd=CreateWindow( "hehe", // pointer to registered class name "Jarily", // pointer to window name WS_OVERLAPPEDWINDOW, // window style 0, // horizontal position of window 0, // vertical position of window 600, // window width 400, // window height NULL, // handle to parent or owner window NULL, // handle to menu or child-window identifier hInstance, // handle to application instance NULL // pointer to window-creation data ); ShowWindow(hwnd,SW_SHOWNORMAL); UpdateWindow(hwnd); MSG msg;//消息循环 //while(GetMessage(&msg,hwnd,0,0)) while(GetMessage(&msg,NULL,0,0)) { TranslateMessage(&msg); DispatchMessage(&msg); } return msg.wParam; //return 0; } LRESULT CALLBACK winhehepro( HWND hwnd, // handle to window UINT uMsg, // message identifier WPARAM wParam, // first message parameter LPARAM lParam // second message parameter ) { switch(uMsg) { case WM_CHAR: char szChar[20]; sprintf(szChar,"char is %d",wParam); MessageBox(hwnd,szChar,"xixi",0); break; case WM_LBUTTONDOWN: MessageBox(hwnd,"left button is checked","xixi",0); HDC hdc; hdc=GetDC(hwnd);//不能在响应WM_PAINT消息时调用 TextOut(hdc,0,50,"Hello World!",strlen("Hello World!")); ReleaseDC(hwnd,hdc); break; case WM_PAINT: HDC hDC; PAINTSTRUCT ps; hDC=BeginPaint(hwnd,&ps);//BeginPaint只能在响应WM_PAINT消息时调用 TextOut(hDC,0,0,"hehe and xixi!",strlen("hehe and xixi!")); EndPaint(hwnd,&ps); break; case WM_CLOSE: if(IDYES==MessageBox(hwnd,"是否真的退出窗口?","iloveyou",MB_YESNO)) { DestroyWindow(hwnd); } break; case WM_DESTROY: PostQuitMessage(0); break; default: return DefWindowProc(hwnd,uMsg,wParam,lParam); } return 0; }
相关文章推荐
- 我的第一个windows程序
- Windows程序设计--第一个窗口程序
- 第一个Windows程序
- 运行第一个 Delphi 7/XE2/Lazarus 的 Windows 程序,并熟悉 IDE
- 一个计算机爱好者的不完整回忆(二十)第一个windows程序
- 第一个带界面的Windows程序
- 最完整的Windows下React Native开发环境搭建与第一个程序HelloWorld
- windows驱动编程入门(第一个程序)
- 你的第一个Windows程序——绘制窗口
- 你的第一个Windows程序——关闭窗口
- windows程序设计(1)---第一个windows程序--MessageBox
- 窗口程序你的第一个Windows程序窗口程序
- 第一个Windows程序讲解
- MFC第一个例子 -- windows程序运行原理
- VC#初学入门:第一个Windows程序
- 创建你的第一个带有窗口的Windows程序
- [C语言](一)第一个Windows 32 API的窗口程序
- 手工编写第一个windows程序
- 第一个Windows程序
- 【Caffe的C++接口使用说明(一)】caffe_windows下的第一个测试程序学习教程