Leaked source code of windows server 2003
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.

2441 lines
60 KiB

  1. #include "Main.h"
  2. #include "KernelMode.h"
  3. #include "UserMode.h"
  4. #include "WinMessages.h"
  5. #include "resource.h"
  6. #include "clist.h"
  7. #include "cuserlist.h"
  8. #include "reportFault.h"
  9. #include "CERHELP.h"
  10. HWND g_hWnd;
  11. HINSTANCE g_hinst;
  12. HWND hKrnlMode = NULL;
  13. HWND hUserMode = NULL;
  14. KMODE_DATA KModeData;
  15. TCHAR CerRoot[MAX_PATH];
  16. HWND LoadThreadParam = NULL;
  17. MRU_LIST MruList;
  18. Clist CsvContents;
  19. CUserList cUserData;
  20. GLOBAL_POLICY GlobalPolicy;
  21. BOOL g_bFirstBucket = TRUE;
  22. BOOL g_bAdminAccess = TRUE;
  23. TCHAR szUserColumnHeaders[][100] =
  24. { _T("Bucket ID"),
  25. _T("App. Name"),
  26. _T("App. Ver"),
  27. _T("Module Name"),
  28. _T("Module Version"),
  29. _T("Offset"),
  30. _T("Hits"),
  31. _T("Cabs Collected"),
  32. _T("Cabs Not Reported"),
  33. _T("Requested Collection"),
  34. _T("Allowed Collection"),
  35. _T("Microsoft Response"),
  36. _T("URL to Launch")
  37. };
  38. TCHAR szKerenelColumnHeaders[][100] =
  39. { _T("BucketID"),
  40. _T("Cabs Collected"),
  41. _T("Microsoft Response")
  42. };
  43. BOOL GetFileName(HWND hwnd, TCHAR *FileName, int iType)
  44. {
  45. OPENFILENAME opfn;
  46. // if we are running on NT4.0 use sizeof (OPENFILENAME_SIZE_VERSION_400)
  47. ZeroMemory (&opfn, sizeof OPENFILENAME );
  48. opfn.lStructSize = sizeof OPENFILENAME;
  49. opfn.hwndOwner = hwnd;
  50. opfn.nMaxFileTitle = MAX_PATH * sizeof TCHAR;
  51. opfn.lpstrFileTitle = FileName;
  52. opfn.lpstrFilter=_T("*.TXT");
  53. opfn.nFilterIndex = iType;
  54. opfn.Flags = OFN_CREATEPROMPT | OFN_OVERWRITEPROMPT | OFN_OVERWRITEPROMPT;
  55. if (GetSaveFileName((LPOPENFILENAME) &opfn))
  56. return TRUE;
  57. else
  58. return FALSE;
  59. }
  60. void ExportUserModeData(HWND hwnd)
  61. {
  62. TCHAR szFileName[MAX_PATH];
  63. int iFileType = 1;
  64. TCHAR tchDelimiter = _T(',');
  65. HANDLE hFile = INVALID_HANDLE_VALUE;
  66. USER_DATA UserData;
  67. DWORD dwWritten = 0;
  68. BOOL bEOF = FALSE;
  69. ZeroMemory (szFileName, sizeof szFileName);
  70. if ( !GetFileName(hwnd, szFileName, iFileType))
  71. {
  72. goto ERRORS;
  73. }
  74. if (iFileType == 3)
  75. {
  76. //determine the max column widths
  77. goto ERRORS;
  78. }
  79. if (iFileType == 1)
  80. {
  81. tchDelimiter = _T(',');
  82. }
  83. if (iFileType == 2)
  84. {
  85. tchDelimiter = _T('\t');
  86. }
  87. // Write out the data
  88. hFile = CreateFile (szFileName,
  89. GENERIC_WRITE,
  90. FILE_SHARE_READ,
  91. NULL,
  92. CREATE_ALWAYS,
  93. FILE_ATTRIBUTE_NORMAL,
  94. NULL);
  95. if (hFile == INVALID_HANDLE_VALUE)
  96. goto ERRORS;
  97. for (int i = 0; i < USER_COL_COUNT; i++)
  98. {
  99. WriteFile(hFile, szUserColumnHeaders[i], _tcslen(szUserColumnHeaders[i]) *sizeof TCHAR, &dwWritten, NULL);
  100. }
  101. CloseHandle (hFile);
  102. //loop through the linked list and write the data to the output file
  103. cUserData.ResetCurrPos();
  104. while (cUserData.GetNextEntry(&UserData, &bEOF))
  105. {
  106. // write the output buffer to the file
  107. ;
  108. }
  109. ERRORS:
  110. ;
  111. }
  112. void ExportKernelModeData(HWND hwnd)
  113. {
  114. TCHAR FileName[MAX_PATH];
  115. int iType = 0;
  116. GetFileName(hwnd, FileName, iType);
  117. }
  118. typedef enum REPORTING_MODES {USER_MODE, KERNEL_MODE,GENERAL_MODE};
  119. REPORTING_MODES ReportMode = USER_MODE;
  120. DLGTEMPLATE * WINAPI DoLockDlgRes(LPCSTR lpszResName)
  121. {
  122. HRSRC hrsrc = FindResource(NULL, lpszResName, RT_DIALOG);
  123. if (hrsrc)
  124. {
  125. HGLOBAL hglb = LoadResource(g_hinst, hrsrc);
  126. return (DLGTEMPLATE *) LockResource(hglb);
  127. }
  128. else
  129. {
  130. return NULL;
  131. }
  132. }
  133. void DoKernelMode(HWND hwnd)
  134. {
  135. TCHAR DialogTitle[255];
  136. DLGTEMPLATE *Temp = NULL;
  137. if (_tcscmp(CerRoot, _T("\0")))
  138. {
  139. if (StringCbPrintf(DialogTitle, sizeof DialogTitle, _T("Corporate Error Reporting - KERNEL MODE - %s"), CerRoot)!= S_OK)
  140. {
  141. goto ERRORS;
  142. }
  143. }
  144. else
  145. {
  146. if (StringCbPrintf(DialogTitle, sizeof DialogTitle, _T("Corporate Error Reporting - KERNEL MODE")) != S_OK)
  147. {
  148. goto ERRORS;
  149. }
  150. }
  151. SendMessage(hwnd, WM_SETTEXT, 0, (LPARAM)DialogTitle);
  152. if (ReportMode != KERNEL_MODE)
  153. {
  154. ReportMode = KERNEL_MODE;
  155. if (hKrnlMode == NULL)
  156. {
  157. Temp = DoLockDlgRes(MAKEINTRESOURCE(IDD_KERNEL_MODE));
  158. if (Temp)
  159. {
  160. hKrnlMode = CreateDialogIndirect(g_hinst,Temp , hwnd, (DLGPROC) KrnlDlgProc);
  161. }
  162. }
  163. else
  164. {
  165. HMENU hMenu = GetMenu(hwnd);
  166. if (hMenu)
  167. {
  168. EnableMenuItem (hMenu, ID_REPORT_SELECTEDCRASHES , MF_BYCOMMAND| MF_GRAYED);
  169. }
  170. ShowWindow(hKrnlMode,1);
  171. }
  172. if (hUserMode != NULL)
  173. {
  174. ShowWindow(hUserMode,0);
  175. }
  176. }
  177. ERRORS:
  178. return;
  179. }
  180. void DoUserMode(HWND hwnd)
  181. {
  182. TCHAR DialogTitle[255];
  183. DLGTEMPLATE *Temp = NULL;
  184. if (_tcscmp(CerRoot, _T("\0")))
  185. {
  186. if (StringCbPrintf(DialogTitle, sizeof DialogTitle, _T("Corporate Error Reporting - USER MODE - %s"), CerRoot)!= S_OK)
  187. {
  188. goto ERRORS;
  189. }
  190. }
  191. else
  192. {
  193. if (StringCbPrintf(DialogTitle, sizeof DialogTitle, _T("Corporate Error Reporting - USER MODE")) != S_OK)
  194. {
  195. goto ERRORS;
  196. }
  197. }
  198. SendMessage(hwnd, WM_SETTEXT, 0, (LPARAM)DialogTitle);
  199. if (ReportMode != USER_MODE)
  200. {
  201. ReportMode = USER_MODE;
  202. if (hUserMode == NULL)
  203. {
  204. Temp = DoLockDlgRes(MAKEINTRESOURCE(IDD_USER_MODE));
  205. if (Temp)
  206. {
  207. hUserMode = CreateDialogIndirect(g_hinst,Temp , hwnd, (DLGPROC) UserDlgProc);
  208. }
  209. }
  210. else
  211. {
  212. HMENU hMenu = GetMenu(hwnd);
  213. if (hMenu)
  214. {
  215. if (_tcscmp(CerRoot, _T("\0")))
  216. {
  217. EnableMenuItem (hMenu, ID_REPORT_SELECTEDCRASHES , MF_BYCOMMAND| MF_ENABLED);
  218. }
  219. }
  220. ShowWindow(hUserMode,1);
  221. }
  222. if (hKrnlMode != NULL)
  223. {
  224. ShowWindow(hKrnlMode,0);
  225. }
  226. }
  227. ERRORS:
  228. return;
  229. }
  230. BOOL FileSystemIsNTFS(TCHAR *szPath)
  231. {
  232. TCHAR szPathToValidate[MAX_PATH];
  233. TCHAR szType[50];
  234. ZeroMemory (szPathToValidate, sizeof szPathToValidate);
  235. ZeroMemory (szType, sizeof szType);
  236. if (StringCbCopy (szPathToValidate, sizeof szPathToValidate, szPath) != S_OK)
  237. goto ERRORS;
  238. PathStripToRoot(szPathToValidate);
  239. // add a \ if one is not found
  240. if (_tcslen (szPathToValidate ) > 1)
  241. {
  242. if (szPathToValidate[_tcslen(szPathToValidate)-1] != _T('\\'))
  243. {
  244. if (StringCbCat(szPathToValidate, sizeof szPathToValidate, _T("\\"))!= S_OK)
  245. goto ERRORS;
  246. }
  247. if (GetVolumeInformation(szPathToValidate, NULL, 0, NULL, 0, NULL, szType, sizeof szType / sizeof TCHAR))
  248. {
  249. if (!_tcscmp(szType, _T("NTFS")))
  250. {
  251. return TRUE;
  252. }
  253. }
  254. }
  255. ERRORS:
  256. return FALSE;
  257. }
  258. int CALLBACK BrowseCallbackProc(
  259. HWND hwnd,
  260. UINT uMsg,
  261. LPARAM lParam,
  262. LPARAM lpData
  263. )
  264. {
  265. TCHAR Msg [100];
  266. switch (uMsg)
  267. {
  268. case BFFM_VALIDATEFAILEDW:
  269. {
  270. if (StringCbPrintf(Msg, sizeof Msg, _T("The selected directory is not valid.\r\nPlease select another directory."))!= S_OK)
  271. {
  272. goto ERRORS;
  273. }
  274. MessageBox(hwnd, Msg, NULL,MB_OK);
  275. return 1;
  276. }
  277. default:
  278. return 0;
  279. }
  280. ERRORS:
  281. return 0;
  282. }
  283. void DoCreateFileTree(HWND hwnd)
  284. /*
  285. */
  286. {
  287. TCHAR szSubDir[MAX_PATH];
  288. DWORD ErrorCode;
  289. WCHAR wzPath[MAX_PATH];
  290. BROWSEINFOW bi;
  291. ACL *NewAcl;
  292. EXPLICIT_ACCESS eAccess[3];
  293. TCHAR szPath[MAX_PATH];
  294. ULARGE_INTEGER FreeBytesAvailable;
  295. ULARGE_INTEGER TotalFreeBytes ;
  296. ULARGE_INTEGER TotalBytes ;
  297. LPMALLOC pMalloc = NULL;
  298. PSID pSidAdministrators = NULL;
  299. PSID pSidEveryone = NULL;
  300. ZeroMemory (&bi, sizeof BROWSEINFOW);
  301. bi.hwndOwner = hwnd;
  302. bi.pidlRoot = NULL;
  303. bi.pszDisplayName = wzPath;
  304. bi.lpszTitle = L"Select a file share to be used as the root of the CER file tree...";
  305. bi.ulFlags = BIF_USENEWUI | BIF_RETURNONLYFSDIRS | BIF_EDITBOX | BIF_VALIDATE;
  306. bi.lpfn = BrowseCallbackProc;
  307. SID_IDENTIFIER_AUTHORITY pSIANTAuth = SECURITY_NT_AUTHORITY;
  308. SID_IDENTIFIER_AUTHORITY pSIAWorld = SECURITY_WORLD_SID_AUTHORITY;
  309. CoInitialize(NULL);
  310. ZeroMemory (wzPath, sizeof wzPath);
  311. ITEMIDLIST *pidl = SHBrowseForFolderW(&bi);
  312. if (SHGetMalloc(&pMalloc) == E_FAIL)
  313. {
  314. // we couldn't get to the shell
  315. MessageBox(hwnd, _T("Failed to open the selected directory"), NULL,MB_OK);
  316. goto DONE;
  317. }
  318. if (!wcscmp(wzPath, L"My Documents"))
  319. {
  320. MessageBox(hwnd, _T("Failed to open the selected directory"), NULL,MB_OK);
  321. goto DONE;
  322. }
  323. ZeroMemory(&FreeBytesAvailable, sizeof ULARGE_INTEGER);
  324. ZeroMemory(&TotalFreeBytes, sizeof ULARGE_INTEGER);
  325. ZeroMemory(&TotalBytes, sizeof ULARGE_INTEGER);
  326. if (pidl != NULL)
  327. {
  328. if (SHGetPathFromIDList(pidl, szPath))
  329. {
  330. if (StringCbCopy (CerRoot,sizeof CerRoot, szPath) != S_OK)
  331. {
  332. goto ERRORS;
  333. }
  334. if (PathIsDirectory(szPath))
  335. {
  336. if (!FileSystemIsNTFS(szPath))
  337. {
  338. MessageBox(hwnd, _T("The CER tree can only be created on an NTFS file system"), NULL, MB_OK);
  339. goto DONE;
  340. }
  341. // Now check for space
  342. if (!GetDiskFreeSpaceEx(szPath, &FreeBytesAvailable, &TotalBytes,&TotalFreeBytes))
  343. {
  344. // We were unable to retrieve the space info.
  345. // Now what.
  346. goto ERRORS;
  347. }
  348. else
  349. {
  350. if (FreeBytesAvailable.QuadPart < 2000000000)
  351. {
  352. MessageBox(hwnd, _T("There is not enough free space to create a CER tree.\r\nA minimum of 2GB free space is required."), NULL, MB_OK);
  353. goto DONE;
  354. }
  355. }
  356. // Builtin\Administrators
  357. AllocateAndInitializeSid(&pSIANTAuth, 2, SECURITY_BUILTIN_DOMAIN_RID, DOMAIN_ALIAS_RID_ADMINS, 0, 0, 0, 0, 0, 0, &pSidAdministrators);
  358. // Everyone
  359. AllocateAndInitializeSid(&pSIAWorld, 1, SECURITY_WORLD_RID, 0, 0, 0, 0, 0, 0, 0, &pSidEveryone);
  360. // Create the cabs subdirectory
  361. if (StringCbPrintf(szSubDir, sizeof szSubDir, _T("%s\\Cabs"), szPath) != S_OK)
  362. {
  363. goto ERRORS;
  364. }
  365. if ( !CreateDirectory(szSubDir,NULL))
  366. {
  367. ErrorCode = 2;
  368. goto ERRORS;
  369. }
  370. else
  371. {
  372. // Set Everyone = WriteAccess
  373. ZeroMemory (eAccess, sizeof EXPLICIT_ACCESS);
  374. eAccess[0].grfAccessMode = SET_ACCESS;
  375. eAccess[0].grfInheritance = SUB_CONTAINERS_AND_OBJECTS_INHERIT ;
  376. eAccess[0].grfAccessPermissions = FILE_APPEND_DATA | FILE_WRITE_DATA | FILE_WRITE_ATTRIBUTES | FILE_WRITE_EA ;
  377. //eAccess[1].Trustee.TrusteeForm = TRUSTEE_IS_NAME;
  378. eAccess[0].Trustee.TrusteeForm = TRUSTEE_IS_SID;
  379. eAccess[0].Trustee.TrusteeType = TRUSTEE_IS_GROUP;
  380. //eAccess[1].Trustee.ptstrName = _T("Everyone");
  381. eAccess[0].Trustee.ptstrName = (LPTSTR) pSidEveryone;
  382. eAccess[2].grfAccessMode = SET_ACCESS;
  383. eAccess[2].grfInheritance = SUB_CONTAINERS_AND_OBJECTS_INHERIT ;
  384. eAccess[2].grfAccessPermissions = GENERIC_ALL;
  385. eAccess[2].Trustee.TrusteeForm = TRUSTEE_IS_SID;
  386. eAccess[2].Trustee.TrusteeType = TRUSTEE_IS_GROUP;
  387. //eAccess[2].Trustee.ptstrName = _T("Administrators");
  388. eAccess[2].Trustee.ptstrName = (LPTSTR) pSidAdministrators;
  389. eAccess[1].grfAccessMode = SET_ACCESS;
  390. eAccess[1].grfInheritance =CONTAINER_INHERIT_ACE ;
  391. eAccess[1].grfAccessPermissions = FILE_EXECUTE | GENERIC_READ | FILE_LIST_DIRECTORY;
  392. eAccess[1].Trustee.TrusteeForm = TRUSTEE_IS_SID;
  393. eAccess[1].Trustee.TrusteeType = TRUSTEE_IS_GROUP;
  394. eAccess[1].Trustee.ptstrName = (LPTSTR) pSidEveryone;
  395. SetEntriesInAcl( 3, eAccess, NULL, &NewAcl);
  396. ErrorCode = SetNamedSecurityInfo(szSubDir,
  397. SE_FILE_OBJECT,
  398. DACL_SECURITY_INFORMATION |
  399. PROTECTED_DACL_SECURITY_INFORMATION |
  400. PROTECTED_SACL_SECURITY_INFORMATION,
  401. NULL,
  402. NULL,
  403. NewAcl,
  404. NULL) != ERROR_SUCCESS;
  405. if (ErrorCode != ERROR_SUCCESS)
  406. {
  407. LocalFree((HLOCAL) NewAcl);
  408. goto ERRORS;
  409. }
  410. else
  411. LocalFree((HLOCAL) NewAcl);
  412. }
  413. // Create the counts SubDirecotry
  414. if (StringCbPrintf(szSubDir, sizeof szSubDir, _T("%s\\Counts"), szPath) != S_OK)
  415. {
  416. goto ERRORS;
  417. }
  418. if ( !CreateDirectory(szSubDir,NULL))
  419. {
  420. ErrorCode = 2;
  421. goto ERRORS;
  422. }
  423. else
  424. {
  425. // Set Everyone = WriteAccess
  426. ZeroMemory (eAccess, sizeof EXPLICIT_ACCESS);
  427. eAccess[0].grfAccessMode = SET_ACCESS;
  428. eAccess[0].grfInheritance =SUB_CONTAINERS_AND_OBJECTS_INHERIT ;
  429. eAccess[0].grfAccessPermissions = FILE_LIST_DIRECTORY | GENERIC_READ | GENERIC_WRITE | FILE_APPEND_DATA;
  430. eAccess[0].Trustee.TrusteeForm = TRUSTEE_IS_SID;
  431. eAccess[0].Trustee.TrusteeType = TRUSTEE_IS_GROUP;
  432. eAccess[0].Trustee.ptstrName = (LPTSTR) pSidEveryone;
  433. eAccess[1].grfAccessMode = SET_ACCESS;
  434. eAccess[1].grfInheritance = SUB_CONTAINERS_AND_OBJECTS_INHERIT;
  435. eAccess[1].grfAccessPermissions = GENERIC_ALL;
  436. eAccess[1].Trustee.TrusteeForm = TRUSTEE_IS_SID;
  437. eAccess[1].Trustee.TrusteeType = TRUSTEE_IS_GROUP;
  438. eAccess[1].Trustee.ptstrName = (LPTSTR) pSidAdministrators;
  439. eAccess[2].grfAccessMode = SET_ACCESS;
  440. eAccess[2].grfInheritance =CONTAINER_INHERIT_ACE ;
  441. eAccess[2].grfAccessPermissions = FILE_EXECUTE | GENERIC_READ | FILE_LIST_DIRECTORY | FILE_APPEND_DATA;
  442. eAccess[2].Trustee.TrusteeForm = TRUSTEE_IS_SID;
  443. eAccess[2].Trustee.TrusteeType = TRUSTEE_IS_GROUP;
  444. eAccess[2].Trustee.ptstrName =(LPTSTR) pSidEveryone;
  445. SetEntriesInAcl( 3, eAccess, NULL, &NewAcl);
  446. ErrorCode = SetNamedSecurityInfo(szSubDir,
  447. SE_FILE_OBJECT,
  448. DACL_SECURITY_INFORMATION |
  449. PROTECTED_DACL_SECURITY_INFORMATION |
  450. PROTECTED_SACL_SECURITY_INFORMATION,
  451. NULL,
  452. NULL,
  453. NewAcl,
  454. NULL) != ERROR_SUCCESS;
  455. if (ErrorCode != ERROR_SUCCESS)
  456. {
  457. LocalFree((HLOCAL) NewAcl);
  458. goto ERRORS;
  459. }
  460. else
  461. LocalFree((HLOCAL) NewAcl);
  462. }
  463. // Create the Status SubDirecotry
  464. if (StringCbPrintf(szSubDir, sizeof szSubDir, _T("%s\\Status"), szPath) != S_OK)
  465. {
  466. goto ERRORS;
  467. }
  468. if ( !CreateDirectory(szSubDir,NULL))
  469. {
  470. ErrorCode = 2;
  471. goto ERRORS;
  472. }
  473. else
  474. {
  475. ZeroMemory (eAccess, sizeof EXPLICIT_ACCESS);
  476. eAccess[2].grfAccessMode = SET_ACCESS;
  477. eAccess[2].grfInheritance =SUB_CONTAINERS_AND_OBJECTS_INHERIT ;
  478. eAccess[2].grfAccessPermissions = FILE_LIST_DIRECTORY | GENERIC_READ;
  479. eAccess[2].Trustee.TrusteeForm = TRUSTEE_IS_SID;
  480. eAccess[2].Trustee.TrusteeType = TRUSTEE_IS_GROUP;
  481. eAccess[2].Trustee.ptstrName = (LPTSTR) pSidEveryone;
  482. eAccess[1].grfAccessMode = SET_ACCESS;
  483. eAccess[1].grfInheritance = SUB_CONTAINERS_AND_OBJECTS_INHERIT;
  484. eAccess[1].grfAccessPermissions = GENERIC_ALL;
  485. eAccess[1].Trustee.TrusteeForm = TRUSTEE_IS_SID;
  486. eAccess[1].Trustee.TrusteeType = TRUSTEE_IS_GROUP;
  487. eAccess[1].Trustee.ptstrName = (LPTSTR) pSidAdministrators;
  488. eAccess[0].grfAccessMode = SET_ACCESS;
  489. eAccess[0].grfInheritance =CONTAINER_INHERIT_ACE ;
  490. eAccess[0].grfAccessPermissions = FILE_EXECUTE | GENERIC_READ | FILE_LIST_DIRECTORY | FILE_APPEND_DATA;
  491. eAccess[0].Trustee.TrusteeForm = TRUSTEE_IS_SID;
  492. eAccess[0].Trustee.TrusteeType = TRUSTEE_IS_GROUP;
  493. eAccess[0].Trustee.ptstrName =(LPTSTR) pSidEveryone;
  494. SetEntriesInAcl( 3, eAccess, NULL, &NewAcl);
  495. ErrorCode = SetNamedSecurityInfo(szSubDir,
  496. SE_FILE_OBJECT,
  497. DACL_SECURITY_INFORMATION |
  498. PROTECTED_DACL_SECURITY_INFORMATION |
  499. PROTECTED_SACL_SECURITY_INFORMATION,
  500. NULL,
  501. NULL,
  502. NewAcl,
  503. NULL) != ERROR_SUCCESS;
  504. if (ErrorCode != ERROR_SUCCESS)
  505. {
  506. LocalFree((HLOCAL) NewAcl);
  507. goto ERRORS;
  508. }
  509. else
  510. LocalFree((HLOCAL) NewAcl);
  511. }
  512. }
  513. }
  514. MessageBox(hwnd, szPath, _T("Successfully created CER file tree in: "), MB_OK);
  515. }
  516. if(pidl)
  517. {
  518. if (pMalloc)
  519. pMalloc->Free(pidl);
  520. }
  521. if (pMalloc)
  522. pMalloc->Release();
  523. if (pSidAdministrators)
  524. FreeSid(pSidAdministrators);
  525. if (pSidEveryone)
  526. FreeSid(pSidEveryone);
  527. CoUninitialize();
  528. return;
  529. ERRORS:
  530. MessageBox(hwnd, _T("Failed to Create CER File Tree."), NULL,MB_OK);
  531. DONE:
  532. if(pidl)
  533. {
  534. if (pMalloc)
  535. pMalloc->Free(pidl);
  536. }
  537. if (pMalloc)
  538. pMalloc->Release();
  539. if (pSidAdministrators)
  540. FreeSid(pSidAdministrators);
  541. if (pSidEveryone)
  542. FreeSid(pSidEveryone);
  543. CoUninitialize();
  544. return;
  545. }
  546. void PopulateMruList(HWND hwnd, BOOL bUpdate)
  547. {
  548. HMENU hmenu = GetSubMenu(GetMenu(hwnd), 0);
  549. HMENU hNewMenu = NULL;
  550. int iCount = 0;
  551. if (!bUpdate)
  552. {
  553. hNewMenu = CreateMenu();
  554. if (hmenu && hNewMenu)
  555. {
  556. if (_tcscmp(MruList.szMRU1, _T("\0")))
  557. {
  558. AppendMenu(hNewMenu, MF_STRING, ID_FILE_MRU1, MruList.szMRU1);
  559. ModifyMenu(hmenu, ID_FILE_RECENTFILETREES165, MF_BYCOMMAND | MF_POPUP, (UINT_PTR) hNewMenu, _T("Recent File &Trees"));
  560. if (_tcscmp(MruList.szMRU2, _T("\0")))
  561. {
  562. AppendMenu(hNewMenu, MF_STRING, ID_FILE_MRU2, MruList.szMRU2);
  563. }
  564. if (_tcscmp(MruList.szMRU3, _T("\0")))
  565. {
  566. AppendMenu(hNewMenu, MF_STRING, ID_FILE_MRU3, MruList.szMRU3);
  567. }
  568. if (_tcscmp(MruList.szMRU3, _T("\0")))
  569. {
  570. AppendMenu(hNewMenu, MF_STRING, ID_FILE_MRU4, MruList.szMRU4);
  571. }
  572. }
  573. }
  574. }
  575. else
  576. {
  577. hNewMenu= GetSubMenu(hmenu, 6);
  578. if (!hNewMenu)
  579. {
  580. hNewMenu = CreateMenu();
  581. if (_tcscmp(MruList.szMRU1, _T("\0")))
  582. {
  583. ModifyMenu(hmenu, ID_FILE_RECENTFILETREES165, MF_BYCOMMAND | MF_POPUP, (UINT_PTR) hNewMenu, _T("Recent File &Trees"));
  584. AppendMenu(hNewMenu, MF_STRING, ID_FILE_MRU1, MruList.szMRU1);
  585. }
  586. }
  587. else
  588. {
  589. iCount = GetMenuItemCount(hNewMenu);
  590. // Delete the old menu items and rebuild the menu
  591. if (iCount == 4)
  592. {
  593. DeleteMenu(hNewMenu, ID_FILE_MRU4, MF_BYCOMMAND);
  594. DeleteMenu(hNewMenu, ID_FILE_MRU3, MF_BYCOMMAND);
  595. DeleteMenu(hNewMenu, ID_FILE_MRU2, MF_BYCOMMAND);
  596. DeleteMenu(hNewMenu, ID_FILE_MRU1, MF_BYCOMMAND);
  597. AppendMenu(hNewMenu, MF_STRING, ID_FILE_MRU1, MruList.szMRU1);
  598. AppendMenu(hNewMenu, MF_STRING, ID_FILE_MRU2, MruList.szMRU2);
  599. AppendMenu(hNewMenu, MF_STRING, ID_FILE_MRU3, MruList.szMRU3);
  600. AppendMenu(hNewMenu, MF_STRING, ID_FILE_MRU4, MruList.szMRU4);
  601. }
  602. else
  603. {
  604. switch (iCount)
  605. {
  606. case 3:
  607. // display Fourth
  608. if (_tcscmp(MruList.szMRU4, _T("\0")))
  609. {
  610. AppendMenu(hNewMenu, MF_STRING, ID_FILE_MRU4, MruList.szMRU4);
  611. }
  612. break;
  613. case 2:
  614. // display third
  615. if (_tcscmp(MruList.szMRU3, _T("\0")))
  616. {
  617. AppendMenu(hNewMenu, MF_STRING, ID_FILE_MRU3, MruList.szMRU3);
  618. }
  619. break;
  620. case 1:
  621. // Display second
  622. if (_tcscmp(MruList.szMRU2, _T("\0")))
  623. {
  624. AppendMenu(hNewMenu, MF_STRING, ID_FILE_MRU2, MruList.szMRU2);
  625. }
  626. break;
  627. default:
  628. // All the slots were full we need to change the menu item
  629. ModifyMenu(hNewMenu, ID_FILE_MRU4, MF_BYCOMMAND | MF_STRING, ID_FILE_MRU4, MruList.szMRU4);
  630. ;
  631. }
  632. }
  633. }
  634. }
  635. }
  636. void OnDlgInit(HWND hwnd)
  637. {
  638. HICON hIcon = LoadIcon(g_hinst, MAKEINTRESOURCE(IDI_MAIN));
  639. if (hIcon)
  640. {
  641. SendMessage(hwnd, WM_SETICON, ICON_BIG, (LPARAM)hIcon);
  642. SendMessage(hwnd, WM_SETICON, ICON_SMALL, (LPARAM)hIcon);
  643. }
  644. if (StringCbCopy(CerRoot, sizeof CerRoot, _T("\0")) != S_OK)
  645. {
  646. goto ERRORS;
  647. }
  648. MakeHelpFileName();
  649. // Disable Menu items that cannot be accessed until a filetree is loaded
  650. HMENU hMenu = GetMenu(hwnd);
  651. if (hMenu)
  652. {
  653. //EnableMenuItem (hMenu, ID_EDIT_COPY115, MF_BYCOMMAND| MF_GRAYED);
  654. EnableMenuItem (hMenu, ID_EDIT_SELECTALL , MF_BYCOMMAND| MF_GRAYED);
  655. EnableMenuItem (hMenu, ID_EDIT_DEFAULTPOLICY , MF_BYCOMMAND| MF_GRAYED);
  656. EnableMenuItem (hMenu, ID_EDIT_SELECTEDBUCKETSPOLICY , MF_BYCOMMAND| MF_GRAYED);
  657. EnableMenuItem (hMenu, ID_REPORT_ALLCRASHES , MF_BYCOMMAND| MF_GRAYED);
  658. EnableMenuItem (hMenu, ID_REPORT_SELECTEDFAULTS , MF_BYCOMMAND| MF_GRAYED);
  659. EnableMenuItem (hMenu, ID_VIEW_BUCKETCABFILEDIRECTORY , MF_BYCOMMAND| MF_GRAYED);
  660. EnableMenuItem (hMenu, ID_VIEW_BUCKETINSTANCEDATA , MF_BYCOMMAND| MF_GRAYED);
  661. EnableMenuItem (hMenu, ID_VIEW_RESPONSESELECTED , MF_BYCOMMAND| MF_GRAYED);
  662. EnableMenuItem (hMenu, ID_VIEW_REFRESH , MF_BYCOMMAND| MF_GRAYED);
  663. //EnableMenuItem (hMenu, ID_FILE_EXPORTBUCKETS , MF_BYCOMMAND| MF_GRAYED);
  664. //EnableMenuItem (hMenu, ID_FILE_EXPORTSELECTEDBUCKETS , MF_BYCOMMAND| MF_GRAYED);
  665. EnableMenuItem (hMenu, ID_FILE_RELOADFILETREE, MF_BYCOMMAND| MF_GRAYED);
  666. EnableMenuItem (hMenu, ID_REPORT_USERMODEFAULTS, MF_BYCOMMAND | MF_GRAYED);
  667. EnableMenuItem (hMenu, ID_REPORT_KERNELMODEFAULTS, MF_BYCOMMAND | MF_GRAYED);
  668. EnableMenuItem (hMenu, ID_VIEW_CRASHLOG, MF_BYCOMMAND | MF_GRAYED);
  669. // EnableMenuItem (hMenu, ID_EXPORT_USERMODEBUCKETDATA, MF_BYCOMMAND | MF_GRAYED);
  670. // EnableMenuItem (hMenu, ID_EXPORT_KERNELMODEFAULTDATA, MF_BYCOMMAND | MF_GRAYED);
  671. }
  672. // Create the User and Kernel mode dialog boxes.
  673. ReportMode = USER_MODE;
  674. DoKernelMode(hwnd);
  675. ReportMode = KERNEL_MODE;
  676. DoUserMode(hwnd);
  677. if (LoadMruList())
  678. {
  679. //Populate the file menu with the mrulist;
  680. PopulateMruList(hwnd, FALSE);
  681. }
  682. ERRORS:
  683. return;
  684. }
  685. int GetTreePBarRange()
  686. {
  687. int Range = 10;
  688. // Count the directories to load - 2 for the . and .. directories.
  689. return Range;
  690. }
  691. DWORD WINAPI tfCollectBucketStart (void *ThreadParam)
  692. {
  693. // Get progress bar range values
  694. // Load the user mode tree
  695. if (!GetAllBuckets (*((HWND *) ThreadParam)))
  696. {
  697. MessageBox(*((HWND *) ThreadParam), _T("Failed to load the CER file tree."), NULL,MB_OK);
  698. }
  699. else
  700. {
  701. PostMessage(hUserMode, WM_FileTreeLoaded, 0,0);
  702. // Load the kernel mode tree
  703. PostMessage(hKrnlMode, WM_FileTreeLoaded, 0,0);
  704. }
  705. PostMessage(*((HWND *) ThreadParam), WmSyncDone, FALSE, 0);
  706. return TRUE;
  707. }
  708. void CenterDialogInParent(HWND hwnd)
  709. {
  710. HWND hParent = GetParent(hwnd);
  711. RECT rcParent;
  712. RECT rcDlg;
  713. RECT newRect;
  714. GetWindowRect(hParent, &rcParent);
  715. GetWindowRect(hwnd, &rcDlg);
  716. newRect.left = rcParent.left + (rcParent.right - rcParent.left) /2 - (rcDlg.right - rcDlg.left) /2;
  717. newRect.top = rcParent.top + (rcParent.bottom - rcParent.top) /2 - (rcDlg.bottom - rcDlg.top) /2;
  718. MoveWindow(hwnd, newRect.left, newRect.top, rcDlg.right - rcDlg.left , rcDlg.bottom - rcDlg.top, TRUE);
  719. }
  720. BOOL CALLBACK LoadDlgProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
  721. {
  722. HANDLE hThread = NULL;
  723. // DWORD dw;
  724. LoadThreadParam = hDlg;
  725. switch (uMsg)
  726. {
  727. case WM_INITDIALOG:
  728. CenterDialogInParent(hDlg);
  729. // Set Dialog Title
  730. TCHAR DialogTitle[MAX_PATH];
  731. if (StringCbPrintf(DialogTitle, sizeof DialogTitle, _T("Loading File Tree: %s"), CerRoot)!= S_OK)
  732. {
  733. goto ERRORS;
  734. }
  735. SendMessage(hDlg, WM_SETTEXT, 0, (LPARAM)DialogTitle);
  736. SendDlgItemMessage(hDlg, IDC_PB, PBM_SETSTEP, 1, 0);
  737. hThread = CreateThread(NULL, 0, tfCollectBucketStart, &LoadThreadParam, 0, NULL);
  738. if (hThread)
  739. CloseHandle(hThread);
  740. return TRUE;
  741. case WM_CLOSE:
  742. // Cancel the tree load and clear the Data structures.
  743. EndDialog(hDlg, TRUE);
  744. return TRUE;
  745. case WmSyncDone:
  746. EndDialog(hDlg, 1);
  747. return TRUE;
  748. }
  749. ERRORS:
  750. return FALSE;
  751. }
  752. BOOL DoLoadFileTree(HWND hwnd, TCHAR *Directory, BOOL bGetDir)
  753. {
  754. WCHAR wzPath[MAX_PATH];
  755. BROWSEINFOW bi;
  756. TCHAR szPath[MAX_PATH];
  757. TCHAR szSubDir[MAX_PATH];
  758. ZeroMemory (szSubDir, sizeof szSubDir);
  759. ZeroMemory (szPath, sizeof szPath);
  760. if (bGetDir)
  761. {
  762. bi.hwndOwner = hwnd;
  763. bi.pidlRoot = NULL;
  764. bi.pszDisplayName = wzPath;
  765. bi.lpszTitle = L"Select a CER File Tree to open...";
  766. bi.ulFlags = BIF_USENEWUI | BIF_RETURNONLYFSDIRS | BIF_EDITBOX;
  767. bi.lpfn = NULL;
  768. ITEMIDLIST *pidl = SHBrowseForFolderW(&bi);
  769. if (pidl != NULL)
  770. {
  771. if (!SHGetPathFromIDList(pidl, szPath))
  772. {
  773. goto CANCELED;
  774. }
  775. }
  776. else
  777. {
  778. goto CANCELED;
  779. }
  780. }
  781. else
  782. {
  783. if (!Directory)
  784. {
  785. goto CANCELED;
  786. }
  787. if (StringCbCopy (szPath, sizeof szPath, Directory) != S_OK)
  788. {
  789. goto ERRORS;
  790. }
  791. }
  792. if (PathIsDirectory(szPath))
  793. {
  794. if (StringCbPrintf(szSubDir, sizeof szSubDir, _T("%s\\Cabs"), szPath) != S_OK)
  795. {
  796. goto ERRORS;
  797. }
  798. }
  799. else
  800. {
  801. if (!PathIsDirectory(szSubDir))
  802. {
  803. goto ERRORS;
  804. }
  805. }
  806. if (StringCbPrintf(szSubDir, sizeof szSubDir, _T("%s\\Counts"), szPath) != S_OK)
  807. {
  808. goto ERRORS;
  809. }
  810. else
  811. {
  812. if (!PathIsDirectory(szSubDir))
  813. {
  814. goto ERRORS;
  815. }
  816. }
  817. if (StringCbPrintf(szSubDir, sizeof szSubDir, _T("%s\\Status"), szPath) != S_OK)
  818. {
  819. goto ERRORS;
  820. }
  821. else
  822. {
  823. if (!PathIsDirectory(szSubDir))
  824. {
  825. goto ERRORS;
  826. }
  827. }
  828. if (StringCbCopy (CerRoot,sizeof CerRoot, szPath) != S_OK)
  829. {
  830. goto ERRORS;
  831. }
  832. if (!DialogBox(g_hinst, MAKEINTRESOURCE(IDD_LOAD), hwnd, (DLGPROC) LoadDlgProc))
  833. {
  834. //MessageBox(NULL, "FAILED TO LOAD TREE", NULL, MB_OK);
  835. goto ERRORS;
  836. }
  837. else
  838. {
  839. AddToMruList(hwnd, CerRoot);
  840. SaveMruList();
  841. PopulateMruList(hwnd, TRUE);
  842. }
  843. return TRUE;
  844. ERRORS:
  845. MessageBox(hwnd, _T("Failed to load the CER file tree."), NULL,MB_OK);
  846. CANCELED:
  847. return FALSE;
  848. }
  849. void OnAboutBoxInit(HWND hwnd)
  850. {
  851. TCHAR wz1[MAX_PATH];
  852. TCHAR wz2[MAX_PATH];
  853. HRSRC hRsrc = FindResourceW(GetModuleHandle(NULL), MAKEINTRESOURCEW(1), MAKEINTRESOURCEW(RT_VERSION));
  854. if (!hRsrc)
  855. {
  856. goto ERRORS;
  857. }
  858. void *pver = LoadResource(GetModuleHandle(NULL), hRsrc);
  859. if (!pver)
  860. {
  861. goto ERRORS;
  862. }
  863. VS_FIXEDFILEINFO *pVer = NULL;
  864. UINT dwVer;
  865. VerQueryValue(pver, _T("\\"), (void **)&pVer, &dwVer);
  866. if (!pVer)
  867. {
  868. goto ERRORS;
  869. }
  870. if (StringCbCopy(wz1, sizeof wz1, _T("Version %d.%d.%d.%d")) != S_OK)
  871. {
  872. goto ERRORS;
  873. }
  874. if (StringCbPrintf(wz2,sizeof wz2, wz1,
  875. HIWORD(pVer->dwProductVersionMS), LOWORD(pVer->dwProductVersionMS),
  876. HIWORD(pVer->dwProductVersionLS), LOWORD(pVer->dwProductVersionLS)) != S_OK)
  877. {
  878. goto ERRORS;
  879. }
  880. SetDlgItemText(hwnd, IDC_VERSION_STRING, wz2);
  881. WORD *lpTranslate = NULL;
  882. VerQueryValue(pver,_T("\\VarFileInfo\\Translation"), (void **)&lpTranslate, &dwVer);
  883. if (!lpTranslate)
  884. {
  885. goto ERRORS;
  886. }
  887. if (StringCbPrintf(wz1,sizeof wz1, _T("\\StringFileInfo\\%04x%04x\\LegalCopyright"), lpTranslate[0], lpTranslate[1]) != S_OK)
  888. {
  889. goto ERRORS;
  890. }
  891. TCHAR *wzCopyright = NULL;
  892. VerQueryValue(pver, wz1, (void **)&wzCopyright, &dwVer);
  893. if (!wzCopyright)
  894. {
  895. goto ERRORS;
  896. }
  897. SetDlgItemText(hwnd, IDC_COPYRIGHT_STRING, wzCopyright);
  898. ERRORS:
  899. return;
  900. }
  901. LRESULT CALLBACK AboutDlgProc(HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam)
  902. {
  903. switch (iMsg)
  904. {
  905. case WM_INITDIALOG:
  906. OnAboutBoxInit (hwnd);
  907. return TRUE;
  908. case WM_COMMAND:
  909. {
  910. switch (LOWORD(wParam))
  911. {
  912. case IDOK:
  913. EndDialog(hwnd, TRUE);
  914. return TRUE;
  915. }
  916. }
  917. case WM_DESTROY:
  918. EndDialog(hwnd, TRUE);
  919. return TRUE;
  920. default:
  921. break;
  922. }
  923. return FALSE;
  924. }
  925. void EnableMenuItems(HWND hwnd)
  926. {
  927. // Main menu
  928. HMENU hMenu = GetMenu(hwnd);
  929. //
  930. //EnableMenuItem (hMenu, ID_EDIT_SELECTALL , MF_BYCOMMAND| MF_ENABLED);
  931. if (hMenu)
  932. {
  933. EnableMenuItem (hMenu, ID_EDIT_DEFAULTPOLICY , MF_BYCOMMAND| MF_ENABLED);
  934. EnableMenuItem (hMenu, ID_EDIT_SELECTEDBUCKETSPOLICY , MF_BYCOMMAND| MF_ENABLED);
  935. EnableMenuItem (hMenu, ID_REPORT_ALLCRASHES , MF_BYCOMMAND| MF_ENABLED);
  936. EnableMenuItem (hMenu, ID_REPORT_SELECTEDFAULTS , MF_BYCOMMAND| MF_ENABLED);
  937. EnableMenuItem (hMenu, ID_VIEW_BUCKETCABFILEDIRECTORY , MF_BYCOMMAND| MF_ENABLED);
  938. EnableMenuItem (hMenu, ID_VIEW_BUCKETINSTANCEDATA , MF_BYCOMMAND| MF_ENABLED);
  939. EnableMenuItem (hMenu, ID_VIEW_RESPONSESELECTED , MF_BYCOMMAND| MF_ENABLED);
  940. EnableMenuItem (hMenu, ID_VIEW_REFRESH , MF_BYCOMMAND| MF_ENABLED);
  941. //EnableMenuItem (hMenu, ID_FILE_EXPORTBUCKETS , MF_BYCOMMAND| MF_ENABLED);
  942. //EnableMenuItem (hMenu, ID_FILE_EXPORTSELECTEDBUCKETS , MF_BYCOMMAND| MF_ENABLED);
  943. EnableMenuItem (hMenu, ID_FILE_RELOADFILETREE, MF_BYCOMMAND| MF_ENABLED);
  944. EnableMenuItem (hMenu, ID_REPORT_USERMODEFAULTS, MF_BYCOMMAND | MF_ENABLED);
  945. EnableMenuItem (hMenu, ID_REPORT_KERNELMODEFAULTS, MF_BYCOMMAND | MF_ENABLED);
  946. EnableMenuItem (hMenu, ID_VIEW_CRASHLOG, MF_BYCOMMAND | MF_ENABLED);
  947. //EnableMenuItem (hMenu, ID_EDIT_COPY115, MF_BYCOMMAND| MF_ENABLED);
  948. if ( !g_bAdminAccess)
  949. {
  950. EnableMenuItem (hMenu, ID_REPORT_ALLCRASHES , MF_BYCOMMAND| MF_GRAYED);
  951. //EnableMenuItem (hMenu, ID_REPORT_SELECTEDCRASHES , MF_BYCOMMAND| MF_GRAYED);
  952. EnableMenuItem (hMenu, ID_REPORT_SELECTEDFAULTS , MF_BYCOMMAND| MF_GRAYED);
  953. EnableMenuItem (hMenu, ID_REPORT_USERMODEFAULTS, MF_BYCOMMAND | MF_GRAYED);
  954. EnableMenuItem (hMenu, ID_REPORT_KERNELMODEFAULTS, MF_BYCOMMAND | MF_GRAYED);
  955. EnableMenuItem (hMenu, ID_EDIT_DEFAULTPOLICY , MF_BYCOMMAND| MF_GRAYED);
  956. EnableMenuItem (hMenu, ID_EDIT_SELECTEDBUCKETSPOLICY , MF_BYCOMMAND| MF_GRAYED);
  957. }
  958. }
  959. // EnableMenuItem (hMenu, ID_EXPORT_USERMODEBUCKETDATA, MF_BYCOMMAND | MF_ENABLED);
  960. // EnableMenuItem (hMenu, ID_EXPORT_KERNELMODEFAULTDATA, MF_BYCOMMAND | MF_ENABLED);
  961. }
  962. BOOL SaveMruList()
  963. {
  964. HKEY hHKLM = NULL;
  965. HKEY hMruKey = NULL;
  966. // BYTE Buffer[(MAX_PATH + 1) * sizeof TCHAR] ;
  967. // DWORD Type;
  968. DWORD BufferSize = MAX_PATH +1; // Set for largest value
  969. BOOL Status = TRUE;
  970. if(!RegConnectRegistry(NULL, HKEY_CURRENT_USER, &hHKLM))
  971. {
  972. if(RegOpenKeyEx(hHKLM,_T("Software\\Microsoft\\CER1.5"), 0, KEY_ALL_ACCESS, &hMruKey))
  973. {
  974. // The key probably doesn't exists try to create it.
  975. if (RegCreateKey(hHKLM, _T("Software\\Microsoft\\CER1.5"), &hMruKey))
  976. {
  977. // Ok Now What
  978. goto ERRORS;
  979. }
  980. }
  981. if (hMruKey)
  982. {
  983. // Get the input queue directory path
  984. BufferSize = (_tcslen(MruList.szMRU1) + 1 ) * sizeof TCHAR;
  985. if (BufferSize > sizeof TCHAR)
  986. {
  987. if (RegSetValueEx(hMruKey,_T("CerMRU1"), 0, REG_SZ,(BYTE *) MruList.szMRU1, BufferSize) != ERROR_SUCCESS)
  988. {
  989. //LogEvent(_T("Failed to get InputQueue value from registry."));
  990. Status = FALSE;
  991. }
  992. }
  993. BufferSize = (_tcslen(MruList.szMRU2) + 1 ) * sizeof TCHAR;
  994. if (BufferSize > sizeof TCHAR)
  995. {
  996. if (RegSetValueEx(hMruKey,_T("CerMRU2"), 0, REG_SZ,(BYTE *) MruList.szMRU2, BufferSize) != ERROR_SUCCESS)
  997. {
  998. //LogEvent(_T("Failed to get InputQueue value from registry."));
  999. Status = FALSE;
  1000. }
  1001. }
  1002. BufferSize = (_tcslen(MruList.szMRU3) + 1 ) * sizeof TCHAR;
  1003. if (BufferSize > sizeof TCHAR)
  1004. {
  1005. if (RegSetValueEx(hMruKey,_T("CerMRU3"), 0, REG_SZ, (BYTE *)MruList.szMRU3, BufferSize) != ERROR_SUCCESS)
  1006. {
  1007. //LogEvent(_T("Failed to get InputQueue value from registry."));
  1008. Status = FALSE;
  1009. }
  1010. }
  1011. BufferSize = (_tcslen(MruList.szMRU4) + 1 ) * sizeof TCHAR;
  1012. if (BufferSize > sizeof TCHAR)
  1013. {
  1014. if (RegSetValueEx(hMruKey,_T("CerMRU4"), 0, REG_SZ, (BYTE *)MruList.szMRU4, BufferSize) != ERROR_SUCCESS)
  1015. {
  1016. Status = FALSE;
  1017. }
  1018. }
  1019. if (hMruKey)
  1020. {
  1021. RegCloseKey(hMruKey);
  1022. hMruKey = NULL;
  1023. }
  1024. }
  1025. if (hHKLM)
  1026. {
  1027. RegCloseKey(hHKLM);
  1028. hHKLM = NULL;
  1029. }
  1030. return TRUE;
  1031. }
  1032. ERRORS:
  1033. if (hMruKey)
  1034. {
  1035. RegCloseKey(hMruKey);
  1036. }
  1037. if (hHKLM)
  1038. {
  1039. RegCloseKey(hHKLM);
  1040. }
  1041. return FALSE;
  1042. }
  1043. // Load the mru's
  1044. BOOL LoadMruList()
  1045. {
  1046. HKEY hHKLM = NULL;
  1047. HKEY hMruKey = NULL;
  1048. // TCHAR ErrorString[20];
  1049. BYTE Buffer[(MAX_PATH + 1) * sizeof TCHAR] ;
  1050. DWORD Type;
  1051. DWORD BufferSize = MAX_PATH +1; // Set for largest value
  1052. BOOL Status = TRUE;
  1053. BOOL bNeedSave = FALSE;
  1054. if(!RegConnectRegistry(NULL, HKEY_CURRENT_USER, &hHKLM))
  1055. {
  1056. if(RegOpenKeyEx(hHKLM,_T("Software\\Microsoft\\CER1.5"), 0, KEY_ALL_ACCESS, &hMruKey))
  1057. {
  1058. hMruKey = NULL;
  1059. if (RegOpenKeyEx(hHKLM, _T("Software\\Microsoft\\Office\\10.0\\ResourceKit"), 0, KEY_ALL_ACCESS, &hMruKey))
  1060. {
  1061. goto ERRORS;
  1062. }
  1063. else
  1064. {
  1065. bNeedSave = TRUE;
  1066. }
  1067. }
  1068. if (hMruKey)
  1069. {
  1070. // Get the input queue directory path
  1071. BufferSize = MAX_PATH +1;
  1072. ZeroMemory(Buffer, BufferSize);
  1073. if (RegQueryValueEx(hMruKey,_T("CerMRU1"), 0, &Type, Buffer, &BufferSize) != ERROR_SUCCESS)
  1074. {
  1075. //LogEvent(_T("Failed to get InputQueue value from registry."));
  1076. Status = FALSE;
  1077. }
  1078. else
  1079. {
  1080. if (StringCbCopy(MruList.szMRU1, sizeof MruList.szMRU1, (TCHAR *)Buffer)!= S_OK)
  1081. {
  1082. goto ERRORS;
  1083. }
  1084. }
  1085. BufferSize = MAX_PATH +1;
  1086. ZeroMemory(Buffer, BufferSize);
  1087. if (RegQueryValueEx(hMruKey,_T("CerMRU2"), 0, &Type, Buffer, &BufferSize) != ERROR_SUCCESS)
  1088. {
  1089. //LogEvent(_T("Failed to get InputQueue value from registry."));
  1090. Status = FALSE;
  1091. }
  1092. else
  1093. {
  1094. if (StringCbCopy(MruList.szMRU2, sizeof MruList.szMRU2, (TCHAR *)Buffer)!= S_OK)
  1095. {
  1096. goto ERRORS;
  1097. }
  1098. }
  1099. BufferSize = MAX_PATH +1;
  1100. ZeroMemory(Buffer, BufferSize);
  1101. if (RegQueryValueEx(hMruKey,_T("CerMRU3"), 0, &Type, Buffer, &BufferSize) != ERROR_SUCCESS)
  1102. {
  1103. //LogEvent(_T("Failed to get InputQueue value from registry."));
  1104. Status = FALSE;
  1105. }
  1106. else
  1107. {
  1108. if (StringCbCopy(MruList.szMRU3, sizeof MruList.szMRU3, (TCHAR *)Buffer)!= S_OK)
  1109. {
  1110. goto ERRORS;
  1111. }
  1112. }
  1113. BufferSize = MAX_PATH +1;
  1114. ZeroMemory(Buffer, BufferSize);
  1115. if (RegQueryValueEx(hMruKey,_T("CerMRU4"), 0, &Type, Buffer, &BufferSize) != ERROR_SUCCESS)
  1116. {
  1117. //LogEvent(_T("Failed to get InputQueue value from registry."));
  1118. Status = FALSE;
  1119. }
  1120. else
  1121. {
  1122. if (StringCbCopy(MruList.szMRU4, sizeof MruList.szMRU4, (TCHAR *)Buffer)!= S_OK)
  1123. {
  1124. goto ERRORS;
  1125. }
  1126. }
  1127. RegCloseKey(hMruKey);
  1128. hMruKey = NULL;
  1129. }
  1130. RegCloseKey(hHKLM);
  1131. hHKLM = NULL;
  1132. if (bNeedSave)
  1133. SaveMruList();
  1134. return TRUE;
  1135. }
  1136. ERRORS:
  1137. if (hMruKey)
  1138. RegCloseKey (hMruKey);
  1139. if (hHKLM)
  1140. RegCloseKey (hHKLM);
  1141. return FALSE;
  1142. }
  1143. BOOL AddToMruList(HWND hwnd, TCHAR *NewEntry)
  1144. {
  1145. // TCHAR Entry[MAX_PATH];
  1146. // int EntryNumber = 0;
  1147. //if (StringCbPrintf(Entry, sizeof Entry, _T("
  1148. // if entry not found in list
  1149. if (!_tcscmp (NewEntry, MruList.szMRU1 + 4))
  1150. goto DONE;
  1151. if (!_tcscmp (NewEntry, MruList.szMRU2 + 4))
  1152. goto DONE;
  1153. if (!_tcscmp (NewEntry, MruList.szMRU3 + 4))
  1154. goto DONE;
  1155. if (!_tcscmp (NewEntry, MruList.szMRU4 + 4))
  1156. goto DONE;
  1157. // Find the first available slot or replace mru4
  1158. if (!_tcscmp (_T("\0"), MruList.szMRU1))
  1159. {
  1160. if (StringCbPrintf(MruList.szMRU1, sizeof MruList.szMRU1, _T("&1. %s"), NewEntry) != S_OK)
  1161. goto ERRORS;
  1162. }
  1163. else
  1164. {
  1165. if (!_tcscmp (_T("\0"), MruList.szMRU2 ))
  1166. {
  1167. if (StringCbPrintf(MruList.szMRU2, sizeof MruList.szMRU2, _T("&2. %s"), NewEntry) != S_OK)
  1168. goto ERRORS;
  1169. }
  1170. else
  1171. {
  1172. if (!_tcscmp (_T("\0"), MruList.szMRU3))
  1173. {
  1174. if (StringCbPrintf(MruList.szMRU3, sizeof MruList.szMRU3, _T("&3. %s"), NewEntry) != S_OK)
  1175. goto ERRORS;
  1176. }
  1177. else
  1178. {
  1179. if (!_tcscmp (_T("\0"), MruList.szMRU4))
  1180. {
  1181. if (StringCbPrintf(MruList.szMRU4, sizeof MruList.szMRU4, _T("&4. %s"), NewEntry) != S_OK)
  1182. goto ERRORS;
  1183. }
  1184. else
  1185. {
  1186. // all of the slots are full move each of the entries up one
  1187. // slot and add the new entry at the bottom of the list.
  1188. if (StringCbCopy(MruList.szMRU1 + 4, sizeof MruList.szMRU1, MruList.szMRU2 + 4) != S_OK)
  1189. {
  1190. goto ERRORS;
  1191. }
  1192. if (StringCbCopy(MruList.szMRU2 + 4, sizeof MruList.szMRU2, MruList.szMRU3 + 4) != S_OK)
  1193. {
  1194. goto ERRORS;
  1195. }
  1196. if (StringCbCopy(MruList.szMRU3 + 4, sizeof MruList.szMRU3, MruList.szMRU4 + 4) != S_OK)
  1197. {
  1198. goto ERRORS;
  1199. }
  1200. if (StringCbPrintf(MruList.szMRU4, sizeof MruList.szMRU4, _T("&4. %s"), NewEntry) != S_OK)
  1201. goto ERRORS;
  1202. }
  1203. }
  1204. }
  1205. }
  1206. // Build the new entry String
  1207. DONE:
  1208. return TRUE;
  1209. ERRORS:
  1210. return FALSE;
  1211. }
  1212. void ViewCrashLog()
  1213. {
  1214. TCHAR szCommandLine[MAX_PATH];
  1215. if (_tcscmp(CerRoot, _T("\0")))
  1216. {
  1217. ZeroMemory (szCommandLine, sizeof szCommandLine);
  1218. if (StringCbPrintf(szCommandLine, sizeof szCommandLine, _T("%s\\crash.log"), CerRoot)!= S_OK)
  1219. {
  1220. goto ERRORS;
  1221. }
  1222. if (_tcscmp(szCommandLine, _T("\0")))
  1223. {
  1224. SHELLEXECUTEINFOA sei = {0};
  1225. sei.cbSize = sizeof(sei);
  1226. sei.lpFile = szCommandLine;
  1227. sei.nShow = SW_SHOWDEFAULT;
  1228. if (! ShellExecuteEx(&sei) )
  1229. {
  1230. // What do we display here.
  1231. ;
  1232. }
  1233. }
  1234. }
  1235. ERRORS:
  1236. return;
  1237. }
  1238. BOOL WriteGlobalPolicyFile()
  1239. {
  1240. TCHAR Buffer[1024];
  1241. HANDLE hFile = INVALID_HANDLE_VALUE;
  1242. TCHAR szPath[MAX_PATH];
  1243. DWORD dwBytesWritten = 0;
  1244. if (StringCbPrintf(szPath, sizeof szPath, _T("%s\\Policy.txt"), CerRoot) != S_OK)
  1245. {
  1246. goto ERRORS;
  1247. }
  1248. hFile = CreateFile(szPath,
  1249. GENERIC_WRITE,
  1250. NULL,
  1251. NULL,
  1252. CREATE_ALWAYS,
  1253. FILE_ATTRIBUTE_NORMAL,
  1254. NULL);
  1255. if (hFile == INVALID_HANDLE_VALUE)
  1256. goto ERRORS;
  1257. else
  1258. {
  1259. // write the Global Policy structure to the file
  1260. ZeroMemory(Buffer, sizeof Buffer);
  1261. if (_tcscmp(GlobalPolicy.EnableCrashTracking,_T("\0")))
  1262. {
  1263. if (StringCbPrintf(Buffer, sizeof Buffer, _T("%s%s\r\n"), TRACKING_PREFIX, GlobalPolicy.EnableCrashTracking)!= S_OK)
  1264. {
  1265. goto ERRORS;
  1266. }
  1267. else
  1268. {
  1269. if (!WriteFile(hFile, Buffer, _tcslen(Buffer) *sizeof TCHAR, &dwBytesWritten, NULL))
  1270. {
  1271. goto ERRORS;
  1272. }
  1273. }
  1274. }
  1275. ZeroMemory(Buffer, sizeof Buffer);
  1276. if (_tcscmp(GlobalPolicy.AllowAdvanced,_T("\0")))
  1277. {
  1278. if (StringCbPrintf(Buffer, sizeof Buffer, _T("%s%s\r\n"), FILE_COLLECTION_PREFIX, GlobalPolicy.AllowAdvanced )!= S_OK)
  1279. {
  1280. goto ERRORS;
  1281. }
  1282. else
  1283. {
  1284. if (!WriteFile(hFile, Buffer, _tcslen(Buffer) *sizeof TCHAR, &dwBytesWritten, NULL))
  1285. {
  1286. goto ERRORS;
  1287. }
  1288. }
  1289. }
  1290. ZeroMemory(Buffer, sizeof Buffer);
  1291. if (_tcscmp(GlobalPolicy.AllowBasic,_T("\0")))
  1292. {
  1293. if (StringCbPrintf(Buffer, sizeof Buffer, _T("%s%s\r\n"), SECOND_LEVEL_DATA_PREFIX, GlobalPolicy.AllowBasic )!= S_OK)
  1294. {
  1295. goto ERRORS;
  1296. }
  1297. else
  1298. {
  1299. if (!WriteFile(hFile, Buffer, _tcslen(Buffer) *sizeof TCHAR, &dwBytesWritten, NULL))
  1300. {
  1301. goto ERRORS;
  1302. }
  1303. }
  1304. }
  1305. ZeroMemory(Buffer, sizeof Buffer);
  1306. if (_tcscmp(GlobalPolicy.CustomURL,_T("\0")))
  1307. {
  1308. if (StringCbPrintf(Buffer, sizeof Buffer, _T("%s%s\r\n"),URLLAUNCH_PREFIX, GlobalPolicy.CustomURL )!= S_OK)
  1309. {
  1310. goto ERRORS;
  1311. }
  1312. else
  1313. {
  1314. if (!WriteFile(hFile, Buffer, _tcslen(Buffer) *sizeof TCHAR, &dwBytesWritten, NULL))
  1315. {
  1316. goto ERRORS;
  1317. }
  1318. }
  1319. }
  1320. ZeroMemory(Buffer, sizeof Buffer);
  1321. if (_tcscmp(GlobalPolicy.AllowMicrosoftResponse,_T("\0")))
  1322. {
  1323. if (StringCbPrintf(Buffer, sizeof Buffer, _T("%s%s\r\n"), ALLOW_EXTERNAL_PREFIX, GlobalPolicy.AllowMicrosoftResponse )!= S_OK)
  1324. {
  1325. goto ERRORS;
  1326. }
  1327. else
  1328. {
  1329. if (!WriteFile(hFile, Buffer, _tcslen(Buffer) *sizeof TCHAR, &dwBytesWritten, NULL))
  1330. {
  1331. goto ERRORS;
  1332. }
  1333. }
  1334. }
  1335. ZeroMemory(Buffer, sizeof Buffer);
  1336. if (_tcscmp(GlobalPolicy.CabsPerBucket,_T("\0")))
  1337. {
  1338. if (StringCbPrintf(Buffer, sizeof Buffer, _T("%s%s\r\n"), CRASH_PERBUCKET_PREFIX, GlobalPolicy.CabsPerBucket )!= S_OK)
  1339. {
  1340. goto ERRORS;
  1341. }
  1342. else
  1343. {
  1344. if (!WriteFile(hFile, Buffer, _tcslen(Buffer) *sizeof TCHAR, &dwBytesWritten, NULL))
  1345. {
  1346. goto ERRORS;
  1347. }
  1348. }
  1349. }
  1350. ZeroMemory(Buffer, sizeof Buffer);
  1351. if (_tcscmp(GlobalPolicy.RedirectFileServer,_T("\0")))
  1352. {
  1353. if (StringCbPrintf(Buffer, sizeof Buffer, _T("%s%s\r\n"), FILE_TREE_ROOT_PREFIX, GlobalPolicy.RedirectFileServer )!= S_OK)
  1354. {
  1355. goto ERRORS;
  1356. }
  1357. else
  1358. {
  1359. if (!WriteFile(hFile, Buffer, _tcslen(Buffer) *sizeof TCHAR, &dwBytesWritten, NULL))
  1360. {
  1361. goto ERRORS;
  1362. }
  1363. }
  1364. }
  1365. CloseHandle(hFile);
  1366. hFile = INVALID_HANDLE_VALUE;
  1367. RefreshUserMode(hUserMode);
  1368. return TRUE;
  1369. }
  1370. ERRORS:
  1371. if (hFile != INVALID_HANDLE_VALUE)
  1372. CloseHandle(hFile);
  1373. return FALSE;
  1374. }
  1375. BOOL InitEditPolicyDlg (HWND hwnd, HWND hMode, BOOL bUserMode, BOOL bGlobal)
  1376. {
  1377. HWND hList = NULL;
  1378. int sel = 0;
  1379. PUSER_DATA pUserData = NULL;
  1380. LVITEM lvi;
  1381. if (bUserMode)
  1382. {
  1383. hList = GetDlgItem(hUserMode, IDC_USER_LIST);
  1384. sel = ListView_GetNextItem(hList,-1, LVNI_SELECTED);
  1385. lvi.iItem = sel;
  1386. lvi.mask = LVIF_PARAM;
  1387. ListView_GetItem(hList, &lvi);
  1388. sel = lvi.lParam;
  1389. pUserData = cUserData.GetEntry(sel);
  1390. if (!pUserData)
  1391. {
  1392. goto ERRORS;
  1393. }
  1394. }
  1395. if (bGlobal)
  1396. {
  1397. if (_tcscmp (GlobalPolicy.AllowBasic, _T("YES")))
  1398. {
  1399. CheckDlgButton(hwnd, IDC_CHECK1,TRUE);
  1400. }
  1401. if (_tcscmp (GlobalPolicy.AllowAdvanced, _T("YES")))
  1402. {
  1403. CheckDlgButton(hwnd, IDC_CHECK2,TRUE);
  1404. }
  1405. if (_tcscmp (GlobalPolicy.AllowMicrosoftResponse, _T("YES")))
  1406. {
  1407. CheckDlgButton(hwnd, IDC_CHECK3,TRUE);
  1408. }
  1409. if (!_tcscmp (GlobalPolicy.EnableCrashTracking, _T("YES")))
  1410. {
  1411. CheckDlgButton(hwnd, IDC_CHECK4,TRUE);
  1412. }
  1413. SetDlgItemText(hwnd, IDC_EDIT1, GlobalPolicy.CustomURL);
  1414. SetDlgItemText(hwnd, IDC_EDIT2, GlobalPolicy.RedirectFileServer);
  1415. SetDlgItemText(hwnd, IDC_EDIT3, GlobalPolicy.CabsPerBucket);
  1416. }
  1417. else
  1418. {
  1419. // Get the selected bucket.
  1420. if (bUserMode)
  1421. {
  1422. if (pUserData)
  1423. {
  1424. if (_tcscmp (pUserData->Status.SecondLevelData, _T("YES")))
  1425. {
  1426. CheckDlgButton(hwnd, IDC_CHECK1,TRUE);
  1427. }
  1428. if (_tcscmp (pUserData->Status.FileCollection, _T("YES")))
  1429. {
  1430. CheckDlgButton(hwnd, IDC_CHECK2,TRUE);
  1431. }
  1432. if (_tcscmp (pUserData->Status.AllowResponse, _T("YES")))
  1433. {
  1434. CheckDlgButton(hwnd, IDC_CHECK3,TRUE);
  1435. }
  1436. if (!_tcscmp (pUserData->Status.Tracking, _T("YES")))
  1437. {
  1438. CheckDlgButton(hwnd, IDC_CHECK4,TRUE);
  1439. }
  1440. SetDlgItemText(hwnd, IDC_EDIT1, pUserData->Status.UrlToLaunch);
  1441. SetDlgItemText(hwnd, IDC_EDIT3, pUserData->Status.CrashPerBucketCount);
  1442. }
  1443. }
  1444. else
  1445. {
  1446. // we only have one status file location for Bluescreens
  1447. if (_tcscmp (CsvContents.KrnlPolicy.SecondLevelData, _T("YES")))
  1448. {
  1449. CheckDlgButton(hwnd, IDC_CHECK1,TRUE);
  1450. }
  1451. if (_tcscmp (CsvContents.KrnlPolicy.FileCollection, _T("YES")))
  1452. {
  1453. CheckDlgButton(hwnd, IDC_CHECK2,TRUE);
  1454. }
  1455. if (_tcscmp (CsvContents.KrnlPolicy.AllowResponse, _T("YES")))
  1456. {
  1457. CheckDlgButton(hwnd, IDC_CHECK3,TRUE);
  1458. }
  1459. if (!_tcscmp (CsvContents.KrnlPolicy.Tracking, _T("YES")))
  1460. {
  1461. CheckDlgButton(hwnd, IDC_CHECK4,TRUE);
  1462. }
  1463. SetDlgItemText(hwnd, IDC_EDIT1, CsvContents.KrnlPolicy.UrlToLaunch);
  1464. SetDlgItemText(hwnd, IDC_EDIT3, CsvContents.KrnlPolicy.CrashPerBucketCount);
  1465. }
  1466. }
  1467. return TRUE;
  1468. ERRORS:
  1469. return FALSE;
  1470. }
  1471. BOOL GetSelPolicyDlgData(BOOL bUserMode, HWND hwnd)
  1472. {
  1473. PUSER_DATA pUserData = NULL;
  1474. HWND hList = NULL;
  1475. int sel = 0;
  1476. LVITEM lvi;
  1477. TCHAR TempBuffer[MAX_PATH];
  1478. TCHAR *pTchar = NULL;
  1479. ZeroMemory (TempBuffer, sizeof TempBuffer);
  1480. if (bUserMode)
  1481. {
  1482. hList = GetDlgItem(hUserMode, IDC_USER_LIST);
  1483. sel = ListView_GetNextItem(hList,-1, LVNI_SELECTED);
  1484. lvi.iItem = sel;
  1485. lvi.mask = LVIF_PARAM;
  1486. ListView_GetItem(hList, &lvi);
  1487. sel = lvi.lParam;
  1488. pUserData = cUserData.GetEntry(sel);
  1489. if (!pUserData)
  1490. {
  1491. goto ERRORS;
  1492. }
  1493. }
  1494. // read the contents of the dialog box into the global policy structure.
  1495. if (IsDlgButtonChecked(hwnd, IDC_CHECK1))
  1496. {
  1497. if (bUserMode)
  1498. {
  1499. if (StringCbCopy(pUserData->Status.SecondLevelData, sizeof pUserData->Status.SecondLevelData, _T("NO") )!= S_OK)
  1500. {
  1501. goto ERRORS;
  1502. }
  1503. }
  1504. else
  1505. {
  1506. if (StringCbCopy(CsvContents.KrnlPolicy.SecondLevelData, sizeof CsvContents.KrnlPolicy.SecondLevelData, _T("NO") )!= S_OK)
  1507. {
  1508. goto ERRORS;
  1509. }
  1510. }
  1511. }
  1512. else
  1513. {
  1514. if (bUserMode)
  1515. {
  1516. if (StringCbCopy(pUserData->Status.SecondLevelData, sizeof pUserData->Status.SecondLevelData, _T("YES") )!= S_OK)
  1517. {
  1518. goto ERRORS;
  1519. }
  1520. }
  1521. else
  1522. {
  1523. if (StringCbCopy(CsvContents.KrnlPolicy.SecondLevelData, sizeof CsvContents.KrnlPolicy.SecondLevelData, _T("YES") )!= S_OK)
  1524. {
  1525. goto ERRORS;
  1526. }
  1527. }
  1528. }
  1529. if (IsDlgButtonChecked(hwnd, IDC_CHECK2))
  1530. {
  1531. if (bUserMode)
  1532. {
  1533. if (StringCbCopy(pUserData->Status.FileCollection, sizeof pUserData->Status.FileCollection, _T("NO") )!= S_OK)
  1534. {
  1535. goto ERRORS;
  1536. }
  1537. }
  1538. else
  1539. {
  1540. if (StringCbCopy(CsvContents.KrnlPolicy.FileCollection, sizeof CsvContents.KrnlPolicy.FileCollection, _T("NO") )!= S_OK)
  1541. {
  1542. goto ERRORS;
  1543. }
  1544. }
  1545. }
  1546. else
  1547. {
  1548. if (bUserMode)
  1549. {
  1550. if (StringCbCopy(pUserData->Status.FileCollection, sizeof pUserData->Status.FileCollection, _T("YES") )!= S_OK)
  1551. {
  1552. goto ERRORS;
  1553. }
  1554. }
  1555. else
  1556. {
  1557. if (StringCbCopy(CsvContents.KrnlPolicy.FileCollection, sizeof CsvContents.KrnlPolicy.FileCollection, _T("YES") )!= S_OK)
  1558. {
  1559. goto ERRORS;
  1560. }
  1561. }
  1562. }
  1563. if (IsDlgButtonChecked(hwnd, IDC_CHECK3))
  1564. {
  1565. if (bUserMode)
  1566. {
  1567. if (StringCbCopy(pUserData->Status.AllowResponse, sizeof pUserData->Status.AllowResponse, _T("NO") )!= S_OK)
  1568. {
  1569. goto ERRORS;
  1570. }
  1571. }
  1572. else
  1573. {
  1574. if (StringCbCopy(CsvContents.KrnlPolicy.AllowResponse, sizeof CsvContents.KrnlPolicy.AllowResponse, _T("NO") )!= S_OK)
  1575. {
  1576. goto ERRORS;
  1577. }
  1578. }
  1579. }
  1580. else
  1581. {
  1582. if (bUserMode)
  1583. {
  1584. if (StringCbCopy(pUserData->Status.AllowResponse, sizeof pUserData->Status.AllowResponse, _T("YES") )!= S_OK)
  1585. {
  1586. goto ERRORS;
  1587. }
  1588. }
  1589. else
  1590. {
  1591. if (StringCbCopy(CsvContents.KrnlPolicy.AllowResponse, sizeof CsvContents.KrnlPolicy.AllowResponse, _T("YES") )!= S_OK)
  1592. {
  1593. goto ERRORS;
  1594. }
  1595. }
  1596. }
  1597. if (IsDlgButtonChecked(hwnd, IDC_CHECK4))
  1598. {
  1599. if (bUserMode)
  1600. {
  1601. if (StringCbCopy(pUserData->Status.Tracking, sizeof pUserData->Status.Tracking, _T("YES") )!= S_OK)
  1602. {
  1603. goto ERRORS;
  1604. }
  1605. }
  1606. else
  1607. {
  1608. if (StringCbCopy(CsvContents.KrnlPolicy.Tracking, sizeof CsvContents.KrnlPolicy.Tracking, _T("YES") )!= S_OK)
  1609. {
  1610. goto ERRORS;
  1611. }
  1612. }
  1613. }
  1614. else
  1615. {
  1616. if (bUserMode)
  1617. {
  1618. if (StringCbCopy(pUserData->Status.Tracking, sizeof pUserData->Status.Tracking, _T("NO") )!= S_OK)
  1619. {
  1620. goto ERRORS;
  1621. }
  1622. }
  1623. else
  1624. {
  1625. if (StringCbCopy(CsvContents.KrnlPolicy.Tracking, sizeof CsvContents.KrnlPolicy.Tracking, _T("NO") )!= S_OK)
  1626. {
  1627. goto ERRORS;
  1628. }
  1629. }
  1630. }
  1631. if (bUserMode)
  1632. {
  1633. // fill temp buffer with string
  1634. GetDlgItemText(hwnd, IDC_EDIT1,TempBuffer, sizeof TempBuffer / sizeof TCHAR);
  1635. pTchar = TempBuffer;
  1636. while ( ( (*pTchar == _T(' ')) || (*pTchar == _T('\t')) ) && (*pTchar != _T('\0')))
  1637. {
  1638. ++pTchar;
  1639. }
  1640. if (StringCbCopy(pUserData->Status.UrlToLaunch, sizeof pUserData->Status.UrlToLaunch, pTchar) != S_OK)
  1641. {
  1642. goto ERRORS;
  1643. }
  1644. GetDlgItemText(hwnd, IDC_EDIT3, pUserData->Status.CrashPerBucketCount, sizeof pUserData->Status.CrashPerBucketCount / sizeof TCHAR);
  1645. }
  1646. else
  1647. {
  1648. GetDlgItemText(hwnd, IDC_EDIT1,TempBuffer, sizeof TempBuffer / sizeof TCHAR);
  1649. pTchar = TempBuffer;
  1650. while ( ( (*pTchar == _T(' ')) || (*pTchar == _T('\t')) ) && (*pTchar != _T('\0')))
  1651. {
  1652. ++pTchar;
  1653. }
  1654. if (StringCbCopy(CsvContents.KrnlPolicy.UrlToLaunch, sizeof CsvContents.KrnlPolicy.UrlToLaunch, pTchar) != S_OK)
  1655. {
  1656. goto ERRORS;
  1657. }
  1658. //GetDlgItemText(hwnd, IDC_EDIT1, CsvContents.KrnlPolicy.UrlToLaunch, sizeof CsvContents.KrnlPolicy.UrlToLaunch / sizeof TCHAR);
  1659. GetDlgItemText(hwnd, IDC_EDIT3, CsvContents.KrnlPolicy.CrashPerBucketCount, sizeof CsvContents.KrnlPolicy.CrashPerBucketCount / sizeof TCHAR);
  1660. }
  1661. return TRUE;
  1662. ERRORS:
  1663. return FALSE;
  1664. }
  1665. LRESULT CALLBACK EditSelectedDlgProc(HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam)
  1666. {
  1667. LVITEM lvi;
  1668. switch (iMsg)
  1669. {
  1670. case WM_INITDIALOG:
  1671. if (ReportMode==USER_MODE)
  1672. {
  1673. InitEditPolicyDlg (hwnd, hUserMode,TRUE,FALSE);
  1674. }
  1675. else
  1676. {
  1677. InitEditPolicyDlg (hwnd, hKrnlMode, FALSE,FALSE);
  1678. }
  1679. return TRUE;
  1680. case WM_DESTROY:
  1681. EndDialog(hwnd, TRUE);
  1682. return TRUE;
  1683. case WM_COMMAND:
  1684. {
  1685. switch (LOWORD(wParam))
  1686. {
  1687. case IDOK:
  1688. if (ReportMode == USER_MODE)
  1689. {
  1690. GetSelPolicyDlgData(TRUE, hwnd);
  1691. PUSER_DATA pUserData;
  1692. HWND hList = NULL;
  1693. int sel = 0;
  1694. hList = GetDlgItem(hUserMode, IDC_USER_LIST);
  1695. sel = ListView_GetNextItem(hList,-1, LVNI_SELECTED);
  1696. lvi.iItem = sel;
  1697. lvi.mask = LVIF_PARAM;
  1698. ListView_GetItem(hList, &lvi);
  1699. sel = lvi.lParam;
  1700. pUserData = cUserData.GetEntry(sel);
  1701. if (!pUserData)
  1702. {
  1703. return TRUE;
  1704. }
  1705. WriteStatusFile(pUserData);
  1706. }
  1707. else
  1708. {
  1709. GetSelPolicyDlgData(FALSE, hwnd);
  1710. WriteKernelStatusFile();
  1711. }
  1712. EndDialog(hwnd, TRUE);
  1713. return TRUE;
  1714. case IDCANCEL:
  1715. EndDialog(hwnd, TRUE);
  1716. }
  1717. }
  1718. break;
  1719. default:
  1720. break;
  1721. }
  1722. return FALSE;
  1723. }
  1724. BOOL GetPolicyDlgData(HWND hwnd)
  1725. {
  1726. TCHAR *pTchar = NULL;
  1727. TCHAR TempBuffer[MAX_PATH];
  1728. ZeroMemory(TempBuffer, sizeof TempBuffer);
  1729. // read the contents of the dialog box into the global policy structure.
  1730. if (IsDlgButtonChecked(hwnd, IDC_CHECK1))
  1731. {
  1732. if (StringCbCopy(GlobalPolicy.AllowBasic, sizeof GlobalPolicy.AllowBasic, _T("NO") )!= S_OK)
  1733. {
  1734. goto ERRORS;
  1735. }
  1736. }
  1737. else
  1738. {
  1739. if (StringCbCopy(GlobalPolicy.AllowBasic, sizeof GlobalPolicy.AllowBasic, _T("YES") )!= S_OK)
  1740. {
  1741. goto ERRORS;
  1742. }
  1743. }
  1744. if (IsDlgButtonChecked(hwnd, IDC_CHECK2))
  1745. {
  1746. if (StringCbCopy(GlobalPolicy.AllowAdvanced, sizeof GlobalPolicy.AllowAdvanced, _T("NO") )!= S_OK)
  1747. {
  1748. goto ERRORS;
  1749. }
  1750. }
  1751. else
  1752. {
  1753. if (StringCbCopy(GlobalPolicy.AllowAdvanced, sizeof GlobalPolicy.AllowAdvanced, _T("YES") )!= S_OK)
  1754. {
  1755. goto ERRORS;
  1756. }
  1757. }
  1758. if (IsDlgButtonChecked(hwnd, IDC_CHECK3))
  1759. {
  1760. if (StringCbCopy(GlobalPolicy.AllowMicrosoftResponse, sizeof GlobalPolicy.AllowMicrosoftResponse, _T("NO") )!= S_OK)
  1761. {
  1762. goto ERRORS;
  1763. }
  1764. }
  1765. else
  1766. {
  1767. if (StringCbCopy(GlobalPolicy.AllowMicrosoftResponse, sizeof GlobalPolicy.AllowMicrosoftResponse, _T("YES") )!= S_OK)
  1768. {
  1769. goto ERRORS;
  1770. }
  1771. }
  1772. if (IsDlgButtonChecked(hwnd, IDC_CHECK4))
  1773. {
  1774. if (StringCbCopy(GlobalPolicy.EnableCrashTracking, sizeof GlobalPolicy.EnableCrashTracking, _T("YES") )!= S_OK)
  1775. {
  1776. goto ERRORS;
  1777. }
  1778. }
  1779. else
  1780. {
  1781. if (StringCbCopy(GlobalPolicy.EnableCrashTracking, sizeof GlobalPolicy.EnableCrashTracking, _T("NO") )!= S_OK)
  1782. {
  1783. goto ERRORS;
  1784. }
  1785. }
  1786. GetDlgItemText(hwnd, IDC_EDIT1,TempBuffer, sizeof TempBuffer / sizeof TCHAR);
  1787. pTchar = TempBuffer;
  1788. while ( ( (*pTchar == _T(' ')) || (*pTchar == _T('\t')) ) && (*pTchar != _T('\0')))
  1789. {
  1790. ++pTchar;
  1791. }
  1792. if (StringCbCopy(GlobalPolicy.CustomURL, sizeof GlobalPolicy.CustomURL, pTchar) != S_OK)
  1793. {
  1794. goto ERRORS;
  1795. }
  1796. //GetDlgItemText(hwnd, IDC_EDIT1, GlobalPolicy.CustomURL, sizeof GlobalPolicy.CustomURL / sizeof TCHAR);
  1797. GetDlgItemText(hwnd, IDC_EDIT2, GlobalPolicy.RedirectFileServer, sizeof GlobalPolicy.RedirectFileServer / sizeof TCHAR);
  1798. GetDlgItemText(hwnd, IDC_EDIT3, GlobalPolicy.CabsPerBucket, sizeof GlobalPolicy.CabsPerBucket / sizeof TCHAR);
  1799. return TRUE;
  1800. ERRORS:
  1801. return FALSE;
  1802. }
  1803. LRESULT CALLBACK EditDefaultDlgProc(HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam)
  1804. {
  1805. switch (iMsg)
  1806. {
  1807. case WM_INITDIALOG:
  1808. InitEditPolicyDlg (hwnd,NULL,FALSE, TRUE);
  1809. return TRUE;
  1810. case WM_DESTROY:
  1811. EndDialog(hwnd, TRUE);
  1812. return TRUE;
  1813. case WM_COMMAND:
  1814. {
  1815. switch (LOWORD(wParam))
  1816. {
  1817. case IDOK:
  1818. if (GetPolicyDlgData(hwnd))
  1819. {
  1820. WriteGlobalPolicyFile();
  1821. }
  1822. else
  1823. ; // What message do we want to display here.
  1824. EndDialog(hwnd, TRUE);
  1825. break;
  1826. case IDCANCEL:
  1827. EndDialog(hwnd, TRUE);
  1828. break;
  1829. }
  1830. }
  1831. break;
  1832. default:
  1833. break;
  1834. }
  1835. return FALSE;
  1836. }
  1837. void DoEditSelectedBucketPolicy(HWND hwnd)
  1838. {
  1839. if (!DialogBox(g_hinst, MAKEINTRESOURCE(IDD_BUCKET_POLICY), hwnd, (DLGPROC) EditSelectedDlgProc))
  1840. {
  1841. ; //MessageBox(NULL, "FAILED TO LOAD TREE", NULL, MB_OK);
  1842. }
  1843. }
  1844. void DoEditDefaultPolicy(HWND hwnd)
  1845. {
  1846. if (!DialogBox(g_hinst, MAKEINTRESOURCE(IDD_GLOBAL_POLICY), hwnd, (DLGPROC) EditDefaultDlgProc))
  1847. {
  1848. ; //MessageBox(NULL, "FAILED TO LOAD TREE", NULL, MB_OK);
  1849. }
  1850. }
  1851. LRESULT CALLBACK MainDlgProc(HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam)
  1852. {
  1853. TCHAR szPath[MAX_PATH];
  1854. HMENU hMenu = NULL;
  1855. switch (iMsg)
  1856. {
  1857. case WM_INITDIALOG:
  1858. OnDlgInit(hwnd);
  1859. return TRUE;
  1860. case WM_DESTROY:
  1861. case WM_CLOSE:
  1862. PostQuitMessage(0);
  1863. return TRUE;
  1864. case WM_COMMAND:
  1865. {
  1866. switch (LOWORD(wParam))
  1867. {
  1868. case ID_FILE_MRU1:
  1869. case ID_FILE_MRU2:
  1870. case ID_FILE_MRU3:
  1871. case ID_FILE_MRU4:
  1872. g_bFirstBucket = TRUE;
  1873. g_bAdminAccess = TRUE;
  1874. ZeroMemory(szPath, sizeof szPath);
  1875. cUserData.CleanupList();
  1876. CsvContents.CleanupList();
  1877. hMenu = GetMenu(hwnd);
  1878. if (hMenu)
  1879. {
  1880. GetMenuStringA(hMenu, LOWORD(wParam), szPath, MAX_PATH, MF_BYCOMMAND);
  1881. if (_tcslen (szPath) > 4)
  1882. {
  1883. if (DoLoadFileTree(hwnd, szPath + 4, FALSE))
  1884. {
  1885. if (ReportMode == USER_MODE)
  1886. {
  1887. DoUserMode(hwnd);
  1888. }
  1889. else
  1890. {
  1891. DoKernelMode(hwnd);
  1892. }
  1893. EnableMenuItems(hwnd);
  1894. }
  1895. }
  1896. //RefreshUserMode(hUserMode);
  1897. //RefreshKrnlView(hKrnlMode);
  1898. }
  1899. break;
  1900. case IDC_KRNLMODE:
  1901. DoKernelMode(hwnd);
  1902. return TRUE;
  1903. case IDC_USERMODE:
  1904. DoUserMode(hwnd);
  1905. return TRUE;
  1906. case ID_REPORT_USERMODEFAULTS:
  1907. ReportUserModeFault(hUserMode, FALSE,0);
  1908. RefreshUserMode(hUserMode);
  1909. return TRUE;
  1910. case ID_REPORT_SELECTEDFAULTS:
  1911. if (ReportMode==USER_MODE)
  1912. {
  1913. ReportUserModeFault(hUserMode, TRUE, GetDlgItem(hUserMode,IDC_USER_LIST));
  1914. RefreshUserMode(hUserMode);
  1915. }
  1916. return TRUE;
  1917. case ID_REPORT_KERNELMODEFAULTS:
  1918. DoSubmitKernelFaults(hKrnlMode);
  1919. return TRUE;
  1920. case ID_FILE_LOADFILETREE:
  1921. g_bFirstBucket = TRUE;
  1922. g_bAdminAccess = TRUE;
  1923. if (DoLoadFileTree(hwnd, NULL, TRUE))
  1924. {
  1925. if (ReportMode == USER_MODE)
  1926. {
  1927. DoUserMode(hwnd);
  1928. }
  1929. else
  1930. {
  1931. DoKernelMode(hwnd);
  1932. }
  1933. EnableMenuItems(hwnd);
  1934. }
  1935. //RefreshUserMode(hUserMode);
  1936. //RefreshKrnlView(hKrnlMode);
  1937. return TRUE;
  1938. case ID_VIEW_REFRESH:
  1939. if (ReportMode == KERNEL_MODE)
  1940. RefreshKrnlView(hKrnlMode);
  1941. else
  1942. RefreshUserMode(hUserMode);
  1943. return TRUE;
  1944. case ID_EDIT_DEFAULTPOLICY:
  1945. DoEditDefaultPolicy(hwnd);
  1946. return TRUE;
  1947. case ID_EDIT_SELECTEDBUCKETSPOLICY:
  1948. if (ReportMode==USER_MODE)
  1949. {
  1950. if (ListView_GetSelectedCount(GetDlgItem(hUserMode, IDC_USER_LIST)) == 1)
  1951. {
  1952. DoEditSelectedBucketPolicy(hwnd);
  1953. RefreshUserMode(hUserMode);
  1954. }
  1955. else
  1956. {
  1957. // what error do we want to display here.
  1958. }
  1959. }
  1960. else
  1961. {
  1962. DoEditSelectedBucketPolicy(hwnd);
  1963. RefreshKrnlView(hKrnlMode);
  1964. }
  1965. return TRUE;
  1966. case ID_VIEW_CRASHLOG:
  1967. ViewCrashLog();
  1968. return TRUE;
  1969. case ID_REPORT_ALLCRASHES:
  1970. ReportUserModeFault(hUserMode, FALSE,0);
  1971. RefreshUserMode(hUserMode);
  1972. DoSubmitKernelFaults(hKrnlMode);
  1973. return FALSE;
  1974. case ID_FILE_CREATEFILETREE:
  1975. DoCreateFileTree(hwnd);
  1976. return TRUE;
  1977. case ID_HELP_ABOUT:
  1978. if (!DialogBox(g_hinst, MAKEINTRESOURCE(IDD_ABOUT), hwnd, (DLGPROC) AboutDlgProc))
  1979. {
  1980. ; //MessageBox(NULL, "FAILED TO LOAD TREE", NULL, MB_OK);
  1981. }
  1982. break;
  1983. case ID_HELP_INDEX120:
  1984. OpenHelpIndex(_T(""));
  1985. break;
  1986. case ID_HELP_CONTENTS:
  1987. OpenHelpTopic(0);
  1988. break;
  1989. /*case ID_EDIT_COPY115:
  1990. if (ReportMode==KERNEL_MODE)
  1991. {
  1992. PostMessage(hKrnlMode, WM_COMMAND, MAKEWPARAM(ID_EDIT_COPY147,0), 0);
  1993. }
  1994. else
  1995. {
  1996. PostMessage(hUserMode, WM_COMMAND, MAKEWPARAM(ID_EDIT_COPY144,0),0);
  1997. }
  1998. break;
  1999. */
  2000. case ID_VIEW_BUCKETCABFILEDIRECTORY:
  2001. if (ReportMode==KERNEL_MODE)
  2002. {
  2003. PostMessage(hKrnlMode, WM_COMMAND, MAKEWPARAM(ID_VIEW_BUCKETCABFILEDIRECTORY,0), 0);
  2004. }
  2005. else
  2006. {
  2007. PostMessage(hUserMode, WM_COMMAND, MAKEWPARAM(ID_VIEW_BUCKETCABFILEDIRECTORY157,0),0);
  2008. }
  2009. break;
  2010. case ID_VIEW_BUCKETOVERRIDERESPONSE:
  2011. if (ReportMode==USER_MODE )
  2012. ViewResponse(hUserMode, FALSE);
  2013. else
  2014. DoLaunchBrowser(hKrnlMode, TRUE);
  2015. break;
  2016. case ID_VIEW_RESPONSESELECTED:
  2017. if (ReportMode==USER_MODE)
  2018. ViewResponse(hUserMode, TRUE);
  2019. else
  2020. DoLaunchBrowser(hKrnlMode, FALSE);
  2021. break;
  2022. case ID_FILE_RELOADFILETREE:
  2023. g_bFirstBucket = TRUE;
  2024. g_bAdminAccess = TRUE;
  2025. cUserData.CleanupList();
  2026. CsvContents.CleanupList();
  2027. if (DoLoadFileTree(hwnd, CerRoot, FALSE))
  2028. {
  2029. EnableMenuItems(hwnd);
  2030. }
  2031. break;
  2032. case ID_FILE_EXIT:
  2033. PostQuitMessage(0);
  2034. break;
  2035. case ID_EXPORT_USERMODEBUCKETDATA:
  2036. ExportUserModeData(hwnd);
  2037. break;
  2038. case ID_EXPORT_KERNELMODEFAULTDATA:
  2039. ExportKernelModeData(hwnd);
  2040. break;
  2041. default:
  2042. break;
  2043. }
  2044. }
  2045. return FALSE;
  2046. case WM_SIZE:
  2047. ResizeKrlMode(hKrnlMode);
  2048. ResizeUserMode(hUserMode);
  2049. return TRUE;
  2050. case WM_ERASEBKGND:
  2051. // Don't know why this doesn't happen automatically...
  2052. {
  2053. HDC hdc = (HDC)wParam;
  2054. HPEN hpen = (HPEN)CreatePen(PS_SOLID, 1, GetSysColor(COLOR_BTNFACE));
  2055. HPEN hpenOld = (HPEN)SelectObject(hdc, hpen);
  2056. SelectObject(hdc, GetSysColorBrush(COLOR_BTNFACE));
  2057. RECT rc;
  2058. GetClientRect(hwnd, &rc);
  2059. Rectangle(hdc, rc.left, rc.top, rc.right, rc.bottom);
  2060. SelectObject(hdc, hpenOld);
  2061. DeleteObject(hpen);
  2062. return TRUE;
  2063. }
  2064. }
  2065. return FALSE;
  2066. }
  2067. /*----------------------------------------------------------------------------
  2068. DragWndProcV
  2069. Window Proc for Vertical Drag Control -- UNICODE WndProc
  2070. ----------------------------------------------------------------- MichMarc --*/
  2071. LRESULT CALLBACK DragWndProcV(HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam)
  2072. {
  2073. switch(iMsg)
  2074. {
  2075. case WM_CREATE:
  2076. return 0;
  2077. case WM_PAINT:
  2078. {
  2079. PAINTSTRUCT ps;
  2080. HDC hdc = BeginPaint(hwnd, &ps);
  2081. HPEN hpenOld = (HPEN)SelectObject(hdc, CreatePen(PS_SOLID, 1, GetSysColor(COLOR_ACTIVEBORDER)));
  2082. MoveToEx(hdc, ps.rcPaint.left, 0, NULL);
  2083. LineTo(hdc, ps.rcPaint.right,0);
  2084. MoveToEx(hdc, ps.rcPaint.left, 2, NULL);
  2085. LineTo(hdc, ps.rcPaint.right,2);
  2086. MoveToEx(hdc, ps.rcPaint.left, 3, NULL);
  2087. LineTo(hdc, ps.rcPaint.right,3);
  2088. DeleteObject(SelectObject(hdc, CreatePen(PS_SOLID, 1, GetSysColor(COLOR_3DHIGHLIGHT))));
  2089. MoveToEx(hdc, ps.rcPaint.left, 1, NULL);
  2090. LineTo(hdc, ps.rcPaint.right,1);
  2091. DeleteObject(SelectObject(hdc, CreatePen(PS_SOLID, 1, GetSysColor(COLOR_3DSHADOW))));
  2092. SelectObject(hdc, GetSysColorBrush(COLOR_3DLIGHT));
  2093. MoveToEx(hdc, ps.rcPaint.left, 4, NULL);
  2094. LineTo(hdc, ps.rcPaint.right,4);
  2095. DeleteObject(SelectObject(hdc, CreatePen(PS_SOLID, 1, GetSysColor(COLOR_3DDKSHADOW))));
  2096. SelectObject(hdc, GetSysColorBrush(COLOR_3DLIGHT));
  2097. MoveToEx(hdc, ps.rcPaint.left, 5, NULL);
  2098. LineTo(hdc, ps.rcPaint.right,5);
  2099. DeleteObject(SelectObject(hdc, hpenOld));
  2100. EndPaint(hwnd, &ps);
  2101. return 0;
  2102. }
  2103. case WM_LBUTTONDOWN:
  2104. PostMessage(GetParent(hwnd), WM_COMMAND, GetWindowLong(hwnd, GWL_ID), (LPARAM)hwnd);
  2105. return 0;
  2106. }
  2107. return DefWindowProcW(hwnd, iMsg, wParam, lParam);
  2108. };
  2109. /*---------------------------------------------------------------------------
  2110. InitWindowClasses
  2111. Registers custom window classes
  2112. --------------------------------------------------------------- MichMarc --*/
  2113. /*void InitWindowClasses(void)
  2114. {
  2115. WNDCLASSEXW wc;
  2116. wc.cbSize = sizeof(WNDCLASSEXW);
  2117. wc.style = CS_HREDRAW | CS_VREDRAW;
  2118. wc.lpfnWndProc = DragWndProcV;
  2119. wc.cbClsExtra = 0;
  2120. wc.cbWndExtra = 0;
  2121. wc.hInstance = g_hinst;
  2122. wc.hIcon = NULL;
  2123. wc.hCursor = LoadCursor(NULL, IDC_SIZENS);
  2124. wc.hbrBackground = (HBRUSH)(COLOR_BTNFACE+1);
  2125. wc.lpszMenuName = NULL;
  2126. wc.lpszClassName = L"DragControlV";
  2127. wc.hIconSm = NULL;
  2128. RegisterClassExW(&wc);
  2129. wc.cbSize = sizeof(WNDCLASSEXW);
  2130. wc.style = CS_HREDRAW | CS_VREDRAW;
  2131. wc.lpfnWndProc = DragWndProcH;
  2132. wc.cbClsExtra = 0;
  2133. wc.cbWndExtra = 0;
  2134. wc.hInstance = vhintl;
  2135. wc.hIcon = NULL;
  2136. wc.hCursor = LoadCursor(NULL, IDC_SIZENS);
  2137. wc.hbrBackground = (HBRUSH)(COLOR_BTNFACE+1);
  2138. wc.lpszMenuName = NULL;
  2139. wc.lpszClassName = L"DragControlH";
  2140. wc.hIconSm = NULL;
  2141. RegisterClassExW(&wc);
  2142. }
  2143. */
  2144. int WINAPI WinMain(HINSTANCE hinst, HINSTANCE hinstPrev, LPSTR szCmdLine,
  2145. int nShowCmd)
  2146. {
  2147. MSG msg;
  2148. HWND hwnd = NULL;
  2149. g_hinst = hinst;
  2150. INITCOMMONCONTROLSEX InitCtrls;
  2151. InitCommonControlsEx(&InitCtrls);
  2152. //InitWindowClasses();
  2153. LoadIcon(hinst, MAKEINTRESOURCE(IDI_MAIN));
  2154. hwnd = CreateDialog(g_hinst,
  2155. MAKEINTRESOURCE(IDD_MAIN),
  2156. NULL,
  2157. (DLGPROC)MainDlgProc);
  2158. g_hWnd = hwnd;
  2159. if (hwnd)
  2160. {
  2161. while(GetMessageW(&msg, NULL, 0, 0))
  2162. //if (!TranslateAcceleratorW(hwnd, hAccel, &msg))
  2163. if (!IsDialogMessageW(hwnd, &msg))
  2164. {
  2165. TranslateMessage(&msg);
  2166. DispatchMessageW(&msg);
  2167. }
  2168. }
  2169. return 0;
  2170. }