forked from audetto/AppleWin
/
Win32Frame.cpp
618 lines (532 loc) · 16.6 KB
/
Win32Frame.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
#include "StdAfx.h"
#include "Windows/Win32Frame.h"
#include "Interface.h"
#include "Core.h"
#include "CPU.h"
#include "Joystick.h"
#include "Log.h"
#include "Memory.h"
#include "CardManager.h"
#include "Debugger/Debug.h"
#include "../resource/resource.h"
// Win32Frame methods are implemented in AppleWin, WinFrame and WinVideo.
// in time they should be brought together and more freestanding functions added to Win32Frame.
Win32Frame::Win32Frame()
{
g_pFramebufferinfo = NULL;
num_draw_devices = 0;
g_lpDD = NULL;
g_hLogoBitmap = (HBITMAP)0;
g_hDeviceBitmap = (HBITMAP)0;
g_hDeviceDC = (HDC)0;
g_bAltEnter_ToggleFullScreen = false;
g_bIsFullScreen = false;
g_bShowingCursor = true;
g_bLastCursorInAppleViewport = false;
g_uCount100msec = 0;
g_TimerIDEvent_100msec = 0;
g_bUsingCursor = FALSE;
g_bAppActive = false;
g_bFrameActive = false;
g_windowMinimized = false;
g_bFullScreen_ShowSubunitStatus = true;
g_win_fullscreen_scale = 1;
g_win_fullscreen_offsetx = 0;
g_win_fullscreen_offsety = 0;
m_bestWidthForFullScreen = 0;
m_bestHeightForFullScreen = 0;
m_changedDisplaySettings = false;
g_nViewportCX = GetVideo().GetFrameBufferBorderlessWidth() * kDEFAULT_VIEWPORT_SCALE;
g_nViewportCY = GetVideo().GetFrameBufferBorderlessHeight() * kDEFAULT_VIEWPORT_SCALE;
g_nViewportScale = kDEFAULT_VIEWPORT_SCALE; // saved REGSAVE
g_nMaxViewportScale = kDEFAULT_VIEWPORT_SCALE; // Max scale in Windowed mode with borders, buttons etc (full-screen may be +1)
btnfacebrush = (HBRUSH)0;
btnfacepen = (HPEN)0;
btnhighlightpen = (HPEN)0;
btnshadowpen = (HPEN)0;
buttonactive = -1;
buttondown = -1;
buttonover = -1;
buttonx = BUTTONX; // NB. macro uses g_nViewportCX
buttony = BUTTONY;
g_hFrameDC = (HDC)0;
memset(&framerect, 0, sizeof(framerect));
helpquit = 0;
smallfont = (HFONT)0;
tooltipwindow = (HWND)0;
viewportx = VIEWPORTX; // Default to Normal (non-FullScreen) mode
viewporty = VIEWPORTY; // Default to Normal (non-FullScreen) mode
g_bScrollLock_FullSpeed = false;
g_nTrackDrive1 = -1;
g_nTrackDrive2 = -1;
g_nSectorDrive1 = -1;
g_nSectorDrive2 = -1;
strcpy_s(g_sTrackDrive1, sizeof(g_sTrackDrive1), "??");
strcpy_s(g_sTrackDrive2, sizeof(g_sTrackDrive1), "??");
strcpy_s(g_sSectorDrive1, sizeof(g_sTrackDrive1), "??");
strcpy_s(g_sSectorDrive2, sizeof(g_sTrackDrive1), "??");
g_eStatusDrive1 = DISK_STATUS_OFF;
g_eStatusDrive2 = DISK_STATUS_OFF;
}
void Win32Frame::videoCreateDIBSection(Video & video)
{
// CREATE THE DEVICE CONTEXT
HWND window = GetDesktopWindow();
HDC dc = GetDC(window);
if (g_hDeviceDC)
{
DeleteDC(g_hDeviceDC);
}
g_hDeviceDC = CreateCompatibleDC(dc);
// CREATE THE FRAME BUFFER DIB SECTION
if (g_hDeviceBitmap)
DeleteObject(g_hDeviceBitmap);
uint8_t* pFramebufferbits;
g_hDeviceBitmap = CreateDIBSection(
dc,
g_pFramebufferinfo,
DIB_RGB_COLORS,
(LPVOID*)&pFramebufferbits, 0, 0
);
SelectObject(g_hDeviceDC, g_hDeviceBitmap);
video.Initialize(pFramebufferbits);
}
void Win32Frame::Initialize(void)
{
// LOAD THE LOGO
g_hLogoBitmap = LoadBitmap(g_hInstance, MAKEINTRESOURCE(IDB_APPLEWIN));
// CREATE A BITMAPINFO STRUCTURE FOR THE FRAME BUFFER
g_pFramebufferinfo = (LPBITMAPINFO) new BYTE[sizeof(BITMAPINFOHEADER) + 256 * sizeof(RGBQUAD)];
Video & video = GetVideo();
memset(g_pFramebufferinfo, 0, sizeof(BITMAPINFOHEADER) + 256 * sizeof(RGBQUAD));
g_pFramebufferinfo->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
g_pFramebufferinfo->bmiHeader.biWidth = video.GetFrameBufferWidth();
g_pFramebufferinfo->bmiHeader.biHeight = video.GetFrameBufferHeight();
g_pFramebufferinfo->bmiHeader.biPlanes = 1;
g_pFramebufferinfo->bmiHeader.biBitCount = 32;
g_pFramebufferinfo->bmiHeader.biCompression = BI_RGB;
g_pFramebufferinfo->bmiHeader.biClrUsed = 0;
videoCreateDIBSection(video);
#if 0
DDInit(); // For WaitForVerticalBlank()
#endif
}
void Win32Frame::Destroy(void)
{
// DESTROY BUFFERS
delete[] g_pFramebufferinfo;
g_pFramebufferinfo = NULL;
// DESTROY FRAME BUFFER
DeleteDC(g_hDeviceDC);
g_hDeviceDC = (HDC)0;
DeleteObject(g_hDeviceBitmap); // this invalidates the Video's FrameBuffer pointer
GetVideo().Destroy(); // this resets the Video's FrameBuffer pointer
g_hDeviceBitmap = (HBITMAP)0;
// DESTROY LOGO
if (g_hLogoBitmap) {
DeleteObject(g_hLogoBitmap);
g_hLogoBitmap = (HBITMAP)0;
}
DDUninit();
}
//===========================================================================
void Win32Frame::Benchmark(void)
{
_ASSERT(g_nAppMode == MODE_BENCHMARK);
Sleep(500);
Video& video = GetVideo();
// PREPARE TWO DIFFERENT FRAME BUFFERS, EACH OF WHICH HAVE HALF OF THE
// BYTES SET TO 0x14 AND THE OTHER HALF SET TO 0xAA
int loop;
LPDWORD mem32 = (LPDWORD)mem;
for (loop = 4096; loop < 6144; loop++)
*(mem32 + loop) = ((loop & 1) ^ ((loop & 0x40) >> 6)) ? 0x14141414
: 0xAAAAAAAA;
for (loop = 6144; loop < 8192; loop++)
*(mem32 + loop) = ((loop & 1) ^ ((loop & 0x40) >> 6)) ? 0xAAAAAAAA
: 0x14141414;
// SEE HOW MANY TEXT FRAMES PER SECOND WE CAN PRODUCE WITH NOTHING ELSE
// GOING ON, CHANGING HALF OF THE BYTES IN THE VIDEO BUFFER EACH FRAME TO
// SIMULATE THE ACTIVITY OF AN AVERAGE GAME
DWORD totaltextfps = 0;
video.SetVideoMode(VF_TEXT);
memset(mem + 0x400, 0x14, 0x400);
VideoRedrawScreen();
DWORD milliseconds = GetTickCount();
while (GetTickCount() == milliseconds);
milliseconds = GetTickCount();
DWORD cycle = 0;
do {
if (cycle & 1)
memset(mem + 0x400, 0x14, 0x400);
else
memcpy(mem + 0x400, mem + ((cycle & 2) ? 0x4000 : 0x6000), 0x400);
VideoPresentScreen();
if (cycle++ >= 3)
cycle = 0;
totaltextfps++;
} while (GetTickCount() - milliseconds < 1000);
// SEE HOW MANY HIRES FRAMES PER SECOND WE CAN PRODUCE WITH NOTHING ELSE
// GOING ON, CHANGING HALF OF THE BYTES IN THE VIDEO BUFFER EACH FRAME TO
// SIMULATE THE ACTIVITY OF AN AVERAGE GAME
DWORD totalhiresfps = 0;
video.SetVideoMode(VF_HIRES);
memset(mem + 0x2000, 0x14, 0x2000);
VideoRedrawScreen();
milliseconds = GetTickCount();
while (GetTickCount() == milliseconds);
milliseconds = GetTickCount();
cycle = 0;
do {
if (cycle & 1)
memset(mem + 0x2000, 0x14, 0x2000);
else
memcpy(mem + 0x2000, mem + ((cycle & 2) ? 0x4000 : 0x6000), 0x2000);
VideoPresentScreen();
if (cycle++ >= 3)
cycle = 0;
totalhiresfps++;
} while (GetTickCount() - milliseconds < 1000);
// DETERMINE HOW MANY 65C02 CLOCK CYCLES WE CAN EMULATE PER SECOND WITH
// NOTHING ELSE GOING ON
DWORD totalmhz10[2] = { 0,0 }; // bVideoUpdate & !bVideoUpdate
for (UINT i = 0; i < 2; i++)
{
CpuSetupBenchmark();
milliseconds = GetTickCount();
while (GetTickCount() == milliseconds);
milliseconds = GetTickCount();
do {
CpuExecute(100000, i == 0 ? true : false);
totalmhz10[i]++;
} while (GetTickCount() - milliseconds < 1000);
}
// IF THE PROGRAM COUNTER IS NOT IN THE EXPECTED RANGE AT THE END OF THE
// CPU BENCHMARK, REPORT AN ERROR AND OPTIONALLY TRACK IT DOWN
if ((regs.pc < 0x300) || (regs.pc > 0x400))
if (FrameMessageBox(
TEXT("The emulator has detected a problem while running ")
TEXT("the CPU benchmark. Would you like to gather more ")
TEXT("information?"),
TEXT("Benchmarks"),
MB_ICONQUESTION | MB_YESNO | MB_SETFOREGROUND) == IDYES) {
BOOL error = 0;
WORD lastpc = 0x300;
int loop = 0;
while ((loop < 10000) && !error) {
CpuSetupBenchmark();
CpuExecute(loop, true);
if ((regs.pc < 0x300) || (regs.pc > 0x400))
error = 1;
else {
lastpc = regs.pc;
++loop;
}
}
if (error) {
TCHAR outstr[256];
wsprintf(outstr,
TEXT("The emulator experienced an error %u clock cycles ")
TEXT("into the CPU benchmark. Prior to the error, the ")
TEXT("program counter was at $%04X. After the error, it ")
TEXT("had jumped to $%04X."),
(unsigned)loop,
(unsigned)lastpc,
(unsigned)regs.pc);
FrameMessageBox(
outstr,
TEXT("Benchmarks"),
MB_ICONINFORMATION | MB_SETFOREGROUND);
}
else
FrameMessageBox(
TEXT("The emulator was unable to locate the exact ")
TEXT("point of the error. This probably means that ")
TEXT("the problem is external to the emulator, ")
TEXT("happening asynchronously, such as a problem in ")
TEXT("a timer interrupt handler."),
TEXT("Benchmarks"),
MB_ICONINFORMATION | MB_SETFOREGROUND);
}
// DO A REALISTIC TEST OF HOW MANY FRAMES PER SECOND WE CAN PRODUCE
// WITH FULL EMULATION OF THE CPU, JOYSTICK, AND DISK HAPPENING AT
// THE SAME TIME
DWORD realisticfps = 0;
memset(mem + 0x2000, 0xAA, 0x2000);
VideoRedrawScreen();
milliseconds = GetTickCount();
while (GetTickCount() == milliseconds);
milliseconds = GetTickCount();
cycle = 0;
do {
if (realisticfps < 10) {
int cycles = 100000;
while (cycles > 0) {
DWORD executedcycles = CpuExecute(103, true);
cycles -= executedcycles;
GetCardMgr().GetDisk2CardMgr().Update(executedcycles);
}
}
if (cycle & 1)
memset(mem + 0x2000, 0xAA, 0x2000);
else
memcpy(mem + 0x2000, mem + ((cycle & 2) ? 0x4000 : 0x6000), 0x2000);
VideoRedrawScreen();
if (cycle++ >= 3)
cycle = 0;
realisticfps++;
} while (GetTickCount() - milliseconds < 1000);
// DISPLAY THE RESULTS
DisplayLogo();
TCHAR outstr[256];
wsprintf(outstr,
TEXT("Pure Video FPS:\t%u hires, %u text\n")
TEXT("Pure CPU MHz:\t%u.%u%s (video update)\n")
TEXT("Pure CPU MHz:\t%u.%u%s (full-speed)\n\n")
TEXT("EXPECTED AVERAGE VIDEO GAME\n")
TEXT("PERFORMANCE: %u FPS"),
(unsigned)totalhiresfps,
(unsigned)totaltextfps,
(unsigned)(totalmhz10[0] / 10), (unsigned)(totalmhz10[0] % 10), (LPCTSTR)(IS_APPLE2 ? TEXT(" (6502)") : TEXT("")),
(unsigned)(totalmhz10[1] / 10), (unsigned)(totalmhz10[1] % 10), (LPCTSTR)(IS_APPLE2 ? TEXT(" (6502)") : TEXT("")),
(unsigned)realisticfps);
FrameMessageBox(
outstr,
TEXT("Benchmarks"),
MB_ICONINFORMATION | MB_SETFOREGROUND);
}
//===========================================================================
// This is called from PageConfig
void Win32Frame::ChooseMonochromeColor(void)
{
Video& video = GetVideo();
CHOOSECOLOR cc;
memset(&cc, 0, sizeof(CHOOSECOLOR));
cc.lStructSize = sizeof(CHOOSECOLOR);
cc.hwndOwner = g_hFrameWindow;
cc.rgbResult = video.GetMonochromeRGB();
cc.lpCustColors = customcolors + 1;
cc.Flags = CC_RGBINIT | CC_SOLIDCOLOR;
if (ChooseColor(&cc))
{
video.SetMonochromeRGB(cc.rgbResult);
ApplyVideoModeChange();
}
}
//===========================================================================
void Win32Frame::VideoDrawLogoBitmap(HDC hDstDC, int xoff, int yoff, int srcw, int srch, int scale)
{
HDC hSrcDC = CreateCompatibleDC(hDstDC);
SelectObject(hSrcDC, g_hLogoBitmap);
StretchBlt(
hDstDC, // hdcDest
xoff, yoff, // nXDest, nYDest
scale * srcw, scale * srch, // nWidth, nHeight
hSrcDC, // hdcSrc
0, 0, // nXSrc, nYSrc
srcw, srch,
SRCCOPY // dwRop
);
DeleteObject(hSrcDC);
}
//===========================================================================
void Win32Frame::DisplayLogo(void)
{
Video& video = GetVideo();
int nLogoX = 0, nLogoY = 0;
int scale = GetViewportScale();
HDC hFrameDC = FrameGetDC();
// DRAW THE LOGO
SelectObject(hFrameDC, GetStockObject(NULL_PEN));
if (g_hLogoBitmap)
{
BITMAP bm;
if (GetObject(g_hLogoBitmap, sizeof(bm), &bm))
{
nLogoX = (g_nViewportCX - scale * bm.bmWidth) / 2;
nLogoY = (g_nViewportCY - scale * bm.bmHeight) / 2;
if (IsFullScreen())
{
nLogoX += GetFullScreenOffsetX();
nLogoY += GetFullScreenOffsetY();
}
VideoDrawLogoBitmap(hFrameDC, nLogoX, nLogoY, bm.bmWidth, bm.bmHeight, scale);
}
}
// DRAW THE VERSION NUMBER
TCHAR sFontName[] = TEXT("Arial");
HFONT font = CreateFont(-20, 0, 0, 0, FW_NORMAL, 0, 0, 0, ANSI_CHARSET,
OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY,
VARIABLE_PITCH | 4 | FF_SWISS,
sFontName);
SelectObject(hFrameDC, font);
SetTextAlign(hFrameDC, TA_RIGHT | TA_TOP);
SetBkMode(hFrameDC, TRANSPARENT);
TCHAR szVersion[64];
StringCbPrintf(szVersion, 64, "Version %s", VERSIONSTRING);
int xoff = GetFullScreenOffsetX(), yoff = GetFullScreenOffsetY();
#define DRAWVERSION(x,y,c) \
SetTextColor(hFrameDC,c); \
TextOut(hFrameDC, \
scale*540+x+xoff,scale*358+y+yoff, \
szVersion, \
strlen(szVersion));
if (GetDeviceCaps(hFrameDC, PLANES) * GetDeviceCaps(hFrameDC, BITSPIXEL) <= 4) {
DRAWVERSION(2, 2, RGB(0x00, 0x00, 0x00));
DRAWVERSION(1, 1, RGB(0x00, 0x00, 0x00));
DRAWVERSION(0, 0, RGB(0xFF, 0x00, 0xFF));
}
else {
DRAWVERSION(1, 1, PALETTERGB(0x30, 0x30, 0x70));
DRAWVERSION(-1, -1, PALETTERGB(0xC0, 0x70, 0xE0));
DRAWVERSION(0, 0, PALETTERGB(0x70, 0x30, 0xE0));
}
#if _DEBUG
StringCbPrintf(szVersion, 64, "DEBUG");
DRAWVERSION(2, -358 * scale, RGB(0x00, 0x00, 0x00));
DRAWVERSION(1, -357 * scale, RGB(0x00, 0x00, 0x00));
DRAWVERSION(0, -356 * scale, RGB(0xFF, 0x00, 0xFF));
#endif
#undef DRAWVERSION
DeleteObject(font);
}
//===========================================================================
void Win32Frame::VideoPresentScreen(void)
{
HDC hFrameDC = FrameGetDC();
if (hFrameDC)
{
Video& video = GetVideo();
int xSrc = video.GetFrameBufferBorderWidth();
int ySrc = video.GetFrameBufferBorderHeight();
int xdest = IsFullScreen() ? GetFullScreenOffsetX() : 0;
int ydest = IsFullScreen() ? GetFullScreenOffsetY() : 0;
int wdest = g_nViewportCX;
int hdest = g_nViewportCY;
SetStretchBltMode(hFrameDC, COLORONCOLOR);
StretchBlt(
hFrameDC,
xdest, ydest,
wdest, hdest,
g_hDeviceDC,
xSrc, ySrc,
video.GetFrameBufferBorderlessWidth(), video.GetFrameBufferBorderlessHeight(),
SRCCOPY);
}
#ifdef NO_DIRECT_X
#else
//if (g_lpDD) g_lpDD->WaitForVerticalBlank(DDWAITVB_BLOCKBEGIN, NULL);
#endif // NO_DIRECT_X
GdiFlush();
}
//===========================================================================
BOOL CALLBACK Win32Frame::DDEnumProc(LPGUID lpGUID, LPCTSTR lpszDesc, LPCTSTR lpszDrvName, LPVOID lpContext)
{
Win32Frame* obj = (Win32Frame*)lpContext;
int i = obj->num_draw_devices;
if (i == MAX_DRAW_DEVICES)
return TRUE;
if (lpGUID != NULL)
memcpy(&(obj->draw_device_guid[i]), lpGUID, sizeof(GUID));
obj->draw_devices[i] = _strdup(lpszDesc);
if (g_fh) fprintf(g_fh, "%d: %s - %s\n", i, lpszDesc, lpszDrvName);
(obj->num_draw_devices)++;
return TRUE;
}
bool Win32Frame::DDInit(void)
{
#ifdef NO_DIRECT_X
return false;
#else
HRESULT hr = DirectDrawEnumerate((LPDDENUMCALLBACK)DDEnumProc, this);
if (FAILED(hr))
{
LogFileOutput("DSEnumerate failed (%08X)\n", hr);
return false;
}
LogFileOutput("Number of draw devices = %d\n", num_draw_devices);
bool bCreatedOK = false;
for (int x = 0; x < num_draw_devices; x++)
{
hr = DirectDrawCreate(&draw_device_guid[x], &g_lpDD, NULL);
if (SUCCEEDED(hr))
{
LogFileOutput("DSCreate succeeded for draw device #%d\n", x);
bCreatedOK = true;
break;
}
LogFileOutput("DSCreate failed for draw device #%d (%08X)\n", x, hr);
}
if (!bCreatedOK)
{
LogFileOutput("DSCreate failed for all draw devices\n");
return false;
}
return true;
#endif // NO_DIRECT_X
}
// From SoundCore.h
#define SAFE_RELEASE(p) { if(p) { (p)->Release(); (p)=NULL; } }
void Win32Frame::DDUninit(void)
{
SAFE_RELEASE(g_lpDD);
}
#undef SAFE_RELEASE
void Win32Frame::ApplyVideoModeChange(void)
{
Video& video = GetVideo();
video.Config_Save_Video();
video.VideoReinitialize(false);
if (g_nAppMode != MODE_LOGO)
{
if (g_nAppMode == MODE_DEBUG)
{
UINT debugVideoMode;
if (DebugGetVideoMode(&debugVideoMode))
VideoRefreshScreen(debugVideoMode, true);
else
VideoPresentScreen();
}
else
{
VideoPresentScreen();
}
}
}
Win32Frame& Win32Frame::GetWin32Frame()
{
FrameBase& frameBase = GetFrame();
Win32Frame& win32Frame = dynamic_cast<Win32Frame&>(frameBase);
return win32Frame;
}
int Win32Frame::FrameMessageBox(LPCSTR lpText, LPCSTR lpCaption, UINT uType)
{
const HWND handle = g_hFrameWindow ? g_hFrameWindow : GetDesktopWindow();
return MessageBox(handle, lpText, lpCaption, uType);
}
void Win32Frame::GetBitmap(LPCSTR lpBitmapName, LONG cb, LPVOID lpvBits)
{
HBITMAP hBitmap = LoadBitmap(g_hInstance, lpBitmapName);
GetBitmapBits(hBitmap, cb, lpvBits);
DeleteObject(hBitmap);
}
void Win32Frame::Restart()
{
// Changed h/w config, eg. Apple computer type (][+ or //e), slot configuration, etc.
g_bRestart = true;
PostMessage(g_hFrameWindow, WM_CLOSE, 0, 0);
}
BYTE* Win32Frame::GetResource(WORD id, LPCSTR lpType, DWORD dwExpectedSize)
{
HRSRC hResInfo = FindResource(NULL, MAKEINTRESOURCE(id), lpType);
if (hResInfo == NULL)
return NULL;
DWORD dwResSize = SizeofResource(NULL, hResInfo);
if (dwResSize != dwExpectedSize)
return NULL;
HGLOBAL hResData = LoadResource(NULL, hResInfo);
if (hResData == NULL)
return NULL;
BYTE* pResource = (BYTE*)LockResource(hResData); // NB. Don't need to unlock resource
return pResource;
}