标签:
//采用windows API函数来生成一个窗口显示helloword: #include <windows.h> LRESULT CALLBACK myWndProc(HWND hWindow, UINT msg, WPARAM wParam, LPARAM lParam); //进入WinMain函数 int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow) { const static TCHAR appName[] = TEXT("Hello world"); //初始化WNDCLASSEX,调用RegisterClassEx函数注册窗口类 WNDCLASSEX myWin; myWin.cbSize = sizeof(myWin); myWin.style = CS_HREDRAW | CS_VREDRAW; myWin.lpfnWndProc = myWndProc; myWin.cbClsExtra = 0; myWin.cbWndExtra = 0; myWin.hInstance = hInstance; myWin.hIcon = 0; myWin.hIconSm = 0; myWin.hCursor = 0; myWin.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1); myWin.lpszMenuName = 0; myWin.lpszClassName = appName; //Register ,调用RegisterClassEx函数注册窗口类 if (!RegisterClassEx(&myWin)) return 0; const HWND hWindow = CreateWindow( appName, appName, WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, 0, 0, hInstance, 0); //调用ShowWindow和UpdateWindow函数显示并更新窗口 /*进入消息循环。关于消息循环再简单说下,Windows应用程序是消息驱动的, 系统或用户让应用程序进行某项操作或完成某个任务时会发送消息, 进入程序的消息队列,然后消息循环会将消息队列中的消息取出, 交予相应的窗口过程处理,此程序的窗口过程函数就是myWndProc函数, 窗口过程函数处理完消息就完成了某项操作或任务。 本例是要显示“HELLO WORLD”字符串,UpdateWindow函数会发送WM_PAINT消息, 但是此消息不经过消息队列而是直接送到窗口过程处理, 在窗口过程函数中最终绘制了“HELLO WORLD”字符串。*/ ShowWindow(hWindow,iCmdShow); UpdateWindow(hWindow); { MSG msg; while(GetMessage(&msg,0,0,0)) { TranslateMessage(&msg); DispatchMessage(&msg); } return (int)msg.wParam; } } LRESULT CALLBACK myWndProc(HWND hWindow, UINT msg, WPARAM wParam, LPARAM lParam) { if (msg==WM_PAINT) { PAINTSTRUCT ps; const HDC hDC = BeginPaint(hWindow,&ps); RECT rect; GetClientRect(hWindow,&rect); DrawText(hDC,TEXT("HELLO WORLD"),-1,&rect, DT_SINGLELINE | DT_CENTER | DT_VCENTER); EndPaint(hWindow,&ps); return 0; } else if (msg==WM_DESTROY) { PostQuitMessage(0); return 0; } return DefWindowProc(hWindow,msg,wParam,lParam); }
MFC_1——采用windows API函数来生成一个窗口显示helloword
标签:
原文地址:http://www.cnblogs.com/yanliang12138/p/4444818.html