Win32窗口编程P4(P5、P6内容代码实例)

#include
LRESULT CALLBACK WndProc(HWND hwnd, UINT umsg, WPARAM wParam,LPARAM lParam) {
	switch (umsg) {
	case WM_DESTROY:
		PostQuitMessage(0);//可以让GetMessage返回0
	    break;
	}
	return DefWindowProc(hwnd, umsg, wParam,lParam);
}
  //WINAPI也可以写成CALLBACK
int WINAPI WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _In_ LPSTR lpCmdLine, _In_ int nCmdShow) {
	//注册窗口类
	WNDCLASS wc = { 0 };
	wc.cbClsExtra = 0;
	wc.cbWndExtra = 0;
	wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
	wc.hCursor = NULL;
	wc.hIcon = NULL;
	wc.hInstance = hInstance;
	wc.lpfnWndProc = WndProc;
	wc.lpszClassName = "winmain";
	wc.lpszMenuName = NULL;
	wc.style = CS_HREDRAW | CS_VREDRAW;
	//将以上数据写入内核
	RegisterClass(&wc);
	
	HWND hwnd = CreateWindow("winmain", L"2233", WS_OVERLAPPEDWINDOW, 0, 0, 400, 320, NULL, NULL, hInstance, 0);

	UpdateWindow(hwnd);
	ShowWindow(hwnd, SW_SHOW);

	MSG umsg = { 0 };
	while (GetMessage(&umsg, NULL, 0, 0)) {
		TranslateMessage(&umsg);
		DispatchMessage(&umsg);
	}
	return 0;
}

你可能感兴趣的:(Windows窗口基础,c语言,windows)