#include <windows.h> #include <stdlib.h> #include <string.h> #include <tchar.h>
static TCHAR szWindowClass[] = _T("win32app"); static TCHAR szTitle[] = _T("win32 guided tour application"); HINSTANCE hInst;
//窗口过程函数 LRESULT CALLBACK WndProc(HWND hWnd, //handle to window UINT message, //message identifier WPARAM wParam, LPARAM lParam) { PAINTSTRUCT ps; HDC hdc; TCHAR greeting[] = _T("Hellow world!");
switch(message) { case WM_PAINT: hdc = BeginPaint(hWnd, &ps); TextOut(hdc, 5, 5, greeting, _tcslen(greeting)); EndPaint(hWnd, &ps); break;
case WM_DESTROY: PostQuitMessage(0); break;
default: return DefWindowProc(hWnd, message, wParam, lParam); break; }
return 0; }
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { //设计窗口类 WNDCLASSEX wcex;
wcex.cbSize = sizeof(WNDCLASSEX); // 定义结构体大小 wcex.style = CS_HREDRAW | CS_VREDRAW; //类的类型 wcex.lpfnWndProc = WndProc; //指向窗口过程函数的指针 wcex.cbClsExtra = 0; //类附加内存 wcex.cbWndExtra = 0; //窗口附加内存 wcex.hInstance = hInstance; //应用程序实例句柄 wcex.hCursor = LoadCursor(NULL, IDC_ARROW); //光标句柄 wcex.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_APPLICATION)); //图标句柄 wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1); //背景画刷 wcex.lpszClassName = szWindowClass; // wcex.lpszMenuName = NULL; // wcex.hIconSm = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_APPLICATION)); //
//注册 if(!RegisterClassEx(&wcex)) { MessageBox(NULL, _T("call to registerclassex failed!"), _T("win32 guided tour"), NULL); return 1; }
hInst = hInstance;
//创建窗口 HWND hWnd = CreateWindow( szWindowClass, //the name of the application szTitle, //the text that appears in the title bar WS_OVERLAPPEDWINDOW, //the type of window to create CW_USEDEFAULT, CW_USEDEFAULT, //initial position 500, 100, //initial size NULL, //the parent of this window NULL, //this application does not have a menu bar hInstance, //the first parameter form winMain NULL //not used in this application );
if(!hWnd) { MessageBox(NULL, _T("call to createwindow failed!"), _T("win32 guided tour"), NULL);
return 1; }
//显示及刷新 ShowWindow(hWnd, //the value returned from CreateWindow nCmdShow); //the fourth parameter from WinMain
UpdateWindow(hWnd); //消息循环 MSG msg; while(GetMessage(&msg, NULL, 0, 0)) { TranslateMessage(&msg); DispatchMessage(&msg); } return (int) msg.wParam;
}
|