📄 hidediskdlg.cpp
字号:
// hidediskDlg.cpp : implementation file
//
#include "stdafx.h"
#include "hidedisk.h"
#include "hidediskDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
bool bsel = false;
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
// Dialog Data
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
//}}AFX_DATA
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CAboutDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
//{{AFX_MSG(CAboutDlg)
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
//{{AFX_DATA_INIT(CAboutDlg)
//}}AFX_DATA_INIT
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAboutDlg)
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
// No message handlers
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CHidediskDlg dialog
CHidediskDlg::CHidediskDlg(CWnd* pParent /*=NULL*/)
: CDialog(CHidediskDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CHidediskDlg)
// 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 CHidediskDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CHidediskDlg)
DDX_Control(pDX, IDC_SELECTALL, m_sel);
DDX_Control(pDX, IDC_LIST1, m_list);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CHidediskDlg, CDialog)
//{{AFX_MSG_MAP(CHidediskDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_SELECTALL, OnSelectall)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CHidediskDlg message handlers
BOOL CHidediskDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Add "About..." menu item to system menu.
// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// 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
CString str,cstr,savestr,hidestr;
int mlen,nlen,len,number;
nlen = 0;
str = "ABCDEFGHIJKLMNOPQRSTYUWXYZ";
for(int i = 0; i<26; i++)
{
cstr = str.Mid(i,1);
cstr += ":";
m_list.AddString(cstr);
}
int rv;
HKEY hKey;
DWORD slen = 256;
char data[MAX_PATH];
rv = RegOpenKeyEx(HKEY_CURRENT_USER,
"Software\\SunShine",
0,
KEY_READ|KEY_WRITE,
&hKey);
if(rv == ERROR_SUCCESS)
{
rv=RegQueryValueEx(hKey,
"HideDisk",
0,
NULL,
(BYTE *)data,
&slen);
}
RegCloseKey(hKey);
savestr = data;
len = savestr.Find(";",nlen);
while(len != -1)
{
mlen = len - nlen;
hidestr = savestr.Mid(nlen,mlen);
number = atoi(hidestr);
m_list.SetCheck(number,1);
nlen = len+1;
len = savestr.Find(";",nlen);
}
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CHidediskDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}
// 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 CHidediskDlg::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 CHidediskDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CHidediskDlg::OnOK()
{
BOOL IsNT;
DWORD NTVersion;
NTVersion = GetVersion(); // Get major and minor version numbers of Windows
if( NTVersion >= 0x80000000 )
IsNT = FALSE;
else
IsNT = TRUE;
int num,number,nt;
nt = 0;
number = 1;
CString savedisk,str;
savedisk = "";
for(int i = 0; i < 26; i++)
{
num = m_list.GetCheck(i);
if(num == 1)
{
str.Format("%d",i);
savedisk += str;
savedisk += ";";
if(i == 0)
{
nt = 0;
}
else
{
number = 1;
for(int j = 0; j < i; j++)
{
number = 2 * number;
}
}
nt += number;
}
}
int rv;
HKEY hKey;
HKEY hKey2;
DWORD value,value1 = 1,mLen = 4;
DWORD dwDisposition,slen = 256;
char savehide[MAX_PATH];
strcpy(savehide,savedisk);
value = (DWORD)nt;
if(nt >= 1 )
{
rv = RegOpenKeyEx(HKEY_CURRENT_USER,
"Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer",
0,
KEY_READ|KEY_WRITE,
&hKey);
if(rv == ERROR_SUCCESS)
{
rv=RegSetValueEx(hKey,
"NoDrives",
0,
REG_DWORD,
(BYTE *)&value,
mLen);
rv=RegSetValueEx(hKey,
"NoViewOnDrive",
0,
REG_DWORD,
(BYTE *)&value,
mLen);
}
RegCloseKey(hKey);
rv = RegCreateKeyEx(HKEY_CURRENT_USER,
"Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\WinOldApp",
0,
NULL,
REG_OPTION_NON_VOLATILE,
KEY_READ |KEY_WRITE,
NULL,
&hKey,
&dwDisposition);
if(rv == ERROR_SUCCESS)
{
rv=RegSetValueEx(hKey,
"Disabled",
0,
REG_DWORD,
(BYTE *)&value1,
mLen);
}
RegCloseKey(hKey);
if(IsNT)
{
rv = RegOpenKeyEx(HKEY_CURRENT_USER,
"Software\\Policies\\Microsoft\\Windows\\System",
0,
KEY_ALL_ACCESS,
&hKey2);
if(rv != ERROR_SUCCESS)
{
rv = RegCreateKeyEx(HKEY_CURRENT_USER,
"Software\\Policies\\Microsoft\\Windows\\System",
0,
NULL,
REG_OPTION_NON_VOLATILE,
KEY_READ |KEY_WRITE,
NULL,
&hKey2,
&dwDisposition);
rv = RegSetValueEx(hKey2,"DisableCMD",0, REG_DWORD,(BYTE *)&value1,mLen);
}
else
{
rv = RegSetValueEx(hKey2,"DisableCMD",0, REG_DWORD,(BYTE *)&value1,mLen);
}
}
}
else
{
rv = RegOpenKeyEx(HKEY_CURRENT_USER,
"Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer",
0,
KEY_READ|KEY_WRITE,
&hKey);
if(rv == ERROR_SUCCESS)
{
rv = RegDeleteValue(hKey,"NoDrives");
rv = RegDeleteValue(hKey,"NoViewOnDrive");
}
RegCloseKey(hKey);
rv = RegOpenKeyEx(HKEY_CURRENT_USER,
"Software\\Microsoft\\Windows\\CurrentVersion\\Policies",
0,
KEY_READ|KEY_WRITE,
&hKey);
if(rv == ERROR_SUCCESS)
{
rv=RegDeleteKey(hKey,"WinOldApp");
}
RegCloseKey(hKey);
rv = RegOpenKeyEx(HKEY_CURRENT_USER,
"Software\\Policies\\Microsoft\\Windows\\System",
0,
KEY_ALL_ACCESS,
&hKey2);
if(rv == ERROR_SUCCESS)
{
rv = RegDeleteValue(hKey2,"DisableCMD");
}
RegCloseKey(hKey2);
}
rv = RegOpenKeyEx(HKEY_CURRENT_USER,
"Software\\SunShine",
0,
KEY_READ|KEY_WRITE,
&hKey);
if(rv == ERROR_SUCCESS)
{
rv=RegSetValueEx(hKey,
"HideDisk",
0,
REG_SZ,
(BYTE *)savehide,
slen);
}
RegCloseKey(hKey);
//刷新注册表,不用重启机
::SendMessage(HWND_BROADCAST,WM_SETTINGCHANGE,0,0);
CDialog::OnOK();
}
void CHidediskDlg::OnSelectall()
{
// TODO: Add your control notification handler code here
bsel =!bsel;
if (bsel)
{
m_sel.SetWindowText("清除");
for(int i = 0; i < 26; i++)
{
m_list.SetCheck(i,1);
}
}
else
{ m_sel.SetWindowText("全选");
for(int i = 0; i < 26; i++)
{
m_list.SetCheck(i,0);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -