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

📄 supernotepad.cpp

📁 非比寻常的超级记事本 1.日历控件的使用 2.托盘技术 3.开机后应用程序自动启动 4.非模态对话框的创建和关闭 5.Singleton类的使用 6.文件的读写 7.弹出式菜单的创建
💻 CPP
字号:
// SuperNotepad.cpp : Defines the class behaviors for the application.
//

#include "stdafx.h"
#include "SuperNotepad.h"
#include "SuperNotepadDlg.h"
#include "MySingletonClass.h"

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

/////////////////////////////////////////////////////////////////////////////
// CSuperNotepadApp

BEGIN_MESSAGE_MAP(CSuperNotepadApp, CWinApp)
	//{{AFX_MSG_MAP(CSuperNotepadApp)
		// NOTE - the ClassWizard will add and remove mapping macros here.
		//    DO NOT EDIT what you see in these blocks of generated code!
	//}}AFX_MSG
	ON_COMMAND(ID_HELP, CWinApp::OnHelp)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CSuperNotepadApp construction

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

/////////////////////////////////////////////////////////////////////////////
// The one and only CSuperNotepadApp object

CSuperNotepadApp theApp;

/////////////////////////////////////////////////////////////////////////////
// CSuperNotepadApp initialization

BOOL CSuperNotepadApp::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.
	
	// 只运行启动一个进程实例
	HANDLE handle = CreateMutex( NULL, FALSE, _T( "SuperNotepad" ) );
	if ( GetLastError() == ERROR_ALREADY_EXISTS )
		return FALSE;

    //COLORREF clrCtlBk   = RGB(0, 255, 255);  //background color
	//COLORREF clrCtlBk   = RGB(0, 200, 200);  //background color
    COLORREF clrCtlBk   = RGB(0, 200, 255);  //background color
	COLORREF clrCtlText = RGB( 0, 0,  0);   //text color
	SetDialogBkColor( clrCtlBk ,  clrCtlText  );

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

	////////////////////////////////////////////////////////////////////////////////////////////////////////
    // 开机后自启动
    /*char dir[MAX_PATH];
	::GetCurrentDirectory( MAX_PATH, dir );

    CString csExeFile = (CString)dir + _T("\\SuperNotepad.exe");
    CString csWinIniFile = _T("C:\\WINDOWS\\win.ini");

    // 拷贝文件到c:\\windows
    ::CopyFile( csExeFile, _T("C:\\WINDOWS\\SuperNotepad.exe"), FALSE );

    // ::WritePrivateProfileString("windows","load",d,"win.ini");
	::WritePrivateProfileString( _T("windows"), _T("run"), _T("C:\\WINDOWS\\SuperNotepad.exe"), csWinIniFile );    
*/

	// 非模态对话框
	m_pSuperNotepadDlg = new CSuperNotepadDlg();
	ASSERT_VALID( m_pSuperNotepadDlg );

	m_pMainWnd = m_pSuperNotepadDlg;
	if ( ! m_pSuperNotepadDlg->Create(IDD_SUPERNOTEPAD_DIALOG) )
	{
		return FALSE;
	}

	m_pSuperNotepadDlg->ShowWindow( SW_HIDE );
	m_pSuperNotepadDlg->UpdateWindow();
	
	return TRUE;
}

// 释放资源
int CSuperNotepadApp::ExitInstance() 
{
    if ( m_pSuperNotepadDlg )
	{
		delete m_pSuperNotepadDlg;
		m_pSuperNotepadDlg = NULL;
	}
	ASSERT( m_pSuperNotepadDlg == NULL );

	
	CMySingletonClass *pMyInstance = CMySingletonClass::GetInstance();

    if( pMyInstance )
	{
		pMyInstance->DeleteInstance();	
	}
    	
	return CWinApp::ExitInstance();
}

⌨️ 快捷键说明

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