- // WinBase.cpp : Defines the entry point for the application.
- //
- //#include "stdafx.h"
- #include <windows.h>
- //窗口处理函数(用于处理消息)
- LRESULT CALLBACK WndProc( HWND hWnd, UINT msgID,
- WPARAM wParam, LPARAM lParam )
- {
- switch( msgID )
- {
- case WM_DESTROY:
- PostQuitMessage( 0 );//可以使GetMessage返回0??
- break;
- }
- return DefWindowProc( hWnd, msgID, wParam, lParam );
- }
- int APIENTRY WinMain(HINSTANCE hInstance,
- HINSTANCE hPrevInstance,
- LPSTR lpCmdLine,
- 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)WndProc;
- wc.lpszClassName = "Main";
- wc.lpszMenuName = NULL;
- wc.style = CS_HREDRAW | CS_VREDRAW;
- RegisterClass( &wc );//将以上所有赋值全部写入操作系统
- //创建窗口(内存中创建)
- HWND hWnd = CreateWindow( "Main", "window",
- WS_OVERLAPPEDWINDOW, 100, 100, 500, 500, NULL,
- NULL, hInstance, NULL );
- //显示窗口(绘制窗口图像)
- ShowWindow( hWnd, SW_SHOW );
- //消息循环
- MSG msg = { 0 };
- while( GetMessage(&msg, NULL, 0, 0) )
- {
- TranslateMessage( &msg );
- DispatchMessage( &msg );//派发到窗口处理函数
- }
- return 0;
- }
- //该片段来自于http://www.codesnippet.cn/detail/2605201512657.html
来源: http://www.codesnippet.cn/detail/2605201512657.html