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.

3042 lines
75 KiB

  1. /***************************************************************************
  2. * Quick fix application tools
  3. *
  4. * Author: clupu (Feb 16, 2000)
  5. *
  6. * History:
  7. *
  8. * rparsons - 11/10/2000 - Modified titles on common dialogs
  9. *
  10. * rparsons - 11/23/2000 - Added ability to save XML to file
  11. *
  12. * rparsons - 11/25/2000 - Modified to allow matching file on a
  13. * different drive to be selected
  14. *
  15. * rparsons - 05/19/2001 - Added context menu on file tree.
  16. * Added URL for WU package.
  17. * Added Remove Matching button.
  18. * Converted shim list to list view.
  19. *
  20. * rparsons - 07/06/2001 - Converted static tab control to use
  21. * child dialogs.
  22. *
  23. \**************************************************************************/
  24. #include "afxwin.h"
  25. #include "commctrl.h"
  26. #include "commdlg.h"
  27. #include "shlwapi.h"
  28. #include "shellapi.h"
  29. #include "shlobj.h"
  30. #include "shlobjp.h" // needed for Link Window support
  31. #include "uxtheme.h" // needed for tab control theme support
  32. #include "resource.h"
  33. #include <tchar.h>
  34. #include <aclapi.h>
  35. #include "QFixApp.h"
  36. #include "dbSupport.h"
  37. extern "C" {
  38. #include "shimdb.h"
  39. }
  40. CWinApp theApp;
  41. /*
  42. * Global Variables
  43. */
  44. HINSTANCE g_hInstance;
  45. HWND g_hDlg;
  46. HWND g_hLayersDlg;
  47. HWND g_hFixesDlg;
  48. HWND g_hwndTab;
  49. HWND g_hwndListLayers;
  50. TCHAR g_szAppTitle[64];
  51. TCHAR g_szBinary[MAX_PATH]; // the full path of the main binary being shimmed
  52. TCHAR g_szShortName[128]; // the short name of the main EXE
  53. TCHAR g_szParentExeName[MAX_PATH]; // the short name of the parent EXE
  54. TCHAR g_szParentExeFullPath[MAX_PATH]; // the full path of the parent EXE
  55. TCHAR g_szSDBToDelete[MAX_PATH]; // the SDB file to delete from a previous 'Run'
  56. int g_nCrtTab;
  57. HWND g_hwndShimList; // the handle to the list view control
  58. // containing all the shims available
  59. HWND g_hwndFilesTree; // the handle to the tree view control
  60. // containing the matching files selected
  61. HWND g_hwndModuleList; // the handle to the list view control
  62. // containing module information
  63. BOOL g_bSimpleEdition; // simple or dev edition
  64. BOOL g_fW2K; // Win2K or XP
  65. RECT g_rcDlgBig, g_rcDlgSmall; // rectangle of the simple and the dev edition
  66. // of the dialog
  67. BOOL g_bAllShims;
  68. BOOL g_bSelectedParentExe; // flag to indicate if a parent EXE has been
  69. // selected
  70. PFIX g_pFixHead;
  71. TCHAR g_szXPUrl[] = _T("hcp://services/subsite?node=TopLevelBucket_4/")
  72. _T("Fixing_a_problem&topic=MS-ITS%3A%25HELP_LOCATION")
  73. _T("%25%5Cmisc.chm%3A%3A/compatibility_tab_and_wizard.htm")
  74. _T("&select=TopLevelBucket_4/Fixing_a_problem/")
  75. _T("Application_and_software_problems");
  76. TCHAR g_szW2KUrl[] = _T("http://www.microsoft.com/windows2000/")
  77. _T("downloads/tools/appcompat/");
  78. #define ID_COUNT_SHIMS 1234
  79. typedef HRESULT (*PFNEnableThemeDialogTexture)(HWND hwnd, DWORD dwFlags);
  80. #if DBG
  81. void
  82. LogMsgDbg(
  83. LPTSTR pszFmt,
  84. ...
  85. )
  86. /*++
  87. LogMsgDbg
  88. Description: DbgPrint.
  89. --*/
  90. {
  91. TCHAR gszT[1024];
  92. va_list arglist;
  93. va_start(arglist, pszFmt);
  94. _vsntprintf(gszT, 1023, pszFmt, arglist);
  95. gszT[1023] = 0;
  96. va_end(arglist);
  97. OutputDebugString(gszT);
  98. }
  99. #endif // DBG
  100. BOOL
  101. IsUserAnAdministrator(
  102. void
  103. )
  104. /*++
  105. IsUserAnAdministrator
  106. Description: Determine if the currently logged on user is an admin.
  107. --*/
  108. {
  109. HANDLE hToken;
  110. DWORD dwStatus = 0, dwAccessMask = 0;
  111. DWORD dwAccessDesired = 0, dwACLSize = 0;
  112. DWORD dwStructureSize = sizeof(PRIVILEGE_SET);
  113. PACL pACL = NULL;
  114. PSID psidAdmin = NULL;
  115. BOOL fReturn = FALSE;
  116. PRIVILEGE_SET ps;
  117. GENERIC_MAPPING GenericMapping;
  118. PSECURITY_DESCRIPTOR psdAdmin = NULL;
  119. SID_IDENTIFIER_AUTHORITY SystemSidAuthority = SECURITY_NT_AUTHORITY;
  120. // AccessCheck() requires an impersonation token
  121. if (!ImpersonateSelf(SecurityImpersonation)) {
  122. goto cleanup;
  123. }
  124. // Attempt to access the token for the current thread
  125. if (!OpenThreadToken(GetCurrentThread(),
  126. TOKEN_QUERY,
  127. FALSE,
  128. &hToken)) {
  129. if (GetLastError() != ERROR_NO_TOKEN) {
  130. goto cleanup;
  131. }
  132. // If the thread does not have an access token, we'll
  133. // examine the access token associated with the process.
  134. if (!OpenProcessToken(GetCurrentProcess(),
  135. TOKEN_QUERY,
  136. &hToken)) {
  137. goto cleanup;
  138. }
  139. }
  140. // Build a SID for administrators group
  141. if (!AllocateAndInitializeSid(&SystemSidAuthority,
  142. 2,
  143. SECURITY_BUILTIN_DOMAIN_RID,
  144. DOMAIN_ALIAS_RID_ADMINS,
  145. 0, 0, 0, 0, 0, 0,
  146. &psidAdmin)) {
  147. goto cleanup;
  148. }
  149. // Allocate memory for the security descriptor
  150. psdAdmin = HeapAlloc(GetProcessHeap(),
  151. HEAP_ZERO_MEMORY,
  152. SECURITY_DESCRIPTOR_MIN_LENGTH);
  153. if (psdAdmin == NULL) {
  154. goto cleanup;
  155. }
  156. // Initialize the new security descriptor
  157. if (!InitializeSecurityDescriptor(psdAdmin,
  158. SECURITY_DESCRIPTOR_REVISION)) {
  159. goto cleanup;
  160. }
  161. // Compute size needed for the ACL
  162. dwACLSize = sizeof(ACL) + sizeof(ACCESS_ALLOWED_ACE) +
  163. GetLengthSid(psidAdmin) - sizeof(DWORD);
  164. // Allocate memory for ACL
  165. pACL = (PACL) HeapAlloc(GetProcessHeap(),
  166. HEAP_ZERO_MEMORY,
  167. dwACLSize);
  168. if (pACL == NULL) {
  169. goto cleanup;
  170. }
  171. // Initialize the new ACL
  172. if (!InitializeAcl(pACL,
  173. dwACLSize,
  174. ACL_REVISION2)) {
  175. goto cleanup;
  176. }
  177. dwAccessMask = ACCESS_READ | ACCESS_WRITE;
  178. // Add the access-allowed ACE to the DACL
  179. if (!AddAccessAllowedAce(pACL,
  180. ACL_REVISION2,
  181. dwAccessMask,
  182. psidAdmin)) {
  183. goto cleanup;
  184. }
  185. // Set our DACL to the security descriptor
  186. if (!SetSecurityDescriptorDacl(psdAdmin,
  187. TRUE,
  188. pACL,
  189. FALSE)) {
  190. goto cleanup;
  191. }
  192. // AccessCheck is sensitive about the format of the
  193. // security descriptor; set the group & owner
  194. SetSecurityDescriptorGroup(psdAdmin, psidAdmin, FALSE);
  195. SetSecurityDescriptorOwner(psdAdmin, psidAdmin, FALSE);
  196. // Ensure that the SD is valid
  197. if (!IsValidSecurityDescriptor(psdAdmin)) {
  198. goto cleanup;
  199. }
  200. dwAccessDesired = ACCESS_READ;
  201. // Initialize GenericMapping structure even though we
  202. // won't be using generic rights.
  203. GenericMapping.GenericRead = ACCESS_READ;
  204. GenericMapping.GenericWrite = ACCESS_WRITE;
  205. GenericMapping.GenericExecute = 0;
  206. GenericMapping.GenericAll = ACCESS_READ | ACCESS_WRITE;
  207. // After all that work, it boils down to this call
  208. if (!AccessCheck(psdAdmin,
  209. hToken,
  210. dwAccessDesired,
  211. &GenericMapping,
  212. &ps,
  213. &dwStructureSize,
  214. &dwStatus,
  215. &fReturn)) {
  216. goto cleanup;
  217. }
  218. RevertToSelf();
  219. cleanup:
  220. if (pACL) {
  221. HeapFree(GetProcessHeap(), 0, pACL);
  222. }
  223. if (psdAdmin){
  224. HeapFree(GetProcessHeap(), 0, psdAdmin);
  225. }
  226. if (psidAdmin){
  227. FreeSid(psidAdmin);
  228. }
  229. return (fReturn);
  230. }
  231. BOOL
  232. CheckForSDB(
  233. void
  234. )
  235. /*++
  236. CheckForSDB
  237. Description: Attempts to locate sysmain.sdb in the apppatch directory.
  238. --*/
  239. {
  240. HANDLE hFile;
  241. TCHAR szSDBPath[MAX_PATH];
  242. BOOL fResult = FALSE;
  243. if (!GetSystemWindowsDirectory(szSDBPath, MAX_PATH)) {
  244. return FALSE;
  245. }
  246. _tcscat(szSDBPath, _T("\\apppatch\\sysmain.sdb"));
  247. hFile = CreateFile(szSDBPath,
  248. GENERIC_READ,
  249. FILE_SHARE_READ | FILE_SHARE_WRITE,
  250. NULL,
  251. OPEN_EXISTING,
  252. FILE_ATTRIBUTE_NORMAL,
  253. NULL);
  254. if (INVALID_HANDLE_VALUE != hFile) {
  255. CloseHandle(hFile);
  256. fResult = TRUE;
  257. }
  258. return (fResult);
  259. }
  260. void
  261. AddModuleToListView(
  262. TCHAR* pModuleName,
  263. UINT uOption
  264. )
  265. /*++
  266. AddModuleToListView
  267. Description: Adds the specified module to the list view.
  268. --*/
  269. {
  270. LVITEM lvi;
  271. int nIndex;
  272. TCHAR szInclude[MAX_PATH];
  273. TCHAR szExclude[MAX_PATH];
  274. LoadString(g_hInstance, IDS_INCLUDE_HDR, szInclude, MAX_PATH);
  275. LoadString(g_hInstance, IDS_EXCLUDE_HDR, szExclude, MAX_PATH);
  276. lvi.mask = LVIF_TEXT | LVIF_PARAM;
  277. lvi.lParam = uOption == BST_CHECKED ? 1 : 0;
  278. lvi.pszText = uOption == BST_CHECKED ? szInclude : szExclude;
  279. lvi.iItem = ListView_GetItemCount(g_hwndModuleList);
  280. lvi.iSubItem = 0;
  281. nIndex = ListView_InsertItem(g_hwndModuleList, &lvi);
  282. ListView_SetItemText(g_hwndModuleList,
  283. nIndex,
  284. 1,
  285. pModuleName);
  286. }
  287. void
  288. BuildModuleListForShim(
  289. PFIX pFix,
  290. DWORD dwFlags
  291. )
  292. /*++
  293. BuildModuleListForShim
  294. Description: Based on the flag, adds modules to the list view for
  295. the specified shim or retrieves them and adds them
  296. to the linked list.
  297. --*/
  298. {
  299. PMODULE pModule, pModuleTmp, pModuleNew;
  300. int nItemCount = 0, nIndex;
  301. LVITEM lvi;
  302. TCHAR szBuffer[MAX_PATH];
  303. if (dwFlags & BML_ADDTOLISTVIEW) {
  304. //
  305. // Walk the linked list and add the modules to the list view.
  306. //
  307. pModule = pFix->pModule;
  308. while (pModule) {
  309. AddModuleToListView(pModule->pszName,
  310. pModule->fInclude ? BST_CHECKED : 0);
  311. pModule = pModule->pNext;
  312. }
  313. }
  314. if (dwFlags & BML_DELFRLISTVIEW) {
  315. pModule = pFix->pModule;
  316. while (NULL != pModule) {
  317. pModuleTmp = pModule->pNext;
  318. HeapFree(GetProcessHeap(), 0, pModule->pszName);
  319. HeapFree(GetProcessHeap(), 0, pModule);
  320. pModule = pModuleTmp;
  321. }
  322. pFix->pModule = NULL;
  323. }
  324. if (dwFlags & BML_GETFRLISTVIEW) {
  325. pModule = pFix->pModule;
  326. while (NULL != pModule) {
  327. pModuleTmp = pModule->pNext;
  328. HeapFree(GetProcessHeap(), 0, pModule->pszName);
  329. HeapFree(GetProcessHeap(), 0, pModule);
  330. pModule = pModuleTmp;
  331. }
  332. pFix->pModule = NULL;
  333. //
  334. // Get each shim from the list view and add it to the list.
  335. //
  336. nItemCount = ListView_GetItemCount(g_hwndModuleList);
  337. if (nItemCount == 0) {
  338. return;
  339. }
  340. for (nIndex = nItemCount - 1; nIndex >= 0; nIndex--) {
  341. lvi.mask = LVIF_PARAM;
  342. lvi.iItem = nIndex;
  343. lvi.iSubItem = 0;
  344. ListView_GetItem(g_hwndModuleList, &lvi);
  345. ListView_GetItemText(g_hwndModuleList, nIndex, 1, szBuffer, MAX_PATH);
  346. pModuleNew = (PMODULE)HeapAlloc(GetProcessHeap(),
  347. HEAP_ZERO_MEMORY,
  348. sizeof(MODULE));
  349. pModuleNew->pszName = (TCHAR*)HeapAlloc(GetProcessHeap(),
  350. HEAP_ZERO_MEMORY,
  351. sizeof(TCHAR) * (lstrlen(szBuffer) + 1));
  352. if (pModuleNew == NULL || pModuleNew->pszName == NULL) {
  353. LogMsg(_T("[BuildModuleListForShim] Couldn't allocate memory to store module info."));
  354. return;
  355. }
  356. lstrcpy(pModuleNew->pszName, szBuffer);
  357. pModuleNew->fInclude = (BOOL)lvi.lParam;
  358. pModuleNew->pNext = pFix->pModule;
  359. pFix->pModule = pModuleNew;
  360. }
  361. }
  362. }
  363. int
  364. CountShims(
  365. BOOL fCountSelected
  366. )
  367. /*++
  368. CountShims
  369. Description: Counts the number of selected shims in the list and
  370. updates the text on the dialog.
  371. --*/
  372. {
  373. int cShims = 0, nTotalShims, nShims = 0;
  374. BOOL fReturn;
  375. TCHAR szShims[MAX_PATH];
  376. TCHAR szTemp[MAX_PATH];
  377. cShims = ListView_GetItemCount(g_hwndShimList);
  378. if (fCountSelected) {
  379. for (nTotalShims = 0; nTotalShims < cShims; nTotalShims++) {
  380. fReturn = ListView_GetCheckState(g_hwndShimList, nTotalShims);
  381. if (fReturn) {
  382. nShims++;
  383. }
  384. }
  385. }
  386. LoadString(g_hInstance, IDS_SEL_CAPTION, szTemp, MAX_PATH);
  387. wsprintf(szShims, szTemp, nShims, cShims);
  388. SetDlgItemText(g_hFixesDlg, IDC_SELECTED_SHIMS, szShims);
  389. return (cShims);
  390. }
  391. void
  392. DisplayAttrContextMenu(
  393. POINT* pt
  394. )
  395. /*++
  396. DisplayAttrContextMenu
  397. Description: Displays a popup menu for the attributes tree.
  398. --*/
  399. {
  400. HMENU hPopupMenu, hTrackPopup;
  401. //
  402. // Load the popup menu and display it.
  403. //
  404. hPopupMenu = LoadMenu(g_hInstance, MAKEINTRESOURCE(IDM_ATTR_POPUP));
  405. if (hPopupMenu == NULL) {
  406. return;
  407. }
  408. hTrackPopup = GetSubMenu(hPopupMenu, 0);
  409. TrackPopupMenu(hTrackPopup,
  410. TPM_LEFTBUTTON | TPM_NOANIMATION | TPM_LEFTALIGN,
  411. pt->x, pt->y, 0, g_hDlg, NULL);
  412. DestroyMenu(hPopupMenu);
  413. }
  414. void
  415. InsertListViewColumn(
  416. HWND hWndListView,
  417. LPTSTR lpColumnName,
  418. BOOL fCenter,
  419. int nColumnID,
  420. int nSize
  421. )
  422. /*++
  423. InsertListViewColumn
  424. Description: Wrapper for ListView_InsertColumn.
  425. --*/
  426. {
  427. LV_COLUMN lvColumn;
  428. if (fCenter) {
  429. lvColumn.mask = LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM | LVCF_FMT;
  430. } else {
  431. lvColumn.mask = LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM;
  432. }
  433. //
  434. // Fill in the structure and add the column.
  435. //
  436. lvColumn.fmt = LVCFMT_CENTER;
  437. lvColumn.cx = nSize;
  438. lvColumn.iSubItem = 0;
  439. lvColumn.pszText = lpColumnName;
  440. ListView_InsertColumn(hWndListView, nColumnID, &lvColumn);
  441. }
  442. void
  443. EnableTabBackground(
  444. HWND hDlg
  445. )
  446. {
  447. PFNEnableThemeDialogTexture pFnEnableThemeDialogTexture;
  448. HMODULE hUxTheme;
  449. hUxTheme = (HMODULE)LoadLibrary(_T("uxtheme.dll"));
  450. if (hUxTheme) {
  451. pFnEnableThemeDialogTexture = (PFNEnableThemeDialogTexture)
  452. GetProcAddress(hUxTheme, "EnableThemeDialogTexture");
  453. if (pFnEnableThemeDialogTexture) {
  454. pFnEnableThemeDialogTexture(hDlg, ETDT_USETABTEXTURE);
  455. }
  456. FreeLibrary(hUxTheme);
  457. }
  458. }
  459. void
  460. HandleLayersDialogInit(
  461. HWND hDlg
  462. )
  463. {
  464. HWND hParent;
  465. DLGHDR* pHdr;
  466. g_hLayersDlg = hDlg;
  467. hParent = GetParent(hDlg);
  468. pHdr = (DLGHDR*)GetWindowLongPtr(hParent, DWLP_USER);
  469. //
  470. // Position the dialog within the tab.
  471. //
  472. SetWindowPos(hDlg, HWND_TOP,
  473. pHdr->rcDisplay.left, pHdr->rcDisplay.top,
  474. pHdr->rcDisplay.right - pHdr->rcDisplay.left,
  475. pHdr->rcDisplay.bottom - pHdr->rcDisplay.top,
  476. 0);
  477. g_hwndListLayers = GetDlgItem(hDlg, IDC_LAYERS);
  478. EnableTabBackground(hDlg);
  479. }
  480. BOOL
  481. HandleFixesDialogInit(
  482. HWND hDlg
  483. )
  484. {
  485. HWND hParent;
  486. DLGHDR* pHdr;
  487. int nCount = 0;
  488. TCHAR szColumn[MAX_PATH];
  489. g_hFixesDlg = hDlg;
  490. hParent = GetParent(hDlg);
  491. pHdr = (DLGHDR*)GetWindowLongPtr(hParent, DWLP_USER);
  492. //
  493. // Position the dialog within the tab.
  494. //
  495. SetWindowPos(hDlg, HWND_TOP,
  496. pHdr->rcDisplay.left, pHdr->rcDisplay.top,
  497. pHdr->rcDisplay.right - pHdr->rcDisplay.left,
  498. pHdr->rcDisplay.bottom - pHdr->rcDisplay.top,
  499. 0);
  500. g_hwndShimList = GetDlgItem(hDlg, IDC_SHIMS);
  501. //
  502. // Set up the shim list.
  503. //
  504. LoadString(g_hInstance, IDS_FIXNAME_COLUMN, szColumn, MAX_PATH);
  505. InsertListViewColumn(g_hwndShimList, szColumn, FALSE, 0, 200);
  506. LoadString(g_hInstance, IDS_CMDLINE_COLUMN, szColumn, MAX_PATH);
  507. InsertListViewColumn(g_hwndShimList, szColumn, TRUE, 1, 59);
  508. LoadString(g_hInstance, IDS_MODULE_COLUMN, szColumn, MAX_PATH);
  509. InsertListViewColumn(g_hwndShimList, szColumn, TRUE, 2, 52);
  510. ListView_SetExtendedListViewStyle(g_hwndShimList,
  511. LVS_EX_CHECKBOXES | LVS_EX_FULLROWSELECT);
  512. //
  513. // Query the database and show the available general purpose fixes.
  514. //
  515. ShowAvailableFixes(g_hwndShimList);
  516. nCount = CountShims(FALSE);
  517. if (!nCount) {
  518. return FALSE;
  519. }
  520. ListView_SetItemCount(g_hwndShimList, nCount);
  521. EnableTabBackground(hDlg);
  522. return TRUE;
  523. }
  524. DLGTEMPLATE*
  525. LockDlgRes(
  526. LPCTSTR lpResName
  527. )
  528. {
  529. HRSRC hrsrc = FindResource(NULL, lpResName, RT_DIALOG);
  530. if (NULL == hrsrc) {
  531. return NULL;
  532. }
  533. HGLOBAL hglb = LoadResource(g_hInstance, hrsrc);
  534. if (NULL == hglb) {
  535. return NULL;
  536. }
  537. return (DLGTEMPLATE*)LockResource(hglb);
  538. }
  539. void
  540. InitTabs(
  541. HWND hMainDlg,
  542. HWND hTab
  543. )
  544. {
  545. DLGHDR* pHdr;
  546. TCITEM tcitem;
  547. RECT rcTab;
  548. int nCount;
  549. TCHAR szTabText[MAX_PATH];
  550. TCHAR szError[MAX_PATH];
  551. pHdr = (DLGHDR*)HeapAlloc(GetProcessHeap(),
  552. HEAP_ZERO_MEMORY,
  553. sizeof(DLGHDR));
  554. if (NULL == pHdr) {
  555. LoadString(g_hInstance, IDS_TAB_SETUP_FAIL, szError, MAX_PATH);
  556. MessageBox(hMainDlg, szError, g_szAppTitle, MB_OK | MB_ICONERROR);
  557. return;
  558. }
  559. //
  560. // Save away a pointer to the structure.
  561. //
  562. SetWindowLongPtr(hMainDlg, DWLP_USER, (LONG_PTR)pHdr);
  563. //
  564. // Save away the handle to the tab control.
  565. //
  566. pHdr->hTab = hTab;
  567. //
  568. // Add the tabs.
  569. //
  570. LoadString(g_hInstance, IDS_TAB_FIRST_TEXT, szTabText, MAX_PATH);
  571. tcitem.mask = TCIF_TEXT | TCIF_PARAM;
  572. tcitem.pszText = szTabText;
  573. tcitem.lParam = 0;
  574. TabCtrl_InsertItem(pHdr->hTab, 0, &tcitem);
  575. LoadString(g_hInstance, IDS_TAB_SECOND_TEXT, szTabText, MAX_PATH);
  576. tcitem.pszText = szTabText;
  577. tcitem.lParam = 1;
  578. TabCtrl_InsertItem(pHdr->hTab, 1, &tcitem);
  579. //
  580. // Lock the resources for two child dialog boxes.
  581. //
  582. pHdr->pRes[0] = LockDlgRes(MAKEINTRESOURCE(IDD_LAYERS_TAB));
  583. pHdr->pDlgProc[0] = LayersTabDlgProc;
  584. pHdr->pRes[1] = LockDlgRes(MAKEINTRESOURCE(IDD_FIXES_TAB));
  585. pHdr->pDlgProc[1] = FixesTabDlgProc;
  586. //
  587. // Determine the bounding rectangle for all child dialog boxes.
  588. //
  589. GetWindowRect(pHdr->hTab, &rcTab);
  590. TabCtrl_AdjustRect(pHdr->hTab, FALSE, &rcTab);
  591. InflateRect(&rcTab, 1, 1);
  592. rcTab.left -= 2;
  593. MapWindowPoints(NULL, hMainDlg, (LPPOINT)&rcTab, 2);
  594. pHdr->rcDisplay = rcTab;
  595. //
  596. // Create both dialog boxes.
  597. //
  598. for (nCount = 0; nCount < NUM_TABS; nCount++) {
  599. pHdr->hDisplay[nCount] = CreateDialogIndirect(g_hInstance,
  600. pHdr->pRes[nCount],
  601. hMainDlg,
  602. pHdr->pDlgProc[nCount]);
  603. }
  604. }
  605. TCHAR*
  606. GetRelativePath(
  607. TCHAR* pExeFile,
  608. TCHAR* pMatchFile
  609. )
  610. /*++
  611. GetRelativePath
  612. Description: Returns a relative path based on an EXE and a matching file.
  613. The caller must free the memory using free.
  614. --*/
  615. {
  616. int nLenExe = 0;
  617. int nLenMatch = 0;
  618. TCHAR* pExe = NULL;
  619. TCHAR* pMatch = NULL;
  620. TCHAR* pReturn = NULL;
  621. TCHAR result[MAX_PATH] = { _T('\0') };
  622. TCHAR* resultIdx = result;
  623. BOOL bCommonBegin = FALSE; // Indicates if the paths have a common beginning
  624. //
  625. // Ensure that the beginning of the path matches between the two files
  626. //
  627. pExe = _tcschr(pExeFile, _T('\\'));
  628. pMatch = _tcschr(pMatchFile, _T('\\'));
  629. while (pExe && pMatch) {
  630. nLenExe = (int)(pExe - pExeFile);
  631. nLenMatch = (int)(pMatch - pMatchFile);
  632. if (nLenExe != nLenMatch) {
  633. break;
  634. }
  635. if (!(_tcsnicmp(pExeFile, pMatchFile, nLenExe) == 0)) {
  636. break;
  637. }
  638. bCommonBegin = TRUE;
  639. pExeFile = pExe + 1;
  640. pMatchFile = pMatch + 1;
  641. pExe = _tcschr(pExeFile, _T('\\'));
  642. pMatch = _tcschr(pMatchFile, _T('\\'));
  643. }
  644. //
  645. // Walk the path and put '..\' where necessary
  646. //
  647. if (bCommonBegin) {
  648. while (pExe) {
  649. lstrcpy(resultIdx, _T("..\\"));
  650. resultIdx = resultIdx + 3;
  651. pExeFile = pExe + 1;
  652. pExe = _tcschr(pExeFile, _T('\\'));
  653. }
  654. lstrcpy(resultIdx, pMatchFile);
  655. pReturn = (TCHAR*)HeapAlloc(GetProcessHeap(),
  656. HEAP_ZERO_MEMORY,
  657. sizeof(TCHAR) * (lstrlen(result) + 1));
  658. if (NULL == pReturn) {
  659. return NULL;
  660. }
  661. lstrcpy(pReturn, result);
  662. return pReturn;
  663. }
  664. // the two paths don't have a common beginning,
  665. // and there is no relative path
  666. return NULL;
  667. }
  668. void
  669. SaveEntryToFile(
  670. HWND hDlg,
  671. HWND hEdit,
  672. LPCTSTR lpFileName
  673. )
  674. /*++
  675. SaveEntryToFile
  676. Description: Writes the XML out to a file.
  677. --*/
  678. {
  679. int nLen = 0;
  680. DWORD dwBytesWritten = 0;
  681. HANDLE hFile = NULL;
  682. LPTSTR lpData = NULL;
  683. TCHAR szError[MAX_PATH];
  684. //
  685. // Determine how much space we need for the buffer, then allocate it.
  686. //
  687. nLen = GetWindowTextLength(hEdit);
  688. if (nLen) {
  689. lpData = (LPTSTR)HeapAlloc(GetProcessHeap(),
  690. HEAP_ZERO_MEMORY,
  691. nLen * 2 * sizeof(TCHAR));
  692. if (lpData == NULL) {
  693. LoadString(g_hInstance, IDS_BUFFER_ALLOC_FAIL, szError, MAX_PATH);
  694. MessageBox(hDlg, szError, g_szAppTitle, MB_OK | MB_ICONERROR);
  695. return;
  696. }
  697. //
  698. // Get the text out of the text box and write it out to our file.
  699. //
  700. GetWindowText(hEdit, lpData, nLen * 2);
  701. hFile = CreateFile(lpFileName,
  702. GENERIC_WRITE,
  703. 0,
  704. NULL,
  705. CREATE_ALWAYS,
  706. FILE_ATTRIBUTE_NORMAL,
  707. NULL);
  708. if (hFile == INVALID_HANDLE_VALUE) {
  709. LoadString(g_hInstance, IDS_FILE_CREATE_FAIL, szError, MAX_PATH);
  710. MessageBox(hDlg, szError, g_szAppTitle, MB_OK | MB_ICONERROR);
  711. goto Cleanup;
  712. }
  713. WriteFile(hFile, lpData, nLen * 2, &dwBytesWritten, NULL);
  714. CloseHandle(hFile);
  715. }
  716. Cleanup:
  717. HeapFree(GetProcessHeap(), 0, lpData);
  718. }
  719. void
  720. DoFileSave(
  721. HWND hDlg
  722. )
  723. /*++
  724. DoFileSave
  725. Description: Displays the common dialog allowing for file save.
  726. --*/
  727. {
  728. int nAnswer;
  729. TCHAR szError[MAX_PATH];
  730. TCHAR szFilter[MAX_PATH] = _T("");
  731. TCHAR szTemp[MAX_PATH+1] = _T("");
  732. OPENFILENAME ofn = {0};
  733. szTemp[0] = 0;
  734. LoadString(g_hInstance, IDS_SAVE_FILTER, szFilter, MAX_PATH);
  735. ofn.lStructSize = sizeof(OPENFILENAME);
  736. ofn.hwndOwner = hDlg;
  737. ofn.hInstance = NULL;
  738. ofn.lpstrFilter = szFilter;
  739. ofn.lpstrCustomFilter = (LPTSTR)NULL;
  740. ofn.nMaxCustFilter = 0;
  741. ofn.nFilterIndex = 1;
  742. ofn.lpstrFile = szTemp;
  743. ofn.nMaxFile = sizeof(szTemp);
  744. ofn.lpstrTitle = NULL;
  745. ofn.lpstrFileTitle = NULL;
  746. ofn.nMaxFileTitle = 0;
  747. ofn.lpstrInitialDir = NULL;
  748. ofn.nFileOffset = 0;
  749. ofn.nFileExtension = 0;
  750. ofn.lpstrDefExt = _T("xml");
  751. ofn.lCustData = 0;
  752. ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST |
  753. OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT;
  754. if (GetSaveFileName(&ofn)) {
  755. SaveEntryToFile(hDlg, GetDlgItem(hDlg, IDC_XML), szTemp);
  756. }
  757. }
  758. void
  759. GetTopLevelWindowIntoView(
  760. HWND hwnd
  761. )
  762. {
  763. RECT rectWindow, rectScreen;
  764. int nCx, nCy, nCxScreen, nCyScreen;
  765. int dx = 0, dy = 0;
  766. HWND hwndDesktop;
  767. if (GetWindowLong(hwnd, GWL_STYLE) & WS_CHILD) {
  768. return;
  769. }
  770. hwndDesktop = GetDesktopWindow();
  771. GetWindowRect(hwnd, &rectWindow);
  772. GetWindowRect(hwndDesktop, &rectScreen);
  773. nCx = rectWindow.right - rectWindow.left;
  774. nCy = rectWindow.bottom - rectWindow.top;
  775. nCxScreen = rectScreen.right - rectScreen.left;
  776. nCyScreen = rectScreen.bottom - rectScreen.top;
  777. //
  778. // Make it fix on the x coord.
  779. //
  780. if (rectWindow.left < rectScreen.left) {
  781. dx = rectScreen.left - rectWindow.left;
  782. rectWindow.left += dx;
  783. rectWindow.right += dx;
  784. }
  785. if (rectWindow.right > rectScreen.right) {
  786. if (nCx < nCxScreen) {
  787. dx = rectScreen.right - rectWindow.right;
  788. rectWindow.left += dx;
  789. rectWindow.right += dx;
  790. }
  791. }
  792. //
  793. // Make it fix on the y coord.
  794. //
  795. if (rectWindow.top < rectScreen.top) {
  796. dy = rectScreen.top - rectWindow.top;
  797. rectWindow.top += dy;
  798. rectWindow.bottom += dy;
  799. }
  800. if (rectWindow.bottom > rectScreen.bottom) {
  801. if (nCy < nCyScreen) {
  802. dy = rectScreen.bottom - rectWindow.bottom;
  803. rectWindow.top += dy;
  804. rectWindow.bottom += dy;
  805. }
  806. }
  807. if (dx != 0 || dy != 0) {
  808. MoveWindow(hwnd, rectWindow.left, rectWindow.top, nCx, nCy, TRUE);
  809. }
  810. }
  811. BOOL
  812. CenterWindow(
  813. HWND hWnd
  814. )
  815. /*++
  816. CenterWindow
  817. Description: Centers the window specified in hWnd.
  818. --*/
  819. {
  820. RECT rectWindow, rectParent, rectScreen;
  821. int nCX, nCY;
  822. HWND hParent;
  823. POINT ptPoint;
  824. hParent = GetParent(hWnd);
  825. if (hParent == NULL) {
  826. hParent = GetDesktopWindow();
  827. }
  828. GetWindowRect(hParent, &rectParent);
  829. GetWindowRect(hWnd, &rectWindow);
  830. GetWindowRect(GetDesktopWindow(), &rectScreen);
  831. nCX = rectWindow.right - rectWindow.left;
  832. nCY = rectWindow.bottom - rectWindow.top;
  833. ptPoint.x = ((rectParent.right + rectParent.left) / 2) - (nCX / 2);
  834. ptPoint.y = ((rectParent.bottom + rectParent.top ) / 2) - (nCY / 2);
  835. if (ptPoint.x < rectScreen.left) {
  836. ptPoint.x = rectScreen.left;
  837. }
  838. if (ptPoint.x > rectScreen.right - nCX) {
  839. ptPoint.x = rectScreen.right - nCX;
  840. }
  841. if (ptPoint.y < rectScreen.top) {
  842. ptPoint.y = rectScreen.top;
  843. }
  844. if (ptPoint.y > rectScreen.bottom - nCY) {
  845. ptPoint.y = rectScreen.bottom - nCY;
  846. }
  847. if (GetWindowLong(hWnd, GWL_STYLE) & WS_CHILD) {
  848. ScreenToClient(hParent, (LPPOINT)&ptPoint);
  849. }
  850. if (!MoveWindow(hWnd, ptPoint.x, ptPoint.y, nCX, nCY, TRUE)) {
  851. return FALSE;
  852. }
  853. return TRUE;
  854. }
  855. void
  856. ReplaceCmdLine(
  857. PFIX pFix,
  858. TCHAR* pszNewCmdLine
  859. )
  860. /*++
  861. ReplaceCmdLine
  862. Description: Replaces the command line for a shim DLL.
  863. --*/
  864. {
  865. TCHAR szError[MAX_PATH];
  866. if (pFix->pszCmdLine != NULL) {
  867. HeapFree(GetProcessHeap(), 0, pFix->pszCmdLine);
  868. pFix->pszCmdLine = NULL;
  869. }
  870. if (pszNewCmdLine == NULL) {
  871. return;
  872. } else if ((*pszNewCmdLine == '"') && (_tcslen(pszNewCmdLine)==1)) {
  873. LoadString(g_hInstance, IDS_INVALID_CMD_LINE, szError, MAX_PATH);
  874. MessageBox(g_hDlg, szError, g_szAppTitle, MB_OK | MB_ICONEXCLAMATION);
  875. return;
  876. }
  877. pFix->pszCmdLine = (TCHAR*)HeapAlloc(GetProcessHeap(),
  878. HEAP_ZERO_MEMORY,
  879. sizeof(TCHAR) * (lstrlen(pszNewCmdLine) + 1));
  880. if (pFix->pszCmdLine != NULL) {
  881. lstrcpy(pFix->pszCmdLine, pszNewCmdLine);
  882. } else {
  883. LogMsg(_T("[ReplaceCmdLine] failed to replace the cmd line for \"%s\"\n"),
  884. pFix->pszName);
  885. }
  886. }
  887. void
  888. DeselectAllShims(
  889. HWND hdlg
  890. )
  891. /*++
  892. DeselectAllShims
  893. Description: Removes selections for all shims listed.
  894. --*/
  895. {
  896. int cShims, nIndex;
  897. LVITEM lvi;
  898. UINT uState;
  899. //
  900. // Walk all the shims in the list view and deselect them.
  901. //
  902. ZeroMemory(&lvi, sizeof(lvi));
  903. cShims = ListView_GetItemCount(g_hwndShimList);
  904. for (nIndex = 0; nIndex < cShims; nIndex++) {
  905. PFIX pFix;
  906. lvi.iItem = nIndex;
  907. lvi.mask = LVIF_STATE | LVIF_PARAM;
  908. lvi.stateMask = LVIS_STATEIMAGEMASK;
  909. ListView_GetItem(g_hwndShimList, &lvi);
  910. pFix = (PFIX)lvi.lParam;
  911. //
  912. // Clear the check box, removes the 'X', clear the command line,
  913. // and clear the modules.
  914. //
  915. ListView_SetItemText(g_hwndShimList, nIndex, 1, _T(""));
  916. ListView_SetItemText(g_hwndShimList, nIndex, 2, _T(""));
  917. ListView_SetCheckState(g_hwndShimList, nIndex, FALSE);
  918. ReplaceCmdLine(pFix, NULL);
  919. BuildModuleListForShim(pFix, BML_DELFRLISTVIEW);
  920. }
  921. //
  922. // Update the count of selected shims.
  923. //
  924. SetTimer(hdlg, ID_COUNT_SHIMS, 100, NULL);
  925. }
  926. void
  927. AddMatchingFile(
  928. HWND hdlg,
  929. LPCTSTR pszFullPath,
  930. LPCTSTR pszRelativePath,
  931. BOOL bMainEXE
  932. )
  933. /*++
  934. AddMatchingFile
  935. Description: Adds a matching file and it's attributes to the tree.
  936. --*/
  937. {
  938. PATTRINFO pAttrInfo;
  939. TVINSERTSTRUCT is;
  940. HTREEITEM hParent;
  941. DWORD i;
  942. DWORD dwAttrCount;
  943. TCHAR szItem[MAX_PATH];
  944. //
  945. // Call the attribute manager to get all the attributes for this file.
  946. //
  947. SdbGetFileAttributes(pszFullPath, &pAttrInfo, &dwAttrCount);
  948. is.hParent = TVI_ROOT;
  949. is.hInsertAfter = TVI_LAST;
  950. is.item.lParam = (LPARAM)pAttrInfo;
  951. is.item.mask = TVIF_TEXT | TVIF_PARAM;
  952. is.item.pszText = (LPTSTR)pszRelativePath;
  953. hParent = TreeView_InsertItem(g_hwndFilesTree, &is);
  954. is.hParent = hParent;
  955. is.item.mask = TVIF_TEXT | TVIF_STATE | TVIF_PARAM | TVIF_IMAGE | TVIF_SELECTEDIMAGE;
  956. is.item.pszText = szItem;
  957. is.item.iImage = 0;
  958. is.item.iSelectedImage = 1;
  959. //
  960. // By default the attributes are not selected. To have them selected
  961. // by default you need to replace the following 1 with 2.
  962. //
  963. is.item.state = INDEXTOSTATEIMAGEMASK(1);
  964. is.item.stateMask = TVIS_STATEIMAGEMASK;
  965. //
  966. // Loop through all the attributes and show the ones that are available.
  967. //
  968. for (i = 0; i < dwAttrCount; i++) {
  969. if (!SdbFormatAttribute(&pAttrInfo[i], szItem, MAX_PATH)) {
  970. continue;
  971. }
  972. //
  973. // EXETYPE is a bogus attribute. Don't show it!
  974. //
  975. is.item.lParam = i;
  976. TreeView_InsertItem(g_hwndFilesTree, &is);
  977. }
  978. TreeView_Expand(g_hwndFilesTree, hParent, TVE_EXPAND);
  979. }
  980. void
  981. BrowseForApp(
  982. HWND hdlg
  983. )
  984. /*++
  985. BrowseForApp
  986. Description: Browse for the main executable for which a shim
  987. will be applied.
  988. --*/
  989. {
  990. TCHAR szFilter[MAX_PATH] = _T("");
  991. TCHAR szTitle[MAX_PATH] = _T("");
  992. OPENFILENAME ofn = {0};
  993. g_szBinary[0] = 0;
  994. LoadString(g_hInstance, IDS_BROWSE_FILTER, szFilter, MAX_PATH);
  995. LoadString(g_hInstance, IDS_BROWSE_TITLE, szTitle, MAX_PATH);
  996. ofn.lStructSize = sizeof(OPENFILENAME);
  997. ofn.hwndOwner = hdlg;
  998. ofn.hInstance = NULL;
  999. ofn.lpstrFilter = szFilter;
  1000. ofn.lpstrCustomFilter = NULL;
  1001. ofn.nMaxCustFilter = 0;
  1002. ofn.nFilterIndex = 0;
  1003. ofn.lpstrFile = g_szBinary;
  1004. ofn.nMaxFile = MAX_PATH;
  1005. ofn.lpstrFileTitle = g_szShortName;
  1006. ofn.nMaxFileTitle = 128;
  1007. ofn.lpstrInitialDir = NULL;
  1008. ofn.lpstrTitle = szTitle;
  1009. ofn.Flags = OFN_FILEMUSTEXIST | OFN_PATHMUSTEXIST | OFN_HIDEREADONLY;
  1010. ofn.lpstrDefExt = _T("exe");
  1011. if (GetOpenFileName(&ofn)) {
  1012. TCHAR szMainEXE[128];
  1013. // the parent exe defaults to the same as the EXE
  1014. lstrcpy(g_szParentExeName, g_szShortName);
  1015. lstrcpy(g_szParentExeFullPath, g_szBinary);
  1016. g_bSelectedParentExe = FALSE;
  1017. SetDlgItemText(hdlg, IDC_BINARY, g_szBinary);
  1018. EnableWindow(GetDlgItem(hdlg, IDC_ADD_MATCHING), TRUE);
  1019. EnableWindow(GetDlgItem(hdlg, IDC_RUN), TRUE);
  1020. EnableWindow(GetDlgItem(hdlg, IDC_CREATEFILE), TRUE);
  1021. EnableWindow(GetDlgItem(hdlg, IDC_SHOWXML), TRUE);
  1022. TreeView_DeleteAllItems(g_hwndFilesTree);
  1023. wsprintf(szMainEXE, _T("Main executable (%s)"), g_szShortName);
  1024. AddMatchingFile(hdlg, g_szBinary, szMainEXE, TRUE);
  1025. }
  1026. }
  1027. void
  1028. PromptAddMatchingFile(
  1029. HWND hdlg
  1030. )
  1031. /*++
  1032. PromptAddMatchingFile
  1033. Description: Show the open file dialog to allow the user
  1034. to add a matching file.
  1035. --*/
  1036. {
  1037. TCHAR szFullPath[MAX_PATH+1] = _T("");
  1038. TCHAR szShortName[128] = _T("");
  1039. TCHAR szRelativePath[MAX_PATH] = _T("");
  1040. TCHAR szFilter[MAX_PATH] = _T("");
  1041. TCHAR szTitle[MAX_PATH] = _T("");
  1042. TCHAR szParentTitle[MAX_PATH] = _T("");
  1043. TCHAR szInitialPath[MAX_PATH] = _T("");
  1044. TCHAR szDrive[_MAX_DRIVE] = _T("");
  1045. TCHAR szDir[_MAX_DIR] = _T("");
  1046. TCHAR* pMatch = NULL;
  1047. TCHAR szError[MAX_PATH];
  1048. OPENFILENAME ofn = {0};
  1049. szInitialPath[0] = 0;
  1050. LoadString(g_hInstance, IDS_MATCH_FILTER, szFilter, MAX_PATH);
  1051. LoadString(g_hInstance, IDS_MATCH_TITLE, szTitle, MAX_PATH);
  1052. if (g_szParentExeFullPath[0]) {
  1053. _tsplitpath(g_szParentExeFullPath, szDrive, szDir, NULL, NULL);
  1054. lstrcpy(szInitialPath, szDrive);
  1055. lstrcat(szInitialPath, szDir);
  1056. }
  1057. ofn.lStructSize = sizeof(OPENFILENAME);
  1058. ofn.hwndOwner = hdlg;
  1059. ofn.hInstance = NULL;
  1060. ofn.lpstrFilter = szFilter;
  1061. ofn.lpstrCustomFilter = NULL;
  1062. ofn.nMaxCustFilter = 0;
  1063. ofn.nFilterIndex = 0;
  1064. ofn.lpstrFile = szFullPath;
  1065. ofn.nMaxFile = MAX_PATH;
  1066. ofn.lpstrFileTitle = szShortName;
  1067. ofn.nMaxFileTitle = 128;
  1068. ofn.lpstrInitialDir = NULL;
  1069. ofn.lpstrTitle = szTitle;
  1070. ofn.Flags = OFN_FILEMUSTEXIST | OFN_PATHMUSTEXIST | OFN_HIDEREADONLY;
  1071. ofn.lpstrDefExt = _T("EXE");
  1072. if (GetOpenFileName(&ofn)) {
  1073. //
  1074. // Determine if the matching file is on the same drive
  1075. // as the EXE that was selected.
  1076. //
  1077. if (!PathIsSameRoot(szFullPath,
  1078. g_szParentExeFullPath) && !g_bSelectedParentExe) {
  1079. TCHAR szParentFile[MAX_PATH];
  1080. //
  1081. // Prompt the user for the parent EXE.
  1082. //
  1083. szParentFile[0] = 0;
  1084. szInitialPath[0] = 0;
  1085. if (szFullPath[0]) {
  1086. _tsplitpath(szFullPath, szDrive, szDir, NULL, NULL);
  1087. lstrcpy(szInitialPath, szDrive);
  1088. lstrcat(szInitialPath, szDir);
  1089. }
  1090. LoadString(g_hInstance, IDS_PARENT_TITLE, szParentTitle, MAX_PATH);
  1091. ofn.lpstrTitle = szParentTitle;
  1092. ofn.lpstrFile = szParentFile;
  1093. ofn.nMaxFile = sizeof(szParentFile);
  1094. if (GetOpenFileName(&ofn) == TRUE) {
  1095. lstrcpy(g_szParentExeName, szShortName);
  1096. lstrcpy(g_szParentExeFullPath, szParentFile);
  1097. g_bSelectedParentExe = TRUE;
  1098. }
  1099. }
  1100. //
  1101. // Check the drive letters to see which drive the match file is on
  1102. // then calculate a relative path to the matching file.
  1103. //
  1104. if (PathIsSameRoot(szFullPath, g_szParentExeFullPath)) {
  1105. pMatch = GetRelativePath(g_szParentExeFullPath, szFullPath);
  1106. } else if (PathIsSameRoot(szFullPath, g_szBinary)) {
  1107. pMatch = GetRelativePath(g_szBinary, szFullPath);
  1108. } else {
  1109. LoadString(g_hInstance, IDS_MATCH_PATH_NOT_RELATIVE, szError, MAX_PATH);
  1110. MessageBox(hdlg, szError, g_szAppTitle, MB_OK | MB_ICONEXCLAMATION);
  1111. return;
  1112. }
  1113. if (pMatch) {
  1114. //
  1115. // Finally add the maching file and free the memory
  1116. //
  1117. AddMatchingFile(hdlg, szFullPath, pMatch, FALSE);
  1118. HeapFree(GetProcessHeap(), 0, pMatch);
  1119. }
  1120. }
  1121. }
  1122. void
  1123. ShowAvailableFixes(
  1124. HWND hList
  1125. )
  1126. /*++
  1127. ShowAvailableFixes
  1128. Description: Query the shim database and populate the
  1129. shim list with all the available shims.
  1130. --*/
  1131. {
  1132. LVITEM lvitem;
  1133. PFIX pFix;
  1134. TCHAR szError[MAX_PATH];
  1135. UINT uCount = 0;
  1136. g_pFixHead = ReadFixesFromSdb(_T("sysmain.sdb"), g_bAllShims);
  1137. if (g_pFixHead == NULL) {
  1138. LoadString(g_hInstance, IDS_SDB_READ_FAIL, szError, MAX_PATH);
  1139. MessageBox(NULL, szError, g_szAppTitle, MB_OK | MB_ICONERROR);
  1140. return;
  1141. }
  1142. //
  1143. // Walk the list and add all the fixes to the list view.
  1144. //
  1145. pFix = g_pFixHead;
  1146. while (pFix != NULL) {
  1147. if (pFix->bLayer) {
  1148. LPARAM lInd;
  1149. lInd = SendMessage(g_hwndListLayers, LB_ADDSTRING, 0, (LPARAM)pFix->pszName);
  1150. SendMessage(g_hwndListLayers, LB_SETITEMDATA, lInd, (LPARAM)pFix);
  1151. } else {
  1152. lvitem.mask = LVIF_TEXT | LVIF_PARAM | LVIF_STATE;
  1153. lvitem.lParam = (LPARAM)pFix;
  1154. lvitem.pszText = pFix->pszName;
  1155. lvitem.iItem = ListView_GetItemCount(g_hwndShimList);
  1156. lvitem.iSubItem = 0;
  1157. lvitem.state = INDEXTOSTATEIMAGEMASK(1);
  1158. lvitem.stateMask = LVIS_STATEIMAGEMASK;
  1159. ListView_InsertItem(hList, &lvitem);
  1160. }
  1161. pFix = pFix->pNext;
  1162. }
  1163. }
  1164. BOOL
  1165. InstallSDB(
  1166. TCHAR* pszFileName,
  1167. BOOL fInstall
  1168. )
  1169. /*++
  1170. InstallSDB
  1171. Description: Launch SDBInst to install or uninstall
  1172. the specified SDB.
  1173. --*/
  1174. {
  1175. TCHAR szCmd[MAX_PATH];
  1176. TCHAR szExePath[MAX_PATH];
  1177. TCHAR* pExt = NULL;
  1178. STARTUPINFO si;
  1179. PROCESS_INFORMATION pi;
  1180. GetSystemDirectory(szExePath, MAX_PATH);
  1181. _tcscat(szExePath, _T("\\sdbinst.exe"));
  1182. if (GetFileAttributes(szExePath) == -1) {
  1183. return FALSE;
  1184. }
  1185. wsprintf(szCmd,
  1186. fInstall ? _T("%s -q %s") : _T("%s -q -u %s"),
  1187. szExePath,
  1188. pszFileName);
  1189. ZeroMemory(&si, sizeof(si));
  1190. si.cb = sizeof(si);
  1191. if (!CreateProcess(NULL,
  1192. szCmd,
  1193. NULL,
  1194. NULL,
  1195. FALSE,
  1196. NORMAL_PRIORITY_CLASS | CREATE_NO_WINDOW,
  1197. NULL,
  1198. NULL,
  1199. &si,
  1200. &pi)) {
  1201. LogMsg(_T("[InstallSDB] CreateProcess \"%s\" failed 0x%X\n"),
  1202. szCmd, GetLastError());
  1203. return FALSE;
  1204. }
  1205. // Wait for SDBInst to complete it's work.
  1206. WaitForSingleObject(pi.hProcess, INFINITE);
  1207. CloseHandle(pi.hThread);
  1208. CloseHandle(pi.hProcess);
  1209. return TRUE;
  1210. }
  1211. void
  1212. CreateSupportForApp(
  1213. HWND hdlg
  1214. )
  1215. /*++
  1216. CreateSupportForApp
  1217. Description: Build an SDB for the application and offer the user
  1218. the chance to install it.
  1219. --*/
  1220. {
  1221. BOOL bok;
  1222. TCHAR szFileCreated[MAX_PATH];
  1223. TCHAR szError[MAX_PATH];
  1224. TCHAR szTemp[MAX_PATH];
  1225. int nAnswer;
  1226. bok = CollectFix(g_hwndListLayers,
  1227. g_hwndShimList,
  1228. g_hwndFilesTree,
  1229. g_szShortName,
  1230. g_szBinary,
  1231. (g_nCrtTab == 0 ? CFF_USELAYERTAB : 0) |
  1232. (g_fW2K ? CFF_ADDW2KSUPPORT : 0),
  1233. szFileCreated);
  1234. if (!bok) {
  1235. LoadString(g_hInstance, IDS_FIX_CREATE_FAIL, szError, MAX_PATH);
  1236. MessageBox(hdlg, szError, g_szAppTitle, MB_OK | MB_ICONERROR);
  1237. } else {
  1238. LoadString(g_hInstance, IDS_CREATE_FIX, szTemp, MAX_PATH);
  1239. wsprintf(szError, szTemp, szFileCreated);
  1240. nAnswer = MessageBox(hdlg, szError, g_szAppTitle, MB_YESNO | MB_ICONQUESTION);
  1241. if (IDYES == nAnswer) {
  1242. bok = InstallSDB(szFileCreated, TRUE);
  1243. if (!bok) {
  1244. LoadString(g_hInstance, IDS_INSTALL_FIX_FAIL, szError, MAX_PATH);
  1245. MessageBox(hdlg, szError, g_szAppTitle, MB_OK | MB_ICONERROR);
  1246. } else {
  1247. LoadString(g_hInstance, IDS_INSTALL_FIX_OK, szError, MAX_PATH);
  1248. MessageBox(hdlg, szError, g_szAppTitle, MB_OK | MB_ICONINFORMATION);
  1249. }
  1250. }
  1251. }
  1252. }
  1253. BOOL
  1254. ShowXML(
  1255. HWND hdlg
  1256. )
  1257. /*++
  1258. ShowXML
  1259. Description: Show the XML for the current selections.
  1260. --*/
  1261. {
  1262. BOOL bok;
  1263. TCHAR szError[MAX_PATH];
  1264. bok = CollectFix(g_hwndListLayers,
  1265. g_hwndShimList,
  1266. g_hwndFilesTree,
  1267. g_szShortName,
  1268. g_szBinary,
  1269. CFF_SHOWXML |
  1270. (g_nCrtTab == 0 ? CFF_USELAYERTAB : 0) |
  1271. (g_fW2K ? CFF_ADDW2KSUPPORT : 0),
  1272. NULL);
  1273. if (!bok) {
  1274. LoadString(g_hInstance, IDS_TOO_MANY_FILES, szError, MAX_PATH);
  1275. MessageBox(hdlg, szError, g_szAppTitle, MB_OK | MB_ICONEXCLAMATION);
  1276. }
  1277. return (bok);
  1278. }
  1279. void
  1280. RunTheApp(
  1281. HWND hdlg
  1282. )
  1283. /*++
  1284. RunTheApp
  1285. Description: Run the selected app.
  1286. --*/
  1287. {
  1288. STARTUPINFO si;
  1289. PROCESS_INFORMATION pi;
  1290. TCHAR szFileCreated[MAX_PATH];
  1291. TCHAR szCmdLine[MAX_PATH];
  1292. TCHAR szError[MAX_PATH];
  1293. TCHAR szRun[MAX_PATH];
  1294. TCHAR* pszCmd;
  1295. TCHAR* pszDir;
  1296. TCHAR* psz;
  1297. BOOL bok;
  1298. //
  1299. // Cleanup for the previous app.
  1300. //
  1301. CleanupSupportForApp(g_szShortName);
  1302. bok = CollectFix(g_hwndListLayers,
  1303. g_hwndShimList,
  1304. g_hwndFilesTree,
  1305. g_szShortName,
  1306. g_szBinary,
  1307. CFF_SHIMLOG |
  1308. CFF_APPENDLAYER |
  1309. (g_nCrtTab == 0 ? CFF_USELAYERTAB : 0) |
  1310. (g_fW2K ? CFF_ADDW2KSUPPORT : 0),
  1311. szFileCreated);
  1312. if (!bok) {
  1313. LoadString(g_hInstance, IDS_ADD_SUPPORT_FAIL, szError, MAX_PATH);
  1314. MessageBox(hdlg, szError, g_szAppTitle, MB_OK | MB_ICONERROR);
  1315. return;
  1316. }
  1317. //
  1318. // We need to install the fix for them.
  1319. //
  1320. if (!(InstallSDB(szFileCreated, TRUE))) {
  1321. LoadString(g_hInstance, IDS_INSTALL_FIX_FAIL, szError, MAX_PATH);
  1322. MessageBox(g_hDlg, szError, g_szAppTitle, MB_OK | MB_ICONERROR);
  1323. return;
  1324. }
  1325. ZeroMemory(&si, sizeof(si));
  1326. si.cb = sizeof(si);
  1327. //
  1328. // Try to run the app.
  1329. //
  1330. GetDlgItemText(hdlg, IDC_CMD_LINE, szCmdLine, MAX_PATH);
  1331. if (szCmdLine[0] == 0) {
  1332. wsprintf(szRun, _T("\"%s\""), g_szBinary);
  1333. } else {
  1334. wsprintf(szRun, _T("\"%s\" %s"), g_szBinary, szCmdLine);
  1335. }
  1336. pszCmd = szRun;
  1337. pszDir = g_szBinary;
  1338. //
  1339. // We need to change the current directory or some
  1340. // apps won't run.
  1341. //
  1342. psz = pszDir + lstrlen(pszDir) - 1;
  1343. while (psz > pszDir && *psz != _T('\\')) {
  1344. psz--;
  1345. }
  1346. if (psz > pszDir) {
  1347. *psz = 0;
  1348. SetCurrentDirectory(pszDir);
  1349. *psz = _T('\\');
  1350. }
  1351. LogMsg(_T("[RunTheApp] : %s\n"), pszCmd);
  1352. if (!CreateProcess(NULL,
  1353. pszCmd,
  1354. NULL,
  1355. NULL,
  1356. FALSE,
  1357. NORMAL_PRIORITY_CLASS,
  1358. NULL,
  1359. NULL,
  1360. &si,
  1361. &pi)) {
  1362. LogMsg(_T("[RunTheApp] CreateProcess failed 0x%X\n"), GetLastError());
  1363. return;
  1364. }
  1365. CloseHandle(pi.hThread);
  1366. CloseHandle(pi.hProcess);
  1367. //
  1368. // Save this SDB for later so we can remove it.
  1369. //
  1370. lstrcpy(g_szSDBToDelete, szFileCreated);
  1371. }
  1372. void
  1373. ExpandCollapseDialog(
  1374. HWND hdlg,
  1375. BOOL bHide
  1376. )
  1377. /*++
  1378. ExpandCollapseDialog
  1379. Description: Change the current view of the dialog.
  1380. --*/
  1381. {
  1382. TCHAR szSimple[64];
  1383. TCHAR szAdvanced[64];
  1384. int i, nShow;
  1385. DWORD arrId[] = {IDC_ADD_MATCHING,
  1386. IDC_FILE_ATTRIBUTES_STATIC,
  1387. IDC_ATTRIBUTES,
  1388. IDC_CREATEFILE,
  1389. 0};
  1390. if (!bHide) {
  1391. SetWindowPos(hdlg, NULL, 0, 0,
  1392. g_rcDlgBig.right - g_rcDlgBig.left,
  1393. g_rcDlgBig.bottom - g_rcDlgBig.top,
  1394. SWP_NOMOVE | SWP_NOZORDER);
  1395. nShow = SW_SHOW;
  1396. g_bSimpleEdition = FALSE;
  1397. LoadString(g_hInstance, IDS_SIMPLE_TEXT, szSimple, 64);
  1398. SetDlgItemText(hdlg, IDC_DETAILS, szSimple);
  1399. SendDlgItemMessage(hdlg, IDC_CREATEFILE, BM_SETCHECK, BST_CHECKED, 0);
  1400. //
  1401. // Make sure the dialog is in view.
  1402. //
  1403. GetTopLevelWindowIntoView(hdlg);
  1404. } else {
  1405. nShow = SW_HIDE;
  1406. g_bSimpleEdition = TRUE;
  1407. LoadString(g_hInstance, IDS_ADVANCED_TEXT, szAdvanced, 64);
  1408. SetDlgItemText(hdlg, IDC_DETAILS, szAdvanced);
  1409. SendDlgItemMessage(hdlg, IDC_CREATEFILE, BM_SETCHECK, BST_UNCHECKED, 0);
  1410. }
  1411. for (i = 0; arrId[i] != 0; i++) {
  1412. ShowWindow(GetDlgItem(hdlg, arrId[i]), nShow);
  1413. }
  1414. if (bHide) {
  1415. SetWindowPos(hdlg, NULL, 0, 0,
  1416. g_rcDlgSmall.right - g_rcDlgSmall.left,
  1417. g_rcDlgSmall.bottom - g_rcDlgSmall.top,
  1418. SWP_NOMOVE | SWP_NOZORDER);
  1419. }
  1420. }
  1421. void
  1422. LayerChanged(
  1423. HWND hdlg
  1424. )
  1425. /*++
  1426. LayerChanged
  1427. Description: Changing the layer has the effect of selecting the
  1428. shims that the layer consists of.
  1429. --*/
  1430. {
  1431. LRESULT lSel;
  1432. PFIX pFix;
  1433. LVITEM lvi;
  1434. int nIndex, cShims = 0;
  1435. lSel = SendMessage(g_hwndListLayers, LB_GETCURSEL, 0, 0);
  1436. if (lSel == LB_ERR) {
  1437. LogMsg(_T("[LayerChanged] No layer selected.\n"));
  1438. return;
  1439. }
  1440. pFix = (PFIX)SendMessage(g_hwndListLayers, LB_GETITEMDATA, lSel, 0);
  1441. if (pFix->parrShim == NULL) {
  1442. LogMsg(_T("[LayerChanged] No array of DLLs.\n"));
  1443. return;
  1444. }
  1445. // Remove any prior selections.
  1446. DeselectAllShims(g_hFixesDlg);
  1447. //
  1448. // Loop through all the items in the shim list and make the
  1449. // appropriate selections.
  1450. //
  1451. cShims = ListView_GetItemCount(g_hwndShimList);
  1452. for (nIndex = 0; nIndex < cShims; nIndex++) {
  1453. PFIX pFixItem;
  1454. TCHAR szText[1024];
  1455. int nInd = 0;
  1456. lvi.mask = LVIF_PARAM;
  1457. lvi.iItem = nIndex;
  1458. lvi.iSubItem = 0;
  1459. ListView_GetItem(g_hwndShimList, &lvi);
  1460. pFixItem = (PFIX)lvi.lParam;
  1461. //
  1462. // See if this shim DLL is in the array for the selected layer.
  1463. //
  1464. while (pFix->parrShim[nInd] != NULL) {
  1465. if (pFix->parrShim[nInd] == pFixItem) {
  1466. break;
  1467. }
  1468. nInd++;
  1469. }
  1470. //
  1471. // Put a check next to this shim DLL. If he has a command line,
  1472. // put an 'X' in the CmdLine subitem.
  1473. //
  1474. if (pFix->parrShim[nInd] != NULL) {
  1475. ListView_SetCheckState(g_hwndShimList, nIndex, TRUE);
  1476. } else {
  1477. ListView_SetCheckState(g_hwndShimList, nIndex, FALSE);
  1478. }
  1479. if (pFix->parrCmdLine[nInd] != NULL) {
  1480. ReplaceCmdLine(pFixItem, pFix->parrCmdLine[nInd]);
  1481. ListView_SetItemText(g_hwndShimList, nIndex, 1, _T("X"));
  1482. }
  1483. ListView_SetItem(g_hwndShimList, &lvi);
  1484. }
  1485. //
  1486. // Update the count of selected shims.
  1487. //
  1488. SetTimer(g_hFixesDlg, ID_COUNT_SHIMS, 100, NULL);
  1489. }
  1490. BOOL
  1491. InitMainDialog(
  1492. HWND hdlg
  1493. )
  1494. /*++
  1495. InitMainDialog
  1496. Description: Init routine called during WM_INITDIALOG for
  1497. the main dialog of QFixApp.
  1498. --*/
  1499. {
  1500. HICON hIcon;
  1501. RECT rcList, rcTree;
  1502. HIMAGELIST hImage;
  1503. TCHAR szText[MAX_PATH];
  1504. //
  1505. // Initialize globals.
  1506. //
  1507. g_szParentExeFullPath[0] = 0;
  1508. g_szBinary[0] = 0;
  1509. g_hDlg = hdlg;
  1510. //
  1511. // The dialog has two views. Calculate the size of the smaller
  1512. // view and show the simpler view by default.
  1513. //
  1514. GetWindowRect(hdlg, &g_rcDlgBig);
  1515. GetWindowRect(GetDlgItem(hdlg, IDC_ATTRIBUTES), &rcList);
  1516. GetWindowRect(GetDlgItem(hdlg, IDC_TAB_FIXES), &rcTree);
  1517. g_rcDlgSmall.left = g_rcDlgBig.left;
  1518. g_rcDlgSmall.top = g_rcDlgBig.top;
  1519. g_rcDlgSmall.bottom = g_rcDlgBig.bottom;
  1520. g_rcDlgSmall.right = g_rcDlgBig.right -
  1521. (rcList.right - rcList.left) -
  1522. (rcList.left - rcTree.right);
  1523. ExpandCollapseDialog(hdlg, TRUE);
  1524. CenterWindow(hdlg);
  1525. //
  1526. // Disable a bunch of controls.
  1527. //
  1528. EnableWindow(GetDlgItem(hdlg, IDC_ADD_MATCHING), FALSE);
  1529. EnableWindow(GetDlgItem(hdlg, IDC_REMOVE_MATCHING), FALSE);
  1530. EnableWindow(GetDlgItem(hdlg, IDC_RUN), FALSE);
  1531. EnableWindow(GetDlgItem(hdlg, IDC_CREATEFILE), FALSE);
  1532. EnableWindow(GetDlgItem(hdlg, IDC_SHOWXML), FALSE);
  1533. //
  1534. // Show the app icon.
  1535. //
  1536. hIcon = LoadIcon(g_hInstance, MAKEINTRESOURCE(IDI_ICON));
  1537. SetClassLongPtr(hdlg, GCLP_HICON, (LONG_PTR)hIcon);
  1538. g_hwndTab = GetDlgItem(hdlg, IDC_TAB_FIXES);
  1539. g_hwndFilesTree = GetDlgItem(hdlg, IDC_ATTRIBUTES);
  1540. //
  1541. // Set up the tab control.
  1542. //
  1543. InitTabs(hdlg, g_hwndTab);
  1544. hImage = ImageList_LoadImage(g_hInstance,
  1545. MAKEINTRESOURCE(IDB_BMP_CHECK),
  1546. 16,
  1547. 0,
  1548. CLR_DEFAULT,
  1549. IMAGE_BITMAP,
  1550. LR_LOADTRANSPARENT);
  1551. if (hImage != NULL) {
  1552. TreeView_SetImageList(g_hwndFilesTree, hImage, TVSIL_STATE);
  1553. } else {
  1554. LogMsg(_T("[InitMainDialog] Failed to load imagelist\n"));
  1555. }
  1556. //
  1557. // Set the text for the link window.
  1558. //
  1559. LoadString(g_hInstance,
  1560. g_fW2K ? IDS_W2K_LINK : IDS_XP_LINK,
  1561. szText,
  1562. MAX_PATH);
  1563. SetDlgItemText(g_hDlg, IDC_DOWNLOAD_WU, szText);
  1564. //
  1565. // Try selecting the Win95 layer.
  1566. //
  1567. SendMessage(g_hwndListLayers, LB_SELECTSTRING, (WPARAM)(-1), (LPARAM)_T("Win95"));
  1568. LayerChanged(hdlg);
  1569. TabCtrl_SetCurFocus(g_hwndTab, 0);
  1570. ShowWindow(g_hLayersDlg, SW_SHOWNORMAL);
  1571. return TRUE;
  1572. }
  1573. void
  1574. FileTreeToggleSelection(
  1575. HTREEITEM hItem,
  1576. int uMode
  1577. )
  1578. /*++
  1579. FileTreeToggleSelection
  1580. Description: Changes the selection on the attributes tree.
  1581. --*/
  1582. {
  1583. UINT State;
  1584. TVITEM item;
  1585. switch (uMode)
  1586. {
  1587. case uSelect:
  1588. State = INDEXTOSTATEIMAGEMASK(2);
  1589. break;
  1590. case uDeselect:
  1591. State = INDEXTOSTATEIMAGEMASK(1);
  1592. break;
  1593. case uReverse:
  1594. {
  1595. item.mask = TVIF_HANDLE | TVIF_STATE;
  1596. item.hItem = hItem;
  1597. item.stateMask = TVIS_STATEIMAGEMASK;
  1598. TreeView_GetItem(g_hwndFilesTree, &item);
  1599. State = item.state & TVIS_STATEIMAGEMASK;
  1600. if (State) {
  1601. if (((State >> 12) & 0x03) == 2) {
  1602. State = INDEXTOSTATEIMAGEMASK(1);
  1603. } else {
  1604. State = INDEXTOSTATEIMAGEMASK(2);
  1605. }
  1606. }
  1607. break;
  1608. }
  1609. }
  1610. item.mask = TVIF_HANDLE | TVIF_STATE;
  1611. item.hItem = hItem;
  1612. item.state = State;
  1613. item.stateMask = TVIS_STATEIMAGEMASK;
  1614. TreeView_SetItem(g_hwndFilesTree, &item);
  1615. }
  1616. void
  1617. SelectAttrsInTree(
  1618. BOOL fSelect
  1619. )
  1620. /*++
  1621. SelectAttrsInTree
  1622. Description: Walks each attribute in tree and reverses it's selection.
  1623. --*/
  1624. {
  1625. HTREEITEM hItem, hChildItem;
  1626. hItem = TreeView_GetSelection(g_hwndFilesTree);
  1627. hChildItem = TreeView_GetChild(g_hwndFilesTree, hItem);
  1628. FileTreeToggleSelection(hChildItem, fSelect ? uSelect : uDeselect);
  1629. while (hChildItem) {
  1630. hChildItem = TreeView_GetNextSibling(g_hwndFilesTree, hChildItem);
  1631. FileTreeToggleSelection(hChildItem, fSelect ? uSelect : uDeselect);
  1632. }
  1633. }
  1634. void
  1635. ShimListToggleSelection(
  1636. int nItem,
  1637. int uMode
  1638. )
  1639. /*++
  1640. ShimListToggleSelection
  1641. Description: Changes the selection on the shim list.
  1642. --*/
  1643. {
  1644. UINT uState;
  1645. switch (uMode)
  1646. {
  1647. case uSelect:
  1648. ListView_SetCheckState(g_hwndShimList, nItem, TRUE);
  1649. break;
  1650. case uDeselect:
  1651. ListView_SetCheckState(g_hwndShimList, nItem, FALSE);
  1652. break;
  1653. case uReverse:
  1654. uState = ListView_GetItemState(g_hwndShimList,
  1655. nItem,
  1656. LVIS_STATEIMAGEMASK);
  1657. if (uState) {
  1658. if (((uState >> 12) & 0x03) == 2) {
  1659. uState = INDEXTOSTATEIMAGEMASK(2);
  1660. } else {
  1661. uState = INDEXTOSTATEIMAGEMASK(1);
  1662. }
  1663. }
  1664. ListView_SetItemState(g_hwndShimList, nItem, uState,
  1665. LVIS_STATEIMAGEMASK);
  1666. break;
  1667. }
  1668. }
  1669. void
  1670. HandleTabNotification(
  1671. HWND hdlg,
  1672. LPARAM lParam
  1673. )
  1674. /*++
  1675. HandleTabNotification
  1676. Description: Handle all the notifications we care about for the tab.
  1677. --*/
  1678. {
  1679. LPNMHDR pnm = (LPNMHDR)lParam;
  1680. int ind = 0;
  1681. switch (pnm->code) {
  1682. case TCN_SELCHANGE:
  1683. {
  1684. int nSel;
  1685. DLGHDR *pHdr = (DLGHDR*)GetWindowLongPtr(hdlg, DWLP_USER);
  1686. nSel = TabCtrl_GetCurSel(pHdr->hTab);
  1687. if (-1 == nSel) {
  1688. break;
  1689. }
  1690. g_nCrtTab = nSel;
  1691. if (nSel == 0) {
  1692. ShowWindow(pHdr->hDisplay[1], SW_HIDE);
  1693. ShowWindow(pHdr->hDisplay[0], SW_SHOW);
  1694. } else {
  1695. ShowWindow(pHdr->hDisplay[0], SW_HIDE);
  1696. ShowWindow(pHdr->hDisplay[1], SW_SHOW);
  1697. }
  1698. break;
  1699. }
  1700. default:
  1701. break;
  1702. }
  1703. }
  1704. INT_PTR CALLBACK
  1705. OptionsDlgProc(
  1706. HWND hdlg,
  1707. UINT uMsg,
  1708. WPARAM wParam,
  1709. LPARAM lParam
  1710. )
  1711. /*++
  1712. OptionsDlgProc
  1713. Description: Handles messages for the options dialog.
  1714. --*/
  1715. {
  1716. int wCode = LOWORD(wParam);
  1717. int wNotifyCode = HIWORD(wParam);
  1718. switch (uMsg) {
  1719. case WM_INITDIALOG:
  1720. {
  1721. PFIX pFix;
  1722. TCHAR szTitle[MAX_PATH];
  1723. TCHAR szTemp[MAX_PATH];
  1724. TCHAR szType[64];
  1725. TCHAR szModuleName[128];
  1726. pFix = (PFIX)lParam;
  1727. LoadString(g_hInstance, IDS_MOD_TYPE, szType, 64);
  1728. LoadString(g_hInstance, IDS_MOD_NAME, szModuleName, 128);
  1729. LoadString(g_hInstance, IDS_OPTIONS_TITLE, szTemp, MAX_PATH);
  1730. CenterWindow(hdlg);
  1731. SetWindowLongPtr(hdlg, DWLP_USER, lParam);
  1732. EnableWindow(GetDlgItem(hdlg, IDC_REMOVE), FALSE);
  1733. g_hwndModuleList = GetDlgItem(hdlg, IDC_MOD_LIST);
  1734. InsertListViewColumn(g_hwndModuleList, szType, FALSE, 0, 75);
  1735. InsertListViewColumn(g_hwndModuleList, szModuleName, FALSE, 1, 115);
  1736. ListView_SetExtendedListViewStyle(g_hwndModuleList, LVS_EX_FULLROWSELECT);
  1737. wsprintf(szTitle, szTemp, pFix->pszName);
  1738. SetWindowText(hdlg, szTitle);
  1739. if (NULL != pFix->pszCmdLine) {
  1740. SetDlgItemText(hdlg, IDC_SHIM_CMD_LINE, pFix->pszCmdLine);
  1741. }
  1742. CheckDlgButton(hdlg, IDC_INCLUDE, BST_CHECKED);
  1743. // Add any modules to the list view.
  1744. BuildModuleListForShim(pFix, BML_ADDTOLISTVIEW);
  1745. break;
  1746. }
  1747. case WM_NOTIFY:
  1748. HandleModuleListNotification(hdlg, lParam);
  1749. break;
  1750. case WM_COMMAND:
  1751. switch (wCode) {
  1752. case IDC_ADD:
  1753. {
  1754. TCHAR szModName[MAX_PATH];
  1755. TCHAR szError[MAX_PATH];
  1756. LVITEM lvi;
  1757. UINT uInclude, uExclude;
  1758. GetDlgItemText(hdlg, IDC_MOD_NAME, szModName, MAX_PATH);
  1759. if (*szModName == 0) {
  1760. LoadString(g_hInstance, IDS_NO_MOD, szError, MAX_PATH);
  1761. MessageBox(hdlg, szError, g_szAppTitle, MB_ICONEXCLAMATION | MB_OK);
  1762. SetFocus(GetDlgItem(hdlg, IDC_MOD_NAME));
  1763. break;
  1764. }
  1765. uInclude = IsDlgButtonChecked(hdlg, IDC_INCLUDE);
  1766. uExclude = IsDlgButtonChecked(hdlg, IDC_EXCLUDE);
  1767. if ((BST_CHECKED == uInclude) || (BST_CHECKED == uExclude)) {
  1768. AddModuleToListView(szModName, uInclude);
  1769. SetDlgItemText(hdlg, IDC_MOD_NAME, _T(""));
  1770. SetFocus(GetDlgItem(hdlg, IDC_MOD_NAME));
  1771. } else {
  1772. LoadString(g_hInstance, IDS_NO_INCEXC, szError, MAX_PATH);
  1773. MessageBox(hdlg, szError, g_szAppTitle, MB_ICONEXCLAMATION | MB_OK);
  1774. SetFocus(GetDlgItem(hdlg, IDC_INCLUDE));
  1775. break;
  1776. }
  1777. break;
  1778. }
  1779. case IDC_REMOVE:
  1780. { int nIndex;
  1781. nIndex = ListView_GetSelectionMark(g_hwndModuleList);
  1782. ListView_DeleteItem(g_hwndModuleList, nIndex);
  1783. EnableWindow(GetDlgItem(hdlg, IDC_REMOVE), FALSE);
  1784. SetFocus(GetDlgItem(hdlg, IDC_MOD_NAME));
  1785. break;
  1786. }
  1787. case IDOK:
  1788. {
  1789. PFIX pFix;
  1790. TCHAR szCmdLine[1024] = _T("");
  1791. pFix = (PFIX)GetWindowLongPtr(hdlg, DWLP_USER);
  1792. GetDlgItemText(hdlg, IDC_SHIM_CMD_LINE, szCmdLine, 1023);
  1793. if (*szCmdLine != 0) {
  1794. ReplaceCmdLine(pFix, szCmdLine);
  1795. } else {
  1796. ReplaceCmdLine(pFix, NULL);
  1797. }
  1798. // Retrieve any modules from the list view.
  1799. BuildModuleListForShim(pFix, BML_GETFRLISTVIEW);
  1800. EndDialog(hdlg, TRUE);
  1801. break;
  1802. }
  1803. case IDCANCEL:
  1804. EndDialog(hdlg, FALSE);
  1805. break;
  1806. default:
  1807. return FALSE;
  1808. }
  1809. break;
  1810. default:
  1811. return FALSE;
  1812. }
  1813. return TRUE;
  1814. }
  1815. INT_PTR CALLBACK
  1816. MsgBoxDlgProc(
  1817. HWND hdlg,
  1818. UINT uMsg,
  1819. WPARAM wParam,
  1820. LPARAM lParam
  1821. )
  1822. /*++
  1823. MsgBoxDlgProc
  1824. Description: Displays a message box dialog so we can use the hyperlink.
  1825. --*/
  1826. {
  1827. int wCode = LOWORD(wParam);
  1828. int wNotifyCode = HIWORD(wParam);
  1829. switch (uMsg) {
  1830. case WM_INITDIALOG:
  1831. {
  1832. TCHAR szLink[MAX_PATH];
  1833. UINT uNoSDB;
  1834. uNoSDB = (UINT)lParam;
  1835. CenterWindow(hdlg);
  1836. //
  1837. // Use the parameter to determine what text to display.
  1838. //
  1839. if (uNoSDB) {
  1840. LoadString(g_hInstance, IDS_W2K_NO_SDB, szLink, MAX_PATH);
  1841. SetDlgItemText(hdlg, IDC_MESSAGE, szLink);
  1842. } else {
  1843. LoadString(g_hInstance, IDS_SP2_SDB, szLink, MAX_PATH);
  1844. SetDlgItemText(hdlg, IDC_MESSAGE, szLink);
  1845. }
  1846. LoadString(g_hInstance, IDS_MSG_LINK, szLink, MAX_PATH);
  1847. SetDlgItemText(hdlg, IDC_MSG_LINK, szLink);
  1848. break;
  1849. }
  1850. case WM_NOTIFY:
  1851. if (wParam == IDC_MSG_LINK) {
  1852. NMHDR* pHdr = (NMHDR*)lParam;
  1853. if (pHdr->code == NM_CLICK || pHdr->code == NM_RETURN) {
  1854. SHELLEXECUTEINFO sei = { 0 };
  1855. sei.cbSize = sizeof(SHELLEXECUTEINFO);
  1856. sei.fMask = SEE_MASK_DOENVSUBST;
  1857. sei.hwnd = hdlg;
  1858. sei.nShow = SW_SHOWNORMAL;
  1859. sei.lpFile = g_szW2KUrl;
  1860. ShellExecuteEx(&sei);
  1861. break;
  1862. }
  1863. }
  1864. break;
  1865. case WM_COMMAND:
  1866. switch (wCode) {
  1867. case IDCANCEL:
  1868. EndDialog(hdlg, TRUE);
  1869. break;
  1870. default:
  1871. return FALSE;
  1872. }
  1873. break;
  1874. default:
  1875. return FALSE;
  1876. }
  1877. return TRUE;
  1878. }
  1879. INT_PTR CALLBACK
  1880. LayersTabDlgProc(
  1881. HWND hdlg,
  1882. UINT uMsg,
  1883. WPARAM wParam,
  1884. LPARAM lParam
  1885. )
  1886. /*++
  1887. LayersTabDlgProc
  1888. Description: Handle messages for the layers tab.
  1889. --*/
  1890. {
  1891. int wCode = LOWORD(wParam);
  1892. int wNotifyCode = HIWORD(wParam);
  1893. switch (uMsg) {
  1894. case WM_INITDIALOG:
  1895. HandleLayersDialogInit(hdlg);
  1896. break;
  1897. case WM_COMMAND:
  1898. if (wNotifyCode == LBN_SELCHANGE && wCode == IDC_LAYERS) {
  1899. LayerChanged(hdlg);
  1900. break;
  1901. }
  1902. switch (wCode) {
  1903. case IDCANCEL:
  1904. EndDialog(hdlg, TRUE);
  1905. break;
  1906. default:
  1907. return FALSE;
  1908. }
  1909. break;
  1910. default:
  1911. return FALSE;
  1912. }
  1913. return TRUE;
  1914. }
  1915. INT_PTR CALLBACK
  1916. FixesTabDlgProc(
  1917. HWND hdlg,
  1918. UINT uMsg,
  1919. WPARAM wParam,
  1920. LPARAM lParam
  1921. )
  1922. /*++
  1923. LayersDlgProc
  1924. Description: Handle messages for the fixes tab.
  1925. --*/
  1926. {
  1927. int wCode = LOWORD(wParam);
  1928. int wNotifyCode = HIWORD(wParam);
  1929. switch (uMsg) {
  1930. case WM_INITDIALOG:
  1931. if (!HandleFixesDialogInit(hdlg)) {
  1932. EndDialog(g_hDlg, 0);
  1933. }
  1934. break;
  1935. case WM_NOTIFY:
  1936. if (wParam == IDC_SHIMS) {
  1937. HandleShimListNotification(hdlg, lParam);
  1938. }
  1939. break;
  1940. case WM_TIMER:
  1941. if (wParam == ID_COUNT_SHIMS) {
  1942. KillTimer(hdlg, ID_COUNT_SHIMS);
  1943. CountShims(TRUE);
  1944. }
  1945. break;
  1946. case WM_COMMAND:
  1947. switch (wCode) {
  1948. case IDCANCEL:
  1949. EndDialog(hdlg, TRUE);
  1950. break;
  1951. case IDC_CLEAR_SHIMS:
  1952. DeselectAllShims(hdlg);
  1953. break;
  1954. default:
  1955. return FALSE;
  1956. }
  1957. break;
  1958. default:
  1959. return FALSE;
  1960. }
  1961. return TRUE;
  1962. }
  1963. void
  1964. HandleModuleListNotification(
  1965. HWND hdlg,
  1966. LPARAM lParam
  1967. )
  1968. /*++
  1969. HandleModuleListNotification
  1970. Description: Handle all the notifications we care about for the
  1971. shim list.
  1972. --*/
  1973. {
  1974. LPNMHDR pnm = (LPNMHDR)lParam;
  1975. switch (pnm->code) {
  1976. case NM_CLICK:
  1977. {
  1978. LVHITTESTINFO lvhti;
  1979. LVITEM lvi;
  1980. GetCursorPos(&lvhti.pt);
  1981. ScreenToClient(g_hwndShimList, &lvhti.pt);
  1982. ListView_HitTest(g_hwndShimList, &lvhti);
  1983. //
  1984. // If the user clicked on a list view item,
  1985. // enable the Remove button.
  1986. //
  1987. if (lvhti.flags & LVHT_ONITEMLABEL) {
  1988. EnableWindow(GetDlgItem(hdlg, IDC_REMOVE), TRUE);
  1989. }
  1990. break;
  1991. }
  1992. default:
  1993. break;
  1994. }
  1995. }
  1996. void
  1997. HandleShimListNotification(
  1998. HWND hdlg,
  1999. LPARAM lParam
  2000. )
  2001. /*++
  2002. HandleShimListNotification
  2003. Description: Handle all the notifications we care about for the
  2004. shim list.
  2005. --*/
  2006. {
  2007. LPNMHDR pnm = (LPNMHDR)lParam;
  2008. switch (pnm->code) {
  2009. case NM_CLICK:
  2010. {
  2011. LVHITTESTINFO lvhti;
  2012. LVITEM lvi;
  2013. GetCursorPos(&lvhti.pt);
  2014. ScreenToClient(g_hwndShimList, &lvhti.pt);
  2015. ListView_HitTest(g_hwndShimList, &lvhti);
  2016. //
  2017. // If the check box state has changed,
  2018. // toggle the selection. Either way,
  2019. // maintain selection as we go.
  2020. //
  2021. if (lvhti.flags & LVHT_ONITEMSTATEICON) {
  2022. ShimListToggleSelection(lvhti.iItem, uReverse);
  2023. }
  2024. ListView_SetItemState(g_hwndShimList,
  2025. lvhti.iItem,
  2026. LVIS_FOCUSED | LVIS_SELECTED,
  2027. 0x000F);
  2028. SetTimer(hdlg, ID_COUNT_SHIMS, 100, NULL);
  2029. break;
  2030. }
  2031. case NM_DBLCLK:
  2032. {
  2033. LVITEM lvi;
  2034. TCHAR szShimName[MAX_PATH];
  2035. int nItem;
  2036. PFIX pFix;
  2037. nItem = ListView_GetSelectionMark(g_hwndShimList);
  2038. if (-1 == nItem) {
  2039. break;
  2040. }
  2041. lvi.mask = LVIF_PARAM;
  2042. lvi.iItem = nItem;
  2043. ListView_GetItem(g_hwndShimList, &lvi);
  2044. pFix = (PFIX)lvi.lParam;
  2045. // If this is a shim, display the options dialog.
  2046. if (!pFix->bFlag) {
  2047. if (DialogBoxParam(g_hInstance,
  2048. MAKEINTRESOURCE(IDD_OPTIONS),
  2049. hdlg,
  2050. OptionsDlgProc,
  2051. (LPARAM)pFix)) {
  2052. if (NULL != pFix->pszCmdLine) {
  2053. ListView_SetItemText(g_hwndShimList, nItem, 1, _T("X"));
  2054. } else {
  2055. ListView_SetItemText(g_hwndShimList, nItem, 1, _T(""));
  2056. }
  2057. if (NULL != pFix->pModule) {
  2058. ListView_SetItemText(g_hwndShimList, nItem, 2, _T("X"));
  2059. } else {
  2060. ListView_SetItemText(g_hwndShimList, nItem, 2, _T(""));
  2061. }
  2062. }
  2063. } else {
  2064. MessageBeep(MB_ICONEXCLAMATION);
  2065. }
  2066. break;
  2067. }
  2068. case LVN_ITEMCHANGED:
  2069. {
  2070. LPNMLISTVIEW lpnmlv;
  2071. PFIX pFix;
  2072. lpnmlv = (LPNMLISTVIEW)lParam;
  2073. pFix = (PFIX)lpnmlv->lParam;
  2074. //
  2075. // Only change the text if our selection has changed.
  2076. // If we don't do this, the text goes bye-bye when
  2077. // the user clicks the Clear button.
  2078. //
  2079. if ((lpnmlv->uChanged & LVIF_STATE) &&
  2080. (lpnmlv->uNewState & LVIS_SELECTED)) {
  2081. SetDlgItemText(hdlg, IDC_SHIM_DESCRIPTION, pFix->pszDesc);
  2082. ListView_SetSelectionMark(g_hwndShimList, lpnmlv->iItem);
  2083. }
  2084. break;
  2085. }
  2086. default:
  2087. break;
  2088. }
  2089. }
  2090. void
  2091. HandleAttributeTreeNotification(
  2092. HWND hdlg,
  2093. LPARAM lParam
  2094. )
  2095. /*++
  2096. HandleAttributeTreeNotification
  2097. Description: Handle all the notifications we care about for the
  2098. file attributes tree.
  2099. --*/
  2100. {
  2101. LPNMHDR pnm = (LPNMHDR)lParam;
  2102. switch (pnm->code) {
  2103. case NM_CLICK:
  2104. {
  2105. TVHITTESTINFO HitTest;
  2106. HTREEITEM hParentItem;
  2107. GetCursorPos(&HitTest.pt);
  2108. ScreenToClient(g_hwndFilesTree, &HitTest.pt);
  2109. TreeView_HitTest(g_hwndFilesTree, &HitTest);
  2110. if (HitTest.flags & TVHT_ONITEMSTATEICON) {
  2111. FileTreeToggleSelection(HitTest.hItem, uReverse);
  2112. } else if (HitTest.flags & TVHT_ONITEMLABEL) {
  2113. HWND hwndButton;
  2114. HTREEITEM hItem, hRoot;
  2115. hwndButton = GetDlgItem(hdlg, IDC_REMOVE_MATCHING);
  2116. hItem = TreeView_GetParent(g_hwndFilesTree, HitTest.hItem);
  2117. hRoot = TreeView_GetRoot(g_hwndFilesTree);
  2118. //
  2119. // If the selected item has no parent and it's not
  2120. // the root, enable the remove matching button.
  2121. //
  2122. if ((NULL == hItem) && (hRoot != HitTest.hItem)) {
  2123. EnableWindow(hwndButton, TRUE);
  2124. } else {
  2125. EnableWindow(hwndButton, FALSE);
  2126. }
  2127. }
  2128. break;
  2129. }
  2130. case NM_RCLICK:
  2131. {
  2132. TVHITTESTINFO HitTest;
  2133. POINT pt;
  2134. GetCursorPos(&HitTest.pt);
  2135. pt.x = HitTest.pt.x;
  2136. pt.y = HitTest.pt.y;
  2137. ScreenToClient(g_hwndFilesTree, &HitTest.pt);
  2138. TreeView_HitTest(g_hwndFilesTree, &HitTest);
  2139. if (HitTest.flags & TVHT_ONITEMLABEL)
  2140. {
  2141. HTREEITEM hItem, hParentItem;
  2142. TreeView_SelectItem(g_hwndFilesTree, HitTest.hItem);
  2143. //
  2144. // If the selected item has no parent, we assume that a
  2145. // matching file was right-clicked.
  2146. //
  2147. hParentItem = TreeView_GetParent(g_hwndFilesTree, HitTest.hItem);
  2148. if (NULL == hParentItem) {
  2149. DisplayAttrContextMenu(&pt);
  2150. }
  2151. }
  2152. break;
  2153. }
  2154. case TVN_KEYDOWN:
  2155. {
  2156. LPNMTVKEYDOWN lpKeyDown = (LPNMTVKEYDOWN)lParam;
  2157. HTREEITEM hItem;
  2158. if (lpKeyDown->wVKey == VK_SPACE) {
  2159. hItem = TreeView_GetSelection(g_hwndFilesTree);
  2160. if (hItem != NULL) {
  2161. FileTreeToggleSelection(hItem, uReverse);
  2162. }
  2163. } else if (lpKeyDown->wVKey == VK_DELETE) {
  2164. HTREEITEM hParentItem;
  2165. hItem = TreeView_GetSelection(g_hwndFilesTree);
  2166. hParentItem = TreeView_GetParent(g_hwndFilesTree, hItem);
  2167. if (hParentItem == NULL) {
  2168. if (TreeView_GetPrevSibling(g_hwndFilesTree, hItem) != NULL) {
  2169. TreeView_DeleteItem(g_hwndFilesTree, hItem);
  2170. }
  2171. }
  2172. }
  2173. break;
  2174. }
  2175. default:
  2176. break;
  2177. }
  2178. }
  2179. INT_PTR CALLBACK
  2180. QFixAppDlgProc(
  2181. HWND hdlg,
  2182. UINT uMsg,
  2183. WPARAM wParam,
  2184. LPARAM lParam
  2185. )
  2186. /*++
  2187. QFixAppDlgProc
  2188. Description: The dialog proc of QFixApp.
  2189. --*/
  2190. {
  2191. int wCode = LOWORD(wParam);
  2192. int wNotifyCode = HIWORD(wParam);
  2193. switch (uMsg) {
  2194. case WM_INITDIALOG:
  2195. if (!InitMainDialog(hdlg)) {
  2196. EndDialog(hdlg, TRUE);
  2197. }
  2198. break;
  2199. case WM_NOTIFY:
  2200. if (wParam == IDC_SHIMS) {
  2201. HandleShimListNotification(hdlg, lParam);
  2202. } else if (wParam == IDC_ATTRIBUTES) {
  2203. HandleAttributeTreeNotification(hdlg, lParam);
  2204. } else if (wParam == IDC_TAB_FIXES) {
  2205. HandleTabNotification(hdlg, lParam);
  2206. } else if (wParam == IDC_DOWNLOAD_WU) {
  2207. NMHDR* pHdr = (NMHDR*)lParam;
  2208. if (pHdr->code == NM_CLICK || pHdr->code == NM_RETURN) {
  2209. SHELLEXECUTEINFO sei = { 0 };
  2210. sei.cbSize = sizeof(SHELLEXECUTEINFO);
  2211. sei.fMask = SEE_MASK_DOENVSUBST;
  2212. sei.hwnd = hdlg;
  2213. sei.nShow = SW_SHOWNORMAL;
  2214. sei.lpFile = g_fW2K ? g_szW2KUrl : g_szXPUrl;
  2215. ShellExecuteEx(&sei);
  2216. break;
  2217. }
  2218. }
  2219. break;
  2220. case WM_DESTROY:
  2221. {
  2222. DLGHDR* pHdr;
  2223. //
  2224. // Destory the dialogs and remove any misc files.
  2225. //
  2226. pHdr = (DLGHDR*)GetWindowLongPtr(hdlg, DWLP_USER);
  2227. DestroyWindow(pHdr->hDisplay[0]);
  2228. DestroyWindow(pHdr->hDisplay[1]);
  2229. CleanupSupportForApp(g_szShortName);
  2230. break;
  2231. }
  2232. case WM_COMMAND:
  2233. if (wNotifyCode == LBN_SELCHANGE && wCode == IDC_LAYERS) {
  2234. LayerChanged(hdlg);
  2235. break;
  2236. }
  2237. switch (wCode) {
  2238. case IDC_RUN:
  2239. RunTheApp(hdlg);
  2240. break;
  2241. case IDC_BROWSE:
  2242. BrowseForApp(hdlg);
  2243. break;
  2244. case IDC_DETAILS:
  2245. ExpandCollapseDialog(hdlg, !g_bSimpleEdition);
  2246. break;
  2247. case IDC_CREATEFILE:
  2248. CreateSupportForApp(hdlg);
  2249. break;
  2250. case IDC_SHOWXML:
  2251. ShowXML(hdlg);
  2252. break;
  2253. case IDC_ADD_MATCHING:
  2254. PromptAddMatchingFile(hdlg);
  2255. break;
  2256. case IDC_VIEW_LOG:
  2257. ShowShimLog();
  2258. break;
  2259. case IDCANCEL:
  2260. EndDialog(hdlg, TRUE);
  2261. break;
  2262. case IDM_SELECT_ALL:
  2263. SelectAttrsInTree(TRUE);
  2264. break;
  2265. case IDM_CLEAR_ALL:
  2266. SelectAttrsInTree(FALSE);
  2267. break;
  2268. case IDC_REMOVE_MATCHING:
  2269. {
  2270. HTREEITEM hParentItem, hItem;
  2271. TCHAR szError[MAX_PATH];
  2272. hItem = TreeView_GetSelection(g_hwndFilesTree);
  2273. if (NULL == hItem) {
  2274. LoadString(g_hInstance, IDS_NO_SELECTION, szError, MAX_PATH);
  2275. MessageBox(hdlg, szError, g_szAppTitle, MB_ICONEXCLAMATION | MB_OK);
  2276. return TRUE;
  2277. }
  2278. hParentItem = TreeView_GetParent(g_hwndFilesTree, hItem);
  2279. if (hParentItem == NULL) {
  2280. if (TreeView_GetPrevSibling(g_hwndFilesTree, hItem) != NULL) {
  2281. TreeView_DeleteItem(g_hwndFilesTree, hItem);
  2282. EnableWindow(GetDlgItem(hdlg, IDC_REMOVE_MATCHING), FALSE);
  2283. }
  2284. }
  2285. break;
  2286. }
  2287. default:
  2288. return FALSE;
  2289. }
  2290. break;
  2291. default:
  2292. return FALSE;
  2293. }
  2294. return TRUE;
  2295. }
  2296. int WINAPI
  2297. wWinMain(
  2298. HINSTANCE hInst,
  2299. HINSTANCE hInstPrev,
  2300. LPTSTR lpszCmd,
  2301. int swShow
  2302. )
  2303. /*++
  2304. WinMain
  2305. Description: Application entry point.
  2306. --*/
  2307. {
  2308. BOOL fSP2 = FALSE;
  2309. TCHAR szError[MAX_PATH];
  2310. OSVERSIONINFO osvi;
  2311. INITCOMMONCONTROLSEX icex;
  2312. icex.dwSize = sizeof(INITCOMMONCONTROLSEX);
  2313. icex.dwICC = ICC_LISTVIEW_CLASSES | ICC_TREEVIEW_CLASSES | ICC_TAB_CLASSES;
  2314. if (!InitCommonControlsEx(&icex)) {
  2315. InitCommonControls();
  2316. }
  2317. LoadString(g_hInstance, IDS_APP_TITLE, g_szAppTitle, 64);
  2318. LinkWindow_RegisterClass();
  2319. g_hInstance = hInst;
  2320. osvi.dwOSVersionInfoSize = sizeof(osvi);
  2321. GetVersionEx(&osvi);
  2322. //
  2323. // See if they're an administrator - bail if not.
  2324. //
  2325. if (!(IsUserAnAdministrator())) {
  2326. LoadString(g_hInstance, IDS_NOT_ADMIN, szError, MAX_PATH);
  2327. MessageBox(NULL, szError, g_szAppTitle, MB_ICONERROR | MB_OK);
  2328. return 0;
  2329. }
  2330. //
  2331. // See if we're running on Windows 2000.
  2332. //
  2333. if ((osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 0)) {
  2334. g_fW2K = TRUE;
  2335. }
  2336. // See if we're running on SP2
  2337. if (!(_tcscmp(osvi.szCSDVersion, _T("Service Pack 2")))) {
  2338. fSP2 = TRUE;
  2339. }
  2340. //
  2341. // Attempt to locate the SDB in the AppPatch directory.
  2342. //
  2343. if (!CheckForSDB()) {
  2344. if (g_fW2K) {
  2345. DialogBoxParam(hInst,
  2346. MAKEINTRESOURCE(IDD_MSGBOX_SDB),
  2347. GetDesktopWindow(),
  2348. MsgBoxDlgProc,
  2349. (LPARAM)1);
  2350. return 0;
  2351. } else {
  2352. LoadString(g_hInstance, IDS_XP_NO_SDB, szError, MAX_PATH);
  2353. MessageBox(GetDesktopWindow(), szError, g_szAppTitle, MB_OK | MB_ICONEXCLAMATION);
  2354. return 0;
  2355. }
  2356. }
  2357. //
  2358. // If this is SP2, and the SDB is older, bail out.
  2359. //
  2360. if (fSP2) {
  2361. if (IsSDBFromSP2()) {
  2362. DialogBoxParam(hInst,
  2363. MAKEINTRESOURCE(IDD_MSGBOX_SP2),
  2364. GetDesktopWindow(),
  2365. MsgBoxDlgProc,
  2366. (LPARAM)0);
  2367. return 0;
  2368. }
  2369. }
  2370. LogMsg(_T("[WinMain] Command line \"%s\"\n"), lpszCmd);
  2371. //
  2372. // Check for command line options.
  2373. //
  2374. if (*lpszCmd == _T('a') || *lpszCmd == _T('A')) {
  2375. g_bAllShims = TRUE;
  2376. }
  2377. DialogBox(hInst,
  2378. MAKEINTRESOURCE(IDD_DIALOG),
  2379. GetDesktopWindow(),
  2380. QFixAppDlgProc);
  2381. return 1;
  2382. }