📄 autorundlg.cpp
字号:
// AutoRunDlg.cpp : implementation file
//
#include "stdafx.h"
#include "Capture.h"
#include "AutoRunDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CAutoRunDlg dialog
CAutoRunDlg::CAutoRunDlg(CWnd* pParent /*=NULL*/)
: CDialog(CAutoRunDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CAutoRunDlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
}
void CAutoRunDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAutoRunDlg)
DDX_Control(pDX, IDC_BUTTON4, m_Cancel);
DDX_Control(pDX, IDC_BUTTON1, m_Confirm);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAutoRunDlg, CDialog)
//{{AFX_MSG_MAP(CAutoRunDlg)
ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
ON_BN_CLICKED(IDC_BUTTON4, OnButton4)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CAutoRunDlg message handlers
void CAutoRunDlg::OnOK()
{
// CDialog::OnOK();
}
BOOL CAutoRunDlg::OnInitDialog()
{
CDialog::OnInitDialog();
this->SetWindowText("开机自动运行");
HKEY h_key = HKEY_LOCAL_MACHINE;
CString c_substr = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run";
HKEY h_result;
CString subkey ,str;
subkey = "自动运行";
unsigned long i,j;
if (RegOpenKey(h_key,c_substr,&h_result)==ERROR_SUCCESS)
if (RegQueryValueEx(h_result,subkey,NULL,&j,(unsigned char *)str.GetBuffer(str.GetLength()),&i)==ERROR_SUCCESS)
{
CButton* m_button = (CButton *)GetDlgItem(IDC_RADIOAUTO);
m_button->SetCheck(1);
}
else
{
CButton* m_button = (CButton *)GetDlgItem(IDC_RADIONOAUTO);
m_button->SetCheck(1);
}
RegCloseKey(h_result);
return TRUE;
}
void CAutoRunDlg::OnButton1()
{
CButton* m_button =(CButton *) GetDlgItem(IDC_RADIOAUTO);
HKEY h_key = HKEY_LOCAL_MACHINE;
HKEY h_result;
CString m_SubKey = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run";
RegOpenKey(h_key,m_SubKey,&h_result);
CString m_Appname('0',MAX_PATH) ;
if (m_button->GetCheck()) //设置自动运行
{
GetModuleFileName(NULL,(char*)m_Appname.GetBuffer(m_Appname.GetLength()),MAX_PATH);
if (RegSetValueEx(h_result,"自动运行",0,REG_SZ,(unsigned char*)m_Appname.GetBuffer(m_Appname.GetLength()),m_Appname.GetLength())==ERROR_SUCCESS)
{
MessageBox("设置成功.","提示");
}
else
MessageBox("设置失败.","提示");
}
else //取消自动运行
{
if (RegDeleteValue(h_result,"自动运行")==ERROR_SUCCESS)
MessageBox("设置成功.","提示");
else
MessageBox("设置失败.","提示");
}
RegCloseKey(h_result);
}
void CAutoRunDlg::OnButton4()
{
this->EndDialog(0);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -