您的位置:首页 > 其它

一个win32窗口创建示例

2014-04-27 11:31 941 查看
/*一个简单的win32窗口调用*/#include<Windows.h>#include<tchar.h> //声明窗口函数LRESULT CALLBACK WindowProc(HWND hwnd,       UINT uMsg,       WPARAM wParam,       LPARAM lparam       );int WINAPI WinMain(     HINSTANCE hInstance,     HINSTANCE hPrevInatance,     LPSTR lpCmdLine,     int nCmdShow     ){ WNDCLASS wndclass; wndclass.lpfnWndProc=WindowProc; wndclass.cbClsExtra=0; wndclass.cbWndExtra=0; wndclass.style=CS_HREDRAW|CS_VREDRAW; wndclass.lpszClassName=_T("我的窗体"); wndclass.hInstance=hInstance; wndclass.hCursor=LoadCursor(NULL,IDC_ARROW); wndclass.hIcon=0; wndclass.hbrBackground=(HBRUSH)(COLOR_WINDOW+1); wndclass.lpszMenuName=0; //注册窗口类 if(RegisterClass(&wndclass)==0) {  MessageBox(0,_T("注册窗口类失败"),_T("我的窗体"),MB_OK);  return 0; } //创建窗口实列 HWND hWnd = CreateWindow(_T("我的窗体"),_T("我的第一个窗体"),WS_OVERLAPPEDWINDOW,100,100,500,400,0,0,hInstance,0); //显示和更新窗口 ShowWindow(hWnd,SW_SHOW); UpdateWindow(hWnd);

 //消息循环 MSG msg; while(GetMessage(&msg,0,0,0)) {  TranslateMessage(&msg);  DispatchMessage(&msg); } return 0;}//定义窗口函数LRESULT CALLBACK WindowProc(       HWND hwnd,       UINT uMsg,       WPARAM wParam,       LPARAM IParam       ){ switch(uMsg) { case WM_CLOSE:  PostQuitMessage(0);  break; default:  return DefWindowProc(hwnd,uMsg,wParam,IParam); } return 0;}

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  win32 窗口