newfolderdlg.cpp

来自「一个集成的文本阅读工具」· C++ 代码 · 共 120 行

CPP
120
字号
// NewFolderDlg.cpp : implementation file
//

#include "stdafx.h"
#include "TipReader.h"
#include "NewFolderDlg.h"
#include "FolderSelDlg.h"

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

/////////////////////////////////////////////////////////////////////////////
// CNewFolderDlg dialog


CNewFolderDlg::CNewFolderDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CNewFolderDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CNewFolderDlg)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
}


void CNewFolderDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CNewFolderDlg)
	DDX_Control(pDX, IDC_EDIT3, m_path);
	DDX_Control(pDX, IDC_EDIT1, m_edit);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CNewFolderDlg, CDialog)
	//{{AFX_MSG_MAP(CNewFolderDlg)
	ON_BN_CLICKED(IDSEEKPATH, OnSeekpath)
	ON_EN_SETFOCUS(IDC_EDIT1, OnSetfocusEdit1)
	ON_EN_KILLFOCUS(IDC_EDIT1, OnKillfocusEdit1)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CNewFolderDlg message handlers

void CNewFolderDlg::OnSeekpath() 
{
	// TODO: Add your control notification handler code here
	CFolderSelDlg dlg;
	CString pathstr;
	if(IDOK==dlg.DoModal())
	{
		pathstr=dlg.m_folderpath;
		if(pathstr.Right(1)!="\\")
			pathstr+="\\";
		this->m_path.SetWindowText(pathstr);
	}
}

void CNewFolderDlg::OnOK() 
{
	// TODO: Add extra validation here
	CString pathstr,foldername;
	this->m_path.GetWindowText(pathstr);
	this->m_edit.GetWindowText(foldername);
	
	if(foldername=="输入新建文件夹名!")
	{
		::AfxMessageBox("请输入文件夹名!");
	}
	else
	{
		pathstr+=foldername;
		if(!::CreateDirectory(pathstr,NULL))
		{
			::AfxMessageBox("不能正确创建该文件夹!\n请确认名称正确或驱动器正常!");
		}
		else
		{
			this->defaultpath=pathstr;
			CDialog::OnOK();		
		}
	}
}

BOOL CNewFolderDlg::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	// TODO: Add extra initialization here
	this->m_edit.SetWindowText("输入新建文件夹名!");
	this->m_path.SetWindowText(this->defaultpath);
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CNewFolderDlg::OnSetfocusEdit1() 
{
	// TODO: Add your control notification handler code here
	CString str;
	this->m_edit.GetWindowText(str);
	if(str=="输入新建文件夹名!")
	{
		this->m_edit.SetSel(0,str.GetLength(),FALSE);
		this->m_edit.Clear();
	}
}

void CNewFolderDlg::OnKillfocusEdit1() 
{
	// TODO: Add your control notification handler code here
	CString str;
	this->m_edit.GetWindowText(str);
	if(str=="")
		this->m_edit.SetWindowText("输入新建文件夹名!");	
}

⌨️ 快捷键说明

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