Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 87 additions & 0 deletions StayAwake/SelectKeyCodesDlg.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
// CSelectKeyCodesDlg.cpp : implementation file
//

#include "pch.h"
#include "StayAwake.h"
#include "afxdialogex.h"
#include "SelectKeyCodesDlg.h"

static_assert(IDC_KEY_UNASSIGNED_10 - IDC_KEY_SCROLL_LOCK + 1 == LEN_KEYCODES_ROSTER, "Roster checkbox IDs must be consecutive");

// CSelectKeyCodesDlg dialog

IMPLEMENT_DYNAMIC(CSelectKeyCodesDlg, CDialogEx)

CSelectKeyCodesDlg::CSelectKeyCodesDlg(CStayAwakeDlg* pCaller)
: CDialogEx(IDD_SELECT_KEYCODES_DIALOG, pCaller)
, m_pCaller(pCaller)
{
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

CSelectKeyCodesDlg::~CSelectKeyCodesDlg()
{
}

void CSelectKeyCodesDlg::DoDataExchange(CDataExchange* pDX)
{
CDialogEx::DoDataExchange(pDX);
}


BEGIN_MESSAGE_MAP(CSelectKeyCodesDlg, CDialogEx)
ON_BN_CLICKED(IDC_KEY_SELECT_APPLY_BTN, &CSelectKeyCodesDlg::OnOK)
ON_BN_CLICKED(IDC_KEY_SELECT_ALL_BTN, &CSelectKeyCodesDlg::OnClickedKeySelectAllBtn)
ON_BN_CLICKED(IDC_KEY_SELECT_NONE_BTN, &CSelectKeyCodesDlg::OnClickedKeySelectNoneBtn)
END_MESSAGE_MAP()


BOOL CSelectKeyCodesDlg::OnInitDialog()
{
CDialogEx::OnInitDialog();

SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon

CheckAllBoxes(m_pCaller->GetSelectedKeyCodes());

return TRUE; // return TRUE unless you set the focus to a control
}

void CSelectKeyCodesDlg::OnOK()
{
wstring sSelectedKeyCodes{};

for (int i{}; i < LEN_KEYCODES_ROSTER; i++)
sSelectedKeyCodes += (IsDlgButtonChecked(IDC_KEY_SCROLL_LOCK + i)) ? L"1" : L"0";

if (sSelectedKeyCodes == wstring(LEN_KEYCODES_ROSTER, L'0'))
{
MessageBox(L"Please select at least one Key Code", L"Select multiple Key Codes", MB_ICONEXCLAMATION);
return;
}

if (!m_pCaller->SaveSelectedKeyCodes(sSelectedKeyCodes))
{
MessageBox(L"Unable to save to the StayAwake.ini file.", L"Select multiple Key Codes", MB_ICONEXCLAMATION);
return;
}

CDialogEx::OnOK();
}

void CSelectKeyCodesDlg::CheckAllBoxes(const wstring& sSelectedKeyCodes)
{
for (int i{}; i < LEN_KEYCODES_ROSTER; i++)
CheckDlgButton(IDC_KEY_SCROLL_LOCK + i, sSelectedKeyCodes.at(i) == L'1');
}

void CSelectKeyCodesDlg::OnClickedKeySelectAllBtn()
{
CheckAllBoxes(wstring(LEN_KEYCODES_ROSTER, L'1'));
}

void CSelectKeyCodesDlg::OnClickedKeySelectNoneBtn()
{
CheckAllBoxes(wstring(LEN_KEYCODES_ROSTER, L'0'));
}
34 changes: 34 additions & 0 deletions StayAwake/SelectKeyCodesDlg.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#pragma once

#include "Utils.h"
#include "StayAwakeDlg.h"

class CSelectKeyCodesDlg : public CDialogEx
{
DECLARE_DYNAMIC(CSelectKeyCodesDlg)

public:
explicit CSelectKeyCodesDlg(CStayAwakeDlg* pCaller);
virtual ~CSelectKeyCodesDlg();

// Dialog Data
#ifdef AFX_DESIGN_TIME
enum { IDD = IDD_SELECT_KEYCODES_DIALOG };
#endif

protected:
CStayAwakeDlg* m_pCaller;
HICON m_hIcon;

virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support

virtual BOOL OnInitDialog();
afx_msg void OnClickedKeySelectAllBtn();
afx_msg void OnClickedKeySelectNoneBtn();
afx_msg void OnOK();

DECLARE_MESSAGE_MAP()

private:
void CheckAllBoxes(const wstring& sSelectedKeyCodes);
};
2 changes: 1 addition & 1 deletion StayAwake/StayAwake.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ BOOL CStayAwakeApp::InitInstance()

CStayAwakeDlg dlg;
m_pMainWnd = &dlg;
INT_PTR nResponse = dlg.DoModal();
dlg.DoModal();

#if !defined(_AFXDLL) && !defined(_AFX_NO_MFC_CONTROLS_IN_DIALOGS)
ControlBarCleanUp();
Expand Down
3 changes: 2 additions & 1 deletion StayAwake/StayAwake.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@

#include "resource.h"

#define LAST_CODE_UPDATE_TIME "Sep 17 2026 - 22:09:25"
constexpr auto LAST_CODE_UPDATE_TIME = "Sep 19 2026 - 17:20:42";


class CStayAwakeApp : public CWinApp
{
Expand Down
Binary file modified StayAwake/StayAwake.rc
Binary file not shown.
4 changes: 2 additions & 2 deletions StayAwake/StayAwake.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@
</ItemDefinitionGroup>
<ItemGroup>
<ClInclude Include="framework.h" />
<ClInclude Include="SelectKeyCodesDlg.h" />
<ClInclude Include="StayAwake.h" />
<ClInclude Include="StayAwakeAboutDlg.h" />
<ClInclude Include="StayAwakeDlg.h" />
Expand All @@ -220,6 +221,7 @@
<ClInclude Include="Utils.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="SelectKeyCodesDlg.cpp" />
<ClCompile Include="StayAwake.cpp" />
<ClCompile Include="StayAwakeAboutDlg.cpp" />
<ClCompile Include="StayAwakeDlg.cpp" />
Expand All @@ -238,9 +240,7 @@
<None Include="res\StayAwake.rc2" />
</ItemGroup>
<ItemGroup>
<Image Include="icon1.ico" />
<Image Include="res\about.bmp" />
<Image Include="res\alarm-clock.ico" />
<Image Include="res\StayAwake.ico" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
Expand Down
12 changes: 6 additions & 6 deletions StayAwake/StayAwake.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@
<ClInclude Include="StayAwakeAboutDlg.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="SelectKeyCodesDlg.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="StayAwake.cpp">
Expand All @@ -56,6 +59,9 @@
<ClCompile Include="StayAwakeAboutDlg.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="SelectKeyCodesDlg.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="StayAwake.rc">
Expand All @@ -71,12 +77,6 @@
<Image Include="res\StayAwake.ico">
<Filter>Resource Files</Filter>
</Image>
<Image Include="icon1.ico">
<Filter>Resource Files</Filter>
</Image>
<Image Include="res\alarm-clock.ico">
<Filter>Resource Files</Filter>
</Image>
<Image Include="res\about.bmp">
<Filter>Resource Files</Filter>
</Image>
Expand Down
Loading