⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 startupprogdlg.cpp

📁 Visual.C++程序设计技巧与实例--配套光盘 第6章 文件和系统操作 本章共11个实例: 1. FolderCopy文件夹的选择和拷贝 2. DeleteCertainFile删除指定路
💻 CPP
字号:
// StartUpProgDlg.cpp : implementation file
//

#include "stdafx.h"
#include "StartUpProg.h"
#include "StartUpProgDlg.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CStartUpProgDlg dialog

CStartUpProgDlg::CStartUpProgDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CStartUpProgDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CStartUpProgDlg)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CStartUpProgDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CStartUpProgDlg)
		// NOTE: the ClassWizard will add DDX and DDV calls here
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CStartUpProgDlg, CDialog)
	//{{AFX_MSG_MAP(CStartUpProgDlg)
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_SETASSTARTUPPROG, OnSetAsstartupprog)
	ON_BN_CLICKED(IDC_GETFILE, OnGetfile)
	ON_BN_CLICKED(IDC_CREATEKEY, OnCreatekey)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CStartUpProgDlg message handlers

BOOL CStartUpProgDlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	// Set the icon for this dialog.  The framework does this automatically
	//  when the application's main window is not a dialog
	SetIcon(m_hIcon, TRUE);			// Set big icon
	SetIcon(m_hIcon, FALSE);		// Set small icon
	
	// TODO: Add extra initialization here
	
	return TRUE;  // return TRUE  unless you set the focus to a control
}

// If you add a minimize button to your dialog, you will need the code below
//  to draw the icon.  For MFC applications using the document/view model,
//  this is automatically done for you by the framework.

void CStartUpProgDlg::OnPaint() 
{
	if (IsIconic())
	{
		CPaintDC dc(this); // device context for painting

		SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);

		// Center icon in client rectangle
		int cxIcon = GetSystemMetrics(SM_CXICON);
		int cyIcon = GetSystemMetrics(SM_CYICON);
		CRect rect;
		GetClientRect(&rect);
		int x = (rect.Width() - cxIcon + 1) / 2;
		int y = (rect.Height() - cyIcon + 1) / 2;

		// Draw the icon
		dc.DrawIcon(x, y, m_hIcon);
	}
	else
	{
		CDialog::OnPaint();
	}
}

// The system calls this to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR CStartUpProgDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}

//将应用程序路径加载到注册表相应位置
void CStartUpProgDlg::OnSetAsstartupprog() 
{
	//定义所需要的变量
	HKEY hKey;
	CString sKeyName;
	unsigned char szFilePath[100];

	//打开注册表
	LONG lnRes = RegOpenKeyEx( 
						//要打开的目录在HKEY_LOCAL_MACHINE下
 						HKEY_LOCAL_MACHINE,  
						//子目录
						"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", 
						//必须取0
						0L,
						//KEY_WRITE是STANDARD_RIGHTS_WRITE, KEY_SET_VALUE, 
						//和 KEY_CREATE_SUB_KEY 访问权限的组合
						KEY_WRITE,
						&hKey      
						); 

	
	lstrcpy( (char *) szFilePath , LPCTSTR(m_strFileName) );
//	GetDlgItemText( IDC_KEYNAME, sKeyName );

	//假如RegOpenKeyEx成功,返回值为ERROR_SUCCESS
	if( ERROR_SUCCESS == lnRes )
	{
		//把应用程序路径加入到RUN键下面
		lnRes = RegSetValueEx(hKey,
				LPCTSTR( sKeyName ),   
				0,      
				REG_SZ,    
				szFilePath,   //value data
				REG_SZ ); 
		//假如RegSetValueEx成功,返回值为ERROR_SUCCESS
		if( ERROR_SUCCESS == lnRes )
			AfxMessageBox("已经成功加载此应用程序!");
		else
			AfxMessageBox("不能加载此应用程序!");
	}
	else
	{
		AfxMessageBox("不能加载此应用程序!");
	}	
}
//得到可执行文件路径
void CStartUpProgDlg::OnGetfile() 
{
	//时只能选择exe文件
	static char szFilter[] = "(*.exe)|*.exe";
	CFileDialog OpenFileDlg(
		true,"*.tpe",NULL,OFN_HIDEREADONLY ,szFilter);	
	if( OpenFileDlg.DoModal() == IDCANCEL )
		return ;
	//得到文件路径
	m_strFileName = OpenFileDlg.GetPathName();	 
	//将文件路径显示到Edit控件上
	SetDlgItemText( IDC_EDIT, LPCTSTR(m_strFileName) );	
}

void CStartUpProgDlg::OnCreatekey() 
{

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -