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

📄 newvaluedword.cpp

📁 基于EVC环境下的注册表编辑功能的完整源代码
💻 CPP
字号:
// NewValueDWORD.cpp : implementation file
//

#include "stdafx.h"
#include "RegEdit.h"
#include "NewValueDWORD.h"

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

/////////////////////////////////////////////////////////////////////////////
// CNewValueDWORD dialog


CNewValueDWORD::CNewValueDWORD(CWnd* pParent /*=NULL*/)
	: CDialog(CNewValueDWORD::IDD, pParent)
{
	//{{AFX_DATA_INIT(CNewValueDWORD)
	m_Name = _T("");
	m_strValue = _T("");
	//}}AFX_DATA_INIT
}


void CNewValueDWORD::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CNewValueDWORD)
	DDX_Text(pDX, IDC_EDIT_NAME, m_Name);
	DDX_Text(pDX, IDC_EDIT_VALUE, m_strValue);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CNewValueDWORD, CDialog)
	//{{AFX_MSG_MAP(CNewValueDWORD)
	ON_BN_CLICKED(IDC_RADIO1, OnRadio1)
	ON_BN_CLICKED(IDC_RADIO2, OnRadio2)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CNewValueDWORD message handlers

BOOL CNewValueDWORD::OnInitDialog() 
{
	CDialog::OnInitDialog();
	CheckDlgButton(IDC_RADIO1,BST_CHECKED);
	// TODO: Add extra initialization here
	
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CNewValueDWORD::OnOK() 
{
	// TODO: Add extra validation here
		UpdateData(TRUE);

	 if(m_strValue.Left(2)=="0x")
	   swscanf((LPCTSTR)m_strValue,_T("%x"),&m_dwValue);
 	 else
	   swscanf((LPCTSTR)m_strValue,_T("%l"),&m_dwValue);

	if(ERROR_SUCCESS!=RegSetValueEx(h_Key,(LPCTSTR)m_Name,NULL, REG_DWORD,(BYTE *)&m_dwValue,sizeof(m_dwValue)))
		MessageBox(_T("设置值失败!"),_T("失败"),MB_OK);
	CDialog::OnOK();
	CDialog::OnOK();
}

void CNewValueDWORD::Disp(HKEY hKey, CString strName, CString strValue)
{
	h_Key=hKey;
	m_Name=strName;
	m_strValue=strValue.Left(10);


	CDialog::DoModal ();
}

void CNewValueDWORD::OnRadio1() 
{
	// TODO: Add your control notification handler code here
		UpdateData(TRUE);
//	MessageBox(m_strValue,NULL,MB_OK);
	if(IsDlgButtonChecked(IDC_RADIO1)==BST_CHECKED) 
	{
	 if(m_strValue.Left(2)=="0x")
	//	wcstol((LPCTSTR)m_strValue,(unsigned short **)&m_dwValue,16);
	  swscanf((LPCTSTR)m_strValue,_T("%x"),&m_dwValue);
 	else
	  swscanf((LPCTSTR)m_strValue,_T("%lu"),&m_dwValue);
	 // wcstol((LPCTSTR)m_strValue,(unsigned short **)&m_dwValue,10);

	m_strValue.Format (_T("%x"),m_dwValue);	

 	while(m_strValue.GetLength ()<8)
 		m_strValue=_T("0")+m_strValue;
    	m_strValue=_T("0x")+m_strValue;
	UpdateData(FALSE);
	}
}

void CNewValueDWORD::OnRadio2() 
{
	// TODO: Add your control notification handler code here
	UpdateData(TRUE);
	if(IsDlgButtonChecked(IDC_RADIO2)==BST_CHECKED) 
	{
     if(m_strValue.Left(2)==_T("0x"))
	//	 wcstol((LPCTSTR)m_strValue,(unsigned short **)&m_dwValue,16);
	 	swscanf((LPCTSTR)m_strValue,_T("%x"),&m_dwValue);
	 else
	   swscanf((LPCTSTR)m_strValue,_T("%lu"),&m_dwValue);
	//	wcstol((LPCTSTR)m_strValue,(unsigned short **)&m_dwValue,10);
	m_strValue.Format (_T("%u"),m_dwValue);
	}
	UpdateData(FALSE);
}

⌨️ 快捷键说明

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