// WIN_PAINT_MESSAGE.cpp : 定义应用程序的入口点。//#include "stdafx.h"#include "windows_Mouse.h"#include <iostream>HINSTANCE g_hInst = NULL;HANDLE g_hStdout = NULL;CHAR szText[256] = { 0 };//第二步,窗口处理函数void OnPaint(HWND hWnd, UINT nMsg, WPARAM wParam, LPARAM lParam){ PAINTSTRUCT ps = { 0 }; HDC hDC = BeginPaint(hWnd, &ps); TextOut(hDC, LOWORD(lParam)+100, HIWORD(lParam)+100, "oooooooooooooooooo", strlen("oooooooooooooooooo")); EndPaint(hWnd, &ps);}LRESULT CALLBACK WndProc(HWND hWnd, UINT nMsg, WPARAM wParam, LPARAM lParam){ switch (nMsg) { case WM_PAINT: OnPaint(hWnd, nMsg, wParam, lParam); break; case WM_MOUSEMOVE: sprintf_s(szText, 256, "WM_MOUSEMOVE:X=%d, Y=%d\n",LOWORD(lParam),HIWORD(lParam)); WriteConsole(g_hStdout, szText, strlen(szText), NULL, NULL); PostMessage(hWnd, WM_PAINT, wParam, lParam); InvalidateRect(hWnd, NULL, TRUE); break; case WM_DESTROY: sprintf_s(szText, 256, "bug post quit!\n"); WriteConsole(g_hStdout, szText, strlen(szText), NULL, NULL); PostQuitMessage(0); break; } return DefWindowProc(hWnd, nMsg, wParam, lParam);}//第三步,注册窗口BOOL RegisterWnd(LPSTR pszClassName){ WNDCLASSEX wce = { 0 }; wce.cbSize = sizeof(wce); wce.cbClsExtra = 0; wce.cbWndExtra = 0; wce.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1); wce.hCursor = NULL; wce.hIcon = NULL; wce.hIconSm = NULL; wce.hInstance = g_hInst; wce.lpfnWndProc = WndProc; wce.lpszClassName = pszClassName; wce.style = CS_HREDRAW|CS_VREDRAW; ATOM aTom = RegisterClassEx(&wce); if (aTom == 0) { return FALSE; } else { return TRUE; }}//第四步,创建窗口HWND CreateWnd(LPSTR pszClassName){ HWND hWnd = CreateWindowEx(0, pszClassName, "清风明月", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, g_hInst, NULL); return hWnd;}//第五步,显示窗口void ShowWnd(HWND hWnd){ ShowWindow(hWnd, SW_SHOW); UpdateWindow(hWnd);}//第六步,消息循环void Msg(){ MSG msg = { 0 }; while (GetMessage(&msg, NULL, 0, 0)) { TranslateMessage(&msg); DispatchMessage(&msg); }}void ConsoloWnd(){ AllocConsole(); g_hStdout = GetStdHandle(STD_OUTPUT_HANDLE); CHAR szText[] = "Debug start:\n"; WriteConsole(g_hStdout, szText, strlen(szText), NULL, NULL);}//第一步,入口函数int WINAPI WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _In_ LPSTR lpCmdLine, _In_ int nShowCmd){ g_hInst = hInstance; ConsoloWnd(); RegisterWnd("oooo"); HWND hWnd = CreateWnd("oooo"); ShowWnd(hWnd); Msg(); return 0;}