@@ -72,6 +72,25 @@ BOOL DialogTab03::OnInitDialog()
7272 checkbox->SetCheck (BST_CHECKED);
7373 }
7474
75+ HKEY hKey;
76+ const std::string key = " SOFTWARE\\ Microsoft\\ Windows\\ CurrentVersion\\ Run" ;
77+ const std::string subkey = " TegraRcmGUI" ;
78+
79+ // Open Run Registry location
80+ LONG lnRes = RegOpenKeyExA (HKEY_CURRENT_USER,
81+ key.c_str (), 0 , KEY_READ, &hKey);
82+
83+ if (ERROR_SUCCESS == lnRes)
84+ {
85+ lnRes = RegQueryValueExA (hKey, subkey.c_str (), NULL , NULL , NULL , NULL );
86+ if (lnRes != ERROR_FILE_NOT_FOUND)
87+ {
88+ CMFCButton*checkbox = (CMFCButton*)GetDlgItem (RUN_WINSTART);
89+ checkbox->SetCheck (BST_CHECKED);
90+ }
91+ }
92+
93+
7594 return TRUE ; // return TRUE unless you set the focus to a control
7695 // EXCEPTION: OCX Property Pages should return FALSE
7796}
@@ -80,6 +99,7 @@ BEGIN_MESSAGE_MAP(DialogTab03, CDialogEx)
8099 ON_BN_CLICKED(AUTO_INJECT, &DialogTab03::OnClickedAutoInject)
81100 ON_BN_CLICKED(MIN_TO_TRAY, &DialogTab03::OnClickedMinToTray)
82101 ON_BN_CLICKED(ID_INSTALL_DRIVER, &DialogTab03::OnBnClickedInstallDriver)
102+ ON_BN_CLICKED(RUN_WINSTART, &DialogTab03::OnBnClickedWinstart)
83103END_MESSAGE_MAP()
84104
85105
@@ -131,3 +151,63 @@ void DialogTab03::OnBnClickedInstallDriver()
131151 m_TegraRcm->InstallDriver ();
132152}
133153
154+
155+
156+ void DialogTab03::OnBnClickedWinstart ()
157+ {
158+ // Init
159+ HKEY hKey;
160+ const std::string key = " TegraRcmGUI" ;
161+ std::vector<char > buffer;
162+
163+ // Get checkbox value (checked, unchecked)
164+ CButton *m_ctlCheck = (CButton*)GetDlgItem (RUN_WINSTART);
165+ BOOL IsCheckChecked = (m_ctlCheck->GetCheck () == 1 ) ? true : false ;
166+
167+ // Get application absolute path
168+ TCHAR szPath[_MAX_PATH];
169+ VERIFY (::GetModuleFileName (AfxGetApp ()->m_hInstance , szPath, _MAX_PATH));
170+ // Convert path to ANSI string
171+ int size = WideCharToMultiByte (CP_UTF8, 0 , szPath, -1 , NULL , 0 , NULL , NULL );
172+ if (size > 0 ) {
173+ buffer.resize (size);
174+ WideCharToMultiByte (CP_UTF8, 0 , szPath, -1 , (LPSTR)(&buffer[0 ]), buffer.size (), NULL , NULL );
175+ }
176+ std::string appPath (&buffer[0 ]);
177+ std::string keyValue;
178+ keyValue.append (" \" " );
179+ keyValue.append (appPath);
180+ keyValue.append (" \" /autostart" );
181+
182+ // Open Run Registry location
183+ LONG lnRes = RegOpenKeyEx (HKEY_CURRENT_USER,
184+ _T (" SOFTWARE\\ Microsoft\\ Windows\\ CurrentVersion\\ Run" ),
185+ 0L , KEY_WRITE,
186+ &hKey);
187+
188+ if (ERROR_SUCCESS == lnRes)
189+ {
190+ if (IsCheckChecked)
191+ {
192+ // Set full application path with a keyname to registry
193+ lnRes = RegSetValueExA (hKey,
194+ key.c_str (),
195+ 0 ,
196+ REG_SZ,
197+ (LPBYTE)(keyValue.c_str ()),
198+ keyValue.size () + 1 );
199+ }
200+ else
201+ {
202+ lnRes = RegDeleteValueA (hKey, key.c_str ());
203+ }
204+ if (ERROR_SUCCESS != lnRes)
205+ {
206+ AfxMessageBox (_T (" Failed to set/unset at startup" ));
207+ }
208+ }
209+ else
210+ {
211+ AfxMessageBox (_T (" Failed to access registry" ));
212+ }
213+ }
0 commit comments