Tools.cpp 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. // Tools.cpp : Defines the entry point for the application.
  2. //
  3. #include "stdafx.h"
  4. #include "Tools.h"
  5. #define MAX_LOADSTRING 100
  6. // Global Variables:
  7. HINSTANCE hInst; // current instance
  8. TCHAR szTitle[MAX_LOADSTRING]; // The title bar text
  9. TCHAR 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 _tWinMain(HINSTANCE hInstance,
  16. HINSTANCE hPrevInstance,
  17. LPTSTR lpCmdLine,
  18. int nCmdShow)
  19. {
  20. UNREFERENCED_PARAMETER(hPrevInstance);
  21. UNREFERENCED_PARAMETER(lpCmdLine);
  22. // TODO: Place code here.
  23. MSG msg;
  24. HACCEL hAccelTable;
  25. // Initialize global strings
  26. LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
  27. LoadString(hInstance, IDC_TOOLS, szWindowClass, MAX_LOADSTRING);
  28. MyRegisterClass(hInstance);
  29. // Perform application initialization:
  30. if (!InitInstance (hInstance, nCmdShow))
  31. {
  32. return FALSE;
  33. }
  34. hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_TOOLS));
  35. // Main message loop:
  36. while (GetMessage(&msg, NULL, 0, 0))
  37. {
  38. if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
  39. {
  40. TranslateMessage(&msg);
  41. DispatchMessage(&msg);
  42. }
  43. }
  44. return (int) msg.wParam;
  45. }
  46. //
  47. // FUNCTION: MyRegisterClass()
  48. //
  49. // PURPOSE: Registers the window class.
  50. //
  51. // COMMENTS:
  52. //
  53. // This function and its usage are only necessary if you want this code
  54. // to be compatible with Win32 systems prior to the 'RegisterClassEx'
  55. // function that was added to Windows 95. It is important to call this function
  56. // so that the application will get 'well formed' small icons associated
  57. // with it.
  58. //
  59. ATOM MyRegisterClass(HINSTANCE hInstance)
  60. {
  61. WNDCLASSEX wcex;
  62. wcex.cbSize = sizeof(WNDCLASSEX);
  63. wcex.style = CS_HREDRAW | CS_VREDRAW;
  64. wcex.lpfnWndProc = WndProc;
  65. wcex.cbClsExtra = 0;
  66. wcex.cbWndExtra = 0;
  67. wcex.hInstance = hInstance;
  68. wcex.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_TOOLS));
  69. wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
  70. wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
  71. wcex.lpszMenuName = MAKEINTRESOURCE(IDC_TOOLS);
  72. wcex.lpszClassName = szWindowClass;
  73. wcex.hIconSm = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_SMALL));
  74. return RegisterClassEx(&wcex);
  75. }
  76. //
  77. // FUNCTION: InitInstance(HINSTANCE, int)
  78. //
  79. // PURPOSE: Saves instance handle and creates main window
  80. //
  81. // COMMENTS:
  82. //
  83. // In this function, we save the instance handle in a global variable and
  84. // create and display the main program window.
  85. //
  86. BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
  87. {
  88. HWND hWnd;
  89. hInst = hInstance; // Store instance handle in our global variable
  90. hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
  91. CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);
  92. if (!hWnd)
  93. {
  94. return FALSE;
  95. }
  96. ShowWindow(hWnd, nCmdShow);
  97. UpdateWindow(hWnd);
  98. return TRUE;
  99. }
  100. //
  101. // FUNCTION: WndProc(HWND, UINT, WPARAM, LPARAM)
  102. //
  103. // PURPOSE: Processes messages for the main window.
  104. //
  105. // WM_COMMAND - process the application menu
  106. // WM_PAINT - Paint the main window
  107. // WM_DESTROY - post a quit message and return
  108. //
  109. //
  110. LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
  111. {
  112. int wmId, wmEvent;
  113. PAINTSTRUCT ps;
  114. HDC hdc;
  115. switch (message)
  116. {
  117. case WM_COMMAND:
  118. wmId = LOWORD(wParam);
  119. wmEvent = HIWORD(wParam);
  120. // Parse the menu selections:
  121. switch (wmId)
  122. {
  123. case IDM_ABOUT:
  124. DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About);
  125. break;
  126. case IDM_EXIT:
  127. DestroyWindow(hWnd);
  128. break;
  129. default:
  130. return DefWindowProc(hWnd, message, wParam, lParam);
  131. }
  132. break;
  133. case WM_PAINT:
  134. hdc = BeginPaint(hWnd, &ps);
  135. // TODO: Add any drawing code here...
  136. EndPaint(hWnd, &ps);
  137. break;
  138. case WM_DESTROY:
  139. PostQuitMessage(0);
  140. break;
  141. default:
  142. return DefWindowProc(hWnd, message, wParam, lParam);
  143. }
  144. return 0;
  145. }
  146. // Message handler for about box.
  147. INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
  148. {
  149. UNREFERENCED_PARAMETER(lParam);
  150. switch (message)
  151. {
  152. case WM_INITDIALOG:
  153. return (INT_PTR)TRUE;
  154. case WM_COMMAND:
  155. if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
  156. {
  157. EndDialog(hDlg, LOWORD(wParam));
  158. return (INT_PTR)TRUE;
  159. }
  160. break;
  161. }
  162. return (INT_PTR)FALSE;
  163. }