Win32_Window(day02)
Posted Kernel001
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Win32_Window(day02)相关的知识,希望对你有一定的参考价值。
#include <Windows.h> //窗口处理函数 HINSTANCE g_hIns; LRESULT CALLBACK WndProc(HWND hWnd,UINT msgID, WPARAM wParam,LPARAM IParam) { switch (msgID) { case WM_DESTROY: PostQuitMessage(0);//消息窗口关闭按钮点击后,退出程序 break; } return DefWindowProc(hWnd,msgID,wParam,IParam); //给各种消息做默认处理 } //注册窗口 void Register(LPSTR IpClassName,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_hIns; wce.lpfnWndProc = wndProc; wce.lpszClassName = IpClassName; wce.lpszMenuName = NULL ; wce.style = CS_HREDRAW|CS_VREDRAW; RegisterClassEx(&wce); } //创建窗口 HWND CreateMain(LPSTR IpClassName,LPSTR IpWndName) { HWND hWnd = CreateWindowEx(0,IpClassName,IpWndName,WS_OVERLAPPEDWINDOW, 100,100,700,500,NULL,NULL,g_hIns,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 CALLBACK WinMain(HINSTANCE hIns,HINSTANCE hPreIns,LPSTR IpCmdline,int nCmdShow) { g_hIns = hIns; //注册窗口类 Register("Main",WndProc); //创建窗口 HWND hWnd = CreateMain("Main","Window"); //显示窗口 Display(hWnd); //消息循环 Message(); return 0; }
以上是关于Win32_Window(day02)的主要内容,如果未能解决你的问题,请参考以下文章