-
Notifications
You must be signed in to change notification settings - Fork 697
/
wfinit.c
1596 lines (1222 loc) · 43.6 KB
/
wfinit.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/********************************************************************
wfinit.c
Windows File System Initialization Routines
Copyright (c) Microsoft Corporation. All rights reserved.
Licensed under the MIT License.
********************************************************************/
#include <stdlib.h>
#include "winfile.h"
#include "lfn.h"
#include "wnetcaps.h" // WNetGetCaps()
#include <ole2.h>
#include <shlobj.h>
typedef VOID (APIENTRY *FNPENAPP)(WORD, BOOL);
VOID (APIENTRY *lpfnRegisterPenApp)(WORD, BOOL);
BYTE chPenReg[] = "RegisterPenApp"; // used in GetProcAddress call
TCHAR szNTlanman[] = TEXT("ntlanman.dll");
TCHAR szHelv[] = TEXT("MS Shell Dlg");
/*
** 6/13/95 FloydR Note re: MS Gothic, MS Shell Dlg and System fonts for Japan.
** For 3.51J, the "MS Shell Dlg" font is linked to the "MS Gothic" Japanese
** TTF. This means that all this stuff about using different fonts for
** Japan (and Korea/China) is gone.
*/
HBITMAP hbmSave;
DWORD RGBToBGR(DWORD rgb);
VOID BoilThatDustSpec(register WCHAR *pStart, BOOL bLoadIt);
VOID DoRunEquals(PINT pnCmdShow);
VOID GetSavedWindow(LPWSTR szBuf, PWINDOW pwin);
VOID GetSettings(VOID);
#define MENU_STRING_SIZ 80
#define PROFILE_STRING_SIZ 300
INT
GetHeightFromPointsString(LPTSTR szPoints)
{
HDC hdc;
INT height;
hdc = GetDC(NULL);
height = MulDiv(-atoi(szPoints), GetDeviceCaps(hdc, LOGPIXELSY), 72);
ReleaseDC(NULL, hdc);
return height;
}
VOID
BiasMenu(HMENU hMenu, UINT Bias)
{
UINT pos, id, count;
HMENU hSubMenu;
TCHAR szMenuString[MENU_STRING_SIZ];
count = GetMenuItemCount(hMenu);
if (count == (UINT) -1)
return;
for (pos = 0; pos < count; pos++) {
id = GetMenuItemID(hMenu, pos);
if (id == (UINT) -1) {
// must be a popup, recurse and update all ID's here
if (hSubMenu = GetSubMenu(hMenu, pos))
BiasMenu(hSubMenu, Bias);
} else if (id) {
// replace the item that was there with a new
// one with the id adjusted
GetMenuString(hMenu, pos, szMenuString, COUNTOF(szMenuString), MF_BYPOSITION);
DeleteMenu(hMenu, pos, MF_BYPOSITION);
InsertMenu(hMenu, pos, MF_BYPOSITION | MF_STRING, id + Bias, szMenuString);
}
}
}
VOID
InitExtensions()
{
TCHAR szBuf[PROFILE_STRING_SIZ];
TCHAR szPath[MAXPATHLEN];
LPTSTR p;
HANDLE hMod;
FM_EXT_PROC fp;
HMENU hMenu;
INT iMax;
HMENU hMenuFrame;
HWND hwndActive;
INT iMenuOffset=0;
BOOL bUnicode;
hMenuFrame = GetMenu(hwndFrame);
hwndActive = (HWND)SendMessage(hwndMDIClient, WM_MDIGETACTIVE, 0, 0L);
if (hwndActive && GetWindowLongPtr(hwndActive, GWL_STYLE) & WS_MAXIMIZE)
iMax = 1;
else
iMax = 0;
GetPrivateProfileString(szAddons, NULL, szNULL, szBuf, COUNTOF(szBuf), szTheINIFile);
for (p = szBuf; *p && iNumExtensions < MAX_EXTENSIONS; p += lstrlen(p) + 1) {
GetPrivateProfileString(szAddons, p, szNULL, szPath, COUNTOF(szPath), szTheINIFile);
hMod = LoadLibrary(szPath);
if (hMod) {
fp = (FM_EXT_PROC)GetProcAddress(hMod, FM_EXT_PROC_ENTRYW);
if (fp) {
bUnicode = TRUE;
} else {
fp = (FM_EXT_PROC)GetProcAddress(hMod, FM_EXT_PROC_ENTRYA);
bUnicode = FALSE;
}
if (fp) {
UINT bias;
FMS_LOADA lsA;
FMS_LOADW lsW;
bias = ((IDM_EXTENSIONS + iNumExtensions + 1)*100);
// We are now going to bias each menu, since extensions
// don't know about each other and may clash IDM_xx if
// we don't.
// Our system is as follow: IDMs 1000 - 6999 are reserved
// for us (menus 0 - 5 inclusive). Thus, IDMs
// 7000 - 1199 is reserved for extensions.
// This is why we added 1 in the above line to compute
// bias: IDMs 0000-0999 are not used for menu 0.
if (bUnicode)
lsW.wMenuDelta = bias;
else
lsA.wMenuDelta = bias;
if ((*fp)(hwndFrame, FMEVENT_LOAD, bUnicode ? (LPARAM)&lsW : (LPARAM)&lsA)) {
if ((bUnicode ? lsW.dwSize : lsA.dwSize)
!= (bUnicode ? sizeof(FMS_LOADW) : sizeof(FMS_LOADA)))
goto LoadFail;
hMenu = bUnicode ? lsW.hMenu : lsA.hMenu;
extensions[iNumExtensions].ExtProc = fp;
extensions[iNumExtensions].Delta = bias;
extensions[iNumExtensions].hModule = hMod;
extensions[iNumExtensions].hMenu = hMenu;
extensions[iNumExtensions].bUnicode = bUnicode;
if (hMenu) {
BiasMenu(hMenu, bias);
if (bUnicode) {
InsertMenuW(hMenuFrame,
IDM_EXTENSIONS + iMenuOffset + iMax,
MF_BYPOSITION | MF_POPUP,
(UINT_PTR) hMenu, lsW.szMenuName);
} else {
InsertMenuA(hMenuFrame,
IDM_EXTENSIONS + iMenuOffset + iMax,
MF_BYPOSITION | MF_POPUP,
(UINT_PTR) hMenu, lsA.szMenuName);
}
iMenuOffset++;
}
iNumExtensions++;
} else {
goto LoadFail;
}
} else {
LoadFail:
FreeLibrary(hMod);
}
}
}
}
/*--------------------------------------------------------------------------*/
/* */
/* GetSettings() - */
/* */
/*--------------------------------------------------------------------------*/
VOID
GetSettings()
{
TCHAR szTemp[128];
INT size;
INT weight;
INT bfCharset;
/* Get the flags out of the INI file. */
bMinOnRun = GetPrivateProfileInt(szSettings, szMinOnRun, bMinOnRun, szTheINIFile);
wTextAttribs = (WORD)GetPrivateProfileInt(szSettings, szLowerCase, wTextAttribs, szTheINIFile);
bStatusBar = GetPrivateProfileInt(szSettings, szStatusBar, bStatusBar, szTheINIFile);
bDriveBar = GetPrivateProfileInt(szSettings, szDriveBar, bDriveBar, szTheINIFile);
bToolbar = GetPrivateProfileInt(szSettings, szToolbar, bToolbar, szTheINIFile);
bNewWinOnConnect = GetPrivateProfileInt(szSettings, szNewWinOnNetConnect, bNewWinOnConnect, szTheINIFile);
bConfirmDelete = GetPrivateProfileInt(szSettings, szConfirmDelete, bConfirmDelete, szTheINIFile);
bConfirmSubDel = GetPrivateProfileInt(szSettings, szConfirmSubDel, bConfirmSubDel, szTheINIFile);
bConfirmReplace = GetPrivateProfileInt(szSettings, szConfirmReplace,bConfirmReplace,szTheINIFile);
bConfirmMouse = GetPrivateProfileInt(szSettings, szConfirmMouse, bConfirmMouse, szTheINIFile);
bConfirmFormat = GetPrivateProfileInt(szSettings, szConfirmFormat, bConfirmFormat, szTheINIFile);
bConfirmReadOnly= GetPrivateProfileInt(szSettings, szConfirmReadOnly, bConfirmReadOnly, szTheINIFile);
uChangeNotifyTime= GetPrivateProfileInt(szSettings, szChangeNotifyTime, uChangeNotifyTime, szTheINIFile);
bSaveSettings = GetPrivateProfileInt(szSettings, szSaveSettings, bSaveSettings, szTheINIFile);
weight = GetPrivateProfileInt(szSettings, szFaceWeight, 400, szTheINIFile);
GetPrivateProfileString(szSettings,
szSize,
bJAPAN ?
TEXT("14") :
TEXT("8"),
szTemp,
COUNTOF(szTemp),
szTheINIFile);
size = GetHeightFromPointsString(szTemp);
GetPrivateProfileString(szSettings,
szFace,
szHelv,
szTemp,
COUNTOF(szTemp),
szTheINIFile);
bfCharset = bJAPAN ?
GetPrivateProfileInt(szSettings,
szSaveCharset,
SHIFTJIS_CHARSET,
szTheINIFile) :
ANSI_CHARSET;
hFont = CreateFont(size,
0, 0, 0, weight,
wTextAttribs & TA_ITALIC, 0, 0,
bfCharset,
OUT_DEFAULT_PRECIS,
CLIP_DEFAULT_PRECIS,
DEFAULT_QUALITY,
DEFAULT_PITCH | FF_SWISS,
szTemp);
}
/*--------------------------------------------------------------------------*/
/* */
/* GetInternational() - */
/* */
/*--------------------------------------------------------------------------*/
VOID
GetInternational()
{
GetLocaleInfoW(lcid, LOCALE_STHOUSAND, (LPWSTR) szComma, COUNTOF(szComma));
GetLocaleInfoW(lcid, LOCALE_SDECIMAL, (LPWSTR) szDecimal, COUNTOF(szDecimal));
}
INT
GetDriveOffset(register DRIVE drive)
{
if (IsRemoteDrive(drive)) {
if (aDriveInfo[drive].bRemembered)
return dxDriveBitmap * 5;
else
return dxDriveBitmap * 4;
}
if (IsRemovableDrive(drive))
return dxDriveBitmap * 1;
if (IsRamDrive(drive))
return dxDriveBitmap * 3;
if (IsCDRomDrive(drive))
return dxDriveBitmap * 0;
return dxDriveBitmap * 2;
}
/*--------------------------------------------------------------------------*/
/* */
/* InitMenus() - */
/* */
/*--------------------------------------------------------------------------*/
VOID
InitMenus()
{
HMENU hMenu;
INT iMax;
TCHAR szValue[MAXPATHLEN];
HWND hwndActive;
HMENU hMenuOptions;
TCHAR szPathName[MAXPATHLEN];
hwndActive = (HWND)SendMessage(hwndMDIClient, WM_MDIGETACTIVE, 0, 0L);
if (hwndActive && GetWindowLongPtr(hwndActive, GWL_STYLE) & WS_MAXIMIZE)
iMax = 1;
else
iMax = 0;
GetPrivateProfileString(szSettings, szUndelete, szNULL, szValue, COUNTOF(szValue), szTheINIFile);
if (szValue[0]) {
// create explicit filename to avoid searching the path
GetSystemDirectory(szPathName, COUNTOF(szPathName));
AddBackslash(szPathName);
lstrcat(szPathName, szValue);
hModUndelete = LoadLibrary(szValue);
if (hModUndelete) {
lpfpUndelete = (FM_UNDELETE_PROC)GetProcAddress(hModUndelete, UNDELETE_ENTRYW);
if (lpfpUndelete) {
bUndeleteUnicode = TRUE;
} else {
lpfpUndelete = (FM_UNDELETE_PROC)GetProcAddress(hModUndelete, UNDELETE_ENTRYA);
bUndeleteUnicode = FALSE;
}
if (lpfpUndelete) {
hMenu = GetSubMenu(GetMenu(hwndFrame), IDM_FILE + iMax);
LoadString(hAppInstance, IDS_UNDELETE, szValue, COUNTOF(szValue));
InsertMenu(hMenu, 4, MF_BYPOSITION | MF_STRING, IDM_UNDELETE, szValue);
}
} else {
FreeLibrary(hModUndelete);
hModUndelete = NULL;
}
}
//
// use submenu because we are doing this by position
//
hMenu = GetSubMenu(GetMenu(hwndFrame), IDM_DISK + iMax);
if (WNetStat(NS_CONNECTDLG)) { // Network Connections...
InsertMenu(hMenu, 4, MF_BYPOSITION | MF_SEPARATOR, 0, NULL);
LoadString(hAppInstance, IDS_NEWWINONCONNECT, szValue, COUNTOF(szValue));
hMenuOptions = GetSubMenu(GetMenu(hwndFrame), 4);
InsertMenu(hMenuOptions, 8, MF_BYPOSITION | MF_STRING, IDM_NEWWINONCONNECT, szValue);
LoadString(hAppInstance, IDS_CONNECT, szValue, COUNTOF(szValue));
InsertMenu(hMenu, 5, MF_BYPOSITION | MF_STRING, IDM_CONNECT, szValue);
LoadString(hAppInstance, IDS_DISCONNECT, szValue, COUNTOF(szValue));
InsertMenu(hMenu, 6, MF_BYPOSITION | MF_STRING, IDM_DISCONNECT, szValue);
}
// Shared Directories
if (WNetStat(NS_SHAREDLG)) {
InsertMenu(hMenu, 7, MF_BYPOSITION | MF_SEPARATOR, 0, NULL);
LoadString(hAppInstance, IDS_SHAREAS, szValue, COUNTOF(szValue));
InsertMenu(hMenu, 8, MF_BYPOSITION | MF_STRING, IDM_SHAREAS, szValue);
LoadString(hAppInstance, IDS_STOPSHARE, szValue, COUNTOF(szValue));
InsertMenu(hMenu, 9, MF_BYPOSITION | MF_STRING, IDM_STOPSHARE, szValue);
}
//
// Init the Disk menu.
//
hMenu = GetMenu(hwndFrame);
if (nFloppies == 0) {
EnableMenuItem(hMenu, IDM_DISKCOPY, MF_BYCOMMAND | MF_GRAYED);
EnableMenuItem(hMenu, IDM_FORMAT, MF_BYCOMMAND | MF_GRAYED);
}
if (bStatusBar)
CheckMenuItem(hMenu, IDM_STATUSBAR, MF_BYCOMMAND | MF_CHECKED);
if (bMinOnRun)
CheckMenuItem(hMenu, IDM_MINONRUN, MF_BYCOMMAND | MF_CHECKED);
if (bSaveSettings)
CheckMenuItem(hMenu, IDM_SAVESETTINGS, MF_BYCOMMAND | MF_CHECKED);
if (bDriveBar)
CheckMenuItem(hMenu, IDM_DRIVEBAR, MF_BYCOMMAND | MF_CHECKED);
if (bToolbar)
CheckMenuItem(hMenu, IDM_TOOLBAR, MF_BYCOMMAND | MF_CHECKED);
if (bNewWinOnConnect)
CheckMenuItem(hMenu, IDM_NEWWINONCONNECT, MF_BYCOMMAND | MF_CHECKED);
//
// Init menus after the window/menu has been created
//
InitExtensions();
InitToolbarButtons();
//
// Redraw the menu bar since it's already displayed
//
DrawMenuBar(hwndFrame);
}
/*--------------------------------------------------------------------------*/
/* */
/* BoilThatDustSpec() - */
/* */
/*--------------------------------------------------------------------------*/
/* Parses the command line (if any) passed into WINFILE and exec's any tokens
* it may contain.
*/
VOID
BoilThatDustSpec(register TCHAR *pStart, BOOL bLoadIt)
{
register TCHAR *pEnd;
DWORD ret;
BOOL bFinished;
if (*pStart == CHAR_NULL)
return;
bFinished = FALSE;
while (!bFinished) {
pEnd = pStart;
while ((*pEnd) && (*pEnd != CHAR_SPACE) && (*pEnd != CHAR_COMMA))
++pEnd;
if (*pEnd == CHAR_NULL)
bFinished = TRUE;
else
*pEnd = CHAR_NULL;
ret = ExecProgram(pStart, szNULL, NULL, bLoadIt, FALSE);
if (ret)
MyMessageBox(NULL, IDS_EXECERRTITLE, ret, MB_OK | MB_ICONEXCLAMATION | MB_SYSTEMMODAL);
pStart = pEnd+1;
}
}
//
// BOOL LoadBitmaps()
//
// this routine loads DIB bitmaps, and "fixes up" their color tables
// so that we get the desired result for the device we are on.
//
// this routine requires:
// the DIB is a 16 color DIB authored with the standard windows colors
// bright green (FF 00 00) is converted to the background color!
// light grey (C0 C0 C0) is replaced with the button face color
// dark grey (80 80 80) is replaced with the button shadow color
//
// this means you can't have any of these colors in your bitmap
//
#define BACKGROUND 0x0000FF00 // bright green
#define BACKGROUNDSEL 0x00FF00FF // bright red
#define BUTTONFACE 0x00C0C0C0 // bright grey
#define BUTTONSHADOW 0x00808080 // dark grey
DWORD
FlipColor(DWORD rgb)
{
return RGB(GetBValue(rgb), GetGValue(rgb), GetRValue(rgb));
}
BOOL
LoadBitmaps(VOID)
{
HDC hdc;
HANDLE h;
DWORD FAR *p;
LPBYTE lpBits;
HANDLE hRes;
LPBITMAPINFOHEADER lpBitmapInfo;
INT numcolors;
DWORD rgbSelected;
DWORD rgbUnselected;
UINT cbBitmapSize;
LPBITMAPINFOHEADER lpBitmapData;
rgbSelected = FlipColor(GetSysColor(COLOR_HIGHLIGHT));
rgbUnselected = FlipColor(GetSysColor(COLOR_WINDOW));
h = FindResource(hAppInstance, (LPTSTR) MAKEINTRESOURCE(BITMAPS), RT_BITMAP);
hRes = LoadResource(hAppInstance, h);
// Lock the bitmap data and make a copy of it for the mask and the bitmap.
//
cbBitmapSize = SizeofResource( hAppInstance, h );
lpBitmapData = (LPBITMAPINFOHEADER)( hRes );
lpBitmapInfo = (LPBITMAPINFOHEADER) LocalAlloc(LMEM_FIXED, cbBitmapSize);
if (!lpBitmapInfo) {
return FALSE;
}
CopyMemory( (PBYTE)lpBitmapInfo, (PBYTE)lpBitmapData, cbBitmapSize );
//
// Get a pointer into the color table of the bitmaps, cache the number of
// bits per pixel
//
p = (DWORD FAR *)((PBYTE)(lpBitmapInfo) + lpBitmapInfo->biSize);
//
// Search for the Solid Blue entry and replace it with the current
// background RGB.
//
numcolors = 16;
while (numcolors-- > 0) {
if (*p == BACKGROUND)
*p = rgbUnselected;
else if (*p == BACKGROUNDSEL)
*p = rgbSelected;
else if (*p == BUTTONFACE)
*p = FlipColor(GetSysColor(COLOR_BTNFACE));
else if (*p == BUTTONSHADOW)
*p = FlipColor(GetSysColor(COLOR_BTNSHADOW));
p++;
}
//
// Now create the DIB.
//
//
// First skip over the header structure
//
lpBits = (LPBYTE)(lpBitmapInfo + 1);
//
// Skip the color table entries, if any
//
lpBits += (1 << (lpBitmapInfo->biBitCount)) * sizeof(RGBQUAD);
//
// Create a color bitmap compatible with the display device
//
hdc = GetDC(NULL);
if (hdcMem = CreateCompatibleDC(hdc)) {
if (hbmBitmaps = CreateDIBitmap(hdc, lpBitmapInfo, (DWORD)CBM_INIT, lpBits, (LPBITMAPINFO)lpBitmapInfo, DIB_RGB_COLORS))
hbmSave = SelectObject(hdcMem, hbmBitmaps);
}
ReleaseDC(NULL, hdc);
#ifndef KKBUGFIX
//It is not necessary to free a resource loaded by using the LoadResource function.
LocalUnlock(hRes);
FreeResource(hRes);
#endif
LocalFree(lpBitmapInfo);
return TRUE;
}
/////////////////////////////////////////////////////////////////////
//
// Name: GetSavedWindow
//
// Synopsis:
//
// IN szBuf buffer to parse out all save win info (NULL = default)
// OUT pwin pwin filled with szBuf fields.
//
// Return:
//
//
// Assumes:
//
// Effects:
//
//
// Notes:
//
/////////////////////////////////////////////////////////////////////
VOID
GetSavedWindow(
LPWSTR szBuf,
PWINDOW pwin)
{
PINT pint;
INT count;
//
// defaults
//
// (CW_USEDEFAULT must be type casted since it is defined
// as an int.
//
pwin->rc.right = pwin->rc.left = (LONG)CW_USEDEFAULT;
pwin->pt.x = pwin->pt.y = pwin->rc.top = pwin->rc.bottom = 0;
pwin->sw = SW_SHOWNORMAL;
pwin->dwSort = IDD_NAME;
pwin->dwView = VIEW_NAMEONLY;
pwin->dwAttribs = ATTR_DEFAULT;
pwin->nSplit = 0;
pwin->szDir[0] = CHAR_NULL;
if (!szBuf)
return;
//
// BUGBUG: (LATER)
// This assumes the members of the point structure are
// the same size as INT (sizeof(LONG) == sizeof(INT) == sizeof(UINT))!
//
count = 0;
pint = (PINT)&pwin->rc; // start by filling the rect
while (*szBuf && count < 11) {
*pint++ = atoi(szBuf); // advance to next field
while (*szBuf && *szBuf != CHAR_COMMA)
szBuf++;
while (*szBuf && *szBuf == CHAR_COMMA)
szBuf++;
count++;
}
lstrcpy(pwin->szDir, szBuf); // this is the directory
}
BOOL
CheckDirExists(
LPWSTR szDir)
{
BOOL bRet = FALSE;
if (IsNetDrive(DRIVEID(szDir)) == 2) {
CheckDrive(hwndFrame, DRIVEID(szDir), FUNC_SETDRIVE);
return TRUE;
}
if (IsValidDisk(DRIVEID(szDir)))
bRet = SetCurrentDirectory(szDir);
return bRet;
}
BOOL
CreateSavedWindows()
{
WCHAR buf[2*MAXPATHLEN+7*7], key[10];
WINDOW win;
//
// since win.szDir is bigger.
//
WCHAR szDir[2*MAXPATHLEN];
INT nDirNum;
HWND hwnd;
INT iNumTrees;
//
// make sure this thing exists so we don't hit drives that don't
// exist any more
//
nDirNum = 1;
iNumTrees = 0;
do {
wsprintf(key, szDirKeyFormat, nDirNum++);
GetPrivateProfileString(szSettings, key, szNULL, buf, COUNTOF(buf), szTheINIFile);
if (*buf) {
GetSavedWindow(buf, &win);
//
// clean off some junk so we
// can do this test
//
lstrcpy(szDir, win.szDir);
StripFilespec(szDir);
StripBackslash(szDir);
if (!CheckDirExists(szDir))
continue;
dwNewView = win.dwView;
dwNewSort = win.dwSort;
dwNewAttribs = win.dwAttribs;
hwnd = CreateTreeWindow(win.szDir,
win.rc.left,
win.rc.top,
win.rc.right - win.rc.left,
win.rc.bottom - win.rc.top,
win.nSplit);
if (!hwnd) {
continue;
}
iNumTrees++;
//
// keep track of this for now...
//
if (IsIconic(hwnd))
SetWindowPos(hwnd, NULL, win.pt.x, win.pt.y, 0, 0, SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
ShowWindow(hwnd, win.sw);
}
} while (*buf);
//
// if nothing was saved create a tree for the current drive
//
if (!iNumTrees) {
lstrcpy(buf, szOriginalDirPath);
AddBackslash(buf);
lstrcat(buf, szStarDotStar);
//
// default to split window
//
hwnd = CreateTreeWindow(buf, CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, -1);
if (!hwnd)
return FALSE;
iNumTrees++;
}
return TRUE;
}
// void GetTextStuff(HDC hdc)
//
// this computes all the globals that are dependent on the
// currently selected font
//
// in:
// hdc DC with font selected into it
//
VOID
GetTextStuff(HDC hdc)
{
SIZE size;
TEXTMETRIC tm;
GetTextExtentPoint32(hdc, TEXT("W"), 1, &size);
dxText = size.cx;
dyText = size.cy;
//
// the old method of GetTextExtent("M") was not good enough for the
// drive bar because in Arial 8 (the default font), a lowercase 'w'
// is actually wider than an uppercase 'M', which causes drive W in
// the drive bar to clip. rather than play around with a couple of
// sample letters and taking the max, or fudging the width, we just
// get the metrics and use the real max character width.
//
// to avoid the tree window indents looking too wide, we use the old
// 'M' extent everywhere besides the drive bar, though.
//
GetTextMetrics(hdc, &tm);
//
// these are all dependent on the text metrics
//
dxDrive = dxDriveBitmap + tm.tmMaxCharWidth + (4*dyBorderx2);
dyDrive = max(dyDriveBitmap + (4*dyBorderx2), dyText);
dyFileName = max(dyText, dyFolder); // + dyBorder;
}
UINT
FillDocType(
PPDOCBUCKET ppDoc,
LPCWSTR pszSection,
LPCWSTR pszDefault)
{
LPWSTR pszDocuments = NULL;
LPWSTR p;
LPWSTR p2;
UINT uLen = 0;
UINT uRetval = 0;
do {
uLen += 32;
if (pszDocuments)
LocalFree((HLOCAL)pszDocuments);
pszDocuments = LocalAlloc(LMEM_FIXED, uLen*sizeof(WCHAR));
if (!pszDocuments) {
return 0;
}
} while (GetProfileString(szWindows,
pszSection,
pszDefault,
pszDocuments,
uLen) == (DWORD)uLen-2);
//
// Parse through string, searching for blanks
//
for (p=pszDocuments; *p; p++) {
if (CHAR_SPACE == *p) {
*p = CHAR_NULL;
}
}
for(p2=pszDocuments; p2<p; p2++) {
if (*p2) {
if (DocInsert(ppDoc, p2, NULL) == 1)
uRetval++;
while(*p2 && p2!=p)
p2++;
}
}
LocalFree((HLOCAL)pszDocuments);
return uRetval;
}
/*--------------------------------------------------------------------------*/
/* */
/* InitFileManager() - */
/* */
/*--------------------------------------------------------------------------*/
BOOL
InitFileManager(
HANDLE hInstance,
LPWSTR lpCmdLine,
INT nCmdShow)
{
INT i;
HDC hdcScreen;
//
// 2*MAXPATHLEN since may have huge filter.
//
WCHAR szBuffer[2*MAXPATHLEN];
HCURSOR hcurArrow;
WNDCLASS wndClass;
WINDOW win;
HWND hwnd;
HANDLE hOld;
RECT rcT, rcS;
WCHAR szTemp[80];
DWORD Ignore;
HANDLE hThread;
DWORD dwRetval;
hThread = GetCurrentThread();
SetThreadPriority(hThread, THREAD_PRIORITY_ABOVE_NORMAL);
InitializeCriticalSection(&CriticalSectionPath);
// ProfStart();
//
// Preserve this instance's module handle
//
hAppInstance = hInstance;
lcid = GetThreadLocale();
JAPANBEGIN
bJapan = (PRIMARYLANGID(LANGIDFROMLCID(lcid)) == LANG_JAPANESE);
JAPANEND
if (*lpCmdLine)
nCmdShow = SW_SHOWMINNOACTIVE;
// setup ini file location
lstrcpy(szTheINIFile, szBaseINIFile);
dwRetval = GetEnvironmentVariable(TEXT("APPDATA"), szBuffer, MAXPATHLEN);
if (dwRetval > 0 && dwRetval <= (DWORD)(MAXPATHLEN - lstrlen(szRoamINIPath) - 1 - lstrlen(szBaseINIFile) - 1)) {
wsprintf(szTheINIFile, TEXT("%s%s"), szBuffer, szRoamINIPath);
if (CreateDirectory(szTheINIFile, NULL) || GetLastError() == ERROR_ALREADY_EXISTS) {
wsprintf(szTheINIFile, TEXT("%s%s\\%s"), szBuffer, szRoamINIPath, szBaseINIFile);
}
else {
wsprintf(szTheINIFile, TEXT("%s\\%s"), szBuffer, szBaseINIFile);
}
}
//
// Constructors for info system.
// Must always do since these never fail and we don't test for
// non-initialization during destruction (if FindWindow returns valid)
//
M_Info();
M_Type();
M_Space();
M_NetCon();
M_VolInfo();
//
// Bounce errors to us, not fs.
//
SetErrorMode(1);
for (i=0; i<26;i++) {
I_Space(i);
}
if (OleInitialize(0) != NOERROR)
return FALSE;
if (lpfnRegisterPenApp = (FNPENAPP)GetProcAddress((HANDLE)GetSystemMetrics(SM_PENWINDOWS), chPenReg))
(*lpfnRegisterPenApp)(1, TRUE);
//
// Remember the current directory.
//
GetCurrentDirectory(COUNTOF(szOriginalDirPath), szOriginalDirPath);
if (*lpCmdLine) {
if (dwRetval = ExecProgram(lpCmdLine, pszNextComponent(lpCmdLine), NULL, FALSE, FALSE))
MyMessageBox(NULL, IDS_EXECERRTITLE, dwRetval, MB_OK | MB_ICONEXCLAMATION | MB_SYSTEMMODAL);