-
Notifications
You must be signed in to change notification settings - Fork 12
/
MainFrame.cpp
3161 lines (2680 loc) · 83.5 KB
/
MainFrame.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
//
// メインウインドウクラス
//
//
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <process.h>
#include <shellapi.h>
#include <commdlg.h>
#include <imm.h>
#include <string>
using namespace std;
#include "VirtuaNESres.h"
#include "DebugOut.h"
#include "App.h"
#include "Pathlib.h"
#include "Plugin.h"
#include "Wnd.h"
#include "WndHook.h"
#include "MainFrame.h"
#include "Recent.h"
#include "Config.h"
#include "NetPlay.h"
#include "AboutDlg.h"
#include "EmulatorDlg.h"
#include "GraphicsDlg.h"
#include "SoundDlg.h"
#include "ControllerDlg.h"
#include "ShortcutDlg.h"
#include "FolderDlg.h"
#include "LanguageDlg.h"
#include "MovieDlg.h"
#include "GameOptionDlg.h"
#include "JoyAxisDlg.h"
#include "RomInfoDlg.h"
#include "NetPlayDlg.h"
#include "MovieInfoDlg.h"
#include "DirectDraw.h"
#include "DirectSound.h"
#include "DirectInput.h"
#include "nes.h"
#include "rom.h"
#include "romdb.h"
#include "pad.h"
BOOL CMainFrame::m_bKeyEnable = FALSE;
volatile BOOL CMainFrame::m_bKeyThreadExit = FALSE;
DWORD CMainFrame::m_dwKeyTime = 0;
BYTE CMainFrame::m_KeyBuf[256+64*8];
BYTE CMainFrame::m_KeyOld[256+64*8];
BYTE CMainFrame::m_KeyCnt[256*64*8];
// メッセージマップ
WND_MESSAGE_BEGIN(CMainFrame)
// メッセージ
WND_ON_MESSAGE( WM_CREATE, OnCreate )
WND_ON_MESSAGE( WM_CLOSE, OnClose )
WND_ON_MESSAGE( WM_DESTROY, OnDestroy )
WND_ON_MESSAGE( WM_GETMINMAXINFO, OnGetMinMaxInfo )
WND_ON_MESSAGE( WM_ACTIVATE, OnActivate )
WND_ON_MESSAGE( WM_ACTIVATEAPP, OnActivateApp )
WND_ON_MESSAGE( WM_VNS_SHORTCUTENABLE, OnShortCutEnable )
WND_ON_MESSAGE( WM_ENABLE, OnEnable )
WND_ON_MESSAGE( WM_ENTERMENULOOP, OnEnterMenuLoop )
WND_ON_MESSAGE( WM_EXITMENULOOP, OnExitMenuLoop )
WND_ON_MESSAGE( WM_SETFOCUS, OnSetFocus )
WND_ON_MESSAGE( WM_KILLFOCUS, OnKillFocus )
WND_ON_MESSAGE( WM_INITMENU, OnInitMenu )
WND_ON_MESSAGE( WM_INITMENUPOPUP, OnInitMenuPopup )
WND_ON_MESSAGE( WM_PAINT, OnPaint )
WND_ON_MESSAGE( WM_DISPLAYCHANGE, OnDisplayChange )
WND_ON_MESSAGE( WM_PALETTECHANGED, OnPaletteChanged )
WND_ON_MESSAGE( WM_QUERYNEWPALETTE, OnQueryNewPalette )
WND_ON_MESSAGE( WM_MENUCHAR, OnMenuChar )
WND_ON_MESSAGE( WM_KEYDOWN, OnKeyDown )
WND_ON_MESSAGE( WM_SIZE, OnSize )
WND_ON_MESSAGE( WM_SYSCOMMAND, OnSysCommand )
WND_ON_MESSAGE( WM_EXITSIZEMOVE, OnExitSizeMove )
WND_ON_MESSAGE( WM_SETCURSOR, OnSetCursor )
WND_ON_MESSAGE( WM_TIMER, OnTimer )
WND_ON_MESSAGE( WM_COPYDATA, OnCopyData )
WND_ON_MESSAGE( WM_VNS_ERRORMSG, OnErrorMessage )
WND_ON_MESSAGE( WM_DROPFILES, OnDropFiles )
WND_ON_MESSAGE( WM_VNS_COMMANDLINE, OnCommandLine )
WND_ON_MESSAGE( WM_VNS_LAUNCHERCMD, OnLauncherCommand )
WND_ON_MESSAGE( WM_NETPLAY, OnNetPlay )
WND_ON_MESSAGE( WM_NETPLAY_CLOSE, OnNetPlayClose )
WND_ON_MESSAGE( WM_NETPLAY_ERROR, OnNetPlayError )
WND_ON_MESSAGE( WM_VNS_CHATPOPUP, OnNetPlayChatPopup )
// コマンド
WND_COMMAND_BEGIN()
WND_ON_COMMAND( ID_EXIT, OnExit )
WND_ON_COMMAND( ID_HTMLHELP, OnHelp )
WND_ON_COMMAND( ID_ABOUT, OnAbout )
WND_ON_COMMAND( ID_OPEN, OnFileOpen )
WND_ON_COMMAND( ID_CLOSE, OnFileClose )
WND_ON_COMMAND( ID_ROMINFO, OnRomInfo )
WND_ON_COMMAND( ID_WAVERECORD, OnWaveRecord )
WND_ON_COMMAND( ID_LAUNCHER, OnLauncher )
WND_ON_COMMAND_RANGE( ID_MRU_PATH0, ID_MRU_PATH9, OnRecentOpenPath )
WND_ON_COMMAND_RANGE( ID_MRU_FILE0, ID_MRU_FILE9, OnRecentOpen )
WND_ON_COMMAND( ID_NETPLAY_CONNECT, OnNetPlayConnect )
WND_ON_COMMAND( ID_NETPLAY_DISCONNECT, OnNetPlayDisconnect )
WND_ON_COMMAND( ID_NETPLAY_CHAT, OnNetPlayChat )
WND_ON_COMMAND( ID_CFG_EMULATOR, OnEmulatorCfg )
WND_ON_COMMAND( ID_CFG_GRAPHICS, OnGraphicsCfg )
WND_ON_COMMAND( ID_CFG_SOUND, OnSoundCfg )
WND_ON_COMMAND( ID_CFG_CONTROLLER, OnControllerCfg )
WND_ON_COMMAND( ID_CFG_SHORTCUT, OnShortcutCfg )
WND_ON_COMMAND( ID_CFG_FOLDER, OnFolderCfg )
WND_ON_COMMAND( ID_CFG_LANGUAGE, OnLanguageCfg )
WND_ON_COMMAND( ID_CFG_MOVIE, OnMovieCfg )
WND_ON_COMMAND( ID_CFG_GAMEOPTION, OnGameOptionCfg )
WND_ON_COMMAND( ID_CFG_JOYAXIS, OnJoyAxisCfg )
WND_ON_COMMAND( ID_CFG_PALETTE, OnPaletteEditCfg )
WND_ON_COMMAND( ID_SEARCH, OnSearch )
WND_ON_COMMAND( ID_CHEAT, OnCheat )
WND_ON_COMMAND_RANGE( ID_CHEAT_ENABLE, ID_CHEAT_DISABLE, OnCheatCommand )
WND_ON_COMMAND( ID_GENIE, OnGenie )
WND_ON_COMMAND( ID_BARCODEBATTLER, OnDatachBacode )
WND_ON_COMMAND( ID_VSUNISYSTEM_DIPSWITCH, OnDipSwitch )
WND_ON_COMMAND( ID_FULLSCREEN, OnFullScreen )
WND_ON_COMMAND_RANGE( ID_ZOOMx1, ID_ZOOMx4, OnZoom )
WND_ON_COMMAND( ID_HWRESET, OnEmuCommand )
WND_ON_COMMAND( ID_SWRESET, OnEmuCommand )
WND_ON_COMMAND( ID_PAUSE, OnEmuCommand )
WND_ON_COMMAND( ID_THROTTLE, OnEmuCommand )
WND_ON_COMMAND( ID_STATE_UP, OnEmuCommand )
WND_ON_COMMAND( ID_STATE_DOWN, OnEmuCommand )
WND_ON_COMMAND( ID_FPSDISP, OnEmuCommand )
WND_ON_COMMAND( ID_TVASPECT, OnEmuCommand )
WND_ON_COMMAND( ID_TVFRAME, OnEmuCommand )
WND_ON_COMMAND( ID_SCANLINE, OnEmuCommand )
WND_ON_COMMAND( ID_ALLLINE, OnEmuCommand )
WND_ON_COMMAND( ID_ALLSPRITE, OnEmuCommand )
WND_ON_COMMAND( ID_SYNCDRAW, OnEmuCommand )
WND_ON_COMMAND( ID_FITSCREEN, OnEmuCommand )
WND_ON_COMMAND( ID_SNAPSHOT, OnEmuCommand )
WND_ON_COMMAND( ID_LEFTCLIP, OnEmuCommand )
WND_ON_COMMAND( ID_ONEFRAME, OnEmuCommand )
WND_ON_COMMAND( ID_STATE_LOAD, OnStateCommand )
WND_ON_COMMAND( ID_STATE_SAVE, OnStateCommand )
WND_ON_COMMAND( ID_MOVIE_PLAY, OnMovieCommand )
WND_ON_COMMAND( ID_MOVIE_REC, OnMovieCommand )
WND_ON_COMMAND( ID_MOVIE_REC_APPEND, OnMovieCommand )
WND_ON_COMMAND( ID_MOVIE_STOP, OnMovieCommand )
WND_ON_COMMAND( ID_MOVIE_INFO, OnMovieInfo )
WND_ON_COMMAND( ID_TAPE_PLAY, OnTapeCommand )
WND_ON_COMMAND( ID_TAPE_REC, OnTapeCommand )
WND_ON_COMMAND( ID_TAPE_STOP, OnTapeCommand )
WND_ON_COMMAND( ID_FRAMESKIP_AUTO, OnEmuCommand )
WND_ON_COMMAND( ID_FRAMESKIP_UP, OnEmuCommand )
WND_ON_COMMAND( ID_FRAMESKIP_DOWN, OnEmuCommand )
// Viewers
WND_ON_COMMAND( ID_VIEW_PATTERN, OnViewCommand )
WND_ON_COMMAND( ID_VIEW_NAMETABLE, OnViewCommand )
WND_ON_COMMAND( ID_VIEW_PALETTE, OnViewCommand )
WND_ON_COMMAND( ID_VIEW_MEMORY, OnViewCommand )
//
WND_ON_COMMAND_RANGE( ID_FILTER_NONE, ID_FILTER_END, OnEmuCommand )
WND_ON_COMMAND_RANGE( ID_STATE_SLOT0, ID_STATE_SLOT9, OnEmuCommand )
WND_ON_COMMAND_RANGE( ID_DISK_EJECT, ID_DISK_1B, OnEmuCommand )
//WND_ON_COMMAND_RANGE( ID_EXCTR_NONE, ID_EXCTR_END, OnEmuCommand )
WND_ON_COMMAND_RANGE( ID_EXCTR_SUBOR_KEYBOARD, ID_EXCTR_END, OnEmuCommand )
WND_ON_COMMAND_RANGE( ID_MUTE_0, ID_MUTE_F, OnEmuCommand )
WND_ON_COMMAND_RANGE( ID_TURBOFILE_BANK0, ID_TURBOFILE_BANK3, OnEmuCommand )
WND_ON_COMMAND_RANGE( ID_QUICKLOAD_SLOT0, ID_QUICKLOAD_SLOT9, OnStateCommand2 )
WND_ON_COMMAND_RANGE( ID_QUICKSAVE_SLOT0, ID_QUICKSAVE_SLOT9, OnStateCommand2 )
WND_COMMAND_END()
WND_MESSAGE_END()
BOOL CMainFrame::Create( HWND hWndParent )
{
// NESオブジェクト
Nes = NULL;
// メンバ変数
m_hMenu = NULL;
WNDCLASSEX wcl;
ZEROMEMORY( &wcl, sizeof(wcl) );
wcl.cbSize = sizeof(wcl);
wcl.lpszClassName = "VirtuaNESwndclass";
wcl.lpfnWndProc = g_WndProc;
// wcl.style = CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS;
wcl.style = CS_DBLCLKS;
wcl.cbClsExtra = wcl.cbWndExtra = 0;
wcl.hInstance = CApp::GetInstance();
wcl.lpszMenuName = NULL;
wcl.hIcon =
wcl.hIconSm = ::LoadIcon( CApp::GetInstance(), MAKEINTRESOURCE(IDI_ICON) );
wcl.hCursor = ::LoadCursor( NULL, IDC_ARROW );
wcl.hbrBackground = 0;
if( !RegisterClassEx( &wcl ) ) {
// DEBUGOUT( "RegisterClassEx faild.\n" );
return FALSE;
}
HWND hWnd = CreateWindowEx(
WS_EX_CLIENTEDGE,
VIRTUANES_WNDCLASS,
VIRTUANES_CAPTION,
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
hWndParent,
NULL,
CApp::GetInstance(),
(LPVOID)this // This を埋め込む為
);
if( !hWnd ) {
// DEBUGOUT( "CreateWindow faild.\n" );
return FALSE;
}
// メインウインドウとして登録
CApp::SetHWnd( hWnd );
// ステートスロット
m_nStateSlot = 0;
return TRUE;
}
void CMainFrame::Destroy()
{
if( m_hWnd && IsWindow(m_hWnd) ) {
::DestroyWindow( m_hWnd );
m_hWnd = NULL;
}
}
BOOL CMainFrame::PreTranslateMessage( MSG* pMsg )
{
if( pMsg->message >= WM_KEYFIRST && pMsg->message <= WM_KEYLAST ) {
// return TRUE;
}
return FALSE;
}
WNDMSG CMainFrame::OnCreate( WNDMSGPARAM )
{
// DEBUGOUT( "CMainFrame::OnCreate\n" );
DirectDraw.SetSystemMemory( Config.graphics.bSystemMemory );
DirectDraw.SetUseHEL ( Config.graphics.bUseHEL );
if( !DirectDraw.InitialDDraw( m_hWnd ) ) {
hResult = -1L;
return TRUE;
}
if( !DirectSound.InitialDSound( m_hWnd ) ) {
hResult = -1L;
return TRUE;
}
if( !DirectInput.InitialDInput( m_hWnd, CApp::GetInstance() ) ) {
hResult = -1L;
return TRUE;
}
// DirectDrawオプションの設定
DirectDraw.SetFlipMode ( Config.graphics.bSyncDraw );
DirectDraw.SetAspectMode ( Config.graphics.bAspect );
DirectDraw.SetAllLineMode ( Config.graphics.bAllLine );
DirectDraw.SetMaxZoom ( Config.graphics.bFitZoom );
DirectDraw.SetTVFrameMode ( Config.graphics.bTVFrame );
DirectDraw.SetScanlineMode ( Config.graphics.bScanline );
DirectDraw.SetScanlineColor( Config.graphics.nScanlineColor );
DirectDraw.SetWindowVSyncMode( Config.graphics.bWindowVSync );
DirectDraw.SetDoubleSize( Config.graphics.bDoubleSize );
DirectDraw.SetGraphicsFilter( Config.graphics.nGraphicsFilter );
// DirectDrawサーフェスの構築
if( !DirectDraw.InitialSurface( FALSE ) ) {
hResult = -1L;
return TRUE;
}
// パレットファイルのロード
if( Config.graphics.bPaletteFile ) {
string pathstr = CPathlib::CreatePath( CApp::GetModulePath(), Config.graphics.szPaletteFile );
DirectDraw.SetPaletteFile( pathstr.c_str() );
}
// DirectSoundオプションの設定
DirectSound.SetSamplingRate( Config.sound.nRate, Config.sound.nBits );
DirectSound.SetBufferSize( Config.sound.nBufferSize );
// ExtraSoundFileのロード
for( INT i = 0; i < ESF_FILE_MAX; i++ ) {
string pathstr = CPathlib::CreatePath( CApp::GetModulePath(), Config.extsound.szExtSoundFile[i] );
DirectSound.LoadEsf( pathstr.c_str(), i );
}
// DirectInputオプションの設定
DirectInput.SetJoyAxisMode( Config.general.JoyAxisSetting );
// DirectSoundバッファの構築
if( !DirectSound.InitialBuffer() ) {
hResult = -1L;
return TRUE;
}
// パレットテーブルの計算
DirectDraw.CalcPaletteTable();
// ネットプレイ
NetPlay.Initialize( m_hWnd );
// メニューのロード
m_hMenu = CApp::LoadMenu( IDR_MENU );
CApp::SetMenu( m_hMenu );
::SetMenu( m_hWnd, m_hMenu );
m_bMenu = TRUE; // メニュー表示中フラグ
// メニューにアクセラレータキー名の追加
OnRebuildMenu();
// ウインドウ位置の設定
RECT rc = Config.general.rcWindowPos;
if( !((rc.right-rc.left) <= 0 || (rc.bottom-rc.top) <= 0) ) {
if( (m_bZoomed = Config.general.bWindowZoom) ) {
CApp::SetCmdShow( SW_SHOWMAXIMIZED );
}
// 保存されていたウインドウサイズにする
m_WindowRect = rc;
::SetWindowPos( m_hWnd, HWND_NOTOPMOST, rc.left, rc.top,
rc.right-rc.left, rc.bottom-rc.top, 0 );
} else {
m_bZoomed = FALSE;
// デフォルトサイズを調整する
OnSetWindowSize();
}
// ウインドウスタイルの保存
m_StyleBackup = ::GetWindowLong( m_hWnd, GWL_STYLE );
m_ExStyleBackup = ::GetWindowLong( m_hWnd, GWL_EXSTYLE );
// IME使用禁止:D
::ImmAssociateContext( m_hWnd, NULL );
// Drag&Dropの許可
::DragAcceptFiles( m_hWnd, TRUE );
// フラグ類
m_bActivate = TRUE;
m_bActivateApp = TRUE;
m_bForcus = TRUE;
m_bCursor = TRUE;
m_bEnable = TRUE;
m_bKeyEnable = TRUE;
m_bKeyChecking = FALSE;
m_LastMovedTime = 0;
m_uTimerID = ::SetTimer( m_hWnd, 0x0001, 1000, NULL );
// m_uKeyTimerID = ::SetTimer( m_hWnd, 0x0100, 30, NULL ); // 30ms
m_dwKeyTime = 0;
// Key Thread
::memset( m_KeyBuf, 0x00, sizeof(m_KeyBuf) );
::memset( m_KeyOld, 0x00, sizeof(m_KeyBuf) );
::memset( m_KeyCnt, 0x00, sizeof(m_KeyCnt) );
::_beginthread( KeyThreadProc, 0, NULL );
ZEROMEMORY( m_KeyBuf, sizeof(m_KeyBuf) );
ZEROMEMORY( m_KeyCnt, sizeof(m_KeyCnt) );
#if 0
// For Command Lines
if( ::strlen( CApp::GetCmdLine() ) > 0 ) {
LPSTR pCmd = CApp::GetCmdLine();
if( pCmd[0] == '"' ) { // Shell execute!!
ZEROMEMORY( m_szCommandLine, sizeof(m_szCommandLine) );
::memcpy( m_szCommandLine, pCmd+1, ::strlen(pCmd)-2 );
m_szCommandLine[::strlen(m_szCommandLine)] = '\0';
} else {
::strcpy( m_szCommandLine, pCmd );
}
::PostMessage( m_hWnd, WM_VNS_COMMANDLINE, 0, 0L );
}
#endif
return FALSE;
}
WNDMSG CMainFrame::OnClose( WNDMSGPARAM )
{
// DEBUGOUT( "CMainFrame::OnClose\n" );
// ネットプレイ
NetPlay.Release();
// エミュレーション終了
Emu.Stop();
DELETEPTR( Nes );
// キースレッド終了
m_bKeyThreadExit = TRUE;
// タイマーの終了
::KillTimer( m_hWnd, m_uTimerID );
// ::KillTimer( m_hWnd, m_uKeyTimerID );
m_uTimerID = 0;
m_uKeyTimerID = 0;
// ウインドウ破棄
::DestroyWindow( m_hWnd );
// サーチダイアログ終了
m_SearchDlg.Destroy();
// ランチャー終了
m_LauncherDlg.Destroy();
// チャット終了
m_ChatDlg.Destroy();
// パターンビュア終了
m_PatternView.Destroy();
m_NameTableView.Destroy();
m_PaletteView.Destroy();
m_MemoryView.Destroy();
// バーコード入力ダイアログ終了
m_DatachBarcodeDlg.Destroy();
// パレット編集の終了
m_PaletteEdit.Destroy();
// ウインドウ位置の保存
Config.general.bWindowZoom = m_bZoomed;
Config.general.rcWindowPos = m_WindowRect;
::DragAcceptFiles( m_hWnd, FALSE );
return FALSE;
}
WNDMSG CMainFrame::OnDestroy( WNDMSGPARAM )
{
// DEBUGOUT( "CMainFrame::OnDestroy\n" );
::PostQuitMessage( 0 );
return FALSE;
}
WNDMSG CMainFrame::OnGetMinMaxInfo( WNDMSGPARAM )
{
MINMAXINFO* lpMMI = (MINMAXINFO*)lParam;
// 最小サイズだけ
lpMMI->ptMinTrackSize.x = 128;
lpMMI->ptMinTrackSize.y = 128;
// lpMMI->ptMaxTrackSize.x = 65535;
// lpMMI->ptMaxTrackSize.y = 65535;
return TRUE;
}
WNDMSG CMainFrame::OnActivate( WNDMSGPARAM )
{
//DEBUGOUT( "WA_ACTIVATE: Minimized:%s Prev:%08X This:%08X\n", HIWORD(wParam)?"TRUE":"FALSE", lParam, m_hWnd );
#if 1
if( HIWORD(wParam) || (LOWORD(wParam) == WA_INACTIVE && !lParam) ) {
if( m_bActivate ) {
// DEBUGOUT( "Inactivate.\n" );
m_bActivate = FALSE;
// バックグラウンド動作ONかネットプレイ中はポーズしない
if( !(Config.emulator.bBackground || NetPlay.IsConnect()) ) {
Emu.Pause();
}
}
// DirectInput無効化
DirectInput.Unacquire();
} else if( !lParam ) {
// DEBUGOUT( "Activate.\n" );
m_bActivate = TRUE;
// バックグラウンド動作ONかネットプレイ中はレジュームしない
if( !(Config.emulator.bBackground || NetPlay.IsConnect()) ) {
Emu.Resume();
}
// DirectInput有効
DirectInput.Acquire();
}
#else
if( LOWORD(wParam) == WA_INACTIVE ) {
// DEBUGOUT( "WM_ACTIVATE: WA_INACTIVE\n" );
//// DEBUGOUT( "CMainFrame::OnActivate:Inactive\n" );
m_bActivate = FALSE;
//// m_bActivate = TRUE;
} else if( LOWORD(wParam) == WA_ACTIVE ) {
// DEBUGOUT( "WM_ACTIVATE: WA_ACTIVE\n" );
//// DEBUGOUT( "CMainFrame::OnActivate:Active\n" );
m_bActivate = TRUE;
} else if( LOWORD(wParam) == WA_CLICKACTIVE ) {
// DEBUGOUT( "WM_ACTIVATE: WA_CLICKACTIVE\n" );
//// DEBUGOUT( "CMainFrame::OnActivate:ClickActive\n" );
m_bActivate = TRUE;
}
#endif
return FALSE;
}
WNDMSG CMainFrame::OnActivateApp( WNDMSGPARAM )
{
//DEBUGOUT( "wParam:%08X lParam:%08X\n", wParam, lParam );
#if 0
if( (BOOL)wParam ) {
// DEBUGOUT( "CMainFrame::OnActivateApp:Active\n" );
m_bActivateApp = TRUE;
// バックグラウンド動作ONかネットプレイ中はレジュームしない
if( !(Config.emulator.bBackground || NetPlay.IsConnect()) ) {
Emu.Resume();
}
DirectInput.Acquire();
} else {
// DEBUGOUT( "CMainFrame::OnActivateApp:Inactive\n" );
if( m_bActivateApp ) {
m_bActivateApp = FALSE;
// バックグラウンド動作ONかネットプレイ中はポーズしない
if( !(Config.emulator.bBackground || NetPlay.IsConnect()) ) {
Emu.Pause();
}
}
DirectInput.Unacquire();
}
#else
if( (BOOL)wParam ) {
// DEBUGOUT( "CMainFrame::OnActivateApp:Active\n" );
m_bActivateApp = TRUE;
if( !m_bActivate ) {
m_bActivate = TRUE;
// バックグラウンド動作ONかネットプレイ中はレジュームしない
if( !(Config.emulator.bBackground || NetPlay.IsConnect()) ) {
Emu.Resume();
}
}
DirectInput.Acquire();
} else {
// DEBUGOUT( "CMainFrame::OnActivateApp:Inactive\n" );
m_bActivateApp = FALSE;
if( m_bActivate ) {
m_bActivate = FALSE;
// バックグラウンド動作ONかネットプレイ中はポーズしない
if( !(Config.emulator.bBackground || NetPlay.IsConnect()) ) {
Emu.Pause();
}
}
DirectInput.Unacquire();
}
#endif
return FALSE;
}
WNDMSG CMainFrame::OnShortCutEnable( WNDMSGPARAM )
{
// DEBUGOUT( "CMainFrame::OnShortCutmode Req=%s\n", (BOOL)wParam?"TRUE":"FALSE" );
if( (BOOL)wParam ) {
if( m_bEnable ) {
m_bKeyEnable = TRUE;
//DEBUGOUT( "CMainFrame::OnShortCutmode TRUE\n" );
}
} else {
m_bKeyEnable = FALSE;
//DEBUGOUT( "CMainFrame::OnShortCutmode FALSE\n" );
}
// m_bKeyEnable = (BOOL)wParam;
#if 0
if( (BOOL)wParam ) {
if( --m_nKeyDisableCount < 0 ) {
m_bKeyEnable = TRUE;
}
} else {
m_nKeyDisableCount++;
m_bKeyEnable = FALSE;
}
#endif
return FALSE;
}
WNDMSG CMainFrame::OnEnable( WNDMSGPARAM )
{
// DEBUGOUT( "CMainFrame::OnEnable = %s\n", (BOOL)wParam?"TRUE":"FALSE" );
if( (BOOL)wParam )
Emu.Resume();
else
Emu.Pause();
m_bEnable = (BOOL)wParam;
m_bKeyEnable = (BOOL)wParam;
return FALSE;
}
WNDMSG CMainFrame::OnEnterMenuLoop( WNDMSGPARAM )
{
// DEBUGOUT( "CMainFrame::OnEnterMenuLoop\n" );
m_bKeyEnable = FALSE;
Emu.Pause();
return FALSE;
}
WNDMSG CMainFrame::OnExitMenuLoop( WNDMSGPARAM )
{
// DEBUGOUT( "CMainFrame::OnExitMenuLoop\n" );
m_bKeyEnable = TRUE;
Emu.Resume();
return FALSE;
}
WNDMSG CMainFrame::OnSetFocus( WNDMSGPARAM )
{
// DEBUGOUT( "CMainFrame::OnSetFocus\n" );
m_bForcus = TRUE;
if( Config.general.bScreenMode ) {
if( Emu.IsRunning() ) {
if( !m_bMenu ) {
Emu.EventParam( CEmuThread::EV_FULLSCREEN_GDI, FALSE );
}
}
}
return FALSE;
}
WNDMSG CMainFrame::OnKillFocus( WNDMSGPARAM )
{
// DEBUGOUT( "CMainFrame::OnKillFocus\n" );
m_bForcus = FALSE;
return FALSE;
}
WNDMSG CMainFrame::OnInitMenu( WNDMSGPARAM )
{
// DEBUGOUT( "CMainFrame::OnInitMenu\n" );
CRecent::UpdateMenu( CApp::GetMenu() );
DrawMenuBar( m_hWnd );
return FALSE;
}
WNDMSG CMainFrame::OnInitMenuPopup( WNDMSGPARAM )
{
// DEBUGOUT( "CMainFrame::OnInitMenuPopup\n" );
// System menu
if( (BOOL)HIWORD(lParam) )
return FALSE;
// DEBUGOUT( "SubMenu=%08X uPos=%d bSys=%d\n", wParam, (UINT)LOWORD(lParam), (UINT)HIWORD(lParam) );
HMENU hMenu = (HMENU)wParam;
INT MenuCount = ::GetMenuItemCount( hMenu );
for( INT i = 0; i < MenuCount; i++ ) {
OnUpdateMenu( hMenu, ::GetMenuItemID( hMenu, i ) );
}
return FALSE;
}
WNDMSG CMainFrame::OnPaint( WNDMSGPARAM )
{
// DEBUGOUT( "CMainFrame::OnPaint\n" );
HDC hDC;
PAINTSTRUCT ps;
hDC = ::BeginPaint( m_hWnd, &ps );
if( !Emu.IsRunning() ) {
RECT rc;
::GetClientRect( m_hWnd, &rc );
::SetBkColor( hDC, 0x00000000 );
::ExtTextOut( hDC, 0, 0, ETO_OPAQUE, &rc, NULL, 0, NULL );
} else if( Emu.IsPausing() ) {
DirectDraw.OnScreenDraw();
}
::EndPaint( m_hWnd, &ps );
return TRUE;
}
WNDMSG CMainFrame::OnDisplayChange( WNDMSGPARAM )
{
// DEBUGOUT( "CMainFrame::OnDisplayChange\n" );
// フルスクリーンならば自分でチェンジ中もしくはALT+TAB切り替え中
if( !Config.general.bScreenMode ) {
// 危険なのでスレッドをポーズ
Emu.Pause();
DirectDraw.OnChangeDisplayMode();
// 再描画
::InvalidateRect( m_hWnd, NULL, TRUE );
// スレッドをレジューム
Emu.Resume();
}
return FALSE;
}
WNDMSG CMainFrame::OnPaletteChanged( WNDMSGPARAM )
{
if( (HWND)wParam == m_hWnd )
return FALSE;
DirectDraw.RealizePalette();
return FALSE;
}
WNDMSG CMainFrame::OnQueryNewPalette( WNDMSGPARAM )
{
DirectDraw.RealizePalette();
return TRUE;
}
WNDMSG CMainFrame::OnMenuChar( WNDMSGPARAM )
{
// DEBUGOUT( "CMainFrame::OnMenuChar\n" );
// キンキンうるさいから閉じる…と嘘をつく
hResult = MAKELONG(0,MNC_CLOSE);
return TRUE;
}
WNDMSG CMainFrame::OnKeyDown( WNDMSGPARAM )
{
// DEBUGOUT( "CMainFrame::OnKeyDown\n" );
if( Config.general.bScreenMode ) {
if( wParam == VK_ESCAPE && (lParam & (1<<30)) == 0 ) {
OnChangeMenu( !m_bMenu );
return TRUE;
}
}
return FALSE;
}
WNDMSG CMainFrame::OnSize( WNDMSGPARAM )
{
// 最大化表示等
// WM_SYSCOMMANDでも良いのだが,キャプションをダブルクリックしたときに来ないので...
switch( wParam ) {
case SIZE_MAXIMIZED:
m_bZoomed = TRUE;
{
WINDOWPLACEMENT wpl;
::GetWindowPlacement( m_hWnd, &wpl );
m_WindowRect = wpl.rcNormalPosition; // 元の位置をコピー
}
break;
case SIZE_RESTORED:
m_bZoomed = FALSE;
break;
default:
break;
}
return FALSE;
}
WNDMSG CMainFrame::OnSysCommand( WNDMSGPARAM )
{
// エミュレーション中のみ
if( Emu.IsRunning() ) {
// スクリーンセーバーの起動の抑止
if( wParam == SC_SCREENSAVE ) {
// DEBUGOUT( "CMainFrame::OnSysCommand SC_SCREENSAVE\n" );
hResult = 1L;
return TRUE;
}
// ディスプレイ電源オフの抑止
if( wParam == SC_MONITORPOWER ) {
// DEBUGOUT( "CMainFrame::OnSysCommand SC_MONITORPOWER\n" );
hResult = 1L;
return TRUE;
}
}
return FALSE;
}
WNDMSG CMainFrame::OnExitSizeMove( WNDMSGPARAM )
{
// DEBUGOUT( "CMainFrame::OnExitSizeMove\n" );
if( !Config.general.bScreenMode ) {
::GetWindowRect( m_hWnd, &m_WindowRect );
}
return FALSE;
}
WNDMSG CMainFrame::OnSetCursor( WNDMSGPARAM )
{
// DEBUGOUT( "CMainFrame::OnSetCursor\n" );
if( LOWORD(lParam) == HTCLIENT ) {
if( Emu.IsRunning() ) {
// if( !Emu.IsPausing() && !Emu.IsEmuPausing() ) {
if( !Emu.IsPausing() ) {
if( DirectDraw.GetZapperMode() ) {
m_bCursor = TRUE;
::SetCursor( NULL );
hResult = 1L;
return TRUE;
} else {
m_bCursor = FALSE;
m_LastMovedTime = ::timeGetTime();
}
} else {
m_bCursor = TRUE;
}
} else {
m_bCursor = TRUE;
}
} else {
m_bCursor = TRUE;
}
return FALSE;
}
WNDMSG CMainFrame::OnTimer( WNDMSGPARAM )
{
// DEBUGOUT( "CMainFrame::OnTimer\n" );
// DEBUGOUT( "CMainFrame::OnTimer bCursor=%s bForcus=%s\n", m_bCursor?"TRUE":"FALSE", m_bForcus?"TRUE":"FALSE" );
if( wParam == 0x0001 ) {
// マウスカーソル用タイマー
RECT rc;
POINT pt;
::GetWindowRect( m_hWnd, &rc );
::GetCursorPos( &pt );
if( !m_bCursor && m_bForcus && pt.x >= rc.left && pt.x <= rc.right && pt.y >= rc.top && pt.y <= rc.bottom ) {
if( Emu.IsRunning() && !Emu.IsPausing() ) {
if( (::timeGetTime()-m_LastMovedTime) > 1500 ) {
::SetCursor( NULL );
}
}
}
} else if( wParam == 0x0100 ) {
// キーチェック用タイマー
// アクティブウインドウでない時やダイアログ等が出ている時はキャンセル
//// if( m_bActivate && m_bKeyEnable )
//// if( m_bKeyEnable )
// OnKeyControl();
}
return FALSE;
}
WNDMSG CMainFrame::OnCopyData( WNDMSGPARAM )
{
// DEBUGOUT( "CMainFrame::OnCopyData\n" );
COPYDATASTRUCT* pcds = (COPYDATASTRUCT*)lParam;
OnEmulationStart( (LPSTR)pcds->lpData, FALSE );
return TRUE;
}
WNDMSG CMainFrame::OnErrorMessage( WNDMSGPARAM )
{
// DEBUGOUT( "CMainFrame::OnErrorMessage\n" );
// チャット終了
m_ChatDlg.Destroy();
// サーチダイアログ終了
m_SearchDlg.Destroy();
// パターンビュア終了
m_PatternView.Destroy();
m_NameTableView.Destroy();
m_PaletteView.Destroy();
m_MemoryView.Destroy();
// バーコード入力ダイアログ終了
m_DatachBarcodeDlg.Destroy();
// NetPlay切断
NetPlay.Disconnect();
// エミュレーション終了
Emu.Stop();
DELETEPTR( Nes );
// キャプションを変える
::SetWindowText( m_hWnd, VIRTUANES_CAPTION );
if( Config.general.bScreenMode ) {
OnFullScreenGDI( TRUE );
}
::MessageBox( m_hWnd, (LPCTSTR)lParam, "ERROR", MB_ICONERROR|MB_OK );
::InvalidateRect( m_hWnd, NULL, TRUE );
if( Config.general.bScreenMode ) {
OnChangeMenu( TRUE );
}
return TRUE;
}
WNDCMD CMainFrame::OnExit( WNDCMDPARAM )
{
// DEBUGOUT( "CMainFrame::OnExit\n" );
::PostMessage( m_hWnd, WM_CLOSE, 0, 0 );
}
WNDCMD CMainFrame::OnHelp( WNDCMDPARAM )
{
// DEBUGOUT( "CMainFrame::OnHelp\n" );
string sHelp = CPathlib::MakePath( CApp::GetModulePath(), "virtuanes.chm" );
// 面倒なんでShellExecuteで代用
::ShellExecute( HWND_DESKTOP, "open", sHelp.c_str(), NULL, NULL, SW_SHOWNORMAL );
// ::HtmlHelp( m_hWnd, "virtuanes.chm", HH_DISPLAY_TOPIC, NULL );
}
WNDCMD CMainFrame::OnAbout( WNDCMDPARAM )
{
// DEBUGOUT( "CMainFrame::OnAbout\n" );
CAboutDlg dlg;
dlg.DoModal( m_hWnd );
}
WNDCMD CMainFrame::OnFileOpen( WNDCMDPARAM )
{
// DEBUGOUT( "CMainFrame::OnFileOpen\n" );
if( Emu.IsRunning() ) {
Emu.Pause();
}
if( Config.general.bScreenMode ) {
if( Emu.IsRunning() ) {
OnFullScreenGDI( TRUE );
}
}
OPENFILENAME ofn;
CHAR szFile[_MAX_PATH];
ZEROMEMORY( szFile, sizeof(szFile) );
ZEROMEMORY( &ofn, sizeof(ofn) );
string pathstr;
if( Config.path.bRomPath ) {
pathstr = CPathlib::CreatePath( CApp::GetModulePath(), Config.path.szRomPath );
} else {
pathstr = CApp::GetModulePath();
}
CHAR szTitle[256];
CApp::LoadString( IDS_UI_OPENROM, szTitle, sizeof(szTitle) );
ofn.lpstrTitle = szTitle;
ofn.lStructSize = sizeof(ofn);
ofn.hwndOwner = m_hWnd;
ofn.lpstrFile = szFile;