diff --git a/ECTrainer2/BaseProcess.cpp b/ECTrainer2/BaseProcess.cpp index ffbfab4..316b1d3 100644 --- a/ECTrainer2/BaseProcess.cpp +++ b/ECTrainer2/BaseProcess.cpp @@ -8,6 +8,7 @@ , _messageQueReady(false) , _threadHandle(NULL) , _threadID(0) + , _mainThread(false) { } @@ -24,7 +25,10 @@ // �X���b�h�{�� bool BaseProcess::MainLoop() { - if (_threadID == 0) _threadID = ::GetCurrentThreadId(); // ���C���X���b�hID�擾 + if (_threadID == 0) { + _mainThread = true; + _threadID = ::GetCurrentThreadId(); // ���C���X���b�hID�擾 + } mwut::DebugPrintf(_T("Thread %d start\n"), _threadID); // ���b�Z�[�W���[�v @@ -32,6 +36,10 @@ while (1) { if (::PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE)) { if (!::GetMessage(&msg, NULL, 0, 0)) break; + if (_mainThread) { // ���C���X���b�h�ł̓E�C���h�E�v���V�[�W���Ƀf�B�X�p�b�`���� + ::TranslateMessage(&msg); + ::DispatchMessage(&msg); + } if (!this->EventProc(msg)) break; } else { if (!this->Routine()) break; diff --git a/ECTrainer2/BaseProcess.h b/ECTrainer2/BaseProcess.h index 6e1e48f..9a02161 100644 --- a/ECTrainer2/BaseProcess.h +++ b/ECTrainer2/BaseProcess.h @@ -14,6 +14,7 @@ bool _messageQueReady; // ���b�Z�[�W�L���[�̏����� HANDLE _threadHandle; // �X���b�h�n���h�� DWORD _threadID; // �X���b�hID + bool _mainThread; // ���C��(GUI)�X���b�h���ǂ��� // �X���b�h�G���g���|�C���g static DWORD WINAPI ThreadEntry(LPVOID lpParameter); diff --git a/ECTrainer2/ECTrainer.cpp b/ECTrainer2/ECTrainer.cpp index 2c3fd26..dca7d3c 100644 --- a/ECTrainer2/ECTrainer.cpp +++ b/ECTrainer2/ECTrainer.cpp @@ -44,8 +44,8 @@ } // �X���b�h�J�n - for (int i = (int)PROC::REST; i < (int)PROC::NUM; i++) { - if (!_pProcs[i]->Launch()) return false; + for (int i = 0; i < (int)PROC::NUM; i++) { + if (i != (int)PROC::GUI) _pProcs[i]->Launch(); } _pProcs[(int)PROC::GUI]->MainLoop(); diff --git a/ECTrainer2/ECTrainerGUI.cpp b/ECTrainer2/ECTrainerGUI.cpp index e7b7261..fdcb2a5 100644 --- a/ECTrainer2/ECTrainerGUI.cpp +++ b/ECTrainer2/ECTrainerGUI.cpp @@ -21,7 +21,7 @@ , _DispImageHeight(0) , _SceneBufferScale(1.F) , _hWndMain(NULL) - , _AppRunning(true) + //, _AppRunning(true) , _dsm(NULL) { _dsm = new DShowMovie(); @@ -162,40 +162,65 @@ if (!_dsm->IsPlaying()) cv::imshow(WIN_DISP, _FullDispBuf); if (snapshot) cv::imwrite(SNAPSHOT_FILE, _MainFrame); - // �L�[���� - int key = cv::waitKey(1); - switch (key) { - case '1': PlaySound(_T("../voices/Good_S.wav"), NULL, SND_FILENAME | SND_ASYNC); break; - case '2': PlaySound(_T("../voices/Nice_S.wav"), NULL, SND_FILENAME | SND_ASYNC); break; - case '3': PlaySound(_T("../voices/Great_S.wav"), NULL, SND_FILENAME | SND_ASYNC); break; - case '4': PlaySound(_T("../voices/Excellent_S.wav"), NULL, SND_FILENAME | SND_ASYNC); break; - case '5': PlaySound(_T("../voices/Good_L.wav"), NULL, SND_FILENAME | SND_ASYNC); break; - case '6': PlaySound(_T("../voices/Nice_L.wav"), NULL, SND_FILENAME | SND_ASYNC); break; - case '7': PlaySound(_T("../voices/Great_L.wav"), NULL, SND_FILENAME | SND_ASYNC); break; - case '8': PlaySound(_T("../voices/Excellent_L.wav"), NULL, SND_FILENAME | SND_ASYNC); break; + //int key = cv::waitKey(1); + if (_hWndMain != ::FindWindowA(NULL, WIN_MAIN.c_str())) { + mwut::DebugPrintf(_T("getWindowProperty\n")); + ((BaseProcess*)_pEct->PWorker())->PostMsg(ECTMSG::SOFTWARE_END); + } - if (key == KEY_ESC || cv::getWindowProperty(WIN_MAIN, 0) < 0) { + if (cv::getWindowProperty(WIN_MAIN, 0) < 0) { // �E�C���h�E�~�{�^���ŕ‚����� + mwut::DebugPrintf(_T("getWindowProperty\n")); ((BaseProcess*)_pEct->PWorker())->PostMsg(ECTMSG::SOFTWARE_END); } + // �L�[���� + //int key = cv::waitKey(1); + //switch (key) { + //case '1': PlaySound(_T("../voices/Good_S.wav"), NULL, SND_FILENAME | SND_ASYNC); break; + //case '2': PlaySound(_T("../voices/Nice_S.wav"), NULL, SND_FILENAME | SND_ASYNC); break; + //case '3': PlaySound(_T("../voices/Great_S.wav"), NULL, SND_FILENAME | SND_ASYNC); break; + //case '4': PlaySound(_T("../voices/Excellent_S.wav"), NULL, SND_FILENAME | SND_ASYNC); break; + //case '5': PlaySound(_T("../voices/Good_L.wav"), NULL, SND_FILENAME | SND_ASYNC); break; + //case '6': PlaySound(_T("../voices/Nice_L.wav"), NULL, SND_FILENAME | SND_ASYNC); break; + //case '7': PlaySound(_T("../voices/Great_L.wav"), NULL, SND_FILENAME | SND_ASYNC); break; + //case '8': PlaySound(_T("../voices/Excellent_L.wav"), NULL, SND_FILENAME | SND_ASYNC); break; + //} + return true; } -// �C�x���g���[�v�iGUI�̓��C���X���b�h�̂��߃��b�Z�[�W�������Ȃ�) -bool ECTrainerGUI::MainLoop() { - - while (_AppRunning) { - this->Routine(); +// �C�x���g���� +bool ECTrainerGUI::EventProc(MSG& msg) { + switch (msg.message) { + case WM_PAINT: + case WM_NCMOUSEMOVE: + case WM_NCLBUTTONDOWN: + case WM_NCMOUSELEAVE: + case WM_MOUSEMOVE: + break; + case WM_LBUTTONDOWN: + mwut::DebugPrintf(_T("-------------------------\n")); + break; + case WM_TIMER: + mwut::DebugPrintf(_T("Event Timer\n")); + break; + case WM_CHAR: + if (msg.wParam == KEY_ESC) ((BaseProcess*)_pEct->PWorker())->PostMsg(ECTMSG::SOFTWARE_END); + break; + default: + mwut::DebugPrintf(_T("Event %04X\n"), msg.message); + break; } - //_pEct->StopApp(); + return true; } + // ���b�Z�[�W�ʒm�iGUI�̓��C���X���b�h�̂��ߒ��ڏ���) -bool ECTrainerGUI::Tell(ECTMSG msg, WPARAM wp, LPARAM lp) { - if (msg == ECTMSG::QUIT) _AppRunning = false; - return true; -} +//bool ECTrainerGUI::Tell(ECTMSG msg, WPARAM wp, LPARAM lp) { +// if (msg == ECTMSG::QUIT) _AppRunning = false; +// return true; +//} // �h���摜�o�b�t�@�ɉ摜��ݒ� void ECTrainerGUI::MakeFullDispBuffer(cv::Mat& img) { diff --git a/ECTrainer2/ECTrainerGUI.h b/ECTrainer2/ECTrainerGUI.h index 7425066..fdaf7b0 100644 --- a/ECTrainer2/ECTrainerGUI.h +++ b/ECTrainer2/ECTrainerGUI.h @@ -22,7 +22,6 @@ DShowMovie* _dsm; cv::Mat _MainFrame; // ���C���E�C���h�E�t���[�� - //cv::Mat _DispImage; // �h���摜�i����җp�j cv::Mat _FullDispBuf; // �h����ʁi�팱�җp�j cv::Mat _Logo; // ���S cv::Mat _blank; // �u�����N @@ -30,12 +29,11 @@ float _SceneBufferScale; int _DispImageHeight; HWND _hWndMain; - bool _AppRunning; // ���s���t���O // ��{���� bool Routine(); - // GUI�X���b�h���C�����[�v - bool MainLoop(); + // �C�x���g���� + bool EventProc(MSG& msg); // �S��ʕ\���o�b�t�@�̐��� void MakeFullDispBuffer(cv::Mat& img); @@ -45,7 +43,7 @@ // ������ bool Init(); // GUI�X���b�h���b�Z�[�W�ʒm - bool Tell(ECTMSG msg, WPARAM wp = 0, LPARAM lp = 0); + //bool Tell(ECTMSG msg, WPARAM wp = 0, LPARAM lp = 0); // ���C����ʂ̃E�C���h�E�n���h����Ԃ� HWND GetMainHWnd() { return _hWndMain; } };