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.

1308 lines
37 KiB

  1. /****************************************************************************/
  2. /* */
  3. /* WFINIT.C - */
  4. /* */
  5. /* Windows File System Initialization Routines */
  6. /* */
  7. /****************************************************************************/
  8. #include "winfile.h"
  9. #include "lfn.h"
  10. #include "winnet.h"
  11. #include "wnetcaps.h" // WNetGetCaps()
  12. #include "stdlib.h"
  13. typedef DWORD ( APIENTRY *EXTPROC)(HWND, WORD, LONG);
  14. typedef DWORD ( APIENTRY *UNDELPROC)(HWND, LPSTR);
  15. typedef VOID ( APIENTRY *FNPENAPP)(WORD, BOOL);
  16. VOID (APIENTRY *lpfnRegisterPenApp)(WORD, BOOL);
  17. CHAR szPenReg[] = "RegisterPenApp";
  18. CHAR szHelv[] = "MS Shell Dlg"; // default font, status line font face name
  19. HBITMAP hbmSave;
  20. INT GetDriveOffset(register WORD wDrive);
  21. DWORD RGBToBGR(DWORD rgb);
  22. VOID BoilThatDustSpec(register CHAR *pStart, BOOL bLoadIt);
  23. VOID DoRunEquals(PINT pnCmdShow);
  24. VOID GetSavedWindow(LPSTR szBuf, PSAVE_WINDOW pwin);
  25. VOID GetSettings(VOID);
  26. VOID InitMenus(VOID);
  27. INT
  28. APIENTRY
  29. GetHeightFromPointsString(
  30. LPSTR szPoints
  31. )
  32. {
  33. HDC hdc;
  34. INT height;
  35. hdc = GetDC(NULL);
  36. height = MulDiv(-atoi(szPoints), GetDeviceCaps(hdc, LOGPIXELSY), 72);
  37. ReleaseDC(NULL, hdc);
  38. return height;
  39. }
  40. VOID
  41. BiasMenu(
  42. HMENU hMenu,
  43. INT Bias
  44. )
  45. {
  46. INT pos, id, count;
  47. HMENU hSubMenu;
  48. CHAR szMenuString[80];
  49. ENTER("BiasMenu");
  50. count = GetMenuItemCount(hMenu);
  51. if (count < 0)
  52. return;
  53. for (pos = 0; pos < count; pos++) {
  54. id = GetMenuItemID(hMenu, pos);
  55. if (id < 0) {
  56. // must be a popup, recurse and update all ID's here
  57. if (hSubMenu = GetSubMenu(hMenu, pos))
  58. BiasMenu(hSubMenu, Bias);
  59. } else if (id) {
  60. // replace the item that was there with a new
  61. // one with the id adjusted
  62. GetMenuString(hMenu, (WORD)pos, szMenuString, sizeof(szMenuString), MF_BYPOSITION);
  63. DeleteMenu(hMenu, pos, MF_BYPOSITION);
  64. InsertMenu(hMenu, (WORD)pos, MF_BYPOSITION | MF_STRING, id + Bias, szMenuString);
  65. }
  66. }
  67. LEAVE("BiasMenu");
  68. }
  69. VOID
  70. APIENTRY
  71. InitExtensions()
  72. {
  73. CHAR szBuf[300] = {0};
  74. CHAR szPath[MAXPATHLEN];
  75. LPSTR p;
  76. HANDLE hMod;
  77. FM_EXT_PROC fp;
  78. HMENU hMenu;
  79. INT iMax;
  80. HMENU hMenuFrame;
  81. HWND hwndActive;
  82. ENTER("InitExtensions");
  83. hMenuFrame = GetMenu(hwndFrame);
  84. hwndActive = (HWND)SendMessage(hwndMDIClient, WM_MDIGETACTIVE, 0, 0L);
  85. if (hwndActive && GetWindowLong(hwndActive, GWL_STYLE) & WS_MAXIMIZE)
  86. iMax = 1;
  87. else
  88. iMax = 0;
  89. GetPrivateProfileString(szAddons, NULL, szNULL, szBuf, sizeof(szBuf), szTheINIFile);
  90. for (p = szBuf; *p && iNumExtensions < MAX_EXTENSIONS; p += lstrlen(p) + 1) {
  91. GetPrivateProfileString(szAddons, p, szNULL, szPath, sizeof(szPath), szTheINIFile);
  92. hMod = MLoadLibrary(szPath);
  93. if (hMod >= (HANDLE)32) {
  94. fp = (FM_EXT_PROC)GetProcAddress(hMod, "FMExtensionProc");
  95. if (fp) {
  96. WORD bias;
  97. FMS_LOAD ls;
  98. bias = (WORD)((IDM_EXTENSIONS + iNumExtensions + 1)*100);
  99. ls.wMenuDelta = bias;
  100. if ((*fp)(hwndFrame, FMEVENT_LOAD, (LPARAM)&ls)) {
  101. if (ls.dwSize != sizeof(FMS_LOAD) || !ls.hMenu)
  102. goto LoadFail;
  103. hMenu = ls.hMenu;
  104. extensions[iNumExtensions].ExtProc = fp;
  105. extensions[iNumExtensions].Delta = bias;
  106. extensions[iNumExtensions].hModule = hMod;
  107. extensions[iNumExtensions].hMenu = hMenu;
  108. BiasMenu(hMenu, bias);
  109. InsertMenu(hMenuFrame,
  110. IDM_EXTENSIONS + iNumExtensions + iMax,
  111. MF_BYPOSITION | MF_POPUP,
  112. (UINT_PTR)hMenu, ls.szMenuName);
  113. iNumExtensions++;
  114. }
  115. } else {
  116. LoadFail:
  117. FreeLibrary(hMod);
  118. }
  119. }
  120. }
  121. LEAVE("InitExtensions");
  122. }
  123. /*--------------------------------------------------------------------------*/
  124. /* */
  125. /* GetSettings() - */
  126. /* */
  127. /*--------------------------------------------------------------------------*/
  128. VOID
  129. GetSettings()
  130. {
  131. CHAR szTemp[128] = {0};
  132. INT size;
  133. ENTER("GetSettings");
  134. /* Get the flags out of the INI file. */
  135. bMinOnRun = GetPrivateProfileInt(szSettings, szMinOnRun, bMinOnRun, szTheINIFile);
  136. wTextAttribs = (WORD)GetPrivateProfileInt(szSettings, szLowerCase, wTextAttribs, szTheINIFile);
  137. bStatusBar = GetPrivateProfileInt(szSettings, szStatusBar, bStatusBar, szTheINIFile);
  138. bConfirmDelete = GetPrivateProfileInt(szSettings, szConfirmDelete, bConfirmDelete, szTheINIFile);
  139. bConfirmSubDel = GetPrivateProfileInt(szSettings, szConfirmSubDel, bConfirmSubDel, szTheINIFile);
  140. bConfirmReplace = GetPrivateProfileInt(szSettings, szConfirmReplace,bConfirmReplace,szTheINIFile);
  141. bConfirmMouse = GetPrivateProfileInt(szSettings, szConfirmMouse, bConfirmMouse, szTheINIFile);
  142. bConfirmFormat = GetPrivateProfileInt(szSettings, szConfirmFormat, bConfirmFormat, szTheINIFile);
  143. bSaveSettings = GetPrivateProfileInt(szSettings, szSaveSettings, bSaveSettings, szTheINIFile);
  144. // test font for now
  145. GetPrivateProfileString(szSettings, szSize, "8", szTemp, sizeof(szTemp), szTheINIFile);
  146. size = GetHeightFromPointsString(szTemp);
  147. GetPrivateProfileString(szSettings, szFace, szHelv, szTemp, sizeof(szTemp), szTheINIFile);
  148. hFont = CreateFont(size, 0, 0, 0,
  149. wTextAttribs & TA_BOLD ? 700 : 400,
  150. wTextAttribs & TA_ITALIC, 0, 0,
  151. ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS,
  152. DEFAULT_QUALITY, DEFAULT_PITCH | FF_SWISS, szTemp);
  153. LEAVE("GetSettings");
  154. }
  155. /*--------------------------------------------------------------------------*/
  156. /* */
  157. /* GetInternational() - */
  158. /* */
  159. /*--------------------------------------------------------------------------*/
  160. VOID
  161. APIENTRY
  162. GetInternational()
  163. {
  164. ENTER("GetInternational");
  165. GetProfileString(szInternational, "sShortDate", szShortDate, szShortDate, 11);
  166. AnsiUpper(szShortDate);
  167. GetProfileString(szInternational, "sTime", szTime, szTime, 2);
  168. GetProfileString(szInternational, "s1159", sz1159, sz1159, 9);
  169. GetProfileString(szInternational, "s2359", sz2359, sz2359, 9);
  170. GetProfileString(szInternational, "sThousand", szComma, szComma, sizeof(szComma));
  171. iTime = GetProfileInt(szInternational, "iTime", iTime);
  172. iTLZero = GetProfileInt(szInternational, "iTLZero", iTLZero);
  173. LEAVE("GetInternational");
  174. }
  175. /*--------------------------------------------------------------------------*/
  176. /* */
  177. /* BuildDocumentString() - */
  178. /* */
  179. /*--------------------------------------------------------------------------*/
  180. /* Create a string which contains all of the extensions the user wants us to
  181. * display with document icons. This consists of any associated extensions
  182. * as well as any extensions listed in the "Documents=" WIN.INI line.
  183. */
  184. VOID
  185. APIENTRY
  186. BuildDocumentString()
  187. {
  188. register LPSTR p;
  189. register INT len;
  190. INT lenDocs;
  191. CHAR szT[10];
  192. INT i;
  193. HKEY hk;
  194. ENTER("BuildDocumentString");
  195. len = 32;
  196. /* Get all of the "Documents=" stuff. */
  197. szDocuments = (LPSTR)LocalAlloc(LPTR, len);
  198. if (!szDocuments)
  199. return;
  200. while ((lenDocs = GetProfileString(szWindows, "Documents", szNULL, szDocuments, len-1)) == len-1) {
  201. len += 32;
  202. szDocuments = (LPSTR)LocalReAlloc((HANDLE)szDocuments, len, LMEM_MOVEABLE);
  203. if (!szDocuments) {
  204. LEAVE("BuildDocumentString");
  205. return;
  206. }
  207. }
  208. lstrcat(szDocuments, szBlank);
  209. lenDocs++;
  210. p = (LPSTR)(szDocuments + lenDocs);
  211. /* Read all of the [Extensions] keywords into 'szDocuments'. */
  212. while ((INT)GetProfileString(szExtensions, NULL, szNULL, p, len-lenDocs) > (len-lenDocs-3)) {
  213. len += 32;
  214. szDocuments = (LPSTR)LocalReAlloc((HANDLE)szDocuments, len, LMEM_MOVEABLE);
  215. if (!szDocuments) {
  216. LEAVE("BuildDocumentString");
  217. return;
  218. }
  219. p = (LPSTR)(szDocuments + lenDocs);
  220. }
  221. /* Step through each of the keywords in 'szDocuments' changing NULLS into
  222. * spaces until a double-NULL is found.
  223. */
  224. p = szDocuments;
  225. while (*p) {
  226. /* Find the next NULL. */
  227. while (*p)
  228. p++;
  229. /* Change it into a space. */
  230. *p = ' ';
  231. p++;
  232. }
  233. if (RegOpenKey(HKEY_CLASSES_ROOT,szNULL,&hk) == ERROR_SUCCESS) {
  234. /* now enumerate the classes in the registration database and get all
  235. * those that are of the form *.ext
  236. */
  237. for (i = 0; RegEnumKey(hk,(DWORD)i,szT,sizeof(szT))
  238. == ERROR_SUCCESS; i++) {
  239. if (szT[0] != '.' ||
  240. (szT[1] && szT[2] && szT[3] && szT[4])) {
  241. /* either the class does not start with . or it has a greater
  242. * than 3 byte extension... skip it.
  243. */
  244. continue;
  245. }
  246. if (FindExtensionInList(szT+2,szDocuments)) {
  247. // don't add it if it's already there!
  248. continue;
  249. }
  250. len += 4;
  251. szDocuments = (PSTR)LocalReAlloc((HANDLE)szDocuments, len,
  252. LMEM_MOVEABLE);
  253. if (!szDocuments)
  254. break;
  255. lstrcat(szDocuments, szT+1);
  256. lstrcat(szDocuments, szBlank);
  257. }
  258. RegCloseKey(hk);
  259. }
  260. PRINT(BF_PARMTRACE, "OUT: szDocuments=%s", szDocuments);
  261. LEAVE("BuildDocumentString - ok");
  262. return;
  263. }
  264. INT
  265. GetDriveOffset(
  266. register WORD wDrive
  267. )
  268. {
  269. if (IsCDRomDrive(wDrive))
  270. return dxDriveBitmap * 0;
  271. switch (IsNetDrive(wDrive)) {
  272. case 1:
  273. return dxDriveBitmap * 4;
  274. case 2:
  275. return dxDriveBitmap * 5;
  276. }
  277. if (IsRemovableDrive(wDrive))
  278. return dxDriveBitmap * 1;
  279. if (IsRamDrive(wDrive))
  280. return dxDriveBitmap * 3;
  281. return dxDriveBitmap * 2;
  282. }
  283. VOID
  284. APIENTRY
  285. InitDriveBitmaps()
  286. {
  287. INT nDrive;
  288. ENTER("InitDiskMenus");
  289. // and now add all new ones
  290. for (nDrive=0; nDrive < cDrives; nDrive++) {
  291. // refresh/init this here as well
  292. rgiDrivesOffset[nDrive] = GetDriveOffset((WORD)rgiDrive[nDrive]);
  293. }
  294. LEAVE("InitDiskMenus");
  295. }
  296. /*--------------------------------------------------------------------------*/
  297. /* */
  298. /* InitMenus() - */
  299. /* */
  300. /*--------------------------------------------------------------------------*/
  301. VOID
  302. InitMenus()
  303. {
  304. WORD i;
  305. HMENU hMenu;
  306. OFSTRUCT os;
  307. INT iMax;
  308. CHAR szValue[MAXPATHLEN];
  309. HWND hwndActive;
  310. ENTER("InitMenus");
  311. hwndActive = (HWND)SendMessage(hwndMDIClient, WM_MDIGETACTIVE, 0, 0L);
  312. if (hwndActive && GetWindowLong(hwndActive, GWL_STYLE) & WS_MAXIMIZE)
  313. iMax = 1;
  314. else
  315. iMax = 0;
  316. GetPrivateProfileString(szSettings, szUndelete, szNULL, szValue, sizeof(szValue), szTheINIFile);
  317. if (szValue[0]) {
  318. // create explicit filename to avoid searching the path
  319. GetSystemDirectory(os.szPathName, sizeof(os.szPathName));
  320. AddBackslash(os.szPathName);
  321. lstrcat(os.szPathName, szValue);
  322. if (MOpenFile(os.szPathName, &os, OF_EXIST) > 0) {
  323. hModUndelete = MLoadLibrary(szValue);
  324. if (hModUndelete >= (HANDLE)32) {
  325. lpfpUndelete = (FM_UNDELETE_PROC)GetProcAddress(hModUndelete, "UndeleteFile");
  326. if (lpfpUndelete) {
  327. hMenu = GetSubMenu(GetMenu(hwndFrame), IDM_FILE + iMax);
  328. LoadString(hAppInstance, IDS_UNDELETE, szValue, sizeof(szValue));
  329. InsertMenu(hMenu, 4, MF_BYPOSITION | MF_STRING, IDM_UNDELETE, szValue);
  330. }
  331. } else {
  332. FreeLibrary(hModUndelete);
  333. }
  334. }
  335. }
  336. /* Init the Disk menu. */
  337. hMenu = GetMenu(hwndFrame);
  338. if (nFloppies == 0) {
  339. EnableMenuItem(hMenu, IDM_DISKCOPY, MF_BYCOMMAND | MF_GRAYED);
  340. EnableMenuItem(hMenu, IDM_FORMAT, MF_BYCOMMAND | MF_GRAYED);
  341. EnableMenuItem(hMenu, IDM_SYSDISK, MF_BYCOMMAND | MF_GRAYED);
  342. }
  343. bNetAdmin = WNetGetCaps(WNNC_ADMIN) & WNNC_ADM_GETDIRECTORYTYPE;
  344. /* Should we enable the network items? */
  345. i = (WORD)WNetGetCaps(WNNC_DIALOG);
  346. i = 0;
  347. bConnect = i & WNNC_DLG_ConnectDialog; // note, these should both
  348. bDisconnect = i & WNNC_DLG_DisconnectDialog; // be true or both false
  349. // use submenu because we are doing this by position
  350. hMenu = GetSubMenu(GetMenu(hwndFrame), IDM_DISK + iMax);
  351. if (i)
  352. InsertMenu(hMenu, 5, MF_BYPOSITION | MF_SEPARATOR, 0, NULL);
  353. if (bConnect && bDisconnect) {
  354. // lanman style double connect/disconnect
  355. LoadString(hAppInstance, IDS_CONNECT, szValue, sizeof(szValue));
  356. InsertMenu(hMenu, 6, MF_BYPOSITION | MF_STRING, IDM_CONNECT, szValue);
  357. LoadString(hAppInstance, IDS_DISCONNECT, szValue, sizeof(szValue));
  358. InsertMenu(hMenu, 7, MF_BYPOSITION | MF_STRING, IDM_DISCONNECT, szValue);
  359. } else if (WNetGetCaps(WNNC_CONNECTION)) {
  360. }
  361. hMenu = GetMenu(hwndFrame);
  362. if (bStatusBar)
  363. CheckMenuItem(hMenu, IDM_STATUSBAR, MF_BYCOMMAND | MF_CHECKED);
  364. if (bMinOnRun)
  365. CheckMenuItem(hMenu, IDM_MINONRUN, MF_BYCOMMAND | MF_CHECKED);
  366. if (bSaveSettings)
  367. CheckMenuItem(hMenu, IDM_SAVESETTINGS, MF_BYCOMMAND | MF_CHECKED);
  368. InitDriveBitmaps();
  369. InitExtensions();
  370. LEAVE("InitMenus");
  371. }
  372. /*--------------------------------------------------------------------------*/
  373. /* */
  374. /* BoilThatDustSpec() - */
  375. /* */
  376. /*--------------------------------------------------------------------------*/
  377. /* Parses the command line (if any) passed into WINFILE and exec's any tokens
  378. * it may contain.
  379. */
  380. VOID
  381. BoilThatDustSpec(
  382. register CHAR *pStart,
  383. BOOL bLoadIt
  384. )
  385. {
  386. register CHAR *pEnd;
  387. WORD ret;
  388. BOOL bFinished;
  389. ENTER("BoilThatDustSpec");
  390. if (*pStart == TEXT('\0'))
  391. return;
  392. bFinished = FALSE;
  393. while (!bFinished) {
  394. pEnd = pStart;
  395. while ((*pEnd) && (*pEnd != ' ') && (*pEnd != ','))
  396. pEnd = AnsiNext(pEnd);
  397. if (*pEnd == TEXT('\0'))
  398. bFinished = TRUE;
  399. else
  400. *pEnd = TEXT('\0');
  401. ret = ExecProgram(pStart, szNULL, NULL, bLoadIt);
  402. if (ret)
  403. MyMessageBox(NULL, IDS_EXECERRTITLE, ret, MB_OK | MB_ICONEXCLAMATION | MB_SYSTEMMODAL);
  404. pStart = pEnd+1;
  405. }
  406. LEAVE("BoilThatDustSpec");
  407. }
  408. /*--------------------------------------------------------------------------*/
  409. /* */
  410. /* DoRunEquals() - */
  411. /* */
  412. /*--------------------------------------------------------------------------*/
  413. /* Handle the "Run=" and "Load=" lines in WIN.INI. */
  414. VOID
  415. DoRunEquals(
  416. PINT pnCmdShow
  417. )
  418. {
  419. CHAR szBuffer[128] = {0};
  420. /* "Load" apps before "Run"ning any. */
  421. GetProfileString(szWindows, "Load", szNULL, szBuffer, 128);
  422. if (*szBuffer)
  423. BoilThatDustSpec(szBuffer, TRUE);
  424. GetProfileString(szWindows, "Run", szNULL, szBuffer, 128);
  425. if (*szBuffer) {
  426. BoilThatDustSpec(szBuffer, FALSE);
  427. *pnCmdShow = SW_SHOWMINNOACTIVE;
  428. }
  429. }
  430. //
  431. // BOOL APIENTRY LoadBitmaps()
  432. //
  433. // this routine loads DIB bitmaps, and "fixes up" their color tables
  434. // so that we get the desired result for the device we are on.
  435. //
  436. // this routine requires:
  437. // the DIB is a 16 color DIB authored with the standard windows colors
  438. // bright blue (00 00 FF) is converted to the background color!
  439. // light grey (C0 C0 C0) is replaced with the button face color
  440. // dark grey (80 80 80) is replaced with the button shadow color
  441. //
  442. // this means you can't have any of these colors in your bitmap
  443. //
  444. #define BACKGROUND 0x000000FF // bright blue
  445. #define BACKGROUNDSEL 0x00FF00FF // bright blue
  446. #define BUTTONFACE 0x00C0C0C0 // bright grey
  447. #define BUTTONSHADOW 0x00808080 // dark grey
  448. DWORD
  449. FlipColor(
  450. DWORD rgb
  451. )
  452. {
  453. return RGB(GetBValue(rgb), GetGValue(rgb), GetRValue(rgb));
  454. }
  455. BOOL
  456. APIENTRY
  457. LoadBitmaps()
  458. {
  459. HDC hdc;
  460. HANDLE h;
  461. DWORD *p;
  462. LPSTR lpBits;
  463. HANDLE hRes;
  464. LPBITMAPINFOHEADER lpBitmapInfo;
  465. INT numcolors;
  466. DWORD n;
  467. DWORD rgbSelected;
  468. DWORD rgbUnselected;
  469. PVOID pv;
  470. ENTER("LoadBitmaps");
  471. rgbSelected = FlipColor(GetSysColor(COLOR_HIGHLIGHT));
  472. rgbUnselected = FlipColor(GetSysColor(COLOR_WINDOW));
  473. h = FindResource(hAppInstance, MAKEINTRESOURCE(BITMAPS), RT_BITMAP);
  474. if (!h) {
  475. return FALSE;
  476. }
  477. n = SizeofResource(hAppInstance, h);
  478. lpBitmapInfo = (LPBITMAPINFOHEADER)LocalAlloc(LPTR, n);
  479. if (!lpBitmapInfo)
  480. return FALSE;
  481. /* Load the bitmap and copy it to R/W memory */
  482. hRes = LoadResource(hAppInstance, h);
  483. pv = (PVOID) LockResource(hRes);
  484. if (pv)
  485. memcpy( lpBitmapInfo, pv, n );
  486. UnlockResource(hRes);
  487. FreeResource(hRes);
  488. p = (DWORD *)((LPSTR)(lpBitmapInfo) + lpBitmapInfo->biSize);
  489. /* Search for the Solid Blue entry and replace it with the current
  490. * background RGB.
  491. */
  492. numcolors = 16;
  493. while (numcolors-- > 0) {
  494. if (*p == BACKGROUND)
  495. *p = rgbUnselected;
  496. else if (*p == BACKGROUNDSEL)
  497. *p = rgbSelected;
  498. else if (*p == BUTTONFACE)
  499. *p = FlipColor(GetSysColor(COLOR_BTNFACE));
  500. else if (*p == BUTTONSHADOW)
  501. *p = FlipColor(GetSysColor(COLOR_BTNSHADOW));
  502. p++;
  503. }
  504. /* Now create the DIB. */
  505. /* First skip over the header structure */
  506. lpBits = (LPSTR)(lpBitmapInfo + 1);
  507. /* Skip the color table entries, if any */
  508. lpBits += (1 << (lpBitmapInfo->biBitCount)) * sizeof(RGBQUAD);
  509. /* Create a color bitmap compatible with the display device */
  510. hdc = GetDC(NULL);
  511. if (hdcMem = CreateCompatibleDC(hdc)) {
  512. if (hbmBitmaps = CreateDIBitmap(hdc, lpBitmapInfo, (DWORD)CBM_INIT, lpBits, (LPBITMAPINFO)lpBitmapInfo, DIB_RGB_COLORS))
  513. hbmSave = SelectObject(hdcMem, hbmBitmaps);
  514. }
  515. ReleaseDC(NULL, hdc);
  516. LEAVE("LoadBitmaps");
  517. return TRUE;
  518. }
  519. //
  520. // void GetSavedWindow(LPSTR szBuf, PSAVE_WINDOW pwin)
  521. //
  522. // in:
  523. // szBuf buffer to parse out all the saved window stuff
  524. // if NULL pwin is filled with all defaults
  525. // out:
  526. // pwin this structure is filled with all fields from
  527. // szBuf. if any fields do not exist this is
  528. // initialized with the standard defaults
  529. //
  530. VOID
  531. GetSavedWindow(
  532. LPSTR szBuf,
  533. PSAVE_WINDOW pwin
  534. )
  535. {
  536. PINT pint;
  537. INT count;
  538. ENTER("GetSavedWindow");
  539. // defaults
  540. pwin->rc.right = pwin->rc.left = CW_USEDEFAULT;
  541. pwin->pt.x = pwin->pt.y = pwin->rc.top = pwin->rc.bottom = 0;
  542. pwin->sw = SW_SHOWNORMAL;
  543. pwin->sort = IDD_NAME;
  544. pwin->view = VIEW_NAMEONLY;
  545. pwin->attribs = ATTR_DEFAULT;
  546. pwin->split = 0;
  547. pwin->szDir[0] = 0;
  548. if (!szBuf)
  549. return;
  550. count = 0;
  551. pint = (PINT)&pwin->rc; // start by filling the rect
  552. while (*szBuf && count < 11) {
  553. *pint++ = atoi(szBuf); // advance to next field
  554. while (*szBuf && *szBuf != ',')
  555. szBuf++;
  556. while (*szBuf && *szBuf == ',')
  557. szBuf++;
  558. count++;
  559. }
  560. lstrcpy(pwin->szDir, szBuf); // this is the directory
  561. LEAVE("GetSavedWindow");
  562. }
  563. // szDir (OEM) path to check for existance
  564. BOOL
  565. CheckDirExists(
  566. LPSTR szDir
  567. )
  568. {
  569. BOOL bRet = FALSE;
  570. ENTER("CheckDirExists");
  571. PRINT(BF_PARMTRACE, "szDir=%s", szDir);
  572. if (IsNetDrive((WORD)(DRIVEID(szDir))) == 2)
  573. return FALSE;
  574. if (IsValidDisk(DRIVEID(szDir)))
  575. bRet = !SheChangeDir(szDir);
  576. LEAVE("CheckDirExists");
  577. return bRet;
  578. }
  579. // return the tree directory in szTreeDir
  580. BOOL
  581. APIENTRY
  582. CreateSavedWindows()
  583. {
  584. CHAR buf[MAXPATHLEN+7*7], key[10];
  585. INT dir_num;
  586. HWND hwnd;
  587. SAVE_WINDOW win;
  588. INT iNumTrees;
  589. ENTER("CreateSavedWindows");
  590. // make sure this thing exists so we don't hit drives that don't
  591. // exist any more
  592. dir_num = 1;
  593. iNumTrees = 0;
  594. do {
  595. wsprintf(key, szDirKeyFormat, dir_num++);
  596. GetPrivateProfileString(szSettings, key, szNULL, buf, sizeof(buf), szTheINIFile);
  597. if (*buf) {
  598. CHAR szDir[MAXPATHLEN];
  599. GetSavedWindow(buf, &win);
  600. AnsiUpperBuff(win.szDir, 1);
  601. // clean off some junk so we
  602. // can do this test
  603. lstrcpy(szDir, win.szDir);
  604. StripFilespec(szDir);
  605. StripBackslash(szDir);
  606. FixAnsiPathForDos(szDir);
  607. if (!CheckDirExists(szDir))
  608. continue;
  609. wNewView = (WORD)win.view;
  610. wNewSort = (WORD)win.sort;
  611. dwNewAttribs = win.attribs;
  612. hwnd = CreateTreeWindow(win.szDir, win.split);
  613. if (!hwnd) {
  614. LEAVE("CreateSavedWindows");
  615. return FALSE;
  616. }
  617. iNumTrees++;
  618. // keep track of this for now...
  619. SetInternalWindowPos(hwnd, win.sw, &win.rc, &win.pt);
  620. }
  621. } while (*buf);
  622. // if nothing was saved create a tree for the current drive
  623. if (!iNumTrees) {
  624. //lstrcpy(buf, szOriginalDirPath);
  625. lstrcpy(buf, "\\"); // Don't use current filesystem directory
  626. lstrcat(buf, szStarDotStar);
  627. hwnd = CreateTreeWindow(buf, -1);// default to split window
  628. if (!hwnd)
  629. return FALSE;
  630. // ShowWindow(hwnd, SW_MAXIMIZE);
  631. iNumTrees++;
  632. }
  633. LEAVE("CreateSavedWindows - Ok");
  634. return TRUE;
  635. }
  636. // void APIENTRY GetTextStuff(HDC hdc)
  637. //
  638. // this computues all the globals that are dependant on the
  639. // currently selected font
  640. //
  641. // in:
  642. // hdc DC with font selected into it
  643. //
  644. VOID
  645. APIENTRY
  646. GetTextStuff(
  647. HDC hdc
  648. )
  649. {
  650. ENTER("GetTextStuff");
  651. MGetTextExtent(hdc, "M", 1, &dxText, &dyText);
  652. MGetTextExtent(hdc, szEllipses, 3, &dxEllipses, NULL);
  653. // these are all dependant on the text metrics
  654. dxDrive = dxDriveBitmap + dxText + (4*dyBorderx2);
  655. dyDrive = max(dyDriveBitmap + (4*dyBorderx2), dyText);
  656. // dxFileName = dxFolder + (12*dxText);
  657. dyFileName = max(dyText, dyFolder); // + dyBorder;
  658. LEAVE("GetTextStuff");
  659. }
  660. /*--------------------------------------------------------------------------*/
  661. /* */
  662. /* InitFileManager() - */
  663. /* */
  664. /*--------------------------------------------------------------------------*/
  665. BOOL
  666. APIENTRY
  667. InitFileManager(
  668. HANDLE hInstance,
  669. HANDLE hPrevInstance,
  670. LPSTR lpCmdLine,
  671. INT nCmdShow
  672. )
  673. {
  674. INT i;
  675. WORD ret;
  676. INT nHardDisk;
  677. HDC hdcScreen;
  678. CHAR szBuffer[128];
  679. HCURSOR hcurArrow;
  680. WNDCLASS wndClass;
  681. SAVE_WINDOW win;
  682. HWND hwnd;
  683. HANDLE hOld;
  684. LPSTR lpT;
  685. TEXTMETRIC tm;
  686. CHAR szTemp[80];
  687. ENTER("InitFileManager");
  688. PRINT(BF_PARMTRACE, "lpCmdLine=%s", lpCmdLine);
  689. PRINT(BF_PARMTRACE, "nCmdShow=%d", IntToPtr(nCmdShow));
  690. // ProfStart();
  691. hAppInstance = hInstance; // Preserve this instance's module handle
  692. /* Set the Global DTA Address. This must be done before ExecProgram. */
  693. DosGetDTAAddress();
  694. if (*lpCmdLine)
  695. nCmdShow = SW_SHOWMINNOACTIVE;
  696. PRINT(BF_PARMTRACE, "lpCmdLine=%s", lpCmdLine);
  697. PRINT(BF_PARMTRACE, "nCmdShow=%d", IntToPtr(nCmdShow));
  698. #ifdef LATER
  699. if (hPrevInstance) {
  700. // if we are already running bring up the other instance
  701. +++GetInstanceData - NOOP on 32BIT side+++(hPrevInstance, (NLPSTR)&hwndFrame, sizeof(HWND));
  702. if (hwndFrame) {
  703. hwnd = GetLastActivePopup(hwndFrame);
  704. BringWindowToTop(hwndFrame);
  705. if (IsIconic(hwndFrame))
  706. ShowWindow(hwndFrame, SW_RESTORE);
  707. else
  708. SetActiveWindow(hwnd);
  709. }
  710. LEAVE("InitFileManager");
  711. return FALSE;
  712. }
  713. #else
  714. UNREFERENCED_PARAMETER(hPrevInstance);
  715. {
  716. HWND hwndT;
  717. BYTE szClass[20];
  718. if (CreateEvent(NULL, TRUE, FALSE, szFrameClass) == NULL) {
  719. for (hwndT = GetWindow(GetDesktopWindow(), GW_CHILD); hwndT;
  720. hwndT = GetWindow(hwndT, GW_HWNDNEXT)) {
  721. if (GetClassName(hwndT, szClass, sizeof(szClass)))
  722. if (!lstrcmpi(szFrameClass, szClass)) {
  723. SetForegroundWindow(hwndT);
  724. if (IsIconic(hwndT))
  725. ShowWindow(hwndT, SW_RESTORE);
  726. return FALSE;
  727. }
  728. }
  729. return FALSE;
  730. }
  731. }
  732. #endif
  733. SetErrorMode(1); // turn off critical error bullshit
  734. // if (lpfnRegisterPenApp = (FNPENAPP)GetProcAddress((HANDLE)GetSystemMetrics(SM_PENWINDOWS), szPenReg))
  735. // (*lpfnRegisterPenApp)(1, TRUE);
  736. /* Remember the current directory. */
  737. SheGetDir(0, szOriginalDirPath);
  738. if (!GetWindowsDirectory(szTheINIFile, sizeof(szTheINIFile))) {
  739. szTheINIFile[0] = '\0';
  740. }
  741. AddBackslash(szTheINIFile);
  742. lstrcat(szTheINIFile, szINIFile);
  743. GetProfileString(szWindows, "Programs", szDefPrograms, szTemp, sizeof(szTemp));
  744. szPrograms = (LPSTR)LocalAlloc(LPTR, lstrlen(szTemp)+1);
  745. if (!szPrograms)
  746. szPrograms = szNULL;
  747. else
  748. lstrcpy(szPrograms, szTemp);
  749. BuildDocumentString();
  750. /* Deal with any RUN= or LOAD= lines in WIN.INI. */
  751. if (*lpCmdLine) {
  752. // skip spaces
  753. while (*lpCmdLine == ' ')
  754. lpCmdLine++;
  755. for (lpT = lpCmdLine; *lpT; lpT = AnsiNext(lpT)) {
  756. if (*lpT == ' ')
  757. break;
  758. }
  759. if (*lpT == ' ')
  760. *lpT++ = 0;
  761. ret = ExecProgram(lpCmdLine, lpT, NULL, FALSE);
  762. if (ret)
  763. MyMessageBox(NULL, IDS_EXECERRTITLE, ret, MB_OK | MB_ICONEXCLAMATION | MB_SYSTEMMODAL);
  764. else
  765. nCmdShow = SW_SHOWMINNOACTIVE;
  766. }
  767. /* Read WINFILE.INI and set the approriate variables. */
  768. GetSettings();
  769. /* Read the International constants out of WIN.INI. */
  770. GetInternational();
  771. dyBorder = GetSystemMetrics(SM_CYBORDER);
  772. dyBorderx2 = dyBorder * 2;
  773. dxFrame = GetSystemMetrics(SM_CXFRAME) - dyBorder;
  774. dxDriveBitmap = DRIVES_WIDTH;
  775. dyDriveBitmap = DRIVES_HEIGHT;
  776. dxFolder = FILES_WIDTH;
  777. dyFolder = FILES_HEIGHT;
  778. if (!LoadBitmaps())
  779. return FALSE;
  780. hicoTree = LoadIcon(hAppInstance, MAKEINTRESOURCE(TREEICON));
  781. hicoTreeDir = LoadIcon(hAppInstance, MAKEINTRESOURCE(TREEDIRICON));
  782. hicoDir = LoadIcon(hAppInstance, MAKEINTRESOURCE(DIRICON));
  783. chFirstDrive = (CHAR)((wTextAttribs & TA_LOWERCASE) ? 'a' : 'A');
  784. // now build the parameters based on the font we will be using
  785. hdcScreen = GetDC(NULL);
  786. hOld = SelectObject(hdcScreen, hFont);
  787. GetTextStuff(hdcScreen);
  788. if (hOld)
  789. SelectObject(hdcScreen, hOld);
  790. dxClickRect = max(GetSystemMetrics(SM_CXDOUBLECLK) / 2, 2 * dxText);
  791. dyClickRect = max(GetSystemMetrics(SM_CYDOUBLECLK) / 2, dyText);
  792. hFontStatus = CreateFont(GetHeightFromPointsString("10"), 0, 0, 0, 400, 0, 0, 0,
  793. ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS,
  794. DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS, szHelv);
  795. hOld = SelectObject(hdcScreen, hFontStatus);
  796. GetTextMetrics(hdcScreen, &tm);
  797. if (hOld)
  798. SelectObject(hdcScreen, hOld);
  799. dyStatus = tm.tmHeight + tm.tmExternalLeading + 7 * dyBorder;
  800. dxStatusField = GetDeviceCaps(hdcScreen, LOGPIXELSX) * 3;
  801. ReleaseDC(NULL, hdcScreen);
  802. cDrives = UpdateDriveList();
  803. /* Create an array of INT 13h drive numbers (floppies only). */
  804. nFloppies = 0;
  805. nHardDisk = 0x80;
  806. for (i=0; i < cDrives; i++) {
  807. if (IsRemovableDrive(rgiDrive[i])) {
  808. /* Avoid Phantom B: problems. */
  809. if ((nFloppies == 1) && (i > 1))
  810. nFloppies = 2;
  811. nFloppies++;
  812. } else {
  813. nHardDisk++;
  814. }
  815. }
  816. /* Load the accelerator table. */
  817. hAccel = LoadAccelerators(hInstance, MAKEINTRESOURCE(WFACCELTABLE));
  818. LoadString(hInstance, IDS_DIRSREAD, szDirsRead, sizeof(szDirsRead));
  819. LoadString(hInstance, IDS_BYTES, szBytes, sizeof(szBytes));
  820. LoadString(hInstance, IDS_SBYTES, szSBytes, sizeof(szSBytes));
  821. wDOSversion = DOS_320;
  822. wHelpMessage = RegisterWindowMessage("ShellHelp");
  823. wBrowseMessage = RegisterWindowMessage("commdlg_help");
  824. hhkMessageFilter = SetWindowsHook(WH_MSGFILTER, MessageFilter);
  825. hcurArrow = LoadCursor(NULL, IDC_ARROW);
  826. wndClass.lpszClassName = szFrameClass;
  827. wndClass.style = 0;
  828. wndClass.lpfnWndProc = FrameWndProc;
  829. wndClass.cbClsExtra = 0;
  830. wndClass.cbWndExtra = 0;
  831. wndClass.hInstance = hInstance;
  832. wndClass.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(APPICON));
  833. wndClass.hCursor = hcurArrow;
  834. wndClass.hbrBackground = (HBRUSH)(COLOR_APPWORKSPACE + 1); // COLOR_WINDOW+1;
  835. wndClass.lpszMenuName = MAKEINTRESOURCE(FRAMEMENU);
  836. if (!RegisterClass(&wndClass)) {
  837. LEAVE("InitFileManager");
  838. return FALSE;
  839. }
  840. wndClass.lpszClassName = szTreeClass;
  841. wndClass.style = CS_VREDRAW | CS_HREDRAW;
  842. wndClass.lpfnWndProc = TreeWndProc;
  843. // wndClass.cbClsExtra = 0;
  844. wndClass.cbWndExtra = sizeof(LONG) +// GWL_TYPE
  845. sizeof(LONG) +// wViewStyle GWL_VIEW
  846. sizeof(LONG) +// wSortStyle GWL_SORT
  847. sizeof(LONG) +// dwAttrStyle GWL_ATTRIBS
  848. sizeof(LONG) +// FSC flag GWL_FSCFLAG
  849. sizeof(PVOID) +// hwndLastFocus GWL_LASTFOCUS
  850. sizeof(LONG); // dxSplit GWL_SPLIT
  851. wndClass.hIcon = NULL;
  852. wndClass.hCursor = LoadCursor(hInstance, MAKEINTRESOURCE(SPLITCURSOR));
  853. wndClass.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
  854. wndClass.lpszMenuName = NULL;
  855. if (!RegisterClass(&wndClass)) {
  856. LEAVE("InitFileManager");
  857. return FALSE;
  858. }
  859. wndClass.lpszClassName = szDrivesClass;
  860. wndClass.style = CS_HREDRAW | CS_VREDRAW;
  861. wndClass.lpfnWndProc = DrivesWndProc;
  862. wndClass.cbWndExtra = sizeof(LONG) +// GWL_CURDRIVEIND
  863. sizeof(LONG) +// GWL_CURDRIVEFOCUS
  864. sizeof(PVOID); // GWLP_LPSTRVOLUME
  865. wndClass.hCursor = hcurArrow;
  866. wndClass.hbrBackground = (HBRUSH)(COLOR_BTNFACE+1);
  867. if (!RegisterClass(&wndClass)) {
  868. LEAVE("InitFileManager");
  869. return FALSE;
  870. }
  871. wndClass.lpszClassName = szTreeControlClass;
  872. wndClass.style = CS_DBLCLKS | CS_VREDRAW | CS_HREDRAW;
  873. wndClass.lpfnWndProc = TreeControlWndProc;
  874. wndClass.cbWndExtra = sizeof(LONG); // GWL_READLEVEL
  875. wndClass.hCursor = hcurArrow;
  876. wndClass.hbrBackground = NULL;
  877. if (!RegisterClass(&wndClass)) {
  878. LEAVE("InitFileManager");
  879. return FALSE;
  880. }
  881. wndClass.lpszClassName = szDirClass;
  882. wndClass.style = CS_VREDRAW | CS_HREDRAW;
  883. wndClass.lpfnWndProc = DirWndProc;
  884. wndClass.cbWndExtra = sizeof(PVOID)+ // DTA data GWLP_HDTA
  885. sizeof(PVOID); // GWLP_TABARRAY
  886. wndClass.hIcon = NULL;
  887. wndClass.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
  888. if (!RegisterClass(&wndClass)) {
  889. LEAVE("InitFileManager");
  890. return FALSE;
  891. }
  892. wndClass.lpszClassName = szSearchClass;
  893. wndClass.style = 0;
  894. wndClass.lpfnWndProc = SearchWndProc;
  895. wndClass.cbWndExtra = sizeof(LONG) + // GWL_TYPE
  896. sizeof(LONG) + // wViewStyle GWL_VIEW
  897. sizeof(LONG) + // wSortStyle GWL_SORT
  898. sizeof(LONG) + // dwAttrStyle GWL_ATTRIBS
  899. sizeof(LONG) + // FSC flag GWL_FSCFLAG
  900. sizeof(PVOID) + // GWLP_HDTASEARCH
  901. sizeof(PVOID) + // GWLP_TABARRAYSEARCH
  902. sizeof(PVOID); // GWLP_LASTFOCUSSEARCH
  903. wndClass.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(DIRICON));
  904. wndClass.hbrBackground = NULL;
  905. if (!RegisterClass(&wndClass)) {
  906. LEAVE("InitFileManager");
  907. return FALSE;
  908. }
  909. if (!LoadString(hInstance, IDS_WINFILE, szTitle, 32)) {
  910. LEAVE("InitFileManager");
  911. return FALSE;
  912. }
  913. GetPrivateProfileString(szSettings, szWindow, szNULL, szBuffer, sizeof(szBuffer), szTheINIFile);
  914. GetSavedWindow(szBuffer, &win);
  915. if (!CreateWindowEx(0, szFrameClass, szTitle,WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN,
  916. win.rc.left, win.rc.top, win.rc.right, win.rc.bottom,
  917. NULL, NULL, hInstance, NULL)) {
  918. LEAVE("InitFileManager - Frame class creation failure");
  919. return FALSE;
  920. }
  921. InitMenus(); // after the window/menu has been created
  922. // support forced min or max
  923. if (nCmdShow == SW_SHOWNORMAL && win.sw == SW_SHOWMAXIMIZED)
  924. nCmdShow = SW_SHOWMAXIMIZED;
  925. ShowWindow(hwndFrame, nCmdShow);
  926. UpdateWindow(hwndFrame);
  927. LFNInit();
  928. if (!CreateSavedWindows()) {
  929. LEAVE("InitFileManager");
  930. return FALSE;
  931. }
  932. ShowWindow(hwndMDIClient, SW_NORMAL);
  933. // now refresh all tree windows (start background tree read)
  934. //
  935. // since the tree reads happen in the background the user can
  936. // change the Z order by activating windows once the read
  937. // starts. to avoid missing a window we must restart the
  938. // search through the MDI child list, checking to see if the
  939. // tree has been read yet (if there are any items in the
  940. // list box). if it has not been read yet we start the read
  941. hwnd = GetWindow(hwndMDIClient, GW_CHILD);
  942. while (hwnd) {
  943. HWND hwndTree;
  944. if ((hwndTree = HasTreeWindow(hwnd)) &&
  945. (INT)SendMessage(GetDlgItem(hwndTree, IDCW_TREELISTBOX), LB_GETCOUNT, 0, 0L) == 0) {
  946. SendMessage(hwndTree, TC_SETDRIVE, MAKEWORD(FALSE, 0), 0L);
  947. hwnd = GetWindow(hwndMDIClient, GW_CHILD);
  948. } else {
  949. hwnd = GetWindow(hwnd, GW_HWNDNEXT);
  950. }
  951. }
  952. // ProfStop();
  953. LEAVE("InitFileManager - OK");
  954. return TRUE;
  955. }
  956. VOID
  957. APIENTRY
  958. DeleteBitmaps()
  959. {
  960. ENTER("DeleteBitmaps");
  961. if (hdcMem) {
  962. SelectObject(hdcMem, hbmSave);
  963. if (hbmBitmaps)
  964. DeleteObject(hbmBitmaps);
  965. DeleteDC(hdcMem);
  966. }
  967. LEAVE("DeleteBitmaps");
  968. }
  969. /*--------------------------------------------------------------------------*/
  970. /* */
  971. /* FreeFileManager() - */
  972. /* */
  973. /*--------------------------------------------------------------------------*/
  974. VOID
  975. APIENTRY
  976. FreeFileManager()
  977. {
  978. ENTER("FreeFileManager");
  979. if (lpfnRegisterPenApp)
  980. (*lpfnRegisterPenApp)(1, FALSE);
  981. DeleteBitmaps();
  982. if (hFont)
  983. DeleteObject(hFont);
  984. if (hFontStatus)
  985. DeleteObject(hFontStatus);
  986. LEAVE("FreeFileManager");
  987. }