##
vc6.0版本的"hello world"模板工程
// //@ // vc6.0版本的hello world #include "stdafx.h" #include <windows.h> LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);//回调函数; int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrev, LPSTR lpCmdLine, int nCmdShow) { WNDCLASS wndclass;//窗口类; MSG msg; wndclass.style = CS_HREDRAW | CS_VREDRAW; wndclass.lpfnWndProc = WndProc; wndclass.cbClsExtra = 0; wndclass.cbWndExtra = 0; wndclass.hInstance = hInstance; wndclass.hIcon = LoadIcon(NULL, IDI_APPLICATION); wndclass.hCursor = LoadCursor(NULL, IDC_ARROW); wndclass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH); wndclass.lpszMenuName = NULL; wndclass.lpszClassName = "HELLO"; //窗口类名称 if (!RegisterClass(&wndclass))//注册窗口; { MessageBox(NULL,"创建失败", "error", MB_OK); return false; } HWND hwnd = CreateWindow( //创建窗口,返回句柄; "HELLO", //1.窗口类名称 "window窗口创建", //2.窗口标题 WS_OVERLAPPEDWINDOW, //3.窗口风格 CW_USEDEFAULT, //4.窗口左上角相对于屏幕左上角的初始x坐标 CW_USEDEFAULT, //5.窗口左上角相对于屏幕左上角的初始y坐标 CW_USEDEFAULT, //6.窗口宽度 CW_USEDEFAULT, //7.窗口高度 NULL, //8.一个子窗口的父窗口的句柄,或隶属窗口的拥有者窗口的句柄,若没有拥有者窗口或者父窗口,置为NULL; NULL, //9.选单句柄 hInstance, //10.创建窗口对象的应用程序的实例句柄 NULL //11.创建窗口的额外参数 ); ShowWindow(hwnd, nCmdShow);//显示窗口; UpdateWindow(hwnd);//更新窗口; while (GetMessage(&msg, NULL, 0, 0)) //消息循环; { TranslateMessage(&msg); DispatchMessage(&msg); } return msg.wParam; } LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { switch (message) { case WM_PAINT: HDC hdc; PAINTSTRUCT ps; hdc = BeginPaint(hwnd, &ps); TextOut(hdc, 20, 20, "Window OK!", 10); EndPaint(hwnd, &ps); return 0; case WM_DESTROY: PostQuitMessage(0); return 0; } return DefWindowProc(hwnd, message, wParam, lParam); }
//VS 2005以上..
#include <windows.h> LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);//回调函数; int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrev, LPSTR lpCmdLine, int nCmdShow) { WNDCLASS wndclass;//窗口类; MSG msg; wndclass.style = CS_HREDRAW | CS_VREDRAW; wndclass.lpfnWndProc = WndProc; wndclass.cbClsExtra = 0; wndclass.cbWndExtra = 0; wndclass.hInstance = hInstance; wndclass.hIcon = LoadIcon(NULL, IDI_APPLICATION); wndclass.hCursor = LoadCursor(NULL, IDC_ARROW); wndclass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH); wndclass.lpszMenuName = NULL; wndclass.lpszClassName = L"Window窗口创建"; //窗口类名称 if (!RegisterClass(&wndclass))//注册窗口; { MessageBox(NULL, L"创建失败", L"error", MB_OK); return false; } HWND hwnd = CreateWindow( //创建窗口,返回句柄; L"Window窗口创建", //1.窗口类名称 L"window窗口创建", //2.窗口标题 WS_OVERLAPPEDWINDOW, //3.窗口风格 CW_USEDEFAULT, //4.窗口左上角相对于屏幕左上角的初始x坐标 CW_USEDEFAULT, //5.窗口左上角相对于屏幕左上角的初始y坐标 CW_USEDEFAULT, //6.窗口宽度 CW_USEDEFAULT, //7.窗口高度 NULL, //8.一个子窗口的父窗口的句柄,或隶属窗口的拥有者窗口的句柄,若没有拥有者窗口或者父窗口,置为NULL; NULL, //9.选单句柄 hInstance, //10.创建窗口对象的应用程序的实例句柄 NULL //11.创建窗口的额外参数 ); ShowWindow(hwnd, nCmdShow);//显示窗口; UpdateWindow(hwnd);//更新窗口; while (GetMessage(&msg, NULL, 0, 0)) //消息循环; { TranslateMessage(&msg); DispatchMessage(&msg); } return msg.wParam; } LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { switch (message) { case WM_PAINT: HDC hdc; PAINTSTRUCT ps; hdc = BeginPaint(hwnd, &ps); TextOut(hdc, 20, 20, L"Window OK!", 10); EndPaint(hwnd, &ps); return 0; case WM_DESTROY: PostQuitMessage(0); return 0; } return DefWindowProc(hwnd, message, wParam, lParam); }