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

📄 mtoudlg.cpp

📁 参照别人的程序我做了这个动态改变界面的演示
💻 CPP
字号:
// MtoUDlg.cpp : implementation file
//

#include "stdafx.h"
#include "MtoU.h"
#include "MtoUDlg.h"
#include "direct.h"

#include "ISNConversion.h"
#include "FindFileThread.h"

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


/////////////////////////////////////////////////////////////////////////////
// CMtoUDlg dialog

CMtoUDlg::CMtoUDlg(CWnd* pParent /*=NULL*/)
	: CSkinDialog(CMtoUDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CMtoUDlg)
	m_chartset = _T("");
	m_filecount=0;
	//}}AFX_DATA_INIT
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
	
}

void CMtoUDlg::DoDataExchange(CDataExchange* pDX)
{
	CSkinDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CMtoUDlg)
	DDX_Control(pDX, IDC_BTN_ENDDIALOG, m_btnquit);
	DDX_Control(pDX, IDC_BTN_CONVERSION, m_btnconvert);
	DDX_Control(pDX, IDC_BTN_FINDFILE, m_btnfindfile);
	DDX_Control(pDX, IDC_BTN_SELECTDIR, m_btnselectdir);
	DDX_Control(pDX, IDC_PROGRESS_FILE, m_progressfile);
	DDX_Control(pDX, IDC_LIST_FINDFILE, m_listfindfile);
	DDX_CBString(pDX, IDC_COMBO_CHARTSET, m_chartset);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CMtoUDlg, CSkinDialog)
	//{{AFX_MSG_MAP(CMtoUDlg)
	ON_BN_CLICKED(IDC_BTN_FINDFILE, OnBtnfindfile)
	ON_BN_CLICKED(IDC_BTN_SELECTDIR, OnBtnSelectdir)
	ON_BN_CLICKED(IDC_BTN_ENDDIALOG, OnBtnEnddialog)
	ON_BN_CLICKED(IDC_BTN_CONVERSION, OnBtnConversion)
	ON_WM_CTLCOLOR()
	ON_MESSAGE(WM_ENDFIND, OnEndFind)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()


BOOL CMtoUDlg::OnInitDialog()
{
	CtrlPos.Add(IDC_STATIC_CURDIR);
	CtrlPos.Add(IDC_COMBO_CHARTSET);
	CtrlPos.Add(IDC_EDIT_FILENAME);
	CtrlPos.Add(IDC_LIST_FINDFILE);
	CtrlPos.Add(IDC_STATIC_FILECOUNT);
	CtrlPos.Add(IDC_STATICTIME);
	CtrlPos.Add(IDC_PROGRESS_FILE);
	SetCtrlID(&CtrlPos);
	
	BtnID.Add(IDC_BTN_SELECTDIR);	BtnID.Add(IDC_BTN_FINDFILE);
	BtnID.Add(IDC_BTN_CONVERSION); 	BtnID.Add(IDC_BTN_ENDDIALOG);

	SetMainMenu(IDR_MAINMENU);
	SetBtnID(&BtnID);
	
	
	CSkinDialog::OnInitDialog();

	SetIcon(m_hIcon, TRUE);			
	SetIcon(m_hIcon, FALSE);
	
    //Set combox control default item 	
	((CComboBox *)GetDlgItem(IDC_COMBO_CHARTSET))->SelectString(0,_T("936 Chinese (PRC, Singapore) "));

	return TRUE;  
}


void CMtoUDlg::OnBtnfindfile() 
{

	CString m_CurDir;
	GetDlgItem(IDC_STATIC_CURDIR)->GetWindowText(m_CurDir);
    if(m_CurDir.IsEmpty())
	{
		AfxMessageBox("请先选择文件夹!");
		return;
	}

	CString m_fName;
	GetDlgItem(IDC_STATIC_CURDIR)->GetWindowText(m_fName);
	if(m_fName.IsEmpty())
	{
		AfxMessageBox("请输入文件名!");
		return;
	}

	//////////////////////////////////////
	GetDlgItem(IDC_STATIC_FILECOUNT)->SetWindowText("");
	GetDlgItem(IDC_STATICTIME)->SetWindowText("");

	CWinThread *pThread = AfxBeginThread(RUNTIME_CLASS(CFindFileThread));
	if(pThread!=NULL)
		pThread->PostThreadMessage(WM_BEGINFIND,(WPARAM)this, (LPARAM)NULL);
	//////////////////////////////////////
}


LONG CMtoUDlg::OnEndFind(WPARAM wParam, LPARAM lParam)
{
	CString temp;
	temp.Format("%d",m_filecount);
	GetDlgItem(IDC_STATIC_FILECOUNT)->SetWindowText(temp);

	temp.Format("%.2f", lParam/1000.0);
	GetDlgItem(IDC_STATICTIME)->SetWindowText(temp);

	m_progressfile.SetRange32(0,m_filecount);

	Invalidate();
    m_filecount = 0;
	CWinThread* pThread = (CWinThread*)wParam;
	pThread->ExitInstance();
	AfxMessageBox("Finding file end!");
	return 1;
}



void CMtoUDlg::OnBtnConversion() 
{
	int i,nFileCount;
	CISNConversion m_convert;

	UpdateData(TRUE);

    //Get Code Page from Combox Control
	CString m_set=m_chartset.Left(m_chartset.Find(0x20));
    UINT nCodePage=atoi((LPCTSTR)m_set);

    CString m_filepath;
	nFileCount=m_listfindfile.GetCount();
	if(nFileCount == 0)
	{
		AfxMessageBox("没有要转换的文件!");
		return;
	}
	for(i=0; i<nFileCount; i++)
	{ 
		m_listfindfile.GetText(i,m_filepath);
		m_convert.AnsiToUtf8((LPCTSTR)m_filepath,nCodePage);
		m_progressfile.SetPos(i+1);
	}

	MessageBox(_T("      内码转换完成!\n\nCopyright by Bright_road 2001.7"),_T("谢谢使用"),MB_OK|MB_ICONINFORMATION);

	GetDlgItem(IDC_STATIC_FILECOUNT)->SetWindowText(_T("0"));
	m_listfindfile.ResetContent();
	m_progressfile.SetPos(0);
}

void CMtoUDlg::OnBtnSelectdir() 
{

	char path[500];
	BROWSEINFO bi;
	ITEMIDLIST * pidl;
	bi.hwndOwner =this->GetSafeHwnd();
	bi.iImage =0;
	bi.lParam =0;
	bi.lpfn =0;
	bi.lpszTitle ="请选择文件夹:";
	bi.pidlRoot =0;
	bi.pszDisplayName =0;
	bi.ulFlags =BIF_RETURNONLYFSDIRS;
	pidl=SHBrowseForFolder(&bi);
	if (SHGetPathFromIDList(pidl,path)==TRUE)
	{
		GetDlgItem(IDC_STATIC_CURDIR)->SetWindowText(path);
	}
	
}

void CMtoUDlg::OnBtnEnddialog() 
{
	CSkinDialog::OnOK();
}

BOOL CMtoUDlg::PreTranslateMessage(MSG* pMsg) 
{
	if( pMsg->message == WM_KEYDOWN && pMsg->wParam == 13) 
	{   
		return TRUE;		
	}	
	return CSkinDialog::PreTranslateMessage(pMsg);
}

CString CMtoUDlg::GetFindingDir()
{
	CString strTemp;
	GetDlgItem(IDC_STATIC_CURDIR)->GetWindowText(strTemp);
	return strTemp;
}

CString CMtoUDlg::GetFileName()
{
	CString strTemp;
	GetDlgItem(IDC_EDIT_FILENAME)->GetWindowText(strTemp);
	return strTemp;
}

HBRUSH CMtoUDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) 
{
	HBRUSH hbr = CSkinDialog::OnCtlColor(pDC, pWnd, nCtlColor);

	if(nCtlColor == CTLCOLOR_STATIC)
	{
		pDC->SetTextColor(RGB(0,0,0));
		pDC->SetBkMode(TRANSPARENT);
		hbr = (HBRUSH)GetStockObject(NULL_BRUSH);
	}
	
	// TODO: Return a different brush if the default is not desired
	return hbr;
}

⌨️ 快捷键说明

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