No Description

TestApp1.cpp 4.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. // TestApp1.cpp : Defines the entry point for the application.
  2. //
  3. #include "stdafx.h"
  4. #include "TestApp1.h"
  5. #define MAX_LOADSTRING 100
  6. // Global Variables:
  7. HINSTANCE hInst; // current instance
  8. WCHAR szTitle[MAX_LOADSTRING]; // The title bar text
  9. WCHAR szWindowClass[MAX_LOADSTRING]; // the main window class name
  10. // Forward declarations of functions included in this code module:
  11. ATOM MyRegisterClass(HINSTANCE hInstance);
  12. BOOL InitInstance(HINSTANCE, int);
  13. LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
  14. INT_PTR CALLBACK About(HWND, UINT, WPARAM, LPARAM);
  15. int APIENTRY wWinMain(_In_ HINSTANCE hInstance,
  16. _In_opt_ HINSTANCE hPrevInstance,
  17. _In_ LPWSTR lpCmdLine,
  18. _In_ int nCmdShow)
  19. {
  20. UNREFERENCED_PARAMETER(hPrevInstance);
  21. UNREFERENCED_PARAMETER(lpCmdLine);
  22. // TODO: Place code here.
  23. // Initialize global strings
  24. LoadStringW(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
  25. LoadStringW(hInstance, IDC_TESTAPP1, szWindowClass, MAX_LOADSTRING);
  26. MyRegisterClass(hInstance);
  27. // Perform application initialization:
  28. if (!InitInstance (hInstance, nCmdShow))
  29. {
  30. return FALSE;
  31. }
  32. HACCEL hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_TESTAPP1));
  33. MSG msg;
  34. // Main message loop:
  35. while (GetMessage(&msg, nullptr, 0, 0))
  36. {
  37. if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
  38. {
  39. TranslateMessage(&msg);
  40. DispatchMessage(&msg);
  41. }
  42. }
  43. return (int) msg.wParam;
  44. }
  45. //
  46. // FUNCTION: MyRegisterClass()
  47. //
  48. // PURPOSE: Registers the window class.
  49. //
  50. ATOM MyRegisterClass(HINSTANCE hInstance)
  51. {
  52. WNDCLASSEXW wcex;
  53. wcex.cbSize = sizeof(WNDCLASSEX);
  54. wcex.style = CS_HREDRAW | CS_VREDRAW;
  55. wcex.lpfnWndProc = WndProc;
  56. wcex.cbClsExtra = 0;
  57. wcex.cbWndExtra = 0;
  58. wcex.hInstance = hInstance;
  59. wcex.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_TESTAPP1));
  60. wcex.hCursor = LoadCursor(nullptr, IDC_ARROW);
  61. wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
  62. wcex.lpszMenuName = MAKEINTRESOURCEW(IDC_TESTAPP1);
  63. wcex.lpszClassName = szWindowClass;
  64. wcex.hIconSm = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_SMALL));
  65. return RegisterClassExW(&wcex);
  66. }
  67. //
  68. // FUNCTION: InitInstance(HINSTANCE, int)
  69. //
  70. // PURPOSE: Saves instance handle and creates main window
  71. //
  72. // COMMENTS:
  73. //
  74. // In this function, we save the instance handle in a global variable and
  75. // create and display the main program window.
  76. //
  77. BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
  78. {
  79. hInst = hInstance; // Store instance handle in our global variable
  80. HWND hWnd = CreateWindowW(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
  81. CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, nullptr, nullptr, hInstance, nullptr);
  82. if (!hWnd)
  83. {
  84. return FALSE;
  85. }
  86. ShowWindow(hWnd, nCmdShow);
  87. UpdateWindow(hWnd);
  88. return TRUE;
  89. }
  90. //
  91. // FUNCTION: WndProc(HWND, UINT, WPARAM, LPARAM)
  92. //
  93. // PURPOSE: Processes messages for the main window.
  94. //
  95. // WM_COMMAND - process the application menu
  96. // WM_PAINT - Paint the main window
  97. // WM_DESTROY - post a quit message and return
  98. //
  99. //
  100. LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
  101. {
  102. switch (message)
  103. {
  104. case WM_COMMAND:
  105. {
  106. int wmId = LOWORD(wParam);
  107. // Parse the menu selections:
  108. switch (wmId)
  109. {
  110. case IDM_ABOUT:
  111. DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About);
  112. break;
  113. case IDM_EXIT:
  114. DestroyWindow(hWnd);
  115. break;
  116. default:
  117. return DefWindowProc(hWnd, message, wParam, lParam);
  118. }
  119. }
  120. break;
  121. case WM_PAINT:
  122. {
  123. PAINTSTRUCT ps;
  124. HDC hdc = BeginPaint(hWnd, &ps);
  125. // TODO: Add any drawing code that uses hdc here...
  126. EndPaint(hWnd, &ps);
  127. }
  128. break;
  129. case WM_DESTROY:
  130. PostQuitMessage(0);
  131. break;
  132. default:
  133. return DefWindowProc(hWnd, message, wParam, lParam);
  134. }
  135. return 0;
  136. }
  137. // Message handler for about box.
  138. INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
  139. {
  140. UNREFERENCED_PARAMETER(lParam);
  141. switch (message)
  142. {
  143. case WM_INITDIALOG:
  144. return (INT_PTR)TRUE;
  145. case WM_COMMAND:
  146. if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
  147. {
  148. EndDialog(hDlg, LOWORD(wParam));
  149. return (INT_PTR)TRUE;
  150. }
  151. break;
  152. }
  153. return (INT_PTR)FALSE;
  154. }