Advertisement
Guest User

Untitled

a guest
Apr 26th, 2019
651
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 37.23 KB | None | 0 0
  1. #include "winfile.h"
  2. #include "lfn.h"
  3. #include <commctrl.h>
  4. #include <stdlib.h>
  5.  
  6. LPTSTR CurDirCache[26];
  7.  
  8. #define MAXHISTORY 32
  9. DWORD historyCur = 0;
  10. typedef struct HistoryDir
  11. {
  12. HWND hwnd;
  13. TCHAR szDir[MAXPATHLEN];
  14. } HistoryDir;
  15. HistoryDir rghistoryDir[MAXHISTORY];
  16.  
  17. VOID
  18. SaveHistoryDir(HWND hwnd, LPWSTR szDir)
  19. {
  20. if (rghistoryDir[historyCur].hwnd == hwnd && lstrcmpi(rghistoryDir[historyCur].szDir, szDir) == 0)
  21. return;
  22.  
  23. historyCur = (historyCur + 1) % MAXHISTORY;
  24.  
  25. rghistoryDir[historyCur].hwnd = hwnd;
  26. lstrcpy(rghistoryDir[historyCur].szDir, szDir);
  27.  
  28. // always leave one NULL entry after current
  29. DWORD historyT = (historyCur + 1) % MAXHISTORY;
  30. rghistoryDir[historyT].hwnd = NULL;
  31. rghistoryDir[historyT].szDir[0] = '\0';
  32. }
  33.  
  34. BOOL
  35. GetPrevHistoryDir(BOOL forward, HWND *phwnd, LPWSTR szDir)
  36. {
  37. DWORD historyNext = (historyCur + 1) % MAXHISTORY;
  38. DWORD historyPrev = (historyCur == 0 ? MAXHISTORY : historyCur )- 1;
  39. DWORD historyT = forward ? historyNext : historyPrev;
  40.  
  41. if (rghistoryDir[historyT].hwnd == NULL)
  42. return FALSE;
  43.  
  44. historyCur = historyT;
  45.  
  46. *phwnd = rghistoryDir[historyCur].hwnd;
  47. lstrcpy(szDir, rghistoryDir[historyCur].szDir);
  48. return TRUE;
  49. }
  50.  
  51. LPWSTR
  52. pszNextComponent(
  53. LPWSTR p)
  54. {
  55. BOOL bInQuotes = FALSE;
  56.  
  57. while (*p == L' ' || *p == L'\t')
  58. p++;
  59.  
  60. //
  61. // Skip executable name
  62. //
  63. while (*p) {
  64.  
  65. if ((*p == L' ' || *p == L'\t') && !bInQuotes)
  66. break;
  67.  
  68. if (*p == L'\"')
  69. bInQuotes = !bInQuotes;
  70.  
  71. p++;
  72. }
  73.  
  74. if (*p) {
  75. *p++ = CHAR_NULL;
  76.  
  77. while (*p == L' ' || *p == L'\t')
  78. p++;
  79. }
  80.  
  81. return p;
  82. }
  83.  
  84.  
  85. // Set the status bar text for a given pane
  86.  
  87. VOID CDECL
  88. SetStatusText(int nPane, UINT nFlags, LPCTSTR szFormat, ...)
  89. {
  90. TCHAR szTemp[120+MAXPATHLEN];
  91. TCHAR szTempFormat[120+MAXPATHLEN];
  92.  
  93. va_list vaArgs;
  94.  
  95. if (!hwndStatus)
  96. return;
  97.  
  98. if (nFlags & SST_RESOURCE) {
  99. if (!LoadString(hAppInstance, (DWORD) (LONG_PTR) szFormat,
  100. szTempFormat, COUNTOF(szTempFormat)))
  101.  
  102. return;
  103.  
  104. szFormat = szTempFormat;
  105. }
  106.  
  107. if (nFlags & SST_FORMAT) {
  108.  
  109. va_start(vaArgs, szFormat);
  110. wvsprintf(szTemp, szFormat, vaArgs);
  111. va_end(vaArgs);
  112.  
  113. szFormat = szTemp;
  114. }
  115.  
  116. SendMessage(hwndStatus, SB_SETTEXT, nPane, (LPARAM)szFormat);
  117. }
  118.  
  119.  
  120. // drive zero based drive number (0 = A, 1 = B)
  121. // returns:
  122. // TRUE we have it saved pszPath gets path
  123. // FALSE we don't have it saved
  124.  
  125. BOOL
  126. GetSavedDirectory(DRIVE drive, LPTSTR pszPath)
  127. {
  128. if (CurDirCache[drive]) {
  129. lstrcpy(pszPath, CurDirCache[drive]);
  130. return TRUE;
  131. } else
  132. return FALSE;
  133. }
  134.  
  135. VOID
  136. SaveDirectory(LPTSTR pszPath)
  137. {
  138. DRIVE drive;
  139.  
  140. drive = DRIVEID(pszPath);
  141.  
  142. if (CurDirCache[drive])
  143. LocalFree((HANDLE)CurDirCache[drive]);
  144.  
  145. CurDirCache[drive] = (LPTSTR)LocalAlloc(LPTR, ByteCountOf(lstrlen(pszPath)+1));
  146.  
  147. if (CurDirCache[drive])
  148. lstrcpy(CurDirCache[drive], pszPath);
  149. }
  150.  
  151. /*
  152. * GetSelectedDrive() -
  153. *
  154. * Get the selected drive from the currently active window
  155. *
  156. * should be in wfutil.c
  157. *
  158. * Precond: Active MDI window MUST be a drive window
  159. * (search windows NOT allowed)
  160. */
  161.  
  162. INT
  163. GetSelectedDrive()
  164. {
  165. HWND hwnd;
  166.  
  167. hwnd = (HWND)SendMessage(hwndMDIClient,WM_MDIGETACTIVE,0,0L);
  168. return (INT)SendMessage(hwnd,FS_GETDRIVE,0,0L) - (INT)CHAR_A;
  169. }
  170.  
  171. /*
  172. * GetSelectedDirectory() -
  173. *
  174. * Gets the directory selected for the drive. uses the windows
  175. * z-order to give precedence to windows higher in the order.
  176. *
  177. * works like GetCurrentDirectory() except it looks through
  178. * the window list for directories first (and returns ANSI)
  179. *
  180. * returns:
  181. * lpDir ANSI string of current dir
  182. * NOTE: when drive != 0, string will be empty for an invalid drive.
  183. */
  184.  
  185. VOID
  186. GetSelectedDirectory(DRIVE drive, LPTSTR pszDir)
  187. {
  188. HWND hwnd;
  189. DRIVE driveT;
  190.  
  191. if (drive) {
  192. for (hwnd = GetWindow(hwndMDIClient,GW_CHILD);
  193. hwnd;
  194. hwnd = GetWindow(hwnd,GW_HWNDNEXT)) {
  195.  
  196. driveT = (DRIVE)SendMessage(hwnd,FS_GETDRIVE,0,0L);
  197. if (drive == (DRIVE)(driveT - CHAR_A + 1))
  198. goto hwndfound;
  199. }
  200. if (!GetSavedDirectory(drive - 1, pszDir)) {
  201. GetDriveDirectory(drive, pszDir);
  202. }
  203. return;
  204. } else
  205. hwnd = (HWND)SendMessage(hwndMDIClient,WM_MDIGETACTIVE,0,0L);
  206.  
  207. hwndfound:
  208. SendMessage(hwnd,FS_GETDIRECTORY,MAXPATHLEN,(LPARAM)pszDir);
  209.  
  210. StripBackslash(pszDir);
  211. }
  212.  
  213.  
  214. BOOL GetDriveDirectory(INT iDrive, LPTSTR pszDir)
  215. {
  216. TCHAR drvstr[4];
  217. DWORD ret;
  218.  
  219. pszDir[0] = '\0';
  220.  
  221. if(iDrive!=0)
  222. {
  223. drvstr[0] = ('A') - 1 + iDrive;
  224. drvstr[1] = (':');
  225. drvstr[2] = ('.');
  226. drvstr[3] = ('\0');
  227. }
  228. else
  229. {
  230. drvstr[0] = ('.');
  231. drvstr[1] = ('\0');
  232. }
  233.  
  234. if (GetFileAttributes(drvstr) == INVALID_FILE_ATTRIBUTES)
  235. return FALSE;
  236.  
  237. // if (!CheckDirExists(drvstr))
  238. // return FALSE;
  239.  
  240. ret = GetFullPathName( drvstr, MAXPATHLEN, pszDir, NULL);
  241.  
  242. return ret != 0;
  243. }
  244.  
  245.  
  246. // similar to GetSelectedDirectory but for all already listed directories
  247. // doesn't change the current directory of the drives, but returns a list of them
  248. VOID
  249. GetAllDirectories(LPTSTR rgszDirs[])
  250. {
  251. HWND mpdrivehwnd[MAX_DRIVES];
  252. HWND hwnd;
  253. DRIVE driveT;
  254.  
  255. for (driveT = 0; driveT < MAX_DRIVES; driveT++)
  256. {
  257. rgszDirs[driveT] = NULL;
  258. mpdrivehwnd[driveT] = NULL;
  259. }
  260.  
  261. for (hwnd = GetWindow(hwndMDIClient,GW_CHILD); hwnd; hwnd = GetWindow(hwnd,GW_HWNDNEXT))
  262. {
  263. driveT = (DRIVE)SendMessage(hwnd,FS_GETDRIVE,0,0L) - CHAR_A;
  264. if (mpdrivehwnd[driveT] == NULL)
  265. mpdrivehwnd[driveT] = hwnd;
  266. }
  267.  
  268. for (driveT = 0; driveT < MAX_DRIVES; driveT++)
  269. {
  270. TCHAR szDir[MAXPATHLEN];
  271.  
  272. if (mpdrivehwnd[driveT] != NULL)
  273. {
  274. SendMessage(mpdrivehwnd[driveT],FS_GETDIRECTORY,MAXPATHLEN,(LPARAM)szDir);
  275.  
  276. StripBackslash(szDir);
  277. }
  278. else if (!GetSavedDirectory(driveT, szDir))
  279. szDir[0] = '\0';
  280.  
  281. if (szDir[0] != '\0')
  282. {
  283. rgszDirs[driveT] = (LPTSTR) LocalAlloc(LPTR, ByteCountOf(lstrlen(szDir)+1));
  284. lstrcpy(rgszDirs[driveT], szDir);
  285. }
  286. }
  287. }
  288.  
  289.  
  290. /////////////////////////////////////////////////////////////////////
  291. //
  292. // Name: RefreshWindow
  293. //
  294. // Synopsis: Refreshes any type of MDI Window
  295. // Return:
  296. // Assumes:
  297. // Effects:
  298. // Notes:
  299. //
  300. /////////////////////////////////////////////////////////////////////
  301.  
  302. VOID
  303. RefreshWindow(
  304. HWND hwndActive,
  305. BOOL bUpdateDriveList,
  306. BOOL bFlushCache)
  307. {
  308. HWND hwndTree, hwndDir;
  309. LPARAM lParam;
  310. TCHAR szDir[MAXPATHLEN];
  311. DRIVE drive;
  312.  
  313. //
  314. // make it optional for speed.
  315. //
  316. if (bUpdateDriveList) {
  317.  
  318. UpdateDriveList();
  319. }
  320.  
  321. //
  322. // make sure the thing is still there (floppy drive, net drive)
  323. //
  324. drive = (DRIVE)GetWindowLongPtr(hwndActive, GWL_TYPE);
  325.  
  326. if ((drive >= 0) && !CheckDrive(hwndActive, drive, FUNC_SETDRIVE))
  327. return;
  328.  
  329. //
  330. // If bFlushCache, remind ourselves to try it
  331. //
  332. if (bFlushCache)
  333. aDriveInfo[drive].bShareChkTried = FALSE;
  334.  
  335. // NOTE: similar to CreateDirWindow
  336.  
  337. //
  338. // update the dir part first so tree can steal later
  339. //
  340. if (hwndDir = HasDirWindow(hwndActive))
  341. SendMessage(hwndDir, FS_CHANGEDISPLAY, CD_PATH, 0L);
  342.  
  343. if (hwndTree = HasTreeWindow(hwndActive)) {
  344. //
  345. // remember the current directory
  346. //
  347. SendMessage(hwndActive, FS_GETDIRECTORY, COUNTOF(szDir), (LPARAM)szDir);
  348.  
  349. //
  350. // update the drives windows
  351. //
  352. SendMessage(hwndActive, FS_CHANGEDRIVES, 0, 0L);
  353.  
  354. if (IsValidDisk(DRIVEID(szDir)))
  355. lParam = (LPARAM)szDir;
  356. else
  357. lParam = 0L;
  358.  
  359. //
  360. // update the tree
  361. //
  362. SendMessage(hwndTree,
  363. TC_SETDRIVE,
  364. MAKELONG(MAKEWORD(FALSE,TRUE),TRUE),
  365. lParam);
  366. }
  367.  
  368. if (hwndActive == hwndSearch)
  369. SendMessage(hwndActive, FS_CHANGEDISPLAY, CD_PATH, 0L);
  370. }
  371.  
  372. //
  373. // Assumes there are 2 extra spaces in the array.
  374. //
  375.  
  376. VOID
  377. CheckEsc(LPTSTR szFile)
  378. {
  379. // DrivesDropObject calls w/ 2*MAXPATHLEN
  380.  
  381. TCHAR szT[2 * MAXPATHLEN];
  382.  
  383. TCHAR *p, *pT;
  384.  
  385. for (p = szFile; *p; p++) {
  386. switch (*p) {
  387. case CHAR_SPACE:
  388. case CHAR_COMMA:
  389. case CHAR_SEMICOLON:
  390. #ifdef CARETESC
  391. case CHAR_CARET:
  392. #endif
  393. case CHAR_DQUOTE:
  394. {
  395. // this path contains an annoying character
  396. lstrcpy(szT,szFile);
  397. p = szFile;
  398. *p++ = CHAR_DQUOTE;
  399. for (pT = szT; *pT; ) {
  400. #ifdef CARETESC
  401. if (*pT == CHAR_CARET || *pT == CHAR_DQUOTE)
  402. *p++ = CHAR_CARET;
  403. #endif
  404. *p++ = *pT++;
  405. }
  406. *p++ = CHAR_DQUOTE;
  407. *p = CHAR_NULL;
  408. return;
  409. }
  410. }
  411. }
  412. }
  413.  
  414.  
  415. HWND
  416. GetRealParent(HWND hwnd)
  417. {
  418. // run up the parent chain until you find a hwnd
  419. // that doesn't have WS_CHILD set
  420.  
  421. while (GetWindowLongPtr(hwnd, GWL_STYLE) & WS_CHILD)
  422. hwnd = (HWND)GetWindowLongPtr(hwnd, GWLP_HWNDPARENT);
  423.  
  424. return hwnd;
  425. }
  426.  
  427. VOID
  428. WFHelp(HWND hwnd)
  429. {
  430. if (!WinHelp(hwnd, szWinfileHelp, HELP_CONTEXT, dwContext)) {
  431. MyMessageBox(hwnd, IDS_WINFILE, IDS_WINHELPERR, MB_OK | MB_ICONEXCLAMATION | MB_SYSTEMMODAL);
  432. }
  433.  
  434. }
  435.  
  436. // atoi with decimal comma separators
  437. //
  438.  
  439. //#ifdef INLIBRARY
  440. LPTSTR
  441. AddCommasInternal(LPTSTR szBuf, DWORD dw)
  442. {
  443. TCHAR szTemp[40];
  444. LPTSTR pTemp;
  445. INT count, len;
  446. LPTSTR p;
  447. INT iCommaLen;
  448. INT i;
  449.  
  450. // if *szComma[0] == NULL, get out now
  451.  
  452. if (!szComma[0]) {
  453. wsprintf(szBuf,TEXT("%lu"),dw);
  454. return szBuf;
  455. }
  456.  
  457. len = wsprintf(szTemp, TEXT("%lu"), dw);
  458. iCommaLen = lstrlen(szComma);
  459.  
  460. pTemp = szTemp + len - 1;
  461.  
  462. // szComma size may be < 1 !
  463.  
  464. p = szBuf + len + ((len - 1) / 3)*iCommaLen;
  465.  
  466. *p-- = CHAR_NULL; // null terminate the string we are building
  467.  
  468. count = 1;
  469. while (pTemp >= szTemp) {
  470. *p-- = *pTemp--;
  471. if (count == 3) {
  472. count = 1;
  473. if (p > szBuf) {
  474. for (i=iCommaLen-1 ; i >=0 ;i--)
  475. *p-- = szComma[i];
  476. }
  477. } else
  478. count++;
  479. }
  480. return szBuf;
  481. }
  482. //#endif
  483.  
  484.  
  485. BOOL
  486. IsLastWindow()
  487. {
  488. HWND hwnd;
  489. INT count;
  490.  
  491. count = 0;
  492.  
  493. // count all non title/search windows to see if close is allowed
  494.  
  495. for (hwnd = GetWindow(hwndMDIClient, GW_CHILD); hwnd; hwnd = GetWindow(hwnd, GW_HWNDNEXT))
  496. if (!GetWindow(hwnd, GW_OWNER) && ((INT)GetWindowLongPtr(hwnd, GWL_TYPE) >= 0))
  497. count++;
  498.  
  499. return count == 1;
  500. }
  501.  
  502.  
  503.  
  504. /////////////////////////////////////////////////////////////////////
  505. //
  506. // Name: GetMDIWindowText
  507. //
  508. // Synopsis: Goofy way to store directory name
  509. // Returns number of MDI window & text w/ # stripped off
  510. //
  511. // IN hwnd MDIWindow to get from
  512. // OUT szTitle target string of title
  513. // IN size cch of szTitle
  514. //
  515. // Return: 0 = no number
  516. // >0 title number
  517. //
  518. // Assumes:
  519. //
  520. // Effects:
  521. //
  522. //
  523. // Notes:
  524. //
  525. /////////////////////////////////////////////////////////////////////
  526.  
  527. INT
  528. GetMDIWindowText(HWND hwnd, LPWSTR szTitle, INT size)
  529. {
  530. //
  531. // Need temp buffer due to filter + path
  532. //
  533. WCHAR szTemp[2 * MAXPATHLEN + 40];
  534.  
  535. LPWSTR lpLast;
  536. INT iWindowNumber;
  537.  
  538. EnterCriticalSection(&CriticalSectionPath);
  539.  
  540. InternalGetWindowText(hwnd, szTemp, COUNTOF(szTemp));
  541.  
  542. if (GetWindow(hwnd, GW_OWNER) ||
  543. GetWindowLongPtr(hwnd, GWL_TYPE) == -1L)
  544. lpLast = NULL;
  545. else {
  546. lpLast = szTemp + GetWindowLongPtr(hwnd, GWL_PATHLEN);
  547. if (lpLast == szTemp || !*lpLast)
  548. lpLast = NULL;
  549. }
  550.  
  551. LeaveCriticalSection(&CriticalSectionPath);
  552.  
  553. //
  554. // save the window #
  555. //
  556. if (lpLast) {
  557. iWindowNumber = atoi(lpLast + 1);
  558.  
  559. //
  560. // Delimit title (we just want part of the title)
  561. //
  562. *lpLast = CHAR_NULL;
  563.  
  564. } else {
  565. iWindowNumber = 0;
  566. }
  567.  
  568. //
  569. // Make sure the strcpy below doesn't blow up if COUNTOF( szTemp ) > size
  570. //
  571. if (COUNTOF(szTemp) > size)
  572. szTemp[size-1] = CHAR_NULL;
  573.  
  574. lstrcpy( szTitle, szTemp );
  575.  
  576. return iWindowNumber;
  577. }
  578.  
  579.  
  580.  
  581. /////////////////////////////////////////////////////////////////////
  582. //
  583. // Name: SetMDIWindowText
  584. //
  585. // Synopsis: Sets the titlebar of a MDI window based on the path/filter
  586. //
  587. // IN hwnd -- wnd to modify
  588. // INC szTitle -- path/filter to add (modified but restored)
  589. //
  590. // Return: VOID
  591. //
  592. //
  593. // Assumes:
  594. //
  595. // Effects: title bar of window
  596. //
  597. //
  598. // Notes: modifies szTitle but restores it.
  599. //
  600. // set the MDI window text and add a ":#" on the end if
  601. // there is another window with the same title. this is to
  602. // avoid confusion when there are multiple MDI children
  603. // with the same title. be sure to use GetMDIWindowText to
  604. // strip off the number stuff.
  605. //
  606. /////////////////////////////////////////////////////////////////////
  607.  
  608.  
  609. VOID
  610. SetMDIWindowText(
  611. HWND hwnd,
  612. LPWSTR szTitle)
  613. {
  614. WCHAR szTemp[MAXPATHLEN*2+10]; // BONK! is this big enough?
  615. WCHAR szNumber[20];
  616. HWND hwndT;
  617. INT num, max_num, cur_num;
  618. LPWSTR lpszVolShare;
  619. LPWSTR lpszVolName;
  620.  
  621. UINT cchTempLen;
  622. DRIVE drive;
  623. BOOL bNumIncrement = FALSE;
  624. BOOL bNotSame;
  625.  
  626. UINT uTitleLen;
  627. DWORD dwError;
  628.  
  629. cur_num = GetMDIWindowText(hwnd, szTemp, COUNTOF(szTemp));
  630.  
  631. bNotSame = lstrcmp(szTemp, szTitle);
  632.  
  633. max_num = 0;
  634.  
  635. for (hwndT = GetWindow(hwndMDIClient, GW_CHILD); hwndT; hwndT = GetWindow(hwndT, GW_HWNDNEXT)) {
  636.  
  637. num = GetMDIWindowText(hwndT, szTemp, COUNTOF(szTemp));
  638.  
  639. if (!lstrcmp(szTemp, szTitle)) {
  640.  
  641. if (hwndT == hwnd)
  642. continue;
  643.  
  644. if (!max_num && !num) {
  645.  
  646. DWORD Length = lstrlen(szTemp);
  647.  
  648. lstrcat(szTemp, SZ_COLONONE);
  649. // if (wTextAttribs & TA_LOWERCASE)
  650. // CharLower(szTemp);
  651.  
  652. drive = GetWindowLongPtr(hwnd, GWL_TYPE);
  653. if (drive != -1) { /* if not a search window */
  654. lstrcat(szTemp, SZ_SPACEDASHSPACE);
  655.  
  656. dwError = GetVolShare(drive, &lpszVolShare, ALTNAME_SHORT);
  657.  
  658. if (!dwError || DE_REGNAME == dwError) {
  659. cchTempLen = lstrlen(szTemp);
  660. StrNCpy(szTemp + cchTempLen, lpszVolShare,
  661. COUNTOF(szTemp) - cchTempLen - 1);
  662.  
  663. szTemp[COUNTOF(szTemp) - 1] = CHAR_NULL;
  664. }
  665. }
  666.  
  667. SetWindowText(hwndT, szTemp);
  668. max_num = 1;
  669. SetWindowLongPtr(hwndT, GWL_PATHLEN, Length);
  670. }
  671. max_num = max(max_num, num);
  672. }
  673. }
  674.  
  675.  
  676. drive = GetWindowLongPtr(hwnd, GWL_TYPE);
  677.  
  678. uTitleLen = lstrlen(szTitle);
  679.  
  680. if (max_num) {
  681.  
  682. if (bNotSame || !cur_num) {
  683. max_num++;
  684. } else {
  685. max_num = cur_num;
  686. }
  687.  
  688. wsprintf(szNumber, TEXT(":%d"), max_num);
  689. lstrcat(szTitle, szNumber);
  690. }
  691.  
  692. // if (wTextAttribs & TA_LOWERCASE)
  693. // CharLower(szTitle);
  694.  
  695. if (drive != -1) { /* if this isn't a search window */
  696. lstrcpy(szTemp, szTitle);
  697. lstrcat(szTemp, SZ_SPACEDASHSPACE);
  698.  
  699. // Must store realname in GWL_VOLNAME
  700. // But only for remote drives
  701.  
  702. lpszVolName = (LPTSTR)GetWindowLongPtr(hwnd, GWL_VOLNAME);
  703.  
  704. if (lpszVolName)
  705. LocalFree(lpszVolName);
  706.  
  707. if (GetVolShare(drive, &lpszVolShare, ALTNAME_REG) ||
  708. !IsRemoteDrive(drive)) {
  709.  
  710. //
  711. // If error or not a remote drive, then do not store this.
  712. //
  713. lpszVolName = NULL;
  714.  
  715. } else {
  716. lpszVolName = (LPTSTR) LocalAlloc(LPTR, ByteCountOf(lstrlen(lpszVolShare)+1));
  717.  
  718. if (lpszVolName) {
  719. lstrcpy(lpszVolName, lpszVolShare);
  720. }
  721. }
  722.  
  723. SetWindowLongPtr(hwnd, GWL_VOLNAME, (LONG_PTR)lpszVolName);
  724.  
  725. //
  726. // Use short name in window title
  727. //
  728. dwError = GetVolShare(drive, &lpszVolShare, ALTNAME_SHORT);
  729.  
  730. if (!dwError || DE_REGNAME == dwError) {
  731.  
  732. cchTempLen = lstrlen(szTemp);
  733. StrNCpy(szTemp + cchTempLen, lpszVolShare,
  734. COUNTOF(szTemp) - cchTempLen - 1);
  735.  
  736. szTemp[COUNTOF(szTemp) - 1] = CHAR_NULL;
  737. }
  738.  
  739. EnterCriticalSection(&CriticalSectionPath);
  740.  
  741. SetWindowLongPtr(hwnd, GWL_PATHLEN, uTitleLen);
  742. //
  743. // c:\foo\*.*:1 - [VOL LABEL]
  744. // h:\foo\*.foo - \\server\share
  745. //
  746. SetWindowText(hwnd, szTemp);
  747.  
  748. LeaveCriticalSection(&CriticalSectionPath);
  749.  
  750. } else {
  751.  
  752. SetWindowText(hwnd, szTitle);
  753. }
  754.  
  755. //
  756. // Now delimit szTitle to keep it the same
  757. //
  758. szTitle[uTitleLen] = CHAR_NULL;
  759.  
  760. SaveHistoryDir(hwnd, szTitle);
  761. }
  762.  
  763. #define ISDIGIT(c) ((c) >= TEXT('0') && (c) <= TEXT('9'))
  764.  
  765. INT
  766. atoiW(LPTSTR sz)
  767. {
  768. INT n = 0;
  769. BOOL bNeg = FALSE;
  770.  
  771. if (*sz == CHAR_DASH) {
  772. bNeg = TRUE;
  773. sz++;
  774. }
  775.  
  776. while (ISDIGIT(*sz)) {
  777. n *= 10;
  778. n += *sz - TEXT('0');
  779. sz++;
  780. }
  781. return bNeg ? -n : n;
  782. }
  783.  
  784.  
  785. //
  786. // IsCDROM() - determine if a drive is a CDROM drive
  787. //
  788. // drive drive index (0=A, 1=B, ...)
  789. //
  790. // return TRUE/FALSE
  791. //
  792. BOOL
  793. IsCDRomDrive(DRIVE drive)
  794. {
  795. if (aDriveInfo[drive].uType == DRIVE_CDROM)
  796. return(TRUE);
  797. return(FALSE);
  798. }
  799.  
  800.  
  801. #if 0
  802. // this is called for every drive at init time so it must
  803. // be sure to not trigger things like the phantom B: drive support
  804. //
  805. // drive is a zero based drive number (0 = A, 1 = B)
  806.  
  807. DWORD
  808. IsNetDrive(INT drive)
  809. {
  810. INT err;
  811.  
  812. if (IsCDRomDrive(drive)) // this is bogus... move this out
  813. return 0;
  814.  
  815. if (IsRemoteDrive(drive)) {
  816.  
  817. err = WFGetConnection(drive, NULL, TRUE, ALTNAME_REG);
  818.  
  819. if (err == WN_SUCCESS)
  820. return 1;
  821.  
  822. if (err == WN_CONNECTION_CLOSED /* || err == 111 */)
  823. return 2;
  824.  
  825. //
  826. // For now default on error to an available drive
  827. //
  828. return 1;
  829. }
  830. return 0;
  831. }
  832. #endif
  833.  
  834. BOOL
  835. IsNTFSDrive(register DRIVE drive)
  836. {
  837. U_VolInfo(drive);
  838.  
  839. //
  840. // Return false if the return value was an error condition.
  841. //
  842. if (GETRETVAL(VolInfo, drive))
  843. return FALSE;
  844.  
  845. //
  846. // See if it's an NTFS drive.
  847. //
  848. return (!lstrcmpi(aDriveInfo[drive].szFileSysName, SZ_NTFSNAME)) ?
  849. TRUE : FALSE;
  850. }
  851.  
  852.  
  853. //
  854. // NOTE: This function really says whether or not the drive is not a
  855. // FAT drive. In other words:
  856. // If it IS a FAT drive, it returns FALSE.
  857. // If it is NOT a FAT drive, it returns TRUE.
  858. //
  859. BOOL
  860. IsCasePreservedDrive(register DRIVE drive)
  861. {
  862. U_VolInfo(drive);
  863.  
  864. //
  865. // Return false if the return value was an error condition.
  866. //
  867. if (GETRETVAL(VolInfo, drive))
  868. return FALSE;
  869.  
  870. //
  871. // Can no longer check the FS_CASE_IS_PRESERVED bit to see if it's a
  872. // FAT drive (now that FAT is case preserving and stores Unicode
  873. // on disk.
  874. //
  875. // Instead, we will check the file system string to see if the drive
  876. // is FAT.
  877. //
  878. // OLD CODE:
  879. // return (aDriveInfo[drive].dwFileSystemFlags & FS_CASE_IS_PRESERVED) ?
  880. // TRUE : FALSE;
  881. //
  882. return (!lstrcmpi(aDriveInfo[drive].szFileSysName, SZ_FATNAME)) ?
  883. FALSE : TRUE;
  884. }
  885.  
  886.  
  887. BOOL
  888. IsRemovableDrive(register DRIVE drive)
  889. {
  890. return aDriveInfo[drive].uType == DRIVE_REMOVABLE;
  891. }
  892.  
  893.  
  894. BOOL
  895. IsRemoteDrive(register DRIVE drive)
  896. {
  897. return aDriveInfo[drive].uType == DRIVE_REMOTE;
  898. }
  899.  
  900.  
  901. BOOL
  902. IsRamDrive(DRIVE drive)
  903. {
  904. return aDriveInfo[drive].uType == DRIVE_RAMDISK;
  905. }
  906.  
  907.  
  908. BOOL
  909. IsValidDisk(DRIVE drive)
  910. {
  911. U_Type(drive);
  912. return ((aDriveInfo[drive].uType != DRIVE_UNKNOWN) &&
  913. (aDriveInfo[drive].uType != DRIVE_NO_ROOT_DIR));
  914. }
  915.  
  916. DWORD
  917. GetVolShare(DRIVE drive, LPTSTR* ppszVolShare, DWORD dwType)
  918. {
  919. if (IsRemoteDrive(drive)) {
  920. return WFGetConnection(drive,ppszVolShare,FALSE, dwType);
  921. } else {
  922. return GetVolumeLabel(drive, ppszVolShare, TRUE);
  923. }
  924. }
  925.  
  926.  
  927.  
  928. /*--------------------------------------------------------------------------*/
  929. /* */
  930. /* IsLFNSelected() - */
  931. /* */
  932. /*--------------------------------------------------------------------------*/
  933.  
  934. BOOL
  935. IsLFNSelected()
  936. {
  937. HWND hwndActive;
  938. BOOL fDir;
  939. LPTSTR p;
  940.  
  941. hwndActive = (HWND)SendMessage(hwndMDIClient, WM_MDIGETACTIVE, 0, 0L);
  942.  
  943. p = (LPTSTR)SendMessage(hwndActive, FS_GETSELECTION, 2, (LPARAM)&fDir);
  944. if (p) {
  945. LocalFree((HANDLE)p);
  946. }
  947.  
  948. return(fDir);
  949. }
  950.  
  951.  
  952. //--------------------------------------------------------------------------
  953. //
  954. // GetSelection() -
  955. // caller must free LPTSTR returned.
  956. //
  957. // LPTSTR must have 2 chars for checkesc safety at end
  958. //
  959. //--------------------------------------------------------------------------
  960.  
  961. LPTSTR
  962. GetSelection(INT iSelType, PBOOL pbDir)
  963. {
  964. HWND hwndActive;
  965.  
  966. hwndActive = (HWND)SendMessage(hwndMDIClient, WM_MDIGETACTIVE, 0, 0L);
  967.  
  968. return (LPTSTR)SendMessage(hwndActive,FS_GETSELECTION,
  969. (WPARAM)iSelType, (LPARAM)pbDir);
  970. }
  971.  
  972.  
  973. //
  974. // in:
  975. // pFrom pointer that is used as start of selection search.
  976. // on subsequent calls pass in the previous non NULL
  977. // return value
  978. //
  979. // out:
  980. // pTo buffer that receives the next file in the list
  981. // for non NULL return
  982. //
  983. // returns:
  984. // NULL if no more files in this list (szFile) is undefined
  985. // pointer to be passed to subsequent calls to this function
  986. // to enumerate thorough the file list
  987. //
  988.  
  989. LPTSTR
  990. GetNextFile(LPTSTR pFrom, LPTSTR pTo, INT cchMax)
  991. {
  992. INT i;
  993.  
  994. // Originally, this code tested if the first char was a double quote,
  995. // then either (1) scanned for the next space or (2) scanned for the next
  996. // quote. CMD, however, will let you put quotes anywhere.
  997. // Now, the bInQuotes boolean is used instead.
  998.  
  999. BOOL bInQuotes=FALSE;
  1000.  
  1001. if (!pFrom)
  1002. return NULL;
  1003.  
  1004. // Skip over leading spaces and commas.
  1005. while (*pFrom && (*pFrom == CHAR_SPACE || *pFrom == CHAR_COMMA))
  1006. pFrom++;
  1007.  
  1008. if (!*pFrom)
  1009. return(NULL);
  1010.  
  1011. // Find the next delimiter (space, comma (valid in bInQuotes only))
  1012.  
  1013. for (i=0; *pFrom && ((*pFrom != CHAR_SPACE && *pFrom != CHAR_COMMA) || bInQuotes);) {
  1014.  
  1015. // bQuotes flipped if encountered. ugly.
  1016. // Note: it is also TAKEN OUT!
  1017. if ( CHAR_DQUOTE == *pFrom ) {
  1018. bInQuotes = !bInQuotes;
  1019. ++pFrom;
  1020.  
  1021. if (!*pFrom)
  1022. break;
  1023.  
  1024. // Must continue, or else the space (pFrom was inc'd!) will
  1025. // be stored in the pTo string, which is FATAL!
  1026. continue;
  1027. }
  1028.  
  1029. #ifdef CARETESC
  1030. if (*pFrom == CHAR_CARET) {
  1031. ++pFrom;
  1032. if (!*pFrom)
  1033. break;
  1034. }
  1035. #endif
  1036.  
  1037. if (i < cchMax - 1) {
  1038. i++;
  1039. *pTo++ = *pFrom++;
  1040.  
  1041. // increment to kill off present file name
  1042. } else pFrom++;
  1043.  
  1044. }
  1045.  
  1046. #ifdef KEEPTRAILSPACE
  1047. #else
  1048. // Kill off trailing spaces
  1049.  
  1050. while ( CHAR_SPACE == *(--pTo) )
  1051. ;
  1052. #endif
  1053.  
  1054. *(++pTo) = CHAR_NULL;
  1055.  
  1056. return(pFrom);
  1057. }
  1058.  
  1059.  
  1060. // sets the XP current directory based on the currently active window
  1061.  
  1062. VOID
  1063. SetWindowDirectory()
  1064. {
  1065. // Actually, only needs to be MAX MDI Title = (MAXPATHLEN + few + MAX diskname)
  1066. // like "d:\aaa .. aaa\filter.here - [albertt]"
  1067. // which _could_ be > 2*MAXPATHLEN
  1068. TCHAR szTemp[MAXPATHLEN*2];
  1069.  
  1070. GetSelectedDirectory(0, szTemp);
  1071. SetCurrentDirectory(szTemp);
  1072. }
  1073.  
  1074.  
  1075. /*--------------------------------------------------------------------------*/
  1076. /* */
  1077. /* SetDlgDirectory() - */
  1078. /* */
  1079. /*--------------------------------------------------------------------------*/
  1080.  
  1081. /* Sets the IDD_DIR field of 'hDlg' to whatever the active window says is the
  1082. * active directory.
  1083. *
  1084. * this does not really change the XP current directory
  1085. */
  1086.  
  1087. VOID
  1088. SetDlgDirectory(HWND hDlg, LPTSTR pszPath)
  1089. {
  1090. HDC hDC;
  1091. SIZE size;
  1092. RECT rc;
  1093. HWND hDlgItem;
  1094. HANDLE hFont;
  1095. HANDLE hFontBak;
  1096. TCHAR szPath[MAXPATHLEN+5];
  1097. TCHAR szTemp[MAXPATHLEN+20];
  1098. TCHAR szMessage[MAXMESSAGELEN];
  1099.  
  1100. if (pszPath)
  1101. lstrcpy(szPath, pszPath);
  1102. else
  1103. GetSelectedDirectory(0, szPath);
  1104.  
  1105. /* Make sure that the current directory fits inside the static text field. */
  1106. hDlgItem = GetDlgItem(hDlg, IDD_DIR);
  1107. GetClientRect(hDlgItem, &rc);
  1108.  
  1109. if (LoadString(hAppInstance, IDS_CURDIRIS, szMessage, COUNTOF(szMessage))) {
  1110. hDC = GetDC(hDlg);
  1111. hFont = (HANDLE)SendMessage(hDlgItem, WM_GETFONT, 0, 0L);
  1112.  
  1113. //
  1114. // This is required because Japanese Windows uses System font
  1115. // for dialog box
  1116. //
  1117. if (hFont)
  1118. hFontBak = SelectObject(hDC, hFont);
  1119.  
  1120. GetTextExtentPoint32(hDC, szMessage, lstrlen(szMessage), &size);
  1121. CompactPath(hDC, szPath, (rc.right-rc.left-size.cx));
  1122.  
  1123. if (hFont)
  1124. SelectObject(hDC, hFontBak);
  1125.  
  1126. ReleaseDC(hDlg, hDC);
  1127. wsprintf(szTemp, szMessage, szPath);
  1128. SetDlgItemText(hDlg, IDD_DIR, szTemp);
  1129. }
  1130. }
  1131.  
  1132.  
  1133. /*--------------------------------------------------------------------------*/
  1134. /* */
  1135. /* WritePrivateProfileBool() - */
  1136. /* */
  1137. /*--------------------------------------------------------------------------*/
  1138.  
  1139. VOID
  1140. WritePrivateProfileBool(LPTSTR szKey, BOOL bParam)
  1141. {
  1142. TCHAR szBool[6];
  1143.  
  1144. wsprintf(szBool, SZ_PERCENTD, bParam);
  1145. WritePrivateProfileString(szSettings, szKey, szBool, szTheINIFile);
  1146. }
  1147.  
  1148.  
  1149.  
  1150. /////////////////////////////////////////////////////////////////////
  1151. //
  1152. // Name: CleanupMessages
  1153. //
  1154. // Synopsis: Make sure all the WM_FSC messages have been processed.
  1155. //
  1156. //
  1157. // Return: VOID
  1158. //
  1159. //
  1160. // Assumes:
  1161. //
  1162. // Effects:
  1163. //
  1164. //
  1165. // Notes:
  1166. //
  1167. /////////////////////////////////////////////////////////////////////
  1168.  
  1169.  
  1170. VOID
  1171. CleanupMessages()
  1172. {
  1173. MSG msg;
  1174.  
  1175. while (PeekMessage(&msg, NULL, 0, 0, TRUE)) {
  1176. if (!IsDialogMessage(hdlgProgress, &msg))
  1177. DispatchMessage(&msg);
  1178. }
  1179. return;
  1180. }
  1181.  
  1182.  
  1183. /*--------------------------------------------------------------------------*/
  1184. /* */
  1185. /* IsWild() - */
  1186. /* */
  1187. /*--------------------------------------------------------------------------*/
  1188.  
  1189. /* Returns TRUE iff the path contains * or ? */
  1190.  
  1191. BOOL
  1192. IsWild(LPTSTR lpszPath)
  1193. {
  1194. while (*lpszPath)
  1195. {
  1196. if (*lpszPath == CHAR_QUESTION || *lpszPath == CHAR_STAR)
  1197. return(TRUE);
  1198. lpszPath++;
  1199. }
  1200.  
  1201. return(FALSE);
  1202. }
  1203.  
  1204.  
  1205. /*--------------------------------------------------------------------------*/
  1206. /* */
  1207. /* CheckSlashes() - */
  1208. /* */
  1209. /*--------------------------------------------------------------------------*/
  1210.  
  1211. /* Replaces frontslashes (evil) with backslashes (good). */
  1212.  
  1213. VOID
  1214. CheckSlashes(LPTSTR lpT)
  1215. {
  1216. while (*lpT)
  1217. {
  1218. if (*lpT == CHAR_SLASH)
  1219. *lpT = CHAR_BACKSLASH;
  1220. lpT++;
  1221. }
  1222. }
  1223.  
  1224.  
  1225. /*--------------------------------------------------------------------------*/
  1226. /* */
  1227. /* AddBackslash() - */
  1228. /* */
  1229. /*--------------------------------------------------------------------------*/
  1230.  
  1231. /* Ensures that a path ends with a backslash. */
  1232.  
  1233. UINT
  1234. AddBackslash(LPTSTR lpszPath)
  1235. {
  1236. register UINT uLen = lstrlen(lpszPath);
  1237.  
  1238. if (*(lpszPath+uLen-1) != CHAR_BACKSLASH) {
  1239.  
  1240. lpszPath[uLen++] = CHAR_BACKSLASH;
  1241. lpszPath[uLen] = CHAR_NULL;
  1242. }
  1243.  
  1244. return uLen;
  1245. }
  1246.  
  1247.  
  1248. /*--------------------------------------------------------------------------*/
  1249. /* */
  1250. /* StripBackslash() - */
  1251. /* */
  1252. /*--------------------------------------------------------------------------*/
  1253.  
  1254. /* Removes a trailing backslash from a proper directory name UNLESS it is
  1255. * the root directory. Assumes a fully qualified directory path.
  1256. */
  1257.  
  1258. VOID
  1259. StripBackslash(LPTSTR lpszPath)
  1260. {
  1261. register UINT len;
  1262.  
  1263. len = (lstrlen(lpszPath) - 1);
  1264. if ((len == 2) || (lpszPath[len] != CHAR_BACKSLASH))
  1265. return;
  1266.  
  1267. lpszPath[len] = CHAR_NULL;
  1268. }
  1269.  
  1270.  
  1271. /*--------------------------------------------------------------------------*/
  1272. /* */
  1273. /* StripFilespec() - */
  1274. /* */
  1275. /*--------------------------------------------------------------------------*/
  1276.  
  1277. /* Remove the filespec portion from a path (including the backslash). */
  1278.  
  1279. VOID
  1280. StripFilespec(LPTSTR lpszPath)
  1281. {
  1282. LPTSTR p;
  1283.  
  1284. p = lpszPath + lstrlen(lpszPath);
  1285. while ((*p != CHAR_BACKSLASH) && (*p != CHAR_COLON) && (p != lpszPath))
  1286. p--;
  1287.  
  1288. if (*p == CHAR_COLON)
  1289. p++;
  1290.  
  1291. /* Don't strip backslash from root directory entry. */
  1292. if (p != lpszPath) {
  1293. if ((*p == CHAR_BACKSLASH) && (*(p-1) == CHAR_COLON))
  1294. p++;
  1295. }
  1296.  
  1297. *p = CHAR_NULL;
  1298. }
  1299.  
  1300.  
  1301. /*--------------------------------------------------------------------------*/
  1302. /* */
  1303. /* StripPath() - */
  1304. /* */
  1305. /*--------------------------------------------------------------------------*/
  1306.  
  1307. /* Extract only the filespec portion from a path. */
  1308.  
  1309. VOID
  1310. StripPath(LPTSTR lpszPath)
  1311. {
  1312. LPTSTR p;
  1313.  
  1314. p = lpszPath + lstrlen(lpszPath);
  1315. while ((*p != CHAR_BACKSLASH) && (*p != CHAR_COLON) && (p != lpszPath))
  1316. p--;
  1317.  
  1318. if (p != lpszPath)
  1319. p++;
  1320.  
  1321. if (p != lpszPath)
  1322. lstrcpy(lpszPath, p);
  1323. }
  1324.  
  1325.  
  1326. /*--------------------------------------------------------------------------*/
  1327. /* */
  1328. /* GetExtension() - */
  1329. /* */
  1330. /*--------------------------------------------------------------------------*/
  1331.  
  1332. /* Returns the extension part of a filename. */
  1333.  
  1334. LPTSTR
  1335. GetExtension(LPTSTR pszFile)
  1336. {
  1337. LPTSTR p, pSave = NULL;
  1338.  
  1339. p = pszFile;
  1340. while (*p)
  1341. {
  1342. if (*p == CHAR_DOT)
  1343. pSave = p;
  1344. p++;
  1345. }
  1346.  
  1347. if (!pSave)
  1348. return(p);
  1349.  
  1350. return pSave+1;
  1351. }
  1352.  
  1353.  
  1354. /*--------------------------------------------------------------------------*/
  1355. /* */
  1356. /* MyMessageBox() - */
  1357. /* */
  1358. /*--------------------------------------------------------------------------*/
  1359.  
  1360. INT
  1361. MyMessageBox(HWND hwnd, DWORD idTitle, DWORD idMessage, DWORD wStyle)
  1362. {
  1363. TCHAR szTitle[MAXTITLELEN];
  1364. TCHAR szMessage[MAXMESSAGELEN];
  1365. TCHAR szTemp[MAXMESSAGELEN];
  1366.  
  1367. HWND hwndT;
  1368.  
  1369. LoadString(hAppInstance, idTitle, szTitle, COUNTOF(szTitle));
  1370.  
  1371. if (idMessage < 32) {
  1372. LoadString(hAppInstance, IDS_UNKNOWNMSG, szTemp, COUNTOF(szTemp));
  1373. wsprintf(szMessage, szTemp, idMessage);
  1374. } else {
  1375. LoadString(hAppInstance, idMessage, szMessage, COUNTOF(szMessage));
  1376. }
  1377.  
  1378. if (hwnd)
  1379. hwndT = GetLastActivePopup(hwnd);
  1380. else
  1381. hwndT = hwnd;
  1382.  
  1383. return MessageBox(hwndT, szMessage, szTitle, wStyle | MB_TASKMODAL);
  1384. }
  1385.  
  1386.  
  1387. /*--------------------------------------------------------------------------*/
  1388. /* */
  1389. /* ExecProgram() - */
  1390. /* */
  1391. /*--------------------------------------------------------------------------*/
  1392.  
  1393. // Returns 0 for success. Otherwise returns a IDS_ string code.
  1394.  
  1395. // Note: many funcs call this with weird parms like:
  1396. // lpPath and lpParms = "f:\\\"note pad\" \"foo\"."
  1397. // = f:\"note pad" "foo". (without escape sequences)
  1398. //
  1399. // While this appears illegal, it works just fine since quotes only cause
  1400. // the spaces to be "non-delimiters." The quote itself isn't a delimiter
  1401. // and seems therefore legal.
  1402. //
  1403. // (wfsearch.c 885 does this: it appends a period to the lpParms if
  1404. // there is no extension. even if it's already quoted!)
  1405.  
  1406. DWORD
  1407. ExecProgram(LPTSTR lpPath, LPTSTR lpParms, LPTSTR lpDir, BOOL bLoadIt, BOOL bRunAs)
  1408. {
  1409. DWORD ret;
  1410. INT iCurCount;
  1411. INT i;
  1412. HCURSOR hCursor;
  1413. LPTSTR lpszTitle;
  1414.  
  1415. ret = 0;
  1416.  
  1417. hCursor = SetCursor(LoadCursor(NULL, IDC_WAIT));
  1418. iCurCount = ShowCursor(TRUE) - 1;
  1419.  
  1420. //
  1421. // Shell Execute takes ansi string.
  1422. //
  1423.  
  1424. // Set title to file spec only
  1425. // Note: this is set to the app, so
  1426. // drag, drop, execute title shows app, not file
  1427.  
  1428. // Set up title
  1429. for (lpszTitle=lpPath+lstrlen(lpPath); *lpszTitle != CHAR_BACKSLASH && *lpszTitle != CHAR_COLON &&
  1430. lpszTitle != lpPath; lpszTitle --)
  1431. ;
  1432.  
  1433. // If we encountered a \ or : then skip it
  1434.  
  1435. if (lpszTitle != lpPath)
  1436. lpszTitle++;
  1437.  
  1438. SetErrorMode(0);
  1439. ret = (DWORD) ShellExecute(hwndFrame, bRunAs ? L"runas" : NULL, lpPath, lpParms, lpDir, bLoadIt ? SW_SHOWMINNOACTIVE : SW_SHOWNORMAL);
  1440.  
  1441. SetErrorMode(1);
  1442.  
  1443. switch (ret) {
  1444. case 0:
  1445. case 8:
  1446. ret = IDS_NOMEMORYMSG;
  1447. break;
  1448.  
  1449. case 2:
  1450. ret = IDS_FILENOTFOUNDMSG;
  1451. break;
  1452.  
  1453. case 3:
  1454. ret = IDS_BADPATHMSG;
  1455. break;
  1456.  
  1457. case 5:
  1458. ret = IDS_NOACCESSFILE;
  1459. break;
  1460.  
  1461. case 11:
  1462. ret = IDS_EXECERRTITLE;
  1463. break;
  1464.  
  1465. case SE_ERR_SHARE:
  1466. ret = IDS_SHAREERROR;
  1467. break;
  1468.  
  1469. case SE_ERR_ASSOCINCOMPLETE:
  1470. ret = IDS_ASSOCINCOMPLETE;
  1471. break;
  1472.  
  1473. case SE_ERR_DDETIMEOUT:
  1474. case SE_ERR_DDEFAIL:
  1475. case SE_ERR_DDEBUSY:
  1476. ret = IDS_DDEFAIL;
  1477. break;
  1478.  
  1479. case SE_ERR_NOASSOC:
  1480. ret = IDS_NOASSOCMSG;
  1481. break;
  1482.  
  1483. default:
  1484. if (ret < 32)
  1485. goto EPExit;
  1486.  
  1487. if (bMinOnRun && !bLoadIt)
  1488. ShowWindow(hwndFrame, SW_SHOWMINNOACTIVE);
  1489. ret = 0;
  1490. }
  1491.  
  1492. EPExit:
  1493. i = ShowCursor(FALSE);
  1494.  
  1495. #if 0
  1496.  
  1497. /* Make sure that the cursor count is still balanced. */
  1498. if (i != iCurCount)
  1499. ShowCursor(TRUE);
  1500. #endif
  1501.  
  1502. SetCursor(hCursor);
  1503.  
  1504. return ret;
  1505. }
  1506.  
  1507.  
  1508.  
  1509.  
  1510. /////////////////////////////////////////////////////////////////////
  1511. //
  1512. // Name: IsProgramFile
  1513. //
  1514. // Synopsis: Returns TRUE if the Path points to a file which has one of
  1515. // the extensions listed in the "Programs=" part of win.ini.
  1516. //
  1517. // INC lpszPath -- Path to check
  1518. // INC ppDocBucket -- Bucket to search in
  1519. //
  1520. // Return: pBucketTRUE=found
  1521. //
  1522. //
  1523. // Assumes:
  1524. //
  1525. // Effects:
  1526. //
  1527. //
  1528. // Notes:
  1529. //
  1530. /////////////////////////////////////////////////////////////////////
  1531.  
  1532. PDOCBUCKET
  1533. IsBucketFile(LPTSTR lpszPath, PPDOCBUCKET ppBucket)
  1534. {
  1535. LPTSTR szExt;
  1536.  
  1537. //
  1538. // Get the file's extension.
  1539. //
  1540. szExt = GetExtension(lpszPath);
  1541.  
  1542. if (!*szExt) {
  1543.  
  1544. //
  1545. // The specified path didn't have an extension. It can't be a program.
  1546. //
  1547. return(FALSE);
  1548. }
  1549.  
  1550. return DocFind(ppBucket, szExt);
  1551. }
  1552.  
  1553.  
  1554.  
  1555. // string always upper case
  1556. // returns true if additional characters; false if first one
  1557. // repeating the first character leaves only one character
  1558. // ch == '\0' resets the tick and buffer
  1559. BOOL TypeAheadString(WCHAR ch, LPWSTR szT)
  1560. {
  1561. static DWORD tick64 = 0;
  1562. static WCHAR rgchTA[MAXPATHLEN] = { '\0' };
  1563. DWORD tickT;
  1564. size_t ich;
  1565.  
  1566. if (ch == '\0')
  1567. {
  1568. tick64 = 0;
  1569. rgchTA[0] = '\0';
  1570. return FALSE;
  1571. }
  1572.  
  1573. tickT = GetTickCount();
  1574. ch = (WCHAR)CharUpper((LPWSTR)ch);
  1575. ich = wcslen(rgchTA);
  1576.  
  1577. // if only one char and it repeats or more than .5s since last char, start over
  1578. if (ich == 1 && rgchTA[0] == ch || tickT - tick64 > 500)
  1579. ich = 0;
  1580.  
  1581. rgchTA[ich] = ch;
  1582. rgchTA[ich+1] = '\0';
  1583.  
  1584. tick64 = tickT;
  1585. lstrcpy(szT, rgchTA);
  1586.  
  1587. return ich != 0;
  1588. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement