Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

618 lines
20 KiB

  1. #define UNICODE
  2. #include <windows.h> /* required for all Windows applications */
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include "test.h" /* specific to this program */
  6. HANDLE hInst; /* current instance */
  7. HMODULE hMod=NULL;
  8. TCHAR szInfoBuf[1024];
  9. TCHAR szBuffer[256];
  10. TCHAR szFileName[MAX_PATH];
  11. WORD languageid;
  12. /****************************************************************************
  13. FUNCTION: WinMain(HANDLE, HANDLE, LPSTR, int)
  14. PURPOSE: calls initialization function, processes message loop
  15. COMMENTS:
  16. Windows recognizes this function by name as the initial entry point
  17. for the program. This function calls the application initialization
  18. routine, if no other instance of the program is running, and always
  19. calls the instance initialization routine. It then executes a message
  20. retrieval and dispatch loop that is the top-level control structure
  21. for the remainder of execution. The loop is terminated when a WM_QUIT
  22. message is received, at which time this function exits the application
  23. instance by returning the value passed by PostQuitMessage().
  24. If this function must abort before entering the message loop, it
  25. returns the conventional value NULL.
  26. ****************************************************************************/
  27. int WINAPI WinMain(
  28. HINSTANCE hInstance,
  29. HINSTANCE hPrevInstance,
  30. LPSTR lpCmdLine,
  31. int nCmdShow
  32. )
  33. {
  34. MSG msg; /* message */
  35. UNREFERENCED_PARAMETER( lpCmdLine );
  36. if (!hPrevInstance) /* Other instances of app running? */
  37. if (!InitApplication(hInstance)) /* Initialize shared things */
  38. return (FALSE); /* Exits if unable to initialize */
  39. /* Perform initializations that apply to a specific instance */
  40. if (!InitInstance(hInstance, nCmdShow))
  41. return (FALSE);
  42. /* Acquire and dispatch messages until a WM_QUIT message is received. */
  43. while (GetMessage(&msg, /* message structure */
  44. NULL, /* handle of window receiving the message */
  45. 0, /* lowest message to examine */
  46. 0)) /* highest message to examine */
  47. {
  48. TranslateMessage(&msg); /* Translates virtual key codes */
  49. DispatchMessage(&msg); /* Dispatches message to window */
  50. }
  51. return (int)(msg.wParam); /* Returns the value from PostQuitMessage */
  52. }
  53. /****************************************************************************
  54. FUNCTION: InitApplication(HANDLE)
  55. PURPOSE: Initializes window data and registers window class
  56. COMMENTS:
  57. This function is called at initialization time only if no other
  58. instances of the application are running. This function performs
  59. initialization tasks that can be done once for any number of running
  60. instances.
  61. In this case, we initialize a window class by filling out a data
  62. structure of type WNDCLASS and calling the Windows RegisterClass()
  63. function. Since all instances of this application use the same window
  64. class, we only need to do this when the first instance is initialized.
  65. ****************************************************************************/
  66. BOOL InitApplication(HANDLE hInstance) /* current instance */
  67. {
  68. WNDCLASS wc;
  69. /* Fill in window class structure with parameters that describe the */
  70. /* main window. */
  71. wc.style = 0; /* Class style(s). */
  72. wc.lpfnWndProc = MainWndProc; /* Function to retrieve messages for */
  73. /* windows of this class. */
  74. wc.cbClsExtra = 0; /* No per-class extra data. */
  75. wc.cbWndExtra = 0; /* No per-window extra data. */
  76. wc.hInstance = hInstance; /* Application that owns the class. */
  77. wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
  78. wc.hCursor = LoadCursor(NULL, IDC_ARROW);
  79. wc.hbrBackground = GetStockObject(WHITE_BRUSH);
  80. wc.lpszMenuName = MAKEINTRESOURCE(IDM_VERSION);
  81. wc.lpszClassName = TEXT("VerTestWClass"); /* Name used in call to CreateWindow. */
  82. /* Register the window class and return success/failure code. */
  83. return (RegisterClass(&wc));
  84. }
  85. /****************************************************************************
  86. FUNCTION: InitInstance(HANDLE, int)
  87. PURPOSE: Saves instance handle and creates main window
  88. COMMENTS:
  89. This function is called at initialization time for every instance of
  90. this application. This function performs initialization tasks that
  91. cannot be shared by multiple instances.
  92. In this case, we save the instance handle in a static variable and
  93. create and display the main program window.
  94. ****************************************************************************/
  95. BOOL InitInstance(
  96. HANDLE hInstance, /* Current instance identifier. */
  97. int nCmdShow) /* Param for first ShowWindow() call. */
  98. {
  99. HWND hWnd; /* Main window handle. */
  100. /* Save the instance handle in static variable, which will be used in */
  101. /* many subsequence calls from this application to Windows. */
  102. hInst = hInstance;
  103. /* Create a main window for this application instance. */
  104. hWnd = CreateWindow(
  105. TEXT("VerTestWClass"), /* See RegisterClass() call. */
  106. TEXT("Version Test"), /* Text for window title bar. */
  107. WS_OVERLAPPEDWINDOW, /* Window style. */
  108. CW_USEDEFAULT, /* Default horizontal position. */
  109. CW_USEDEFAULT, /* Default vertical position. */
  110. CW_USEDEFAULT, /* Default width. */
  111. CW_USEDEFAULT, /* Default height. */
  112. NULL, /* Overlapped windows have no parent. */
  113. NULL, /* Use the window class menu. */
  114. hInstance, /* This instance owns this window. */
  115. NULL /* Pointer not needed. */
  116. );
  117. /* If window could not be created, return "failure" */
  118. if (!hWnd)
  119. return (FALSE);
  120. /* Make the window visible; update its client area; and return "success" */
  121. ShowWindow(hWnd, nCmdShow); /* Show the window */
  122. UpdateWindow(hWnd); /* Sends WM_PAINT message */
  123. return (TRUE); /* Returns the value from PostQuitMessage */
  124. }
  125. /****************************************************************************
  126. FUNCTION: MainWndProc(HWND, UINT, WPARAM, LPARAM)
  127. PURPOSE: Processes messages
  128. MESSAGES:
  129. WM_COMMAND - application menu
  130. WM_DESTROY - destroy window
  131. COMMENTS:
  132. ****************************************************************************/
  133. LRESULT APIENTRY MainWndProc(
  134. HWND hWnd, /* window handle */
  135. UINT message, /* type of message */
  136. WPARAM wParam, /* additional information */
  137. LPARAM lParam) /* additional information */
  138. {
  139. TCHAR szLang[256];
  140. TCHAR szBuf[256];
  141. PVOID pData;
  142. INT cbData;
  143. INT dummy;
  144. VS_FIXEDFILEINFO *pvs;
  145. DWORD *pdw;
  146. WORD *pw;
  147. PAINTSTRUCT ps;
  148. switch (message) {
  149. case WM_COMMAND: /* message: command from application menu */
  150. switch (LOWORD(wParam)) {
  151. case IDM_ABOUT:
  152. DialogBox(hInst, /* current instance */
  153. MAKEINTRESOURCE(IDD_ABOUT), /* resource to use */
  154. hWnd, /* parent handle */
  155. About); /* About() instance address */
  156. break;
  157. case IDM_FREE:
  158. FreeLibrary(hMod);
  159. break;
  160. case IDM_EXIT:
  161. FreeLibrary(hMod);
  162. DestroyWindow(hWnd);
  163. break;
  164. case IDM_QUERY:
  165. DialogBox(hInst, /* current instance */
  166. MAKEINTRESOURCE(IDD_QUERY), /* resource to use */
  167. hWnd, /* parent handle */
  168. Query); /* About() instance address */
  169. if (VerQueryValue(szInfoBuf, szFileName, &pData, &cbData) == FALSE)
  170. MessageBox(hWnd, TEXT("Returned NULL"), TEXT("VerQueryValue"), MB_OK);
  171. else {
  172. if (lstrcmp(szFileName, TEXT("\\")) == 0) {
  173. pvs = (VS_FIXEDFILEINFO*)pData;
  174. wsprintf(szBuffer, TEXT("0x%lx 0x%lx 0x%lx 0x%lx 0x%lx 0x%lx 0x%lx 0x%lx 0x%lx 0x%lx 0x%lx 0x%lx 0x%lx "),
  175. pvs->dwSignature,
  176. pvs->dwStrucVersion,
  177. pvs->dwFileVersionMS,
  178. pvs->dwFileVersionLS,
  179. pvs->dwProductVersionMS,
  180. pvs->dwProductVersionLS,
  181. pvs->dwFileFlagsMask,
  182. pvs->dwFileFlags,
  183. pvs->dwFileOS,
  184. pvs->dwFileType,
  185. pvs->dwFileSubtype,
  186. pvs->dwFileDateMS,
  187. pvs->dwFileDateLS);
  188. MessageBox(hWnd, szBuffer, TEXT("VerQueryValue VS_FIXEDFILEINFO"), MB_OK);
  189. }
  190. else if (lstrcmpi(szFileName, TEXT("\\VarFileInfo\\Translation")) == 0) {
  191. pw = (WORD*)pData; /* assume 2 words */
  192. wsprintf(szBuffer, TEXT("0x%lx 0x%lx"), *pw, *(pw+1));
  193. MessageBox(hWnd, szBuffer, TEXT("VerQueryValue VS_FIXEDFILEINFO"), MB_OK);
  194. }
  195. else if (
  196. #ifndef UNICODE
  197. strnicmp
  198. #else
  199. _wcsnicmp
  200. #endif
  201. (szFileName, TEXT("\\StringFileInfo\\"), 16) == 0) {
  202. wsprintf(szBuffer, TEXT("%s:%ws"), szFileName, pData);
  203. MessageBox(hWnd, szBuffer, TEXT("VerQueryValue"), MB_OK);
  204. }
  205. else
  206. MessageBox(hWnd, TEXT("Other"), TEXT("VerQueryValue"), MB_OK);
  207. }
  208. break;
  209. case IDM_INFO:
  210. DialogBox(hInst, /* current instance */
  211. MAKEINTRESOURCE(IDD_INFO), /* resource to use */
  212. hWnd, /* parent handle */
  213. Information); /* About() instance address */
  214. if (GetFileVersionInfoSize(szFileName, NULL) == FALSE)
  215. MessageBox(hWnd, TEXT("Returned NULL"), TEXT("GetFileVersionInfoSize"), MB_OK);
  216. else {
  217. if (GetFileVersionInfo(szFileName, 0, 1024, szInfoBuf) == FALSE)
  218. MessageBox(hWnd, TEXT("Returned NULL"), TEXT("GetFileVersionInfo"), MB_OK);
  219. else {
  220. MessageBox(hWnd, TEXT("Returned OK"), TEXT("GetFileVersionInfo"), MB_OK);
  221. }
  222. }
  223. break;
  224. case IDM_FIND:
  225. DialogBox(hInst, /* current instance */
  226. MAKEINTRESOURCE(IDD_FIND), /* resource to use */
  227. hWnd, /* parent handle */
  228. Find); /* About() instance address */
  229. GetWindowsDirectory(szBuf, 256);
  230. dummy = 256;
  231. cbData = 1024;
  232. if (VerFindFile(0L, szFileName, szBuf, TEXT("c:\\tmp"), szLang, &dummy, szInfoBuf, &cbData) == FALSE)
  233. MessageBox(hWnd, TEXT("Returned NULL"), TEXT("VerFindFile"), MB_OK);
  234. else {
  235. wsprintf(szBuffer, TEXT("%s:%s"), szLang, szInfoBuf);
  236. MessageBox(hWnd, szBuffer, TEXT("VerFindFile"), MB_OK);
  237. }
  238. break;
  239. case IDM_INSTALL:
  240. DialogBox(hInst, /* current instance */
  241. MAKEINTRESOURCE(IDD_INSTALL), /* resource to use */
  242. hWnd, /* parent handle */
  243. Install); /* About() instance address */
  244. dummy = 256;
  245. cbData = VerInstallFile(VIFF_FORCEINSTALL|VIFF_DONTDELETEOLD,
  246. szFileName, szFileName, TEXT("."), szLang, szInfoBuf,
  247. szBuf, &dummy);
  248. if (cbData == 0)
  249. MessageBox(hWnd, TEXT("Returned NULL"), TEXT("VerInstallFile"), MB_OK);
  250. else {
  251. wsprintf(szBuffer, TEXT("0x%lx:%s"), cbData, szBuf);
  252. MessageBox(hWnd, szBuffer, TEXT("VerInstallFile"), MB_OK);
  253. }
  254. break;
  255. case IDM_LANG:
  256. DialogBox(hInst, /* current instance */
  257. MAKEINTRESOURCE(IDD_LANG), /* resource to use */
  258. hWnd, /* parent handle */
  259. Language); /* About() instance address */
  260. VerLanguageName(languageid, szLang, 256);
  261. MessageBox(hWnd, szLang, TEXT("Language ID is:"), MB_OK);
  262. break;
  263. default:
  264. return (DefWindowProc(hWnd, message, wParam, lParam));
  265. }
  266. case WM_PAINT:
  267. BeginPaint(hWnd, (LPPAINTSTRUCT)&ps);
  268. EndPaint(hWnd, (LPPAINTSTRUCT)&ps);
  269. break;
  270. case WM_DESTROY: /* message: window being destroyed */
  271. PostQuitMessage(0);
  272. break;
  273. default: /* Passes it on if unproccessed */
  274. return (DefWindowProc(hWnd, message, wParam, lParam));
  275. }
  276. return (0);
  277. }
  278. /****************************************************************************
  279. FUNCTION: About(HWND, unsigned, WPARAM, LPARAM)
  280. PURPOSE: Processes messages for "About" dialog box
  281. MESSAGES:
  282. WM_INITDIALOG - initialize dialog box
  283. WM_COMMAND - Input received
  284. COMMENTS:
  285. No initialization is needed for this particular dialog box, but TRUE
  286. must be returned to Windows.
  287. Wait for user to click on "Ok" button, then close the dialog box.
  288. ****************************************************************************/
  289. INT_PTR APIENTRY About(
  290. HWND hDlg, /* window handle of the dialog box */
  291. UINT message, /* type of message */
  292. WPARAM wParam, /* message-specific information */
  293. LPARAM lParam)
  294. {
  295. switch (message) {
  296. case WM_INITDIALOG: /* message: initialize dialog box */
  297. return (TRUE);
  298. case WM_COMMAND: /* message: received a command */
  299. if (LOWORD(wParam) == IDOK) /* "OK" box selected? */
  300. EndDialog(hDlg, TRUE); /* Exits the dialog box */
  301. else if (LOWORD(wParam) == IDCANCEL) /* close command? */
  302. EndDialog(hDlg, FALSE); /* Exits the dialog box */
  303. return (TRUE);
  304. }
  305. return (FALSE); /* Didn't process a message */
  306. UNREFERENCED_PARAMETER(lParam);
  307. }
  308. /****************************************************************************
  309. FUNCTION: Find(HWND, unsigned, WPARAM, LPARAM)
  310. PURPOSE: Processes messages for "Find" dialog box
  311. MESSAGES:
  312. WM_INITDIALOG - initialize dialog box
  313. WM_COMMAND - Input received
  314. COMMENTS:
  315. No initialization is needed for this particular dialog box, but TRUE
  316. must be returned to Windows.
  317. Wait for user to click on "Ok" button, then close the dialog box.
  318. ****************************************************************************/
  319. INT_PTR APIENTRY Find(
  320. HWND hDlg, /* window handle of the dialog box */
  321. UINT message, /* type of message */
  322. WPARAM wParam, /* message-specific information */
  323. LPARAM lParam)
  324. {
  325. switch (message) {
  326. case WM_INITDIALOG: /* message: initialize dialog box */
  327. return (TRUE);
  328. case WM_COMMAND: /* message: received a command */
  329. if (LOWORD(wParam) == IDOK) { /* "OK" box selected? */
  330. GetDlgItemText(hDlg, IDC_FILENAME, szFileName, MAX_PATH);
  331. EndDialog(hDlg, TRUE); /* Exits the dialog box */
  332. }
  333. else if (LOWORD(wParam) == IDCANCEL) /* close command? */
  334. EndDialog(hDlg, FALSE); /* Exits the dialog box */
  335. return (TRUE);
  336. break;
  337. }
  338. return (FALSE); /* Didn't process a message */
  339. UNREFERENCED_PARAMETER(lParam);
  340. }
  341. /****************************************************************************
  342. FUNCTION: Install(HWND, unsigned, WPARAM, LPARAM)
  343. PURPOSE: Processes messages for "Install" dialog box
  344. MESSAGES:
  345. WM_INITDIALOG - initialize dialog box
  346. WM_COMMAND - Input received
  347. COMMENTS:
  348. No initialization is needed for this particular dialog box, but TRUE
  349. must be returned to Windows.
  350. Wait for user to click on "Ok" button, then close the dialog box.
  351. ****************************************************************************/
  352. INT_PTR APIENTRY Install(
  353. HWND hDlg, /* window handle of the dialog box */
  354. UINT message, /* type of message */
  355. WPARAM wParam, /* message-specific information */
  356. LPARAM lParam)
  357. {
  358. switch (message) {
  359. case WM_INITDIALOG: /* message: initialize dialog box */
  360. return (TRUE);
  361. case WM_COMMAND: /* message: received a command */
  362. if (LOWORD(wParam) == IDOK) { /* "OK" box selected? */
  363. GetDlgItemText(hDlg, IDC_FILENAME, szFileName, MAX_PATH);
  364. EndDialog(hDlg, TRUE); /* Exits the dialog box */
  365. }
  366. else if (LOWORD(wParam) == IDCANCEL) /* close command? */
  367. EndDialog(hDlg, FALSE); /* Exits the dialog box */
  368. return (TRUE);
  369. break;
  370. }
  371. return (FALSE); /* Didn't process a message */
  372. UNREFERENCED_PARAMETER(lParam);
  373. }
  374. /****************************************************************************
  375. FUNCTION: Query(HWND, unsigned, WPARAM, LPARAM)
  376. PURPOSE: Processes messages for "Query" dialog box
  377. MESSAGES:
  378. WM_INITDIALOG - initialize dialog box
  379. WM_COMMAND - Input received
  380. COMMENTS:
  381. No initialization is needed for this particular dialog box, but TRUE
  382. must be returned to Windows.
  383. Wait for user to click on "Ok" button, then close the dialog box.
  384. ****************************************************************************/
  385. INT_PTR APIENTRY Query(
  386. HWND hDlg, /* window handle of the dialog box */
  387. UINT message, /* type of message */
  388. WPARAM wParam, /* message-specific information */
  389. LPARAM lParam)
  390. {
  391. switch (message) {
  392. case WM_INITDIALOG: /* message: initialize dialog box */
  393. return (TRUE);
  394. case WM_COMMAND: /* message: received a command */
  395. if (LOWORD(wParam) == IDOK) { /* "OK" box selected? */
  396. GetDlgItemText(hDlg, IDC_FILENAME, szFileName, MAX_PATH);
  397. EndDialog(hDlg, TRUE); /* Exits the dialog box */
  398. }
  399. else if (LOWORD(wParam) == IDCANCEL) /* close command? */
  400. EndDialog(hDlg, FALSE); /* Exits the dialog box */
  401. return (TRUE);
  402. break;
  403. }
  404. return (FALSE); /* Didn't process a message */
  405. UNREFERENCED_PARAMETER(lParam);
  406. }
  407. /****************************************************************************
  408. FUNCTION: Language(HWND, unsigned, WPARAM, LPARAM)
  409. PURPOSE: Processes messages for "Language" dialog box
  410. MESSAGES:
  411. WM_INITDIALOG - initialize dialog box
  412. WM_COMMAND - Input received
  413. COMMENTS:
  414. No initialization is needed for this particular dialog box, but TRUE
  415. must be returned to Windows.
  416. Wait for user to click on "Ok" button, then close the dialog box.
  417. ****************************************************************************/
  418. INT_PTR APIENTRY Language(
  419. HWND hDlg, /* window handle of the dialog box */
  420. UINT message, /* type of message */
  421. WPARAM wParam, /* message-specific information */
  422. LPARAM lParam)
  423. {
  424. UINT lang;
  425. UINT sublang;
  426. switch (message) {
  427. case WM_INITDIALOG: /* message: initialize dialog box */
  428. return (TRUE);
  429. case WM_COMMAND: /* message: received a command */
  430. if (LOWORD(wParam) == IDOK) { /* "OK" box selected? */
  431. lang = GetDlgItemInt(hDlg, IDC_LANGID, NULL, FALSE);
  432. sublang = GetDlgItemInt(hDlg, IDC_SUBLANGID, NULL, FALSE);
  433. languageid = MAKELANGID(lang, sublang);
  434. EndDialog(hDlg, TRUE); /* Exits the dialog box */
  435. }
  436. else if (LOWORD(wParam) == IDCANCEL) /* close command? */
  437. EndDialog(hDlg, FALSE); /* Exits the dialog box */
  438. return (TRUE);
  439. break;
  440. }
  441. return (FALSE); /* Didn't process a message */
  442. UNREFERENCED_PARAMETER(lParam);
  443. }
  444. /****************************************************************************
  445. FUNCTION: Information(HWND, unsigned, WPARAM, LPARAM)
  446. PURPOSE: Processes messages for "Information" dialog box
  447. MESSAGES:
  448. WM_INITDIALOG - initialize dialog box
  449. WM_COMMAND - Input received
  450. COMMENTS:
  451. No initialization is needed for this particular dialog box, but TRUE
  452. must be returned to Windows.
  453. Wait for user to click on "Ok" button, then close the dialog box.
  454. ****************************************************************************/
  455. INT_PTR APIENTRY Information(
  456. HWND hDlg, /* window handle of the dialog box */
  457. UINT message, /* type of message */
  458. WPARAM wParam, /* message-specific information */
  459. LPARAM lParam)
  460. {
  461. switch (message) {
  462. case WM_INITDIALOG: /* message: initialize dialog box */
  463. return (TRUE);
  464. case WM_COMMAND: /* message: received a command */
  465. if (LOWORD(wParam) == IDOK) { /* "OK" box selected? */
  466. GetDlgItemText(hDlg, IDC_FILENAME, szFileName, MAX_PATH);
  467. EndDialog(hDlg, TRUE); /* Exits the dialog box */
  468. }
  469. else if (LOWORD(wParam) == IDCANCEL) /* close command? */
  470. EndDialog(hDlg, FALSE); /* Exits the dialog box */
  471. return (TRUE);
  472. break;
  473. }
  474. return (FALSE); /* Didn't process a message */
  475. UNREFERENCED_PARAMETER(lParam);
  476. }