首页 > 代码库 > Windoows窗口程序三
Windoows窗口程序三
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <windows.h> HINSTANCE g_hInstance=0; //主窗口处理函数 LRESULT WndProc(HWND hWnd,UINT nMsg,WPARAM wParam,LPARAM lParam) { switch(nMsg) { case WM_DESTROY: PostQuitMessage(0); break; default: break; } return DefWindowProc(hWnd,nMsg,wParam,lParam); } //注册窗口类 BOOL Register(LPSTR lpClassName,WNDPROC wndproc) { WNDCLASSEX wce={0}; wce.cbSize=sizeof(wce); wce.cbClsExtra=0; wce.cbWndExtra=0; wce.hbrBackground=(HBRUSH)(COLOR_WINDOW+1); wce.hCursor=NULL; wce.hIcon=NULL; wce.hIconSm=NULL; wce.hInstance=g_hInstance; wce.lpfnWndProc=wndproc; wce.lpszClassName=lpClassName; wce.lpszMenuName=NULL; wce.style=CS_HREDRAW|CS_VREDRAW; ATOM nAtom=RegisterClassEx(&wce); if(nAtom==0) { return FALSE; } return TRUE; } //创建主窗口 HWND CreateMain(LPSTR lpClassName,LPSTR lpWndName) { HWND hWnd=CreateWindowEx(0,lpClassName,lpWndName,WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,NULL,NULL,g_hInstance,NULL); return hWnd; } //显示窗口 void Display(HWND hWnd) { ShowWindow(hWnd,SW_SHOW); UpdateWindow(hWnd); } //消息循环 void Message() { MSG nMsg={0}; while(GetMessage(&nMsg,NULL,0,0)) { TranslateMessage(&nMsg); DispatchMessage(&nMsg); } } int WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow) { g_hInstance=hInstance; if(!Register("Main",(WNDPROC)WndProc)) { MessageBox(NULL,"注册失败","error",MB_OK); return -1; } HWND hWnd=CreateMain("Main","window"); Display(hWnd); Message(); return 0; }
Windoows窗口程序三
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。