?? desktop_scdlg.cpp
字號:
// desktop_scDlg.cpp : implementation file
//
#include "stdafx.h"
#include "desktop_sc.h"
#include "desktop_scDlg.h"
#include <atlbase.h>
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CDesktop_scDlg dialog
CDesktop_scDlg::CDesktop_scDlg(CWnd* pParent /*=NULL*/)
: CDialog(CDesktop_scDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CDesktop_scDlg)
m_szGUID = _T("");
m_szCmd = _T("");
m_szIconPath = _T("");
m_szDName = _T("");
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
m_szGUID ="{9F0DBE59-C479-49c5-951B-2545242FBDF6}"; //設(shè)置GUID
m_szCmd = "cmd /K dir c:\\"; //設(shè)置命令
m_szIconPath = "F:\\res\\MFC.ico"; //圖標(biāo)文件
m_szDName = "我的圖標(biāo)"; //設(shè)置顯示的名稱
}
void CDesktop_scDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CDesktop_scDlg)
DDX_Text(pDX, IDC_GUID, m_szGUID);
DDX_Text(pDX, IDC_CMD, m_szCmd);
DDX_Text(pDX, IDC_ICONP, m_szIconPath);
DDX_Text(pDX, IDC_DNAME, m_szDName);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CDesktop_scDlg, CDialog)
//{{AFX_MSG_MAP(CDesktop_scDlg)
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_CREATE, OnCreate)
ON_BN_CLICKED(IDC_DEL, OnDel)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CDesktop_scDlg message handlers
BOOL CDesktop_scDlg::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 CDesktop_scDlg::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 CDesktop_scDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CDesktop_scDlg::OnCreate()
{
UpdateData(TRUE);
//
char szTemp[256];
CRegKey m_kdsktp;
//創(chuàng)建GUID入口
sprintf(szTemp,"CLSID\\%s",m_szGUID);
m_kdsktp.Create(HKEY_CLASSES_ROOT,szTemp);
m_kdsktp.SetValue(m_szDName);
m_kdsktp.Close();
//設(shè)置圖標(biāo)
sprintf(szTemp,"CLSID\\%s\\DefaultIcon",m_szGUID);
m_kdsktp.Create(HKEY_CLASSES_ROOT,szTemp);
m_kdsktp.SetValue(m_szIconPath);
m_kdsktp.Close();
//設(shè)置雙擊圖標(biāo)時(shí)的打開命令
sprintf(szTemp,"CLSID\\%s\\Shell\\Open\\Command",m_szGUID);
m_kdsktp.Create(HKEY_CLASSES_ROOT,szTemp );
m_kdsktp.SetValue(m_szCmd);
m_kdsktp.Close();
//設(shè)置菜單屬性
sprintf(szTemp,"CLSID\\%s\\ShellFolder",m_szGUID);
BYTE bValue[4];
m_kdsktp.Create(HKEY_CLASSES_ROOT,szTemp);
bValue[0]=0x0; //"00.00.00.00"
bValue[1]=0x0;
bValue[2]=0x0;
bValue[3]=0x0;
RegSetValueEx(m_kdsktp.m_hKey,"Attributes",0,REG_BINARY,bValue,4);
m_kdsktp.Close();
//在桌面放置圖標(biāo)
sprintf(szTemp,"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Desktop\\NameSpace\\%s",m_szGUID);
m_kdsktp.Create(HKEY_LOCAL_MACHINE,szTemp);
m_kdsktp.SetValue(m_szDName);
m_kdsktp.Close();
//通知桌面更新
SHChangeNotify(SHCNE_ASSOCCHANGED,SHCNF_FLUSHNOWAIT,0, 0);
}
void CDesktop_scDlg::OnDel()
{
UpdateData(TRUE);
//
char szTemp[256];
CRegKey m_kdsktp;
//刪除GUID入口
sprintf(szTemp,"CLSID");
m_kdsktp.Open(HKEY_CLASSES_ROOT,szTemp);
m_kdsktp.DeleteSubKey(m_szGUID);
m_kdsktp.Close();
//刪除桌面圖標(biāo)
sprintf(szTemp,"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Desktop\\NameSpace");
m_kdsktp.Open(HKEY_LOCAL_MACHINE,szTemp);
m_kdsktp.DeleteSubKey(m_szGUID);
m_kdsktp.Close();
//通知桌面更新
SHChangeNotify(SHCNE_ASSOCCHANGED,SHCNF_FLUSHNOWAIT,0, 0);
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -