Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

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