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.

681 lines
18 KiB

  1. #include "compatadmin.h"
  2. #include "Controls.h"
  3. #ifndef __CAPPHELPWIZARD_H
  4. #include "CAppHelpWizard.h"
  5. #endif
  6. #define NOBLOCK 1
  7. #define BLOCK 2
  8. #define PAGE_GETAPP_INFO 0
  9. #define PAGE_GET_MATCH_FILES 1
  10. #define PAGE_GETMESSAGE_TYPE 2
  11. #define PAGE_GETMESSAGE_INFORMATION 3
  12. #define PAGE_DONE 4
  13. #define NUM_PAGES (PAGE_DONE + 1)
  14. extern CShimWizard* g_pCurrentWizard;
  15. UINT g_nMAXHELPID = 0;
  16. BOOL
  17. DeleteAppHelp (
  18. UINT nHelpID
  19. );
  20. BOOL
  21. WipeAppHelp(
  22. PDBRECORD pRecord
  23. );
  24. BOOL
  25. CAppHelpWizard::BeginWizard(
  26. HWND hParent
  27. )
  28. {
  29. PROPSHEETPAGE Pages[NUM_PAGES];
  30. ZeroMemory(&m_Record,sizeof(m_Record));
  31. //
  32. // BUGBUG: This can overwrite the existing guid.
  33. //
  34. CoCreateGuid(&m_Record.guidID);
  35. // Setup wizard variables
  36. g_pCurrentWizard = this;
  37. g_pCurrentWizard->m_uType = TYPE_APPHELP;
  38. // begin the wizard
  39. PROPSHEETHEADER Header;
  40. Header.dwSize = sizeof(PROPSHEETHEADER);
  41. Header.dwFlags = PSH_WIZARD97 | PSH_PROPSHEETPAGE | PSH_HEADER;
  42. Header.hwndParent = hParent;
  43. Header.hInstance = g_hInstance;
  44. Header.pszCaption = MAKEINTRESOURCE(IDS_WIZARD);
  45. Header.nStartPage = 0;
  46. Header.ppsp = Pages;
  47. Header.nPages = NUM_PAGES;
  48. Header.pszbmHeader = MAKEINTRESOURCE(IDB_WIZBMP);
  49. Pages[PAGE_GETAPP_INFO].dwSize = sizeof(PROPSHEETPAGE);
  50. Pages[PAGE_GETAPP_INFO].dwFlags = PSP_USEHEADERSUBTITLE;
  51. Pages[PAGE_GETAPP_INFO].hInstance = g_hInstance;
  52. Pages[PAGE_GETAPP_INFO].pszTemplate = MAKEINTRESOURCE(IDD_APPHELP1);
  53. Pages[PAGE_GETAPP_INFO].pfnDlgProc = (DLGPROC)GetAppInfo;
  54. Pages[PAGE_GETAPP_INFO].pszHeaderSubTitle = TEXT("Give Application information");
  55. Pages[PAGE_GET_MATCH_FILES].dwSize = sizeof(PROPSHEETPAGE);
  56. Pages[PAGE_GET_MATCH_FILES].dwFlags = PSP_USEHEADERSUBTITLE;
  57. Pages[PAGE_GET_MATCH_FILES].hInstance = g_hInstance;
  58. Pages[PAGE_GET_MATCH_FILES].pszTemplate = MAKEINTRESOURCE(IDD_ADDWIZARD7);
  59. Pages[PAGE_GET_MATCH_FILES].pfnDlgProc = (DLGPROC)SelectFiles;
  60. Pages[PAGE_GET_MATCH_FILES].pszHeaderSubTitle = TEXT("Select files used for application identification");
  61. Pages[PAGE_GETMESSAGE_TYPE].dwSize = sizeof(PROPSHEETPAGE);
  62. Pages[PAGE_GETMESSAGE_TYPE].dwFlags = PSP_USEHEADERSUBTITLE;
  63. Pages[PAGE_GETMESSAGE_TYPE].hInstance = g_hInstance;
  64. Pages[PAGE_GETMESSAGE_TYPE].pszTemplate = MAKEINTRESOURCE(IDD_APPHELP2);
  65. Pages[PAGE_GETMESSAGE_TYPE].pfnDlgProc = (DLGPROC)GetMessageType;
  66. Pages[PAGE_GETMESSAGE_TYPE].pszHeaderSubTitle = TEXT("Enter Message Type");
  67. Pages[PAGE_GETMESSAGE_INFORMATION].dwSize = sizeof(PROPSHEETPAGE);
  68. Pages[PAGE_GETMESSAGE_INFORMATION].dwFlags = PSP_USEHEADERSUBTITLE;
  69. Pages[PAGE_GETMESSAGE_INFORMATION].hInstance = g_hInstance;
  70. Pages[PAGE_GETMESSAGE_INFORMATION].pszTemplate = MAKEINTRESOURCE(IDD_APPHELP3);
  71. Pages[PAGE_GETMESSAGE_INFORMATION].pfnDlgProc = (DLGPROC)GetMessageInformation;
  72. Pages[PAGE_GETMESSAGE_INFORMATION].pszHeaderSubTitle = TEXT("Enter message information");
  73. Pages[PAGE_DONE].dwSize = sizeof(PROPSHEETPAGE);
  74. Pages[PAGE_DONE].dwFlags = PSP_USEHEADERSUBTITLE;
  75. Pages[PAGE_DONE].hInstance = g_hInstance;
  76. Pages[PAGE_DONE].pszTemplate = MAKEINTRESOURCE(IDD_APPHELPDONE);
  77. Pages[PAGE_DONE].pfnDlgProc = (DLGPROC)AppWizardDone;
  78. Pages[PAGE_DONE].pszHeaderSubTitle = TEXT("Custom AppHelp has been created !");
  79. if ( 0 < PropertySheet(&Header) ) {
  80. PDBRECORD pRecord = new DBRECORD;
  81. if ( NULL != pRecord ) {
  82. ZeroMemory(pRecord,sizeof(DBRECORD));
  83. pRecord->szEXEName = m_Record.szEXEName;
  84. pRecord->szAppName = m_Record.szAppName;
  85. pRecord->guidID = m_Record.guidID;
  86. pRecord->pEntries = m_Record.pEntries;
  87. g_theApp.GetDBLocal().InsertRecord(pRecord);
  88. return TRUE;
  89. }
  90. }else{
  91. //
  92. // Cancel pressed, we migth have to delete the new apphelp in the Database.
  93. //
  94. if (nPresentHelpId != -1) {
  95. DeleteAppHelp(g_nMAXHELPID);
  96. nPresentHelpId = -1;
  97. --g_nMAXHELPID;
  98. }
  99. }
  100. return FALSE;
  101. }
  102. //////////////////////////////////////////////////////
  103. // Dilaog Box routines //
  104. //////////////////////////////////////////////////////
  105. BOOL
  106. CALLBACK
  107. GetAppInfo(
  108. HWND hDlg,
  109. UINT uMsg,
  110. WPARAM wParam,
  111. LPARAM lParam
  112. )
  113. {
  114. switch ( uMsg ) {
  115. case WM_INITDIALOG:
  116. {
  117. //
  118. // Heading
  119. //
  120. HWND hParent = GetParent(hDlg);
  121. SetWindowText(hParent,TEXT("Create a custom AppHelp message"));
  122. //
  123. // Limit the length of the text boxes
  124. //
  125. SendMessage(
  126. GetDlgItem(hDlg,IDC_APPNAME), // handle to destination window
  127. EM_LIMITTEXT, // message to send
  128. (WPARAM) LIMIT_APP_NAME, // text length
  129. (LPARAM) 0
  130. );
  131. SendMessage(
  132. GetDlgItem(hDlg,IDC_EXEPATH), // handle to destination window
  133. EM_LIMITTEXT, // message to send
  134. (WPARAM) MAX_PATH, // text length
  135. (LPARAM) 0
  136. );
  137. if ( 0 == g_pCurrentWizard->m_Record.szAppName.Length() )
  138. g_pCurrentWizard->m_Record.szAppName = TEXT("No Name");
  139. SetDlgItemText(hDlg,IDC_APPNAME, g_pCurrentWizard->m_Record.szAppName);
  140. if ( g_pCurrentWizard->m_Record.szAppName == TEXT("No Name") )
  141. SendMessage(GetDlgItem(hDlg,IDC_APPNAME),EM_SETSEL,0,-1);
  142. // Force proper Next button state.
  143. SHAutoComplete(GetDlgItem(hDlg,IDC_EXEPATH), AUTOCOMPLETE);
  144. SendMessage(hDlg,WM_COMMAND,MAKEWPARAM(IDC_APPNAME,EN_CHANGE),0);
  145. }
  146. break;
  147. case WM_NOTIFY:
  148. {
  149. NMHDR * pHdr = (NMHDR *) lParam;
  150. switch ( pHdr->code ) {
  151. case PSN_SETACTIVE:
  152. {
  153. SendMessage(hDlg,WM_COMMAND,MAKEWPARAM(IDC_NAME,EN_CHANGE),0);
  154. }
  155. break;
  156. case PSN_WIZNEXT:
  157. {
  158. TCHAR szTemp[MAX_STRING_SIZE];
  159. TCHAR szEXEPath[MAX_PATH_BUFFSIZE];
  160. GetDlgItemText(hDlg,IDC_APPNAME,szTemp,MAX_STRING_SIZE);
  161. CSTRING::Trim(szTemp);
  162. g_pCurrentWizard->m_Record.szAppName = szTemp;
  163. GetDlgItemText(hDlg,IDC_EXEPATH,szEXEPath,MAX_PATH_BUFFSIZE);
  164. CSTRING::Trim(szEXEPath);
  165. HANDLE hFile = CreateFile (szEXEPath,
  166. 0,
  167. 0,
  168. NULL,
  169. OPEN_EXISTING,
  170. FILE_ATTRIBUTE_NORMAL,
  171. NULL);
  172. if ( INVALID_HANDLE_VALUE == hFile ) {
  173. MessageBox(hDlg,TEXT("Unable to locate specified file"),TEXT("Invalid file name"),MB_OK);
  174. SetWindowLongPtr(hDlg,DWLP_MSGRESULT,-1);
  175. return -1;
  176. }
  177. g_pCurrentWizard->m_szLongName = szEXEPath;
  178. CSTRING str = szEXEPath;
  179. g_pCurrentWizard->m_Record.szEXEName = str;
  180. g_pCurrentWizard->m_Record.szEXEName.ShortFilename();
  181. }
  182. break;
  183. }
  184. }
  185. break;
  186. case WM_COMMAND:
  187. switch ( LOWORD(wParam) ) {
  188. case IDC_EXEPATH:
  189. case IDC_APPNAME:
  190. if ( EN_CHANGE == HIWORD(wParam) ) {
  191. TCHAR szTemp[MAX_STRING_SIZE];
  192. GetDlgItemText(hDlg,IDC_APPNAME,szTemp,MAX_STRING_SIZE);
  193. BOOL bEnable = ( CSTRING::Trim(szTemp) > 0) ? TRUE:FALSE;
  194. bEnable &= (GetWindowTextLength(GetDlgItem(hDlg,IDC_EXEPATH)) > 0) ? TRUE:FALSE;
  195. DWORD dwFlags = PSWIZB_BACK;
  196. if ( bEnable )
  197. dwFlags |= PSWIZB_NEXT;
  198. SendMessage(GetParent(hDlg),PSM_SETWIZBUTTONS,0, dwFlags);
  199. }
  200. break;
  201. case IDC_BROWSE:
  202. {
  203. CSTRING szFilename;
  204. HWND hwndFocus = GetFocus();
  205. if ( g_theApp.GetFilename(TEXT("Find executable"),
  206. TEXT("EXE File (*.EXE)\0*.EXE\0All files (*.*)\0*.*\0\0"),
  207. TEXT(""),
  208. TEXT("EXE"),
  209. OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST,
  210. TRUE,
  211. szFilename)) {
  212. SetDlgItemText(hDlg,IDC_EXEPATH,szFilename);
  213. // Force proper Next button state.
  214. SendMessage(hDlg,WM_COMMAND,MAKEWPARAM(IDC_EXEPATH,EN_CHANGE),0);
  215. }
  216. SetFocus( hwndFocus );
  217. }
  218. break;
  219. }//switch ( LOWORD(wParam) )
  220. }// switch ( uMsg )
  221. return FALSE;
  222. }//end of GetAppName(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
  223. BOOL
  224. CALLBACK
  225. GetMessageType (
  226. HWND hDlg,
  227. UINT uMsg,
  228. WPARAM wParam,
  229. LPARAM lParam)
  230. {
  231. switch ( uMsg ) {
  232. case WM_INITDIALOG:
  233. {
  234. SendMessage(GetDlgItem(hDlg,IDC_NOBLOCK),
  235. BM_SETCHECK, // message to send
  236. (WPARAM) 1, // check state
  237. (LPARAM) 0 // not used; must be zero
  238. );
  239. return TRUE;
  240. }
  241. case WM_NOTIFY:
  242. {
  243. NMHDR * pHdr = (NMHDR *) lParam;
  244. switch ( pHdr->code ) {
  245. case PSN_WIZNEXT:
  246. {
  247. int iReturn = SendMessage(GetDlgItem(hDlg,IDC_NOBLOCK),
  248. BM_GETCHECK, // message to send
  249. (WPARAM) 1, // check state
  250. (LPARAM) 0 // not used; must be zero
  251. );
  252. if (iReturn == BST_CHECKED) {
  253. ((CAppHelpWizard*)g_pCurrentWizard)->bBlock = FALSE;
  254. }else{
  255. ((CAppHelpWizard*)g_pCurrentWizard)->bBlock = TRUE;
  256. }
  257. return TRUE;
  258. }
  259. case PSN_SETACTIVE:
  260. {
  261. DWORD dwFlags = PSWIZB_NEXT | PSWIZB_BACK;
  262. SendMessage(GetParent(hDlg),PSM_SETWIZBUTTONS,0, dwFlags);
  263. return TRUE;
  264. }
  265. }//switch( pHdr->code )
  266. break;
  267. }
  268. }//SWITCH
  269. return FALSE;
  270. }//end of GetMessageType (HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  271. BOOL
  272. CALLBACK
  273. GetMessageInformation (
  274. HWND hDlg,
  275. UINT uMsg,
  276. WPARAM wParam,
  277. LPARAM lParam
  278. )
  279. {
  280. switch ( uMsg ) {
  281. case WM_INITDIALOG:
  282. {
  283. //
  284. // Set the maximum length of the text boxes
  285. //
  286. SendMessage(
  287. GetDlgItem(hDlg,IDC_URL), // handle to destination window
  288. EM_LIMITTEXT, // message to send
  289. (WPARAM) 1024, // text length
  290. (LPARAM) 0
  291. );
  292. SendMessage(
  293. GetDlgItem(hDlg,IDC_MSG_SUMMARY), // handle to destination window
  294. EM_LIMITTEXT, // message to send
  295. (WPARAM) 1024, // text length
  296. (LPARAM) 0
  297. );
  298. // Force proper Next button state.
  299. SendMessage(hDlg,WM_COMMAND,MAKEWPARAM(IDC_MSG_SUMMARY,EN_CHANGE),0);
  300. }
  301. break;
  302. case WM_NOTIFY:
  303. {
  304. NMHDR * pHdr = (NMHDR *) lParam;
  305. switch ( pHdr->code ) {
  306. case PSN_SETACTIVE:
  307. {
  308. SendMessage(hDlg,WM_COMMAND,MAKEWPARAM(IDC_MSG_SUMMARY,EN_CHANGE),0);
  309. }
  310. break;
  311. case PSN_WIZNEXT:
  312. {
  313. PAPPHELP pAppHelp = new APPHELP;
  314. if (pAppHelp == NULL) {
  315. MEM_ERR;
  316. return FALSE;
  317. }
  318. pAppHelp->HTMLHELPID = ++g_nMAXHELPID;
  319. ((CAppHelpWizard*)g_pCurrentWizard)->nPresentHelpId = pAppHelp->HTMLHELPID;
  320. TCHAR szTemp[2048];
  321. *szTemp = 0;
  322. GetDlgItemText(hDlg,IDC_MSG_SUMMARY,szTemp,1024);
  323. pAppHelp->strMessage = szTemp;
  324. //
  325. // Add the APPHELP message in the Library.
  326. //
  327. pAppHelp->pNext = g_theApp.GetDBLocal().m_pAppHelp;
  328. g_theApp.GetDBLocal().m_pAppHelp = pAppHelp;
  329. //
  330. // Add the AppHelp for the entry
  331. //
  332. PHELPENTRY pHelp = new HELPENTRY;
  333. if ( NULL != pHelp ) {
  334. pHelp->Entry.uType = ENTRY_APPHELP;
  335. pHelp->uHelpID = ((CAppHelpWizard*)g_pCurrentWizard)->nPresentHelpId;
  336. pHelp->bBlock = ((CAppHelpWizard*)g_pCurrentWizard)->bBlock ;
  337. if (pHelp->bBlock) {
  338. pHelp->uSeverity = BLOCK;
  339. }else{
  340. pHelp->uSeverity = NOBLOCK;
  341. }
  342. *szTemp = 0;
  343. GetDlgItemText(hDlg,IDC_URL,szTemp,1024);
  344. pHelp->strURL = szTemp;
  345. pHelp->Entry.pNext = ((CAppHelpWizard*)g_pCurrentWizard)->m_Record.pEntries;
  346. ((CAppHelpWizard*)g_pCurrentWizard)->m_Record.pEntries = (PDBENTRY)pHelp;
  347. }else{
  348. MEM_ERR;
  349. }
  350. return TRUE;
  351. }
  352. }
  353. }
  354. break;
  355. case WM_COMMAND:
  356. switch ( LOWORD(wParam) ) {
  357. case IDC_MSG_SUMMARY:
  358. if ( EN_CHANGE == HIWORD(wParam) ) {
  359. BOOL bEnable = (GetWindowTextLength(GetDlgItem(hDlg,IDC_MSG_SUMMARY)) > 0) ? TRUE:FALSE;
  360. DWORD dwFlags = PSWIZB_BACK;
  361. if ( bEnable )
  362. dwFlags |= PSWIZB_NEXT;
  363. SendMessage(GetParent(hDlg),PSM_SETWIZBUTTONS,0, dwFlags);
  364. }
  365. break;
  366. }//switch ( LOWORD(wParam) )
  367. }// switch ( uMsg )
  368. return FALSE;
  369. }//end of GetMessageInformation (HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  370. BOOL
  371. CALLBACK
  372. AppWizardDone (
  373. HWND hDlg,
  374. UINT uMsg,
  375. WPARAM wParam,
  376. LPARAM lParam)
  377. {
  378. switch ( uMsg ) {
  379. case WM_NOTIFY:
  380. {
  381. NMHDR * pHdr = (NMHDR *) lParam;
  382. switch ( pHdr->code ) {
  383. case PSN_SETACTIVE:
  384. SendMessage(GetParent(hDlg),PSM_SETWIZBUTTONS, 0, PSWIZB_BACK | PSWIZB_FINISH);
  385. return TRUE;
  386. case PSN_WIZBACK:
  387. {
  388. //
  389. // We have to delete the apphelp message that has been added to the library.
  390. //
  391. if (((CAppHelpWizard*)g_pCurrentWizard)->nPresentHelpId != -1) {
  392. DeleteAppHelp(g_nMAXHELPID);
  393. --g_nMAXHELPID;
  394. ((CAppHelpWizard*)g_pCurrentWizard)->nPresentHelpId = -1;
  395. WipeAppHelp(&((CAppHelpWizard*)g_pCurrentWizard)->m_Record);
  396. }
  397. break;
  398. }
  399. }
  400. }
  401. break;
  402. case WM_COMMAND:
  403. switch ( LOWORD(wParam) ) {
  404. case IDC_TESTRUN:
  405. {
  406. HWND hndFocus = GetFocus();
  407. g_theApp.TestRun(&g_pCurrentWizard->m_Record,&g_pCurrentWizard->m_szLongName,NULL,hDlg);
  408. SetFocus(hndFocus);
  409. return TRUE;
  410. }
  411. break;
  412. }
  413. break;
  414. }
  415. return FALSE;
  416. }//end of WizardDone (HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  417. BOOL
  418. DeleteAppHelp (
  419. UINT nHelpID
  420. )
  421. {
  422. PAPPHELP pAppHelp = g_theApp.GetDBLocal().m_pAppHelp,
  423. pPrev = NULL;
  424. while (pAppHelp){
  425. if (pAppHelp->HTMLHELPID == nHelpID) {
  426. if (pPrev == NULL) {
  427. //
  428. // This is the first element
  429. //
  430. g_theApp.GetDBLocal().m_pAppHelp = g_theApp.GetDBLocal().m_pAppHelp->pNext;
  431. }else{
  432. pPrev->pNext = pAppHelp->pNext;
  433. }
  434. delete pAppHelp;
  435. return TRUE;
  436. }else{
  437. pPrev = pAppHelp;
  438. pAppHelp = pAppHelp->pNext;
  439. }
  440. }
  441. return FALSE;
  442. }
  443. BOOL
  444. WipeAppHelp(
  445. PDBRECORD pRecord
  446. )
  447. {
  448. PDBENTRY pEntry = pRecord->pEntries;
  449. PDBENTRY pPrev = NULL;
  450. while (pEntry) {
  451. if ( ENTRY_APPHELP == pEntry->uType) {
  452. if (pPrev == NULL) {
  453. pRecord->pEntries = pEntry->pNext;
  454. }
  455. else{
  456. pPrev->pNext = pEntry->pNext;
  457. }
  458. delete pEntry;
  459. return TRUE;
  460. }else{
  461. pEntry = pEntry->pNext;
  462. }
  463. }
  464. return FALSE;
  465. }