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

📄 regdlg.cpp

📁 完成注册表修改的应用程序,能修改多种键值,实现注册表编辑器的禁止和解除禁止.
💻 CPP
字号:
// REGDlg.cpp : implementation file
//

#include "stdafx.h"
#include "REG.h"
#include "REGDlg.h"
#include <assert.h>
#include "gneng.h"

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

/////////////////////////////////////////////////////////////////////////////
// CREGDlg dialog

 
 DWORD   fValue;	

CREGDlg::CREGDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CREGDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CREGDlg)
	m_xiandword = _T("");
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CREGDlg::DoDataExchange(CDataExchange* pDX)
{
 DWORD type_1=REG_DWORD;
     DWORD   rc; 
     DWORD   len; 
	
	LPCTSTR data_Set="Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\System\\";
    
	 HKEY hkey;
    
	
 
     len = 4; 
    RegOpenKeyEx(HKEY_CURRENT_USER,data_Set, 0, KEY_READ, &hkey);
    rc = RegQueryValueEx( hkey, "DisableRegistryTools", 0, &type_1, (LPBYTE)&fValue, &len ); 
      if (rc != ERROR_SUCCESS) { 
        if (rc == ERROR_FILE_NOT_FOUND) { 
            fValue = 0; 
           
        } 
        else { 
            assert( rc == ERROR_SUCCESS ); 
        } 
    } 

  
    //fValu=fValue;
	if(fValue==0)
	{
     m_xiandword="注册表已经开启";
	 //UpdateData(false);
	}
	if(fValue==1)
	{
     m_xiandword="注册表已经关闭";
	 //UpdateData(false);
	}

	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CREGDlg)
	DDX_Text(pDX, IDC_EDIT1, m_xiandword);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CREGDlg, CDialog)
	//{{AFX_MSG_MAP(CREGDlg)
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
	ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
	ON_BN_CLICKED(IDC_BUTTON3, OnButton3)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CREGDlg message handlers

BOOL CREGDlg::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 CREGDlg::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 CREGDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}

void CREGDlg::OnButton1() 
{
DWORD type_1=REG_DWORD;
     DWORD   rc; 
     DWORD   len; 
	 DWORD   fValue;
      DWORD  m_xiudw;
	LPCTSTR data_Set="Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\System\\";
    
	 HKEY hkey;
    
	
 
    len = 4; 
    RegOpenKeyEx(HKEY_CURRENT_USER,data_Set, 0, KEY_QUERY_VALUE | KEY_SET_VALUE, &hkey);
    rc = RegQueryValueEx( hkey, "DisableRegistryTools", 0, &type_1, (LPBYTE)&fValue, &len ); 
    if (rc != ERROR_SUCCESS) { 
        if (rc == ERROR_FILE_NOT_FOUND) { 
            fValue = 0; 
           
        } 
        else { 
            assert( rc == ERROR_SUCCESS ); 
        } 
    } 
  
    //fValu=fValue;
	if(fValue==0)
	{
     MessageBox("注册表已经开启请勿重新开启","错误",MB_OK);
	}
	else
	{
      m_xiudw=0;
      rc = RegSetValueEx( hkey, "DisableRegistryTools", 0, REG_DWORD, (LPBYTE)&m_xiudw, 4 ); 
    assert( rc == ERROR_SUCCESS );
   MessageBox("注册表已经成功开启","成功",MB_OK);
	}
 UpdateData(false);
	
}

void CREGDlg::OnOK() 
{
	// TODO: Add extra validation here
	
	CDialog::OnOK();
}

void CREGDlg::OnButton2() 
{
	DWORD type_1=REG_DWORD;
     DWORD   rc; 
     DWORD   len; 
	 DWORD   fValue;
      DWORD  m_xiudw;
	LPCTSTR data_Set="Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\System\\";
    
	 HKEY hkey;
    
	
 
    len = 4; 
    RegOpenKeyEx(HKEY_CURRENT_USER,data_Set, 0, KEY_QUERY_VALUE | KEY_SET_VALUE, &hkey);
    rc = RegQueryValueEx( hkey, "DisableRegistryTools", 0, &type_1, (LPBYTE)&fValue, &len ); 
    if (rc != ERROR_SUCCESS) { 
        if (rc == ERROR_FILE_NOT_FOUND) { 
            fValue = 0; 
           
        } 
        else { 
            assert( rc == ERROR_SUCCESS ); 
        } 
    } 
  
    //fValu=fValue;
	if(fValue==1)
	{
     MessageBox("注册表已经禁用请勿重新关闭","错误",MB_OK);
	}
	else
	{
      m_xiudw=1;
      rc = RegSetValueEx( hkey, "DisableRegistryTools", 0, REG_DWORD, (LPBYTE)&m_xiudw, 4 ); 
    assert( rc == ERROR_SUCCESS );
   MessageBox("注册表已经成功禁用","成功",MB_OK);

	}
 UpdateData(false);
	
}

void CREGDlg::OnButton3() 
{
	if(fValue==1)
	{
     MessageBox("注册表已经禁用请开启后使用","错误",MB_OK);
	}
	else
	{
     gneng dlg;
     	CDialog::OnOK();
		dlg.DoModal();
	}
}

⌨️ 快捷键说明

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