1windows_Mouse

  1. // WIN_PAINT_MESSAGE.cpp : 定义应用程序的入口点。
  2. //
  3. #include "stdafx.h"
  4. #include "windows_Mouse.h"
  5. #include <iostream>
  6. HINSTANCE g_hInst = NULL;
  7. HANDLE g_hStdout = NULL;
  8. CHAR szText[256] = { 0 };
  9. //第二步,窗口处理函数
  10. void OnPaint(HWND hWnd, UINT nMsg, WPARAM wParam, LPARAM lParam)
  11. {
  12. PAINTSTRUCT ps = { 0 };
  13. HDC hDC = BeginPaint(hWnd, &ps);
  14. TextOut(hDC, LOWORD(lParam)+100, HIWORD(lParam)+100, "oooooooooooooooooo", strlen("oooooooooooooooooo"));
  15. EndPaint(hWnd, &ps);
  16. }
  17. LRESULT CALLBACK WndProc(HWND hWnd, UINT nMsg, WPARAM wParam, LPARAM lParam)
  18. {
  19. switch (nMsg)
  20. {
  21. case WM_PAINT:
  22. OnPaint(hWnd, nMsg, wParam, lParam);
  23. break;
  24. case WM_MOUSEMOVE:
  25. sprintf_s(szText, 256, "WM_MOUSEMOVE:X=%d, Y=%d\n",LOWORD(lParam),HIWORD(lParam));
  26. WriteConsole(g_hStdout, szText, strlen(szText), NULL, NULL);
  27. PostMessage(hWnd, WM_PAINT, wParam, lParam);
  28. InvalidateRect(hWnd, NULL, TRUE);
  29. break;
  30. case WM_DESTROY:
  31. sprintf_s(szText, 256, "bug post quit!\n");
  32. WriteConsole(g_hStdout, szText, strlen(szText), NULL, NULL);
  33. PostQuitMessage(0);
  34. break;
  35. }
  36. return DefWindowProc(hWnd, nMsg, wParam, lParam);
  37. }
  38. //第三步,注册窗口
  39. BOOL RegisterWnd(LPSTR pszClassName)
  40. {
  41. WNDCLASSEX wce = { 0 };
  42. wce.cbSize = sizeof(wce);
  43. wce.cbClsExtra = 0;
  44. wce.cbWndExtra = 0;
  45. wce.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
  46. wce.hCursor = NULL;
  47. wce.hIcon = NULL;
  48. wce.hIconSm = NULL;
  49. wce.hInstance = g_hInst;
  50. wce.lpfnWndProc = WndProc;
  51. wce.lpszClassName = pszClassName;
  52. wce.style = CS_HREDRAW|CS_VREDRAW;
  53. ATOM aTom = RegisterClassEx(&wce);
  54. if (aTom == 0)
  55. {
  56. return FALSE;
  57. }
  58. else
  59. {
  60. return TRUE;
  61. }
  62. }
  63. //第四步,创建窗口
  64. HWND CreateWnd(LPSTR pszClassName)
  65. {
  66. HWND hWnd = CreateWindowEx(0, pszClassName, "清风明月", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, g_hInst, NULL);
  67. return hWnd;
  68. }
  69. //第五步,显示窗口
  70. void ShowWnd(HWND hWnd)
  71. {
  72. ShowWindow(hWnd, SW_SHOW);
  73. UpdateWindow(hWnd);
  74. }
  75. //第六步,消息循环
  76. void Msg()
  77. {
  78. MSG msg = { 0 };
  79. while (GetMessage(&msg, NULL, 0, 0))
  80. {
  81. TranslateMessage(&msg);
  82. DispatchMessage(&msg);
  83. }
  84. }
  85. void ConsoloWnd()
  86. {
  87. AllocConsole();
  88. g_hStdout = GetStdHandle(STD_OUTPUT_HANDLE);
  89. CHAR szText[] = "Debug start:\n";
  90. WriteConsole(g_hStdout, szText, strlen(szText), NULL, NULL);
  91. }
  92. //第一步,入口函数
  93. int WINAPI WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _In_ LPSTR lpCmdLine, _In_ int nShowCmd)
  94. {
  95. g_hInst = hInstance;
  96. ConsoloWnd();
  97. RegisterWnd("oooo");
  98. HWND hWnd = CreateWnd("oooo");
  99. ShowWnd(hWnd);
  100. Msg();
  101. return 0;
  102. }

来自为知笔记(Wiz)

时间: 2024-10-13 11:18:49

1windows_Mouse的相关文章