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

📄 xynotedlg.cpp

📁 在文件的前端和后端添加说明的程序
💻 CPP
字号:

///********************************************************
//                               \\\|///
//                             \\  - -  //
//                              (  @ @  )
//┏━━━━━━━━━━━━━oOOo-(_)-oOOo━━━━━━━━━━━━┓
//┃☆☆☆☆☆☆   ≈≈≈大家好!我是【王晓钰】≈≈≈  ☆☆☆☆☆☆┃
//┃№№№№$$$$№№№№$$$$№№№№$$$$№№№№$$$ ┃
//┃¤¤※※※※ ≈≈≈≈≈≈谢谢大家的厚爱≈≈≈≈≈≈※※※※¤¤┃
//┃★★★★★主页“笑语小园”:http://xiaoyuyeah.yeah.net★★★★★┃
//┃★★★★★主页“笑语小园”:http://xiaoyuyeah.126.com ★★★★★┃
//┃★★★★★☆☆电子邮件:   Garden.XiaoYu@263.net  ☆☆★★★★★┃
//┃★★★★★OICQ: 285126                               ★★★★★┃
//┃☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆ ┃
//┃                                   Oooo〖王晓钰〗2001年02月12日┃
//┗━━━━━━━━━━━━━━oooO---(  )━━━━━━━━━━━━┛
//                             (   )   ) /
//                              \ (   (_/
//                               \_)
///*******************************************************
/// xyNoteDlg.cpp : implementation file
//

#include "stdafx.h"
#include "xyNote.h"
#include "xyNoteDlg.h"

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

/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
#include "HyperLink.h"
class CAboutDlg : public CDialog
{
public:
	CAboutDlg();

// Dialog Data
	//{{AFX_DATA(CAboutDlg)
	enum { IDD = IDD_ABOUTBOX };
	CHyperLink	m_web2;
	CHyperLink	m_web1;
	CHyperLink	m_mail;
	//}}AFX_DATA

	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CAboutDlg)
	public:
	virtual BOOL Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID, CCreateContext* pContext = NULL);
	protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
	//}}AFX_VIRTUAL

// Implementation
protected:
	//{{AFX_MSG(CAboutDlg)
	//}}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)
	DDX_Control(pDX, IDC_XY_WEB2, m_web2);
	DDX_Control(pDX, IDC_XY_WEB1, m_web1);
	DDX_Control(pDX, IDC_XY_MAIL, m_mail);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
	//{{AFX_MSG_MAP(CAboutDlg)
		// No message handlers
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CXyNoteDlg dialog

CXyNoteDlg::CXyNoteDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CXyNoteDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CXyNoteDlg)
	m_isIncludeSub = FALSE;
	m_noteText = _T("");
	m_insertBefore = _T("");
	m_opBegin = FALSE;
	m_opEnd = FALSE;
	m_opMid = FALSE;
	m_repeat = FALSE;
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	newline[0]=char(0x0d);
	newline[1]=char(0x0a);
	newline[2]=0;
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CXyNoteDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CXyNoteDlg)
	DDX_Control(pDX, IDC_XY_DIR, m_dirComb);
	DDX_Control(pDX, IDC_XY_LIST, m_list);
	DDX_Control(pDX, IDC_TAB3, m_tabCtrl);
	DDX_Check(pDX, IDC_XY_CHECK, m_isIncludeSub);
	DDX_Text(pDX, IDC_XY_TEXT, m_noteText);
	DDX_Text(pDX, IDC_XYOPT_TEXT, m_insertBefore);
	DDX_Check(pDX, IDC_XYOP_BEGIN, m_opBegin);
	DDX_Check(pDX, IDC_XYOP_END, m_opEnd);
	DDX_Check(pDX, IDC_XYOP_MID, m_opMid);
	DDX_Check(pDX, IDC_XYOP_REPEAT, m_repeat);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CXyNoteDlg, CDialog)
	//{{AFX_MSG_MAP(CXyNoteDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_NOTIFY(TCN_SELCHANGE, IDC_TAB3, OnSelchangeTab3)
	ON_BN_CLICKED(IDC_BEGIN, OnBegin)
	ON_BN_CLICKED(IDC_XY_ADDDIR, OnXyAdddir)
	ON_BN_CLICKED(IDC_XY_DELDIR, OnXyDeldir)
	ON_BN_CLICKED(IDC_XY_ABOUT, OnXyAbout)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CXyNoteDlg message handlers

BOOL CXyNoteDlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	// Add "About..." menu item to system menu.

	// IDM_ABOUTBOX must be in the system command range.
	ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
	ASSERT(IDM_ABOUTBOX < 0xF000);

	CMenu* pSysMenu = GetSystemMenu(FALSE);
	if (pSysMenu != NULL)
	{
		CString strAboutMenu;
		strAboutMenu.LoadString(IDS_ABOUTBOX);
		if (!strAboutMenu.IsEmpty())
		{
			pSysMenu->AppendMenu(MF_SEPARATOR);
			pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
		}
	}

	// 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
	m_tabCtrl.InsertItem(0,"注释文本");
	m_tabCtrl.InsertItem(1,"高级设置");
	id_tab1.Add(IDC_XY_TEXT);
	id_tab1.Add(IDC_XY_FRAME);
	id_tab1.Add(IDC_XY_DIR);
	id_tab1.Add(IDC_XY_CHECK);
	//id_tab1.Add(IDC_XY_ADDDIR);
	id_tab1.Add(IDC_XY_LIST);
	//id_tab1.Add(IDC_XY_TEXTINITEM);

	id_tab2.Add(IDC_XYOP_BEGIN);
	id_tab2.Add(IDC_XYOP_END);
	id_tab2.Add(IDC_XYOP_MID);
	id_tab2.Add(IDC_XY_TEXT_INSBEFORE);
	id_tab2.Add(IDC_XY_PROMT_TXT);
	id_tab2.Add(IDC_XY_PROMT);
	
	m_list.AddString("*.c");
	m_list.AddString("*.cpp");
	m_list.AddString("*.h");
	m_list.AddString("*.hpp");
	m_list.SetSel(-1);
	m_isIncludeSub=TRUE;
	//m_op=BEGIN;
	///GetDlgItem(IDC_XYOP_BEGIN);
//	m_opB=1;
	//加入当前目录
	/*
	char	dirCh[50];
	GetCurrentDirectory(50,dirCh);
	m_dirComb.AddString(dirCh);
	m_dirComb.SetCurSel(0);
	*/

	m_wndDisp=GetDlgItem(IDC_XY_DISP);
	m_noteText.LoadString(IDS_NOTESTR);
	m_noteText.Replace("\n",newline);

	m_opBegin=false;
	m_opEnd=true;
	m_opMid=false;
	m_repeat=false;
	UpdateData(false);

	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CXyNoteDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
	if ((nID & 0xFFF0) == IDM_ABOUTBOX)
	{
		CAboutDlg dlgAbout;
		dlgAbout.DoModal();
	}
	else
	{
		CDialog::OnSysCommand(nID, lParam);
	}
}

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

void CXyNoteDlg::OnSelchangeTab3(NMHDR* pNMHDR, LRESULT* pResult) 
{
	// TODO: Add your control notification handler code here
	int i,id,showItem;
	showItem=m_tabCtrl.GetCurSel();


	for(i=0;i<id_tab1.GetSize();i++)
	{	id=id_tab1[i];
		if(GetDlgItem(id))
			GetDlgItem(id)->ShowWindow(showItem==0?SW_SHOW:SW_HIDE);
	}

	for(i=0;i<id_tab2.GetSize();i++)
	{	id=id_tab2[i];
		if(GetDlgItem(id))
		GetDlgItem(id)->ShowWindow(showItem==1?SW_SHOW:SW_HIDE);
	}
	//GetDlgItem(IDC_XY_TEXT_INSBEFORE)->ShowWindow(SW_HIDE);
	if(showItem==0)	GetDlgItem(IDC_XY_TEXT)->SetFocus();

	*pResult = 0;
}

void CXyNoteDlg::OnBegin() 
{
	// TODO: Add your control notification handler code here
	UpdateData();
	m_noteText.Insert(0,newline);
	m_noteText.Insert(m_noteText.GetLength()-1,newline);
	//MessageBox("begin");
	int	i,j;
	CString	dir,filter;
	for(i=0;i<m_dirComb.GetCount();i++)
	{	m_dirComb.GetLBText(i,dir);
		for(j=0;j<m_list.GetCount();j++)
		{	m_list.GetText(j,filter);
			if(m_isIncludeSub)
				multiDir(dir,filter,m_noteText);
			else
				noteDir(dir,filter,m_noteText);
		}
	}
	MessageBox("任务处理完毕");
}



int CXyNoteDlg::noteDir(CString dir, CString filter, CString note)
{	CFileFind	finder;
	CString	findStr;
	BOOL	findReturn;

	if(dir.Right(2)=="..")	return	1;
	findStr=dir+"\\";
	findStr+=filter;
	findReturn=finder.FindFile(findStr);
	while(findReturn)
	{	findReturn=finder.FindNextFile();
		noteFile(finder.GetFilePath(),note);
	}
	return 0;
}

int CXyNoteDlg::noteFile(CString fileName, CString note)
{	CFile	file;
	CFileStatus	status;
	if(!file.GetStatus(fileName,status))
		return 1;	//file not exist;
	
	m_wndDisp->SetWindowText(file.GetFilePath());
	m_wndDisp->UpdateWindow();
	if(!file.Open(fileName,CFile::modeReadWrite|CFile::shareDenyWrite))
		return 2;	//error in read;
//	file.SeekToBegin();//注意,这里是加在文件的最前面!!
	char* fileChar;
	DWORD	len=file.GetLength();
	file.SeekToBegin();
	fileChar=new char[len];
	len=file.Read(fileChar,len);
	//准备好,开始写程序。
	file.SeekToBegin();
	if(m_opBegin)
	{	file.Write(LPCTSTR(note),note.GetLength());
	}
	//看是否在中间加入注释。如果是,改造.
	if(m_opMid)
	{	CString	fileStr(fileChar,len);
		int	findIndex=-1;//从0开始
		do
		{	findIndex=fileStr.Find(m_insertBefore,findIndex+1);
			if(findIndex>-1)
			{	fileStr.Insert(findIndex,m_noteText);
				findIndex+=m_noteText.GetLength();
			}
		}while(findIndex>-1);
		file.Write(LPCTSTR(fileStr),fileStr.GetLength());
	}	//否则不改造,直接写入。
	else
	{	file.Write(fileChar,len);
	}
	if(m_opEnd)
	{	
		file.SeekToEnd();
		file.Write(LPCTSTR(note),note.GetLength());
	}
	file.Close();
	return 0;
}

int CXyNoteDlg::noteMutiDir(CString dir, CString filter, CString note)
{	CFileFind	finder;
	BOOL	findReturn;

	findReturn=finder.FindFile(dir+"\\*.*");
	while(findReturn)
	{	findReturn=finder.FindNextFile();
		if(finder.IsDirectory())
			if(finder.IsDots())
				noteDir(dir,filter,note);
			else
				noteMutiDir(dir,filter,note);
	}
	return 0;
}

int CXyNoteDlg::SelectDirDlg(char Dir[])
{	BROWSEINFO bi; 
	static ITEMIDLIST* pidl; 

	bi.hwndOwner=NULL; 
	bi.pidlRoot=NULL; 
	bi.pszDisplayName=Dir; 
	bi.lpszTitle="请选择要提取目录的文件夹";
	bi.ulFlags=BIF_RETURNONLYFSDIRS; 
	bi.lpfn=NULL; 
	bi.lParam=0; 
	bi.iImage=0; 

	pidl=SHBrowseForFolder(&bi);/*Display"SelectFolder"dialogbox,Get the foldernameandconvertit 
	intoaITEMLIST 	datastructure.*/ 
	if(pidl==NULL) 
	{	Dir[0]=0; 
		return 1;
	}
	if(!SHGetPathFromIDList(pidl,Dir))/*Retrievefoldername from ITEMLIST structure.*/ 
	{	Dir[0]=0; return 2;}
	return 0;
}

void CXyNoteDlg::OnXyAdddir() 
{
	// TODO: Add your control notification handler code here
	UpdateData();
	char directory[50];
	if(!SelectDirDlg(directory))
	{	m_dir.Add(CString(directory));
		m_dirComb.AddString(directory);
		m_dirComb.SetCurSel(m_dirComb.GetCount()-1);
		UpdateData(false);
	}
}

void CXyNoteDlg::OnXyDeldir() 
{
	// TODO: Add your control notification handler code here
	UpdateData();
	int i=m_dirComb.GetCurSel();
	m_dirComb.DeleteString(i);
	m_dirComb.SetCurSel(i-1>=0?i-1:0);
	UpdateData(false);
}

int CXyNoteDlg::multiDir(CString dir, CString filter, CString note)
{	CFileFind	finder;
	BOOL	findReturn;

	//m_wndDisp->ShowWindow(SW_SHOW);
	findReturn=finder.FindFile(dir+"\\*.*");
	while(findReturn)
	{	findReturn=finder.FindNextFile();
		if(finder.IsDots())
			noteDir(finder.GetFilePath(),filter,note);
		else
			multiDir(finder.GetFilePath(),filter,note);
	}
	return 0;
}

BOOL CXyNoteDlg::PreTranslateMessage(MSG* pMsg) 
{
	// TODO: Add your specialized code here and/or call the base class
	return CDialog::PreTranslateMessage(pMsg);
}

BOOL CAboutDlg::Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID, CCreateContext* pContext) 
{
	// TODO: Add your specialized code here and/or call the base class
	m_web1.SetURL("http://XiaoyuYeah.yeah.net");
	m_web2.SetURL("http://XiaoyuYeah.126.com");
	m_mail.SetURL("mail to:Garden.XiaoYu@263.net");
	
	return CDialog::Create(IDD, pParentWnd);
}

void CXyNoteDlg::OnXyAbout() 
{
	// TODO: Add your control notification handler code here
	CAboutDlg	dlg;
	dlg.DoModal();
}

///********************************************************
//                               \\\|///
//                             \\  - -  //
//                              (  @ @  )
//┏━━━━━━━━━━━━━oOOo-(_)-oOOo━━━━━━━━━━━━┓
//┃☆☆☆☆☆☆   ≈≈≈大家好!我是【王晓钰】≈≈≈  ☆☆☆☆☆☆┃
//┃№№№№$$$$№№№№$$$$№№№№$$$$№№№№$$$ ┃
//┃¤¤※※※※ ≈≈≈≈≈≈谢谢大家的厚爱≈≈≈≈≈≈※※※※¤¤┃
//┃★★★★★主页“笑语小园”:http://xiaoyuyeah.yeah.net★★★★★┃
//┃★★★★★主页“笑语小园”:http://xiaoyuyeah.126.com ★★★★★┃
//┃★★★★★☆☆电子邮件:   Garden.XiaoYu@263.net  ☆☆★★★★★┃
//┃★★★★★OICQ: 285126                               ★★★★★┃
//┃☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆ ┃
//┃                                   Oooo〖王晓钰〗2001年02月12日┃
//┗━━━━━━━━━━━━━━oooO---(  )━━━━━━━━━━━━┛
//                             (   )   ) /
//                              \ (   (_/
//                               \_)
///*******************************************************
/

⌨️ 快捷键说明

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