diff --git a/Source/Project64/UserInterface/CheatClassUI.cpp b/Source/Project64/UserInterface/CheatClassUI.cpp index 779836c08..2949f7958 100644 --- a/Source/Project64/UserInterface/CheatClassUI.cpp +++ b/Source/Project64/UserInterface/CheatClassUI.cpp @@ -22,13 +22,24 @@ CCheatsUI::~CCheatsUI() { } -void CCheatsUI::Display(HWND hParent) +void CCheatsUI::Display(HWND hParent, bool BlockExecution) { if (g_BaseSystem) { g_BaseSystem->ExternalEvent(SysEvent_PauseCPU_Cheats); } - DoModal(hParent); + if (BlockExecution) + { + DoModal(hParent); + } + else if (m_hWnd != NULL) + { + SetFocus(); + } + else + { + Create(hParent); + } } LRESULT CCheatsUI::OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/) @@ -90,13 +101,26 @@ LRESULT CCheatsUI::OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lPara return 0; } +LRESULT CCheatsUI::OnDestroy(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/) +{ + m_StateBtn.Detach(); + return 0; +} + LRESULT CCheatsUI::OnCloseCmd(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/) { if (g_BaseSystem) { g_BaseSystem->ExternalEvent(SysEvent_ResumeCPU_Cheats); } - EndDialog(0); + if (m_bModal) + { + EndDialog(0); + } + else + { + DestroyWindow(); + } return 0; } @@ -220,6 +244,12 @@ LRESULT CCheatList::OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lPar return true; } +LRESULT CCheatList::OnDestroy(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/) +{ + m_hCheatTree.Detach(); + return 0; +} + LRESULT CCheatList::OnChangeCodeExtension(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM lParam, BOOL& /*bHandled*/) { m_hSelectedItem = (HTREEITEM)lParam; diff --git a/Source/Project64/UserInterface/CheatClassUI.h b/Source/Project64/UserInterface/CheatClassUI.h index 899b6db2a..775e747be 100644 --- a/Source/Project64/UserInterface/CheatClassUI.h +++ b/Source/Project64/UserInterface/CheatClassUI.h @@ -24,6 +24,7 @@ class CCheatList : public: BEGIN_MSG_MAP_EX(CCheatList) MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog) + MESSAGE_HANDLER(WM_DESTROY, OnDestroy) MESSAGE_HANDLER(UM_CHANGECODEEXTENSION, OnChangeCodeExtension) COMMAND_ID_HANDLER(IDC_UNMARK, OnUnmark) COMMAND_ID_HANDLER(ID_POPUP_DELETE, OnPopupDelete) @@ -48,6 +49,7 @@ private: enum TV_CHECK_STATE { TV_STATE_UNKNOWN, TV_STATE_CLEAR, TV_STATE_CHECKED, TV_STATE_INDETERMINATE }; LRESULT OnInitDialog(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled); + LRESULT OnDestroy(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled); LRESULT OnChangeCodeExtension(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled); LRESULT OnUnmark(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled); LRESULT OnPopupDelete(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled); @@ -169,6 +171,7 @@ class CCheatsUI : public: BEGIN_MSG_MAP_EX(CCheatsUI) MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog) + MESSAGE_HANDLER(WM_DESTROY, OnDestroy) COMMAND_ID_HANDLER(IDC_STATE, OnStateChange) COMMAND_ID_HANDLER(IDCANCEL, OnCloseCmd) END_MSG_MAP() @@ -178,10 +181,11 @@ public: CCheatsUI(void); ~CCheatsUI(void); - void Display(HWND hParent); + void Display(HWND hParent, bool BlockExecution); private: LRESULT OnInitDialog(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled); + LRESULT OnDestroy(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled); LRESULT OnCloseCmd(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled); LRESULT OnStateChange(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled); diff --git a/Source/Project64/UserInterface/MainMenu.cpp b/Source/Project64/UserInterface/MainMenu.cpp index 1eb2b0406..f77c60a82 100644 --- a/Source/Project64/UserInterface/MainMenu.cpp +++ b/Source/Project64/UserInterface/MainMenu.cpp @@ -274,7 +274,7 @@ void CMainMenu::OnLodState(HWND hWnd) void CMainMenu::OnCheats(HWND hWnd) { - CCheatsUI().Display(hWnd); + m_Gui->DisplayCheatsUI(false); } void CMainMenu::OnSettings(HWND hWnd) diff --git a/Source/Project64/UserInterface/MainWindow.cpp b/Source/Project64/UserInterface/MainWindow.cpp index e4817244f..c6a2145ab 100644 --- a/Source/Project64/UserInterface/MainWindow.cpp +++ b/Source/Project64/UserInterface/MainWindow.cpp @@ -256,6 +256,10 @@ void CMainGui::GameCpuRunning(CMainGui * Gui) } else { + if (Gui->m_CheatsUI.m_hWnd != NULL) + { + Gui->m_CheatsUI.SendMessage(WM_COMMAND, MAKELONG(IDCANCEL, 0)); + } PostMessage(Gui->m_hMainWindow, WM_GAME_CLOSED, 0, 0); } } @@ -466,6 +470,11 @@ bool CMainGui::ResetPluginsInUiThread(CPlugins * plugins, CN64System * System) return bRes; } +void CMainGui::DisplayCheatsUI(bool BlockExecution) +{ + m_CheatsUI.Display(m_hMainWindow, BlockExecution); +} + void CMainGui::BringToTop(void) { CGuard Guard(m_CS); @@ -516,6 +525,10 @@ WPARAM CMainGui::ProcessAllMessages(void) SetEvent(m_ResetInfo->hEvent); m_ResetInfo = NULL; } + if (m_CheatsUI.m_hWnd != NULL && IsDialogMessage(m_CheatsUI.m_hWnd, &msg)) + { + continue; + } if (m_Menu->ProcessAccelerator(m_hMainWindow, &msg)) { continue; } TranslateMessage(&msg); DispatchMessage(&msg); @@ -1062,7 +1075,7 @@ LRESULT CALLBACK CMainGui::MainGui_Proc(HWND hWnd, DWORD uMsg, DWORD wParam, DWO } else if (LOWORD(wParam) == ID_POPUPMENU_EDITCHEATS) { - CCheatsUI().Display(hWnd); + CCheatsUI().Display(hWnd, true); } if (g_Rom) @@ -1091,7 +1104,7 @@ LRESULT CALLBACK CMainGui::MainGui_Proc(HWND hWnd, DWORD uMsg, DWORD wParam, DWO } else if (LOWORD(wParam) == ID_POPUPMENU_EDITCHEATS) { - CCheatsUI().Display(hWnd); + CCheatsUI().Display(hWnd,true); } if (g_Disk) diff --git a/Source/Project64/UserInterface/MainWindow.h b/Source/Project64/UserInterface/MainWindow.h index 69cdd332b..c99b0d35d 100644 --- a/Source/Project64/UserInterface/MainWindow.h +++ b/Source/Project64/UserInterface/MainWindow.h @@ -13,6 +13,7 @@ #include "../Settings/GuiSettings.h" #include #include +#include class CGfxPlugin; //Plugin that controls the rendering class CAudioPlugin; //Plugin for audio, need the hwnd @@ -86,6 +87,9 @@ public: //Plugins bool ResetPluginsInUiThread(CPlugins * plugins, CN64System * System); + //Cheats + void DisplayCheatsUI(bool BlockExecution); + //Get Window Handle void * GetWindowHandle(void) const { return m_hMainWindow; } void * GetStatusBar(void) const { return m_hStatusWnd; } @@ -126,6 +130,7 @@ private: HWND m_hMainWindow, m_hStatusWnd; DWORD m_ThreadId; + CCheatsUI m_CheatsUI; const bool m_bMainWindow; bool m_Created;