2017-11-09 07:06:52 +00:00
|
|
|
#pragma once
|
|
|
|
|
2019-01-13 08:12:00 +00:00
|
|
|
#include <Project64-core/Settings/SettingType/SettingsType-Application.h>
|
2016-01-27 09:11:59 +00:00
|
|
|
template <class T>
|
|
|
|
class CDebugDialog :
|
|
|
|
public CDialogImpl < T >
|
|
|
|
{
|
|
|
|
protected:
|
|
|
|
CDebuggerUI * m_Debugger;
|
|
|
|
HANDLE m_CreatedEvent;
|
|
|
|
HANDLE m_DialogThread;
|
2019-01-14 07:06:01 +00:00
|
|
|
UISettingID m_UISettingID;
|
|
|
|
bool m_bInitialized;
|
2016-01-27 09:11:59 +00:00
|
|
|
|
|
|
|
static DWORD CreateDebuggerWindow(CDebugDialog<T> * pThis)
|
|
|
|
{
|
2021-04-12 11:35:39 +00:00
|
|
|
pThis->DoModal(nullptr);
|
2016-01-27 09:11:59 +00:00
|
|
|
pThis->WindowCreated();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void WindowCreated(void)
|
|
|
|
{
|
|
|
|
SetEvent(m_CreatedEvent);
|
|
|
|
}
|
|
|
|
|
2019-01-14 07:06:01 +00:00
|
|
|
void DlgSavePos_Init(UISettingID uiSettingID)
|
|
|
|
{
|
|
|
|
m_UISettingID = uiSettingID;
|
|
|
|
m_bInitialized = true;
|
|
|
|
}
|
2019-01-14 04:03:02 +00:00
|
|
|
|
2019-12-25 00:41:20 +00:00
|
|
|
void LoadWindowPos()
|
|
|
|
{
|
2019-01-14 04:03:02 +00:00
|
|
|
|
2019-01-14 07:06:01 +00:00
|
|
|
if (!m_bInitialized)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2019-01-14 04:03:02 +00:00
|
|
|
|
2019-01-14 07:06:01 +00:00
|
|
|
T* pT = static_cast<T*>(this);
|
|
|
|
std::string str = UISettingsLoadStringVal(m_UISettingID);
|
|
|
|
int left, top, width, height;
|
|
|
|
int nParams = sscanf(str.c_str(), "%d,%d,%d,%d", &left, &top, &width, &height);
|
|
|
|
if (nParams == 4)
|
|
|
|
{
|
2021-04-12 11:35:39 +00:00
|
|
|
pT->SetWindowPos(nullptr, left, top, width, height, 0);
|
2019-01-14 07:06:01 +00:00
|
|
|
pT->RedrawWindow();
|
|
|
|
}
|
2019-04-19 01:18:55 +00:00
|
|
|
if (nParams == 2) {
|
2021-04-12 11:35:39 +00:00
|
|
|
pT->SetWindowPos(nullptr, left, top, width, height, 1);
|
2019-04-19 01:18:55 +00:00
|
|
|
pT->RedrawWindow();
|
|
|
|
}
|
2019-12-25 00:41:20 +00:00
|
|
|
}
|
2019-01-14 04:03:02 +00:00
|
|
|
|
2019-12-25 00:41:20 +00:00
|
|
|
void SaveWindowPos(bool bSaveSize)
|
|
|
|
{
|
2019-01-14 07:06:01 +00:00
|
|
|
if (!m_bInitialized)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2019-04-19 01:18:55 +00:00
|
|
|
|
2019-01-14 07:06:01 +00:00
|
|
|
T* pT = static_cast<T*>(this);
|
|
|
|
CRect rect;
|
|
|
|
pT->GetWindowRect(&rect);
|
2019-04-19 01:18:55 +00:00
|
|
|
if (!bSaveSize) {
|
|
|
|
UISettingsSaveString(m_UISettingID, stdstr_f("%d,%d", rect.left, rect.top).c_str());
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
UISettingsSaveString(m_UISettingID, stdstr_f("%d,%d,%d,%d", rect.left, rect.top, rect.Width(), rect.Height()).c_str());
|
|
|
|
}
|
2019-12-25 00:41:20 +00:00
|
|
|
}
|
2019-01-14 04:03:02 +00:00
|
|
|
|
2016-01-27 09:11:59 +00:00
|
|
|
public:
|
|
|
|
CDebugDialog(CDebuggerUI * debugger) :
|
|
|
|
m_Debugger(debugger),
|
2021-04-12 11:35:39 +00:00
|
|
|
m_CreatedEvent(CreateEvent(nullptr, true, false, nullptr)),
|
|
|
|
m_DialogThread(nullptr)
|
2016-01-27 09:11:59 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
virtual ~CDebugDialog(void)
|
|
|
|
{
|
|
|
|
HideWindow();
|
|
|
|
CloseHandle(m_CreatedEvent);
|
|
|
|
if (m_DialogThread)
|
|
|
|
{
|
|
|
|
CloseHandle(m_DialogThread);
|
2021-04-12 11:35:39 +00:00
|
|
|
m_DialogThread = nullptr;
|
2016-01-27 09:11:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void HideWindow(void)
|
|
|
|
{
|
|
|
|
if (m_hWnd && ::IsWindow(m_hWnd))
|
|
|
|
{
|
|
|
|
::EndDialog(m_hWnd, 0);
|
|
|
|
}
|
|
|
|
if (m_DialogThread)
|
|
|
|
{
|
|
|
|
if (WaitForSingleObject(m_DialogThread, 5000) == WAIT_TIMEOUT)
|
|
|
|
{
|
|
|
|
WriteTrace(TraceUserInterface, TraceError, "CDebugDialog - time out on close");
|
|
|
|
|
|
|
|
TerminateThread(m_DialogThread, 1);
|
|
|
|
}
|
|
|
|
CloseHandle(m_DialogThread);
|
2021-04-12 11:35:39 +00:00
|
|
|
m_DialogThread = nullptr;
|
2016-01-27 09:11:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ShowWindow(void)
|
|
|
|
{
|
2021-04-12 11:35:39 +00:00
|
|
|
if (m_hWnd == nullptr)
|
2016-01-27 09:11:59 +00:00
|
|
|
{
|
|
|
|
DWORD ThreadID;
|
|
|
|
ResetEvent(m_CreatedEvent);
|
2021-04-12 11:35:39 +00:00
|
|
|
m_DialogThread = CreateThread(nullptr, 0, (LPTHREAD_START_ROUTINE)CreateDebuggerWindow, (LPVOID)this, 0, &ThreadID);
|
2016-01-27 09:11:59 +00:00
|
|
|
if (WaitForSingleObject(m_CreatedEvent, 20000) == WAIT_TIMEOUT)
|
|
|
|
{
|
|
|
|
WriteTrace(TraceUserInterface, TraceError, "Failed to get window create notification");
|
|
|
|
}
|
|
|
|
}
|
2018-01-18 06:53:07 +00:00
|
|
|
if (m_hWnd)
|
|
|
|
{
|
2021-04-12 11:35:39 +00:00
|
|
|
if (::IsIconic((HWND)m_hWnd))
|
|
|
|
{
|
2019-01-11 04:05:21 +00:00
|
|
|
SendMessage(m_hWnd, WM_SYSCOMMAND, SC_RESTORE, NULL);
|
|
|
|
}
|
2018-01-18 06:53:07 +00:00
|
|
|
SetForegroundWindow((HWND)m_hWnd);
|
|
|
|
}
|
2016-01-27 09:11:59 +00:00
|
|
|
}
|
2019-01-13 08:12:00 +00:00
|
|
|
private:
|
|
|
|
bool m_SaveWnd;
|
|
|
|
LONG m_SaveWndTop;
|
|
|
|
LONG m_SaveWndLeft;
|
2021-03-18 03:29:23 +00:00
|
|
|
};
|