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.

2842 lines
86 KiB

  1. //#define __DEBUG2
  2. //This var. is TRUE if we want the TVN_SELCHANGED to be processed process after a NM_RCLCK msg,
  3. //this is FALSE when we send Tree_SelectItem(, NULL)
  4. #include "compatadmin.h"
  5. #include "dbviewer.h"
  6. #include "xmldialog.h"
  7. #ifndef __CAPPHELPWIZARD_H
  8. #include "CAppHelpWizard.h"
  9. #endif
  10. #include "customlayer.h"
  11. //#define __DEBUG
  12. HSDB g_hSDB = NULL;
  13. WNDPROC g_OldTreeProc = NULL;
  14. extern HWND g_hWndLastFocus;
  15. extern BOOL g_DEBUG;
  16. BOOL g_do_notProcess = FALSE;
  17. LRESULT CALLBACK TreeViewProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  18. {
  19. switch ( uMsg ) {
  20. case WM_KEYDOWN:
  21. {
  22. if ( VK_TAB == wParam ) {
  23. NMKEY Key;
  24. Key.hdr.hwndFrom = hWnd;
  25. Key.hdr.idFrom = 0;
  26. Key.hdr.code = NM_KEYDOWN;
  27. Key.nVKey = VK_TAB;
  28. SendMessage(GetParent(hWnd),WM_NOTIFY,0,(LPARAM) &Key);
  29. }
  30. }
  31. break;
  32. case WM_KILLFOCUS:
  33. g_hWndLastFocus = hWnd;
  34. break;
  35. }
  36. return CallWindowProc(g_OldTreeProc,hWnd,uMsg,wParam,lParam);
  37. }
  38. CDBView::CDBView()
  39. {
  40. m_pCurrentRecord = NULL;
  41. m_pListRecord = NULL;
  42. m_uContext = -1;
  43. m_hSelectedItem = NULL;
  44. m_bDrag = FALSE;
  45. }
  46. BOOL CDBView::Initialize(void)
  47. {
  48. if ( !Create( TEXT("DBViewClass"),
  49. TEXT("This is the first window in the DBViewer::Initialize"),
  50. 0,0,
  51. 10,10,
  52. &g_theApp,
  53. (HMENU)VIEW_DATABASE,
  54. 0,
  55. WS_CHILD | WS_CLIPSIBLINGS | WS_CLIPCHILDREN) ) {
  56. return FALSE;
  57. }
  58. // These two windows are child of the window created above. So now we have 3 generations.....
  59. if ( ! m_GlobalList.Create(TEXT("CListView"),
  60. TEXT("Microsoft Application Database"),
  61. 0,0,10,10,
  62. this,
  63. 0,
  64. 0,
  65. WS_CHILD | WS_VISIBLE | WS_CLIPCHILDREN | WS_CLIPSIBLINGS | WS_VISIBLE | WS_VSCROLL | WS_BORDER)
  66. ) return FALSE;
  67. if ( !m_LocalList.Create(TEXT("CListView"),
  68. TEXT("Untitled.SDB"),
  69. 0,0,10,10,
  70. this,
  71. 0,
  72. 0,
  73. WS_CHILD | WS_VISIBLE | WS_CLIPCHILDREN | WS_CLIPSIBLINGS | WS_VISIBLE | WS_VSCROLL | WS_BORDER)
  74. )
  75. return FALSE;
  76. m_hMenu = LoadMenu(g_hInstance,MAKEINTRESOURCE(IDR_DBVIEWER));
  77. // Create the listview for displaying the applications in the database.
  78. m_uListSize = 250;
  79. g_theApp.ReadReg(TEXT("DBVIEW_SIZE"),&m_uListSize,sizeof(UINT));
  80. RECT rRect;
  81. GetClientRect(g_theApp.m_hWnd,&rRect);
  82. m_uListHeight = rRect.bottom / 2 -2 ;
  83. g_theApp.ReadReg(TEXT("DBVIEW_HEIGHT"),&m_uListHeight,sizeof(UINT));
  84. m_hListView = CreateWindowEx( 0,
  85. WC_LISTVIEW,
  86. TEXT(""),
  87. WS_CHILD |/* WS_VISIBLE |*/ WS_BORDER | WS_CLIPSIBLINGS | LVS_REPORT | LVS_OWNERDRAWFIXED,
  88. 0,0,
  89. 10,10,
  90. m_hWnd,
  91. NULL,
  92. g_hInstance,
  93. NULL);
  94. // Subclass the window to prevent paint flashing.
  95. LONG uStyle = ListView_GetExtendedListViewStyle(m_hListView);
  96. ListView_SetExtendedListViewStyle(m_hListView,LVS_EX_FULLROWSELECT | uStyle);
  97. CoInitialize(NULL);
  98. // Create the treeview for showing the files affected by the application
  99. m_hTreeView = CreateWindowEx( 0,
  100. WC_TREEVIEW,
  101. TEXT(""),
  102. WS_CHILD | WS_VISIBLE | WS_BORDER | WS_CLIPSIBLINGS | TVS_HASLINES | TVS_LINESATROOT | TVS_HASBUTTONS | TVS_INFOTIP,
  103. 0,0,
  104. 10,10,
  105. m_hWnd,
  106. NULL,
  107. g_hInstance,
  108. NULL);
  109. //PREFIX
  110. if ( m_hTreeView == NULL ) {
  111. return FALSE;
  112. }
  113. g_OldTreeProc = (WNDPROC) GetWindowLongPtr(m_hTreeView,GWLP_WNDPROC);
  114. SetWindowLongPtr(m_hTreeView,GWLP_WNDPROC,(LONG_PTR) TreeViewProc);
  115. m_hImageList = ImageList_Create(16,15,ILC_COLORDDB | ILC_MASK,24,1);
  116. ImageList_Add(m_hImageList,LoadBitmap(g_hInstance,MAKEINTRESOURCE(IDR_MAINTOOLBAR)),NULL);
  117. ImageList_AddIcon(m_hImageList,LoadIcon(g_hInstance,MAKEINTRESOURCE(IDI_FIXES)));
  118. ImageList_AddIcon(m_hImageList,LoadIcon(g_hInstance,MAKEINTRESOURCE(IDI_HELP)));
  119. ImageList_AddIcon(m_hImageList,LoadIcon(g_hInstance,MAKEINTRESOURCE(IDI_MODE)));
  120. ZeroMemory(&m_uImageRedirector,sizeof(m_uImageRedirector));
  121. TreeView_SetImageList(m_hTreeView,m_hImageList,TVSIL_NORMAL);
  122. // Create the headers for the report list view.
  123. LV_COLUMN Col;
  124. Col.mask = LVCF_TEXT | LVCF_WIDTH;
  125. Col.pszText = TEXT("Application");
  126. Col.cchTextMax = lstrlen(Col.pszText);
  127. Col.cx = m_uListSize;
  128. ListView_InsertColumn(m_hListView,0,&Col);
  129. /*
  130. Col.pszText = "Layer";
  131. Col.cchTextMax = lstrlen(Col.pszText);
  132. Col.cx = (m_uListSize - Col.cx)-1;
  133. ListView_InsertColumn(m_hListView,1,&Col);
  134. */
  135. /*
  136. LOGBRUSH Brush;
  137. Brush.lbStyle = BS_SOLID;
  138. Brush.lbColor = RGB(235,235,235);
  139. m_hFillBrush = CreateBrushIndirect(&Brush);
  140. */
  141. MENUITEMINFO Info;
  142. Info.cbSize = sizeof(MENUITEMINFO);
  143. Info.fMask = MIIM_STATE;
  144. Info.fState = MF_CHECKED;
  145. SetMenuItemInfo(m_hMenu,ID_VIEW_VIEWSHIMFIXES,MF_BYCOMMAND,&Info);
  146. SetMenuItemInfo(m_hMenu,ID_VIEW_VIEWLAYERFIXES,MF_BYCOMMAND,&Info);
  147. SetMenuItemInfo(m_hMenu,ID_VIEW_VIEWAPPHELPENTRIES,MF_BYCOMMAND,&Info);
  148. SetMenuItemInfo(m_hMenu,ID_VIEW_VIEWPATCHES,MF_BYCOMMAND,&Info);
  149. SyncMenu();
  150. return TRUE;
  151. }
  152. void CDBView::msgClose(void)
  153. {
  154. //g_theApp.WriteReg("DBVIEW_HEIGHT",REG_DWORD,&m_uListHeight,sizeof(UINT));
  155. //g_theApp.WriteReg("DBVIEW_SIZE",REG_DWORD,&m_uListSize,sizeof(UINT));
  156. }
  157. BOOL CDBView::Activate(BOOL fNewCreate)
  158. {
  159. if ( g_hWndLastFocus != NULL ) SetFocus(g_hWndLastFocus );
  160. else SetFocus(m_LocalList.m_hWnd);
  161. g_theApp.AddToolbarButton( IMAGE_SHIMWIZARD,
  162. DBCMD_FIXWIZARD,
  163. (NULL == CDatabase::m_pDB) ? 0:TBSTATE_ENABLED,
  164. TBSTYLE_BUTTON);
  165. g_theApp.AddToolbarButton( 0,
  166. 0,
  167. 0,
  168. TBSTYLE_SEP);
  169. g_theApp.AddToolbarButton( IMAGE_DISABLEUSER,
  170. DBCMD_DISABLEUSER,
  171. (NULL == CDatabase::m_pDB) ? 0:TBSTATE_ENABLED,
  172. TBSTYLE_BUTTON);
  173. g_theApp.AddToolbarButton( IMAGE_DISABLEGLOBAL,
  174. DBCMD_DISABLEGLOBAL,
  175. (NULL == CDatabase::m_pDB) ? 0:TBSTATE_ENABLED,
  176. TBSTYLE_BUTTON);
  177. /*
  178. g_theApp.AddToolbarButton( IMAGE_PROPERTIES,
  179. DBCMD_PROPERTIES,
  180. TBSTATE_ENABLED,
  181. TBSTYLE_BUTTON);
  182. */
  183. g_theApp.AddToolbarButton( IMAGE_DELETE,
  184. DBCMD_DELETE,
  185. 0,
  186. TBSTYLE_BUTTON);
  187. g_theApp.AddToolbarButton( 0,
  188. 0,
  189. 0,
  190. TBSTYLE_SEP);
  191. g_theApp.AddToolbarButton( IMAGE_VIEWSHIM,
  192. DBCMD_VIEWSHIMS,
  193. TBSTATE_ENABLED,
  194. TBSTYLE_BUTTON | TBSTYLE_CHECK);
  195. g_theApp.AddToolbarButton( IMAGE_VIEWHELP,
  196. DBCMD_VIEWAPPHELP,
  197. TBSTATE_ENABLED,
  198. TBSTYLE_BUTTON | TBSTYLE_CHECK);
  199. g_theApp.AddToolbarButton( IMAGE_VIEWPATCH,
  200. DBCMD_VIEWPATCH,
  201. TBSTATE_ENABLED,
  202. TBSTYLE_BUTTON | TBSTYLE_CHECK);
  203. g_theApp.AddToolbarButton( IMAGE_SHOWLAYERS,
  204. DBCMD_VIEWLAYERS,
  205. TBSTATE_ENABLED,
  206. TBSTYLE_BUTTON | TBSTYLE_CHECK);
  207. g_theApp.AddToolbarButton( IMAGE_VIEWDISABLED,
  208. DBCMD_VIEWDISABLED,
  209. TBSTATE_ENABLED,
  210. TBSTYLE_BUTTON | TBSTYLE_CHECK);
  211. /*
  212. g_theApp.AddToolbarButton( IMAGE_VIEWGLOBAL,
  213. DBCMD_VIEWGLOBAL,
  214. TBSTATE_ENABLED,
  215. TBSTYLE_BUTTON | TBSTYLE_CHECK);
  216. */
  217. //SendMessage(g_theApp.m_hToolBar,TB_CHECKBUTTON,DBCMD_VIEWSHIMS,MAKELONG(TRUE,0));
  218. //SendMessage(g_theApp.m_hToolBar,TB_CHECKBUTTON,DBCMD_VIEWAPPHELP,MAKELONG(TRUE,0));
  219. //SendMessage(g_theApp.m_hToolBar,TB_CHECKBUTTON,DBCMD_VIEWPATCH,MAKELONG(TRUE,0));
  220. //SendMessage(g_theApp.m_hToolBar,TB_CHECKBUTTON,DBCMD_VIEWLAYERS,MAKELONG(TRUE,0));
  221. SyncStates(ID_VIEW_VIEWSHIMFIXES,DBCMD_VIEWSHIMS,TRUE,FALSE);
  222. SyncStates(ID_VIEW_VIEWLAYERFIXES,DBCMD_VIEWLAYERS,TRUE,FALSE);
  223. SyncStates(ID_VIEW_SHOWDISABLEDENTRIES,DBCMD_VIEWDISABLED,TRUE,FALSE);
  224. SyncStates(ID_VIEW_VIEWPATCHES,DBCMD_VIEWPATCH,TRUE,FALSE);
  225. SyncStates(ID_VIEW_VIEWAPPHELPENTRIES,DBCMD_VIEWAPPHELP,TRUE,FALSE);
  226. Update(fNewCreate);
  227. return TRUE;
  228. }
  229. int CALLBACK lvSortAscend(LPARAM p1, LPARAM p2, LPARAM p3)
  230. {
  231. PDBRECORD pRecord1 = (PDBRECORD) p1;
  232. PDBRECORD pRecord2 = (PDBRECORD) p2;
  233. return lstrcmpi(pRecord1->szAppName,pRecord2->szAppName);
  234. }
  235. void CDBView::Update(BOOL fNewCreate)
  236. {
  237. BOOL bShowShims = (MF_CHECKED == GetMenuState(m_hMenu,ID_VIEW_VIEWSHIMFIXES,MF_BYCOMMAND)) ? TRUE:FALSE;
  238. BOOL bShowApphelp = (MF_CHECKED == GetMenuState(m_hMenu,ID_VIEW_VIEWAPPHELPENTRIES,MF_BYCOMMAND)) ? TRUE:FALSE;
  239. BOOL bShowPatch = (MF_CHECKED == GetMenuState(m_hMenu,ID_VIEW_VIEWPATCHES,MF_BYCOMMAND)) ? TRUE:FALSE;
  240. BOOL bShowLayers = (MF_CHECKED == GetMenuState(m_hMenu,ID_VIEW_VIEWLAYERFIXES,MF_BYCOMMAND)) ? TRUE:FALSE;
  241. BOOL bShowDisabledOnly = (MF_CHECKED == GetMenuState(m_hMenu,ID_VIEW_SHOWDISABLEDENTRIES,MF_BYCOMMAND)) ? TRUE:FALSE;
  242. TCHAR szTemp[MAX_PATH_BUFFSIZE];
  243. CSTRING szName;
  244. HWND hWnd = GetFocus();
  245. //The GetFocus function retrieves the handle to the window that has the
  246. //keyboard focus, if the window is attached to the calling thread's message queue.
  247. if ( m_GlobalList.m_hWnd != hWnd && m_hTreeView != hWnd && m_LocalList.m_hWnd != hWnd ) {
  248. SetFocus(m_GlobalList.m_hWnd);
  249. }
  250. if ( g_theApp.GetDBLocal().m_szCurrentDatabase.Length() > 0 )
  251. szName = g_theApp.GetDBLocal().m_szCurrentDatabase;//Name of the SDB File
  252. else
  253. szName = TEXT("Untitled.SDB");
  254. if ( szName.Length() == 0 ) {
  255. MEM_ERR;
  256. return;
  257. }
  258. szName.ShortFilename();
  259. _snwprintf(szTemp,sizeof(szTemp)/sizeof(TCHAR), TEXT("%s (%s)"),(LPCTSTR)szName,(LPCTSTR)g_theApp.GetDBLocal().m_DBName);
  260. //First the name of the SDB, then the name of the database.
  261. SetWindowText(m_LocalList.m_hWnd,szTemp);
  262. if ( NULL == g_theApp.GetDBLocal().m_pDB )
  263. //K The database is closed, that is we are working on the system DB
  264. {
  265. g_theApp.SetButtonState(DBCMD_FIXWIZARD,0);
  266. }
  267. g_theApp.SetButtonState(DBCMD_FIXWIZARD,TBSTATE_ENABLED);
  268. // Enumerate the applications
  269. //SendMessage(m_hListView,WM_SETREDRAW,FALSE,0);
  270. SendMessage(m_GlobalList.m_hWnd,WM_SETREDRAW,FALSE,0);
  271. if ( fNewCreate ) {
  272. m_GlobalList.RemoveAllEntries();
  273. m_LocalList.RemoveAllEntries();
  274. }
  275. // Clear and update the list view with current information.
  276. PDBRECORD pWalk = g_theApp.GetDBGlobal().m_pRecordHead;
  277. PDBRECORD pWalk2 = g_theApp.GetDBGlobal().m_pRecordHead;
  278. int nItem = 0;
  279. for (int iLoop = 0 ; iLoop <= 1 ; ++iLoop) {
  280. while ( NULL != pWalk2 && fNewCreate )//For all exes
  281. //Loop control by pWalk2
  282. {
  283. BOOL bShow = FALSE;
  284. pWalk = pWalk2;
  285. while ( NULL != pWalk )
  286. //Follows all exes of the same application as that of the pWalk2 exe
  287. // including pWalk2, with the help of the pWalk->pDup
  288. {
  289. //LV_ITEM Item;
  290. PDBENTRY pEntry = pWalk->pEntries;
  291. if ( 0 != pWalk->szLayerName.Length() && bShowLayers )
  292. bShow = TRUE;
  293. while ( NULL != pEntry && !bShow ) {// Not for layers
  294. /*
  295. Note that both Shims and Patches have the same uTupe as
  296. ENTRY_SHIM and they are distinguished by only the SHIMDESC.bSim
  297. */
  298. if ( ENTRY_SHIM == pEntry->uType ) {
  299. PSHIMENTRY pShim = (PSHIMENTRY) pEntry;
  300. if ( NULL != pShim->pDesc ) {
  301. if ( bShowShims && pShim->pDesc->bShim )//This is a shim and not Patch
  302. bShow = TRUE;
  303. if ( bShowPatch && !pShim->pDesc->bShim )//Patch
  304. bShow = TRUE;
  305. } else
  306. #ifdef __DEBUG
  307. __asm int 3;//Trap to debugger.
  308. #endif
  309. ;
  310. }
  311. if ( ENTRY_APPHELP == pEntry->uType && bShowApphelp )
  312. bShow = TRUE;
  313. pEntry = pEntry->pNext;
  314. }
  315. if ( bShow ) {
  316. // Determine if we're showing disabled only.
  317. /* This "if" condition is TRUE then it means that the entry is enabled but we
  318. are interested in viwing only "disabled entries".
  319. So we skip this EXE entry and look for other exes/entries in the same
  320. application as this one, hoping to find one that is disabled.
  321. So that this application can be included in the list of
  322. applications to be shown
  323. */
  324. if ( 0 == pWalk->dwUserFlags && 0 == pWalk->dwGlobalFlags && bShowDisabledOnly ) {
  325. bShow = FALSE;
  326. pWalk = pWalk->pDup;
  327. continue;//Go to next file of the same application
  328. }
  329. break;
  330. }
  331. pWalk = pWalk->pDup;//Go to next file of the same application, bShow was FALSE
  332. }//while (NULL != pWalk)
  333. if ( bShow ) {
  334. if ( pWalk2->bGlobal )
  335. m_GlobalList.AddEntry(pWalk2->szAppName,0,pWalk2);
  336. else
  337. m_LocalList.AddEntry(pWalk2->szAppName,0,pWalk2);
  338. }
  339. pWalk2 = pWalk2->pNext;// Go to the next exe.
  340. }//while (NULL != pWalk2 && fNewCreate)
  341. pWalk = g_theApp.GetDBLocal().m_pRecordHead;
  342. pWalk2 = g_theApp.GetDBLocal().m_pRecordHead;
  343. } //for
  344. //ListView_SortItems(m_hListView,lvSortAscend,0);
  345. // Update the list view
  346. //SendMessage(m_hListView,WM_SETREDRAW,TRUE,0);
  347. //UpdateWindow(m_hListView);
  348. SendMessage(m_GlobalList.m_hWnd,WM_SETREDRAW,TRUE,0);
  349. m_GlobalList.Refresh();
  350. m_LocalList.Refresh();
  351. }
  352. void CDBView::msgResize(UINT uWidth, UINT uHeight)
  353. {
  354. //MoveWindow(m_hListView,0,0,m_uListSize,uHeight/2,TRUE);
  355. MoveWindow(m_GlobalList.m_hWnd,0,0,m_uListSize,m_uListHeight,TRUE);
  356. MoveWindow(m_LocalList.m_hWnd,0,m_uListHeight + SLIDER_WIDTH,m_uListSize,(uHeight - m_uListHeight) - SLIDER_WIDTH,TRUE);
  357. MoveWindow(m_hTreeView,m_uListSize + SLIDER_WIDTH,0,uWidth - m_uListSize,uHeight,TRUE);
  358. //InvalidateRect(m_hListView,NULL,TRUE);
  359. //UpdateWindow(m_hListView);
  360. UpdateWindow(m_hTreeView);
  361. Refresh();
  362. }
  363. void CDBView::RefreshTree(void)
  364. {
  365. SendMessage(m_hTreeView,WM_SETREDRAW,FALSE,0);
  366. TreeView_DeleteAllItems(m_hTreeView);
  367. PDBRECORD pRecord = m_pListRecord;
  368. while ( NULL != pRecord ) {
  369. AddRecordToTree(pRecord);
  370. pRecord = pRecord->pDup;
  371. }
  372. SendMessage(m_hTreeView,WM_SETREDRAW,TRUE,0);
  373. SyncMenu();
  374. }
  375. void CDBView::msgCommand(UINT uID, HWND hSender)
  376. {
  377. switch ( uID ) {
  378. case ID_DATABASE_CHANGEDATABASENAME:
  379. {
  380. g_theApp.GetDBLocal().ChangeDatabaseName();
  381. m_LocalList.Refresh();
  382. }
  383. break;
  384. case ID_FILE_EXPORTXML:
  385. case ID_DATABASE_GENERATEXML:
  386. {
  387. CXMLDialog XML;
  388. XML.BeginXMLView(g_theApp.GetDBLocal().m_pRecordHead,m_hWnd,TRUE,TRUE,TRUE,TRUE,FALSE);
  389. }
  390. break;
  391. case ID_EDIT_ADDMATCHINGINFORMATION:
  392. case ID_NA2_ADDMATCHINGINFORMATION:
  393. {
  394. CSTRING szFilename;
  395. if (m_pCurrentRecord == NULL) {
  396. MessageBox(this->m_hWnd, TEXT("Please select a file for the specified operation\nYou might need to re-select the application on the left first."), TEXT("CompatAdmin"),MB_ICONWARNING);
  397. break;
  398. }
  399. if ( g_theApp.GetFilename(TEXT("Find matching file"),TEXT("All files (*.*)\0*.*\0\0"),TEXT(""),TEXT(""),OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST,TRUE,szFilename) ) {
  400. CShimWizard Wiz;
  401. PMATCHENTRY pEntry = new MATCHENTRY;
  402. if ( pEntry == NULL ) {
  403. MEM_ERR;
  404. break;
  405. }
  406. if (m_pCurrentRecord == NULL) {
  407. MessageBox(this->m_hWnd, TEXT("Please select a file for the specified operation\nYou might need to re-select the application on the left first."), TEXT("Compatadmin"),MB_ICONWARNING);
  408. break;
  409. }
  410. PDBENTRY pWalk = m_pCurrentRecord->pEntries;
  411. PMATCHENTRY pSrc = NULL;
  412. CSTRING szCheck = szFilename;
  413. szCheck.ShortFilename();
  414. while ( NULL != pWalk ) {
  415. if ( ENTRY_MATCH == pWalk->uType ) {
  416. PMATCHENTRY pTest = (PMATCHENTRY) pWalk;
  417. CSTRING szShort = pTest->szMatchName;
  418. szShort.ShortFilename();
  419. if ( pTest->szMatchName == TEXT("*") )
  420. pSrc = pTest;
  421. if ( szShort == szCheck ) {
  422. MessageBox(m_hWnd,TEXT("This file is already being used for matching information. To update, please remove and re-add it."),TEXT("File matching error"),MB_OK);
  423. return;
  424. }
  425. }
  426. pWalk = pWalk->pNext;
  427. }
  428. //BUG: NULL pSrc
  429. //if (pSrc->szFullName.Length() == 0)
  430. if ( (pSrc->szFullName.Length() == 0) ) {
  431. CSTRING szSrc;
  432. MessageBox(m_hWnd,TEXT("In order to properly resolve the relative path of the file to be matched, the source executable must be specified.\n\nThis next step will ask for the source executable location."),TEXT("Locate source executable"),MB_ICONWARNING);
  433. if ( g_theApp.GetFilename(TEXT("Find source executable"),TEXT("All files (*.*)\0*.*\0\0"),TEXT(""),TEXT(""),OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST,TRUE,szSrc) ) {
  434. szCheck = szSrc;
  435. szCheck.ShortFilename();
  436. if ( szCheck == m_pCurrentRecord->szEXEName )
  437. pSrc->szFullName = szSrc;
  438. else {
  439. MessageBox(m_hWnd,TEXT("The source executable must have the same name as file to be fixed"),TEXT("Source file error"),MB_ICONERROR);
  440. break;
  441. }
  442. } else
  443. break;
  444. }
  445. // BUGBUG: THIS SUCKS. Move GetFileAttributes() et al to someplace
  446. // more utility oriented.. like CDatabase or something.
  447. if ( NULL != pEntry ) {
  448. ZeroMemory(pEntry,sizeof(MATCHENTRY));
  449. HANDLE hFile = CreateFile((LPCTSTR) szFilename,GENERIC_READ,0,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL);
  450. if ( INVALID_HANDLE_VALUE != hFile ) {
  451. pEntry->dwSize = GetFileSize(hFile,NULL);
  452. CloseHandle(hFile);
  453. }
  454. pEntry->Entry.uType = ENTRY_MATCH;
  455. pEntry->Entry.uIconID = 0;
  456. pEntry->szFullName = szFilename;
  457. if (szFilename.RelativeFile(pSrc->szFullName) == FALSE) {
  458. //
  459. //The matching file is not on the same drive as the matching file
  460. //
  461. MessageBox( NULL,
  462. TEXT("The matching file and the matched file are not on the same drive."),
  463. TEXT("Matching Error"),
  464. MB_ICONWARNING
  465. );
  466. break;
  467. }
  468. pEntry->szMatchName = szFilename;
  469. Wiz.GetFileAttributes(pEntry);
  470. // Take this file and add it to the current record.
  471. // Insert at the end
  472. PDBENTRY pWalk = m_pCurrentRecord->pEntries;
  473. PDBENTRY pHold = NULL;
  474. while ( NULL != pWalk ) {
  475. pHold = pWalk;
  476. pWalk = pWalk->pNext;
  477. }
  478. if ( pHold != NULL ) {
  479. pHold->pNext = (PDBENTRY) pEntry;
  480. }
  481. pEntry->Entry.pNext = NULL;
  482. // Update the tree.
  483. RefreshTree();
  484. g_theApp.GetDBLocal().m_bDirty = TRUE;
  485. g_theApp.UpdateView(TRUE);
  486. }
  487. }
  488. }//case ID_NA2_ADDMATCHINGINFORMATION:
  489. break;
  490. case ID_DATABASE_REMOVEENTRY:
  491. case ID_NA_REMOVEANENTRY:
  492. {
  493. HTREEITEM hParent = TreeView_GetParent(m_hTreeView,m_hSelectedItem);
  494. while ( NULL != hParent ) {
  495. HTREEITEM hNew = TreeView_GetParent(m_hTreeView,hParent);
  496. if ( NULL != hNew )
  497. hParent = hNew;
  498. else
  499. break;
  500. }
  501. //
  502. //hParent is the item whose parent is NULL
  503. //
  504. if ( NULL == hParent )
  505. hParent = m_hSelectedItem;
  506. DeleteDBWithTree(hParent);
  507. }
  508. break;
  509. case ID_EDIT_REMOVEMATCHINGINFORMATION:
  510. case ID_NA2_REMOVEMATCHINGINFORMATION:
  511. {
  512. DeleteDBWithTree(m_hSelectedItem);
  513. }
  514. break;
  515. case ID_DATABASE_DEFINECUSTOMLAYER:
  516. {
  517. CCustomLayer Layer;
  518. HWND hWnd = GetFocus();
  519. if ( Layer.AddCustomLayer() ) {
  520. g_theApp.GetDBLocal().m_bDirty = TRUE;
  521. g_theApp.UpdateView(TRUE);
  522. SetFocus(hWnd);
  523. SyncMenu();
  524. }
  525. }
  526. break;
  527. case ID_DATABASE_EDITCUSTOMCOMPATIBILITYMODE:
  528. {
  529. CCustomLayer Layer;
  530. if ( Layer.EditCustomLayer() ) {
  531. g_theApp.GetDBLocal().m_bDirty = TRUE;
  532. g_theApp.UpdateView(TRUE);
  533. }
  534. }
  535. break;
  536. case ID_DATABASE_REMOVECUSTOMCOMPATIBILITYMODE:
  537. {
  538. CCustomLayer Layer;
  539. HWND hWnd = GetFocus();
  540. if ( Layer.RemoveCustomLayer() ) {
  541. g_theApp.GetDBLocal().m_bDirty = TRUE;
  542. g_theApp.UpdateView(TRUE);
  543. SetFocus(hWnd);
  544. SyncMenu();
  545. }
  546. }
  547. break;
  548. case DBCMD_VIEWSHIMS:
  549. SyncStates(ID_VIEW_VIEWSHIMFIXES,DBCMD_VIEWSHIMS,TRUE,FALSE);
  550. Update();
  551. break;
  552. case DBCMD_VIEWDISABLED:
  553. SyncStates(ID_VIEW_SHOWDISABLEDENTRIES,DBCMD_VIEWDISABLED,TRUE,FALSE);
  554. Update();
  555. break;
  556. case ID_VIEW_VIEWSHIMFIXES:
  557. SyncStates(ID_VIEW_VIEWSHIMFIXES,DBCMD_VIEWSHIMS,FALSE,TRUE);
  558. Update();
  559. break;
  560. case DBCMD_VIEWPATCH:
  561. SyncStates(ID_VIEW_VIEWPATCHES,DBCMD_VIEWPATCH,TRUE,FALSE);
  562. Update();
  563. break;
  564. case DBCMD_VIEWLAYERS:
  565. SyncStates(ID_VIEW_VIEWLAYERFIXES,DBCMD_VIEWLAYERS,TRUE,FALSE);
  566. Update();
  567. break;
  568. case DBCMD_VIEWAPPHELP:
  569. SyncStates(ID_VIEW_VIEWAPPHELPENTRIES,DBCMD_VIEWAPPHELP,TRUE,FALSE);
  570. Update();
  571. break;
  572. case ID_VIEW_VIEWAPPHELPENTRIES:
  573. SyncStates(ID_VIEW_VIEWAPPHELPENTRIES,DBCMD_VIEWAPPHELP,FALSE,TRUE);
  574. Update();
  575. break;
  576. case ID_VIEW_VIEWLAYERFIXES:
  577. SyncStates(ID_VIEW_VIEWLAYERFIXES,DBCMD_VIEWLAYERS,FALSE,TRUE);
  578. Update();
  579. break;
  580. case ID_VIEW_VIEWPATCHES:
  581. SyncStates(ID_VIEW_VIEWPATCHES,DBCMD_VIEWPATCH,FALSE,TRUE);
  582. Update();
  583. break;
  584. case ID_VIEW_SHOWDISABLEDENTRIES:
  585. SyncStates(ID_VIEW_SHOWDISABLEDENTRIES,DBCMD_VIEWDISABLED,FALSE,TRUE);
  586. Update();
  587. break;
  588. case ID_TEST_TESTRUN:
  589. case ID_TESTRUN:
  590. {
  591. HWND hwndFocus = GetFocus();
  592. if ( NULL != m_pCurrentRecord )
  593. g_theApp.TestRun(m_pCurrentRecord,NULL,NULL,g_theApp.m_hWnd);
  594. SetFocus(hwndFocus);
  595. }
  596. break;
  597. case ID_VIEWXML:
  598. {
  599. CXMLDialog XML;
  600. if ( NULL != m_pCurrentRecord )
  601. XML.BeginXMLView(m_pCurrentRecord,m_hWnd,FALSE);
  602. else
  603. XML.BeginXMLView(m_pListRecord,m_hWnd,TRUE);
  604. }
  605. break;
  606. case ID_DATABASE_CREATENEWAPPHELPMESSAGE:
  607. {
  608. CAppHelpWizard wizAppHelp;
  609. if ( wizAppHelp.BeginWizard(m_hWnd) ) {
  610. g_theApp.GetDBLocal().m_bDirty = TRUE;
  611. g_theApp.UpdateView(TRUE);
  612. Update();
  613. }
  614. break;
  615. }
  616. case ID_ADDENTRY:
  617. case ID_DATABASE_ADDANENTRY:
  618. case DBCMD_FIXWIZARD:
  619. {
  620. CShimWizard Wiz;
  621. if ( Wiz.BeginWizard(m_hWnd) ) {
  622. g_theApp.GetDBLocal().m_bDirty = TRUE;
  623. g_theApp.UpdateView(TRUE);
  624. Update();
  625. }
  626. }
  627. break;
  628. case ID_EDIT_ENABLEDISABLEGLOBALLY:
  629. case ID_DISABLEGLOBALLY:
  630. case DBCMD_DISABLEGLOBAL:
  631. {
  632. if ( NULL == m_pCurrentRecord )
  633. break;
  634. //DWORD dwFlags = DialogBoxParam(g_hInstance,MAKEINTRESOURCE(IDD_DISABLE),m_hWnd,DisableDialog,(LPARAM) m_pCurrentRecord->dwGlobalFlags);
  635. DWORD dwFlags = !m_pCurrentRecord->dwGlobalFlags;
  636. //if (dwFlags != m_pCurrentRecord->dwGlobalFlags)
  637. //{
  638. // Save new flags
  639. m_pCurrentRecord->dwGlobalFlags = dwFlags;
  640. // Update the registry
  641. CDatabase::SetEntryFlags(HKEY_LOCAL_MACHINE,m_pCurrentRecord->guidID,dwFlags);
  642. // Refresh tree view
  643. SendMessage(m_hTreeView,WM_SETREDRAW,FALSE,0);
  644. PDBRECORD pHoldCurrent = m_pCurrentRecord;
  645. TreeView_DeleteAllItems(m_hTreeView);
  646. PDBRECORD pRecord = m_pListRecord;
  647. while ( NULL != pRecord ) {
  648. AddRecordToTree(pRecord);
  649. pRecord = pRecord->pDup;
  650. }
  651. SendMessage(m_hTreeView,WM_SETREDRAW,TRUE,0);
  652. InvalidateRect(m_hListView,NULL,TRUE);
  653. UpdateWindow(m_hListView);
  654. TreeView_SelectItem(m_hTreeView,NULL);
  655. m_pCurrentRecord = pHoldCurrent;
  656. SyncMenu();
  657. //}
  658. }
  659. break;
  660. case ID_EDIT_ENABLEDISABLELOCALLY:
  661. case ID_DISABLEFORUSER:
  662. case DBCMD_DISABLEUSER:
  663. {
  664. if ( NULL == m_pCurrentRecord )
  665. break;
  666. //DWORD dwFlags = DialogBoxParam(g_hInstance,MAKEINTRESOURCE(IDD_DISABLE),m_hWnd,DisableDialog,(LPARAM) m_pCurrentRecord->dwUserFlags | 0x80000000);
  667. DWORD dwFlags = !m_pCurrentRecord->dwUserFlags;
  668. //if (dwFlags != m_pCurrentRecord->dwUserFlags)
  669. //{
  670. // Save new flags
  671. m_pCurrentRecord->dwUserFlags = dwFlags;
  672. // Update the registry
  673. CDatabase::SetEntryFlags(HKEY_CURRENT_USER,m_pCurrentRecord->guidID,dwFlags);
  674. // Refresh tree view
  675. SendMessage(m_hTreeView,WM_SETREDRAW,FALSE,0);
  676. PDBRECORD pHoldCurrent = m_pCurrentRecord;
  677. TreeView_DeleteAllItems(m_hTreeView);
  678. PDBRECORD pRecord = m_pListRecord;
  679. while ( NULL != pRecord ) {
  680. AddRecordToTree(pRecord);
  681. pRecord = pRecord->pDup;
  682. }
  683. SendMessage(m_hTreeView,WM_SETREDRAW,TRUE,0);
  684. InvalidateRect(m_hListView,NULL,TRUE);
  685. UpdateWindow(m_hListView);
  686. TreeView_SelectItem(m_hTreeView,NULL);
  687. m_pCurrentRecord = pHoldCurrent;
  688. SyncMenu();
  689. //}
  690. }
  691. break;
  692. }
  693. }
  694. void CDBView::msgPaint(HDC hDC)
  695. {
  696. RECT rRect;
  697. // Draw the slider bar
  698. GetClientRect(m_hWnd,&rRect);
  699. SetRect(&rRect,m_uListSize+1,0,m_uListSize + SLIDER_WIDTH - 1,rRect.bottom);
  700. FillRect(hDC,&rRect,(HBRUSH) (COLOR_BTNFACE + 1));
  701. SetRect(&rRect,m_uListSize-1,0,m_uListSize+1,rRect.bottom);
  702. FillRect(hDC,&rRect,(HBRUSH) GetStockObject(WHITE_BRUSH));
  703. SetRect(&rRect,m_uListSize+SLIDER_WIDTH - 1,0,m_uListSize + SLIDER_WIDTH + 1,rRect.bottom);
  704. FillRect(hDC,&rRect,(HBRUSH) GetStockObject(GRAY_BRUSH));
  705. // Draw horizontal bar.
  706. SetRect(&rRect,0,m_uListHeight ,rRect.right,m_uListHeight + SLIDER_WIDTH - 1);
  707. FillRect(hDC,&rRect,(HBRUSH) (COLOR_BTNFACE + 1));
  708. SetRect(&rRect,0,m_uListHeight + SLIDER_WIDTH,rRect.right,m_uListHeight + SLIDER_WIDTH + 1);
  709. FillRect(hDC,&rRect,(HBRUSH) GetStockObject(GRAY_BRUSH));
  710. }
  711. void CDBView::AddRecordToTree(PDBRECORD pRecord)
  712. {
  713. PDBENTRY pEntry;
  714. HTREEITEM hRoot;
  715. HTREEITEM hShim = NULL;
  716. HTREEITEM hMatch = NULL;
  717. HTREEITEM hAppHelp = NULL;
  718. UINT uImage;
  719. uImage = LookupFileImage(pRecord->szEXEName,IMAGE_APPLICATION);
  720. // Add the main .EXE/.DLL or other file that's affected by this record.
  721. if ( 0 != (pRecord->dwUserFlags | pRecord->dwGlobalFlags) )
  722. uImage = IMAGE_WARNING;
  723. hRoot = AddTreeItem(TVI_ROOT,
  724. TVIF_TEXT | TVIF_STATE | TVIF_IMAGE | TVIF_SELECTEDIMAGE | TVIF_PARAM,
  725. TVIS_EXPANDED,
  726. pRecord->szEXEName,
  727. uImage,
  728. (LPARAM) pRecord);
  729. /*
  730. if (0 != pRecord->guidID.Data1)
  731. {
  732. TCHAR szGUID[80];
  733. // NOTE: We could use StringFromGUID2, or StringfromIID, but that
  734. // would require loading OLE32.DLL. Unless we have to, avoid it.
  735. wsprintf(szGUID, "{%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}",
  736. pRecord->guidID.Data1,
  737. pRecord->guidID.Data2,
  738. pRecord->guidID.Data3,
  739. pRecord->guidID.Data4[0],
  740. pRecord->guidID.Data4[1],
  741. pRecord->guidID.Data4[2],
  742. pRecord->guidID.Data4[3],
  743. pRecord->guidID.Data4[4],
  744. pRecord->guidID.Data4[5],
  745. pRecord->guidID.Data4[6],
  746. pRecord->guidID.Data4[7]);
  747. AddTreeItem( hRoot,
  748. TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE,
  749. 0,
  750. szGUID,
  751. IMAGE_GUID);
  752. }
  753. */
  754. //
  755. //The tree tip is done here
  756. //
  757. if ( 0 != pRecord->dwGlobalFlags ) {
  758. PDBTREETIP pTip = &m_TipList[m_uNextTip++];
  759. pTip->uType = ENTRY_UI;
  760. pTip->uContext = 3;
  761. if ( pRecord->bGlobal )
  762. pTip->uContext = 2;
  763. HTREEITEM hGlobal;
  764. hGlobal = AddTreeItem( hRoot,
  765. TVIF_TEXT | TVIF_STATE | TVIF_IMAGE | TVIF_SELECTEDIMAGE | TVIF_PARAM,
  766. TVIS_EXPANDED,
  767. TEXT("Disabled"),
  768. IMAGE_DISABLEGLOBAL,
  769. (LPARAM) pTip);
  770. //WriteFlagsToTree(hGlobal,pRecord->dwGlobalFlags);
  771. }
  772. /*
  773. if (0 != pRecord->dwUserFlags)
  774. {
  775. PDBTREETIP pTip = &m_TipList[m_uNextTip++];
  776. pTip->uType = ENTRY_UI;
  777. pTip->uContext = 3;
  778. if (pRecord->bGlobal)
  779. pTip->uContext = 2;
  780. HTREEITEM hUser;
  781. hUser = AddTreeItem(hRoot,
  782. TVIF_TEXT | TVIF_STATE | TVIF_IMAGE | TVIF_SELECTEDIMAGE | TVIF_PARAM,
  783. TVIS_EXPANDED,
  784. "Disabled Locally",
  785. IMAGE_DISABLEUSER,
  786. (LPARAM) pTip);
  787. //WriteFlagsToTree(hUser,pRecord->dwUserFlags);
  788. }
  789. */
  790. pEntry = pRecord->pEntries;
  791. BOOL bHasMatch = FALSE;
  792. BOOL bHasShim = FALSE;
  793. BOOL bHasAppHelp = FALSE;
  794. BOOL bHasLayer = FALSE;
  795. while ( NULL != pEntry ) {
  796. if ( ENTRY_MATCH == pEntry->uType )
  797. bHasMatch = TRUE;
  798. if ( ENTRY_SHIM == pEntry->uType )
  799. bHasShim = TRUE;
  800. if ( pRecord->szLayerName.Length() > 0 )
  801. bHasLayer = TRUE;
  802. if ( ENTRY_APPHELP == pEntry->uType )
  803. bHasAppHelp = TRUE;
  804. pEntry = pEntry->pNext;
  805. }
  806. if ( bHasAppHelp ) {
  807. PDBTREETIP pTip = &m_TipList[m_uNextTip++];
  808. pTip->uType = ENTRY_UI;
  809. pTip->uContext = 3;
  810. if ( pRecord->bGlobal )
  811. pTip->uContext = 2;
  812. hAppHelp = AddTreeItem( hRoot,
  813. TVIF_TEXT | TVIF_STATE | TVIF_IMAGE | TVIF_SELECTEDIMAGE | TVIF_PARAM,
  814. TVIS_EXPANDED,
  815. TEXT("Application Help"),
  816. IMAGE_APPHELP,
  817. (LPARAM) pTip);
  818. }
  819. if ( bHasLayer ) {
  820. PDBTREETIP pTip = &m_TipList[m_uNextTip++];
  821. pTip->uType = ENTRY_UI;
  822. pTip->uContext = 3;
  823. if ( pRecord->bGlobal )
  824. pTip->uContext = 2;
  825. TCHAR szText[ MAX_PATH * 10 ];
  826. wsprintf(szText,TEXT("Applied Compatibility Modes: %s"),pRecord->szLayerName);
  827. hShim = AddTreeItem(hRoot,
  828. TVIF_TEXT | TVIF_STATE | TVIF_IMAGE | TVIF_SELECTEDIMAGE | TVIF_PARAM,
  829. TVIS_EXPANDED,
  830. szText,
  831. IMAGE_LAYERS,
  832. (LPARAM) pTip);
  833. }
  834. if ( bHasShim ) {
  835. PDBTREETIP pTip = &m_TipList[m_uNextTip++];
  836. pTip->uType = ENTRY_UI;
  837. pTip->uContext = 3;
  838. if ( pRecord->bGlobal )
  839. pTip->uContext = 2;
  840. hShim = AddTreeItem(hRoot,
  841. TVIF_TEXT | TVIF_STATE | TVIF_IMAGE | TVIF_SELECTEDIMAGE | TVIF_PARAM,
  842. 0,
  843. TEXT("Applied Compatability Fixes"),
  844. IMAGE_SHIM,
  845. (LPARAM) pTip);
  846. }
  847. if ( bHasMatch ) {
  848. PDBTREETIP pTip = &m_TipList[m_uNextTip++];
  849. pTip->uType = ENTRY_UI;
  850. pTip->uContext = 3;
  851. if ( pRecord->bGlobal )
  852. pTip->uContext = 2;
  853. hMatch = AddTreeItem(hRoot,
  854. TVIF_TEXT | TVIF_STATE | TVIF_PARAM,
  855. 0, //TVIS_EXPANDED,
  856. TEXT("File Matching"),
  857. 0,
  858. (LPARAM) pTip);
  859. }
  860. pEntry = pRecord->pEntries;
  861. while ( NULL != pEntry ) {
  862. switch ( pEntry->uType ) {
  863. case ENTRY_APPHELP:
  864. {
  865. PHELPENTRY pHelp = (PHELPENTRY) pEntry;
  866. PDBTREETIP pTip = &m_TipList[m_uNextTip++];
  867. TCHAR * szText[]={ TEXT("None"),
  868. TEXT("Non-Blocking"),
  869. TEXT("Hard Block"),
  870. TEXT("Minor Problem"),
  871. TEXT("Reinstall application"),
  872. TEXT("Version Sub"),
  873. TEXT("Shim")};
  874. pTip->uType = ENTRY_APPHELP;
  875. pTip->pHelp = pHelp;
  876. pTip->uContext = 0;
  877. if ( pRecord->bGlobal )
  878. pTip->uContext = 2;
  879. AddTreeItem(hAppHelp,
  880. TVIF_TEXT | TVIF_PARAM,
  881. 0,
  882. szText[pHelp->uSeverity],
  883. 0,
  884. (LPARAM) pTip);
  885. }
  886. break;
  887. case ENTRY_SHIM:
  888. {
  889. PSHIMENTRY pShim = (PSHIMENTRY) pEntry;
  890. PSHIMDESC pDesc;
  891. HTREEITEM hShimName;
  892. pDesc = g_theApp.GetDBGlobal().m_pShimList;
  893. while ( NULL != pDesc ) {
  894. if ( 0 == lstrcmpi(pDesc->szShimName,pShim->szShimName) )
  895. break;
  896. pDesc=pDesc->pNext;
  897. }
  898. PDBTREETIP pTip = &m_TipList[m_uNextTip++];
  899. pTip->uType = ENTRY_SHIM;
  900. pTip->pShim = pDesc;
  901. pTip->uContext = 0;
  902. if ( pRecord->bGlobal )
  903. pTip->uContext = 2;
  904. TCHAR szText[MAX_PATH * 10];
  905. if ( NULL != pDesc ) {
  906. if ( pDesc->bShim )
  907. wsprintf(szText,TEXT("Compat Fix: %s"),pShim->szShimName);
  908. else
  909. wsprintf(szText,TEXT("Patch: %s"),pShim->szShimName);
  910. } else
  911. lstrcpy(szText,pShim->szShimName);
  912. //
  913. //Always look up the image or use the default image for all the shims. the foll 2 lines not required
  914. //
  915. //
  916. //Also look for the include, exclude items.
  917. if ( 0 == pShim->Entry.uIconID )
  918. pShim->Entry.uIconID = LookupFileImage(pShim->szShimName,IMAGE_APPLICATION);
  919. hShimName = AddTreeItem(hShim,
  920. TVIF_TEXT | TVIF_PARAM | TVIF_IMAGE | TVIF_SELECTEDIMAGE,
  921. 0,
  922. szText,
  923. IMAGE_SHIM,//pShim->Entry.uIconID,
  924. (LPARAM) pTip);
  925. if ( lstrlen(pShim->szCmdLine) > 0 ) {
  926. wsprintf(szText,TEXT("Command Line: %s"),(LPCTSTR) pShim->szCmdLine);
  927. AddTreeItem(hShimName,
  928. TVIF_TEXT,
  929. 0,
  930. szText);
  931. }
  932. }
  933. break;
  934. case ENTRY_MATCH:
  935. {
  936. PMATCHENTRY pMatch = (PMATCHENTRY) pEntry;
  937. TCHAR szText[MAX_PATH * 10];
  938. HTREEITEM hFile = hMatch;
  939. if ( lstrlen(pMatch->szMatchName) > 0 ) {
  940. PDBTREETIP pTip = &m_TipList[m_uNextTip++];
  941. pTip->uType = ENTRY_MATCH;
  942. pTip->pMatch = pMatch;
  943. pTip->uContext = 1;
  944. if ( pRecord->bGlobal )
  945. pTip->uContext = 2;
  946. if ( TEXT('*') != *(LPCTSTR)pMatch->szMatchName )
  947. wsprintf(szText,TEXT("Match File: %s"),pMatch->szMatchName);
  948. else {
  949. pTip->uContext = 3;
  950. wsprintf(szText,TEXT("Match File: %s"),pRecord->szEXEName);
  951. }
  952. if ( 0 == pMatch->Entry.uIconID )
  953. pMatch->Entry.uIconID = LookupFileImage(pMatch->szMatchName,IMAGE_APPLICATION);
  954. hFile = AddTreeItem(hMatch,
  955. TVIF_TEXT | TVIF_PARAM | TVIF_IMAGE | TVIF_SELECTEDIMAGE,
  956. 0,
  957. szText,
  958. pMatch->Entry.uIconID,
  959. (LPARAM) pTip);
  960. }
  961. if ( lstrlen(pMatch->szDescription) > 0 ) {
  962. wsprintf(szText,TEXT("Description: %s"),pMatch->szDescription);
  963. PDBTREETIP pTip = &m_TipList[m_uNextTip++];
  964. pTip->uType = ENTRY_SUBMATCH;
  965. pTip->pMatch = pMatch;
  966. pTip->uID = MATCH_DESCRIPTION;
  967. pTip->uContext = 3;
  968. if ( pRecord->bGlobal )
  969. pTip->uContext = 2;
  970. AddTreeItem(hFile,
  971. TVIF_TEXT | TVIF_PARAM,
  972. 0,
  973. szText,
  974. 0,
  975. (LPARAM) pTip);
  976. }
  977. if ( lstrlen(pMatch->szCompanyName) > 0 ) {
  978. wsprintf(szText,TEXT("Company Name: %s"),pMatch->szCompanyName);
  979. PDBTREETIP pTip = &m_TipList[m_uNextTip++];
  980. pTip->uType = ENTRY_SUBMATCH;
  981. pTip->pMatch = pMatch;
  982. pTip->uID = MATCH_COMPANY;
  983. pTip->uContext = 3;
  984. if ( pRecord->bGlobal )
  985. pTip->uContext = 2;
  986. AddTreeItem(hFile,
  987. TVIF_TEXT | TVIF_PARAM,
  988. 0,
  989. szText,
  990. 0,
  991. (LPARAM) pTip);
  992. }
  993. if ( pMatch->dwSize > 0 ) {
  994. DWORD dwSize = pMatch->dwSize;
  995. TCHAR szSize[80];
  996. FormatFileSize(pMatch->dwSize,szSize);
  997. wsprintf(szText,TEXT("File Size: %s bytes"),szSize);
  998. PDBTREETIP pTip = &m_TipList[m_uNextTip++];
  999. pTip->uType = ENTRY_SUBMATCH;
  1000. pTip->pMatch = pMatch;
  1001. pTip->uID = MATCH_SIZE;
  1002. pTip->uContext = 3;
  1003. if ( pRecord->bGlobal )
  1004. pTip->uContext = 2;
  1005. AddTreeItem(hFile,
  1006. TVIF_TEXT | TVIF_PARAM,
  1007. 0,
  1008. szText,
  1009. 0,
  1010. (LPARAM) pTip);
  1011. }
  1012. if ( pMatch->dwChecksum > 0 ) {
  1013. wsprintf(szText,TEXT("Checksum: %08X"),pMatch->dwChecksum);
  1014. PDBTREETIP pTip = &m_TipList[m_uNextTip++];
  1015. pTip->uType = ENTRY_SUBMATCH;
  1016. pTip->pMatch = pMatch;
  1017. pTip->uID = MATCH_CHECKSUM;
  1018. pTip->uContext = 3;
  1019. if ( pRecord->bGlobal )
  1020. pTip->uContext = 2;
  1021. AddTreeItem(hFile,
  1022. TVIF_TEXT | TVIF_PARAM,
  1023. 0,
  1024. szText,
  1025. 0,
  1026. (LPARAM) pTip);
  1027. }
  1028. if ( lstrlen(pMatch->szProductVersion) > 0 ) {
  1029. wsprintf(szText,TEXT("Product Version: %s"),pMatch->szProductVersion);
  1030. PDBTREETIP pTip = &m_TipList[m_uNextTip++];
  1031. pTip->uType = ENTRY_SUBMATCH;
  1032. pTip->pMatch = pMatch;
  1033. pTip->uID = MATCH_PRODUCTVERSTRING;
  1034. pTip->uContext = 3;
  1035. if ( pRecord->bGlobal )
  1036. pTip->uContext = 2;
  1037. AddTreeItem(hFile,
  1038. TVIF_TEXT | TVIF_PARAM,
  1039. 0,
  1040. szText,
  1041. 0,
  1042. (LPARAM) pTip);
  1043. }
  1044. if ( lstrlen(pMatch->szFileVersion) > 0 ) {
  1045. wsprintf(szText,TEXT("File Version: %s"),pMatch->szFileVersion);
  1046. PDBTREETIP pTip = &m_TipList[m_uNextTip++];
  1047. pTip->uType = ENTRY_SUBMATCH;
  1048. pTip->pMatch = pMatch;
  1049. pTip->uID = MATCH_FILEVERSTRING;
  1050. pTip->uContext = 3;
  1051. if ( pRecord->bGlobal )
  1052. pTip->uContext = 2;
  1053. AddTreeItem(hFile,
  1054. TVIF_TEXT | TVIF_PARAM,
  1055. 0,
  1056. szText,
  1057. 0,
  1058. (LPARAM) pTip);
  1059. }
  1060. if ( pMatch->FileVersion.QuadPart > 0 ) {
  1061. wsprintf( szText,
  1062. TEXT("Binary File Version: %u.%u.%u.%u"),
  1063. HIWORD(pMatch->FileVersion.HighPart),
  1064. LOWORD(pMatch->FileVersion.HighPart),
  1065. HIWORD(pMatch->FileVersion.LowPart),
  1066. LOWORD(pMatch->FileVersion.LowPart));
  1067. PDBTREETIP pTip = &m_TipList[m_uNextTip++];
  1068. pTip->uType = ENTRY_SUBMATCH;
  1069. pTip->pMatch = pMatch;
  1070. pTip->uID = MATCH_FILEVERSION;
  1071. pTip->uContext = 3;
  1072. if ( pRecord->bGlobal )
  1073. pTip->uContext = 2;
  1074. AddTreeItem(hFile,
  1075. TVIF_TEXT | TVIF_PARAM,
  1076. 0,
  1077. szText,
  1078. 0,
  1079. (LPARAM) pTip);
  1080. }
  1081. if ( pMatch->ProductVersion.QuadPart > 0 ) {
  1082. wsprintf( szText,
  1083. TEXT("Binary Product Version: %u.%u.%u.%u"),
  1084. HIWORD(pMatch->ProductVersion.HighPart),
  1085. LOWORD(pMatch->ProductVersion.HighPart),
  1086. HIWORD(pMatch->ProductVersion.LowPart),
  1087. LOWORD(pMatch->ProductVersion.LowPart));
  1088. PDBTREETIP pTip = &m_TipList[m_uNextTip++];
  1089. pTip->uType = ENTRY_SUBMATCH;
  1090. pTip->pMatch = pMatch;
  1091. pTip->uID = MATCH_PRODUCTVERSION;
  1092. pTip->uContext = 3;
  1093. if ( pRecord->bGlobal )
  1094. pTip->uContext = 2;
  1095. AddTreeItem(hFile,
  1096. TVIF_TEXT | TVIF_PARAM,
  1097. 0,
  1098. szText,
  1099. 0,
  1100. (LPARAM) pTip);
  1101. }
  1102. }
  1103. break;
  1104. }
  1105. pEntry = pEntry->pNext;
  1106. }
  1107. }
  1108. void CDBView::msgChar(TCHAR chChar)
  1109. {
  1110. // send notifications to the list views to update their views.
  1111. m_GlobalList.msgChar(chChar);
  1112. m_LocalList.msgChar(chChar);
  1113. }
  1114. void CDBView::DeleteDBWithTree(HTREEITEM hItem)
  1115. {
  1116. HTREEITEM hHold = NULL;
  1117. TV_ITEM Item;
  1118. PDBRECORD pRecord;
  1119. HTREEITEM hParent = hItem;
  1120. // Lookup the current record.
  1121. while ( NULL != hParent ) {
  1122. hHold = hParent;
  1123. hParent = TreeView_GetParent(m_hTreeView,hParent);
  1124. }
  1125. //PREFAST
  1126. if ( hHold == NULL ) {
  1127. return;
  1128. }
  1129. Item.mask = TVIF_PARAM;
  1130. Item.hItem = hHold;
  1131. TreeView_GetItem(m_hTreeView,&Item);
  1132. pRecord = (PDBRECORD) Item.lParam;
  1133. if ( pRecord->bGlobal ) {
  1134. MessageBeep(MB_OK);
  1135. return;
  1136. }
  1137. g_theApp.GetDBLocal().m_bDirty = TRUE;
  1138. g_theApp.UpdateView(TRUE);
  1139. if ( hHold != hItem ) {
  1140. PDBENTRY pEntry;
  1141. PDBENTRY pWalk;
  1142. PDBENTRY pHold;
  1143. PDBTREETIP pTip;
  1144. Item.mask = TVIF_PARAM;
  1145. Item.hItem = hItem;
  1146. TreeView_GetItem(m_hTreeView,&Item);
  1147. // Delete only the entry information;
  1148. pTip = (PDBTREETIP) Item.lParam;
  1149. if ( NULL == pTip ) {
  1150. MessageBeep(MB_OK);
  1151. return;
  1152. }
  1153. if ( ENTRY_UI == pTip->uType )
  1154. return;
  1155. if ( ENTRY_SUBMATCH == pTip->uType ) {
  1156. PMATCHENTRY pMatch = pTip->pMatch;
  1157. switch ( pTip->uID ) {
  1158. case MATCH_NAME:
  1159. MessageBeep(MB_OK);
  1160. return;
  1161. case MATCH_SIZE:
  1162. pMatch->dwSize = 0;
  1163. break;
  1164. case MATCH_CHECKSUM:
  1165. pMatch->dwChecksum = 0;
  1166. break;
  1167. case MATCH_FILEVERSION:
  1168. pMatch->FileVersion.QuadPart = 0;
  1169. break;
  1170. case MATCH_PRODUCTVERSION:
  1171. pMatch->ProductVersion.QuadPart = 0;
  1172. break;
  1173. case MATCH_COMPANY:
  1174. pMatch->szCompanyName.Release();
  1175. break;
  1176. case MATCH_DESCRIPTION:
  1177. pMatch->szDescription.Release();
  1178. break;
  1179. case MATCH_FILEVERSTRING:
  1180. pMatch->szFileVersion.Release();
  1181. break;
  1182. case MATCH_PRODUCTVERSTRING:
  1183. pMatch->szProductVersion.Release();
  1184. break;
  1185. }
  1186. } else {
  1187. pEntry = (PDBENTRY) pTip->pShim;
  1188. pWalk = pRecord->pEntries;
  1189. while ( NULL != pWalk ) {
  1190. if ( pEntry == pWalk )
  1191. break;
  1192. pHold = pWalk;
  1193. pWalk = pWalk->pNext;
  1194. }
  1195. if ( NULL == pWalk )
  1196. return;
  1197. if ( ENTRY_MATCH == pEntry->uType ) {
  1198. // Cannot delete self reference
  1199. PMATCHENTRY pMatch = (PMATCHENTRY) pEntry;
  1200. if ( pMatch->szMatchName == TEXT("*") ) {
  1201. MessageBeep(MB_OK);
  1202. return;
  1203. }
  1204. } else {
  1205. MessageBeep(MB_OK);
  1206. return;
  1207. }
  1208. if ( pWalk == pRecord->pEntries )
  1209. pRecord->pEntries = pRecord->pEntries->pNext;
  1210. else
  1211. pHold->pNext = pEntry->pNext;
  1212. }
  1213. } else {
  1214. if ( DELRES_RECORDREMOVED == g_theApp.GetDBLocal().DeleteRecord(pRecord) )
  1215. Update();
  1216. }
  1217. TreeView_DeleteItem(m_hTreeView,hItem);
  1218. }
  1219. void CDBView::msgNotify(LPNMHDR pHdr)
  1220. {
  1221. switch ( pHdr->code ) {
  1222. case NM_KEYDOWN:
  1223. {
  1224. LPNMKEY pKey = (LPNMKEY) pHdr;
  1225. if ( VK_TAB == pKey->nVKey ) {
  1226. if ( pKey->hdr.hwndFrom == m_LocalList.m_hWnd ) {
  1227. SetFocus(m_hTreeView);
  1228. }
  1229. else if ( pKey->hdr.hwndFrom == m_GlobalList.m_hWnd ) {
  1230. SetFocus(m_hTreeView);
  1231. }
  1232. else if ( pKey->hdr.hwndFrom == m_hTreeView ) {
  1233. if (g_hWndLastFocus != NULL ) {
  1234. if (g_hWndLastFocus == m_LocalList.m_hWnd) SetFocus(m_GlobalList.m_hWnd);
  1235. else SetFocus(m_LocalList.m_hWnd);
  1236. }
  1237. else
  1238. SetFocus(m_LocalList.m_hWnd);
  1239. }//else if ( pKey->hdr.hwndFrom == m_hTreeView )
  1240. }//if ( VK_TAB == pKey->nVKey )
  1241. }
  1242. break;
  1243. case LVN_SELCHANGED:////This is a user defined NM. Here we are building the tree.....
  1244. {
  1245. PLISTVIEWNOTIFY plvn = (PLISTVIEWNOTIFY) pHdr;
  1246. if ( pHdr->hwndFrom == m_GlobalList.m_hWnd )
  1247. g_theApp.SetStatusText(2,CSTRING(TEXT("Read Only")));
  1248. else
  1249. g_theApp.SetStatusText(2,CSTRING(TEXT("")));
  1250. g_theApp.SetButtonState(DBCMD_DISABLEGLOBAL, 0);
  1251. g_theApp.SetButtonState(DBCMD_DISABLEUSER, 0);
  1252. // Update the tree view.
  1253. SendMessage(m_hTreeView,WM_SETREDRAW,FALSE,0);
  1254. TreeView_DeleteAllItems(m_hTreeView);
  1255. PDBRECORD pRecord = (PDBRECORD) plvn->pData;
  1256. if ( m_pListRecord != pRecord )
  1257. m_pCurrentRecord = NULL;
  1258. m_pListRecord = pRecord;
  1259. UINT uFiles = 0;
  1260. m_uNextTip = 0;
  1261. while ( NULL != pRecord ) {
  1262. ++uFiles;
  1263. AddRecordToTree(pRecord);
  1264. pRecord = pRecord->pDup;
  1265. }
  1266. SendMessage(m_hTreeView,WM_SETREDRAW,TRUE,0);
  1267. UpdateWindow(m_hTreeView);
  1268. TCHAR szText[MAX_PATH * 10];
  1269. if (uFiles == 0)
  1270. lstrcpy(szText,TEXT("No affected file found"));
  1271. else
  1272. wsprintf(szText,TEXT("%d affected file(s) found associated with this application"),uFiles);
  1273. SetWindowText(g_theApp.m_hStatusBar,szText);
  1274. SyncMenu();
  1275. }
  1276. break;
  1277. case NM_SETFOCUS:
  1278. {
  1279. if ( pHdr->hwndFrom == m_GlobalList.m_hWnd ) {
  1280. m_GlobalList.ShowHilight(TRUE);
  1281. m_LocalList.ShowHilight(FALSE);
  1282. SendMessage(m_hTreeView,WM_SETREDRAW,FALSE,0);
  1283. TreeView_DeleteAllItems(m_hTreeView);
  1284. SendMessage(m_hTreeView,WM_SETREDRAW,TRUE,0);
  1285. UINT uEntry = m_GlobalList.GetSelectedEntry();
  1286. if ( -1 != uEntry ) {
  1287. m_pListRecord = (PDBRECORD)m_GlobalList.GetEntryData(uEntry);
  1288. RefreshTree();
  1289. } else
  1290. m_pListRecord = NULL;
  1291. m_pCurrentRecord = NULL;
  1292. SyncMenu();
  1293. }
  1294. if ( pHdr->hwndFrom == m_LocalList.m_hWnd ) {
  1295. m_GlobalList.ShowHilight(FALSE);
  1296. m_LocalList.ShowHilight(TRUE);
  1297. SendMessage(m_hTreeView,WM_SETREDRAW,FALSE,0);
  1298. TreeView_DeleteAllItems(m_hTreeView);
  1299. SendMessage(m_hTreeView,WM_SETREDRAW,TRUE,0);
  1300. UINT uEntry = m_LocalList.GetSelectedEntry();
  1301. if ( -1 != uEntry ) {
  1302. m_pListRecord = (PDBRECORD)m_LocalList.GetEntryData(uEntry);
  1303. RefreshTree();
  1304. } else
  1305. m_pListRecord = NULL;
  1306. m_pCurrentRecord = NULL;
  1307. SyncMenu();
  1308. }
  1309. if ( pHdr->hwndFrom == m_GlobalList.m_hWnd )
  1310. g_theApp.SetStatusText(2,CSTRING(TEXT("Read Only")));
  1311. else if ( pHdr->hwndFrom == m_LocalList.m_hWnd )
  1312. g_theApp.SetStatusText(2,CSTRING(TEXT("")));
  1313. PDBRECORD pRecord = m_pListRecord;
  1314. UINT uFiles = 0;
  1315. while ( NULL != pRecord ) {
  1316. ++uFiles;
  1317. pRecord = pRecord->pDup;
  1318. }
  1319. TCHAR szText[MAX_PATH * 10];
  1320. if (uFiles == 0)
  1321. lstrcpy(szText,TEXT("No affected file found"));
  1322. else
  1323. wsprintf(szText,TEXT("%d affected file(s) found associated with this application."),uFiles);
  1324. SetWindowText(g_theApp.m_hStatusBar,szText);
  1325. }
  1326. break;
  1327. case NM_RCLICK:
  1328. {
  1329. if ( pHdr->hwndFrom == m_hTreeView ) {
  1330. #ifdef __DEBUG
  1331. MessageBox(NULL,TEXT("NM_RCLICK"),TEXT("NM_RCLICK"),MB_OK);
  1332. #endif
  1333. TVHITTESTINFO ht;
  1334. GetCursorPos(&ht.pt);
  1335. ScreenToClient(m_hTreeView, &ht.pt);
  1336. TreeView_HitTest(m_hTreeView,&ht);
  1337. if ( 0 != ht.hItem ){
  1338. g_do_notProcess = TRUE;
  1339. TreeView_SelectItem(m_hTreeView,NULL);
  1340. g_do_notProcess = FALSE;
  1341. TreeView_SelectItem(m_hTreeView,ht.hItem);
  1342. }
  1343. }
  1344. }
  1345. break;
  1346. case TVN_KEYDOWN:
  1347. {
  1348. LPNMTVKEYDOWN pKey = (LPNMTVKEYDOWN) pHdr;
  1349. switch ( pKey->wVKey ) {
  1350. case VK_DELETE:
  1351. {
  1352. DeleteDBWithTree(m_hSelectedItem);
  1353. }
  1354. break;
  1355. }
  1356. }
  1357. break;
  1358. case TVN_SELCHANGED:
  1359. {
  1360. //MessageBox(NULL,NULL,NULL,MB_OK);
  1361. if (g_do_notProcess) {
  1362. break;
  1363. }
  1364. LPNMTREEVIEW pItem = (LPNMTREEVIEW) pHdr;
  1365. if ( pItem == NULL ) {
  1366. break;
  1367. }
  1368. BOOL bEnabled = FALSE;
  1369. HTREEITEM hItem = TreeView_GetParent(m_hTreeView,pItem->itemNew.hItem);
  1370. HTREEITEM hHold = pItem->itemNew.hItem;
  1371. TV_ITEM Item;
  1372. PDBTREETIP pTip = (PDBTREETIP) pItem->itemNew.lParam;
  1373. m_hSelectedItem = pItem->itemNew.hItem;
  1374. // Lookup the current record.
  1375. while ( NULL != hItem ) {
  1376. hHold = hItem;
  1377. hItem = TreeView_GetParent(m_hTreeView,hItem);
  1378. }
  1379. // Determine which context menu to use.
  1380. // Root level item.
  1381. if ( pItem->itemNew.hItem == hHold )
  1382. m_uContext = 0;
  1383. else
  1384. if ( NULL != pTip )
  1385. m_uContext = pTip->uContext;
  1386. else
  1387. m_uContext = 0;
  1388. Item.mask = TVIF_PARAM;
  1389. Item.hItem = hHold;
  1390. TreeView_GetItem(m_hTreeView,&Item);
  1391. //
  1392. //The m_pCurrentRecord is changed here !!
  1393. //
  1394. m_pCurrentRecord = (PDBRECORD) Item.lParam;
  1395. #ifdef __DEBUG
  1396. CSTRING message;
  1397. message.sprintf(
  1398. TEXT("%s : % u Message: = %u"),
  1399. TEXT(__FILE__),
  1400. __LINE__,
  1401. TEXT("m_pCurrentRecord"),
  1402. m_pCurrentRecord
  1403. );
  1404. MessageBox(NULL,message,TEXT("Inside TVN_SELCHANGED/NM_RCLICK"),MB_OK);
  1405. #endif
  1406. if ( NULL != m_pCurrentRecord ) {
  1407. g_theApp.SetButtonState(DBCMD_DISABLEGLOBAL,TBSTATE_ENABLED);
  1408. g_theApp.SetButtonState(DBCMD_DISABLEUSER,TBSTATE_ENABLED);
  1409. if ( m_pCurrentRecord->bGlobal )
  1410. m_uContext = 2;
  1411. } else {
  1412. g_theApp.SetButtonState(DBCMD_DISABLEGLOBAL, 0);
  1413. g_theApp.SetButtonState(DBCMD_DISABLEUSER, 0);
  1414. }
  1415. SyncMenu();
  1416. }
  1417. break;
  1418. case LVN_ITEMCHANGED:
  1419. {
  1420. g_theApp.SetButtonState(DBCMD_DISABLEGLOBAL, 0);
  1421. g_theApp.SetButtonState(DBCMD_DISABLEUSER, 0);
  1422. // Update the tree view.
  1423. SendMessage(m_hTreeView,WM_SETREDRAW,FALSE,0);
  1424. TreeView_DeleteAllItems(m_hTreeView);
  1425. LPNMLISTVIEW pList = (LPNMLISTVIEW) pHdr;
  1426. PDBRECORD pRecord = (PDBRECORD) pList->lParam;
  1427. if ( m_pListRecord != pRecord )
  1428. m_pCurrentRecord = NULL;
  1429. m_pListRecord = pRecord;
  1430. UINT uFiles = 0;
  1431. m_uNextTip = 0;
  1432. do {
  1433. ++uFiles;
  1434. AddRecordToTree(pRecord);
  1435. pRecord = pRecord->pDup;
  1436. }
  1437. while ( NULL != pRecord );
  1438. SendMessage(m_hTreeView,WM_SETREDRAW,TRUE,0);
  1439. UpdateWindow(m_hTreeView);
  1440. SyncMenu();
  1441. TCHAR szText[MAX_PATH * 10];
  1442. wsprintf(szText,TEXT("%d files affected"),uFiles);
  1443. SetWindowText(g_theApp.m_hStatusBar,szText);
  1444. }
  1445. break;
  1446. case TBN_GETINFOTIP:
  1447. {
  1448. LPNMTBGETINFOTIP pTip = (LPNMTBGETINFOTIP) pHdr;
  1449. static TCHAR * szTips[] = { TEXT("Properties"),
  1450. TEXT("Delete Entry"),
  1451. TEXT("Enable/Disable for user"),
  1452. TEXT("Enable/Disable global"),
  1453. TEXT("View Shims"),
  1454. TEXT("View Application Help"),
  1455. TEXT("Application Fix Wizard"),
  1456. TEXT("View Global Database"),
  1457. TEXT("View Patches"),
  1458. TEXT("View Compatibility Modes"),
  1459. TEXT("View Disabled")};
  1460. switch ( pTip->iItem ) {
  1461. case DBCMD_PROPERTIES:
  1462. case DBCMD_DELETE:
  1463. case DBCMD_DISABLEUSER:
  1464. case DBCMD_DISABLEGLOBAL:
  1465. case DBCMD_VIEWSHIMS:
  1466. case DBCMD_VIEWAPPHELP:
  1467. case DBCMD_FIXWIZARD:
  1468. case DBCMD_VIEWPATCH:
  1469. case DBCMD_VIEWLAYERS:
  1470. case DBCMD_VIEWDISABLED:
  1471. lstrcpy(pTip->pszText,szTips[pTip->iItem - DBCMD_PROPERTIES]);
  1472. break;
  1473. }
  1474. }
  1475. break;
  1476. case TVN_GETINFOTIP:
  1477. {
  1478. LPNMTVGETINFOTIP pTip = (LPNMTVGETINFOTIP) pHdr;
  1479. *(pTip->pszText) = 0;
  1480. GenerateTreeToolTip((PDBTREETIP) pTip->lParam,pTip->pszText);
  1481. }
  1482. break;
  1483. }
  1484. }
  1485. LRESULT CDBView::MsgProc(UINT uMsg,WPARAM wParam, LPARAM lParam)
  1486. {
  1487. switch ( uMsg ) {
  1488. case WM_LBUTTONDOWN:
  1489. {
  1490. SetCapture(m_hWnd);
  1491. if ( LOWORD(lParam) > m_uListSize - SLIDER_WIDTH/2 ) {
  1492. m_uCapturePos = LOWORD(lParam);
  1493. m_bHorzDrag = TRUE;
  1494. } else {
  1495. m_uCapturePos = HIWORD(lParam);
  1496. m_bHorzDrag = FALSE;
  1497. }
  1498. m_bDrag = TRUE;
  1499. }
  1500. break;
  1501. case WM_CONTEXTMENU:
  1502. {
  1503. UINT uX = LOWORD(lParam);
  1504. UINT uY = HIWORD(lParam);
  1505. HWND hWnd = (HWND) wParam;
  1506. if ( hWnd == m_hTreeView ) {
  1507. #ifdef __DEBUG
  1508. MessageBox(NULL,TEXT("WM_CONTEXT"),TEXT("WM_CONTEXT"),MB_OK);
  1509. #endif
  1510. TVHITTESTINFO ht;
  1511. GetCursorPos(&ht.pt);
  1512. ScreenToClient(m_hTreeView, &ht.pt);
  1513. TreeView_HitTest(m_hTreeView,&ht);
  1514. if ( 0 != ht.hItem ) {
  1515. TVITEM Item;
  1516. Item.mask = TVIF_PARAM;
  1517. Item.hItem = ht.hItem;
  1518. TreeView_GetItem(m_hTreeView,&Item);
  1519. HTREEITEM hParent = TreeView_GetParent(m_hTreeView,ht.hItem);
  1520. HMENU hMenu = LoadMenu(g_hInstance,MAKEINTRESOURCE(IDR_DBVCONTEXT1));
  1521. HMENU hContext = NULL;
  1522. if ( NULL == hParent ) {
  1523. PDBRECORD pRecord = (PDBRECORD) Item.lParam;
  1524. if ( pRecord->bGlobal )
  1525. hContext = GetSubMenu(hMenu,2);
  1526. else
  1527. hContext = GetSubMenu(hMenu,3);
  1528. } else {
  1529. PDBTREETIP pTip = (PDBTREETIP) Item.lParam;
  1530. if ( NULL != pTip )
  1531. hContext = GetSubMenu(hMenu,pTip->uContext);
  1532. }
  1533. if ( hContext == NULL ) { //prefast
  1534. break;
  1535. }
  1536. if ( NULL != m_pCurrentRecord ) {
  1537. MENUITEMINFO Info;
  1538. Info.cbSize = sizeof(MENUITEMINFO);
  1539. Info.fMask = MIIM_STRING;
  1540. /*
  1541. if (0 == m_pCurrentRecord->dwUserFlags)
  1542. Info.dwTypeData = "Disable for User";
  1543. else
  1544. Info.dwTypeData = "Enable for User";
  1545. SetMenuItemInfo(hContext,ID_DISABLEFORUSER,MF_BYCOMMAND,&Info);
  1546. */
  1547. if ( 0 == m_pCurrentRecord->dwGlobalFlags )
  1548. Info.dwTypeData = TEXT("Disable Entry");
  1549. else
  1550. Info.dwTypeData = TEXT("Enable Entry");
  1551. SetMenuItemInfo(hContext,ID_DISABLEGLOBALLY,MF_BYCOMMAND,&Info);
  1552. }
  1553. TrackPopupMenuEx(hContext,
  1554. TPM_LEFTALIGN | TPM_TOPALIGN,
  1555. uX,
  1556. uY,
  1557. m_hWnd,
  1558. NULL);
  1559. DestroyMenu(hMenu);
  1560. }
  1561. }
  1562. }
  1563. break;
  1564. case WM_LBUTTONUP:
  1565. m_bDrag = FALSE;
  1566. ReleaseCapture();
  1567. break;
  1568. case WM_MOUSEMOVE:
  1569. {
  1570. if ( LOWORD(lParam) > m_uListSize - SLIDER_WIDTH/2 )
  1571. SetCursor(LoadCursor(NULL,IDC_SIZEWE));
  1572. else
  1573. SetCursor(LoadCursor(NULL,IDC_SIZENS));
  1574. if ( 0 != (wParam & MK_LBUTTON) && m_bDrag ) {
  1575. RECT rRect;
  1576. short int nX = (short int) LOWORD(lParam);
  1577. short int nY = (short int) HIWORD(lParam);
  1578. if ( m_bHorzDrag )
  1579. m_uListSize = m_uCapturePos + (nX - m_uCapturePos);
  1580. else
  1581. m_uListHeight = m_uCapturePos + (nY - m_uCapturePos);
  1582. GetClientRect(m_hWnd,&rRect);
  1583. if ( (int)m_uListHeight < 100 )
  1584. m_uListHeight = 100;
  1585. if ( (int)m_uListSize < 100 )
  1586. m_uListSize = 100;
  1587. if ( (int)m_uListHeight > (int)(rRect.bottom * 0.75f) )
  1588. m_uListHeight = (UINT)(rRect.bottom * 0.75f);
  1589. if ( (int)m_uListSize > (int)(rRect.right * 0.75f) )
  1590. m_uListSize = (UINT)(rRect.right * 0.75f);
  1591. msgResize(rRect.right,rRect.bottom);
  1592. }
  1593. }
  1594. break;
  1595. case WM_DRAWITEM:
  1596. {
  1597. //***Probably this is never called.
  1598. LPDRAWITEMSTRUCT pDraw = (LPDRAWITEMSTRUCT) lParam;
  1599. LV_ITEM Item;
  1600. HDC hDC = CreateCompatibleDC(pDraw->hDC);
  1601. HBITMAP hBmp = CreateCompatibleBitmap(pDraw->hDC,pDraw->rcItem.right - pDraw->rcItem.left,pDraw->rcItem.bottom - pDraw->rcItem.top);
  1602. HBITMAP hOldBmp = (HBITMAP) SelectObject(hDC,hBmp);
  1603. RECT rBmpRect;
  1604. HFONT hFont = (HFONT) SendMessage(m_hListView,WM_GETFONT,0,0);
  1605. HBRUSH hFillBrush = GetSysColorBrush(COLOR_WINDOW);
  1606. hFont = (HFONT) SelectObject(hDC,hFont);
  1607. SetRect(&rBmpRect,0,0,pDraw->rcItem.right - pDraw->rcItem.left,pDraw->rcItem.bottom - pDraw->rcItem.top);
  1608. Item.mask = LVIF_PARAM;
  1609. Item.iItem = pDraw->itemID;
  1610. Item.iSubItem = 0;
  1611. LV_COLUMN Col;
  1612. Col.mask = LVCF_WIDTH;
  1613. ListView_GetColumn(m_hListView,0,&Col);
  1614. Col.cx = pDraw->rcItem.right;
  1615. ListView_GetItem(m_hListView,&Item);
  1616. pDraw->rcItem.right = m_uListSize;
  1617. if ( 0 != (pDraw->itemState & ODS_FOCUS) ) {
  1618. //FillRect(pDraw->hDC,&pDraw->rcItem,GetSysColorBrush(COLOR_HIGHLIGHT));
  1619. FillRect(hDC,&rBmpRect,GetSysColorBrush(COLOR_HIGHLIGHT));
  1620. SetBkColor(hDC,GetSysColor(COLOR_HIGHLIGHT));
  1621. } else
  1622. if ( 0 == pDraw->itemID % 2 ) {
  1623. //FillRect(pDraw->hDC,&pDraw->rcItem,(HBRUSH) GetStockObject(WHITE_BRUSH));
  1624. FillRect(hDC,&rBmpRect,(HBRUSH) GetStockObject(WHITE_BRUSH));
  1625. SetBkColor(hDC,RGB(255,255,255));
  1626. } else {
  1627. //FillRect(pDraw->hDC,&pDraw->rcItem,hFillBrush);
  1628. FillRect(hDC,&rBmpRect,hFillBrush);
  1629. SetBkColor(hDC,RGB(235,235,235));
  1630. }
  1631. //SelectObject(pDraw->hDC,(HPEN) GetStockObject(BLACK_PEN));
  1632. SelectObject(hDC,(HPEN) GetStockObject(BLACK_PEN));
  1633. //MoveToEx(pDraw->hDC,Col.cx-1,pDraw->rcItem.top,NULL);
  1634. //LineTo(pDraw->hDC,Col.cx-1,pDraw->rcItem.bottom);
  1635. MoveToEx(hDC,Col.cx-1,0,NULL);
  1636. LineTo(hDC,Col.cx-1,rBmpRect.bottom);
  1637. //MoveToEx(pDraw->hDC,pDraw->rcItem.left,pDraw->rcItem.bottom-1,NULL);
  1638. //LineTo(pDraw->hDC,pDraw->rcItem.right,pDraw->rcItem.bottom-1);
  1639. MoveToEx(hDC,0,rBmpRect.bottom-1,NULL);
  1640. LineTo(hDC,rBmpRect.right,rBmpRect.bottom-1);
  1641. // Draw the actual name.
  1642. PDBRECORD pRecord = (PDBRECORD) Item.lParam;
  1643. //pDraw->rcItem.right = Col.cx - 2;
  1644. //pDraw->rcItem.bottom --;
  1645. BOOL bDisableUser = FALSE;
  1646. BOOL bDisableGlobal = FALSE;
  1647. BOOL bShim = FALSE;
  1648. BOOL bHelp = FALSE;
  1649. PDBRECORD pWalk = pRecord;
  1650. while ( NULL != pWalk ) {
  1651. if ( 0 != pWalk->dwUserFlags )
  1652. bDisableUser = TRUE;
  1653. if ( 0 != pWalk->dwGlobalFlags )
  1654. bDisableGlobal = TRUE;
  1655. PDBENTRY pEntry = pWalk->pEntries;
  1656. while ( NULL != pEntry ) {
  1657. if ( ENTRY_SHIM == pEntry->uType )
  1658. bShim = TRUE;
  1659. if ( ENTRY_APPHELP == pEntry->uType )
  1660. bHelp = TRUE;
  1661. pEntry = pEntry->pNext;
  1662. }
  1663. pWalk = pWalk->pDup;
  1664. }
  1665. {
  1666. HDC hBmpDC = CreateCompatibleDC(hDC);
  1667. HBITMAP hOldBmp = (HBITMAP) SelectObject(hBmpDC,g_theApp.m_hToolBitmap);
  1668. UINT uIndex;
  1669. if ( bShim )
  1670. uIndex = IMAGE_SHIM;
  1671. if ( bHelp )
  1672. uIndex = IMAGE_APPHELP;
  1673. if ( bDisableGlobal | bDisableUser ) {
  1674. uIndex = IMAGE_WARNING;
  1675. SetTextColor(hDC,RGB(128,128,128));
  1676. }
  1677. // Draw the appropriate bitmap
  1678. UINT uSize = pDraw->rcItem.bottom - pDraw->rcItem.top;
  1679. if ( IMAGE_SHIM != uIndex )
  1680. StretchBlt( hDC,
  1681. 3,0,
  1682. uSize - 1, uSize - 1,
  1683. hBmpDC,
  1684. 16 * uIndex,0,
  1685. 16,16,
  1686. SRCCOPY);
  1687. SelectObject(hBmpDC,hOldBmp);
  1688. DeleteDC(hBmpDC);
  1689. }
  1690. LPTSTR szText = pRecord->szAppName;
  1691. if ( 0 == lstrlen(szText) )
  1692. szText = pRecord->szEXEName;
  1693. //ExtTextOut(pDraw->hDC,pDraw->rcItem.left + 20, pDraw->rcItem.top, ETO_OPAQUE | ETO_CLIPPED, &pDraw->rcItem, szText, lstrlen(szText), NULL);
  1694. RECT rClipRect = rBmpRect;
  1695. rClipRect.left = 20;
  1696. rClipRect.right = Col.cx - 2;
  1697. --rClipRect.bottom;
  1698. ExtTextOut( hDC,
  1699. 20, 0,
  1700. ETO_OPAQUE | ETO_CLIPPED,
  1701. &rClipRect,
  1702. szText, lstrlen(szText),
  1703. NULL);
  1704. BitBlt( pDraw->hDC,
  1705. pDraw->rcItem.left,
  1706. pDraw->rcItem.top,
  1707. (pDraw->rcItem.right - pDraw->rcItem.left),
  1708. (pDraw->rcItem.bottom - pDraw->rcItem.top)+1,
  1709. hDC,
  1710. 0,0,
  1711. SRCCOPY);
  1712. SelectObject(hDC,hOldBmp);
  1713. SelectObject(hDC,hFont);
  1714. DeleteObject(hBmp);
  1715. DeleteDC(hDC);
  1716. }
  1717. break;
  1718. }
  1719. return CView::MsgProc(uMsg,wParam,lParam);
  1720. }
  1721. void CDBView::GenerateTreeToolTip(PDBTREETIP pTip, LPTSTR szText)
  1722. {
  1723. if ( NULL != pTip )
  1724. switch ( pTip->uType ) {
  1725. case ENTRY_SHIM:
  1726. {
  1727. PSHIMDESC pShim = pTip->pShim;
  1728. if (NULL == pShim ) {
  1729. return;
  1730. }
  1731. if ( 0 != pShim->szShimDesc.Length() ){
  1732. lstrcpy(szText,pShim->szShimDesc);
  1733. }else{
  1734. if (pShim->bGeneral == false) {
  1735. lstrcpy(szText,TEXT("No description available"));
  1736. }
  1737. }
  1738. }
  1739. break;
  1740. case ENTRY_APPHELP:
  1741. {
  1742. PHELPENTRY pHelp = pTip->pHelp;
  1743. TCHAR * szToolHelp[] = {
  1744. TEXT("No application help is available. Nothing will be done."),
  1745. TEXT("An update may be available for the application.\nThis application will execute."),
  1746. TEXT("This application is not allowed to execute\non this machine."),
  1747. TEXT("This application will run with minor problems."),
  1748. TEXT("The application needs to be reinstalled."),
  1749. TEXT("Versionsub"),
  1750. TEXT("Shim")};
  1751. if ( NULL != pHelp )
  1752. lstrcpy(szText,szToolHelp[pHelp->uSeverity]);
  1753. }
  1754. break;
  1755. case ENTRY_MATCH:
  1756. {
  1757. PMATCHENTRY pMatch = pTip->pMatch;
  1758. TCHAR szTemp[1024];
  1759. wsprintf(szText,TEXT("Match File: %s\n"),pMatch->szMatchName);
  1760. if ( lstrlen(pMatch->szDescription) > 0 ) {
  1761. wsprintf(szTemp,TEXT("Description: %s\n"),pMatch->szDescription);
  1762. lstrcat(szText,szTemp);
  1763. }
  1764. if ( lstrlen(pMatch->szCompanyName) > 0 ) {
  1765. wsprintf(szTemp,TEXT("Company Name: %s\n"),pMatch->szCompanyName);
  1766. lstrcat(szText,szTemp);
  1767. }
  1768. if ( pMatch->dwSize > 0 ) {
  1769. TCHAR szSize[80];
  1770. FormatFileSize(pMatch->dwSize,szSize);
  1771. wsprintf(szTemp,TEXT("File Size: %s bytes\n"),szSize);
  1772. lstrcat(szText,szTemp);
  1773. }
  1774. if ( pMatch->dwChecksum > 0 ) {
  1775. wsprintf(szTemp,TEXT("Checksum: %08X\n"),pMatch->dwChecksum);
  1776. lstrcat(szText,szTemp);
  1777. }
  1778. if ( lstrlen(pMatch->szProductVersion) > 0 ) {
  1779. wsprintf(szTemp,TEXT("Product Version: %s\n"),pMatch->szProductVersion);
  1780. lstrcat(szText,szTemp);
  1781. }
  1782. if ( lstrlen(pMatch->szFileVersion) > 0 ) {
  1783. wsprintf(szTemp,TEXT("File Version: %s\n"),pMatch->szFileVersion);
  1784. lstrcat(szText,szTemp);
  1785. }
  1786. if ( pMatch->FileVersion.QuadPart > 0 ) {
  1787. wsprintf( szTemp,
  1788. TEXT("File Version: %u.%04u.%04u.%04u\n"),
  1789. HIWORD(pMatch->FileVersion.HighPart),
  1790. LOWORD(pMatch->FileVersion.HighPart),
  1791. HIWORD(pMatch->FileVersion.LowPart),
  1792. LOWORD(pMatch->FileVersion.LowPart));
  1793. lstrcat(szText,szTemp);
  1794. }
  1795. if ( pMatch->ProductVersion.QuadPart > 0 ) {
  1796. wsprintf( szTemp,
  1797. TEXT("Product Version: %u.%04u.%04u.%04u\n"),
  1798. HIWORD(pMatch->ProductVersion.HighPart),
  1799. LOWORD(pMatch->ProductVersion.HighPart),
  1800. HIWORD(pMatch->ProductVersion.LowPart),
  1801. LOWORD(pMatch->ProductVersion.LowPart));
  1802. lstrcat(szText,szTemp);
  1803. }
  1804. // Terminate 1 character early... effectively removing
  1805. // the very last <CR>.
  1806. szText[lstrlen(szText)-1] = 0;
  1807. }
  1808. break;
  1809. }
  1810. }
  1811. void FormatFileSize(UINT uSize, LPTSTR szText)
  1812. {
  1813. DWORD dwSize = uSize;
  1814. DWORD dwMax = 1000000000;
  1815. BOOL bFirst = TRUE;
  1816. szText[0] = 0;
  1817. while ( dwSize > 0 ) {
  1818. if ( dwSize / dwMax > 0 ) {
  1819. TCHAR szTemp[5];
  1820. if ( bFirst )
  1821. wsprintf(szTemp,TEXT("%d,"),dwSize/dwMax);
  1822. else
  1823. wsprintf(szTemp,TEXT("%03d,"),dwSize/dwMax);
  1824. bFirst = FALSE;
  1825. lstrcat(szText,szTemp);
  1826. }
  1827. dwSize -= (dwSize / dwMax) * dwMax;
  1828. dwMax /= 1000;
  1829. }
  1830. szText[lstrlen(szText)-1] = 0;
  1831. }
  1832. void FormatVersion(LARGE_INTEGER liVer, LPTSTR szText)
  1833. {
  1834. wsprintf( szText,
  1835. TEXT("%u.%u.%u.%u"),
  1836. HIWORD(liVer.HighPart),
  1837. LOWORD(liVer.HighPart),
  1838. HIWORD(liVer.LowPart),
  1839. LOWORD(liVer.LowPart));
  1840. }
  1841. HTREEITEM CDBView::AddTreeItem(HTREEITEM hParent,DWORD dwFlags,DWORD dwState,LPCTSTR szText,UINT uImage, LPARAM lParam)
  1842. {
  1843. TVINSERTSTRUCT Item;
  1844. Item.hParent = hParent;
  1845. Item.hInsertAfter = TVI_LAST;
  1846. Item.item.mask = dwFlags;
  1847. Item.item.stateMask = dwState;
  1848. Item.item.state = dwState;
  1849. Item.item.pszText = (LPTSTR) szText;
  1850. Item.item.cchTextMax = lstrlen(Item.item.pszText);
  1851. Item.item.iImage = uImage;
  1852. Item.item.iSelectedImage = Item.item.iImage;
  1853. Item.item.lParam = lParam;
  1854. return TreeView_InsertItem(m_hTreeView,&Item);
  1855. }
  1856. UINT CDBView::LookupFileImage(LPCTSTR szFilename, UINT uDefault)
  1857. {
  1858. return uDefault;
  1859. SHFILEINFO Info;
  1860. HIMAGELIST hList;
  1861. UINT uImage;
  1862. ZeroMemory(&Info,sizeof(Info));
  1863. hList = (HIMAGELIST) SHGetFileInfo(szFilename,FILE_ATTRIBUTE_NORMAL,&Info,sizeof(Info),SHGFI_ICON | SHGFI_SMALLICON | SHGFI_USEFILEATTRIBUTES);
  1864. if ( NULL != hList ) {
  1865. if ( 0 == m_uImageRedirector[Info.iIcon] )
  1866. m_uImageRedirector[Info.iIcon] = ImageList_AddIcon(m_hImageList,Info.hIcon);
  1867. uImage = m_uImageRedirector[Info.iIcon];
  1868. } else
  1869. uImage = uDefault;
  1870. return uImage;
  1871. }
  1872. void CDBView::WriteFlagsToTree(HTREEITEM hParent, DWORD dwFlags)
  1873. {
  1874. //
  1875. // NOT USED ANYWHERE !!!
  1876. //
  1877. if ( 0 != (dwFlags & SHIMREG_DISABLE_SHIM) ) {
  1878. AddTreeItem(hParent,
  1879. TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE,
  1880. 0,
  1881. TEXT("Disable Shims"),
  1882. IMAGE_WARNING);
  1883. }
  1884. if ( 0 != (dwFlags & SHIMREG_DISABLE_APPHELP) ) {
  1885. AddTreeItem(hParent,
  1886. TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE,
  1887. 0,
  1888. TEXT("Disable App Help"),
  1889. IMAGE_WARNING);
  1890. }
  1891. if ( 0 != (dwFlags & SHIMREG_DISABLE_LAYER) ) {
  1892. AddTreeItem(hParent,
  1893. TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE,
  1894. 0,
  1895. TEXT("Disable Layer"),
  1896. IMAGE_WARNING);
  1897. }
  1898. if ( 0 != (dwFlags & SHIMREG_APPHELP_NOUI) ) {
  1899. AddTreeItem(hParent,
  1900. TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE,
  1901. 0,
  1902. TEXT("Disable UI"),
  1903. IMAGE_WARNING);
  1904. }
  1905. }
  1906. BOOL CALLBACK DisableDialog(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
  1907. {
  1908. switch ( uMsg ) {
  1909. case WM_INITDIALOG:
  1910. {
  1911. SetWindowLongPtr(hDlg,GWLP_USERDATA,lParam);
  1912. if ( 0 != (lParam & SHIMREG_DISABLE_SHIM) )
  1913. SendDlgItemMessage(hDlg,IDC_SHIMS,BM_SETCHECK,BST_CHECKED,0);
  1914. if ( 0 != (lParam & SHIMREG_DISABLE_APPHELP) )
  1915. SendDlgItemMessage(hDlg,IDC_APPHELP,BM_SETCHECK,BST_CHECKED,0);
  1916. if ( 0 != (lParam & SHIMREG_DISABLE_LAYER) )
  1917. SendDlgItemMessage(hDlg,IDC_LAYERS,BM_SETCHECK,BST_CHECKED,0);
  1918. if ( 0 != (lParam & SHIMREG_APPHELP_NOUI) )
  1919. SendDlgItemMessage(hDlg,IDC_HELPUI,BM_SETCHECK,BST_CHECKED,0);
  1920. if ( 0 != (lParam & 0x80000000) )
  1921. SetWindowText(hDlg,TEXT("Set user specific app flags"));
  1922. else
  1923. SetWindowText(hDlg,TEXT("Set global application flags"));
  1924. }
  1925. return TRUE;
  1926. case WM_COMMAND:
  1927. switch ( LOWORD(wParam) ) {
  1928. case IDC_DISABLEALL:
  1929. {
  1930. SendDlgItemMessage(hDlg,IDC_SHIMS,BM_SETCHECK,BST_CHECKED,0);
  1931. SendDlgItemMessage(hDlg,IDC_APPHELP,BM_SETCHECK,BST_CHECKED,0);
  1932. SendDlgItemMessage(hDlg,IDC_LAYERS,BM_SETCHECK,BST_CHECKED,0);
  1933. SendDlgItemMessage(hDlg,IDC_HELPUI,BM_SETCHECK,BST_CHECKED,0);
  1934. }
  1935. break;
  1936. case IDOK:
  1937. {
  1938. DWORD dwFlags = 0;
  1939. // Construct final flags
  1940. dwFlags |= (SendDlgItemMessage(hDlg,IDC_SHIMS,BM_GETCHECK,0,0) == BST_CHECKED) ? SHIMREG_DISABLE_SHIM:0;
  1941. dwFlags |= (SendDlgItemMessage(hDlg,IDC_LAYERS,BM_GETCHECK,0,0) == BST_CHECKED) ? SHIMREG_DISABLE_LAYER:0;
  1942. dwFlags |= (SendDlgItemMessage(hDlg,IDC_HELPUI,BM_GETCHECK,0,0) == BST_CHECKED) ? SHIMREG_APPHELP_NOUI:0;
  1943. dwFlags |= (SendDlgItemMessage(hDlg,IDC_APPHELP,BM_GETCHECK,0,0) == BST_CHECKED) ? SHIMREG_DISABLE_APPHELP:0;
  1944. // Terminate the dialog.
  1945. EndDialog(hDlg,dwFlags);
  1946. }
  1947. break;
  1948. case IDCANCEL:
  1949. {
  1950. DWORD dwState = GetWindowLongPtr(hDlg, GWLP_USERDATA);
  1951. EndDialog(hDlg,dwState);
  1952. }
  1953. break;
  1954. }
  1955. break;
  1956. }
  1957. return FALSE;
  1958. }
  1959. void CDBView::SyncStates(UINT uMenuCMD, UINT uToolCmd, BOOL bToolbar, BOOL bToggle)
  1960. {
  1961. BOOL bOn = FALSE;
  1962. /*
  1963. if (bToolbar)
  1964. bOn = SendMessage(g_theApp.m_hToolBar,TB_ISBUTTONCHECKED,uToolCmd,0) ? TRUE:FALSE;
  1965. else
  1966. {
  1967. */
  1968. UINT uState = GetMenuState(m_hMenu,uMenuCMD,MF_BYCOMMAND);
  1969. bOn = (0 != (uState & MF_CHECKED)) ? TRUE:FALSE;
  1970. // }
  1971. if ( bToggle )
  1972. bOn = !bOn;
  1973. MENUITEMINFO Info;
  1974. Info.cbSize = sizeof(MENUITEMINFO);
  1975. Info.fMask = MIIM_STATE;
  1976. Info.fState = bOn ? MF_CHECKED:0;
  1977. // SendMessage(g_theApp.m_hToolBar,TB_CHECKBUTTON,uToolCmd,MAKELONG(bOn ? TRUE:FALSE,0));
  1978. SetMenuItemInfo(m_hMenu,uMenuCMD,MF_BYCOMMAND,&Info);
  1979. //return;
  1980. //Update();
  1981. }
  1982. void CDBView::SyncMenu(void)
  1983. {
  1984. //
  1985. //Enables or disables the entries in the menu
  1986. //
  1987. // This varaile reflects whether we should disable entries because we are working on the global database.
  1988. BOOL bDisableGlobal=TRUE;
  1989. if ( NULL != m_pListRecord )
  1990. bDisableGlobal = m_pListRecord->bGlobal;
  1991. else
  1992. if ( m_LocalList.m_hWnd == GetFocus() )
  1993. bDisableGlobal = FALSE;
  1994. MENUITEMINFO Info;
  1995. Info.cbSize = sizeof(MENUITEMINFO);
  1996. Info.fMask = MIIM_STATE;
  1997. Info.fState = bDisableGlobal ? MFS_DISABLED:MFS_ENABLED;
  1998. //
  1999. //Disable the enties if we are working on a global database.
  2000. //
  2001. SetMenuItemInfo(m_hMenu,ID_DATABASE_CHANGEDATABASENAME,MF_BYCOMMAND,&Info);
  2002. //SetMenuItemInfo(m_hMenu,ID_DATABASE_ADDANENTRY,MF_BYCOMMAND,&Info);
  2003. SetMenuItemInfo(m_hMenu,ID_DATABASE_DEFINECUSTOMLAYER,MF_BYCOMMAND,&Info);
  2004. SetMenuItemInfo(m_hMenu,ID_DATABASE_CREATENEWAPPHELPMESSAGE,MF_BYCOMMAND,&Info);
  2005. SetMenuItemInfo(m_hMenu,ID_FILE_SAVEDATABASE,MF_BYCOMMAND,&Info);
  2006. SetMenuItemInfo(m_hMenu,ID_FILE_SAVEDATABASEAS,MF_BYCOMMAND,&Info);
  2007. Info.fState = MFS_DISABLED;
  2008. SetMenuItemInfo(m_hMenu,ID_DATABASE_EDITCUSTOMCOMPATIBILITYMODE,MF_BYCOMMAND,&Info);
  2009. SetMenuItemInfo(m_hMenu,ID_DATABASE_REMOVECUSTOMCOMPATIBILITYMODE,MF_BYCOMMAND,&Info);
  2010. //
  2011. //Disable add matching, removing matching, remove entry
  2012. //
  2013. SetMenuItemInfo(m_hMenu,ID_EDIT_ADDMATCHINGINFORMATION,MF_BYCOMMAND,&Info);
  2014. SetMenuItemInfo(m_hMenu,ID_EDIT_REMOVEMATCHINGINFORMATION,MF_BYCOMMAND,&Info);
  2015. SetMenuItemInfo(m_hMenu,ID_DATABASE_REMOVEENTRY,MF_BYCOMMAND,&Info);
  2016. if ( !bDisableGlobal ) {
  2017. HTREEITEM hItem;
  2018. Info.cbSize = sizeof(MENUITEMINFO);
  2019. Info.fMask = MIIM_STATE;
  2020. Info.fState = MFS_ENABLED;
  2021. // Determine if file matching stuff is presently selected to enable remove.
  2022. hItem = TreeView_GetSelection(m_hTreeView);
  2023. if ( NULL != hItem ) {
  2024. TVITEM Item;
  2025. Item.mask = TVIF_PARAM;
  2026. Item.hItem = hItem;
  2027. TreeView_GetItem(m_hTreeView,&Item);
  2028. PDBTREETIP pTip = (PDBTREETIP) Item.lParam;
  2029. // The tip is only valid if not on the root.
  2030. if ( NULL != pTip && NULL != TreeView_GetParent(m_hTreeView,hItem) )
  2031. if ( 1 == pTip->uContext )
  2032. SetMenuItemInfo(m_hMenu,ID_EDIT_REMOVEMATCHINGINFORMATION,MF_BYCOMMAND,&Info);
  2033. }
  2034. // Determine if we can edit or remove compat modes
  2035. PDBLAYER pWalk = g_theApp.GetDBLocal().m_pLayerList;
  2036. while ( NULL != pWalk ) {
  2037. if ( !pWalk->bPermanent )
  2038. break;
  2039. pWalk = pWalk->pNext;
  2040. }
  2041. if ( NULL != pWalk ) {
  2042. SetMenuItemInfo(m_hMenu,ID_DATABASE_EDITCUSTOMCOMPATIBILITYMODE,MF_BYCOMMAND,&Info);
  2043. SetMenuItemInfo(m_hMenu,ID_DATABASE_REMOVECUSTOMCOMPATIBILITYMODE,MF_BYCOMMAND,&Info);
  2044. }
  2045. // Determine if we can remove the entry
  2046. if ( NULL != m_pCurrentRecord ) {
  2047. SetMenuItemInfo(m_hMenu,ID_EDIT_ADDMATCHINGINFORMATION,MF_BYCOMMAND,&Info);
  2048. SetMenuItemInfo(m_hMenu,ID_DATABASE_REMOVEENTRY,MF_BYCOMMAND,&Info);
  2049. }
  2050. }
  2051. if ( NULL == m_pCurrentRecord )
  2052. Info.fState = MFS_DISABLED;
  2053. else
  2054. Info.fState = MFS_ENABLED;
  2055. SetMenuItemInfo(m_hMenu,ID_TEST_TESTRUN,MF_BYCOMMAND,&Info);
  2056. SetMenuItemInfo(m_hMenu,ID_EDIT_ENABLEDISABLEGLOBALLY,MF_BYCOMMAND,&Info);
  2057. SetMenuItemInfo(m_hMenu,ID_EDIT_ENABLEDISABLELOCALLY,MF_BYCOMMAND,&Info);
  2058. if ( NULL != m_pCurrentRecord ) {
  2059. // Find this one and make sure it's selected.
  2060. if ( NULL == TreeView_GetSelection(m_hTreeView) ) {
  2061. HTREEITEM hItem = TreeView_GetRoot(m_hTreeView);
  2062. TVITEM Item;
  2063. while ( NULL != hItem ) {
  2064. Item.mask = TVIF_PARAM;
  2065. Item.hItem = hItem;
  2066. TreeView_GetItem(m_hTreeView,&Item);
  2067. if ( Item.lParam == (LPARAM) m_pCurrentRecord ) {
  2068. TreeView_SelectItem(m_hTreeView,hItem);
  2069. break;
  2070. }
  2071. hItem = TreeView_GetNextItem(m_hTreeView,hItem,TVGN_NEXT);
  2072. }
  2073. }
  2074. }
  2075. }