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.

4029 lines
120 KiB

  1. /*
  2. * pmdlgs.c - program manager dialog procedures
  3. *
  4. * Copyright (c) 1991, Microsoft Corporation
  5. *
  6. * DESCRIPTION
  7. *
  8. * This file is for support of program manager under NT Windows.
  9. * This file is/was ported from pmdlgs.c (program manager).
  10. *
  11. * MODIFICATION HISTORY
  12. * Initial Version: x/x/90 Author Unknown, since he didn't feel
  13. * like lettings us know...
  14. *
  15. * NT 32b Version: 2/1/91 Jeff Pack
  16. * Intitial port to begin.
  17. *
  18. *
  19. */
  20. #include "progman.h"
  21. #include "commdlg.h"
  22. #include "io.h"
  23. #include "stdio.h"
  24. #include <vdmapi.h>
  25. #define CBCUSTFILTER 40 // Max size of custom filter.
  26. BOOL fFirstPass; // For IconDlgProc so we can fill the list
  27. // with stuff from progman if the first
  28. // file given has no icons.
  29. BOOL fNewIcon; // Flags if the icon has been explicitely
  30. // set.
  31. extern BOOL bHandleProgramGroupsEvent;
  32. TCHAR szDotPIF[] = TEXT(".pif");
  33. TCHAR szCommdlg[] = TEXT("comdlg32.dll"); // The name of the common dialog.
  34. typedef BOOL (APIENTRY *OPENFILENAME_PROC)(LPOPENFILENAME); // Commdlgs GetOpenFileName routine.
  35. OPENFILENAME_PROC lpfnGOFN;
  36. #define szGetOpenFileName "GetOpenFileNameW"
  37. /* from pmgseg.c */
  38. DWORD PASCAL SizeofGroup(LPGROUPDEF lpgd);
  39. void RemoveBackslashFromKeyName(LPTSTR lpKeyName);
  40. VOID CentreWindow(HWND hwnd);
  41. VOID FreeIconList(HANDLE hIconList, int iKeepIcon);
  42. #define CHECK_BINARY_EVENT_NAME TEXT("CheckBinaryEvent")
  43. #define CHECK_BINARY_ID 1
  44. BOOL bCheckBinaryType;
  45. HANDLE hCheckBinaryEvent;
  46. UINT uiCheckBinaryTimeout;
  47. BOOL bCheckBinaryDirtyFlag;
  48. void CheckBinaryThread (LPVOID);
  49. extern TCHAR szCheckBinaryType[];
  50. extern TCHAR szCheckBinaryTimeout[];
  51. //#ifdef JAPAN
  52. //BOOL CheckPortName(HWND,LPTSTR );
  53. //BOOL PortName(LPTSTR );
  54. //#endif
  55. BOOL APIENTRY InQuotes(LPTSTR sz)
  56. {
  57. if (*sz == TEXT('"') && *(sz + lstrlen(sz) - 1) == TEXT('"')) {
  58. return(TRUE);
  59. }
  60. return(FALSE);
  61. }
  62. //-------------------------------------------------------------------------
  63. // Removes leading and trailing spaces.
  64. VOID APIENTRY RemoveLeadingSpaces(LPTSTR sz)
  65. {
  66. TCHAR *pChr2;
  67. LPTSTR lpTmp;
  68. while(*sz == TEXT(' ')) {
  69. // First Char is a space.
  70. // Move them all down one.
  71. for (pChr2 = sz; *pChr2; pChr2++) {
  72. *pChr2 = *(pChr2+1);
  73. }
  74. }
  75. if (!*sz) {
  76. return;
  77. }
  78. lpTmp = sz + lstrlen(sz) - 1;
  79. while (*lpTmp && *lpTmp == TEXT(' ')) {
  80. *lpTmp-- = TEXT('\0');
  81. }
  82. }
  83. /*** GroupFull - Check for full group. Returns FALSE if the group isn't full.
  84. *
  85. *
  86. * BOOL PASCAL GroupFull(PGROUP pGroup)
  87. *
  88. * ENTRY - PGROUP pGroup
  89. *
  90. * EXIT - BOOL - returns TRUE if group is full
  91. *
  92. * SYNOPSIS -
  93. *
  94. * WARNINGS -
  95. * EFFECTS -
  96. *
  97. * 08-08-91 JohanneC - ported from Windows 3.1
  98. *
  99. */
  100. BOOL PASCAL GroupFull(PGROUP pGroup)
  101. {
  102. WORD i=0;
  103. PITEM pItem;
  104. BOOL ret;
  105. // Count the items in the group.
  106. for (pItem = pGroup->pItems;pItem;pItem = pItem->pNext)
  107. i++;
  108. if (i >= CITEMSMAX) {
  109. MyMessageBox(hwndProgman, IDS_GROUPFILEERR, IDS_TOOMANYITEMS, NULL,
  110. MB_OK | MB_ICONEXCLAMATION|MB_SYSTEMMODAL);
  111. ret = TRUE;
  112. }
  113. else
  114. ret = FALSE;
  115. return ret;
  116. }
  117. /*** ValidPathDrive
  118. *
  119. *
  120. * BOOL APIENTRY ValidPathDrive(LPTSTR lpPath)
  121. *
  122. * ENTRY - LPTSTR lpPath - pointer to path
  123. *
  124. * EXIT - BOOL - returns TRUE if drive path is valid
  125. *
  126. * SYNOPSIS - Check the drive letter of the given path (if it has one).
  127. *
  128. * WARNINGS -
  129. * EFFECTS -
  130. *
  131. * 08-08-91 JohanneC - ported from Windows 3.1
  132. *
  133. */
  134. BOOL APIENTRY PASCAL ValidPathDrive(LPTSTR lpPath)
  135. {
  136. int nValid;
  137. TCHAR szDriveRoot[4] = TEXT("?:\\");
  138. // Store first letter of path.
  139. *szDriveRoot = *lpPath;
  140. lpPath = CharNext(lpPath);
  141. if (*lpPath == TEXT(':')) {
  142. //
  143. // It's got a drive letter. Test the drive type with the root directory.
  144. //
  145. nValid = GetDriveType(szDriveRoot);
  146. if ( nValid == 1 || nValid == 0) {
  147. return FALSE;
  148. }
  149. else {
  150. return TRUE;
  151. }
  152. }
  153. return TRUE;
  154. }
  155. /*** StripArgs -- strip everything after a space
  156. *
  157. *
  158. * VOID APIENTRY StripArgs(LPTSTR szCmmdLine)
  159. *
  160. * ENTRY - LPTSTR szCmmdLine - Pointer to command line
  161. * int index
  162. *
  163. *
  164. * EXIT - VOID
  165. *
  166. * SYNOPSIS - This searches for first space, and places NULL there, stripping
  167. * everything after that
  168. *
  169. * WARNINGS -
  170. * EFFECTS -
  171. *
  172. */
  173. void NEAR PASCAL StripArgs(LPTSTR szCmmdLine)
  174. {
  175. TCHAR *pch;
  176. //
  177. // first skip leading spaces
  178. //
  179. for (pch = szCmmdLine; *pch && *pch == TEXT(' '); pch = CharNext(pch))
  180. ;
  181. //
  182. // check if we have a quote, if so look for second quote.
  183. //
  184. if (*pch == TEXT('"')) {
  185. for (pch++; *pch; pch = CharNext(pch)) {
  186. if (*pch == TEXT('"')) {
  187. // Found it, limit string at this point.
  188. pch++;
  189. *pch = TEXT('\0');
  190. break;
  191. }
  192. }
  193. }
  194. else {
  195. // Search forward to find the first space in the cmmd line.
  196. for (; *pch; pch = CharNext(pch)) {
  197. if (*pch == TEXT(' ')) {
  198. // Found it, limit string at this point.
  199. *pch = TEXT('\0');
  200. break;
  201. }
  202. }
  203. }
  204. }
  205. /*** GetPathInfo -- tokenizes string to path/name/extension components
  206. *
  207. *
  208. * VOID APIENTRY GetPathInfo(LPTSTR szPath, LPTSTR *pszLastSlash, LPTSTR *pszExt, DWORD *pich)
  209. *
  210. * ENTRY - LPTSTR szPath - pointer to path stuff
  211. * LPTSTR *pszLastSlash - last slash in path
  212. * LPTSTR *pszExt - pointer to extension
  213. * WORD *plich - index of last slash
  214. *
  215. *
  216. * EXIT - VOID
  217. *
  218. * SYNOPSIS - This searches for first space, and places NULL there, stripping
  219. * everything after that
  220. *
  221. * WARNINGS - BUG BUG , NOT LFN aware!
  222. * EFFECTS -
  223. *
  224. */
  225. void PASCAL GetPathInfo(LPTSTR szPath,
  226. LPTSTR *pszFileName,
  227. LPTSTR *pszExt,
  228. WORD *pich,
  229. BOOL *pfUnc)
  230. {
  231. TCHAR *pch; // Temp variable.
  232. WORD ich = 0; // Temp.
  233. BOOL InQuotes;
  234. *pszExt = NULL; // If no extension, return NULL.
  235. *pszFileName = szPath; // If no seperate filename component, return path.
  236. *pich = 0;
  237. *pfUnc = FALSE; // Default to not UNC style.
  238. //
  239. // Check if path is in quotes.
  240. //
  241. if (InQuotes = (*szPath == TEXT('"'))) {
  242. szPath++;
  243. }
  244. // Check for UNC style paths.
  245. if (*szPath == TEXT('\\') && *(szPath+1) == TEXT('\\'))
  246. *pfUnc = TRUE;
  247. // Search forward to find the last backslash or colon in the path.
  248. // While we're at it, look for the last dot.
  249. for (pch = szPath; *pch; pch = CharNext(pch)) {
  250. if ((*pch == TEXT(' ')) && (!InQuotes)) {
  251. // Found a space - stop here.
  252. break;
  253. }
  254. if (*pch == TEXT('"')) {
  255. // Found a the second quote - stop here.
  256. pch++;
  257. break;
  258. }
  259. if (*pch == TEXT('\\') || *pch == TEXT(':')) {
  260. // Found it, record ptr to it and it's index.
  261. *pszFileName = pch+1;
  262. *pich = ich + (WORD)1;
  263. }
  264. if (*pch == TEXT('.')) {
  265. // Found a dot.
  266. *pszExt = pch;
  267. }
  268. ich++;
  269. }
  270. /* Check that the last dot is part of the last filename. */
  271. if (*pszExt < *pszFileName)
  272. *pszExt = NULL;
  273. }
  274. /*** TagExtension
  275. *
  276. *
  277. * void APIENTRY TagExtension(PSTR pszPath, UINT cbPath)
  278. *
  279. * ENTRY - PSTR pszPath -
  280. * UINT cbPath - length of path in bytes
  281. *
  282. * EXIT -
  283. *
  284. * SYNOPSIS - Checks a string to see if it has an extension.
  285. * If it doesn't then .exe will be appended.
  286. *
  287. * WARNINGS -
  288. * EFFECTS -
  289. *
  290. * 08-08-91 JohanneC - ported from Windows 3.1
  291. *
  292. */
  293. void FAR PASCAL TagExtension(LPTSTR szPath, UINT cbPath)
  294. {
  295. DWORD dummy;
  296. LPTSTR szFileName;
  297. LPTSTR pszExt;
  298. LPTSTR pch;
  299. GetPathInfo(szPath, &szFileName, &pszExt, (WORD*) &dummy, (BOOL*) &dummy);
  300. if (!pszExt && (sizeof(TCHAR) * (lstrlen(szPath) + 5)) < cbPath) {
  301. // No extension, tag on a ".exe"
  302. // but first check if the path is in quotes
  303. pch = szPath + lstrlen(szPath);
  304. if (InQuotes(szPath)) {
  305. *pch = TEXT('\0');
  306. lstrcat(szPath, TEXT(".exe\""));
  307. }
  308. else {
  309. lstrcat(szPath, TEXT(".exe"));
  310. }
  311. }
  312. }
  313. // PIF stuff added 1/9/92
  314. #define PTITLELEN 30
  315. #define PPATHLEN 63
  316. #define PATHMAX 64
  317. #define COMMAX 64
  318. #define PIFEDITMAXPIFL 1024L
  319. typedef struct tagPIFFILE
  320. {
  321. TCHAR Reserved1[2];
  322. TCHAR PTITLE[PTITLELEN];
  323. WORD MAXMEMWORD;
  324. WORD MINMEMWORD;
  325. TCHAR PPATHNAME[PPATHLEN];
  326. TCHAR MSFLAGS;
  327. TCHAR Reserved2;
  328. TCHAR INITIALDIR[PATHMAX];
  329. TCHAR INITIALCOM[COMMAX];
  330. TCHAR SCREENTYPE;
  331. TCHAR SCREENPAGES;
  332. TCHAR INTVECLOW;
  333. TCHAR INTVECHIGH;
  334. TCHAR ROWS;
  335. TCHAR COLUMNS;
  336. TCHAR ROWOFFS;
  337. TCHAR COLOFFS;
  338. WORD SYSTEMMEM;
  339. TCHAR SHAREDPROG[64];
  340. TCHAR SHAREDDATA[64];
  341. TCHAR BEHAVBYTE;
  342. TCHAR SYSTEMFLAGS;
  343. } PIFFILE ;
  344. void NEAR PASCAL GetTheString(LPTSTR pDst, LPTSTR pSrc, UINT iLen)
  345. {
  346. TCHAR cTemp;
  347. /* Ensure there is NULL termination, and then copy the description
  348. */
  349. cTemp = pSrc[iLen];
  350. pSrc[iLen] = TEXT('\0');
  351. lstrcpy(pDst, pSrc);
  352. pSrc[iLen] = cTemp;
  353. /* Strip off trailing spaces
  354. */
  355. for (pSrc=NULL; *pDst; pDst=CharNext(pDst))
  356. if (*pDst != TEXT(' '))
  357. pSrc = pDst;
  358. if (pSrc)
  359. *CharNext(pSrc) = TEXT('\0');
  360. }
  361. void NEAR PASCAL GetStuffFromPIF(LPTSTR szPath, LPTSTR szName, LPTSTR szDir)
  362. {
  363. TCHAR szTemp[MAXITEMPATHLEN+1];
  364. DWORD dummy;
  365. LPTSTR pszExt;
  366. LPTSTR pszFileName;
  367. PIFFILE pfTemp;
  368. HANDLE fh;
  369. DWORD dwBytesRead ;
  370. /* Do nothing if the user has filled in these fields
  371. */
  372. if (*szName && *szDir)
  373. return;
  374. /* Check for the ".pif" extension
  375. */
  376. lstrcpy(szTemp, szPath);
  377. StripArgs(szTemp);
  378. GetPathInfo(szTemp, &pszFileName, &pszExt, (WORD*) &dummy,
  379. (BOOL*) &dummy);
  380. if (!pszExt || lstrcmpi(pszExt, szDotPIF))
  381. return;
  382. /* There is no real way to verify the PIF format, like the COM format,
  383. * so we are assuming that the extension is our verification
  384. */
  385. fh = CreateFile(szTemp,
  386. GENERIC_READ,FILE_SHARE_READ, NULL,
  387. OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,0) ;
  388. if ( fh == INVALID_HANDLE_VALUE)
  389. return;
  390. ReadFile(fh,(LPTSTR)&pfTemp,sizeof(pfTemp),&dwBytesRead,NULL) ;
  391. if (dwBytesRead == sizeof(pfTemp)
  392. && SetFilePointer(fh, 0L, NULL, FILE_END) < PIFEDITMAXPIFL) {
  393. if (!*szName) {
  394. GetTheString(szName, pfTemp.PTITLE, CharSizeOf(pfTemp.PTITLE));
  395. DoEnvironmentSubst(szName, CharSizeOf(szNameField));
  396. }
  397. if (!*szDir) {
  398. GetTheString(szDir, pfTemp.INITIALDIR, CharSizeOf(pfTemp.INITIALDIR));
  399. }
  400. }
  401. CloseHandle(fh);
  402. }
  403. /*** GetDirectoryFromPath
  404. *
  405. *
  406. * VOID APIENTRY GetDirectoryFromPath (PSTR szFilePath, PSTR szDir)
  407. *
  408. * ENTRY - PSTR szFilePath - Full path to a file.
  409. * PSTR szDir - Directory returned in here, the buffer
  410. * is assumed to be as big as szFilePath.
  411. *
  412. * EXIT -
  413. *
  414. * SYNOPSIS - Given a full path, returns the directory of the file specified
  415. * by the path. If the path is UNC style or the path is just a
  416. * filename then the directory returned will be a NULL.
  417. *
  418. * WARNINGS -
  419. * EFFECTS -
  420. *
  421. * 08-08-91 JohanneC - ported from Windows 3.1
  422. *
  423. */
  424. VOID FAR PASCAL GetDirectoryFromPath(LPTSTR szFilePath, LPTSTR szDir)
  425. {
  426. LPTSTR pFileName;
  427. LPTSTR pExt;
  428. WORD ich;
  429. BOOL fUnc;
  430. *szDir = TEXT('\0');
  431. /* Get info about file path. */
  432. GetPathInfo(szFilePath, &pFileName, &pExt, &ich, &fUnc);
  433. /* UNC paths don't (conceptually to Progman) have a directory component. */
  434. if (fUnc)
  435. return;
  436. /* Does it have a directory component ? */
  437. if (pFileName != szFilePath) { // Yep.
  438. /* copy path to temp. */
  439. if (*szFilePath == TEXT('"')) {
  440. szFilePath++;
  441. }
  442. lstrcpy(szDir, szFilePath);
  443. /* check path style. */
  444. if (ich <= 3 && *(szDir+1) == TEXT(':')){
  445. /*
  446. * The path is "c:\foo.c" or "c:foo.c" style.
  447. * Don't remove the last slash/colon, just the filename.
  448. */
  449. szDir[pFileName-szFilePath] = TEXT('\0');
  450. }
  451. else if (ich == 1) {
  452. /*
  453. * something like "\foo.c"
  454. * Don't remove the last slash/colon, just the filename.
  455. */
  456. szDir[pFileName-szFilePath] = TEXT('\0');
  457. }
  458. else {
  459. /*
  460. * The filepath is a full normal path.
  461. * Could be something like "..\foo.c" or ".\foo.c" though.
  462. * Stomp on the last slash to get just the path.
  463. */
  464. szDir[pFileName-szFilePath-1] = TEXT('\0');
  465. }
  466. }
  467. /* else just a filename with no path. */
  468. }
  469. /*** GetFilenameFromPath
  470. *
  471. *
  472. * PSTR APIENTRY GetFilenameFromPath (PSTR szPath)
  473. *
  474. * ENTRY - PSTR szPath -
  475. *
  476. * EXIT - PSTR -
  477. *
  478. * SYNOPSIS - Given a full path returns a ptr to the filename bit.
  479. * Unless it's a UNC style path in which case it returns the path.
  480. *
  481. * WARNINGS -
  482. * EFFECTS -
  483. *
  484. * 08-08-91 JohanneC - ported from Windows 3.1
  485. *
  486. */
  487. VOID FAR PASCAL GetFilenameFromPath(LPTSTR szPath, LPTSTR szFilename)
  488. {
  489. DWORD dummy;
  490. LPTSTR pFileName;
  491. LPTSTR pExt;
  492. BOOL fUNC;
  493. GetPathInfo(szPath, &pFileName, &pExt, (WORD*) &dummy, &fUNC);
  494. /* If it's a UNC then the 'filename' part is the whole thing. */
  495. if (fUNC || (szPath == pFileName))
  496. lstrcpy(szFilename, szPath);
  497. else {
  498. if (*szPath == TEXT('"')) {
  499. *szFilename++ = TEXT('"');
  500. }
  501. lstrcpy(szFilename, pFileName);
  502. }
  503. }
  504. /*** HandleDosApps
  505. *
  506. *
  507. * void HandleDosApps (PSTR sz)
  508. *
  509. * ENTRY - PSTR sz - full path sans arguments
  510. *
  511. * EXIT -
  512. *
  513. * SYNOPSIS - Takes a full path to a file and checks if it's a dos app mentioned
  514. * in the pif.inf file.
  515. * If it isn't in the pif.inf file then the the routine returns without
  516. * doing anything.
  517. * If it is then it looks for a pif file with the same base name
  518. * in the same directory.
  519. * If there isn't one then it checks the windows directory.
  520. * If that fails it calls setup to create a new one giving the full
  521. * path to the app in question. - NOT supported in NTSetup.
  522. * The procedure doesn't alter the input string.
  523. *
  524. * WARNINGS -
  525. * EFFECTS -
  526. *
  527. * 08-08-91 JohanneC - ported from Windows 3.1
  528. *
  529. */
  530. void FAR PASCAL HandleDosApps(LPTSTR sz)
  531. {
  532. TCHAR szPath[MAXITEMPATHLEN+1]; // Copy of path so we can stomp all over
  533. // it.
  534. LPTSTR pszFileName; // The file filename part.
  535. LPTSTR pszExt; // The extension.
  536. WORD ich; // Index to filename.
  537. TCHAR szPifSection[32]; // Section in file to search,
  538. TCHAR szPifIniFile[16]; // Ini file to check.
  539. TCHAR szSystemDir[MAXITEMPATHLEN+1]; // Path to system dir.
  540. TCHAR szReturnString[2]; // Mini buffer to check return from GPPS.
  541. //OFSTRUCT of; // OF struct.
  542. TCHAR szExecSetup[MAXITEMPATHLEN+1]; // String used to WinExec setup to
  543. // create the pif for this app.
  544. BOOL dummy; // Dummy variable.
  545. DWORD dwResult ;
  546. TCHAR szPathFieldTemp[MAXITEMPATHLEN+1] ;
  547. LPTSTR FilePart ;
  548. /* Get system dir. */
  549. GetSystemDirectory(szSystemDir, CharSizeOf(szSystemDir));
  550. /* Load ini file info. */
  551. LoadString(hAppInstance, IDS_PIFINIFILE, szPifIniFile, CharSizeOf(szPifIniFile));
  552. LoadString(hAppInstance, IDS_PIFSECTION, szPifSection, CharSizeOf(szPifSection));
  553. LoadString(hAppInstance, IDS_EXECSETUP, szExecSetup, CharSizeOf(szExecSetup));
  554. /* Set up path to inf file. */
  555. if (lstrlen(szSystemDir) > 3) {
  556. lstrcat(szSystemDir, TEXT("\\"));
  557. }
  558. lstrcat(szSystemDir, szPifIniFile);
  559. /* Copy path */
  560. lstrcpy(szPath, sz);
  561. /* Get info about the path. */
  562. GetPathInfo(szPath, &pszFileName, &pszExt, &ich, &dummy);
  563. #ifdef DEBUG
  564. OutputDebugString(TEXT("\n\rLooking in apps.ini for "));
  565. OutputDebugString(pszFileName);
  566. OutputDebugString(TEXT("\n\r"));
  567. #endif
  568. /* Init the default to null. */
  569. szReturnString[0] = TEXT('\0');
  570. /*
  571. * Check in pif.ini file.
  572. * GPPS([section], keyname, szDef, szResultString, cbResString, FileName);
  573. */
  574. GetPrivateProfileString(szPifSection, pszFileName, szReturnString,
  575. szReturnString, CharSizeOf(szReturnString), szSystemDir);
  576. if (szReturnString[0] == TEXT('\0')) {
  577. /* It's not there. */
  578. #ifdef DEBUG
  579. OutputDebugString(TEXT("App not in inf file"));
  580. OutputDebugString(TEXT("\n\r"));
  581. #endif
  582. return;
  583. }
  584. #ifdef DEBUG
  585. OutputDebugString(TEXT("App in inf file"));
  586. OutputDebugString(TEXT("\n\r"));
  587. #endif
  588. /*
  589. * It's in the pif file, there should be a .pif for it somewhere.
  590. * Change extension to .pif
  591. */
  592. if (pszExt) {
  593. // copy .pif\0 over the existing extension.
  594. lstrcpy(pszExt, TEXT(".pif"));
  595. }
  596. else {
  597. // cat .pif\0 onto the end.
  598. lstrcat(szPath,TEXT(".pif"));
  599. }
  600. // Check given directory first.
  601. #ifdef DEBUG
  602. OutputDebugString(TEXT("Checking "));
  603. OutputDebugString(szPath);
  604. OutputDebugString(TEXT("\n\r"));
  605. #endif
  606. //SearchPath!!!
  607. dwResult = SearchPath(NULL,szPath,NULL,MAXITEMPATHLEN+1,
  608. szPathFieldTemp,&FilePart) ;
  609. if (dwResult == 0 && GetLastError() != 0x20) {
  610. //if (OpenFile(szPath, &of, OF_EXIST) == (HFILE)-1 && of.nErrCode != 0x20) {
  611. // It's not there.
  612. #ifdef DEBUG
  613. OutputDebugString(TEXT("Checking "));
  614. OutputDebugString(pszFileName);
  615. OutputDebugString(TEXT("\n\r"));
  616. #endif
  617. // Check path.
  618. dwResult = SearchPath(NULL,pszFileName,NULL,MAXITEMPATHLEN+1,
  619. szPathFieldTemp,&FilePart) ;
  620. if (dwResult == 0 && GetLastError() != 0x20) {
  621. //if (! (OpenFile(pszFileName, &of, OF_EXIST) == (HFILE)-1 && of.nErrCode !=0x20) ) {
  622. // Found it on path - winoldapp app will find it,
  623. #ifdef DEBUG
  624. OutputDebugString(TEXT("Found it on path. "));
  625. OutputDebugString(szPathFieldTemp);
  626. OutputDebugString(TEXT("\n\r"));
  627. #endif
  628. }
  629. else {
  630. #ifdef LATER
  631. //
  632. // NT Setup does not support this.
  633. // sunilp said so 9-9-92
  634. //
  635. // It's not anywhere so get setup to create it.
  636. lstrcat(szExecSetup, sz);
  637. // Exec setup - REVIEW silently ignore any errors from win exec.
  638. WinExec(szExecSetup, SW_SHOWNORMAL);
  639. #endif
  640. }
  641. }
  642. }
  643. /*** FixUpNulls -- replace "#" with NULL
  644. *
  645. *
  646. * VOID APIENTRY FixUpNulls(PSTR p)
  647. *
  648. * ENTRY - PSTR p - pointer to string to replaces chars
  649. *
  650. *
  651. * EXIT - VOID
  652. *
  653. * SYNOPSIS - seraches for any "#" chars, and replaces them with NULL
  654. *
  655. *
  656. * WARNINGS -
  657. * EFFECTS -
  658. *
  659. */
  660. void NEAR PASCAL FixupNulls(LPTSTR p)
  661. {
  662. while (*p) {
  663. if (*p == TEXT('#'))
  664. *p = TEXT('\0');
  665. p++;
  666. }
  667. }
  668. /*** GetFileNameFromBrowser --
  669. *
  670. *
  671. * BOOL APIENTRY GetFileNameFromBrowse(HWND, PSTR, WORD, PSTR, WORD, PSTR)
  672. *
  673. * ENTRY - HWND hwnd - Owner for browse dialog.
  674. * PSTR szFilePath - Path to file
  675. * WORD cbFilePath - Max length of file path buffer, in bytes.
  676. * PSTR szWorkingDir - Working directory
  677. * WORD wId - Id for filters string.
  678. * PSTR szDefExt - Default extension to use if the user doesn't
  679. * specify enter one.
  680. * EXIT - BOOL
  681. *
  682. * SYNOPSIS - Use the common browse dialog to get a filename. The working
  683. * directory of the common dialog will be set to the directory
  684. * part of the file path if it is more than just a filename.
  685. * If the filepath consists of just a filename then the working
  686. * directory will be used. The full path to the selected file will
  687. * be returned in szFilePath.
  688. *
  689. * WARNINGS -
  690. * EFFECTS -
  691. *
  692. */
  693. BOOL GetFileNameFromBrowse(
  694. HWND hwnd,
  695. LPTSTR szFilePath,
  696. WORD cbFilePath,
  697. LPTSTR szWorkingDir,
  698. WORD wId,
  699. LPTSTR szDefExt)
  700. {
  701. OPENFILENAME ofn; // Structure used to init dialog.
  702. TCHAR szFilters[200];// Filters string.
  703. TCHAR szTitle[80]; // Title for dialog.
  704. TCHAR szBrowserDir[MAXITEMPATHLEN+1]; // Directory to start browsing from.
  705. BOOL fBrowseOK; // Result from browser.
  706. szBrowserDir[0] = TEXT('\0'); // By default use CWD.
  707. // Try to set the directory in the user's home directory.
  708. SetCurrentDirectory(szOriginalDirectory);
  709. // Load filter for the browser.
  710. LoadString(hAppInstance, wId, szFilters, CharSizeOf(szFilters));
  711. // Convert the hashes in the filter into NULLs for the browser.
  712. FixupNulls(szFilters);
  713. // Load the title for the browser.
  714. LoadString(hAppInstance, IDS_BROWSE, szTitle, CharSizeOf(szTitle));
  715. // Set up info for browser. */
  716. GetDirectoryFromPath(szFilePath, szBrowserDir);
  717. if (*szBrowserDir == TEXT('\0') && szWorkingDir) {
  718. lstrcpy(szBrowserDir, szWorkingDir);
  719. }
  720. /*
  721. * Stomp on the file path so that the dialog doesn't
  722. * try to use it to initialise the dialog. The result is put
  723. * in here.
  724. */
  725. szFilePath[0] = TEXT('\0');
  726. /* Setup info for comm dialog. */
  727. ofn.lStructSize = sizeof(ofn);
  728. ofn.hwndOwner = hwnd;
  729. ofn.hInstance = NULL;
  730. ofn.lpstrFilter = szFilters;
  731. ofn.lpstrCustomFilter = NULL;
  732. ofn.nFilterIndex = 1;
  733. ofn.nMaxCustFilter = 0;
  734. ofn.lpstrFile = szFilePath;
  735. ofn.nMaxFile = cbFilePath/sizeof(TCHAR);
  736. ofn.lpstrInitialDir = szBrowserDir;
  737. ofn.lpstrTitle = szTitle;
  738. ofn.Flags = OFN_SHOWHELP | OFN_HIDEREADONLY | OFN_FILEMUSTEXIST |
  739. OFN_NOCHANGEDIR;
  740. ofn.lpfnHook = NULL;
  741. ofn.lpstrDefExt = szDefExt;
  742. ofn.lpstrFileTitle = NULL;
  743. /*
  744. * Get a filename from the dialog...
  745. * Load the commdlg dll.
  746. */
  747. if (!hCommdlg) {
  748. hCommdlg = LoadLibrary(szCommdlg);
  749. if (!hCommdlg) {
  750. /* Commdlg not available. */
  751. MyMessageBox(hwnd, IDS_APPTITLE, IDS_COMMDLGLOADERR, NULL, MB_OK | MB_ICONEXCLAMATION | MB_SYSTEMMODAL);
  752. hCommdlg = NULL;
  753. fBrowseOK = FALSE;
  754. goto ProcExit;
  755. }
  756. else {
  757. lpfnGOFN = (OPENFILENAME_PROC)GetProcAddress(hCommdlg, (LPSTR)szGetOpenFileName);
  758. if (!lpfnGOFN) {
  759. MyMessageBox(hwnd, IDS_APPTITLE, IDS_COMMDLGLOADERR, NULL, MB_OK | MB_ICONEXCLAMATION | MB_SYSTEMMODAL);
  760. hCommdlg = NULL;
  761. fBrowseOK = FALSE;
  762. goto ProcExit;
  763. }
  764. }
  765. }
  766. /*
  767. * Commdlg is loaded...
  768. * Call it.
  769. */
  770. fBrowseOK = (*lpfnGOFN)(&ofn);
  771. ProcExit:
  772. // restore the current dir
  773. SetCurrentDirectory(szWindowsDirectory);
  774. return fBrowseOK;
  775. }
  776. /*** PMHelp --
  777. *
  778. *
  779. * VOID APIENTRY PMHelp(HWND hwnd)
  780. *
  781. * ENTRY - HWND hwnd
  782. *
  783. *
  784. * EXIT - VOID
  785. *
  786. * SYNOPSIS -
  787. *
  788. *
  789. * WARNINGS -
  790. * EFFECTS -
  791. *
  792. */
  793. void FAR PASCAL PMHelp(HWND hwnd)
  794. {
  795. SetCurrentDirectory(szOriginalDirectory);
  796. if (!WinHelp(hwnd, szProgmanHelp, HELP_CONTEXT, dwContext)) {
  797. MyMessageBox(hwnd, IDS_APPTITLE, IDS_WINHELPERR, NULL, MB_OK | MB_ICONEXCLAMATION | MB_SYSTEMMODAL);
  798. }
  799. SetCurrentDirectory(szWindowsDirectory);
  800. }
  801. /*** MyDialogBox --
  802. *
  803. *
  804. * WORD APIENTRY MyDialogBox(WORD idd, HWND hwndParent, FARPROC lpfnDlgProc)
  805. *
  806. * ENTRY - WORD idd
  807. * HWND hwnd
  808. * FARPROC lpfnDlgProc
  809. *
  810. * EXIT - WORD xxx
  811. *
  812. * SYNOPSIS -
  813. *
  814. *
  815. * WARNINGS -
  816. * EFFECTS -
  817. *
  818. */
  819. WORD APIENTRY MyDialogBox(WORD idd, HWND hwndParent, DLGPROC lpfnDlgProc)
  820. {
  821. WORD wRet;
  822. DWORD dwSave = dwContext;
  823. dwContext = IDH_DLGFIRST + idd;
  824. wRet = (WORD)DialogBox(hAppInstance, (LPTSTR) MAKEINTRESOURCE(idd), hwndParent,
  825. lpfnDlgProc);
  826. dwContext = dwSave;
  827. return(wRet);
  828. }
  829. /*** ChooserDlgProc -- Dialog Procedure for chooser
  830. *
  831. *
  832. *
  833. * ChooserDlgProc(HWND hwnd, UINT uiMsg, DWORD wParam, LPARAM lParam)
  834. *
  835. * ENTRY - HWND hhwnd - handle to dialog box.
  836. * UINT uiMsg - message to be acted upon.
  837. * WPARAM wParam - value specific to uiMsg.
  838. * LPARAM lParam - value specific to uiMsg.
  839. *
  840. * EXIT - True if success, False if not.
  841. * SYNOPSIS - Dialog box message processing function.
  842. *
  843. * WARNINGS -
  844. * EFFECTS -
  845. *
  846. */
  847. INT_PTR APIENTRY ChooserDlgProc(HWND hwnd, UINT uiMsg, WPARAM wParam, LPARAM lParam)
  848. {
  849. register WORD wTempSelection;
  850. switch (uiMsg)
  851. {
  852. case WM_INITDIALOG:
  853. if (!AccessToCommonGroups) {
  854. EnableWindow(GetDlgItem(hwnd, IDD_COMMONGROUP), FALSE);
  855. }
  856. wNewSelection = SelectionType();
  857. if (wNewSelection == TYPE_ITEM)
  858. wTempSelection = IDD_ITEM;
  859. else {
  860. wTempSelection = IDD_PERSGROUP;
  861. wNewSelection = TYPE_PERSGROUP;
  862. }
  863. /* Grey out illegal items. */
  864. if (!pCurrentGroup || !GroupCheck(pCurrentGroup)) {
  865. /* Group is RO - can't create new items. */
  866. EnableWindow(GetDlgItem(hwnd,IDD_ITEM), FALSE);
  867. wTempSelection = IDD_PERSGROUP;
  868. wNewSelection = TYPE_PERSGROUP;
  869. }
  870. if (dwEditLevel == 1) {
  871. /* Not allowed to create new groups. */
  872. EnableWindow(GetDlgItem(hwnd,IDD_PERSGROUP), FALSE);
  873. wTempSelection = IDD_ITEM;
  874. wNewSelection = TYPE_ITEM;
  875. }
  876. CheckRadioButton(hwnd, IDD_ITEM, IDD_COMMONGROUP, wTempSelection);
  877. break;
  878. case WM_COMMAND:
  879. switch(GET_WM_COMMAND_ID(wParam, lParam))
  880. {
  881. case IDD_HELP:
  882. goto DoHelp;
  883. case IDD_ITEM:
  884. if (IsWindowEnabled(GetDlgItem(hwnd,IDD_ITEM)))
  885. wNewSelection = TYPE_ITEM;
  886. break;
  887. case IDD_PERSGROUP:
  888. if (IsWindowEnabled(GetDlgItem(hwnd,IDD_PERSGROUP)))
  889. wNewSelection = TYPE_PERSGROUP;
  890. break;
  891. case IDD_COMMONGROUP:
  892. if (IsWindowEnabled(GetDlgItem(hwnd,IDD_COMMONGROUP)))
  893. wNewSelection = TYPE_COMMONGROUP;
  894. break;
  895. case IDOK:
  896. EndDialog(hwnd, TRUE);
  897. break;
  898. case IDCANCEL:
  899. EndDialog(hwnd, FALSE);
  900. break;
  901. default:
  902. return(FALSE);
  903. }
  904. break;
  905. default:
  906. if (uiMsg == uiHelpMessage) {
  907. DoHelp:
  908. PMHelp(hwnd);
  909. return TRUE;
  910. } else
  911. return FALSE;
  912. }
  913. UNREFERENCED_PARAMETER(lParam);
  914. return(TRUE);
  915. }
  916. /*** MoveItemDlgProc -- Dialog Procedure
  917. *
  918. *
  919. *
  920. * INT_PTR APIENTRY MoveItemDlgProc(HWND hwnd, UINT uiMsg, DWORD wParam, LONG lParam)
  921. *
  922. * ENTRY - HWND hwnd - handle to dialog box.
  923. * UINT uiMsg - message to be acted upon.
  924. * WPARAM wParam - value specific to uiMsg.
  925. * LPARAM lParam - value specific to uiMsg.
  926. *
  927. * EXIT - True if success, False if not.
  928. * SYNOPSIS - Dialog box message processing function.
  929. *
  930. * WARNINGS -
  931. * EFFECTS -
  932. *
  933. */
  934. INT_PTR APIENTRY MoveItemDlgProc(HWND hwnd, UINT uiMsg, WPARAM wParam, LPARAM lParam)
  935. {
  936. int iSel;
  937. HWND hwndCB;
  938. register PGROUP pGroup;
  939. hwndCB = GetDlgItem(hwnd, IDD_GROUPS);
  940. switch (uiMsg) {
  941. case WM_INITDIALOG:
  942. {
  943. LPITEMDEF lpid;
  944. LPGROUPDEF lpgd;
  945. int i=0;
  946. lpgd = LockGroup(pCurrentGroup->hwnd);
  947. if (lpgd == 0L)
  948. goto MoveDlgExit;
  949. lpid = ITEM(lpgd,pCurrentGroup->pItems->iItem);
  950. SetDlgItemText(hwnd, IDD_ITEM, (LPTSTR) PTR(lpgd, lpid->pName));
  951. SetDlgItemText(hwnd, IDD_GROUP, (LPTSTR) PTR(lpgd, lpgd->pName));
  952. UnlockGroup(pCurrentGroup->hwnd);
  953. pGroup = pFirstGroup;
  954. while (pGroup) {
  955. if (IsGroupReadOnly(pGroup->lpKey, pGroup->fCommon))
  956. pGroup->fRO = TRUE;
  957. else
  958. pGroup->fRO = FALSE;
  959. if (!pGroup->fRO) {
  960. if (pGroup != pCurrentGroup) {
  961. GetWindowText(pGroup->hwnd, (LPTSTR)szMessage, MAXGROUPNAMELEN + 1);
  962. iSel = (int)SendMessage(hwndCB, CB_ADDSTRING, 0, (LPARAM)(LPTSTR)szMessage);
  963. SendMessage(hwndCB, CB_SETITEMDATA, iSel, (LPARAM)(LPTSTR)pGroup);
  964. i++;
  965. }
  966. }
  967. pGroup = pGroup->pNext;
  968. }
  969. SendMessage(hwndCB, CB_SETCURSEL, 0, 0L);
  970. if (i==0) {
  971. /* No items in list box - Kill the OK button. */
  972. EnableWindow(GetDlgItem(hwnd, IDOK), FALSE);
  973. }
  974. break;
  975. }
  976. case WM_COMMAND:
  977. switch(GET_WM_COMMAND_ID(wParam, lParam)) {
  978. case IDD_HELP:
  979. goto DoHelp;
  980. case IDOK:
  981. {
  982. int nIndex;
  983. PGROUP pGTemp;
  984. /* Get the pointer to the selected group. */
  985. nIndex = (int)SendMessage(hwndCB, CB_GETCURSEL, 0, 0L);
  986. pGroup = (PGROUP)SendMessage(hwndCB, CB_GETITEMDATA, nIndex, 0L);
  987. /* Check pointer. */
  988. if (!pGroup)
  989. goto ExitCase;
  990. pGTemp = pCurrentGroup;
  991. /*
  992. * Only do this operation if the user actually had a
  993. * group selected. CB_GETITEMDATA will return -1 if
  994. * an item wasn't selected. This happens if the user
  995. * tries to do a move when there's only one group around.
  996. */
  997. if (pGroup != (PGROUP)(-1)) {
  998. if (DuplicateItem(pGTemp,pGTemp->pItems,pGroup,NULL)) {
  999. // OK to delete the original.
  1000. DeleteItem(pGTemp,pGTemp->pItems);
  1001. // It's messy to change the focus when using the keyboard.
  1002. // SendMessage(hwndMDIClient, WM_MDIACTIVATE, (WPARAM)(pGroup->hwnd), 0L);
  1003. CalcGroupScrolls(pGroup->hwnd);
  1004. }
  1005. }
  1006. ExitCase:
  1007. EndDialog(hwnd, TRUE);
  1008. break;
  1009. }
  1010. case IDCANCEL:
  1011. MoveDlgExit:
  1012. EndDialog(hwnd, FALSE);
  1013. break;
  1014. default:
  1015. return(FALSE);
  1016. }
  1017. break;
  1018. default:
  1019. if (uiMsg == uiHelpMessage)
  1020. DoHelp:
  1021. {
  1022. DWORD dwSave = dwContext;
  1023. dwContext = IDH_MOVEDLG;
  1024. PMHelp(hwnd);
  1025. dwContext = dwSave;
  1026. return TRUE;
  1027. } else
  1028. return FALSE;
  1029. }
  1030. UNREFERENCED_PARAMETER(lParam);
  1031. return(TRUE);
  1032. }
  1033. /*** CopyItemDlgProc -- Dialog Procedure
  1034. *
  1035. *
  1036. *
  1037. * INT_PTR APIENTRY CopyItemDlgProc(HWND hwnd, UINT uiMsg, WPARAM wParam, LPARAM lParam)
  1038. *
  1039. * ENTRY - HWND hhwnd - handle to dialog box.
  1040. * UINT uiMsg - message to be acted upon.
  1041. * WPARAM wParam - value specific to uiMsg.
  1042. * LPARAM lParam - value specific to uiMsg.
  1043. *
  1044. * EXIT - True if success, False if not.
  1045. * SYNOPSIS - Dialog box message processing function.
  1046. *
  1047. * WARNINGS -
  1048. * EFFECTS -
  1049. *
  1050. */
  1051. INT_PTR APIENTRY CopyItemDlgProc(HWND hwnd, UINT uiMsg, WPARAM wParam, LPARAM lParam)
  1052. {
  1053. int iSel;
  1054. HWND hwndCB;
  1055. register PGROUP pGroup;
  1056. LPITEMDEF lpid;
  1057. LPGROUPDEF lpgd;
  1058. hwndCB = GetDlgItem(hwnd, IDD_GROUPS);
  1059. switch (uiMsg) {
  1060. case WM_INITDIALOG:
  1061. {
  1062. int i=0;
  1063. LoadString(hAppInstance, IDS_COPYDLGTITLE, (LPTSTR)szTitle, MAXTITLELEN);
  1064. SetWindowText(hwnd, szTitle);
  1065. LoadString(hAppInstance, IDS_COPYDLGTITLE1, (LPTSTR)szTitle, MAXTITLELEN);
  1066. SetDlgItemText(hwnd, IDD_MOVETITLE1, szTitle);
  1067. lpgd = LockGroup(pCurrentGroup->hwnd);
  1068. if (lpgd == 0L)
  1069. goto CopyDlgExit;
  1070. lpid = ITEM(lpgd,pCurrentGroup->pItems->iItem);
  1071. SetDlgItemText(hwnd, IDD_ITEM, (LPTSTR) PTR(lpgd, lpid->pName));
  1072. SetDlgItemText(hwnd, IDD_GROUP, (LPTSTR) PTR(lpgd, lpgd->pName));
  1073. UnlockGroup(pCurrentGroup->hwnd);
  1074. pGroup = pFirstGroup;
  1075. while (pGroup) {
  1076. if (IsGroupReadOnly(pGroup->lpKey, pGroup->fCommon))
  1077. pGroup->fRO = TRUE;
  1078. else
  1079. pGroup->fRO = FALSE;
  1080. if (!pGroup->fRO) {
  1081. GetWindowText(pGroup->hwnd, (LPTSTR)szMessage, MAXGROUPNAMELEN + 1);
  1082. iSel = (int)SendMessage(hwndCB, CB_ADDSTRING, 0, (LPARAM)(LPTSTR)szMessage);
  1083. SendMessage(hwndCB, CB_SETITEMDATA, iSel, (LPARAM)(LPTSTR)pGroup);
  1084. i++;
  1085. }
  1086. pGroup = pGroup->pNext;
  1087. }
  1088. SendMessage(hwndCB, CB_SETCURSEL, 0, 0L);
  1089. if (i==0) {
  1090. // No items in list box - Kill the OK button.
  1091. EnableWindow(GetDlgItem(hwnd, IDOK), FALSE);
  1092. }
  1093. break;
  1094. }
  1095. case WM_COMMAND:
  1096. switch(GET_WM_COMMAND_ID(wParam, lParam)) {
  1097. case IDD_HELP:
  1098. goto DoHelp;
  1099. case IDOK:
  1100. {
  1101. int nIndex;
  1102. /* Get the pointer to the selected group. */
  1103. nIndex = (int)SendMessage(hwndCB, CB_GETCURSEL, 0, 0L);
  1104. pGroup = (PGROUP)SendMessage(hwndCB, CB_GETITEMDATA, nIndex, 0L);
  1105. /* Check pointer. */
  1106. if (!pGroup)
  1107. goto ExitCase;
  1108. DuplicateItem(pCurrentGroup,pCurrentGroup->pItems,
  1109. pGroup,NULL);
  1110. // Don't change focus to destination on a copy, very messy if you have a
  1111. // group maximised and you want to copy a whole bunch of stuff to another
  1112. // group using the keyboard.
  1113. // SendMessage(hwndMDIClient, WM_MDIACTIVATE, (WPARAM)(pGroup->hwnd), 0L);
  1114. /* Redo scroll bars for destination. */
  1115. CalcGroupScrolls(pGroup->hwnd);
  1116. /* Redo scroll bars for source. */
  1117. CalcGroupScrolls(pCurrentGroup->hwnd);
  1118. ExitCase:
  1119. EndDialog(hwnd, TRUE);
  1120. break;
  1121. }
  1122. case IDCANCEL:
  1123. CopyDlgExit:
  1124. EndDialog(hwnd, FALSE);
  1125. break;
  1126. default:
  1127. return(FALSE);
  1128. }
  1129. break;
  1130. default:
  1131. if (uiMsg == uiHelpMessage)
  1132. DoHelp:
  1133. {
  1134. DWORD dwSave = dwContext;
  1135. dwContext = IDH_COPYDLG;
  1136. PMHelp(hwnd);
  1137. dwContext = dwSave;
  1138. return TRUE;
  1139. } else
  1140. return FALSE;
  1141. }
  1142. UNREFERENCED_PARAMETER(lParam);
  1143. return(TRUE);
  1144. }
  1145. /*** SaveRecentFileList -- Save the list of recently used files
  1146. *
  1147. * void APIENTRY SaveRecentFileList (HWND hwnd, LPTSTR szCurrentFile);
  1148. *
  1149. *
  1150. *
  1151. * ENTRY - HWND hwnd - handle to dialog box.
  1152. * LPTSTR szCurrentFile - pointer to selected filename
  1153. * WORD idControl - control id
  1154. *
  1155. * EXIT -
  1156. * SYNOPSIS -
  1157. *
  1158. * WARNINGS -
  1159. * EFFECTS -
  1160. *
  1161. */
  1162. void APIENTRY SaveRecentFileList (HWND hwnd, LPTSTR szCurrentFile, WORD idControl)
  1163. {
  1164. HKEY hKey;
  1165. DWORD dwDisp;
  1166. DWORD dwDataType, dwMaxFiles=INIT_MAX_FILES, dwMaxFilesSize, dwCount;
  1167. TCHAR szFileEntry[20];
  1168. DWORD dwEnd=0;
  1169. DWORD dwFileNum=0;
  1170. DWORD dwDup;
  1171. static TCHAR szRecentFilePath[MAXITEMPATHLEN+1];
  1172. //
  1173. // Open registry key
  1174. //
  1175. if ( RegCreateKeyEx (HKEY_CURRENT_USER, FILES_KEY, 0, 0,
  1176. REG_OPTION_NON_VOLATILE, KEY_READ | KEY_WRITE,
  1177. NULL, &hKey, &dwDisp) != ERROR_SUCCESS) {
  1178. return;
  1179. }
  1180. //
  1181. // Query the max number of files to save first.
  1182. //
  1183. dwMaxFilesSize = sizeof (DWORD);
  1184. RegQueryValueEx (hKey, MAXFILES_ENTRY, NULL, &dwDataType,
  1185. (LPBYTE)&dwMaxFiles, &dwMaxFilesSize);
  1186. //
  1187. // If the user request 0 entries, then exit now.
  1188. //
  1189. if (dwMaxFiles == 0) {
  1190. RegCloseKey (hKey);
  1191. return;
  1192. }
  1193. //
  1194. // Find out how many items are in the list box.
  1195. //
  1196. dwEnd = (DWORD)SendDlgItemMessage (hwnd, idControl, CB_GETCOUNT, 0, 0);
  1197. //
  1198. // If the max number of items we want to save is less than the
  1199. // number of entries, then change the ending point.
  1200. //
  1201. if (dwMaxFiles < dwEnd) {
  1202. dwEnd = dwMaxFiles;
  1203. }
  1204. //
  1205. // Add the first entry (the current file)
  1206. //
  1207. wsprintf (szFileEntry, FILE_ENTRY, dwFileNum++);
  1208. dwMaxFilesSize = MAXITEMPATHLEN+1;
  1209. RegSetValueEx (hKey, szFileEntry, 0, REG_SZ, (CONST BYTE *)szCurrentFile,
  1210. sizeof (TCHAR) * (lstrlen (szCurrentFile)+1));
  1211. //
  1212. // Check for a duplicate string.
  1213. //
  1214. dwDup = (DWORD)SendDlgItemMessage (hwnd, idControl, CB_FINDSTRING,
  1215. (WPARAM) -1, (LPARAM) szCurrentFile);
  1216. //
  1217. // If we already have dwMaxFiles in the list and we don't have any
  1218. // duplicates, then we only want to save dwMaxFiles - 1 entries
  1219. // (drop the last entry).
  1220. //
  1221. //
  1222. if ( (dwEnd == dwMaxFiles) && (dwDup == CB_ERR) ) {
  1223. dwEnd--;
  1224. }
  1225. //
  1226. // Now loop through the remaining entries
  1227. //
  1228. for (dwCount=0; dwCount < dwEnd; dwCount++) {
  1229. //
  1230. // Check to see if we are at the duplicate entry. If
  1231. // so skip on to the next item.
  1232. //
  1233. if ((dwDup != CB_ERR) && (dwCount == dwDup)) {
  1234. continue;
  1235. }
  1236. //
  1237. // Get an entry out of the listbox.
  1238. //
  1239. SendDlgItemMessage (hwnd, idControl, CB_GETLBTEXT, (WPARAM) dwCount,
  1240. (LPARAM) szRecentFilePath);
  1241. //
  1242. // If we get a NULL string, break out of the loop.
  1243. //
  1244. if (!(*szRecentFilePath) || !szRecentFilePath) {
  1245. break;
  1246. }
  1247. //
  1248. // Build the entry name
  1249. //
  1250. wsprintf (szFileEntry, FILE_ENTRY, dwFileNum);
  1251. dwMaxFilesSize = MAXITEMPATHLEN+1;
  1252. //
  1253. // Save the entry
  1254. //
  1255. RegSetValueEx (hKey, szFileEntry, 0, REG_SZ,(CONST BYTE *) szRecentFilePath,
  1256. sizeof (TCHAR) * (lstrlen (szRecentFilePath)+1));
  1257. //
  1258. // Increment our current file number
  1259. //
  1260. dwFileNum++;
  1261. }
  1262. //
  1263. // Close the key
  1264. //
  1265. RegCloseKey (hKey);
  1266. }
  1267. /*** RunDlgProc -- Dialog Procedure
  1268. *
  1269. *
  1270. *
  1271. * INT_PTR APIENTRY RunDlgProc(HWND hwnd, UINT uiMsg, WPARAM wParam, LPARAM lParam)
  1272. *
  1273. * ENTRY - HWND hhwnd - handle to dialog box.
  1274. * UINT uiMsg - message to be acted upon.
  1275. * WPARAM wParam - value specific to uiMsg.
  1276. * LPARAM lParam - value specific to uiMsg.
  1277. *
  1278. * EXIT - True if success, False if not.
  1279. * SYNOPSIS - Dialog box message processing function.
  1280. *
  1281. * WARNINGS -
  1282. * EFFECTS -
  1283. *
  1284. */
  1285. INT_PTR APIENTRY RunDlgProc(HWND hwnd, UINT uiMsg, WPARAM wParam, LPARAM lParam)
  1286. {
  1287. WORD ret;
  1288. TCHAR szFullPath[MAXITEMPATHLEN+1];
  1289. HKEY hKey;
  1290. DWORD dwDisp;
  1291. DWORD dwDataType, dwMaxFiles=INIT_MAX_FILES, dwMaxFilesSize, dwCount;
  1292. TCHAR szFileEntry[20];
  1293. DWORD dwThreadID;
  1294. HANDLE hThread;
  1295. DWORD dwBinaryInfo, cbData;
  1296. BOOL bDoit;
  1297. switch (uiMsg) {
  1298. case WM_INITDIALOG:
  1299. SendDlgItemMessage(hwnd, IDD_PATH, EM_LIMITTEXT, CharSizeOf(szPathField)-1, 0L);
  1300. szPathField[0] =TEXT('\0'); // initialize the path to null
  1301. SetDlgItemText(hwnd, IDD_PATH, szPathField);
  1302. CheckDlgButton(hwnd, IDD_NEWVDM, 1);
  1303. EnableWindow(GetDlgItem(hwnd,IDD_NEWVDM), FALSE);
  1304. EnableWindow(GetDlgItem(hwnd, IDOK), FALSE);
  1305. //
  1306. // Load the combobox with recently used files from the registry.
  1307. //
  1308. // Query the max number of files first.
  1309. //
  1310. if (RegCreateKeyEx (HKEY_CURRENT_USER, FILES_KEY, 0, 0,
  1311. REG_OPTION_NON_VOLATILE, KEY_READ | KEY_WRITE,
  1312. NULL, &hKey, &dwDisp) == ERROR_SUCCESS) {
  1313. if (dwDisp == REG_OPENED_EXISTING_KEY) {
  1314. //
  1315. // Query the max number of entries
  1316. //
  1317. dwMaxFilesSize = sizeof (DWORD);
  1318. if (RegQueryValueEx (hKey, MAXFILES_ENTRY, NULL, &dwDataType,
  1319. (LPBYTE)&dwMaxFiles, &dwMaxFilesSize) == ERROR_SUCCESS) {
  1320. //
  1321. // Now Query each entry and add it to the list box.
  1322. //
  1323. for (dwCount=0; dwCount < dwMaxFiles; dwCount++) {
  1324. wsprintf (szFileEntry, FILE_ENTRY, dwCount);
  1325. dwMaxFilesSize = MAXITEMPATHLEN+1;
  1326. if (RegQueryValueEx (hKey, szFileEntry, NULL, &dwDataType,
  1327. (LPBYTE) szFullPath, &dwMaxFilesSize) == ERROR_SUCCESS) {
  1328. //
  1329. // Found an entry. Add it to the combo box.
  1330. //
  1331. SendDlgItemMessage (hwnd, IDD_PATH,
  1332. CB_ADDSTRING, 0,
  1333. (LPARAM)szFullPath);
  1334. } else {
  1335. break;
  1336. }
  1337. }
  1338. }
  1339. } else {
  1340. //
  1341. // We are working with a new key, so we need to
  1342. // set the default number of files.
  1343. //
  1344. RegSetValueEx (hKey, MAXFILES_ENTRY, 0, REG_DWORD,
  1345. (CONST BYTE *) &dwMaxFiles, sizeof (DWORD));
  1346. }
  1347. //
  1348. // Close the registry key
  1349. //
  1350. RegCloseKey (hKey);
  1351. }
  1352. //
  1353. // Set the inital state for the thread which checks the binary
  1354. // type.
  1355. //
  1356. //
  1357. // Query if the binary type checking is enabled.
  1358. //
  1359. cbData = sizeof(dwBinaryInfo);
  1360. if (RegQueryValueEx(hkeyPMSettings, szCheckBinaryType, 0, &dwDataType,
  1361. (LPBYTE)&dwBinaryInfo, &cbData) == ERROR_SUCCESS) {
  1362. bCheckBinaryType = (BOOL) dwBinaryInfo;
  1363. } else {
  1364. bCheckBinaryType = BINARY_TYPE_DEFAULT;
  1365. }
  1366. //
  1367. // Query the binary type checking timeout value.
  1368. //
  1369. cbData = sizeof(dwBinaryInfo);
  1370. if (RegQueryValueEx(hkeyPMSettings, szCheckBinaryTimeout, 0, &dwDataType,
  1371. (LPBYTE)&dwBinaryInfo, &cbData) == ERROR_SUCCESS) {
  1372. uiCheckBinaryTimeout = (UINT) dwBinaryInfo;
  1373. } else {
  1374. uiCheckBinaryTimeout = BINARY_TIMEOUT_DEFAULT;
  1375. }
  1376. //
  1377. // Create the worker thread, and the signal event. If appropriate.
  1378. //
  1379. if (bCheckBinaryType) {
  1380. hCheckBinaryEvent = CreateEvent (NULL, FALSE, FALSE,
  1381. CHECK_BINARY_EVENT_NAME);
  1382. hThread = CreateThread (NULL, 0,
  1383. (LPTHREAD_START_ROUTINE) CheckBinaryThread,
  1384. (LPVOID) hwnd, 0, &dwThreadID);
  1385. bCheckBinaryDirtyFlag = FALSE;
  1386. }
  1387. if (!hCheckBinaryEvent || !hThread || !bCheckBinaryType) {
  1388. //
  1389. // If this statement is true, either we failed to create
  1390. // the event, the thread, or binary type checking is disabled.
  1391. // In this case, enable the separate memory checkbox, and let
  1392. // the user decide on his own.
  1393. //
  1394. CheckDlgButton(hwnd, IDD_NEWVDM, 0);
  1395. EnableWindow(GetDlgItem(hwnd,IDD_NEWVDM), TRUE);
  1396. //
  1397. // Clean up either item that succeeded
  1398. //
  1399. if (hCheckBinaryEvent) {
  1400. CloseHandle (hCheckBinaryEvent);
  1401. }
  1402. if (hThread) {
  1403. TerminateThread (hThread, 0);
  1404. }
  1405. //
  1406. // Setting this variable to NULL will prevent the second
  1407. // thread from trying to check the binary type.
  1408. //
  1409. hCheckBinaryEvent = NULL;
  1410. }
  1411. break;
  1412. case WM_TIMER:
  1413. if (hCheckBinaryEvent && bCheckBinaryDirtyFlag) {
  1414. bCheckBinaryDirtyFlag = FALSE;
  1415. SetEvent (hCheckBinaryEvent);
  1416. }
  1417. break;
  1418. case MYCBN_SELCHANGE:
  1419. if (bCheckBinaryType) {
  1420. bCheckBinaryDirtyFlag = TRUE;
  1421. SetTimer (hwnd, CHECK_BINARY_ID, uiCheckBinaryTimeout, NULL);
  1422. }
  1423. bDoit = (GetDlgItemText(hwnd, IDD_COMMAND, szPathField, MAXITEMPATHLEN+1) > 0);
  1424. EnableWindow(GetDlgItem(hwnd, IDOK), bDoit);
  1425. break;
  1426. case WM_COMMAND:
  1427. switch (GET_WM_COMMAND_ID(wParam, lParam)) {
  1428. case IDD_HELP:
  1429. goto DoHelp;
  1430. case IDD_PATH:
  1431. if ((GET_WM_COMMAND_CMD(wParam, lParam) != CBN_EDITCHANGE) &&
  1432. (GET_WM_COMMAND_CMD(wParam, lParam) != CBN_SELCHANGE) )
  1433. break;
  1434. PostMessage (hwnd, MYCBN_SELCHANGE, wParam, lParam);
  1435. break;
  1436. case IDOK:
  1437. {
  1438. TCHAR szFilename[MAXITEMPATHLEN+3]; // added chars for ".\"
  1439. BOOL bNewVDM;
  1440. //
  1441. // Run this app in the user's home directory
  1442. //
  1443. SetCurrentDirectory(szOriginalDirectory);
  1444. GetDlgItemText(hwnd, IDD_PATH, szPathField, CharSizeOf(szPathField));
  1445. //#ifdef JAPAN
  1446. // if (CheckPortName(hwnd,szPathField))
  1447. // break;
  1448. //#endif
  1449. DoEnvironmentSubst(szPathField, CharSizeOf(szPathField));
  1450. GetDirectoryFromPath(szPathField, szDirField);
  1451. if (*szDirField) {
  1452. // Convert path into a .\foo.exe style thing.
  1453. lstrcpy(szFilename, TEXT(".\\"));
  1454. // Tag the filename and params on to the end of the dot slash.
  1455. GetFilenameFromPath(szPathField, szFilename+2);
  1456. if (*(szFilename+2) == TEXT('"') ) {
  1457. SheRemoveQuotes(szFilename+2);
  1458. CheckEscapes(szFilename, CharSizeOf(szFilename));
  1459. }
  1460. }
  1461. else {
  1462. GetFilenameFromPath(szPathField, szFilename);
  1463. }
  1464. bNewVDM = ( IsWindowEnabled(GetDlgItem(hwnd,IDD_NEWVDM)) &&
  1465. IsDlgButtonChecked(hwnd, IDD_NEWVDM) );
  1466. ret = ExecProgram(szFilename, szDirField, szFilename,
  1467. IsDlgButtonChecked(hwnd, IDD_LOAD),
  1468. 0, 0, bNewVDM);
  1469. //
  1470. // reset Progman's working directory.
  1471. //
  1472. SetCurrentDirectory(szWindowsDirectory);
  1473. if (ret) {
  1474. MyMessageBox(hwnd, IDS_EXECERRTITLE, ret, szPathField, MB_OK | MB_ICONEXCLAMATION | MB_SYSTEMMODAL);
  1475. } else {
  1476. GetDlgItemText(hwnd, IDD_PATH, szPathField, CharSizeOf(szPathField));
  1477. SaveRecentFileList (hwnd, szPathField, IDD_PATH);
  1478. if (bCheckBinaryType) {
  1479. //
  1480. // Setting this variable to false, and signaling the event
  1481. // will cause the binary checking thread to terminate.
  1482. //
  1483. bCheckBinaryType = FALSE;
  1484. SetEvent (hCheckBinaryEvent);
  1485. KillTimer (hwnd, CHECK_BINARY_ID);
  1486. }
  1487. EndDialog(hwnd, TRUE);
  1488. }
  1489. break;
  1490. }
  1491. case IDD_BROWSE:
  1492. {
  1493. DWORD dwSave = dwContext;
  1494. TCHAR szPathField[MAXITEMPATHLEN+1];
  1495. dwContext = IDH_RUNBROWSEDLG;
  1496. GetDlgItemText(hwnd,IDD_PATH,szPathField,MAXITEMPATHLEN+1);
  1497. wParam = GetFileNameFromBrowse(hwnd, szPathField, sizeof(szPathField),
  1498. NULL, IDS_PROPERTIESPROGS, TEXT("exe"));
  1499. dwContext = dwSave;
  1500. if (wParam) {
  1501. //
  1502. // if filename or directory have spaces, put the path
  1503. // between quotes.
  1504. //
  1505. CheckEscapes(szPathField, MAXITEMPATHLEN+1);
  1506. SetDlgItemText(hwnd, IDD_PATH, szPathField);
  1507. PostMessage (hwnd, MYCBN_SELCHANGE, wParam, lParam);
  1508. // Set default button to OK.
  1509. PostMessage(hwnd, WM_NEXTDLGCTL, (WPARAM)GetDlgItem(hwnd, IDOK), TRUE);
  1510. }
  1511. break;
  1512. }
  1513. case IDCANCEL:
  1514. if (bCheckBinaryType) {
  1515. //
  1516. // Setting this variable to false, and signaling the event
  1517. // will cause the binary checking thread to terminate.
  1518. //
  1519. bCheckBinaryType = FALSE;
  1520. SetEvent (hCheckBinaryEvent);
  1521. KillTimer (hwnd, CHECK_BINARY_ID);
  1522. }
  1523. EndDialog(hwnd, FALSE);
  1524. break;
  1525. default:
  1526. return(FALSE);
  1527. }
  1528. break;
  1529. default:
  1530. if (uiMsg == uiHelpMessage || uiMsg == uiBrowseMessage)
  1531. DoHelp:
  1532. {
  1533. PMHelp(hwnd);
  1534. return TRUE;
  1535. } else
  1536. return FALSE;
  1537. }
  1538. UNREFERENCED_PARAMETER(lParam);
  1539. return(TRUE);
  1540. }
  1541. /*** CheckBinaryThread --
  1542. *
  1543. *
  1544. *
  1545. * void CheckBinaryThread (HWND, INT)
  1546. *
  1547. * ENTRY - HWND hDlg - handle to dialog box.
  1548. * INT idCheckBox - Checkbox control id
  1549. *
  1550. * EXIT - void
  1551. *
  1552. * 05-18-94 Eric Flo - created
  1553. *
  1554. */
  1555. void CheckBinaryThread (LPVOID hwndDlg)
  1556. {
  1557. HWND hwnd = (HWND) hwndDlg;
  1558. TCHAR szFullPath[MAXITEMPATHLEN+1];
  1559. LPTSTR FilePart ;
  1560. DWORD dwBinaryType;
  1561. while (bCheckBinaryType) {
  1562. WaitForSingleObject (hCheckBinaryEvent, INFINITE);
  1563. if (bCheckBinaryType) {
  1564. DoEnvironmentSubst(szPathField, CharSizeOf(szPathField));
  1565. StripArgs(szPathField);
  1566. TagExtension(szPathField, sizeof(szPathField));
  1567. SheRemoveQuotes(szPathField);
  1568. if (SearchPath(NULL, szPathField, NULL, MAXITEMPATHLEN+1,
  1569. szFullPath, &FilePart) &&
  1570. GetBinaryType(szFullPath, &dwBinaryType) &&
  1571. dwBinaryType == SCS_WOW_BINARY) {
  1572. CheckDlgButton(hwnd, IDD_NEWVDM, 0);
  1573. EnableWindow(GetDlgItem(hwnd,IDD_NEWVDM), TRUE);
  1574. } else {
  1575. CheckDlgButton(hwnd, IDD_NEWVDM, 1);
  1576. EnableWindow(GetDlgItem(hwnd,IDD_NEWVDM), FALSE);
  1577. }
  1578. }
  1579. }
  1580. //
  1581. // Close our event handle and exit the thread.
  1582. //
  1583. CloseHandle (hCheckBinaryEvent);
  1584. ExitThread (0);
  1585. }
  1586. /*** ValidatePath --
  1587. *
  1588. *
  1589. *
  1590. * DWORD APIENTRY ValidatePath(HWND, PSTR, PSTR, PSTR)
  1591. *
  1592. * ENTRY - HWND hDlg - handle to dialog box.
  1593. * PSTR szPath - path to item.
  1594. * PSTR szDir - path to working directory.
  1595. * PSTR szExePath - path to associated exe.
  1596. *
  1597. * EXIT - DWORD - returns PATH_VALID is path is valid.
  1598. * if path is not valid returns PATH_INVALID_OK
  1599. * if user hits OK to invalid message box,
  1600. * otherwise returns PATH_VALID
  1601. *
  1602. * SYNOPSIS -
  1603. *
  1604. * WARNINGS -
  1605. * EFFECTS -
  1606. *
  1607. * 08-08-91 JohanneC - updated to Windows 3.1
  1608. *
  1609. */
  1610. DWORD APIENTRY ValidatePath(HWND hDlg, LPTSTR szPath, LPTSTR szDir, LPTSTR szExePath)
  1611. {
  1612. int cDrive;
  1613. TCHAR szTemp[MAXITEMPATHLEN+1];
  1614. int err;
  1615. BOOL bOriginalDirectory; // using original directory
  1616. DWORD dwRet = PATH_VALID;
  1617. BOOL fOK = TRUE; // If the path or the dir check fail
  1618. // then don't bother with the assoc check.
  1619. /* Check working directory. */
  1620. GetCurrentDirectory(MAXITEMPATHLEN, szTemp);
  1621. SetCurrentDirectory(szOriginalDirectory);
  1622. //CharToOem(szDir, szDir);
  1623. /* Allow dir field to be NULL without error. */
  1624. if (szDir && *szDir) {
  1625. /* Remove leading spaces. */
  1626. // RemoveLeadingSpaces(szDir);
  1627. SheRemoveQuotes(szDir);
  1628. //
  1629. // Test if the directory szDir is valid.
  1630. //
  1631. if (!ValidPathDrive(szDir) || !SetCurrentDirectory(szDir)) {
  1632. if (MyMessageBox(hDlg, IDS_BADPATHTITLE, IDS_BADPATHMSG3, NULL, MB_OKCANCEL | MB_DEFBUTTON2 | MB_ICONEXCLAMATION) == IDCANCEL)
  1633. goto ExitFalse;
  1634. fOK = FALSE;
  1635. }
  1636. }
  1637. //
  1638. // Before searching for the executable, check the validity of the szPath
  1639. // drive if there's one specified.
  1640. //
  1641. if (!ValidPathDrive(szPath)) {
  1642. if (MyMessageBox(hDlg, IDS_BADPATHTITLE, IDS_BADPATHMSG, szPath, MB_OKCANCEL | MB_DEFBUTTON2 | MB_ICONEXCLAMATION) == IDCANCEL)
  1643. goto ExitFalse;
  1644. fOK = FALSE;
  1645. }
  1646. else {
  1647. err = (int)((DWORD_PTR)FindExecutable(szPath, szDir, szExePath));
  1648. }
  1649. /* Check if the file exists if there is no associated exe. */
  1650. if (fOK && !*szExePath) {
  1651. if (err == SE_ERR_FNF) {
  1652. /* File doesn't exist. */
  1653. if (MyMessageBox(hDlg, IDS_BADPATHTITLE, IDS_BADPATHMSG, szPath, MB_OKCANCEL | MB_DEFBUTTON2 | MB_ICONEXCLAMATION) == IDCANCEL)
  1654. goto ExitFalse;
  1655. }
  1656. else {
  1657. /* Association is bogus. */
  1658. if (MyMessageBox(hDlg, IDS_BADPATHTITLE, IDS_BADPATHMSG2, szPath, MB_OKCANCEL | MB_DEFBUTTON2 | MB_ICONEXCLAMATION) == IDCANCEL)
  1659. goto ExitFalse;
  1660. else
  1661. dwRet = PATH_INVALID_OK;
  1662. }
  1663. }
  1664. /* Warn people against using removable or remote paths. */
  1665. /* HACK: Hard code UNC path format. Yuck. */
  1666. if (szPath[0] == TEXT('\\') && szPath[1] == TEXT('\\'))
  1667. goto VPWarnNet;
  1668. if (szPath[1] != TEXT(':') ) {
  1669. cDrive = (int)((DWORD_PTR)CharUpper((LPTSTR)szTemp[0]));
  1670. cDrive = cDrive - (INT)TEXT('A');
  1671. bOriginalDirectory = TRUE;
  1672. }
  1673. else {
  1674. cDrive = (int)((DWORD_PTR)CharUpper((LPTSTR)szPath[0]));
  1675. cDrive = cDrive - (INT)TEXT('A');
  1676. bOriginalDirectory = FALSE;
  1677. }
  1678. /* Change back to old directory. */
  1679. SetCurrentDirectory(szTemp);
  1680. //OemToChar(szDir, szDir);
  1681. if (IsRemovableDrive(cDrive)) {
  1682. if (MyMessageBox(hDlg, IDS_REMOVEPATHTITLE, IDS_PATHWARNING, NULL, MB_YESNO | MB_ICONEXCLAMATION | MB_DEFBUTTON2) == IDNO)
  1683. return(PATH_INVALID);
  1684. else
  1685. return(dwRet);
  1686. }
  1687. if (IsRemoteDrive(cDrive) && !bOriginalDirectory) {
  1688. VPWarnNet:
  1689. if (MyMessageBox(hDlg, IDS_NETPATHTITLE, IDS_PATHWARNING, NULL, MB_YESNO | MB_ICONEXCLAMATION | MB_DEFBUTTON2) == IDNO)
  1690. return(PATH_INVALID);
  1691. }
  1692. return(dwRet);
  1693. ExitFalse:
  1694. // Change back to old directory.
  1695. SetCurrentDirectory(szTemp);
  1696. //OemToChar(szDir, szDir);
  1697. return(PATH_INVALID);
  1698. }
  1699. /*--------------------------------------------------------------------------*/
  1700. /* */
  1701. /* BrowseOK() - */
  1702. /* */
  1703. /*--------------------------------------------------------------------------*/
  1704. BOOL NEAR PASCAL BrowseOK(HWND hWnd)
  1705. {
  1706. DWORD dwSave = dwContext;
  1707. TCHAR szPathField[MAXITEMPATHLEN+1];
  1708. BOOL ret;
  1709. dwContext = IDH_ICONBROWSEDLG;
  1710. GetDlgItemText(hWnd, IDD_NAME, szPathField, CharSizeOf(szPathField));
  1711. if (GetFileNameFromBrowse(hWnd, szPathField, sizeof(szPathField),
  1712. NULL, IDS_CHNGICONPROGS, TEXT("ico"))) {
  1713. //
  1714. // if filename or directory have spaces, put the path
  1715. // between quotes.
  1716. //
  1717. CheckEscapes(szPathField, MAXITEMPATHLEN+1);
  1718. SetDlgItemText(hWnd, IDD_NAME, szPathField);
  1719. /* Set default button to OK. */
  1720. PostMessage(hWnd, WM_NEXTDLGCTL, (WPARAM)GetDlgItem(hWnd, IDOK), TRUE);
  1721. ret = TRUE;
  1722. }
  1723. else
  1724. ret = FALSE;
  1725. dwContext = dwSave;
  1726. return ret;
  1727. }
  1728. /*--------------------------------------------------------------------------*/
  1729. /* */
  1730. /* IconFileExists() - */
  1731. /* */
  1732. /* Checks if the file exists, if it doesn't it tries tagging on .exe and */
  1733. /* if that fails it reports an error. The given path is environment expanded. */
  1734. /* If it needs to put up an error box, it changes the cursor back. */
  1735. /* Path s assumed to be MAXITEMPATHLEN long. */
  1736. /* The main reason for moving this out of the DlgProc was because we're */
  1737. /* running out of stack space on the call to the comm dlg. */
  1738. /* */
  1739. /*--------------------------------------------------------------------------*/
  1740. BOOL NEAR PASCAL IconFileExists(HWND hWnd, HCURSOR hCur, LPTSTR szPath)
  1741. {
  1742. TCHAR szExtended[MAXITEMPATHLEN+1]; // Path with .exe if needed.
  1743. BOOL ret = TRUE;
  1744. //OFSTRUCT of;
  1745. HCURSOR hCursor;
  1746. DWORD dwResult ;
  1747. TCHAR szPathFieldTemp[MAXITEMPATHLEN+1] ;
  1748. LPTSTR FilePart ;
  1749. /* Check Files existance. */
  1750. DoEnvironmentSubst(szPath, MAXITEMPATHLEN+1);
  1751. StripArgs(szPath);
  1752. if (*szPath == TEXT('"')) {
  1753. SheRemoveQuotes(szPath);
  1754. }
  1755. lstrcpy(szExtended, szPath);
  1756. // use SearchPath instead of MOpenFile(OF_EXIST) to see if a file exists
  1757. dwResult = SearchPath(NULL,szPath,NULL,MAXITEMPATHLEN+1,
  1758. szPathFieldTemp,&FilePart) ;
  1759. if (dwResult == 0 && GetLastError() != 0x20) {
  1760. dwResult = SearchPath(NULL,szExtended,TEXT(".exe"),MAXITEMPATHLEN+1,
  1761. szPathFieldTemp,&FilePart) ;
  1762. if (dwResult == 0 && GetLastError() != 0x20) {
  1763. ShowCursor(FALSE);
  1764. hCursor = SetCursor(hCur);
  1765. /*
  1766. * File doesn't exist,tidier if we report the error with the
  1767. * unextended path only.
  1768. */
  1769. MyMessageBox(hWnd, IDS_NOICONSTITLE, IDS_BADPATHMSG,
  1770. szPath, MB_OK | MB_ICONEXCLAMATION);
  1771. ret = FALSE;
  1772. ShowCursor(TRUE);
  1773. SetCursor(hCursor);
  1774. }
  1775. else {
  1776. lstrcpy(szPath, FilePart);
  1777. }
  1778. }
  1779. return ret;
  1780. }
  1781. /*--------------------------------------------------------------------------*/
  1782. /* */
  1783. /* IconDlgProc() - */
  1784. /* */
  1785. /*--------------------------------------------------------------------------*/
  1786. /* NOTE: Returns Icon's path in 'szIconPath' and number in 'iDlgIconId'.
  1787. *
  1788. * INPUT:
  1789. * 'szIconPath' has the default icon's path.
  1790. * 'iDlgIconId' is set to the default icon's id.
  1791. *
  1792. * 'szMessage' is used as a temporary variable.
  1793. * 'szPathField' is used as a temporary variable.
  1794. *
  1795. * OUTPUT:
  1796. * 'szIconPath' contains the icon's path.
  1797. * 'iDlgIconId' contains the icon's resource id.
  1798. * 'iDlgIconIndex' contains the icon's index.
  1799. */
  1800. INT_PTR APIENTRY IconDlgProc( HWND hwnd, UINT uiMsg, WPARAM wParam, LPARAM lParam)
  1801. {
  1802. int i;
  1803. int iIconSelected = 0;
  1804. static HANDLE hIconList = NULL;
  1805. static LPMYICONINFO lpIconList;
  1806. static INT cIcons;
  1807. switch (uiMsg) {
  1808. case WM_INITDIALOG:
  1809. {
  1810. RECT rc;
  1811. int cy;
  1812. TCHAR szExpanded[MAXITEMPATHLEN+1];
  1813. /*
  1814. * All this first pass stuff is so that the first time something
  1815. * bogus happens (file not found, no icons) we give the user
  1816. * a list of icons from progman.
  1817. */
  1818. fFirstPass = TRUE;
  1819. SetDlgItemText(hwnd, IDD_NAME, (LPTSTR)szIconPath);
  1820. SendDlgItemMessage(hwnd, IDD_NAME, EM_LIMITTEXT, MAXITEMPATHLEN, 0L);
  1821. SendDlgItemMessage(hwnd,IDD_ICON,LB_SETCOLUMNWIDTH,
  1822. GetSystemMetrics(SM_CXICON) + 12,0L);
  1823. wParam = (WPARAM)GetDlgItem(hwnd,IDD_ICON);
  1824. /* compute the height of the listbox based on icon dimensions
  1825. */
  1826. GetClientRect((HWND) wParam,&rc);
  1827. cy = GetSystemMetrics(SM_CYICON)
  1828. + GetSystemMetrics(SM_CYHSCROLL)
  1829. + GetSystemMetrics(SM_CYBORDER)
  1830. + 4;
  1831. SetWindowPos((HWND)wParam, NULL, 0, 0, rc.right, cy,
  1832. SWP_NOMOVE | SWP_NOZORDER);
  1833. cy = rc.bottom - cy;
  1834. GetWindowRect(hwnd,&rc);
  1835. rc.bottom -= rc.top;
  1836. rc.right -= rc.left;
  1837. /* FE FONTS are taller than US Font */
  1838. if ( GetSystemMetrics( SM_DBCSENABLED ) )
  1839. rc.bottom = rc.bottom - cy;
  1840. SetWindowPos(hwnd,NULL,0,0,rc.right,rc.bottom,SWP_NOMOVE);
  1841. wParam = (WPARAM)iDlgIconId;
  1842. PutIconsInList:
  1843. if (!GetDlgItemText(hwnd, IDD_NAME, (LPTSTR)szPathField, CharSizeOf(szPathField))) {
  1844. szPathField[0] = TEXT('\0');
  1845. }
  1846. wParam = (WPARAM)SetCursor(LoadCursor(NULL, IDC_WAIT));
  1847. ShowCursor(TRUE);
  1848. SendDlgItemMessage(hwnd, IDD_ICON, LB_RESETCONTENT, 0, 0L);
  1849. lstrcpy(szExpanded, szPathField);
  1850. if (!IconFileExists(hwnd, (HCURSOR)wParam, szExpanded)) {
  1851. if (fFirstPass) {
  1852. /* Icon File doesn't exist, use progman. */
  1853. fFirstPass = FALSE; // Only do this bit once.
  1854. GetModuleFileName(hAppInstance, (LPTSTR)szPathField, CharSizeOf(szPathField));
  1855. SetDlgItemText(hwnd, IDD_NAME, (LPTSTR)szPathField);
  1856. lstrcpy(szExpanded, szPathField);
  1857. }
  1858. else {
  1859. ShowCursor(FALSE);
  1860. SetCursor((HCURSOR)wParam);
  1861. break;
  1862. }
  1863. }
  1864. if (hIconList) {
  1865. FreeIconList(hIconList, -1);
  1866. hIconList = NULL;
  1867. }
  1868. cIcons = (INT)((DWORD_PTR)ExtractIcon(hAppInstance, szExpanded, (UINT)-1));
  1869. if (!cIcons) {
  1870. if (fFirstPass) {
  1871. TCHAR szFilename[MAXITEMPATHLEN+1];
  1872. fFirstPass = FALSE; // Only do this bit once.
  1873. ShowCursor(FALSE);
  1874. SetCursor((HCURSOR)wParam);
  1875. MyMessageBox(hwnd, IDS_NOICONSTITLE, IDS_NOICONSMSG1, NULL, MB_OK | MB_ICONEXCLAMATION);
  1876. /*
  1877. * No icons here - change the path do somewhere where we
  1878. * know there are icons.
  1879. * Get the path to progman.
  1880. */
  1881. GetModuleFileName(hAppInstance, (LPTSTR)szPathField, CharSizeOf(szPathField));
  1882. GetFilenameFromPath((LPTSTR)szPathField, szFilename);
  1883. SetDlgItemText(hwnd, IDD_NAME, szFilename);
  1884. goto PutIconsInList;
  1885. }
  1886. ShowCursor(FALSE);
  1887. SetCursor((HCURSOR) wParam);
  1888. MyMessageBox(hwnd, IDS_NOICONSTITLE, IDS_NOICONSMSG, NULL, MB_OK | MB_ICONEXCLAMATION);
  1889. break;
  1890. }
  1891. SendDlgItemMessage(hwnd,IDD_ICON,WM_SETREDRAW,FALSE,0L);
  1892. // Get shell.dll to return a list of icons.
  1893. if (hIconList = InternalExtractIconList(hAppInstance, szExpanded, &cIcons)) {
  1894. if (lpIconList = (LPMYICONINFO)GlobalLock(hIconList)) {
  1895. for (i = 0; i < cIcons; i++) {
  1896. if (!(lpIconList+i)->hIcon) {
  1897. cIcons = i;
  1898. break;
  1899. }
  1900. SendDlgItemMessage(hwnd,IDD_ICON,LB_ADDSTRING,0,
  1901. (LPARAM)((lpIconList+i)->hIcon));
  1902. if ((lpIconList+i)->iIconId == iDlgIconId)
  1903. iIconSelected = i;
  1904. }
  1905. GlobalUnlock(hIconList);
  1906. }
  1907. else {
  1908. cIcons = 0;
  1909. }
  1910. }
  1911. else {
  1912. cIcons = 0;
  1913. }
  1914. if (SendDlgItemMessage(hwnd,IDD_ICON,LB_SETCURSEL,(WPARAM)iIconSelected,0L)
  1915. == LB_ERR)
  1916. {
  1917. // select the first.
  1918. SendDlgItemMessage(hwnd,IDD_ICON,LB_SETCURSEL,0,0L);
  1919. }
  1920. SendDlgItemMessage(hwnd,IDD_ICON,WM_SETREDRAW,TRUE,0L);
  1921. InvalidateRect(GetDlgItem(hwnd,IDD_ICON),NULL,TRUE);
  1922. ShowCursor(FALSE);
  1923. SetCursor((HCURSOR)wParam);
  1924. break;
  1925. }
  1926. case WM_DRAWITEM:
  1927. #define lpdi ((DRAWITEMSTRUCT FAR *)lParam)
  1928. if ((HANDLE)lpdi->itemData == (HANDLE)NULL)
  1929. break;
  1930. InflateRect(&lpdi->rcItem,-4,0);
  1931. if (lpdi->itemState & ODS_SELECTED)
  1932. SetBkColor(lpdi->hDC,GetSysColor(COLOR_HIGHLIGHT));
  1933. else
  1934. SetBkColor(lpdi->hDC,GetSysColor(COLOR_WINDOW));
  1935. /* repaint the selection state
  1936. */
  1937. ExtTextOut(lpdi->hDC,0,0,ETO_OPAQUE,&lpdi->rcItem,NULL,0,NULL);
  1938. /* draw the icon
  1939. */
  1940. DrawIcon(lpdi->hDC,
  1941. lpdi->rcItem.left+2,
  1942. lpdi->rcItem.top+2,
  1943. (HICON) lpdi->itemData);
  1944. /* if it has the focus, draw the focus
  1945. */
  1946. #ifdef NOTINUSER
  1947. if (lpdi->itemState & ODS_FOCUS)
  1948. DrawFocusRect(lpdi->hDC,&lpdi->rcItem);
  1949. #endif
  1950. #undef lpdi
  1951. break;
  1952. case WM_MEASUREITEM:
  1953. #define lpmi ((MEASUREITEMSTRUCT FAR *)lParam)
  1954. lpmi->itemWidth = (WORD)(GetSystemMetrics(SM_CXICON) + 12);
  1955. lpmi->itemHeight = (WORD)(GetSystemMetrics(SM_CYICON) + 4);
  1956. #undef lpmi
  1957. break;
  1958. case WM_COMMAND:
  1959. switch(GET_WM_COMMAND_ID(wParam, lParam)){
  1960. case IDD_HELP:
  1961. goto DoHelp;
  1962. case IDD_BROWSE:
  1963. if (BrowseOK(hwnd))
  1964. goto PutIconsInList;
  1965. else
  1966. break;
  1967. case IDD_NAME:
  1968. if (!GetDlgItemText(hwnd, IDD_NAME, (LPTSTR)szMessage, MAXITEMPATHLEN+1)) {
  1969. szMessage[0] = TEXT('\0');
  1970. }
  1971. /* Did any thing change since we hit 'Next' last? */
  1972. if (lstrcmpi(szMessage, szPathField)) {
  1973. SendDlgItemMessage(hwnd,IDD_ICON,LB_SETCURSEL,(WPARAM)-1,0L);
  1974. }
  1975. break;
  1976. case IDD_ICON:
  1977. GetDlgItemText(hwnd, IDD_NAME, (LPTSTR)szMessage, MAXITEMPATHLEN+1);
  1978. /* Did any thing change since we hit 'Next' last? */
  1979. if (lstrcmpi(szMessage, szPathField)) {
  1980. lstrcpy(szPathField, szMessage);
  1981. wParam = MAKELONG(0, HIWORD(wParam));
  1982. goto PutIconsInList;
  1983. }
  1984. if (GET_WM_COMMAND_CMD(wParam, lParam) != LBN_DBLCLK)
  1985. break;
  1986. /*** FALL THRU on double click ***/
  1987. case IDOK:
  1988. if(!GetDlgItemText(hwnd, IDD_NAME, szMessage, MAXITEMPATHLEN+1))
  1989. goto PutIconsInList;
  1990. //#ifdef JAPAN
  1991. // if (CheckPortName(hwnd,szMessage))
  1992. // break;
  1993. //#endif
  1994. /* Did any thing change since we hit 'Next' last? */
  1995. if (lstrcmpi(szMessage, szPathField)) {
  1996. lstrcpy(szPathField, szMessage);
  1997. wParam = MAKELONG(0, HIWORD(wParam));
  1998. goto PutIconsInList;
  1999. }
  2000. else {
  2001. iIconSelected = (int)SendDlgItemMessage(hwnd,IDD_ICON,
  2002. LB_GETCURSEL,0,0L);
  2003. if (iIconSelected < 0)
  2004. iIconSelected = 0;
  2005. }
  2006. if (hDlgIcon)
  2007. hIconGlobal = hDlgIcon;
  2008. if (cIcons > 0) { /* if there is at least one icon */
  2009. hDlgIcon = (lpIconList+iIconSelected)->hIcon;
  2010. iDlgIconId = (lpIconList+iIconSelected)->iIconId;
  2011. iDlgIconIndex = iIconSelected;
  2012. GlobalUnlock(hIconList);
  2013. FreeIconList(hIconList,iIconSelected);
  2014. hIconList = NULL;
  2015. }
  2016. else {
  2017. hDlgIcon = NULL;
  2018. iDlgIconId = 0;
  2019. iDlgIconIndex = 0;
  2020. }
  2021. lstrcpy(szIconPath, szPathField);
  2022. EndDialog(hwnd, TRUE);
  2023. break;
  2024. case IDCANCEL:
  2025. if (hIconList) {
  2026. FreeIconList(hIconList , -1);
  2027. hIconList = NULL;
  2028. }
  2029. EndDialog(hwnd, FALSE);
  2030. break;
  2031. default:
  2032. return(FALSE);
  2033. }
  2034. break;
  2035. default:
  2036. if (uiMsg == uiHelpMessage || uiMsg == uiBrowseMessage) {
  2037. DoHelp:
  2038. PMHelp(hwnd);
  2039. return TRUE;
  2040. } else
  2041. return FALSE;
  2042. }
  2043. return(TRUE);
  2044. }
  2045. /*** GetRidOfIcon --
  2046. *
  2047. *
  2048. *
  2049. * VOID APIENTRY GetRidOfIcon(VOID)
  2050. *
  2051. * ENTRY - VOID
  2052. *
  2053. * EXIT - VOID
  2054. *
  2055. * SYNOPSIS -
  2056. *
  2057. * WARNINGS -
  2058. * EFFECTS -
  2059. *
  2060. */
  2061. VOID APIENTRY GetRidOfIcon(VOID)
  2062. {
  2063. if (hDlgIcon && (hDlgIcon != hItemIcon) &&
  2064. (hDlgIcon != hProgmanIcon) &&
  2065. (hDlgIcon != hGroupIcon))
  2066. DestroyIcon(hDlgIcon);
  2067. hDlgIcon = NULL;
  2068. }
  2069. /*** GetCurrentIcon --
  2070. *
  2071. *
  2072. *
  2073. * HICON APIENTRY GetCurrentIcon(VOID)
  2074. *
  2075. * ENTRY - VOID
  2076. *
  2077. * EXIT - HICON
  2078. *
  2079. * SYNOPSIS -
  2080. *
  2081. * WARNINGS -
  2082. * EFFECTS -
  2083. *
  2084. */
  2085. HICON APIENTRY GetCurrentIcon(VOID)
  2086. {
  2087. TCHAR szExpanded[MAXITEMPATHLEN+1];
  2088. HANDLE hModule;
  2089. HANDLE h;
  2090. PBYTE p;
  2091. int cb;
  2092. // BUG BUG this was just added and I don't know if it's OK
  2093. if (hDlgIcon) {
  2094. DestroyIcon(hDlgIcon);
  2095. hDlgIcon = NULL;
  2096. }
  2097. lstrcpy(szExpanded, szIconPath);
  2098. DoEnvironmentSubst(szExpanded, CharSizeOf(szExpanded));
  2099. StripArgs(szExpanded);
  2100. TagExtension(szExpanded, sizeof(szExpanded));
  2101. SheRemoveQuotes(szExpanded);
  2102. if (hModule = LoadLibrary(szExpanded)) {
  2103. h = FindResource(hModule, (LPTSTR) MAKEINTRESOURCE(iDlgIconId), (LPTSTR) MAKEINTRESOURCE(RT_ICON));
  2104. if (h) {
  2105. cb = SizeofResource(hModule, h);
  2106. h = LoadResource(hModule, h);
  2107. p = LockResource(h);
  2108. hDlgIcon = CreateIconFromResource(p, cb, TRUE, 0x00030000);
  2109. UnlockResource(h);
  2110. FreeResource(h);
  2111. }
  2112. FreeLibrary(hModule);
  2113. if (hDlgIcon) {
  2114. return(hDlgIcon);
  2115. }
  2116. }
  2117. else {
  2118. hDlgIcon = ExtractIcon(hAppInstance, szExpanded, (UINT)iDlgIconId);
  2119. if (hDlgIcon && hDlgIcon != (HANDLE)1) {
  2120. return(hDlgIcon);
  2121. }
  2122. }
  2123. iDlgIconId = 0;
  2124. if (hDlgIcon == NULL) {
  2125. if (h = FindResource(hAppInstance, (LPTSTR) MAKEINTRESOURCE(ITEMICON), RT_GROUP_ICON)) {
  2126. h = LoadResource(hAppInstance, h);
  2127. p = LockResource(h);
  2128. iDlgIconId = (WORD)LookupIconIdFromDirectory(p, TRUE);
  2129. iDlgIconIndex = ITEMICONINDEX;
  2130. UnlockResource(h);
  2131. FreeResource(h);
  2132. }
  2133. }
  2134. if (hDlgIcon == (HANDLE)1) {
  2135. if (h = FindResource(hAppInstance, (LPTSTR) MAKEINTRESOURCE(DOSAPPICON), RT_GROUP_ICON)) {
  2136. h = LoadResource(hAppInstance, h);
  2137. p = LockResource(h);
  2138. iDlgIconId = (WORD)LookupIconIdFromDirectory(p, TRUE);
  2139. iDlgIconIndex = DOSAPPICONINDEX;
  2140. UnlockResource(h);
  2141. FreeResource(h);
  2142. }
  2143. }
  2144. h = FindResource(hAppInstance, (LPTSTR) MAKEINTRESOURCE(iDlgIconId), (LPTSTR) MAKEINTRESOURCE(RT_ICON));
  2145. if (h) {
  2146. cb = (WORD)SizeofResource(hAppInstance, h);
  2147. h = LoadResource(hAppInstance, h);
  2148. p = LockResource(h);
  2149. hDlgIcon = CreateIconFromResource(p, cb, TRUE, 0x00030000);
  2150. UnlockResource(h);
  2151. FreeResource(h);
  2152. }
  2153. if (hModule)
  2154. FreeLibrary(hModule);
  2155. return(hDlgIcon);
  2156. }
  2157. /*--------------------------------------------------------------------------*/
  2158. /* */
  2159. /* CheckHotKeyInUse() - Return of TRUE means no-dup or user says OK anyway.*/
  2160. /* fNewItem is TRUE if your about to create a new item, FALSE if your */
  2161. /* just editing an old one. */
  2162. /* */
  2163. /*--------------------------------------------------------------------------*/
  2164. BOOL NEAR PASCAL CheckHotKeyInUse(WORD wHotKey, BOOL fNewItem)
  2165. {
  2166. PGROUP pGroup;
  2167. PITEM pItem;
  2168. LPGROUPDEF lpgd;
  2169. LPITEMDEF lpid;
  2170. TCHAR szTemp1[64];
  2171. TCHAR szTemp2[MAXMESSAGELEN+1];
  2172. int ret;
  2173. for (pGroup = pFirstGroup; pGroup; pGroup = pGroup->pNext) {
  2174. for (pItem = pGroup->pItems; pItem; pItem = pItem->pNext) {
  2175. /*
  2176. * If we're editing an existing item in then ignore the one
  2177. * we're editing (the first item in the current group).
  2178. */
  2179. if (!fNewItem && pGroup == pCurrentGroup && pItem == pCurrentGroup->pItems)
  2180. continue;
  2181. if (wHotKey && (wHotKey == GroupFlag(pGroup,pItem,(WORD)ID_HOTKEY)))
  2182. goto Duplicate;
  2183. }
  2184. }
  2185. return TRUE;
  2186. Duplicate:
  2187. if (!(lpgd = LockGroup(pGroup->hwnd)))
  2188. return TRUE; // Crash out without error.
  2189. lpid = ITEM(lpgd, pItem->iItem);
  2190. if (!LoadString(hAppInstance, IDS_ITEMINGROUP, szTemp1, CharSizeOf(szTemp1)))
  2191. return TRUE;
  2192. wsprintf(szTemp2, szTemp1, (LPTSTR) PTR(lpgd, lpid->pName), (LPTSTR) PTR(lpgd, lpgd->pName));
  2193. ret = MyMessageBox(hwndProgman,
  2194. IDS_DUPHOTKEYTTL, IDS_DUPHOTKEYMSG, szTemp2,
  2195. MB_OKCANCEL|MB_DEFBUTTON2|MB_ICONEXCLAMATION);
  2196. UnlockGroup(pGroup->hwnd);
  2197. if (ret == IDOK)
  2198. return TRUE;
  2199. else
  2200. return FALSE;
  2201. }
  2202. /* NOTE:
  2203. * 'szIconPath' has the icon's path.
  2204. * 'iDlgIconId' is set to the icon's id.
  2205. * 'iDlgIconIndex' is set to the icon's index.
  2206. *
  2207. * 'szNameField' is used as a temporary variable.
  2208. * 'szPathField' is used as a temporary variable.
  2209. */
  2210. /*** NewItemDlgProc -- Dialog Procedure
  2211. *
  2212. *
  2213. *
  2214. * INT_PTR APIENTRY NewItemDlgProc(HWND hwnd, UINT uiMsg, WPARAM wParam, LPARAM lParam)
  2215. *
  2216. * ENTRY - HWND hhwnd - handle to dialog box.
  2217. * UINT uiMsg - message to be acted upon.
  2218. * WPARAM wParam - value specific to uiMsg.
  2219. * LPARAM lParam - value specific to uiMsg.
  2220. *
  2221. * EXIT - True if success, False if not.
  2222. * SYNOPSIS - Dialog box message processing function.
  2223. *
  2224. * WARNINGS -
  2225. * EFFECTS -
  2226. *
  2227. */
  2228. INT_PTR APIENTRY NewItemDlgProc(HWND hwnd, UINT uiMsg, WPARAM wParam, LPARAM lParam)
  2229. {
  2230. static BOOL bIsWOWApp = FALSE;
  2231. DWORD dwThreadID;
  2232. HANDLE hThread;
  2233. HWND hIcon;
  2234. DWORD dwBinaryInfo, cbData, dwDataType;
  2235. BOOL bDoit;
  2236. switch (uiMsg) {
  2237. case WM_INITDIALOG:
  2238. if (GroupFull(pCurrentGroup)) {
  2239. EndDialog(hwnd, FALSE);
  2240. break;
  2241. }
  2242. SendDlgItemMessage(hwnd, IDD_NAME, EM_LIMITTEXT, MAXITEMNAMELEN, 0L);
  2243. SendDlgItemMessage(hwnd, IDD_COMMAND, EM_LIMITTEXT, MAXITEMPATHLEN, 0L);
  2244. SendDlgItemMessage(hwnd, IDD_DIR, EM_LIMITTEXT, MAXITEMPATHLEN, 0L);
  2245. szNameField[0] = TEXT('\0');
  2246. szPathField[0] = TEXT('\0');
  2247. szDirField[0] = TEXT('\0');
  2248. szIconPath[0] = TEXT('\0');
  2249. iDlgIconId = 0;
  2250. iDlgIconIndex = 0;
  2251. if (hDlgIcon)
  2252. DestroyIcon(hDlgIcon);
  2253. hDlgIcon = NULL;
  2254. EnableWindow(GetDlgItem(hwnd, IDOK), FALSE);
  2255. EnableWindow(GetDlgItem(hwnd, IDD_ICON), FALSE);
  2256. CheckDlgButton(hwnd, IDD_NEWVDM, 1);
  2257. EnableWindow(GetDlgItem(hwnd, IDD_NEWVDM), FALSE);
  2258. fNewIcon = FALSE;
  2259. //
  2260. // Set the inital state for the thread which checks the binary
  2261. // type.
  2262. //
  2263. //
  2264. // Query if the binary type checking is enabled.
  2265. //
  2266. cbData = sizeof(dwBinaryInfo);
  2267. if (RegQueryValueEx(hkeyPMSettings, szCheckBinaryType, 0, &dwDataType,
  2268. (LPBYTE)&dwBinaryInfo, &cbData) == ERROR_SUCCESS) {
  2269. bCheckBinaryType = (BOOL) dwBinaryInfo;
  2270. } else {
  2271. bCheckBinaryType = BINARY_TYPE_DEFAULT;
  2272. }
  2273. //
  2274. // Query the binary type checking timeout value.
  2275. //
  2276. cbData = sizeof(dwBinaryInfo);
  2277. if (RegQueryValueEx(hkeyPMSettings, szCheckBinaryTimeout, 0, &dwDataType,
  2278. (LPBYTE)&dwBinaryInfo, &cbData) == ERROR_SUCCESS) {
  2279. uiCheckBinaryTimeout = (UINT) dwBinaryInfo;
  2280. } else {
  2281. uiCheckBinaryTimeout = BINARY_TIMEOUT_DEFAULT;
  2282. }
  2283. //
  2284. // Create the worker thread, and the signal event. If appropriate.
  2285. //
  2286. if (bCheckBinaryType) {
  2287. hCheckBinaryEvent = CreateEvent (NULL, FALSE, FALSE,
  2288. CHECK_BINARY_EVENT_NAME);
  2289. hThread = CreateThread (NULL, 0,
  2290. (LPTHREAD_START_ROUTINE) CheckBinaryThread,
  2291. (LPVOID) hwnd, 0, &dwThreadID);
  2292. bCheckBinaryDirtyFlag = FALSE;
  2293. }
  2294. if (!bCheckBinaryType || !hThread || !hCheckBinaryEvent) {
  2295. //
  2296. // If this statement is true, either binary type checking
  2297. // is disabled or we failed to create the event or the thread.
  2298. // In this case, enable the separate memory checkbox, and let
  2299. // the user decide on his own.
  2300. //
  2301. CheckDlgButton(hwnd, IDD_NEWVDM, 0);
  2302. EnableWindow(GetDlgItem(hwnd,IDD_NEWVDM), TRUE);
  2303. //
  2304. // Clean up either item that succeeded
  2305. //
  2306. if (hCheckBinaryEvent) {
  2307. CloseHandle (hCheckBinaryEvent);
  2308. }
  2309. if (hThread) {
  2310. TerminateThread (hThread, 0);
  2311. }
  2312. //
  2313. // Setting this variable to NULL will prevent the second
  2314. // thread from trying to check the binary type.
  2315. //
  2316. hCheckBinaryEvent = NULL;
  2317. }
  2318. break;
  2319. case WM_TIMER:
  2320. if (hCheckBinaryEvent && bCheckBinaryDirtyFlag) {
  2321. bCheckBinaryDirtyFlag = FALSE;
  2322. SetEvent (hCheckBinaryEvent);
  2323. }
  2324. break;
  2325. case WM_COMMAND:
  2326. switch(GET_WM_COMMAND_ID(wParam, lParam)) {
  2327. case IDD_HELP:
  2328. goto DoHelp;
  2329. case IDD_COMMAND:
  2330. {
  2331. if (GET_WM_COMMAND_CMD(wParam, lParam) != EN_UPDATE)
  2332. break;
  2333. if (bCheckBinaryType) {
  2334. bCheckBinaryDirtyFlag = TRUE;
  2335. SetTimer (hwnd, CHECK_BINARY_ID, uiCheckBinaryTimeout, NULL);
  2336. }
  2337. bDoit = (GetDlgItemText(hwnd, IDD_COMMAND, szPathField, MAXITEMPATHLEN+1) > 0);
  2338. EnableWindow(GetDlgItem(hwnd, IDOK), bDoit);
  2339. if ( (hIcon = GetDlgItem(hwnd, IDD_ICON)) ) {
  2340. EnableWindow(hIcon, bDoit);
  2341. }
  2342. break;
  2343. }
  2344. case IDD_BROWSE:
  2345. {
  2346. DWORD dwSave = dwContext;
  2347. TCHAR szPathField[MAXITEMPATHLEN+1];
  2348. dwContext = IDH_PROPBROWSEDLG;
  2349. GetDlgItemText(hwnd, IDD_COMMAND, szPathField, MAXITEMPATHLEN+1);
  2350. GetDlgItemText(hwnd, IDD_DIR, szDirField, MAXITEMPATHLEN+1);
  2351. /* Get PathField using browser dlg. */
  2352. if (GetFileNameFromBrowse(hwnd, szPathField, sizeof(szPathField),
  2353. szDirField, IDS_PROPERTIESPROGS, TEXT("exe"))) {
  2354. // OK.
  2355. //
  2356. // if filename or directory have spaces, put the path
  2357. // between quotes.
  2358. //
  2359. CheckEscapes(szPathField, MAXITEMPATHLEN+1);
  2360. SetDlgItemText(hwnd, IDD_COMMAND, szPathField);
  2361. EnableWindow(GetDlgItem(hwnd, IDOK), TRUE);
  2362. EnableWindow(GetDlgItem(hwnd, IDD_ICON), TRUE);
  2363. /* Set default button to OK. */
  2364. PostMessage(hwnd, WM_NEXTDLGCTL, (WPARAM)GetDlgItem(hwnd, IDOK), TRUE);
  2365. }
  2366. dwContext = dwSave;
  2367. break;
  2368. }
  2369. case IDD_ICON:
  2370. {
  2371. TCHAR szTempField[MAXITEMPATHLEN+1];
  2372. GetDlgItemText(hwnd, IDD_COMMAND, szPathField, MAXITEMPATHLEN+1);
  2373. //#ifdef JAPAN
  2374. // if (CheckPortName(hwnd,szPathField))
  2375. // break;
  2376. //#endif
  2377. GetDlgItemText(hwnd, IDD_DIR, szDirField, MAXITEMPATHLEN+1);
  2378. // Expand env variables.
  2379. DoEnvironmentSubst(szPathField, MAXITEMPATHLEN+1)
  2380. && DoEnvironmentSubst(szDirField, MAXITEMPATHLEN+1);
  2381. // Get a full path to the icon.
  2382. StripArgs(szPathField);
  2383. //
  2384. // Change to original directory in case the use entered a
  2385. // relative path.
  2386. //
  2387. SetCurrentDirectory(szOriginalDirectory);
  2388. FindExecutable(szPathField, szDirField, szTempField);
  2389. SetCurrentDirectory(szWindowsDirectory);
  2390. /* Discard the old Icon Path. */
  2391. lstrcpy(szIconPath, szTempField);
  2392. iDlgIconId = 0;
  2393. iDlgIconIndex = 0;
  2394. if (fNewIcon = MyDialogBox(ICONDLG, hwnd, IconDlgProc)) {
  2395. SendDlgItemMessage(hwnd, IDD_CURICON, STM_SETICON, (WPARAM)hDlgIcon, 0L);
  2396. if (hIconGlobal) {
  2397. DestroyIcon(hIconGlobal);
  2398. hIconGlobal = NULL;
  2399. }
  2400. }
  2401. else { /* Cancel/ESC was selected, reset Icon Path to NULL. */
  2402. *szIconPath = TEXT('\0');
  2403. iDlgIconId = 0;
  2404. iDlgIconIndex = 0;
  2405. }
  2406. break;
  2407. }
  2408. case IDOK:
  2409. {
  2410. WORD hk;
  2411. TCHAR szHackField[MAXITEMPATHLEN + 1];
  2412. DWORD dwRet;
  2413. DWORD dwFlags = CI_ACTIVATE | CI_SET_DOS_FULLSCRN;
  2414. if(!GetDlgItemText(hwnd, IDD_COMMAND, szPathField, MAXITEMPATHLEN + 1)) {
  2415. szPathField[0] = TEXT('\0');
  2416. break;
  2417. }
  2418. //RemoveLeadingSpaces(szPathField);
  2419. hk = (WORD) SendDlgItemMessage(hwnd,IDD_HOTKEY, WM_GETHOTKEY,0,0L);
  2420. if (!CheckHotKeyInUse(hk, TRUE))
  2421. break;
  2422. GetDlgItemText(hwnd, IDD_DIR, szDirField, MAXITEMPATHLEN+1);
  2423. //RemoveLeadingSpaces(szDirField)
  2424. /* Expand env variables. */
  2425. DoEnvironmentSubst(szPathField, MAXITEMPATHLEN+1);
  2426. DoEnvironmentSubst(szDirField, MAXITEMPATHLEN+1);
  2427. /* Now remove the arguments from the command line. */
  2428. StripArgs(szPathField);
  2429. dwRet = ValidatePath(hwnd, szPathField, szDirField, szHackField);
  2430. if (dwRet == PATH_INVALID) {
  2431. break;
  2432. }
  2433. else if (dwRet == PATH_INVALID_OK) {
  2434. dwFlags |= CI_NO_ASSOCIATION;
  2435. }
  2436. /* Special case DOS apps. */
  2437. HandleDosApps(szHackField);
  2438. /* If the user hasn't supplied a description then build one. */
  2439. if (!GetDlgItemText(hwnd, IDD_NAME, szNameField, MAXITEMNAMELEN+1)) {
  2440. szNameField[0] = TEXT('\0');
  2441. }
  2442. /* Get the original command line with arguments. */
  2443. GetDlgItemText(hwnd, IDD_COMMAND, szPathField, MAXITEMPATHLEN+1);
  2444. //#ifdef JAPAN
  2445. // if (CheckPortName(hwnd,szPathField))
  2446. // break;
  2447. //#endif
  2448. /* Get original (unexpanded) directory. */
  2449. if (!GetDlgItemText(hwnd, IDD_DIR, szDirField, MAXITEMPATHLEN+1)) {
  2450. szDirField[0] = TEXT('\0');
  2451. } else {
  2452. LPTSTR lpEnd;
  2453. TCHAR chT;
  2454. // Remove trailing spaces (inside of quote if applicable)
  2455. lpEnd = szDirField + lstrlen (szDirField) - 1;
  2456. chT = *lpEnd;
  2457. if ( (chT == TEXT('\"')) || (chT == TEXT(' ')) ) {
  2458. // MarkTa fix for spaces at the end of a filename
  2459. // Remove the spaces by moving the last character forward.
  2460. while (*(lpEnd-1) == TEXT(' '))
  2461. lpEnd--;
  2462. *lpEnd = chT;
  2463. *(lpEnd+1) = TEXT ('\0');
  2464. // In case the character we saved was a space, we can
  2465. // NULL terminate it because now we know the next character
  2466. // to the left is valid, and the character to the right is
  2467. // already NULL.
  2468. if (*lpEnd == TEXT(' '))
  2469. *lpEnd = TEXT('\0');
  2470. }
  2471. }
  2472. GetStuffFromPIF(szPathField, szNameField, szDirField);
  2473. if (!*szNameField) {
  2474. BuildDescription(szNameField, szPathField);
  2475. }
  2476. /* If there's no default directory then add one. */
  2477. if (!*szDirField) {
  2478. GetDirectoryFromPath(szPathField, szDirField);
  2479. }
  2480. if (!InQuotes(szDirField)) {
  2481. //
  2482. // if szDirField needs quotes and the work dir is too
  2483. // long than we need to truncate it.
  2484. //
  2485. if (lstrlen(szDirField) >= MAXITEMPATHLEN-2) {
  2486. TCHAR chT;
  2487. chT = szDirField[MAXITEMPATHLEN-2];
  2488. szDirField[MAXITEMPATHLEN-2] = 0;
  2489. CheckEscapes(szDirField, MAXITEMPATHLEN+1);
  2490. if (*szDirField != TEXT('"')) {
  2491. szDirField[MAXITEMPATHLEN-2] = chT;
  2492. }
  2493. }
  2494. else {
  2495. CheckEscapes(szDirField, MAXITEMPATHLEN+1);
  2496. }
  2497. }
  2498. if (IsWindowEnabled(GetDlgItem(hwnd, IDD_NEWVDM)) &&
  2499. IsDlgButtonChecked(hwnd, IDD_NEWVDM)) {
  2500. dwFlags |= CI_SEPARATE_VDM;
  2501. }
  2502. /* Create new item using UNICODE strings. */
  2503. CreateNewItem(pCurrentGroup->hwnd,
  2504. szNameField,
  2505. szPathField,
  2506. szIconPath,
  2507. szDirField,
  2508. hk,
  2509. (BOOL)IsDlgButtonChecked(hwnd, IDD_LOAD),
  2510. (WORD)iDlgIconId,
  2511. (WORD)iDlgIconIndex,
  2512. hDlgIcon,
  2513. NULL,
  2514. dwFlags);
  2515. }
  2516. // Update scroll bars for new item
  2517. if ((bAutoArrange) && (!bAutoArranging))
  2518. ArrangeItems(pCurrentGroup->hwnd);
  2519. else if (!bAutoArranging)
  2520. CalcGroupScrolls(pCurrentGroup->hwnd);
  2521. // fall through...
  2522. case IDCANCEL:
  2523. if (bCheckBinaryType) {
  2524. //
  2525. // Setting this variable to false, and signaling the event
  2526. // will cause the binary checking thread to terminate.
  2527. //
  2528. bCheckBinaryType = FALSE;
  2529. SetEvent (hCheckBinaryEvent);
  2530. KillTimer (hwnd, CHECK_BINARY_ID);
  2531. }
  2532. EndDialog(hwnd, GET_WM_COMMAND_ID(wParam, lParam) == IDOK);
  2533. GetRidOfIcon();
  2534. break;
  2535. default:
  2536. return(FALSE);
  2537. }
  2538. break;
  2539. default:
  2540. if (uiMsg == uiHelpMessage || uiMsg == uiBrowseMessage) {
  2541. DoHelp:
  2542. PMHelp(hwnd);
  2543. return TRUE;
  2544. } else
  2545. return FALSE;
  2546. }
  2547. UNREFERENCED_PARAMETER(lParam);
  2548. return(TRUE);
  2549. }
  2550. /*** NewGroupDlgProc -- Dialog Procedure
  2551. *
  2552. *
  2553. *
  2554. * INT_PTR APIENTRY NewGroupDlgProc(HWND hwnd, UINT uiMsg, WPARAM wParam, LPARAM lParam)
  2555. *
  2556. * ENTRY - HWND hhwnd - handle to dialog box.
  2557. * UINT uiMsg - message to be acted upon.
  2558. * DWORD wParam - value specific to uiMsg.
  2559. * LPARAM lParam - value specific to uiMsg.
  2560. *
  2561. * EXIT - True if success, False if not.
  2562. * SYNOPSIS - Dialog box message processing function.
  2563. *
  2564. * WARNINGS -
  2565. * EFFECTS -
  2566. *
  2567. */
  2568. INT_PTR APIENTRY NewGroupDlgProc(HWND hwnd, UINT uiMsg, WPARAM wParam, LPARAM lParam)
  2569. {
  2570. BOOL bDoit;
  2571. HWND hwndGroup;
  2572. switch (uiMsg) {
  2573. case WM_INITDIALOG:
  2574. if (wNewSelection == TYPE_COMMONGROUP) {
  2575. TCHAR szCommonGroupTitle[64];
  2576. if (LoadString(hAppInstance, IDS_COMMONGROUPPROP,
  2577. szCommonGroupTitle, CharSizeOf(szCommonGroupTitle))) {
  2578. SetWindowText(hwnd, szCommonGroupTitle);
  2579. }
  2580. }
  2581. SendDlgItemMessage(hwnd, IDD_NAME, EM_LIMITTEXT, MAXGROUPNAMELEN, 0L);
  2582. break;
  2583. case WM_COMMAND:
  2584. switch(GET_WM_COMMAND_ID(wParam, lParam)) {
  2585. HCURSOR hCursor;
  2586. case IDD_NAME:
  2587. case IDD_PATH:
  2588. /* Allow OK if either of the two fields have anything in them. */
  2589. bDoit = (GetDlgItemText(hwnd, IDD_NAME, szPathField, CharSizeOf(szPathField)) > 0);
  2590. EnableWindow(GetDlgItem(hwnd, IDOK), bDoit);
  2591. break;
  2592. case IDD_HELP:
  2593. goto DoHelp;
  2594. case IDOK:
  2595. if(!GetDlgItemText(hwnd, IDD_NAME, szNameField, MAXITEMNAMELEN + 1)) {
  2596. szNameField[0] = TEXT('\0');
  2597. break;
  2598. }
  2599. hCursor = SetCursor(LoadCursor(NULL, IDC_WAIT));
  2600. ShowCursor(TRUE);
  2601. hwndGroup = CreateNewGroup(szNameField, (wNewSelection == TYPE_COMMONGROUP));
  2602. ShowCursor(FALSE);
  2603. SetCursor(hCursor);
  2604. if (hwndGroup) {
  2605. EndDialog(hwnd, TRUE);
  2606. }
  2607. break;
  2608. case IDCANCEL:
  2609. EndDialog(hwnd, FALSE);
  2610. break;
  2611. default:
  2612. return FALSE;
  2613. }
  2614. break;
  2615. default:
  2616. if (uiMsg == uiHelpMessage) {
  2617. DoHelp:
  2618. PMHelp(hwnd);
  2619. return TRUE;
  2620. } else {
  2621. return FALSE;
  2622. }
  2623. }
  2624. return TRUE;
  2625. }
  2626. /*--------------------------------------------------------------------------*/
  2627. /* */
  2628. /* EditBrowseOK() - */
  2629. /* */
  2630. /*--------------------------------------------------------------------------*/
  2631. BOOL NEAR PASCAL EditBrowseOK(HWND hDlg)
  2632. {
  2633. DWORD dwSave = dwContext;
  2634. TCHAR szPathField[MAXITEMPATHLEN+1];
  2635. BOOL ret;
  2636. dwContext = IDH_PROPBROWSEDLG;
  2637. GetDlgItemText(hDlg, IDD_COMMAND, szPathField, MAXITEMPATHLEN+1);
  2638. GetDlgItemText(hDlg, IDD_DIR, szDirField, MAXITEMPATHLEN+1);
  2639. /* Get PathField using browser dlg. */
  2640. if (GetFileNameFromBrowse(hDlg, szPathField,sizeof(szPathField) ,
  2641. szDirField, IDS_PROPERTIESPROGS, TEXT("exe"))) {
  2642. /* OK. */
  2643. //
  2644. // if filename or directory have spaces, put the path
  2645. // between quotes.
  2646. //
  2647. CheckEscapes(szPathField, MAXITEMPATHLEN+1);
  2648. SetDlgItemText(hDlg, IDD_COMMAND, szPathField);
  2649. EnableWindow(GetDlgItem(hDlg, IDOK), TRUE);
  2650. EnableWindow(GetDlgItem(hDlg, IDD_ICON), TRUE);
  2651. /* Set default button to OK. */
  2652. PostMessage(hDlg, WM_NEXTDLGCTL, (WPARAM)GetDlgItem(hDlg, IDOK), TRUE);
  2653. ret = TRUE;
  2654. }
  2655. else
  2656. ret = FALSE;
  2657. dwContext = dwSave;
  2658. return ret;
  2659. }
  2660. /*** EditItemDlgProc -- Dialog Procedure
  2661. *
  2662. *
  2663. *
  2664. * INT_PTR APIENTRY EditItemDlgProc(HWND hwnd, UINT uiMsg, WPARAM wParam, LPARAM lParam)
  2665. *
  2666. * ENTRY - HWND hhwnd - handle to dialog box.
  2667. * UINT uiMsg - message to be acted upon.
  2668. * WPARAM wParam - value specific to uiMsg.
  2669. * LPARAM lParam - value specific to uiMsg.
  2670. *
  2671. * EXIT - True if success, False if not.
  2672. * SYNOPSIS - Dialog box message processing function.
  2673. *
  2674. * WARNINGS -
  2675. * EFFECTS -
  2676. *
  2677. */
  2678. /* NOTE:
  2679. * 'szIconPath' has the icon's path.
  2680. * 'iDlgIconId' is set to the icon's id.
  2681. * 'iDlgIconIndex' is set to the icon's index.
  2682. *
  2683. * 'szNameField' is used as a temporary variable.
  2684. * 'szPathField' is used as a temporary variable.
  2685. */
  2686. INT_PTR APIENTRY EditItemDlgProc(HWND hwnd, UINT uiMsg, WPARAM wParam, LPARAM lParam)
  2687. {
  2688. LPITEMDEF lpid;
  2689. LPGROUPDEF lpgd;
  2690. TCHAR szTempField[MAXITEMPATHLEN + 1];
  2691. DWORD dwFlags = CI_ACTIVATE;
  2692. DWORD dwBinaryType;
  2693. TCHAR szFullPath[MAXITEMPATHLEN+1] ;
  2694. LPTSTR FilePart ;
  2695. static BOOL bIsWOWApp = FALSE;
  2696. static WORD wHotKey;
  2697. static TCHAR szDescription[MAXITEMNAMELEN + 1];
  2698. DWORD dwThreadID;
  2699. HANDLE hThread;
  2700. HWND hIcon;
  2701. DWORD dwBinaryInfo, cbData, dwDataType;
  2702. BOOL bDoit;
  2703. switch (uiMsg) {
  2704. case WM_INITDIALOG:
  2705. /*
  2706. * Get current item information.
  2707. */
  2708. pActiveGroup = pCurrentGroup;
  2709. lpgd = (LPGROUPDEF)GlobalLock(pActiveGroup->hGroup);
  2710. lpid = LockItem(pActiveGroup,pActiveGroup->pItems);
  2711. if (lpid == 0L)
  2712. goto EditDlgExit;
  2713. fNewIcon = FALSE;
  2714. SendDlgItemMessage(hwnd, IDD_NAME, EM_LIMITTEXT, MAXITEMNAMELEN, 0L);
  2715. SetDlgItemText(hwnd, IDD_NAME, (LPTSTR) PTR(lpgd, lpid->pName));
  2716. lstrcpy(szDescription, (LPTSTR) PTR(lpgd, lpid->pName));
  2717. GetItemCommand(pActiveGroup, pActiveGroup->pItems, szPathField, szDirField);
  2718. /* Keep a copy of what the old item was refering to.
  2719. * A full expanded OEM path to the executable
  2720. */
  2721. DoEnvironmentSubst(szPathField, MAXITEMPATHLEN+1);
  2722. DoEnvironmentSubst(szDirField, MAXITEMPATHLEN+1);
  2723. StripArgs(szPathField);
  2724. // Find exe will toast on ansi strings.
  2725. //
  2726. // Change to original Directory in case the user entered a relative path
  2727. //
  2728. //
  2729. SetCurrentDirectory(szOriginalDirectory);
  2730. FindExecutable(szPathField, szDirField, szNameField);
  2731. SetCurrentDirectory(szWindowsDirectory);
  2732. lstrcpy(szIconPath, (LPTSTR) PTR(lpgd, lpid->pIconPath));
  2733. if (!*szIconPath) {
  2734. /* use default icon path */
  2735. lstrcpy(szIconPath, szNameField);
  2736. }
  2737. iDlgIconId = lpid->iIcon;
  2738. iDlgIconIndex = lpid->wIconIndex;
  2739. TagExtension(szPathField, sizeof(szPathField));
  2740. SheRemoveQuotes (szPathField);
  2741. if (SearchPath(NULL,
  2742. szPathField,
  2743. NULL,
  2744. MAXITEMPATHLEN+1,
  2745. szFullPath,
  2746. &FilePart) &&
  2747. GetBinaryType(szFullPath, &dwBinaryType) &&
  2748. dwBinaryType == SCS_WOW_BINARY) {
  2749. bIsWOWApp = TRUE;
  2750. if (GroupFlag(pActiveGroup,pActiveGroup->pItems,(WORD)ID_NEWVDM)) {
  2751. CheckDlgButton(hwnd, IDD_NEWVDM, 1);
  2752. }
  2753. }
  2754. else {
  2755. CheckDlgButton(hwnd, IDD_NEWVDM, 1);
  2756. EnableWindow(GetDlgItem(hwnd, IDD_NEWVDM), FALSE);
  2757. }
  2758. /* Re-get the fields so that the dlg is initialized with
  2759. * the environment variables intact.
  2760. */
  2761. GetItemCommand(pActiveGroup,pActiveGroup->pItems,szPathField,szDirField);
  2762. SendDlgItemMessage(hwnd, IDD_COMMAND, EM_LIMITTEXT, MAXITEMPATHLEN, 0L);
  2763. SetDlgItemText(hwnd, IDD_COMMAND, szPathField);
  2764. SendDlgItemMessage(hwnd, IDD_DIR, EM_LIMITTEXT, MAXITEMPATHLEN, 0L);
  2765. SetDlgItemText(hwnd, IDD_DIR, szDirField);
  2766. if (GroupFlag(pActiveGroup,pActiveGroup->pItems,(WORD)ID_MINIMIZE))
  2767. CheckDlgButton(hwnd, IDD_LOAD, TRUE);
  2768. SendDlgItemMessage(hwnd,IDD_HOTKEY,WM_SETHOTKEY,
  2769. (WPARAM)GroupFlag(pActiveGroup,pActiveGroup->pItems,(WORD)ID_HOTKEY),
  2770. 0L);
  2771. GetCurrentIcon(); // use szIconPath from above
  2772. GlobalUnlock(pActiveGroup->hGroup);
  2773. UnlockGroup(pActiveGroup->hwnd);
  2774. SendDlgItemMessage(hwnd, IDD_CURICON, STM_SETICON, (WPARAM)hDlgIcon, 0L);
  2775. if (pActiveGroup->fRO || dwEditLevel >= 4) {
  2776. /* if readonly, we can only view... */
  2777. EnableWindow(GetDlgItem(hwnd,IDOK), FALSE);
  2778. EnableWindow(GetDlgItem(hwnd,IDD_ICON), FALSE);
  2779. EnableWindow(GetDlgItem(hwnd,IDD_HOTKEY), FALSE);
  2780. EnableWindow(GetDlgItem(hwnd,IDD_NAME), FALSE);
  2781. EnableWindow(GetDlgItem(hwnd,IDD_DIR), FALSE);
  2782. EnableWindow(GetDlgItem(hwnd,IDD_LOAD), FALSE);
  2783. EnableWindow(GetDlgItem(hwnd,IDD_NEWVDM), FALSE);
  2784. EnableWindow(GetDlgItem(hwnd,IDD_COMMAND), FALSE);
  2785. EnableWindow(GetDlgItem(hwnd,IDD_BROWSE), FALSE);
  2786. }
  2787. else if (dwEditLevel == 3) {
  2788. EnableWindow(GetDlgItem(hwnd,IDD_COMMAND), FALSE);
  2789. EnableWindow(GetDlgItem(hwnd,IDD_BROWSE), FALSE);
  2790. }
  2791. //
  2792. // Set the inital state for the thread which checks the binary
  2793. // type.
  2794. //
  2795. //
  2796. // Query if the binary type checking is enabled.
  2797. //
  2798. cbData = sizeof(dwBinaryInfo);
  2799. if (RegQueryValueEx(hkeyPMSettings, szCheckBinaryType, 0, &dwDataType,
  2800. (LPBYTE)&dwBinaryInfo, &cbData) == ERROR_SUCCESS) {
  2801. bCheckBinaryType = (BOOL) dwBinaryInfo;
  2802. } else {
  2803. bCheckBinaryType = BINARY_TYPE_DEFAULT;
  2804. }
  2805. //
  2806. // Query the binary type checking timeout value.
  2807. //
  2808. cbData = sizeof(dwBinaryInfo);
  2809. if (RegQueryValueEx(hkeyPMSettings, szCheckBinaryTimeout, 0, &dwDataType,
  2810. (LPBYTE)&dwBinaryInfo, &cbData) == ERROR_SUCCESS) {
  2811. uiCheckBinaryTimeout = (UINT) dwBinaryInfo;
  2812. } else {
  2813. uiCheckBinaryTimeout = BINARY_TIMEOUT_DEFAULT;
  2814. }
  2815. //
  2816. // Create the worker thread, and the signal event. If appropriate.
  2817. //
  2818. if (bCheckBinaryType) {
  2819. hCheckBinaryEvent = CreateEvent (NULL, FALSE, FALSE,
  2820. CHECK_BINARY_EVENT_NAME);
  2821. hThread = CreateThread (NULL, 0,
  2822. (LPTHREAD_START_ROUTINE) CheckBinaryThread,
  2823. (LPVOID) hwnd, 0, &dwThreadID);
  2824. bCheckBinaryDirtyFlag = FALSE;
  2825. }
  2826. if (!hCheckBinaryEvent || !hThread || !bCheckBinaryType) {
  2827. //
  2828. // If this statement is true, either we failed to create
  2829. // the event, the thread, or binary type checking is disabled.
  2830. // In this case, enable the separate memory checkbox, and let
  2831. // the user decide on his own.
  2832. //
  2833. CheckDlgButton(hwnd, IDD_NEWVDM, 0);
  2834. EnableWindow(GetDlgItem(hwnd,IDD_NEWVDM), TRUE);
  2835. //
  2836. // Clean up either item that succeeded
  2837. //
  2838. if (hCheckBinaryEvent) {
  2839. CloseHandle (hCheckBinaryEvent);
  2840. }
  2841. if (hThread) {
  2842. TerminateThread (hThread, 0);
  2843. }
  2844. //
  2845. // Setting this variable to NULL will prevent the second
  2846. // thread from trying to check the binary type.
  2847. //
  2848. hCheckBinaryEvent = NULL;
  2849. }
  2850. break;
  2851. case WM_TIMER:
  2852. if (hCheckBinaryEvent && bCheckBinaryDirtyFlag) {
  2853. bCheckBinaryDirtyFlag = FALSE;
  2854. SetEvent (hCheckBinaryEvent);
  2855. }
  2856. break;
  2857. case WM_COMMAND:
  2858. {
  2859. switch(GET_WM_COMMAND_ID(wParam, lParam)) {
  2860. case IDD_HELP:
  2861. goto DoHelp;
  2862. case IDD_COMMAND:
  2863. {
  2864. if (GET_WM_COMMAND_CMD(wParam, lParam) != EN_UPDATE)
  2865. break;
  2866. if (bCheckBinaryType) {
  2867. bCheckBinaryDirtyFlag = TRUE;
  2868. SetTimer (hwnd, CHECK_BINARY_ID, uiCheckBinaryTimeout, NULL);
  2869. }
  2870. bDoit = (GetDlgItemText(hwnd, IDD_COMMAND, szPathField, MAXITEMPATHLEN+1) > 0);
  2871. EnableWindow(GetDlgItem(hwnd, IDOK), bDoit);
  2872. if ( (hIcon = GetDlgItem(hwnd, IDD_ICON)) ) {
  2873. EnableWindow(hIcon, bDoit);
  2874. }
  2875. break;
  2876. }
  2877. case IDD_BROWSE:
  2878. EditBrowseOK(hwnd);
  2879. break;
  2880. case IDD_ICON:
  2881. {
  2882. LPITEMDEF lpid;
  2883. if (!GetDlgItemText(hwnd, IDD_COMMAND, szPathField, MAXITEMPATHLEN+1))
  2884. break;
  2885. //#ifdef JAPAN
  2886. // if (CheckPortName(hwnd,szPathField))
  2887. // break;
  2888. //#endif
  2889. GetDlgItemText(hwnd, IDD_DIR, szDirField, MAXITEMPATHLEN+1);
  2890. /* Expand env variables. */
  2891. DoEnvironmentSubst(szPathField, MAXITEMPATHLEN+1)
  2892. && DoEnvironmentSubst(szDirField, MAXITEMPATHLEN+1);
  2893. /* Get a full path to the icon. */
  2894. StripArgs(szPathField);
  2895. SetCurrentDirectory(szOriginalDirectory);
  2896. FindExecutable(szPathField, szDirField, szTempField);
  2897. SetCurrentDirectory(szWindowsDirectory);
  2898. /*
  2899. * If the icon path hasn't been explicitly set then
  2900. * use a default one.
  2901. */
  2902. if (!fNewIcon) {
  2903. /* Has the items path been changed? */
  2904. if (lstrcmpi(szNameField, szTempField)) {
  2905. /* Yup, it's changed, discard the old Icon Path. */
  2906. lstrcpy(szIconPath, szTempField);
  2907. iDlgIconId = 0;
  2908. iDlgIconIndex = 0;
  2909. }
  2910. else {
  2911. /* The path hasn't changed so use the old icon path. */
  2912. lpid = LockItem(pActiveGroup,pActiveGroup->pItems);
  2913. // BUG BUG! should have LockItem unlock the group
  2914. // before returning. JohanneC 7/5/91
  2915. UnlockGroup(pActiveGroup->hwnd);
  2916. if (lpid == 0L)
  2917. goto EditDlgExit;
  2918. lpgd = LockGroup(pActiveGroup->hwnd);
  2919. lstrcpy(szIconPath, (LPTSTR) PTR(lpgd, lpid->pIconPath));
  2920. UnlockGroup(pActiveGroup->hwnd);
  2921. }
  2922. }
  2923. /* Check if we have a default icon. */
  2924. if (!*szIconPath) {
  2925. /* Invalid path, use the executable's path. */
  2926. lstrcpy(szIconPath, szTempField);
  2927. }
  2928. if (fNewIcon = MyDialogBox(ICONDLG, hwnd, IconDlgProc)) {
  2929. // Set default button to OK.
  2930. PostMessage(hwnd, WM_NEXTDLGCTL, (WPARAM)GetDlgItem(hwnd, IDOK), TRUE);
  2931. SendDlgItemMessage(hwnd, IDD_CURICON, STM_SETICON, (WPARAM)hDlgIcon, 0L);
  2932. if (hIconGlobal) {
  2933. DestroyIcon(hIconGlobal);
  2934. hIconGlobal = NULL;
  2935. }
  2936. }
  2937. else {
  2938. /* They hit cancel, get the old path back. */
  2939. lpid = LockItem(pActiveGroup,pActiveGroup->pItems);
  2940. // BUG BUG! should have LockItem unlock the group
  2941. // before returning. JohanneC 7/5/91
  2942. UnlockGroup(pActiveGroup->hwnd);
  2943. if (lpid == 0L)
  2944. goto EditDlgExit;
  2945. lpgd = LockGroup(pActiveGroup->hwnd);
  2946. lstrcpy(szIconPath, (LPTSTR) PTR(lpgd, lpid->pIconPath));
  2947. UnlockGroup(pActiveGroup->hwnd);
  2948. }
  2949. break;
  2950. }
  2951. case IDOK:
  2952. {
  2953. RECT rc;
  2954. WORD hk;
  2955. BOOL bARTmp; //AutoArrangeFlag
  2956. BOOL fNewItem = FALSE;
  2957. DWORD dwRet;
  2958. hk = (WORD) SendDlgItemMessage(hwnd,IDD_HOTKEY, WM_GETHOTKEY,0,0L);
  2959. if (!CheckHotKeyInUse(hk, FALSE))
  2960. break;
  2961. /* Get the non-parm part of the new command line. */
  2962. GetDlgItemText(hwnd, IDD_COMMAND, szPathField, MAXITEMPATHLEN+1);
  2963. //#ifdef JAPAN
  2964. // if (CheckPortName(hwnd,szPathField))
  2965. // break;
  2966. //#endif
  2967. GetDlgItemText(hwnd, IDD_DIR, szDirField, MAXITEMPATHLEN+1);
  2968. /* Expand env variables. */
  2969. DoEnvironmentSubst(szPathField, MAXITEMPATHLEN+1)
  2970. && DoEnvironmentSubst(szDirField, MAXITEMPATHLEN+1);
  2971. /* Remove arguments before validating path. */
  2972. StripArgs(szPathField);
  2973. dwRet = ValidatePath(hwnd, szPathField, szDirField, szTempField);
  2974. if (dwRet == PATH_INVALID) {
  2975. break;
  2976. }
  2977. else if (dwRet == PATH_INVALID_OK) {
  2978. dwFlags |= CI_NO_ASSOCIATION;
  2979. }
  2980. if (bCheckBinaryType) {
  2981. //
  2982. // Setting this variable to false, and signaling the event
  2983. // will cause the binary checking thread to terminate.
  2984. //
  2985. bCheckBinaryType = FALSE;
  2986. SetEvent (hCheckBinaryEvent);
  2987. KillTimer (hwnd, CHECK_BINARY_ID);
  2988. }
  2989. EndDialog(hwnd, TRUE);
  2990. /*
  2991. * If the item refers to a different exe then we need
  2992. * to update a few things.
  2993. */
  2994. if (lstrcmpi(szNameField, szTempField)) {
  2995. /* Things have changed. */
  2996. if (!fNewIcon) {
  2997. /*
  2998. * The icon hasn't been expicitely set.
  2999. * So use the new exe path for
  3000. * the icon.
  3001. */
  3002. // lstrcpy(szIconPath, szPathField);
  3003. szIconPath[0] = TEXT('\0'); /* reset icon path */
  3004. iDlgIconId = 0;
  3005. iDlgIconIndex = 0;
  3006. }
  3007. fNewItem = TRUE;
  3008. /* Check if the new thing is a DOS app. */
  3009. HandleDosApps(szTempField);
  3010. }
  3011. else {
  3012. /* test if icon has changed. If not, reset iconpath.*/
  3013. if (!fNewIcon) {
  3014. lpgd = LockGroup(pActiveGroup->hwnd);
  3015. lpid = LockItem(pActiveGroup,pActiveGroup->pItems);
  3016. lstrcpy(szIconPath, (LPTSTR) PTR(lpgd, lpid->pIconPath));
  3017. // LockItem locks the group, must unlock
  3018. // after returning. JohanneC
  3019. UnlockGroup(pActiveGroup->hwnd);
  3020. UnlockGroup(pActiveGroup->hwnd);
  3021. }
  3022. }
  3023. CopyRect(&rc, &pActiveGroup->pItems->rcIcon);
  3024. /* Re-get the new command line. */
  3025. GetDlgItemText(hwnd, IDD_COMMAND, szPathField, MAXITEMPATHLEN+1);
  3026. /* Use unexpanded path for the item info. */
  3027. if (!GetDlgItemText(hwnd, IDD_DIR, szDirField, MAXITEMPATHLEN+1)) {
  3028. szDirField[0] = TEXT('\0');
  3029. } else {
  3030. LPTSTR lpEnd;
  3031. TCHAR chT;
  3032. // Remove trailing spaces (inside of quote if applicable)
  3033. lpEnd = szDirField + lstrlen (szDirField) - 1;
  3034. chT = *lpEnd;
  3035. if ( (chT == TEXT('\"')) || (chT == TEXT(' ')) ) {
  3036. // MarkTa fix for spaces at the end of a filename
  3037. // Remove the spaces by moving the last character forward.
  3038. while (*(lpEnd-1) == TEXT(' '))
  3039. lpEnd--;
  3040. *lpEnd = chT;
  3041. *(lpEnd+1) = TEXT ('\0');
  3042. // In case the character we saved was a space, we can
  3043. // NULL terminate it because now we know the next character
  3044. // to the left is valid, and the character to the right is
  3045. // already NULL.
  3046. if (*lpEnd == TEXT(' '))
  3047. *lpEnd = TEXT('\0');
  3048. }
  3049. }
  3050. if (!InQuotes(szDirField)) {
  3051. //
  3052. // if szDirField needs quotes and the work dir is too
  3053. // long than we need to truncate it.
  3054. //
  3055. if (lstrlen(szDirField) >= MAXITEMPATHLEN-2) {
  3056. TCHAR chT;
  3057. chT = szDirField[MAXITEMPATHLEN-2];
  3058. szDirField[MAXITEMPATHLEN-2] = 0;
  3059. CheckEscapes(szDirField, MAXITEMPATHLEN+1);
  3060. if (*szDirField != TEXT('"')) {
  3061. szDirField[MAXITEMPATHLEN-2] = chT;
  3062. }
  3063. }
  3064. else {
  3065. CheckEscapes(szDirField, MAXITEMPATHLEN+1);
  3066. }
  3067. }
  3068. /* Check if the Desc line has been filled. */
  3069. if (!GetDlgItemText(hwnd, IDD_NAME, szNameField, MAXITEMNAMELEN+1)) {
  3070. BuildDescription(szNameField, szPathField);
  3071. SetDlgItemText(hwnd, IDD_NAME, szNameField);
  3072. }
  3073. /*
  3074. * Stop ARing for a mo because we're going to do a
  3075. * delete and the an add and there's no point in doing
  3076. * the auto arrange stuff twice.
  3077. */
  3078. bARTmp = bAutoArrange;
  3079. bAutoArrange = FALSE;
  3080. DeleteItem(pActiveGroup,pActiveGroup->pItems);
  3081. bAutoArrange = bARTmp;
  3082. if (fNewItem || lstrcmpi(szDescription, szNameField)) {
  3083. dwFlags |= CI_SET_DOS_FULLSCRN;
  3084. }
  3085. if (IsWindowEnabled(GetDlgItem(hwnd, IDD_NEWVDM)) &&
  3086. IsDlgButtonChecked(hwnd, IDD_NEWVDM)) {
  3087. dwFlags |= CI_SEPARATE_VDM;
  3088. }
  3089. CreateNewItem(pActiveGroup->hwnd,
  3090. szNameField,
  3091. szPathField,
  3092. szIconPath,
  3093. szDirField,
  3094. hk,
  3095. (BOOL)IsDlgButtonChecked(hwnd, IDD_LOAD),
  3096. (WORD)iDlgIconId,
  3097. (WORD)iDlgIconIndex,
  3098. hDlgIcon,
  3099. (LPPOINT)&rc.left,
  3100. dwFlags);
  3101. GetRidOfIcon();
  3102. pActiveGroup = NULL;
  3103. break;
  3104. }
  3105. case IDCANCEL:
  3106. EditDlgExit:
  3107. if (bCheckBinaryType) {
  3108. //
  3109. // Setting this variable to false, and signaling the event
  3110. // will cause the binary checking thread to terminate.
  3111. //
  3112. bCheckBinaryType = FALSE;
  3113. SetEvent (hCheckBinaryEvent);
  3114. KillTimer (hwnd, CHECK_BINARY_ID);
  3115. }
  3116. pActiveGroup = NULL;
  3117. EndDialog(hwnd, FALSE);
  3118. GetRidOfIcon();
  3119. break;
  3120. default:
  3121. return(FALSE);
  3122. }
  3123. break;
  3124. }
  3125. default:
  3126. if (uiMsg == uiHelpMessage || uiMsg == uiBrowseMessage) {
  3127. DoHelp:
  3128. PMHelp(hwnd);
  3129. return TRUE;
  3130. } else
  3131. return FALSE;
  3132. }
  3133. UNREFERENCED_PARAMETER(lParam);
  3134. return(TRUE);
  3135. }
  3136. /*** EditGroupDlgProc -- Dialog Procedure
  3137. *
  3138. *
  3139. *
  3140. * INT_PTR APIENTRY EditGroupDlgProc(HWND hwnd, UINT uiMsg, WPARAM wParam, LPARAM lParam)
  3141. *
  3142. * ENTRY - HWND hwnd - handle to dialog box.
  3143. * UINT uiMsg - message to be acted upon.
  3144. * WPARAM wParam - value specific to uiMsg.
  3145. * LPARAM lParam - value specific to uiMsg.
  3146. *
  3147. * EXIT - True if success, False if not.
  3148. * SYNOPSIS - Dialog box message processing function.
  3149. *
  3150. * WARNINGS -
  3151. * EFFECTS -
  3152. *
  3153. */
  3154. INT_PTR APIENTRY EditGroupDlgProc(HWND hwnd, UINT uiMsg, WPARAM wParam, LPARAM lParam)
  3155. {
  3156. LPGROUPDEF lpgd;
  3157. static TCHAR szGroupName[MAXGROUPNAMELEN + 1];
  3158. switch (uiMsg) {
  3159. case WM_INITDIALOG:
  3160. pActiveGroup = pCurrentGroup;
  3161. lpgd = LockGroup(pActiveGroup->hwnd);
  3162. if (lpgd == 0L) {
  3163. EndDialog(hwnd, FALSE);
  3164. break;
  3165. }
  3166. if (pActiveGroup->fCommon) {
  3167. TCHAR szCommonGroupTitle[64];
  3168. if (LoadString(hAppInstance, IDS_COMMONGROUPPROP,
  3169. szCommonGroupTitle, CharSizeOf(szCommonGroupTitle))) {
  3170. SetWindowText(hwnd, szCommonGroupTitle);
  3171. }
  3172. }
  3173. lstrcpy(szGroupName, (LPTSTR) PTR(lpgd, lpgd->pName));
  3174. SetDlgItemText(hwnd, IDD_NAME, (LPTSTR) PTR(lpgd, lpgd->pName));
  3175. UnlockGroup(pActiveGroup->hwnd);
  3176. SendDlgItemMessage(hwnd, IDD_NAME, EM_LIMITTEXT, MAXGROUPNAMELEN, 0L);
  3177. if (pActiveGroup->fRO || dwEditLevel >= 1) {
  3178. EnableWindow(GetDlgItem(hwnd,IDOK), FALSE);
  3179. EnableWindow(GetDlgItem(hwnd,IDD_NAME), FALSE);
  3180. }
  3181. break;
  3182. case WM_COMMAND:
  3183. switch(GET_WM_COMMAND_ID(wParam, lParam)) {
  3184. case IDD_HELP:
  3185. goto DoHelp;
  3186. case IDOK:
  3187. {
  3188. INT err = 0;
  3189. #if 0
  3190. HKEY hkey;
  3191. HKEY hkeyGroups;
  3192. TCHAR szKeyName[MAXGROUPNAMELEN + 1];
  3193. PSECURITY_ATTRIBUTES pSecAttr;
  3194. if (!hkeyProgramGroups || !hkeyPMGroups) {
  3195. err = TRUE;
  3196. goto Exit;
  3197. }
  3198. #endif
  3199. GetDlgItemText(hwnd, IDD_NAME, szNameField, MAXITEMNAMELEN+1);
  3200. /* maybe should strip leading and trailing blanks? */
  3201. //
  3202. // If all spaces or null string do not change it, but if WIn3.1 does.
  3203. //
  3204. if (lstrcmp(szGroupName, szNameField)) {
  3205. ChangeGroupTitle(pActiveGroup->hwnd, szNameField, pActiveGroup->fCommon);
  3206. }
  3207. #if 0
  3208. //
  3209. // stop handling of Program Groups key changes.
  3210. //
  3211. bHandleProgramGroupsEvent = FALSE;
  3212. //
  3213. // Determine if we're about to change the name of Personal
  3214. // group and a Common group.
  3215. //
  3216. if (pActiveGroup->fCommon) {
  3217. hkeyGroups = hkeyCommonGroups;
  3218. pSecAttr = pAdminSecAttr;
  3219. }
  3220. else {
  3221. hkeyGroups = hkeyProgramGroups;
  3222. pSecAttr = pSecurityAttributes;
  3223. }
  3224. //
  3225. // If the group name contains backslashes (\) remove them
  3226. // from the key name. Can not have key names with backslash
  3227. // in the registry.
  3228. //
  3229. lstrcpy(szKeyName, szNameField);
  3230. RemoveBackslashFromKeyName(szKeyName);
  3231. /* create a new key, and delete the old key */
  3232. if (err = RegCreateKeyEx(hkeyGroups, szKeyName, 0, 0, 0,
  3233. DELETE | KEY_SET_VALUE | KEY_QUERY_VALUE | KEY_NOTIFY,
  3234. pSecAttr, &hkey, NULL)) {
  3235. goto Exit;
  3236. }
  3237. lpgd = (LPGROUPDEF)GlobalLock(pActiveGroup->hGroup);
  3238. if (err = RegSetValueEx(hkey, NULL, 0, REG_BINARY, (LPTSTR)lpgd,
  3239. SizeofGroup(lpgd))) {
  3240. RegCloseKey(hkey);
  3241. goto Exit;
  3242. }
  3243. RegDeleteKey(hkeyGroups, pActiveGroup->lpKey);
  3244. //
  3245. // Now that it all worked, do the actually name change:
  3246. // Change the group window title and the group key name.
  3247. //
  3248. ChangeGroupTitle(pActiveGroup->hwnd, szNameField, pActiveGroup->fCommon);
  3249. LocalFree((HANDLE)pActiveGroup->lpKey);
  3250. pActiveGroup->lpKey = (LPTSTR)LocalAlloc(LPTR, sizeof(TCHAR)*(lstrlen(szKeyName) + 1));
  3251. lstrcpy(pActiveGroup->lpKey, szKeyName);
  3252. if (bSaveSettings) {
  3253. RegFlushKey(hkey);
  3254. }
  3255. RegCloseKey(hkey);
  3256. if (!pActiveGroup->fCommon) {
  3257. WriteGroupsSection();
  3258. }
  3259. }
  3260. Exit:
  3261. //
  3262. // reset handling of Program Groups key changes.
  3263. //
  3264. ResetProgramGroupsEvent(pActiveGroup->fCommon);
  3265. bHandleProgramGroupsEvent = TRUE;
  3266. if (err) {
  3267. MyMessageBox(hwnd,IDS_CANTRENAMETITLE,
  3268. IDS_CANTRENAMEMSG,NULL, MB_OK|MB_ICONEXCLAMATION);
  3269. }
  3270. GlobalUnlock(pActiveGroup->hGroup);
  3271. #endif
  3272. pActiveGroup = NULL;
  3273. EndDialog(hwnd, TRUE);
  3274. break;
  3275. }
  3276. case IDCANCEL:
  3277. pActiveGroup = NULL;
  3278. EndDialog(hwnd, FALSE);
  3279. break;
  3280. default:
  3281. return(FALSE);
  3282. }
  3283. break;
  3284. default:
  3285. if (uiMsg == uiHelpMessage) {
  3286. DoHelp:
  3287. PMHelp(hwnd);
  3288. return TRUE;
  3289. } else
  3290. return FALSE;
  3291. }
  3292. UNREFERENCED_PARAMETER(lParam);
  3293. return(TRUE);
  3294. }
  3295. /******************************************************************************
  3296. UpdateGroupsDlgProc
  3297. 10-18-93 Created by Johannec
  3298. ******************************************************************************/
  3299. INT_PTR APIENTRY
  3300. UpdateGroupsDlgProc(
  3301. HWND hDlg,
  3302. UINT message,
  3303. WPARAM wParam,
  3304. LPARAM lParam
  3305. )
  3306. {
  3307. switch (message) {
  3308. case WM_INITDIALOG:
  3309. //
  3310. // Position ourselves
  3311. //
  3312. CentreWindow(hDlg);
  3313. return(TRUE);
  3314. case WM_COMMAND:
  3315. switch (LOWORD(wParam)) {
  3316. case IDOK:
  3317. // fall through...
  3318. case IDCANCEL:
  3319. EndDialog(hDlg, LOWORD(wParam) == IDOK);
  3320. break;
  3321. case IDD_HELP:
  3322. goto DoHelp;
  3323. break;
  3324. }
  3325. break;
  3326. default:
  3327. if (message == uiHelpMessage)
  3328. DoHelp:
  3329. {
  3330. DWORD dwSave = dwContext;
  3331. dwContext = IDH_UPDATEGRPDLG;
  3332. PMHelp(hDlg);
  3333. dwContext = dwSave;
  3334. return TRUE;
  3335. } else
  3336. return FALSE;
  3337. }
  3338. // We didn't process the message
  3339. return(FALSE);
  3340. }
  3341. //#ifdef JAPAN
  3342. /******************************************************************************
  3343. CheckPortName(HWND,LPTSTR)
  3344. This function check filename of path is reserveed as device name.
  3345. 1993/1/18 by yutakas
  3346. ******************************************************************************/
  3347. //BOOL CheckPortName(HWND hDlg, LPTSTR lpszPath)
  3348. //{
  3349. // LPTSTR lpT;
  3350. //
  3351. // lpT = lpszPath + lstrlen(lpszPath);
  3352. // while (lpT != lpszPath)
  3353. // {
  3354. // lpT = CharPrev(lpszPath,lpT);
  3355. // }
  3356. //
  3357. // if (PortName(lpT))
  3358. // {
  3359. // MyMessageBox(hDlg, IDS_BADPORTPATHTITLE, IDS_BADPORTPATHMSG, lpszPath,
  3360. // MB_OK | MB_ICONEXCLAMATION);
  3361. // return TRUE;
  3362. // }
  3363. //
  3364. // return FALSE;
  3365. //
  3366. //}
  3367. //
  3368. //BOOL PortName(LPTSTR lpszFileName)
  3369. //{
  3370. //#define PORTARRAY 22
  3371. // static TCHAR *szPorts[PORTARRAY] = {TEXT("LPT1"), TEXT("LPT2"), TEXT("LPT3"), TEXT("LPT4"), TEXT("LPT5"),
  3372. // TEXT("LPT6"), TEXT("LPT7"), TEXT("LPT8"), TEXT("LPT9"),
  3373. // TEXT("COM1"), TEXT("COM2"), TEXT("COM3"), TEXT("COM4"), TEXT("COM5"),
  3374. // TEXT("COM6"), TEXT("COM7"), TEXT("COM8"), TEXT("COM9"),
  3375. // TEXT("NUL"), TEXT("PRN"), TEXT("CON"), TEXT("AUX")};
  3376. // short i;
  3377. // TCHAR cSave;
  3378. //
  3379. // cSave = *(lpszFileName + 4);
  3380. // if (cSave == TEXT('.'))
  3381. // *(lpszFileName + 4) = TEXT('\0');
  3382. // for (i = 0; i < PORTARRAY; i++) {
  3383. // if (!lstrcmpi(szPorts[i], lpszFileName))
  3384. // break;
  3385. // }
  3386. // *(lpszFileName + 4) = cSave;
  3387. // return(i != PORTARRAY);
  3388. //}
  3389. //#endif