2016-08-11 10:38:45 +00:00
|
|
|
#include "stdafx.h"
|
2022-09-21 05:16:07 +00:00
|
|
|
|
2016-08-11 10:38:45 +00:00
|
|
|
#include "SupportEnterCode.h"
|
2016-10-02 21:48:25 +00:00
|
|
|
#include <time.h>
|
2016-08-11 10:38:45 +00:00
|
|
|
|
2020-10-22 02:11:19 +00:00
|
|
|
CSupportWindow * CSupportWindow::m_this = nullptr;
|
2016-08-11 10:38:45 +00:00
|
|
|
|
2020-10-22 02:11:19 +00:00
|
|
|
CSupportWindow::CSupportWindow(CProjectSupport & Support) :
|
|
|
|
m_Support(Support),
|
|
|
|
m_TimeOutTime(30),
|
|
|
|
m_hParent(nullptr),
|
|
|
|
m_Delay(false)
|
2016-08-11 10:38:45 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
CSupportWindow::~CSupportWindow(void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void CALLBACK CSupportWindow::TimerProc(HWND, UINT, UINT_PTR idEvent, DWORD)
|
|
|
|
{
|
2021-04-12 11:35:39 +00:00
|
|
|
::KillTimer(nullptr, idEvent);
|
2020-10-22 02:11:19 +00:00
|
|
|
m_this->DoModal(m_this->m_hParent);
|
2016-08-11 10:38:45 +00:00
|
|
|
}
|
|
|
|
|
2020-10-22 02:11:19 +00:00
|
|
|
void CSupportWindow::Show(HWND hParent, bool Delay)
|
2016-08-11 10:38:45 +00:00
|
|
|
{
|
2020-10-22 02:11:19 +00:00
|
|
|
m_Delay = Delay;
|
|
|
|
if (Delay)
|
2016-08-11 10:38:45 +00:00
|
|
|
{
|
2020-12-30 00:47:25 +00:00
|
|
|
if (m_Support.Validated())
|
2020-10-22 02:11:19 +00:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2016-08-11 10:38:45 +00:00
|
|
|
|
2020-10-22 02:11:19 +00:00
|
|
|
m_Support.IncrementRunCount();
|
2020-10-27 06:11:50 +00:00
|
|
|
if (m_Support.RunCount() < 7 || !m_Support.ShowSuppotWindow())
|
2020-10-22 02:11:19 +00:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
m_hParent = hParent;
|
|
|
|
m_this = this;
|
2021-05-30 11:11:45 +00:00
|
|
|
UISettingsSaveBool(UserInterface_ShowingNagWindow, true);
|
2020-10-22 02:11:19 +00:00
|
|
|
::SetTimer(nullptr, 0, 2500, TimerProc);
|
|
|
|
}
|
|
|
|
else
|
2016-08-11 10:38:45 +00:00
|
|
|
{
|
2021-05-30 11:11:45 +00:00
|
|
|
UISettingsSaveBool(UserInterface_ShowingNagWindow, true);
|
2020-10-22 02:11:19 +00:00
|
|
|
DoModal(hParent);
|
2016-08-11 10:38:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CSupportWindow::EnableContinue()
|
|
|
|
{
|
|
|
|
GetSystemMenu(true);
|
|
|
|
SetWindowLong(GWL_STYLE, GetWindowLong(GWL_STYLE) & ~CS_NOCLOSE);
|
|
|
|
::EnableWindow(GetDlgItem(IDCANCEL), true);
|
|
|
|
}
|
|
|
|
|
2022-09-21 05:16:07 +00:00
|
|
|
LRESULT CSupportWindow::OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL & /*bHandled*/)
|
2016-08-11 10:38:45 +00:00
|
|
|
{
|
2020-10-22 02:11:19 +00:00
|
|
|
m_Logo.SubclassWindow(GetDlgItem(IDC_BMP_LOGO));
|
|
|
|
m_Logo.SetBitmap(MAKEINTRESOURCE(IDB_ABOUT_LOGO));
|
|
|
|
|
|
|
|
std::wstring InfoText = wGS(MSG_SUPPORT_INFO);
|
|
|
|
SetWindowText(wGS(MSG_SUPPORT_TITLE).c_str());
|
|
|
|
GetDlgItem(IDC_ENTER_CODE).SetWindowText(wGS(MSG_SUPPORT_ENTER_CODE).c_str());
|
|
|
|
GetDlgItem(ID_SUPPORT_PJ64).SetWindowText(wGS(MSG_SUPPORT_PROJECT64).c_str());
|
|
|
|
GetDlgItem(IDCANCEL).SetWindowText(wGS(MSG_SUPPORT_CONTINUE).c_str());
|
|
|
|
|
|
|
|
m_EnterLink.SubclassWindow(GetDlgItem(IDC_ENTER_CODE));
|
|
|
|
m_EnterLink.SetHyperLinkExtendedStyle(HLINK_COMMANDBUTTON, HLINK_COMMANDBUTTON);
|
|
|
|
m_EnterLink.EnableWindow(!m_Support.Validated());
|
|
|
|
|
|
|
|
CWindow hInfo = GetDlgItem(IDC_INFO);
|
2022-09-21 05:16:07 +00:00
|
|
|
CRect rcWin = {0};
|
2020-10-22 02:11:19 +00:00
|
|
|
hInfo.GetClientRect(&rcWin);
|
|
|
|
|
|
|
|
CDC hDC = hInfo.GetDC();
|
|
|
|
HFONT hFont = hInfo.GetFont();
|
2022-09-21 05:16:07 +00:00
|
|
|
if (hFont == nullptr)
|
2016-08-11 10:38:45 +00:00
|
|
|
{
|
2020-10-22 02:11:19 +00:00
|
|
|
hFont = (HFONT)::GetStockObject(SYSTEM_FONT);
|
2016-08-11 10:38:45 +00:00
|
|
|
}
|
2020-10-22 02:11:19 +00:00
|
|
|
hDC.SelectFont(hFont);
|
2022-09-21 05:16:07 +00:00
|
|
|
if (hDC.DrawText(InfoText.c_str(), InfoText.length(), &rcWin, DT_LEFT | DT_CALCRECT | DT_WORDBREAK | DT_NOCLIP) > 0)
|
2016-08-11 10:38:45 +00:00
|
|
|
{
|
2022-09-21 05:16:07 +00:00
|
|
|
hInfo.SetWindowPos(nullptr, 0, 0, rcWin.right, rcWin.bottom, SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOOWNERZORDER);
|
2020-10-22 02:11:19 +00:00
|
|
|
}
|
|
|
|
hInfo.SetWindowText(InfoText.c_str());
|
|
|
|
hInfo.GetWindowRect(&rcWin);
|
2021-04-12 11:35:39 +00:00
|
|
|
::MapWindowPoints(nullptr, m_hWnd, (LPPOINT)&rcWin, 2);
|
2022-09-21 05:16:07 +00:00
|
|
|
|
2020-10-22 02:11:19 +00:00
|
|
|
CWindow EnterCode = GetDlgItem(IDC_ENTER_CODE);
|
2022-09-21 05:16:07 +00:00
|
|
|
EnterCode.SetWindowPos(nullptr, rcWin.left, rcWin.bottom + 4, 0, 0, SWP_NOACTIVATE | SWP_NOSIZE | SWP_NOOWNERZORDER);
|
2020-10-22 02:11:19 +00:00
|
|
|
EnterCode.GetWindowRect(&rcWin);
|
2021-04-12 11:35:39 +00:00
|
|
|
::MapWindowPoints(nullptr, m_hWnd, (LPPOINT)&rcWin, 2);
|
2020-10-22 02:11:19 +00:00
|
|
|
|
|
|
|
CWindow SupportBtn = GetDlgItem(ID_SUPPORT_PJ64);
|
2022-09-21 05:16:07 +00:00
|
|
|
RECT SupportBtnWin = {0};
|
2020-10-22 02:11:19 +00:00
|
|
|
SupportBtn.GetWindowRect(&SupportBtnWin);
|
2021-04-12 11:35:39 +00:00
|
|
|
::MapWindowPoints(nullptr, m_hWnd, (LPPOINT)&SupportBtnWin, 2);
|
|
|
|
SupportBtn.SetWindowPos(nullptr, SupportBtnWin.left, rcWin.bottom + 40, 0, 0, SWP_NOACTIVATE | SWP_NOSIZE | SWP_NOOWNERZORDER);
|
2020-10-22 02:11:19 +00:00
|
|
|
|
|
|
|
CWindow CancelBtn = GetDlgItem(IDCANCEL);
|
2022-09-21 05:16:07 +00:00
|
|
|
RECT CancelBtnWin = {0};
|
2020-10-22 02:11:19 +00:00
|
|
|
CancelBtn.GetWindowRect(&CancelBtnWin);
|
2021-04-12 11:35:39 +00:00
|
|
|
::MapWindowPoints(nullptr, m_hWnd, (LPPOINT)&CancelBtnWin, 2);
|
|
|
|
CancelBtn.SetWindowPos(nullptr, CancelBtnWin.left, rcWin.bottom + 40, 0, 0, SWP_NOACTIVATE | SWP_NOSIZE | SWP_NOOWNERZORDER);
|
2020-10-22 02:11:19 +00:00
|
|
|
|
|
|
|
GetWindowRect(&rcWin);
|
|
|
|
SupportBtn.GetWindowRect(&SupportBtnWin);
|
2021-04-12 11:35:39 +00:00
|
|
|
::MapWindowPoints(nullptr, m_hWnd, (LPPOINT)&SupportBtnWin, 2);
|
2020-10-22 02:11:19 +00:00
|
|
|
SetRect(&rcWin, 0, 0, rcWin.Width(), SupportBtnWin.bottom + 30);
|
2021-04-12 11:35:39 +00:00
|
|
|
AdjustWindowRectEx(&rcWin, GetStyle(), GetMenu() != nullptr, GetExStyle());
|
2020-10-22 02:11:19 +00:00
|
|
|
|
|
|
|
int32_t Left = (GetSystemMetrics(SM_CXSCREEN) - rcWin.Width()) / 2;
|
2022-09-21 05:16:07 +00:00
|
|
|
int32_t Top = (GetSystemMetrics(SM_CYSCREEN) - rcWin.Height()) / 2;
|
2020-10-22 02:11:19 +00:00
|
|
|
|
|
|
|
MoveWindow(Left, Top, rcWin.Width(), rcWin.Height(), TRUE);
|
|
|
|
|
2020-10-27 06:11:50 +00:00
|
|
|
if (m_Delay && m_Support.RunCount() >= 15)
|
2020-10-22 02:11:19 +00:00
|
|
|
{
|
|
|
|
CMenuHandle menu = GetSystemMenu(false);
|
|
|
|
menu.RemoveMenu(SC_CLOSE, MF_BYCOMMAND);
|
2016-08-11 10:38:45 +00:00
|
|
|
DWORD dwStyle = GetWindowLong(GWL_STYLE);
|
|
|
|
dwStyle |= CS_NOCLOSE;
|
|
|
|
SetWindowLong(GWL_STYLE, dwStyle);
|
|
|
|
|
2020-10-22 02:11:19 +00:00
|
|
|
GetDlgItem(IDCANCEL).EnableWindow(false);
|
2022-09-21 05:16:07 +00:00
|
|
|
srand((uint32_t)time(nullptr));
|
2021-04-12 11:35:39 +00:00
|
|
|
SetTimer(0, 1000, nullptr);
|
2020-10-27 06:11:50 +00:00
|
|
|
}
|
2016-08-11 10:38:45 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2022-09-21 05:16:07 +00:00
|
|
|
LRESULT CSupportWindow::OnColorStatic(UINT /*uMsg*/, WPARAM wParam, LPARAM /*lParam*/, BOOL & /*bHandled*/)
|
2016-08-11 10:38:45 +00:00
|
|
|
{
|
2020-10-22 02:11:19 +00:00
|
|
|
CDCHandle hdcStatic = (HDC)wParam;
|
|
|
|
hdcStatic.SetTextColor(RGB(0, 0, 0));
|
|
|
|
hdcStatic.SetBkMode(TRANSPARENT);
|
2016-08-11 10:38:45 +00:00
|
|
|
return (LONG)(LRESULT)((HBRUSH)GetStockObject(NULL_BRUSH));
|
|
|
|
}
|
|
|
|
|
2022-09-21 05:16:07 +00:00
|
|
|
LRESULT CSupportWindow::OnEraseBackground(UINT /*uMsg*/, WPARAM wParam, LPARAM /*lParam*/, BOOL & /*bHandled*/)
|
2016-08-11 10:38:45 +00:00
|
|
|
{
|
2020-10-22 02:11:19 +00:00
|
|
|
static HPEN Outline = CreatePen(PS_SOLID, 1, 0x00FFFFFF);
|
|
|
|
static HBRUSH Fill = CreateSolidBrush(0x00FFFFFF);
|
|
|
|
|
|
|
|
CDCHandle hdc = (HDC)wParam;
|
|
|
|
hdc.SelectPen(Outline);
|
|
|
|
hdc.SelectBrush(Fill);
|
2016-08-11 10:38:45 +00:00
|
|
|
|
|
|
|
RECT rect;
|
|
|
|
GetClientRect(&rect);
|
2020-10-22 02:11:19 +00:00
|
|
|
hdc.Rectangle(&rect);
|
2016-08-11 10:38:45 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2022-09-21 05:16:07 +00:00
|
|
|
LRESULT CSupportWindow::OnTimer(UINT /*uMsg*/, WPARAM wParam, LPARAM /*lParam*/, BOOL & /*bHandled*/)
|
2016-08-11 10:38:45 +00:00
|
|
|
{
|
2020-05-11 07:12:58 +00:00
|
|
|
m_TimeOutTime -= 1;
|
|
|
|
if (m_TimeOutTime == 0)
|
|
|
|
{
|
|
|
|
KillTimer(wParam);
|
|
|
|
EnableContinue();
|
|
|
|
}
|
2020-10-22 02:11:19 +00:00
|
|
|
stdstr_f Continue_txt(m_TimeOutTime > 0 ? "%s (%d)" : "%s", GS(MSG_SUPPORT_CONTINUE), m_TimeOutTime);
|
|
|
|
GetDlgItem(IDCANCEL).SetWindowText(Continue_txt.ToUTF16().c_str());
|
2016-08-11 10:38:45 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2022-09-21 05:16:07 +00:00
|
|
|
LRESULT CSupportWindow::OnCloseCmd(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL & /*bHandled*/)
|
2016-08-11 10:38:45 +00:00
|
|
|
{
|
2021-05-30 11:11:45 +00:00
|
|
|
UISettingsSaveBool(UserInterface_ShowingNagWindow, false);
|
2016-08-11 10:38:45 +00:00
|
|
|
EndDialog(wID);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2022-09-21 05:16:07 +00:00
|
|
|
LRESULT CSupportWindow::OnSupportProject64(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL & /*bHandled*/)
|
2016-08-11 10:38:45 +00:00
|
|
|
{
|
2020-10-22 02:11:19 +00:00
|
|
|
stdstr SupportURL = stdstr_f("https://www.pj64-emu.com/support-project64.html?ver=%s&machine=%s", VER_FILE_VERSION_STR, m_Support.MachineID());
|
2021-04-12 11:35:39 +00:00
|
|
|
ShellExecute(nullptr, L"open", SupportURL.ToUTF16().c_str(), nullptr, nullptr, SW_SHOWMAXIMIZED);
|
2016-08-11 10:38:45 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2022-09-21 05:16:07 +00:00
|
|
|
LRESULT CSupportWindow::OnEnterCode(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL & /*bHandled*/)
|
2016-08-11 10:38:45 +00:00
|
|
|
{
|
2020-10-22 02:11:19 +00:00
|
|
|
CSupportEnterCode EnterCodeWindow(m_Support);
|
2016-08-11 10:38:45 +00:00
|
|
|
EnterCodeWindow.DoModal(m_hWnd);
|
2020-10-22 02:11:19 +00:00
|
|
|
if (m_Support.Validated())
|
|
|
|
{
|
2021-05-30 11:11:45 +00:00
|
|
|
UISettingsSaveBool(UserInterface_ShowingNagWindow, false);
|
2020-10-22 02:11:19 +00:00
|
|
|
EndDialog(wID);
|
|
|
|
}
|
2016-08-11 10:38:45 +00:00
|
|
|
return TRUE;
|
2021-03-17 08:33:06 +00:00
|
|
|
}
|