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

📄 minieditdlg.cpp

📁 < VC++编程宝典>>配套源代码, 对于想精通VC++的朋友很有帮助!
💻 CPP
字号:
// MiniEditDlg.cpp : implementation file
//

#include "stdafx.h"
#include "MiniEdit.h"
#include "MiniEditDlg.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#define MAX_FILE_SIZE 10000
/////////////////////////////////////////////////////////////////////////////
// CMiniEditDlg dialog

CMiniEditDlg::CMiniEditDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CMiniEditDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CMiniEditDlg)
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
	m_ctFileText.LimitText(MAX_FILE_SIZE);
}

void CMiniEditDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CMiniEditDlg)
	DDX_Control(pDX, IDC_TEXT, m_ctFileText);
	DDX_Control(pDX, IDC_FILESAVE, m_ctFileSave);
	DDX_Control(pDX, IDC_FILELST, m_ctFileLst);
	DDX_Control(pDX, IDC_BASEDIR, m_ctBaseDir);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CMiniEditDlg, CDialog)
	//{{AFX_MSG_MAP(CMiniEditDlg)
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_SEARCH, OnSearch)
	ON_LBN_DBLCLK(IDC_FILELST, OnDblclkFilelst)
	ON_BN_CLICKED(IDC_SAVE, OnSave)
	ON_WM_CLOSE()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CMiniEditDlg message handlers

BOOL CMiniEditDlg::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 CMiniEditDlg::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 CMiniEditDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}

void CMiniEditDlg::OnSearch() 
{
	//Reset the contents of the list box
	//so we don't have duplicate entries
	m_ctFileLst.ResetContent();
	
	//Get specified directory
	m_ctBaseDir.GetWindowText(m_strBaseDir);
	//Test to make sure m_strBaseDir is not empty
	if(m_strBaseDir.GetLength()==0){
		return;
	}
	
	//Check and see if m_strBaseDir ends in
	// a '\'
	//If it doesn't, add a '\' to the end
	if (m_strBaseDir.Right(1)!="\\"){
		m_strBaseDir+="\\";
	}
	
	//Display the cleaned-up file name
	//in IDC_BASEDIR
	m_ctBaseDir.SetWindowText(m_strBaseDir);
	
	//Create the search criteria string by
	//concatenating m_strBaseDir and "*.mne"
	m_strSearchDir=m_strBaseDir + "*.mne";
	
	//Use CListBox::Dir to populate the list box
	//with file names
	m_ctFileLst.Dir(0,m_strSearchDir);
	
}

void CMiniEditDlg::OnDblclkFilelst() 
{
	CString strFileName;
	int nSelPos;
	char Buf[MAX_FILE_SIZE];

	//Get the position of the current selection
	//and store the selecttion text in strFileName
	nSelPos=m_ctFileLst.GetCurSel();
	m_ctFileLst.GetText(nSelPos,strFileName);
	
	//Form a valid file name by concatenating
	//strFileName with m_strBaseDir since
	//the list box only contains file names
	//without paths
	strFileName=m_strBaseDir + strFileName;
	
	//Set IDC_FILESAVE to the new file name
	m_ctFileSave.SetWindowText(strFileName);
	
	//Create a CFile object and read in the file
	CFile tempFile(strFileName,CFile::modeReadWrite);
	tempFile.Read(Buf,MAX_FILE_SIZE);
	
	//Finally, display the file contents in IDC_FILETEXT
	m_ctFileText.SetWindowText(Buf);
	
	
}

void CMiniEditDlg::OnSave() 
{
	if(m_ctFileSave.LineLength==0){
		AfxMessageBox("A file name and path must be specified");
		return;
	}

	CString strTemp;
	m_ctFileSave.GetWindowText(strTemp);
	CFile tempFile(strTemp,CFile::modeCreate|
		CFile::modeWrite);

	char Buf[MAX_FILE_SIZE];


	m_ctFileText.GetWindowText(Buf,MAX_FILE_SIZE);

	tempFile.Write(Buf,MAX_FILE_SIZE);

	tempFile.Close;
	
}

⌨️ 快捷键说明

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