-
Notifications
You must be signed in to change notification settings - Fork 0
/
pifedit.c
1943 lines (1487 loc) · 52.4 KB
/
pifedit.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
/************************ The Qualitas PIF Editor ***************************
* *
* (C) Copyright 1992, 1993 Qualitas, Inc. GNU General Public License version 3. *
* *
* MODULE : PIFEDIT.C - Main source module for PIFEDIT.EXE *
* *
* HISTORY : Who When What *
* --- ---- ---- *
* WRL 11 DEC 92 Original revision *
* WRL 11 MAR 93 Changes for TWT *
* RCC 21 JUN 95 Added Ctl3d, tightened code a bit *
* *
******************************************************************************/
#include "main.h"
#include "advanced.h"
typedef UINT (CALLBACK * COMMDLGHOOKPROC)(HWND, UINT, WPARAM, LPARAM);
BOOL CALLBACK _export PaneMsgProc(HWND hWndDlg, UINT msg, WPARAM wParam, LPARAM lParam);
VOID Pane_OnCommand(HWND hWnd, UINT id, HWND hWndCtl, WORD codeNotify);
BOOL Pane_OnInitDialog(HWND hWnd, HWND hWndFocus, LPARAM lParam);
VOID Pane_OnPaint(HWND hWnd);
VOID Pane_OnPaint_Iconic(HWND hWnd);
VOID Pane_OnSetFont(HWND hWndCtl, HFONT hFont, BOOL fRedraw);
VOID InitHelpWindow(HWND hWnd);
VOID SetHelpText(HWND hWnd, UINT idString);
LRESULT CALLBACK _export NumEdit_SubClassProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
LRESULT CALLBACK _export KeyEdit_SubClassProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
LRESULT CALLBACK _export Button_SubClassProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
int OpenPIF(VOID);
int SavePIF(VOID);
int SaveAsPIF(VOID);
int CheckSave(HWND hWnd);
int CheckPIFValidity(BOOL fMustBeValid);
int WritePIF(HWND hWndDlg, LPSTR lpszPIFName);
VOID MenuFileNew(BOOL fCheck);
VOID MenuFileOpen(VOID);
int MenuFileSave(VOID);
int MenuFileSaveAs(VOID);
VOID DefaultPIF(VOID);
int ControlsFromPIF(PPIF pPIF, HWND hWnd);
BOOL IsPifFile(LPCSTR lpszFileSpec);
UINT CALLBACK _export GetOpenFileNameHookProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
VOID SnapPif(VOID); // Copy pifModel to pifBackup
BOOL ValidateHotKey(BOOL fComplain);
void MakePathName(char *, char *);
#define IDE_HELP 1
#define BUTTON_BKGNDCOLOR RGB(0, 128, 128)
#define ACTIVE_BTN_BORDER_WIDTH 1
PIFEDIT_GLOBALS Globals;
typedef struct tagCONTROL {
int Pane; // Pane ID
int ID; // Control ID
BYTE Type; // Type of control, EDIT, BUTTON, etc.
BYTE Flags; // EDIT_NUM, etc.
int nDefault; // Default value
int nMin; // Minimum value
int nMax; // Maximum value
HWND hWnd; // HWND of the control
WNDPROC lpfnOld; // Original WndProc
} CONTROL, * PCONTROL, FAR * LPCONTROL;
// Control types for CONTROL.Type
// If the control type isn't one of these, it doesn't get the focus,
// and it doesn't have help text.
#define EDIT 1
#define BUTTON 2
#define KEYEDIT 3
#define LTEXT 4
#define GROUP 5
#define LASTCONTROL 255
// Flags for CONTROL.Flags
#define EDIT_TEXT 0x10 // Text control
#define EDIT_NUM 0x80 // Numeric control
#define EDIT_RANGE (EDIT_NUM | 0x40) // Normal range
#define EDIT_OPTVAL (EDIT_NUM | 0x20) // Optional -1 is allowed
#define EDIT_NOSEL 0x08 // Kill selection on SETFOCUS
#define BUTTON_HOTGRP 0x80
#define BUTTON_STATE 0x08 // Button is 'down', or 'checked'
CONTROL aControls[] = {
{ 0, IDD_HELP, EDIT, EDIT_NOSEL },
{ 0, IDB_ENHANCED, BUTTON },
{ IDD_GENERAL, IDT_FILENAME, LTEXT },
{ IDD_GENERAL, IDE_FILENAME, EDIT, EDIT_TEXT },
{ IDD_GENERAL, IDT_TITLE, LTEXT },
{ IDD_GENERAL, IDE_TITLE, EDIT, EDIT_TEXT },
{ IDD_GENERAL, IDT_PARAMS, LTEXT },
{ IDD_GENERAL, IDE_PARAMS, EDIT, EDIT_TEXT },
{ IDD_GENERAL, IDT_DIRECTORY, LTEXT },
{ IDD_GENERAL, IDE_DIRECTORY, EDIT, EDIT_TEXT },
{ IDD_GENERAL, IDT_VIDMEM, LTEXT },
{ IDD_GENERAL, IDB_TEXT, BUTTON },
{ IDD_GENERAL, IDB_LOW, BUTTON },
{ IDD_GENERAL, IDB_HIGH, BUTTON },
{ IDD_GENERAL, IDT_DOSMEM, LTEXT },
{ IDD_GENERAL, IDT_DOSMIN, LTEXT },
{ IDD_GENERAL, IDE_DOSMIN, EDIT, EDIT_OPTVAL, 128, 0, 640 },
{ IDD_GENERAL, IDT_DOSMAX, LTEXT },
{ IDD_GENERAL, IDE_DOSMAX, EDIT, EDIT_OPTVAL, 640, 0, 736 },
{ IDD_GENERAL, IDT_EMSMEM, LTEXT },
{ IDD_GENERAL, IDT_EMSMIN, LTEXT },
{ IDD_GENERAL, IDE_EMSMIN, EDIT, EDIT_RANGE, 0, 0, 16384 },
{ IDD_GENERAL, IDT_EMSMAX, LTEXT },
{ IDD_GENERAL, IDE_EMSMAX, EDIT, EDIT_OPTVAL, 1024, 0, 16384 },
{ IDD_GENERAL, IDT_XMSMEM, LTEXT },
{ IDD_GENERAL, IDT_XMSMIN, LTEXT },
{ IDD_GENERAL, IDE_XMSMIN, EDIT, EDIT_RANGE, 0, 0, 16384 },
{ IDD_GENERAL, IDT_XMSMAX, LTEXT },
{ IDD_GENERAL, IDE_XMSMAX, EDIT, EDIT_OPTVAL, 1024, 0, 16384 },
{ IDD_GENERAL, IDG_DISPLAY, GROUP },
{ IDD_GENERAL, IDB_FULLSCREEN, BUTTON },
{ IDD_GENERAL, IDB_WINDOWED, BUTTON },
{ IDD_GENERAL, IDG_EXEC, GROUP },
{ IDD_GENERAL, IDB_BACKEXEC, BUTTON },
{ IDD_GENERAL, IDB_EXCLEXEC, BUTTON },
{ IDD_GENERAL, IDB_ADVANCED, BUTTON },
{ IDD_GENERAL, IDB_CLOSEEXIT, BUTTON },
{ 0, LASTCONTROL, LASTCONTROL} // End of table marker
};
/****************************************************************************
*
* FUNCTION : WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
*
* PURPOSE : Main entry point from C runtime startup code
*
* ENTRY : HINSTANCE hInstance; // Handle of current instance
* HINSTANCE hPrevInstance;// Handle of previous instance
* LPSTR lpszCmdLine; // ==> command line tail
* int nCmdShow; // Parameter to ShowWindow()
*
* RETURNS : Return code from PostQuitMessage() or NULL
*
****************************************************************************/
int PASCAL WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmdLine, int nCmdShow)
{
FARPROC lpfn;
int rc;
char szTemp[ 256 ];
DWORD dwVersion;
if (!(GetWinFlags() & WF_PMODE)) { // Real mode
MessageBoxString(0, hInstance, IDS_REALMODE, MB_OK);
return (1);
}
/* Setup Globals */
memset(&Globals, 0, sizeof (Globals));
Globals.hInst = hInstance;
lstrcpy(Globals.szWindowTitle, "");
Globals.fUntitled = TRUE;
Globals.fCheckOnKillFocus = TRUE;
LoadString(Globals.hInst, IDS_APPNAME, Globals.szAppName, sizeof(Globals.szAppName));
LoadString(Globals.hInst, IDS_APPTITLE, Globals.szAppTitle, sizeof(Globals.szAppTitle));
LoadString(Globals.hInst, IDS_UNTITLED, Globals.szUntitled, sizeof(Globals.szUntitled));
LoadString(Globals.hInst, IDS_FILEMASK, Globals.szFilter, sizeof(Globals.szFilter));
{
PSTR p = Globals.szFilter;
while (*p) {
if (*p == '\n') *p = '\0';
p++;
}
}
// Initialize the COMMDLG OPENFILENAME structure
Globals.ofn.lStructSize = sizeof(OPENFILENAME);
Globals.ofn.lpstrFilter = Globals.szFilter;
Globals.ofn.nFilterIndex = 1;
Globals.hIcon = LoadIcon(Globals.hInst, MAKEINTRESOURCE(IDI_QIF));
lpfn = MakeProcInstance((FARPROC) PaneMsgProc, Globals.hInst);
rc = DialogBox(Globals.hInst, MAKEINTRESOURCE(IDD_FRAME), 0, (DLGPROC) lpfn);
FreeProcInstance(lpfn);
if (Globals.hFontHelp)
DeleteFont(Globals.hFontHelp);
return (rc);
} /* WinMain */
/****************************************************************************
*
* FUNCTION : CheckSave(HWND)
*
* PURPOSE : Compare original and current .PIF
* Ask user if they want to save changes if the two differ
*
* ENTRY : HWND hWnd; // Parent window handle
*
* RETURNS : 0 - No changes or user doesn't want to save 'em
* IDCANCEL - User wants to cancel the operation
* IDYES - User wants to save the changes
*
****************************************************************************/
int CheckSave(HWND hWnd)
{
register int rc;
char szBuf[128];
ControlsToPIF(hWnd);
if (memcmp(&Globals.pifModel, &Globals.pifBackup, sizeof(PIF))) { // It's changed
char szFmt[128];
LoadString(Globals.hInst, IDS_SAVECHANGES, szFmt, sizeof(szFmt));
wsprintf(szBuf, szFmt, (LPSTR) (Globals.fUntitled ? Globals.szUntitled : Globals.szFileTitle));
rc = MessageBox(hWnd, szBuf, Globals.szAppTitle, MB_YESNOCANCEL);
// Returns rc == IDYES, IDNO, or IDCANCEL
if (rc == IDCANCEL) { // User pressed CANCEL
return (IDCANCEL);
} else if (rc == IDYES) { // User pressed YES
return (MenuFileSave());
}
}
return (0);
}
/****************************************************************************
*
* FUNCTION : MenuFileNew(BOOL)
*
* PURPOSE : Process the File/New menu selection
* Start editting a fresh default .PIF
* Reset the window caption
*
* ENTRY : BOOL fCheck; // TRUE is CheckSave() required
*
* RETURNS : VOID
*
****************************************************************************/
void MenuFileNew(BOOL fCheck)
{
if (fCheck) {
if (CheckSave(Globals.hWndDlg) == IDCANCEL)
return;
}
lstrcpy(Globals.szWindowTitle, Globals.szAppTitle);
lstrcat(Globals.szWindowTitle, " - ");
lstrcat(Globals.szWindowTitle, Globals.szUntitled);
SetWindowText(Globals.hWndDlg, Globals.szWindowTitle);
Globals.fUntitled = TRUE;
DefaultPIF();
ControlsFromPIF(&Globals.pifModel, Globals.hWndDlg);
// We don't check the return code from ControlFromPIF() because we just
// created the default PIF models and we should be able to count on something
SnapPif();
}
/****************************************************************************
*
* FUNCTION : MenuFileOpen(VOID)
*
* PURPOSE : Process the File/Open menu selection
*
* ENTRY : VOID
*
* RETURNS : VOID
*
****************************************************************************/
VOID MenuFileOpen(VOID)
{
int rc;
PPIF pPIF = NULL;
rc = CheckSave(Globals.hWndDlg);
if (rc == IDCANCEL)
goto MENUFILEOPEN_EXIT;
if (OpenPIF()) { // Open didn't work
} else {
pPIF = (PPIF)LocalLock(Globals.hPIF);
if (!pPIF) {
MessageBoxString(Globals.hWndDlg, Globals.hInst, IDS_OUTOFMEMORY, MB_OK);
goto MENUFILEOPEN_EXIT;
}
rc = ControlsFromPIF(pPIF, Globals.hWndDlg);
if (rc) { // Couldn't set the controls
MenuFileNew(FALSE); // Don't check old contents
goto MENUFILEOPEN_EXIT;
}
ControlsToPIF(Globals.hWndDlg);
SnapPif();
}
MENUFILEOPEN_EXIT:
if (pPIF) { LocalUnlock(Globals.hPIF); pPIF = NULL; }
if (Globals.hPIF) { LocalFree(Globals.hPIF); Globals.hPIF = 0; }
return;
}
/****************************************************************************
*
* FUNCTION : MenuFileSave(VOID)
*
* PURPOSE : Process the File/Save menu selection
*
* ENTRY : VOID
*
* RETURNS : VOID
*
****************************************************************************/
int MenuFileSave(VOID)
{
register int rc;
if (Globals.szFile[0] == '\0') { // Untitled, use SaveAs
rc = SaveAsPIF(); // Save didn't work
} else {
rc = SavePIF(); // Save didn't work
}
// FIXME what if `rc' is set?
SnapPif();
return (rc);
}
/****************************************************************************
*
* FUNCTION : MenuFileSaveAs(VOID)
*
* PURPOSE : Process the File/SaveAs menu selection
*
* ENTRY : VOID
*
* RETURNS : VOID
*
****************************************************************************/
int MenuFileSaveAs(VOID)
{
SaveAsPIF();
// FIXME what is SaveAsPIF() returns an error
SnapPif();
return (0);
}
/****************************************************************************
*
* FUNCTION : CommDlgError(HWND, DWORD)
*
* PURPOSE : Convert a COMMDLG error code to a string in a message box
*
* ENTRY : HWND hWnd; // Parent window handle
* DWORD dwErrorCode; // COMMDLG error code
*
* RETURNS : VOID
*
****************************************************************************/
VOID CommDlgError(HWND hWnd, DWORD dwErrorCode)
{
register WORD id;
char szBuf[128]; // Buffer for LoadString
switch (dwErrorCode) {
case CDERR_DIALOGFAILURE: id = IDS_COMMDLGERR; break;
case CDERR_STRUCTSIZE: id = IDS_COMMDLGERR; break;
case CDERR_INITIALIZATION: id = IDS_COMMDLGERR; break;
case CDERR_NOTEMPLATE: id = IDS_COMMDLGERR; break;
case CDERR_NOHINSTANCE: id = IDS_COMMDLGERR; break;
case CDERR_LOADSTRFAILURE: id = IDS_COMMDLGERR; break;
case CDERR_FINDRESFAILURE: id = IDS_COMMDLGERR; break;
case CDERR_LOADRESFAILURE: id = IDS_COMMDLGERR; break;
case CDERR_LOCKRESFAILURE: id = IDS_COMMDLGERR; break;
case CDERR_MEMALLOCFAILURE: id = IDS_OUTOFMEMORY; break;
case CDERR_MEMLOCKFAILURE: id = IDS_OUTOFMEMORY; break;
case CDERR_NOHOOK: id = IDS_COMMDLGERR; break;
case PDERR_SETUPFAILURE: id = IDS_COMMDLGERR; break;
case PDERR_PARSEFAILURE: id = IDS_COMMDLGERR; break;
case PDERR_RETDEFFAILURE: id = IDS_COMMDLGERR; break;
case PDERR_LOADDRVFAILURE: id = IDS_COMMDLGERR; break;
case PDERR_GETDEVMODEFAIL: id = IDS_COMMDLGERR; break;
case PDERR_INITFAILURE: id = IDS_COMMDLGERR; break;
case PDERR_NODEVICES: id = IDS_COMMDLGERR; break;
case PDERR_NODEFAULTPRN: id = IDS_COMMDLGERR; break;
case PDERR_DNDMMISMATCH: id = IDS_COMMDLGERR; break;
case PDERR_CREATEICFAILURE: id = IDS_COMMDLGERR; break;
case PDERR_PRINTERNOTFOUND: id = IDS_COMMDLGERR; break;
case CFERR_NOFONTS: id = IDS_COMMDLGERR; break;
case FNERR_SUBCLASSFAILURE: id = IDS_COMMDLGERR; break;
case FNERR_INVALIDFILENAME: id = IDS_COMMDLGERR; break;
case FNERR_BUFFERTOOSMALL: id = IDS_COMMDLGERR; break;
case 0: // User may have hit CANCEL or we got a random error
default:
return;
}
if (!LoadString(Globals.hInst, id , szBuf, sizeof(szBuf))) {
MessageBox(hWnd, COMMDLGFAIL_STR, NULL, MB_ICONEXCLAMATION);
return;
}
MessageBox(hWnd, szBuf, Globals.szAppTitle, MB_OK);
}
/****************************************************************************
*
* FUNCTION : IsPifFile(LPCSTR)
*
* PURPOSE : Callback for open file common dialog to check on validity
* of file before closing the dialog when the user clicks OK.
*
* ENTRY : LPCSTR lpszFileSpec; // ==> filename
*
* RETURNS : TRUE if dialog should close
*
****************************************************************************/
BOOL IsPifFile(LPCSTR lpszFileSpec)
{
DWORD dwFileLen;
WORD wFileLen;
int rc;
DWORD dwVersion;
PIF pif;
PPIF pPIF;
OFSTRUCT OpenBuff;
HFILE hFile = OpenFile(lpszFileSpec, &OpenBuff, OF_READ);
if ((int) hFile == HFILE_ERROR) return (FALSE);
dwFileLen = _llseek(hFile, 0L, SEEK_END);
_llseek(hFile, 0L, SEEK_SET);
DebugPrintf("%s filesize is %6ld\r\n", lpszFileSpec, dwFileLen);
dwVersion = GetVersion();
if ((dwFileLen > sizeof(PIF)) && ((dwVersion & 0xFFFF) < 0x350L)) {
DebugPrintf("File is too big to be a valid .PIF\r\n", dwFileLen);
_lclose(hFile); return (FALSE);
} else {
wFileLen = (WORD) dwFileLen;
if (wFileLen <= sizeof(PIFHDR)) { // Old-style .PIF
DebugPrintf("This is an old Windows PIF");
_lclose(hFile); return (FALSE);
}
}
pPIF = &pif;
rc = _lread(hFile, (LPBYTE) pPIF, wFileLen);
if (rc != (int) wFileLen) {
DebugPrintf("OpenPIF() _lread(%d, %.4X:%.4X, %d) failed\r\n",
hFile, SELECTOROF((LPPIF) pPIF), OFFSETOF((LPPIF) pPIF), wFileLen);
_lclose(hFile); return (FALSE);
}
_lclose(hFile);
return (TRUE);
}
/****************************************************************************
*
* FUNCTION : GetOpenFileNameHookProc(HWND, UINT, WPARAM, LPARAM)
*
* PURPOSE : COMMDLG message hook procedure
* Use to get control when the user clicks 'OK' to check the
* validity of the .PIF
*
* ENTRY : HWND hWnd; // Window handle
* UINT msg; // WM_xxx message
* WPARAM wParam; // Message 16-bit parameter
* LPARAM lParam; // Message 32-bit parameter
*
* RETURNS : FALSE - Allow default COMMDLG message processing
* TRUE - Bypass default message processing
*
****************************************************************************/
UINT CALLBACK _export GetOpenFileNameHookProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
static LPOPENFILENAME lpofn;
static UINT msgFileOK;
if (msg == WM_INITDIALOG) {
lpofn = (LPOPENFILENAME) lParam;
msgFileOK = (UINT) LOWORD((DWORD) lpofn->lCustData);
} else if (msg == msgFileOK) {
if (IsPifFile(lpofn->lpstrFile)) {
return (FALSE); // Yes -- exit dialog
} else {
char szBuf[128], szFmt[128];
LoadString(Globals.hInst, IDS_NOTVALIDPIF , szFmt, sizeof(szFmt));
wsprintf(szBuf, szFmt, (LPSTR) lpofn->lpstrFile);
MessageBeep(MB_ICONEXCLAMATION);
MessageBox(hWnd, szBuf, Globals.szAppTitle, MB_ICONEXCLAMATION | MB_OK);
return (TRUE);
}
}
return (FALSE);
}
/****************************************************************************
*
* FUNCTION : OpenPif(VOID)
*
* PURPOSE : Helper function for MenuFileOpen()
* Does the dirty work of the COMMDLG GetOpenFileName()
* Reads the .PIF file in local memory
*
* ENTRY : VOID
*
* RETURNS : 0 - Normal return
* IDABORT - File system error
*
****************************************************************************/
int OpenPIF(VOID)
{
int rc;
OFSTRUCT OpenBuff;
UINT msgFileOK = RegisterWindowMessage(FILEOKSTRING);
WORD wPifLen;
DWORD dwPIFLen;
HCURSOR hCursorOld = 0;
HFILE hFilePIF = 0;
PPIF pPIF = NULL;
Globals.szFile[0] = '\0';
Globals.ofn.hwndOwner = Globals.hWndDlg;
Globals.ofn.lpstrFile = Globals.szFile;
Globals.ofn.nMaxFile = sizeof(Globals.szFile);
Globals.ofn.lpstrFileTitle = Globals.szFileTitle;
Globals.ofn.nMaxFileTitle = sizeof(Globals.szFileTitle);
Globals.ofn.lpstrInitialDir = Globals.szDirName;
Globals.ofn.lpstrDefExt = "PIF";
Globals.ofn.Flags = OFN_PATHMUSTEXIST |
OFN_FILEMUSTEXIST |
OFN_HIDEREADONLY |
OFN_ENABLEHOOK;
Globals.ofn.lpfnHook = (COMMDLGHOOKPROC) MakeProcInstance((FARPROC) GetOpenFileNameHookProc, Globals.hInst);
Globals.ofn.lCustData = MAKELPARAM(msgFileOK, 0);
rc = GetOpenFileName(&Globals.ofn);
FreeProcInstance((FARPROC) Globals.ofn.lpfnHook);
if (!rc) {
if (CommDlgExtendedError()) {
CommDlgError(Globals.hWndDlg, CommDlgExtendedError());
rc = IDABORT;
} else {
rc = IDCANCEL;
}
goto OPENPIF_EXIT;
}
lstrcpy(Globals.szWindowTitle, Globals.szAppTitle);
lstrcat(Globals.szWindowTitle, " - ");
lstrcat(Globals.szWindowTitle, Globals.szFileTitle);
SetWindowText(Globals.hWndDlg, Globals.szWindowTitle);
Globals.fUntitled = FALSE;
strncpy(Globals.szDirName, Globals.szFile, Globals.ofn.nFileOffset-1);
lstrcpy(Globals.szExtension, Globals.szFile + Globals.ofn.nFileExtension);
/* Switch to the hour glass cursor */
SetCapture(Globals.hWndDlg);
hCursorOld = SetCursor(LoadCursor(0, IDC_WAIT));
/* Open and read the file */
DebugPrintf("OpenPIF(): _lopen(%s, OF_READ)\r\n", (LPSTR) Globals.szFile);
hFilePIF = _lopen(Globals.szFile, OF_READ);
if ((int) hFilePIF == HFILE_ERROR) { // Can't open the .PIF
char szFmt[80];
DebugPrintf("OpenPIF() _lopen(%s, OF_READ) failed\r\n", (LPSTR) Globals.szFile);
LoadString(Globals.hInst, IDS_CANTOPEN , szFmt, sizeof(szFmt));
MessageBoxPrintf(szFmt, (LPSTR) Globals.szFile);
rc = IDABORT; goto OPENPIF_EXIT;
}
dwPIFLen = _llseek(hFilePIF, 0L, SEEK_END);
_llseek(hFilePIF, 0L, SEEK_SET);
DebugPrintf("%s filesize is %6ld\r\n", (LPSTR) Globals.szFile, dwPIFLen);
if (dwPIFLen >= 65520L) {
MessageBoxString(Globals.hWndDlg, Globals.hInst, IDS_TOOBIG, MB_OK);
rc = IDABORT; goto OPENPIF_EXIT;
} else {
wPifLen = (WORD) dwPIFLen;
// @todo And??? Why not load old PIFs???
if (wPifLen <= sizeof(PIFHDR)) { // Old-style .PIF
MessageBoxString(Globals.hWndDlg, Globals.hInst, IDS_OLDPIF, MB_OK);
rc = IDABORT; goto OPENPIF_EXIT;
}
}
Globals.hPIF = LocalAlloc(LMEM_MOVEABLE, wPifLen);
if (!Globals.hPIF) {
MessageBoxString(Globals.hWndDlg, Globals.hInst, IDS_OUTOFMEMORY, MB_OK);
rc = IDABORT; goto OPENPIF_EXIT;
}
pPIF = (PPIF)LocalLock(Globals.hPIF);
if (!pPIF) {
MessageBoxString(Globals.hWndDlg, Globals.hInst, IDS_OUTOFMEMORY, MB_OK);
rc = IDABORT; goto OPENPIF_EXIT;
}
rc = _lread(hFilePIF, (LPBYTE) pPIF, wPifLen);
if (rc != (int) wPifLen) {
MessageBoxPrintf( CANTREAD_STR );
DebugPrintf("OpenPIF() _lread(%d, %.4X:%.4X, %d) failed\r\n",
hFilePIF,
SELECTOROF((LPPIF) pPIF),
OFFSETOF((LPPIF) pPIF),
wPifLen
);
rc = IDABORT; goto OPENPIF_EXIT;
}
if (pPIF) { LocalUnlock(Globals.hPIF); pPIF = NULL; }
OPENPIF_EXIT:
if (hCursorOld) {
SetCursor(hCursorOld);
ReleaseCapture();
}
if (pPIF) { LocalUnlock(Globals.hPIF); pPIF = NULL; }
if (hFilePIF > 0) _lclose(hFilePIF);
return (rc);
}
/****************************************************************************
*
* FUNCTION : CheckPIFValidity(BOOL fMustBeValid)
*
* PURPOSE : Checks .PIF model for consistent data
* Presents a message box to the user if the data is invalid
*
* ENTRY : BOOL fMustBeValid; // Don't return 0 unless PIF is OK
*
* RETURNS : 0 - Normal return
* IDCANCEL - Data was invalid, but user said go ahead
*
* Assumes ControlToPIF() has already been called
*
****************************************************************************/
int CheckPIFValidity(BOOL fMustBeValid)
{
int n;
int rc;
char szPathname[_MAX_PATH]; // Buffer to hold full filename
char szDrive[_MAX_DRIVE]; // Drive letter and colon
char szDir[_MAX_DIR]; // Directory
char szFname[_MAX_FNAME]; // Filename w/o extension
char szExt[_MAX_EXT]; // Filename extension
char szBuf[128];
// Checkout the program filename
if (!*SkipWhite(Globals.pifModel.pifHdr.PgmName)) {
LoadString(Globals.hInst, IDS_FILENAMEREQ , szBuf, sizeof(szBuf));
MSGBOXCOM:
rc = MessageBox(0, szBuf, Globals.szAppTitle, MB_OKCANCEL | MB_DEFBUTTON2 | MB_ICONEXCLAMATION);
CHECK_VALID_COM:
if (fMustBeValid)
return (IDCANCEL);
if (rc == IDCANCEL)
return (rc);
}
_fullpath(szPathname,Globals.pifModel.pifHdr.PgmName, _MAX_PATH);
_splitpath(szPathname, szDrive, szDir, szFname, szExt);
n = lstrlen(szFname);
if (n == 0 || n > 8 || (lstrcmpi(szExt, ".BAT") && lstrcmpi(szExt, ".COM") && lstrcmpi(szExt, ".EXE") )) {
LoadString(Globals.hInst, IDS_BADFILENAME , szBuf, sizeof(szBuf));
goto MSGBOXCOM;
}
if (!ValidateHotKey(FALSE)) goto CHECK_VALID_COM;
return (0);
}
/****************************************************************************
*
* FUNCTION : SavePIF(VOID)
*
* PURPOSE : Helper function for SaveAsPIF() and MenuFileSave()
*
* ENTRY : VOID
*
* RETURNS : Return code from lower-level functions
*
****************************************************************************/
int SavePIF(VOID)
{
register int rc;
ControlsToPIF(Globals.hWndDlg);
rc = CheckPIFValidity(FALSE);
if (rc) return (rc);
return (WritePIF(Globals.hWndDlg, Globals.szFile));
}
/****************************************************************************
*
* FUNCTION : SaveAsPIF(VOID)
*
* PURPOSE : Helper function for MenuFileSave() and MenuFileSaveAs()
* Does the dirty work of GetSaveFileName()
* Write out the .PIF
*
* ENTRY : VOID
*
* RETURNS : Return code from lower-level functions
*
****************************************************************************/
int SaveAsPIF(VOID)
{
Globals.szFile[0] = '\0';
Globals.ofn.hwndOwner = Globals.hWndDlg;
Globals.ofn.lpstrFile = Globals.szFile;
Globals.ofn.nMaxFile = sizeof(Globals.szFile);
Globals.ofn.lpstrFileTitle = Globals.szFileTitle;
Globals.ofn.nMaxFileTitle = sizeof(Globals.szFileTitle);
Globals.ofn.lpstrInitialDir = Globals.szDirName;
Globals.ofn.lpstrDefExt = "PIF";
Globals.ofn.Flags = OFN_PATHMUSTEXIST |
OFN_HIDEREADONLY |
OFN_OVERWRITEPROMPT;
if (!GetSaveFileName(&Globals.ofn)) {
if (CommDlgExtendedError() == 0) return (IDCANCEL);
CommDlgError(Globals.hWndDlg, CommDlgExtendedError());
return (1);
}
lstrcpy(Globals.szWindowTitle, Globals.szAppTitle);
lstrcat(Globals.szWindowTitle, " - ");
lstrcat(Globals.szWindowTitle, Globals.szFileTitle);
SetWindowText(Globals.hWndDlg, Globals.szWindowTitle);
strncpy(Globals.szDirName, Globals.szFile, Globals.ofn.nFileOffset-1);
lstrcpy(Globals.szExtension, Globals.szFile + Globals.ofn.nFileExtension);
Globals.fUntitled = FALSE;
return (SavePIF());
}
/****************************************************************************
*
* FUNCTION : PaneMsgProc(HWND, UINT, WPARAM, LPARAM)
*
* PURPOSE : Dialog proc for the frame and panes
*
* ENTRY : HWND hWndDlg; // Dialog window handle
* UINT msg; // WM_xxx message
* WPARAM wParam; // Message 16-bit parameter
* LPARAM lParam; // Message 32-bit parameter
*
* RETURNS : Non-zero - Message processed
* Zero - DefDlgProc() must process the message
*
****************************************************************************/
BOOL CALLBACK _export PaneMsgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
char szBuf[128];
WINDOWPLACEMENT wndpl;
switch (msg) {
case WM_ACTIVATEAPP:
Globals.fCheckOnKillFocus = (BOOL) wParam;
break;
case WM_ACTIVATE:
Globals.fCheckOnKillFocus = (wParam != WA_INACTIVE);
break;
case WM_CLOSE:
{
if (IDCANCEL == CheckSave(hWnd)) break;
Globals.fCheckOnKillFocus = FALSE; // Stop checking controls
if (Globals.nActiveDlg) { // A dialog is still open
SetFocus(hWnd);
Globals.nActiveDlg = 0;
}
EndDialog(hWnd, IDCANCEL);
Globals.nActiveDlg = 0;
}
break;
case WM_COMMAND:
Pane_OnCommand(hWnd, (UINT) wParam, (HWND) LOWORD(lParam), (WORD) HIWORD(lParam));
return (FALSE);
case WM_CTLCOLOR:
{
HDC hDC = (HDC) wParam;
HWND hWndChild = (HWND) LOWORD(lParam);
if (GetDlgItem(hWnd, IDD_HELP) != hWndChild) return FALSE;
switch ((UINT) HIWORD(lParam)) {
case CTLCOLOR_EDIT:
SetBkColor(hDC, GetSysColor(COLOR_BTNFACE));
return ((BOOL) (WORD) Globals.hbrHelp);
case CTLCOLOR_MSGBOX:
return ((BOOL) (WORD) Globals.hbrHelp);
}
return FALSE;
}
case WM_DESTROY:
{
if (Globals.hbrHelp) { DeleteBrush(Globals.hbrHelp); Globals.hbrHelp = 0; }
return (FALSE);
}
case WM_SIZE:
if (wParam == SIZE_MINIMIZED) {
//SetWindowText(hWnd, APPNAME);
} else if (wParam == SIZE_MAXIMIZED || wParam == SIZE_RESTORED) {
//SetWindowText(hWnd, szWindowTitle);
}
return (FALSE); // Requires default processing
case WM_ERASEBKGND:
if (IsIconic(hWnd)) {
return (TRUE); // Pretend we erased it
} else {
return (FALSE); // We didn't erase anything
}
case WM_INITDIALOG:
return (Pane_OnInitDialog(hWnd, (HWND) wParam, lParam));
case WM_PAINT:
if (IsIconic(hWnd)) {
Pane_OnPaint_Iconic(hWnd);
} else {
Pane_OnPaint(hWnd);
}
return (FALSE);
case WM_SETFONT:
Pane_OnSetFont(hWnd, (HFONT) wParam, (BOOL) LOWORD(lParam));
return (FALSE);
}
return (FALSE);
}
/****************************************************************************
*
* FUNCTION : Pane_OnCommand(HWND, UINT, HWND, WORD)
*
* PURPOSE : Process the WM_COMMAND messages sent to PaneMsgProc()
* Processes all the menu selections and button clicks
*
* ENTRY : HWND hWnd; // Parent window handle
* UINT id; // Control ID
* HWND hWndCtl; // Contro window handle
* WORD codeNotify; // 1- if accelerator, 0 - menu
*
* RETURNS : VOID
*
****************************************************************************/
VOID Pane_OnCommand(HWND hWnd, UINT id, HWND hWndCtl, WORD codeNotify)
{
switch (id) {
case IDOK:
case IDCANCEL:
MessageBeep(0xFFFF);
break;