www.pudn.com > 数控仿真与网络控制系统.rar > OptionsDlg.cpp


// OptionsDlg.cpp : implementation file 
// 
 
#include "stdafx.h" 
#include "NoteXpad.h" 
#include "OptionsDlg.h" 
#include  
#ifdef _DEBUG 
#define new DEBUG_NEW 
#undef THIS_FILE 
static char THIS_FILE[] = __FILE__; 
#endif 
 
///////////////////////////////////////////////////////////////////////////// 
// COptionsDlg dialog 
 
 
COptionsDlg::COptionsDlg(CWnd* pParent /*=NULL*/) 
	: CDialog(COptionsDlg::IDD, pParent) 
{ 
	//{{AFX_DATA_INIT(COptionsDlg) 
	m_AssociateWithFiles = FALSE; 
	//}}AFX_DATA_INIT 
} 
 
 
void COptionsDlg::DoDataExchange(CDataExchange* pDX) 
{ 
	CDialog::DoDataExchange(pDX); 
	//{{AFX_DATA_MAP(COptionsDlg) 
	DDX_Control(pDX, IDC_ASSOCIATE, m_Associate); 
	DDX_Check(pDX, IDC_ASSOCIATE, m_AssociateWithFiles); 
	//}}AFX_DATA_MAP 
} 
 
 
BEGIN_MESSAGE_MAP(COptionsDlg, CDialog) 
	//{{AFX_MSG_MAP(COptionsDlg) 
	ON_BN_CLICKED(IDC_ASSOCIATE, OnAssociate) 
	//}}AFX_MSG_MAP 
END_MESSAGE_MAP() 
 
///////////////////////////////////////////////////////////////////////////// 
// COptionsDlg message handlers 
 
BOOL COptionsDlg::OnInitDialog()  
{ 
	CDialog::OnInitDialog(); 
	CWinApp* theApp = (CWinApp*)AfxGetApp(); 
	m_Associate.SetCheck(theApp->GetProfileInt("Settings","AssociateWithFiles",1)); 
 
	 
	return TRUE;  // return TRUE unless you set the focus to a control 
	              // EXCEPTION: OCX Property Pages should return FALSE 
} 
void COptionsDlg::AssociateWithTextFiles(BOOL OnOrOff) 
{ 
	CString exename; 
	CWinApp* app = (CWinApp*)AfxGetApp(); 
	exename.Format("%s%s", app->m_pszExeName, ".EXE"); 
	char path[MAX_PATH]; 
	GetModuleFileName(GetModuleHandle(exename), path, MAX_PATH); 
	char windowspath[MAX_PATH]; 
	GetWindowsDirectory(windowspath,MAX_PATH); 
	CString Notepad; 
	Notepad.Format("%s\\",windowspath); 
	Notepad += "notepad.exe %1"; 
	CRegKey theKey; 
	CString cmdLine = path; 
	cmdLine += " %1";	 
	CString iconPath = path; 
	iconPath += ",1"; 
	CString notepadIconPath = windowspath; 
	notepadIconPath +=  "\\notepad.exe,1"; 
	switch (OnOrOff) 
	{ 
	case TRUE: 
		 
		theKey.Create(HKEY_CLASSES_ROOT,"NoteXpad"); 
		theKey.SetValue(HKEY_CLASSES_ROOT,"NoteXpad","Text File"); 
 
		theKey.Create(HKEY_CLASSES_ROOT,".txt"); 
		theKey.SetValue(HKEY_CLASSES_ROOT,".txt","NoteXpad"); 
 
		theKey.Create(HKEY_CLASSES_ROOT,"NoteXpad"); 
		theKey.SetValue(HKEY_CLASSES_ROOT,"NoteXpad\\shell\\open\\command",cmdLine); 
		 
		theKey.Create(HKEY_CLASSES_ROOT,".txt\\DefaultIcon"); 
		theKey.SetValue(HKEY_CLASSES_ROOT,".txt\\DefaultIcon",iconPath); 
	 
		theKey.Create(HKEY_CLASSES_ROOT,"NoteXpad\\DefaultIcon"); 
		theKey.SetValue(HKEY_CLASSES_ROOT,"NoteXpad\\DefaultIcon",iconPath); 
	 
		theKey.Create(HKEY_CLASSES_ROOT,".txt\\shell\\open\\command"); 
		theKey.SetValue(cmdLine,"NoteXpad"); 
		break; 
 
	case FALSE: 
		 
		theKey.Create(HKEY_CLASSES_ROOT,"Notepad"); 
		theKey.SetValue(HKEY_CLASSES_ROOT,"Notepad","Text File"); 
		theKey.SetValue(HKEY_CLASSES_ROOT,".txt","Notepad"); 
 
		theKey.Create(HKEY_CLASSES_ROOT,"Notepad\\DefaultIcon"); 
		theKey.SetValue(HKEY_CLASSES_ROOT,"Notepad\\DefaultIcon",notepadIconPath); 
 
		theKey.Create(HKEY_CLASSES_ROOT,"Notepad"); 
		theKey.SetValue(HKEY_CLASSES_ROOT,"Notepad\\shell\\open\\command",Notepad); 
 
		theKey.Create(HKEY_CLASSES_ROOT,".txt\\shell\\open\\command"); 
		theKey.SetValue(Notepad,"Notepad"); 
		theKey.SetValue(HKEY_CLASSES_ROOT,".txt\\DefaultIcon",notepadIconPath); 
		theKey.Attach(HKEY_CLASSES_ROOT); 
		theKey.DeleteSubKey("NoteXpad"); 
		break; 
 
	} 
 
} 
 
void COptionsDlg::OnOK()  
{ 
	 
	AssociateWithTextFiles(m_Associate.GetCheck());	 
	CDialog::OnOK(); 
} 
 
 
 
void COptionsDlg::OnAssociate()  
{ 
	CWinApp* theApp = (CWinApp*)AfxGetApp(); 
 
	theApp->WriteProfileInt("Settings","AssociateWithFiles",m_Associate.GetCheck()); 
}