1
0
Fork 0
mirror of https://github.com/eliboa/TegraRcmGUI.git synced 2024-12-29 11:36:02 +00:00

Added : option to run app at Windows startup

This commit is contained in:
eliboa 2018-07-24 20:38:30 +02:00
parent 2516e8192d
commit 7b9b222148
7 changed files with 119 additions and 5 deletions

View file

@ -72,6 +72,25 @@ BOOL DialogTab03::OnInitDialog()
checkbox->SetCheck(BST_CHECKED);
}
HKEY hKey;
const std::string key = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run";
const std::string subkey = "TegraRcmGUI";
// Open Run Registry location
LONG lnRes = RegOpenKeyExA(HKEY_CURRENT_USER,
key.c_str(), 0, KEY_READ, &hKey);
if (ERROR_SUCCESS == lnRes)
{
lnRes = RegQueryValueExA(hKey, subkey.c_str(), NULL, NULL, NULL, NULL);
if (lnRes != ERROR_FILE_NOT_FOUND)
{
CMFCButton*checkbox = (CMFCButton*)GetDlgItem(RUN_WINSTART);
checkbox->SetCheck(BST_CHECKED);
}
}
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
@ -80,6 +99,7 @@ BEGIN_MESSAGE_MAP(DialogTab03, CDialogEx)
ON_BN_CLICKED(AUTO_INJECT, &DialogTab03::OnClickedAutoInject)
ON_BN_CLICKED(MIN_TO_TRAY, &DialogTab03::OnClickedMinToTray)
ON_BN_CLICKED(ID_INSTALL_DRIVER, &DialogTab03::OnBnClickedInstallDriver)
ON_BN_CLICKED(RUN_WINSTART, &DialogTab03::OnBnClickedWinstart)
END_MESSAGE_MAP()
@ -131,3 +151,63 @@ void DialogTab03::OnBnClickedInstallDriver()
m_TegraRcm->InstallDriver();
}
void DialogTab03::OnBnClickedWinstart()
{
// Init
HKEY hKey;
const std::string key = "TegraRcmGUI";
std::vector<char> buffer;
// Get checkbox value (checked, unchecked)
CButton *m_ctlCheck = (CButton*)GetDlgItem(RUN_WINSTART);
BOOL IsCheckChecked = (m_ctlCheck->GetCheck() == 1) ? true : false;
// Get application absolute path
TCHAR szPath[_MAX_PATH];
VERIFY(::GetModuleFileName(AfxGetApp()->m_hInstance, szPath, _MAX_PATH));
// Convert path to ANSI string
int size = WideCharToMultiByte(CP_UTF8, 0, szPath, -1, NULL, 0, NULL, NULL);
if (size > 0) {
buffer.resize(size);
WideCharToMultiByte(CP_UTF8, 0, szPath, -1, (LPSTR)(&buffer[0]), buffer.size(), NULL, NULL);
}
std::string appPath(&buffer[0]);
std::string keyValue;
keyValue.append("\"");
keyValue.append(appPath);
keyValue.append("\" /autostart");
// Open Run Registry location
LONG lnRes = RegOpenKeyEx(HKEY_CURRENT_USER,
_T("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run"),
0L, KEY_WRITE,
&hKey);
if (ERROR_SUCCESS == lnRes)
{
if (IsCheckChecked)
{
// Set full application path with a keyname to registry
lnRes = RegSetValueExA(hKey,
key.c_str(),
0,
REG_SZ,
(LPBYTE)(keyValue.c_str()),
keyValue.size() + 1);
}
else
{
lnRes = RegDeleteValueA(hKey, key.c_str());
}
if (ERROR_SUCCESS != lnRes)
{
AfxMessageBox(_T("Failed to set/unset at startup"));
}
}
else
{
AfxMessageBox(_T("Failed to access registry"));
}
}

View file

@ -30,4 +30,6 @@ public:
afx_msg void OnClickedAutoInject();
afx_msg void OnClickedMinToTray();
afx_msg void OnBnClickedInstallDriver();
afx_msg void OnBnClickedWinstart();
};

View file

@ -78,7 +78,10 @@ BOOL CTegraRcmGUIApp::InitInstance()
InitCommonControlsEx(&InitCtrls);
CWinApp::InitInstance();
// Get command line args
CCustomCommandLineInfo oInfo;
ParseCommandLine(oInfo);
AfxEnableControlContainer();
@ -93,12 +96,14 @@ BOOL CTegraRcmGUIApp::InitInstance()
SetRegistryKey(_T("Local AppWizard-Generated Applications"));
CTegraRcmGUIDlg dlg;
if (oInfo.IsAutostart()) {
dlg.AUTOSTART = TRUE;
}
m_pMainWnd = &dlg;
INT_PTR nResponse = dlg.DoModal();
if (nResponse == IDOK)
{
// TODO: Place code here to handle when the dialog is
// dismissed with OK
// TODO
}
else if (nResponse == IDCANCEL)
{
@ -121,5 +126,4 @@ int CTegraRcmGUIApp::Run()
{
int rc = 0;
return 0;
}
}

View file

@ -30,4 +30,24 @@ public:
DECLARE_MESSAGE_MAP()
};
class CCustomCommandLineInfo : public CCommandLineInfo
{
public:
CCustomCommandLineInfo()
{
m_bAutostart = FALSE;
}
BOOL m_bAutostart;
public:
BOOL IsAutostart() { return m_bAutostart; };
virtual void ParseParam(LPCTSTR pszParam, BOOL bFlag, BOOL bLast)
{
if (0 == wcscmp(pszParam, L"autostart"))
{
m_bAutostart = TRUE;
}
}
};
extern CTegraRcmGUIApp theApp;

Binary file not shown.

View file

@ -386,6 +386,13 @@ void CTegraRcmGUIDlg::OnTimer(UINT nIDEvent)
{
m_TegraRcm->LookUp();
}
// After first initDialog, hide window if min2tray option is enabled
if (AUTOSTART)
{
if (m_TegraRcm->MIN_TO_TRAY_CURR) HideWindowCommand();
AUTOSTART = FALSE;
}
}
void CTegraRcmGUIDlg::OnEnChangePath()

View file

@ -57,6 +57,7 @@ public:
BOOL DELAY_AUTOINJECT = FALSE;
BOOL ASK_FOR_DRIVER = FALSE;
BOOL PAUSE_LKP_DEVICE = FALSE;
BOOL AUTOSTART = FALSE;
BOOL CmdShow;
COLORREF LabelColor = RGB(0, 0, 0);
COLORREF WhiteRGB = RGB(255, 255, 255);