2016-08-11 10:38:45 +00:00
|
|
|
#include "stdafx.h"
|
|
|
|
#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)
|
|
|
|
{
|
|
|
|
::KillTimer(NULL, 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-10-22 02:11:19 +00:00
|
|
|
if (UISettingsLoadDword(SupportWindows_RunCount) == -1 || m_Support.Validated())
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
::SetTimer(nullptr, 0, 2500, TimerProc);
|
|
|
|
}
|
|
|
|
else
|
2016-08-11 10:38:45 +00:00
|
|
|
{
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
LRESULT CSupportWindow::OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
|
|
|
|
{
|
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);
|
|
|
|
CRect rcWin = { 0 };
|
|
|
|
hInfo.GetClientRect(&rcWin);
|
|
|
|
|
|
|
|
CDC hDC = hInfo.GetDC();
|
|
|
|
HFONT hFont = hInfo.GetFont();
|
|
|
|
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);
|
|
|
|
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
|
|
|
{
|
2020-10-22 02:11:19 +00:00
|
|
|
hInfo.SetWindowPos(NULL,0,0,rcWin.right, rcWin.bottom,SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOOWNERZORDER);
|
|
|
|
}
|
|
|
|
hInfo.SetWindowText(InfoText.c_str());
|
|
|
|
hInfo.GetWindowRect(&rcWin);
|
|
|
|
::MapWindowPoints(NULL, m_hWnd, (LPPOINT)&rcWin, 2);
|
|
|
|
|
|
|
|
CWindow EnterCode = GetDlgItem(IDC_ENTER_CODE);
|
|
|
|
EnterCode.SetWindowPos(NULL,rcWin.left,rcWin.bottom + 4,0,0,SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOOWNERZORDER);
|
|
|
|
EnterCode.GetWindowRect(&rcWin);
|
|
|
|
::MapWindowPoints(NULL, m_hWnd, (LPPOINT)&rcWin, 2);
|
|
|
|
|
|
|
|
CWindow SupportBtn = GetDlgItem(ID_SUPPORT_PJ64);
|
|
|
|
RECT SupportBtnWin = { 0 };
|
|
|
|
SupportBtn.GetWindowRect(&SupportBtnWin);
|
|
|
|
::MapWindowPoints(NULL, m_hWnd, (LPPOINT)&SupportBtnWin, 2);
|
|
|
|
SupportBtn.SetWindowPos(NULL, SupportBtnWin.left, rcWin.bottom + 40, 0, 0, SWP_NOACTIVATE | SWP_NOSIZE | SWP_NOOWNERZORDER);
|
|
|
|
|
|
|
|
CWindow CancelBtn = GetDlgItem(IDCANCEL);
|
|
|
|
RECT CancelBtnWin = { 0 };
|
|
|
|
CancelBtn.GetWindowRect(&CancelBtnWin);
|
|
|
|
::MapWindowPoints(NULL, m_hWnd, (LPPOINT)&CancelBtnWin, 2);
|
|
|
|
CancelBtn.SetWindowPos(NULL, CancelBtnWin.left, rcWin.bottom + 40, 0, 0, SWP_NOACTIVATE | SWP_NOSIZE | SWP_NOOWNERZORDER);
|
|
|
|
|
|
|
|
GetWindowRect(&rcWin);
|
|
|
|
SupportBtn.GetWindowRect(&SupportBtnWin);
|
|
|
|
::MapWindowPoints(NULL, m_hWnd, (LPPOINT)&SupportBtnWin, 2);
|
|
|
|
SetRect(&rcWin, 0, 0, rcWin.Width(), SupportBtnWin.bottom + 30);
|
|
|
|
AdjustWindowRectEx(&rcWin, GetStyle(), GetMenu() != NULL, GetExStyle());
|
|
|
|
|
|
|
|
int32_t Left = (GetSystemMetrics(SM_CXSCREEN) - rcWin.Width()) / 2;
|
|
|
|
int32_t Top = (GetSystemMetrics(SM_CYSCREEN) - rcWin.Height()) / 2;
|
|
|
|
|
|
|
|
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);
|
2017-01-20 23:31:09 +00:00
|
|
|
srand ((uint32_t)time(NULL));
|
2020-05-11 07:12:58 +00:00
|
|
|
SetTimer(0, 1000, NULL);
|
2020-10-27 06:11:50 +00:00
|
|
|
}
|
2016-08-11 10:38:45 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
LRESULT CSupportWindow::OnColorStatic(UINT /*uMsg*/, WPARAM wParam, LPARAM /*lParam*/, BOOL& /*bHandled*/)
|
|
|
|
{
|
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));
|
|
|
|
}
|
|
|
|
|
|
|
|
LRESULT CSupportWindow::OnEraseBackground(UINT /*uMsg*/, WPARAM wParam, LPARAM /*lParam*/, BOOL& /*bHandled*/)
|
|
|
|
{
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
LRESULT CSupportWindow::OnTimer(UINT /*uMsg*/, WPARAM wParam, LPARAM /*lParam*/, BOOL& /*bHandled*/)
|
|
|
|
{
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
LRESULT CSupportWindow::OnCloseCmd(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
|
|
|
|
{
|
|
|
|
EndDialog(wID);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
LRESULT CSupportWindow::OnSupportProject64(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
|
|
|
|
{
|
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());
|
2020-05-12 12:19:05 +00:00
|
|
|
ShellExecute(NULL, L"open", SupportURL.ToUTF16().c_str(), NULL, NULL, SW_SHOWMAXIMIZED);
|
2016-08-11 10:38:45 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
LRESULT CSupportWindow::OnEnterCode(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
|
|
|
|
{
|
2020-10-22 02:11:19 +00:00
|
|
|
CSupportEnterCode EnterCodeWindow(m_Support);
|
2016-08-11 10:38:45 +00:00
|
|
|
EnterCodeWindow.DoModal(m_hWnd);
|
|
|
|
if (UISettingsLoadDword(SupportWindows_RunCount) == -1)
|
|
|
|
{
|
|
|
|
EndDialog(wID);
|
|
|
|
}
|
2020-10-22 02:11:19 +00:00
|
|
|
if (m_Support.Validated())
|
|
|
|
{
|
|
|
|
EndDialog(wID);
|
|
|
|
}
|
2016-08-11 10:38:45 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|