Advertisement
Guest User

Untitled

a guest
Nov 12th, 2018
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.08 KB | None | 0 0
  1. // Win32Project3.cpp : Defines the entry point for the application.
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "Win32Project3.h"
  6. #include "Commdlg.h"
  7. #define MAX_LOADSTRING 100
  8.  
  9. // Global Variables:
  10. HINSTANCE hInst; // current instance
  11. WCHAR szTitle[MAX_LOADSTRING]; // The title bar text
  12. WCHAR szWindowClass[MAX_LOADSTRING]; // the main window class name
  13.  
  14. // Forward declarations of functions included in this code module:
  15. ATOM MyRegisterClass(HINSTANCE hInstance);
  16. BOOL InitInstance(HINSTANCE, int);
  17. LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
  18. INT_PTR CALLBACK About(HWND, UINT, WPARAM, LPARAM);
  19.  
  20. int APIENTRY wWinMain(_In_ HINSTANCE hInstance,
  21. _In_opt_ HINSTANCE hPrevInstance,
  22. _In_ LPWSTR lpCmdLine,
  23. _In_ int nCmdShow)
  24. {
  25. UNREFERENCED_PARAMETER(hPrevInstance);
  26. UNREFERENCED_PARAMETER(lpCmdLine);
  27.  
  28. // TODO: Place code here.
  29.  
  30. // Initialize global strings
  31. LoadStringW(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
  32. LoadStringW(hInstance, IDC_WIN32PROJECT3, szWindowClass, MAX_LOADSTRING);
  33. MyRegisterClass(hInstance);
  34.  
  35. // Perform application initialization:
  36. if (!InitInstance (hInstance, nCmdShow))
  37. {
  38. return FALSE;
  39. }
  40.  
  41. HACCEL hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_WIN32PROJECT3));
  42.  
  43. MSG msg;
  44.  
  45. // Main message loop:
  46. while (GetMessage(&msg, nullptr, 0, 0))
  47. {
  48. if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
  49. {
  50. TranslateMessage(&msg);
  51. DispatchMessage(&msg);
  52. }
  53. }
  54.  
  55. return (int) msg.wParam;
  56. }
  57.  
  58.  
  59.  
  60. //
  61. // FUNCTION: MyRegisterClass()
  62. //
  63. // PURPOSE: Registers the window class.
  64. //
  65. ATOM MyRegisterClass(HINSTANCE hInstance)
  66. {
  67. WNDCLASSEXW wcex;
  68.  
  69. wcex.cbSize = sizeof(WNDCLASSEX);
  70.  
  71. wcex.style = CS_HREDRAW | CS_VREDRAW;
  72. wcex.lpfnWndProc = WndProc;
  73. wcex.cbClsExtra = 0;
  74. wcex.cbWndExtra = 0;
  75. wcex.hInstance = hInstance;
  76. wcex.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_WIN32PROJECT3));
  77. wcex.hCursor = LoadCursor(nullptr, IDC_ARROW);
  78. wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
  79. wcex.lpszMenuName = MAKEINTRESOURCEW(IDC_WIN32PROJECT3);
  80. wcex.lpszClassName = szWindowClass;
  81. wcex.hIconSm = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_SMALL));
  82.  
  83. return RegisterClassExW(&wcex);
  84. }
  85.  
  86. //
  87. // FUNCTION: InitInstance(HINSTANCE, int)
  88. //
  89. // PURPOSE: Saves instance handle and creates main window
  90. //
  91. // COMMENTS:
  92. //
  93. // In this function, we save the instance handle in a global variable and
  94. // create and display the main program window.
  95. //
  96. BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
  97. {
  98. hInst = hInstance; // Store instance handle in our global variable
  99.  
  100. HWND hWnd = CreateWindowW(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
  101. CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, nullptr, nullptr, hInstance, nullptr);
  102.  
  103. if (!hWnd)
  104. {
  105. return FALSE;
  106. }
  107.  
  108. ShowWindow(hWnd, nCmdShow);
  109. UpdateWindow(hWnd);
  110.  
  111. return TRUE;
  112. }
  113.  
  114. //
  115. // FUNCTION: WndProc(HWND, UINT, WPARAM, LPARAM)
  116. //
  117. // PURPOSE: Processes messages for the main window.
  118. //
  119. // WM_COMMAND - process the application menu
  120. // WM_PAINT - Paint the main window
  121. // WM_DESTROY - post a quit message and return
  122. //
  123. //
  124. HWND hEdit;
  125. LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
  126. {
  127. OPENFILENAME ofn;
  128. STARTUPINFO si;
  129. PROCESS_INFORMATION pi;
  130. char FileName[200];
  131. bool err;
  132. char seconds[20];
  133.  
  134. //hEdit = CreateWindow(L"EDIT", 0, WS_BORDER | WS_CHILD | WS_VISIBLE, 56, 10, 50, 18, hWnd, (HMENU)15, hInst, 0);
  135. switch (message)
  136. {
  137. case WM_CREATE:
  138. hEdit = CreateWindow(L"EDIT", 0, WS_BORDER | WS_CHILD | WS_VISIBLE, 56, 10, 50, 18, hWnd, 0, hInst, 0);
  139. break;
  140. case WM_COMMAND:
  141. {
  142. int wmId = LOWORD(wParam);
  143. // Parse the menu selections:
  144. switch (wmId)
  145. {
  146. case IDM_RUN_RUN:
  147. ZeroMemory(&ofn, sizeof(ofn));
  148. ofn.lStructSize = sizeof(ofn);
  149. ofn.lpstrFile = (LPWSTR)FileName;
  150. ofn.nMaxFile = 255;
  151.  
  152. if (GetOpenFileName(&ofn)) {
  153. //MessageBox(hWnd, L"text", L"text", MB_OK);
  154. ZeroMemory(&si, sizeof(si));
  155. si.cb = sizeof(si);
  156. err = CreateProcess((LPWSTR)FileName, NULL, NULL, NULL, true, 0, NULL, NULL, &si, &pi);
  157. if (err = false) {
  158. MessageBox(hWnd, L"it does not work", L"info", MB_OK);
  159. }
  160.  
  161. //hEdit = CreateWindow(L"EDIT", 0, WS_BORDER | WS_CHILD | WS_VISIBLE, 56, 10, 50, 18, hWnd, (HMENU)15, hInst, 0);
  162. //GetWindowText(hEdit,(LPWSTR)seconds, 0);
  163. Sleep(5000);
  164. TerminateProcess(pi.hProcess, 0);
  165. }
  166.  
  167. break;
  168. case IDM_ABOUT:
  169. DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About);
  170. break;
  171. break;
  172. case IDM_EXIT:
  173. DestroyWindow(hWnd);
  174. break;
  175. default:
  176. return DefWindowProc(hWnd, message, wParam, lParam);
  177. }
  178. }
  179. break;
  180. case WM_PAINT:
  181. {
  182. PAINTSTRUCT ps;
  183. HDC hdc = BeginPaint(hWnd, &ps);
  184. // TODO: Add any drawing code that uses hdc here...
  185.  
  186. EndPaint(hWnd, &ps);
  187. }
  188. break;
  189. case WM_DESTROY:
  190. PostQuitMessage(0);
  191. break;
  192. default:
  193. return DefWindowProc(hWnd, message, wParam, lParam);
  194. }
  195. return 0;
  196. }
  197.  
  198. // Message handler for about box.
  199. INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
  200. {
  201. UNREFERENCED_PARAMETER(lParam);
  202. switch (message)
  203. {
  204. case WM_INITDIALOG:
  205. return (INT_PTR)TRUE;
  206.  
  207. case WM_COMMAND:
  208. if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
  209. {
  210. EndDialog(hDlg, LOWORD(wParam));
  211. return (INT_PTR)TRUE;
  212. }
  213. break;
  214. }
  215. return (INT_PTR)FALSE;
  216. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement