#include <windows.h> #include <tchar.h> #include <stdio.h> LRESULT CALLBACK WinSunProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam ); int WINAPI WinMain( __in HINSTANCE hInstance, __in_opt HINSTANCE hPrevInstance, __in_opt LPSTR lpCmdLine, __in int nShowCmd ) { WNDCLASS wc; wc.cbClsExtra = 0; wc.cbWndExtra = 0; wc.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH); wc.hCursor = LoadCursor(NULL, IDC_CROSS); wc.hIcon = LoadIcon(NULL, IDI_APPLICATION); wc.hInstance = hInstance; wc.lpszClassName = _T("weixin"); wc.lpszMenuName = NULL; wc.style = CS_HREDRAW | CS_VREDRAW; wc.lpfnWndProc = WinSunProc; RegisterClass(&wc); HWND hWnd; hWnd = CreateWindow(_T("weixin"), _T("Hello(Test)"), WS_OVERLAPPEDWINDOW, 0, 0, 600, 400, NULL, NULL, hInstance, NULL); ShowWindow(hWnd, SW_NORMAL); UpdateWindow(hWnd); MSG msg; while (GetMessage(&msg, NULL, 0, 0)) { TranslateMessage(&msg); DispatchMessage(&msg); } return 0; } LRESULT CALLBACK WinSunProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam ) { switch (uMsg) { case WM_CHAR: TCHAR szChar[20]; wsprintf(szChar, _T("char is %s"), wParam); MessageBox(hwnd, szChar, _T("tell you"), 0); break; case WM_LBUTTONDOWN: MessageBox(hwnd, _T("left button down"), _T("tell you"), 0); HDC hdc; hdc = GetDC(hwnd); TextOut(hdc, 0, 50, _T("write a string in left button down"), wcslen(_T("write a string in left button down"))); ReleaseDC(hwnd, hdc); break; case WM_PAINT: HDC hDc; PAINTSTRUCT ps; hDc = BeginPaint(hwnd, &ps); TextOut(hDc, 0, 0, _T("write a string always"), wcslen(_T("write a string always"))); EndPaint(hwnd, &ps); break; case WM_CLOSE: if (IDYES == MessageBox(hwnd, _T("Really to want to quit?"), _T("quit hit"), MB_YESNO)) { DestroyWindow(hwnd); } break; case WM_DESTROY: PostQuitMessage(0); break; default: return DefWindowProc(hwnd, uMsg, wParam, lParam); } return 0; }