📄 fileopendlg.cpp
字号:
// FileopenDlg.cpp : implementation file
//
#include "stdafx.h"
#include "testd.h"
#include "FileopenDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CFileopenDlg dialog
CFileopenDlg::CFileopenDlg(CWnd* pParent /*=NULL*/)
: CDialog(CFileopenDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CFileopenDlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
recta=CRect(40,90,180,268);
}
void CFileopenDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CFileopenDlg)
DDX_Control(pDX, IDC_FILE, m_file);
DDX_Control(pDX, IDC_DRIVE, m_drive);
DDX_Control(pDX, IDC_DIRECTOR, m_director);
DDX_Control(pDX, IDC_FILELIST, m_list);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CFileopenDlg, CDialog)
//{{AFX_MSG_MAP(CFileopenDlg)
ON_WM_ERASEBKGND()
ON_CBN_SELCHANGE(IDC_COMBOBOX, OnSelchangeCombodir)
ON_NOTIFY(NM_DBLCLK, IDC_DIRTREE, OnDblclkTreedir)
ON_WM_CTLCOLOR()
ON_LBN_SELCHANGE(IDC_FILELIST, OnSelchangeFilelist)
ON_WM_DESTROY()
ON_WM_PAINT()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CFileopenDlg message handlers
BOOL CFileopenDlg::OnEraseBkgnd(CDC *dc)
{
return true;
}
BOOL CFileopenDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
rgna.CreateRoundRectRgn(5,5,358,360,30,30);
rgnb.CreateRoundRectRgn(15,15,365,365,30,30);
rgnc.CreateRoundRectRgn(5,5,500,315,30,30);
rgnc.CombineRgn(&rgnb,&rgna,RGN_OR);
SetWindowRgn(rgnc,TRUE);
drivebox.Create(WS_CHILD|WS_VISIBLE|CBS_DROPDOWNLIST|CBS_OWNERDRAWFIXED|CBS_HASSTRINGS,
CRect(40,40,180,200),this,IDC_COMBOBOX);
AddDrive();
dirtree.Create(WS_CHILD|WS_VISIBLE|TVS_HASLINES|TVS_LINESATROOT|TVS_HASBUTTONS,
recta,this,IDC_DIRTREE);
dirtree.SetBkColor(RGB(232,215,136));
bntok.Create("确定",WS_CHILD|WS_VISIBLE|BS_OWNERDRAW,
CRect(100,300,165,325),this,IDOK);
bntcancel.Create("退出",WS_CHILD|WS_VISIBLE|BS_OWNERDRAW,
CRect(185,300,250,325),this,IDCANCEL);
CFile file("c:\\windows\\key.dat",CFile::modeRead);
CArchive ar(&file,CArchive::load);
doc.Serialize(ar);
defpath=doc.path;
CString k;
int sel;
for(int j=1,s='c';s<'i';s++,j++)
{
k=defpath.Left(1);
k.MakeLower();
if(!k.Compare(CString(s)))
sel=j;
}
drivebox.SetCurSel(sel);
HICON icon=::ExtractIcon( AfxGetApp()->m_hInstance, "shell32.dll", 15);
int index=drivebox.GetCurSel();
dirtree.SetdriveBoot(icon,k+":\\");
dirtree.SetPath("e:\\file\\diary\\");
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CFileopenDlg::OnDblclkTreedir(NMHDR* pNMHDR, LRESULT* pResult)
{
// TODO: Add your control notification handler code here
HTREEITEM item;
CString temp;
m_list.ResetContent();
item=dirtree.GetSelectedItem();
path=dirtree.GetItemText(item);
item=dirtree.GetParentItem(item);
while (item)
{
temp=dirtree.GetItemText(item);
if(temp.Right(1)!="\\")
temp+="\\";
path=temp+path;
item=dirtree.GetParentItem(item);
}
if(path.Right(1)!="\\")
path+="\\";
CFileFind find;
temp=path+"*.*";
BOOL key=find.FindFile(temp);
while(key)
{
key=find.FindNextFile();
if(!find.IsDirectory())
{
CString filename=find.GetFileName();
CString filetitle=find.GetFileTitle();
int l1=filename.GetLength();
int l2=filetitle.GetLength();
int l3=l1-l2-1;
if(filename.Right(l3)=="dia")
m_list.AddString(find.GetFileName());
}
}
*pResult = 0;
}
void CFileopenDlg::OnSelchangeCombodir()
{
// TODO: Add your control notification handler code here
HICON icon=::ExtractIcon( AfxGetApp()->m_hInstance, "shell32.dll", 15);
int index=drivebox.GetCurSel();
char *dirve[]={"a:\\","c:\\","d:\\","e:\\","f:\\","g:\\","h:\\","l:\\","m:\\","n:\\"};
int count=drivebox.GetCount();
for(int i=0;i<count;i++)
st=dirve[index];
dirtree.SetdriveBoot(icon,st);
}
HBRUSH CFileopenDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
// TODO: Change any attributes of the DC here
if(nCtlColor==CTLCOLOR_LISTBOX)
{
pDC->SetBkColor(RGB(0,255,255));
CBrush br(RGB(0,255,255));
return br;
}
// TODO: Return a different brush if the default is not desired
return hbr;
}
void CFileopenDlg::AddDrive()
{
size_t drives;
CString string;
HICON icona;
_TCHAR *buf;
drives=GetLogicalDriveStrings(0,NULL);
buf=new _TCHAR[drives+sizeof(_T(""))];
GetLogicalDriveStrings(drives,buf);
_TCHAR *pdrives=buf;
size_t drivelen=strlen(pdrives);
DWORD iconsize=SHGFI_SMALLICON;
while(drivelen>0)
{
SHFILEINFO fileinfo;
DWORD r=SHGetFileInfo(pdrives,0,&fileinfo,sizeof(fileinfo),SHGFI_DISPLAYNAME| SHGFI_ICON|iconsize);
if(r)
{
string=fileinfo.szDisplayName;
icona=fileinfo.hIcon;
drivebox.AddItem(icona,string);
}
pdrives+=drivelen+1;
drivelen=strlen(pdrives);
}
}
void CFileopenDlg::OnSelchangeFilelist()
{
// TODO: Add your control notification handler code here
CString filename;
int index=m_list.GetCurSel();
m_list.GetText(index,filename);
getfile=path+filename;
}
void CFileopenDlg::OnDestroy()
{
CDialog::OnDestroy();
// TODO: Add your message handler code here
rgna.DeleteObject();
rgnb.DeleteObject();
rgnc.DeleteObject();
}
void CFileopenDlg::OnPaint()
{
CPaintDC dc(this); // device context for painting
CDC memdc;
CBitmap bitmap;
bitmap.LoadBitmap(IDB_BACKGROUND);
memdc.CreateCompatibleDC(&dc);
CBitmap *def=memdc.SelectObject(&bitmap);
CBrush br(RGB(50,50,50));
CRect rect;
GetClientRect(&rect);
CRgn rgna,rgnb,rgnc;
rgna.CreateRoundRectRgn(8,8,367,365,30,40);
rgnb.CreateRoundRectRgn(0,0,354,354,30,40);
rgnc.CreateRoundRectRgn(0,0,510,410,40,40);
rgnc.CombineRgn(&rgna,&rgnb,RGN_DIFF);
memdc.FillRgn(&rgnc,&br);
CPen p1,p2;
COLORREF b1,b2;
b1=RGB(255,255,255);
b2=RGB(0,0,0);
p1.CreatePen(PS_SOLID,3,b2);
memdc.SelectObject(&p1);
memdc.MoveTo(recta.left,recta.bottom);
memdc.LineTo(recta.left,recta.top);
memdc.LineTo(recta.right,recta.top);
p2.CreatePen(PS_SOLID,2,b1);
CPen *defpen=memdc.SelectObject(&p2);
memdc.MoveTo(recta.right,recta.top);
memdc.LineTo(recta.right,recta.bottom);
memdc.LineTo(recta.left,recta.bottom);
memdc.SelectObject(defpen);
p1.DeleteObject();
p2.DeleteObject();
dc.BitBlt(0,0,rect.Width(),rect.Height(),&memdc,0,0,SRCCOPY);
memdc.SelectObject(def);
bitmap.DeleteObject();
ReleaseDC(&memdc);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -