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

📄 regeditdlg.cpp

📁 ARM&WINCE实验与实践(基于S3C2410)第2章 Windows CE.net应用程序开发
💻 CPP
字号:
// RegeditDlg.cpp : implementation file
//

#include "stdafx.h"
#include "Regedit.h"
#include "RegeditDlg.h"

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

/////////////////////////////////////////////////////////////////////////////
// CRegeditDlg dialog

CRegeditDlg::CRegeditDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CRegeditDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CRegeditDlg)
		// 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 CRegeditDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CRegeditDlg)
		// NOTE: the ClassWizard will add DDX and DDV calls here
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CRegeditDlg, CDialog)
	//{{AFX_MSG_MAP(CRegeditDlg)
	ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
	ON_BN_CLICKED(IDC_BUTTON2, OnButtonRead)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CRegeditDlg message handlers

BOOL CRegeditDlg::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
	
	CenterWindow(GetDesktopWindow());	// center to the hpc screen

	// TODO: Add extra initialization here
	
	return TRUE;  // return TRUE  unless you set the focus to a control
}



void CRegeditDlg::OnButton1() 
{
	// TODO: Add your control notification handler code here
	HKEY hOpenKey;
	DWORD dwOpenStyle;
	long lResult=0;
	//定义键名
	LPCTSTR keyName = L"Mysoftware\\RegTest";
	//打开或新建指定的键
	lResult = RegCreateKeyEx(HKEY_CURRENT_USER,
		keyName,0,L"",0,0,NULL,&hOpenKey,&dwOpenStyle);
	ASSERT(lResult == ERROR_SUCCESS);

	//写入键值,整数类型
	LPCTSTR dwKeyName=L"age";
	DWORD dwKeyValue = 25;
	lResult = RegSetValueEx(hOpenKey,dwKeyName,0,REG_DWORD,(BYTE*)&dwKeyValue,
		sizeof(dwKeyValue));
	ASSERT(lResult == ERROR_SUCCESS);

	//关闭打开的键
	RegCloseKey(hOpenKey);
	AfxMessageBox(_T("Write Reg successful"));
	
}

void CRegeditDlg::OnButtonRead() 
{
	// TODO: Add your control notification handler code here
	HKEY hOpenKey =0;
	long lResult = 0;
	DWORD dwKeyValueType = 0;
	DWORD dwKeyValueLength = 0;
	//定义键名
	LPCTSTR keyName=L"Mysoftware\\RegTest";
	//打开指定的键
	lResult = RegOpenKeyEx(HKEY_CURRENT_USER,keyName,0,0,&hOpenKey);
	ASSERT(lResult == ERROR_SUCCESS);
	//读取“age”键值
	LPCTSTR dwKeyName=L"age";
	DWORD dwKeyValue=0;
	dwKeyValueLength=sizeof(dwKeyValue);
	lResult=RegQueryValueEx(hOpenKey,dwKeyName,0,&dwKeyValueType,
		(BYTE*)&dwKeyValue,&dwKeyValueLength);
	ASSERT(lResult == ERROR_SUCCESS);
	//关闭打开的键
	RegCloseKey(hOpenKey);
	//显示读出的值
	CString strShow;
	strShow.Format (L"age:%d ",dwKeyValue);
	AfxMessageBox(strShow);
}

⌨️ 快捷键说明

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