forked from microsoft/Microsoft-3D-Movie-Maker
-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathutest.cpp
4690 lines (4032 loc) · 131 KB
/
utest.cpp
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
/* Copyright (c) Microsoft Corporation.
Licensed under the MIT License. */
/***************************************************************************
utest.cpp: Socrates main app class
Primary Author: ******
Review Status: REVIEWED - any changes to this file must be reviewed!
The APP class handles initialization of the product, and global
actions such as resolution-switching, switching between the building
and the studio, and quitting.
The KWA (App KidWorld) is the parent of the gob tree in the product.
It also is used to display a splash screen, and to find AVIs on the CD.
***************************************************************************/
#include "studio.h"
#include "socres.h"
#include "mminstal.h"
ASSERTNAME
// If the following value is defined, 3DMM displays the dlidDesktopResizing
// and dlidDesktopResized dialogs before and immediately after res-switching.
// The current thought is that these dialogs are unnecessary since we only
// res-switch to 640x480, which should always be safe. We still display a
// dialog if the res-switch failed (dlidDesktopWontResize).
// #define RES_SWITCH_DIALOGS
// If the following value is defined, 3DMM does a run-time performance test
// of the graphics, fixed-point math, and copying speed at startup and sets
// _fSlowCPU to fTrue if it thinks 3DMM is running on a slow computer.
// The current feeling is that we don't have the resources to tweak the
// thresholds and verify that this gives us the result we want on all
// computers.
//#define PERF_TEST
// Duration to display homelogo
const ulong kdtsHomeLogo = 4 * kdtsSecond;
// Duration to display splash screen
const ulong kdtsSplashScreen = 4 * kdtsSecond;
// Duration before res-switch dialog cancels itself
const ulong kdtsMaxResSwitchDlg = 15 * kdtsSecond;
// 2MB cache per source for TAGM
const ulong kcbCacheTagm = 2048 * 1024;
static PSZ kpszAppWndCls = PszLit("3DMOVIE");
const PSZ kpszOpenFile = PszLit("3DMMOpen.tmp");
const long klwOpenDoc = 0x12123434; // arbitrary wParam for WM_USER
BEGIN_CMD_MAP(APP, APPB)
ON_CID_GEN(cidInfo, &APP::FCmdInfo, pvNil)
ON_CID_GEN(cidLoadStudio, &APP::FCmdLoadStudio, pvNil)
ON_CID_GEN(cidLoadBuilding, &APP::FCmdLoadBuilding, pvNil)
ON_CID_GEN(cidTheaterOpen, &APP::FCmdTheaterOpen, pvNil)
ON_CID_GEN(cidTheaterClose, &APP::FCmdTheaterClose, pvNil)
ON_CID_GEN(cidPortfolioOpen, &APP::FCmdPortfolioOpen, pvNil)
ON_CID_GEN(cidPortfolioClear, &APP::FCmdPortfolioClear, pvNil)
ON_CID_GEN(cidDisableAccel, &APP::FCmdDisableAccel, pvNil)
ON_CID_GEN(cidEnableAccel, &APP::FCmdEnableAccel, pvNil)
ON_CID_GEN(cidInvokeSplot, &APP::FCmdInvokeSplot, pvNil)
ON_CID_GEN(cidExitStudio, &APP::FCmdExitStudio, pvNil)
ON_CID_GEN(cidDeactivate, &APP::FCmdDeactivate, pvNil)
END_CMD_MAP_NIL()
APP vapp;
PTAGM vptagm;
RTCLASS(APP)
RTCLASS(KWA)
/***************************************************************************
Entry point for a Kauai-based app.
***************************************************************************/
void FrameMain(void)
{
Debug(vcactAV = 2;) // Speeds up the debug build
vapp.Run(fappOffscreen, fgobNil, kginMark);
}
/******************************************************************************
Run
Overridden APPB::Run method, so that we can attempt to recover
gracefully from a crash.
Arguments:
ulong grfapp -- app flags
ulong grfgob -- GOB flags
long ginDef -- default GOB invalidation
************************************************************ PETED ***********/
void APP::Run(ulong grfapp, ulong grfgob, long ginDef)
{
/* Don't bother w/ AssertThis; we'd have to use AssertBaseThis, or
possibly the parent's AssertValid, which gets done almost right
away anyway */
_CleanupTemp();
__try
{
APP_PAR::Run(grfapp, grfgob, ginDef);
}
__except (UnhandledExceptionFilter(GetExceptionInformation()))
{
PDLG pdlg;
pdlg = DLG::PdlgNew(dlidAbnormalExit, pvNil, pvNil);
if (pdlg != pvNil)
{
pdlg->IditDo();
ReleasePpo(&pdlg);
}
_fQuit = fTrue;
MVU::RestoreKeyboardRepeat();
#ifdef WIN
ClipCursor(NULL);
#endif // WIN
_CleanUp();
}
}
/***************************************************************************
Get the name for the app. Note that the string comes from a resource
in the exe rather than a chunky file since the app name is needed
before any chunky files are opened. The app name should not change
even for different products, i.e., Socrates and Playdo will have
different _stnProduct, but the same _stnAppName.
***************************************************************************/
void APP::GetStnAppName(PSTN pstn)
{
AssertBaseThis(0);
AssertPo(pstn, 0);
if (_stnAppName.Cch() == 0)
{
#ifdef WIN
SZ sz;
if (0 != LoadString(vwig.hinst, stidAppName, sz, kcchMaxSz))
_stnAppName = sz;
else
Warn("Couldn't read app name");
#else // MAC
RawRtn();
#endif // MAC
}
*pstn = _stnAppName;
}
#ifdef DEBUG
struct DBINFO
{
long cactAV;
};
#endif // DEBUG
/***************************************************************************
Init the APP
***************************************************************************/
bool APP::_FInit(ulong grfapp, ulong grfgob, long ginDef)
{
AssertBaseThis(0);
ulong tsHomeLogo;
ulong tsSplashScreen;
FNI fniUserDoc;
long fFirstTimeUser;
// Only allow one copy of 3DMM to run at a time:
if (_FAppAlreadyRunning())
{
_TryToActivateWindow();
_fDontReportInitFailure = fTrue;
goto LFail;
}
#ifdef DEBUG
{
DBINFO dbinfo;
dbinfo.cactAV = vcactAV;
if (FGetSetRegKey(PszLit("DebugSettings"), &dbinfo, size(DBINFO), fregSetDefault | fregBinary))
{
vcactAV = dbinfo.cactAV;
}
}
#endif // DEBUG
if (!_FEnsureOS())
{
_FGenericError(PszLit("_FEnsureOS"));
_fDontReportInitFailure = fTrue;
goto LFail;
}
if (!_FEnsureAudio())
{
_FGenericError(PszLit("_FEnsureAudio"));
_fDontReportInitFailure = fTrue;
goto LFail;
}
if (!_FEnsureVideo())
{
_FGenericError(PszLit("_FEnsureVideo"));
_fDontReportInitFailure = fTrue;
goto LFail;
}
_ParseCommandLine();
// If _ParseCommandLine doesn't set _stnProduct, set to 3dMovieMaker
if (!_FEnsureProductNames())
{
_FGenericError(PszLit("_FEnsureProductNames"));
_fDontReportInitFailure = fTrue;
goto LFail;
}
if (!_FFindMsKidsDir())
{
_FGenericError(PszLit("_FFindMsKidsDir"));
_fDontReportInitFailure = fTrue;
goto LFail;
}
// Init product names for tagman & _fniProductDir & potentially _stnProduct
if (!_FInitProductNames())
{
// _FInitProductNames prints its own errors
_fDontReportInitFailure = fTrue;
goto LFail;
}
if (!_FOpenResourceFile())
{
_FGenericError(PszLit("_FOpenResourceFile"));
_fDontReportInitFailure = fTrue;
goto LFail;
}
if (!_FReadStringTables())
{
_FGenericError(PszLit("_FReadStringTables"));
_fDontReportInitFailure = fTrue;
goto LFail;
}
if (!_FEnsureDisplayResolution())
{ // may call _FInitOS
_FGenericError(PszLit("_FEnsureDisplayResolution"));
_fDontReportInitFailure = fTrue;
goto LFail;
}
if (!_FEnsureColorDepth())
{
_FGenericError(PszLit("_FEnsureColorDepth"));
_fDontReportInitFailure = fTrue;
goto LFail;
}
if (!APP_PAR::_FInit(grfapp, grfgob, ginDef))
{ // calls _FInitOS
_FGenericError(PszLit("APP_PAR::_FInit"));
_fDontReportInitFailure = fTrue;
goto LFail;
}
/* Ensure default font. Do it here just so we get the error reported
early. */
OnnDefVariable();
if (!_FInitKidworld())
{
_FGenericError(PszLit("_FInitKidworld"));
_fDontReportInitFailure = fTrue;
goto LFail;
}
if (!_FDisplayHomeLogo())
{
_FGenericError(PszLit("_FDisplayHomeLogo"));
_fDontReportInitFailure = fTrue;
goto LFail;
}
tsHomeLogo = TsCurrent();
if (!_FDetermineIfSlowCPU())
{
_FGenericError(PszLit("_FDetermineIfSlowCPU"));
_fDontReportInitFailure = fTrue;
goto LFail;
}
if (!_FInitTdt())
{
_FGenericError(PszLit("_FInitTdt"));
_fDontReportInitFailure = fTrue;
goto LFail;
}
if (!MTRL::FSetShadeTable(_pcfl, kctgTmap, 0))
{
_FGenericError(PszLit("FSetShadeTable"));
_fDontReportInitFailure = fTrue;
goto LFail;
}
while (TsCurrent() - tsHomeLogo < kdtsHomeLogo)
; // spin until home logo has been up long enough
if (!_FShowSplashScreen())
{
_FGenericError(PszLit("_FShowSplashScreen"));
_fDontReportInitFailure = fTrue;
goto LFail;
}
tsSplashScreen = TsCurrent();
if (!_FPlaySplashSound())
{
_FGenericError(PszLit("_FPlaySplashSound"));
_fDontReportInitFailure = fTrue;
goto LFail;
}
if (!_FGetUserName())
{
_FGenericError(PszLit("_FGetUserName"));
_fDontReportInitFailure = fTrue;
goto LFail;
}
if (!_FGetUserDirectories())
{
_FGenericError(PszLit("_FGetUserDirectories"));
_fDontReportInitFailure = fTrue;
goto LFail;
}
if (!_FReadUserData())
{
_FGenericError(PszLit("_FReadUserData"));
_fDontReportInitFailure = fTrue;
goto LFail;
}
if (!_FInitCrm())
{
_FGenericError(PszLit("_FInitCrm"));
_fDontReportInitFailure = fTrue;
goto LFail;
}
while (TsCurrent() - tsSplashScreen < kdtsSplashScreen)
; // spin until splash screen has been up long enough
Pkwa()->SetMbmp(pvNil); // bring down splash screen
// If the user specified a doc on the command line, go straight
// to the studio. Otherwise, start the building.
GetPortfolioDoc(&fniUserDoc);
if (fniUserDoc.Ftg() == ftgNil)
{
// Startup place depends on whether this is the user's first time in.
if (!FGetProp(kpridFirstTimeUser, &fFirstTimeUser))
{
_FGenericError(PszLit("FGetProp: kpridFirstTimeUser"));
_fDontReportInitFailure = fTrue;
goto LFail;
}
if (!FSetProp(kpridBuildingGob, (fFirstTimeUser ? kgobCloset : kgobLogin)))
{
_FGenericError(PszLit("FSetProp: kpridBuildingGob"));
_fDontReportInitFailure = fTrue;
goto LFail;
}
if (!_FInitBuilding())
{
_FGenericError(PszLit("_FInitBuilding"));
_fDontReportInitFailure = fTrue;
goto LFail;
}
}
else
{
if (!FSetProp(kpridBuildingGob, kgobStudio1))
{
_FGenericError(PszLit("FSetProp: kpridBuildingGob"));
_fDontReportInitFailure = fTrue;
goto LFail;
}
if (!_FInitStudio(&fniUserDoc, fFalse))
{
_FGenericError(PszLit("_FInitStudio"));
_fDontReportInitFailure = fTrue;
goto LFail;
}
}
EnsureInteractive();
return fTrue;
LFail:
_fQuit = fTrue;
if (_fSwitchedResolution)
{
if (_FSwitch640480(fFalse)) // try to restore desktop
_fSwitchedResolution = fFalse;
}
// _fDontReportInitFailure will be true if one of the above functions
// has already posted an alert explaining why the app is shutting down.
// If it's false, we put up a OOM or generic error dialog.
if (!_fDontReportInitFailure)
{
PDLG pdlg;
if (vpers->FIn(ercOomHq) || vpers->FIn(ercOomPv) || vpers->FIn(ercOomNew))
pdlg = DLG::PdlgNew(dlidInitFailedOOM, pvNil, pvNil);
else
pdlg = DLG::PdlgNew(dlidInitFailed, pvNil, pvNil);
if (pvNil != pdlg)
pdlg->IditDo();
ReleasePpo(&pdlg);
}
return fFalse;
}
/******************************************************************************
_CleanupTemp
Removes any temp files leftover from a previous execution.
************************************************************ PETED ***********/
void APP::_CleanupTemp(void)
{
FNI fni;
/* Attempt to cleanup any leftovers from a previous bad exit */
vftgTemp = kftgSocTemp;
if (fni.FGetTemp())
{
FTG ftgTmp = vftgTemp;
FNE fne;
if (fne.FInit(&fni, &ftgTmp, 1))
{
bool fFlushErs = fFalse;
while (fne.FNextFni(&fni))
{
if (!fni.FDelete())
fFlushErs = fTrue;
}
if (fFlushErs)
vpers->Flush(ercFniDelete);
}
}
}
/***************************************************************************
Determine if another copy of 3DMM is already running by trying to
create a named semaphore.
***************************************************************************/
bool APP::_FAppAlreadyRunning(void)
{
AssertBaseThis(0);
#ifdef WIN
HANDLE hsem;
STN stn;
GetStnAppName(&stn);
hsem = CreateSemaphore(NULL, 0, 1, stn.Psz());
if (hsem != NULL && GetLastError() == ERROR_ALREADY_EXISTS)
{
CloseHandle(hsem);
return fTrue;
}
#endif // WIN
#ifdef MAC
RawRtn();
#endif // MAC
return fFalse;
}
/***************************************************************************
Try to find another instance of 3DMM and bring its window to front
Also, if a document was on the command line, notify the other instance
***************************************************************************/
void APP::_TryToActivateWindow(void)
{
AssertBaseThis(0);
#ifdef WIN
HWND hwnd;
STN stn;
FNI fniUserDoc;
GetStnAppName(&stn);
hwnd = FindWindow(kpszAppWndCls, stn.Psz());
if (NULL != hwnd)
{
SetForegroundWindow(hwnd);
ShowWindow(hwnd, SW_RESTORE); // in case it was minimized
_ParseCommandLine();
GetPortfolioDoc(&fniUserDoc);
if (fniUserDoc.Ftg() != ftgNil)
_FSendOpenDocCmd(hwnd, &fniUserDoc); // ignore failure
}
#endif // WIN
#ifdef MAC
RawRtn();
#endif // MAC
}
/***************************************************************************
If we're not running on at least Win95 or NT 3.51, complain and return
fFalse.
***************************************************************************/
bool APP::_FEnsureOS(void)
{
AssertBaseThis(0);
#ifdef WIN
DWORD dwVersion;
byte bVersionMajor;
byte bVersionMinor;
PDLG pdlg;
dwVersion = GetVersion();
bVersionMinor = (byte)((dwVersion & 0x0000ff00) >> 8);
bVersionMajor = (byte)(dwVersion & 0x000000ff);
if (bVersionMajor >= 4 || (bVersionMajor == 3 && bVersionMinor >= 51))
return fTrue;
// Put up an alert: OS too old
pdlg = DLG::PdlgNew(dlidBadOS, pvNil, pvNil);
if (pvNil == pdlg)
return fFalse;
pdlg->IditDo();
ReleasePpo(&pdlg);
_fDontReportInitFailure = fTrue;
#endif // WIN
#ifdef MAC
RawRtn();
#endif // MAC
return fFalse; // Bad OS
}
/***************************************************************************
Notifies the user if there is no suitable wave-out and/or midi-out
hardware.
***************************************************************************/
bool APP::_FEnsureAudio(void)
{
AssertBaseThis(0);
#ifdef WIN
long cwod; // count of wave-out devices
long cmod; // count of midi-out devices
bool fShowMessage;
PDLG pdlg;
cwod = waveOutGetNumDevs();
if (cwod <= 0)
{
fShowMessage = fTrue;
if (!FGetSetRegKey(kszWaveOutMsgValue, &fShowMessage, size(fShowMessage), fregSetDefault | fregMachine))
{
Warn("Registry query failed");
}
if (fShowMessage)
{
// Put up an alert: no waveout
pdlg = DLG::PdlgNew(dlidNoWaveOut, pvNil, pvNil);
if (pvNil == pdlg)
return fFalse;
pdlg->IditDo();
fShowMessage = !pdlg->FGetCheck(1); // 1 is ID of checkbox
ReleasePpo(&pdlg);
if (!fShowMessage)
{
// ignore failure
FGetSetRegKey(kszWaveOutMsgValue, &fShowMessage, size(fShowMessage), fregSetKey | fregMachine);
}
}
}
if (HWD_SUCCESS == wHaveWaveDevice(WAVE_FORMAT_2M08)) // 22kHz, Mono, 8bit is our minimum
{
if (wHaveACM())
{
// audio compression manager (sound mapper) not installed
wInstallComp(IC_ACM);
_fDontReportInitFailure = fTrue;
return fFalse;
}
if (wHaveACMCodec(WAVE_FORMAT_ADPCM))
{
// audio codecs not installed
wInstallComp(IC_ACM_ADPCM);
_fDontReportInitFailure = fTrue;
return fFalse;
}
} // have wave device
cmod = midiOutGetNumDevs();
if (cmod <= 0)
{
fShowMessage = fTrue;
if (!FGetSetRegKey(kszMidiOutMsgValue, &fShowMessage, size(fShowMessage), fregSetDefault | fregMachine))
{
Warn("Registry query failed");
}
if (fShowMessage)
{
// Put up an alert: no midiout
pdlg = DLG::PdlgNew(dlidNoMidiOut, pvNil, pvNil);
if (pvNil == pdlg)
return fFalse;
pdlg->IditDo();
fShowMessage = !pdlg->FGetCheck(1); // 1 is ID of checkbox
ReleasePpo(&pdlg);
if (!fShowMessage)
{
// ignore failure
FGetSetRegKey(kszMidiOutMsgValue, &fShowMessage, size(fShowMessage), fregSetKey | fregMachine);
}
}
}
#endif // WIN
#ifdef MAC
RawRtn();
#endif // MAC
return fTrue;
}
/***************************************************************************
Notifies the user if there is no suitable video playback devices
***************************************************************************/
bool APP::_FEnsureVideo(void)
{
if (wHaveMCI("AVIVIDEO"))
{
// MCI for video is not installed
wInstallComp(IC_MCI_VFW);
_fDontReportInitFailure = fTrue;
return fFalse;
}
if (HIC_SUCCESS != wHaveICMCodec(MS_VIDEO1))
{
// video 1 codec not installed
wInstallComp(IC_ICM_VIDEO1);
_fDontReportInitFailure = fTrue;
return fFalse;
}
return fTrue;
}
/***************************************************************************
Returns fTrue if color depth is >= 8 bits per pixel. User is alerted
if depth is less than 8, and function fails. User is warned if depth
is greater than 8, unless he has clicked the "don't show this messsage
again" in the dialog before.
***************************************************************************/
bool APP::_FEnsureColorDepth(void)
{
AssertBaseThis(0);
#ifdef WIN
HDC hdc;
long cbitPixel;
PDLG pdlg;
bool fShowMessage;
bool fDontShowAgain = fFalse;
hdc = GetDC(NULL);
if (NULL == hdc)
return fFalse;
cbitPixel = GetDeviceCaps(hdc, BITSPIXEL);
ReleaseDC(NULL, hdc);
if (cbitPixel < 8)
{
// Put up an alert: Not enough colors
pdlg = DLG::PdlgNew(dlidNotEnoughColors, pvNil, pvNil);
if (pvNil == pdlg)
return fFalse;
pdlg->IditDo();
ReleasePpo(&pdlg);
_fDontReportInitFailure = fTrue;
return fFalse;
}
/* FOONE: It's the future, we don't need to worry about running in true-color mode.
if (cbitPixel > 8)
{
// warn user
fShowMessage = fTrue;
if (!FGetSetRegKey(kszGreaterThan8bppMsgValue, &fShowMessage,
size(fShowMessage), fregSetDefault))
{
Warn("Registry query failed");
}
if (fShowMessage)
{
pdlg = DLG::PdlgNew(dlidTooManyColors, pvNil, pvNil);
if (pvNil != pdlg)
{
pdlg->IditDo();
fDontShowAgain = pdlg->FGetCheck(1); // 1 is ID of checkbox
}
ReleasePpo(&pdlg);
if (fDontShowAgain)
{
fShowMessage = fFalse;
FGetSetRegKey(kszGreaterThan8bppMsgValue, &fShowMessage,
size(fShowMessage), fregSetKey); // ignore failure
}
}
}
*/
#endif // WIN
#ifdef MAC
RawRtn();
#endif // MAC
return fTrue;
}
/***************************************************************************
Dialog proc for Resolution Switch dialog. Return fTrue (bring down
the dialog) if kdtsMaxResSwitchDlg has passed since the dialog was
created.
***************************************************************************/
bool _FDlgResSwitch(PDLG pdlg, long *pidit, void *pv)
{
AssertPo(pdlg, 0);
AssertVarMem(pidit);
AssertPvCb(pv, size(long));
long tsResize = *(long *)pv;
long tsCur;
if (*pidit != ivNil)
{
return fTrue; // Cancel or OK pressed
}
else
{
tsCur = TsCurrent();
if (tsCur - tsResize >= kdtsMaxResSwitchDlg)
return fTrue;
}
return fFalse;
}
/***************************************************************************
Ensure that the screen is at the user's preferred resolution for 3DMM.
If user has no registry preference, we offer to switch, try to switch,
and save user's preference. Registry failures are non-fatal, but
failing to create the main window causes this function to fail.
When this function returns, _fRunInWindow is set correctly and the
main app window *might* be created.
***************************************************************************/
bool APP::_FEnsureDisplayResolution(void)
{
AssertBaseThis(0);
PDLG pdlg;
long idit;
bool fSwitchRes;
bool fNoValue;
long tsResize;
if (_FDisplayIs640480())
{
// System is already 640x480, so ignore registry and run fullscreen
_fRunInWindow = fFalse;
return fTrue;
}
if (!_FDisplaySwitchSupported())
{
// System can't switch res, so ignore registry and run in a window
_fRunInWindow = fTrue;
return fTrue;
}
// See if there's a res switch preference in the registry
if (!FGetSetRegKey(kszSwitchResolutionValue, &fSwitchRes, size(fSwitchRes), fregNil, &fNoValue))
{
// Registry error...just run in a window
_fRunInWindow = fTrue;
return fTrue;
}
if (!fNoValue)
{
// User has a preference
if (!fSwitchRes)
{
_fRunInWindow = fTrue;
return fTrue;
}
else // try to switch res
{
_fRunInWindow = fFalse;
if (!_FInitOS())
{
// we're screwed
return fFalse;
}
if (!_FSwitch640480(fTrue))
{
_fRunInWindow = fTrue;
_RebuildMainWindow();
goto LSwitchFailed;
}
return fTrue;
}
}
// User doesn't have a preference yet. Do the interactive thing.
#ifdef RES_SWITCH_DIALOGS
pdlg = DLG::PdlgNew(dlidDesktopResizing, pvNil, pvNil);
if (pvNil == pdlg)
return fFalse;
idit = pdlg->IditDo();
ReleasePpo(&pdlg);
#else //! RES_SWITCH_DIALOGS
idit = 2; // OK
#endif //! RES_SWITCH_DIALOGS
if (idit == 1) // cancel
{
_fRunInWindow = fTrue;
// try to set pref to fFalse
fSwitchRes = fFalse;
goto LWriteReg;
}
_fRunInWindow = fFalse;
if (!_FInitOS())
return fFalse;
if (!_FSwitch640480(fTrue))
{
_fRunInWindow = fTrue;
_RebuildMainWindow();
goto LSwitchFailed;
}
tsResize = TsCurrent();
#ifdef RES_SWITCH_DIALOGS
pdlg = DLG::PdlgNew(dlidDesktopResized, _FDlgResSwitch, &tsResize);
idit = ivNil; // if dialog fails to come up, treat like a cancel
if (pvNil != pdlg)
idit = pdlg->IditDo();
ReleasePpo(&pdlg);
#else //! RES_SWITCH_DIALOGS
idit = 2; // OK
#endif //! RES_SWITCH_DIALOGS
if (idit == 1 || idit == ivNil) // cancel or timeout or dialog failure
{
_fSwitchedResolution = fFalse;
_fRunInWindow = fTrue;
_RebuildMainWindow();
if (!_FSwitch640480(fFalse)) // restore desktop resolution
return fFalse;
goto LSwitchFailed;
}
// try to set pref to fTrue
fSwitchRes = fTrue;
goto LWriteReg;
LSwitchFailed:
pdlg = DLG::PdlgNew(dlidDesktopWontResize, pvNil, pvNil);
if (pvNil != pdlg)
pdlg->IditDo();
ReleasePpo(&pdlg);
// try to set pref to fFalse
fSwitchRes = fFalse;
LWriteReg:
FGetSetRegKey(kszSwitchResolutionValue, &fSwitchRes, size(fSwitchRes), fregSetKey);
return fTrue;
}
/***************************************************************************
Return whether display is currently 640x480
***************************************************************************/
bool APP::_FDisplayIs640480(void)
{
#ifdef WIN
return (GetSystemMetrics(SM_CXSCREEN) == 640 && GetSystemMetrics(SM_CYSCREEN) == 480);
#endif // WIN
#ifdef MAC
RawRtn();
return fFalse;
#endif // MAC
}
/***************************************************************************
Do OS specific initialization.
***************************************************************************/
bool APP::_FInitOS(void)
{
AssertBaseThis(0);
#ifdef WIN
long dxpWindow;
long dypWindow;
long xpWindow;
long ypWindow;
DWORD dwStyle = 0;
STN stnWindowTitle;
if (_fMainWindowCreated) // If someone else called _FInitOS already,
return fTrue; // we can leave
if (!FGetStnApp(idsWindowTitle, &stnWindowTitle))
return fFalse;
// register the window classes
if (vwig.hinstPrev == hNil)
{
WNDCLASS wcs;
wcs.style = CS_BYTEALIGNCLIENT | CS_OWNDC;
wcs.lpfnWndProc = _LuWndProc;
wcs.cbClsExtra = 0;
wcs.cbWndExtra = 0;
wcs.hInstance = vwig.hinst;
wcs.hIcon = LoadIcon(vwig.hinst, MAKEINTRESOURCE(IDI_APP));
wcs.hCursor = LoadCursor(NULL, IDC_ARROW);
wcs.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
wcs.lpszMenuName = 0;
wcs.lpszClassName = kpszAppWndCls;
if (!RegisterClass(&wcs))
return fFalse;
wcs.lpfnWndProc = _LuMdiWndProc;
wcs.lpszClassName = PszLit("MDI");
if (!RegisterClass(&wcs))
return fFalse;
}
_GetWindowProps(&xpWindow, &ypWindow, &dxpWindow, &dypWindow, &dwStyle);
if ((vwig.hwndApp = CreateWindow(kpszAppWndCls, stnWindowTitle.Psz(), dwStyle, xpWindow, ypWindow, dxpWindow,
dypWindow, hNil, hNil, vwig.hinst, pvNil)) == hNil)
{
return fFalse;
}
if (hNil == (vwig.hdcApp = GetDC(vwig.hwndApp)))
return fFalse;
// set a timer, so we can idle regularly.
if (SetTimer(vwig.hwndApp, 0, 1, pvNil) == 0)
return fFalse;
_haccel = LoadAccelerators(vwig.hinst, MIR(acidMain));
_haccelGlobal = LoadAccelerators(vwig.hinst, MIR(acidGlobal));
vwig.haccel = _haccel;
ShowWindow(vwig.hwndApp, vwig.wShow);
_fMainWindowCreated = fTrue;
#endif // WIN
#ifdef MAC
RawRtn();
#endif // MAC
return fTrue;
}
/***************************************************************************
Determine window size, position, and window style. Note that you
should pass in the current dwStyle if the window already exists. If
the window does not already exist, pass in 0.
***************************************************************************/
void APP::_GetWindowProps(long *pxp, long *pyp, long *pdxp, long *pdyp, DWORD *pdwStyle)
{
AssertBaseThis(0);
AssertVarMem(pxp);
AssertVarMem(pyp);
AssertVarMem(pdxp);
AssertVarMem(pdyp);