📄 setdlg.cpp
字号:
// SetDlg.cpp : implementation file
//
#include "stdafx.h"
#include "testd.h"
#include "SetDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CSetDlg dialog
CSetDlg::CSetDlg(CWnd* pParent /*=NULL*/)
: CDialog(CSetDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CSetDlg)
m_editkey = _T("");
m_rekey = _T("");
m_path = _T("");
//}}AFX_DATA_INIT
}
void CSetDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CSetDlg)
DDX_Control(pDX, IDC_TEXT1, m_text1);
DDX_Control(pDX, IDC_TEXT, m_text);
DDX_Control(pDX, IDC_REKEY, m_srekey);
DDX_Control(pDX, IDC_KEY, m_key);
DDX_Control(pDX, IDC_CHECK1, m_check);
DDX_Text(pDX, IDC_EDITKEY, m_editkey);
DDX_Text(pDX, IDC_EDITREKEY, m_rekey);
DDX_Text(pDX, IDC_PATH, m_path);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CSetDlg, CDialog)
//{{AFX_MSG_MAP(CSetDlg)
ON_WM_ERASEBKGND()
ON_WM_DESTROY()
ON_WM_CTLCOLOR()
ON_COMMAND(IDC_LIST,OnList)
ON_WM_PAINT()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CSetDlg message handlers
void CSetDlg::OnOK()
{
// TODO: Add extra validation here
bool check;
check=m_check.GetCheck();
if(!strcmp(m_editkey,m_rekey)&&!check)
{
UpdateData();
char * temp;
int len=m_editkey.GetLength();
temp=new char[len];
for(int i=0;i<len;i++)
{
char j=(char)(m_editkey.GetAt(i)+i*5);
temp[i]=j;
}
temp[len]='\0';
doc.key=temp;
doc.path=m_path;
CFile file("c:\\windows\\key.dat",CFile::modeCreate|CFile::modeWrite);
CArchive arstore(&file,CArchive::store);
doc.Serialize(arstore);
arstore.Close();
file.Close();
}
else if(check)
{
CEdit *pathedit=(CEdit *)GetDlgItem(IDC_PATH);
CString pathstring;
pathedit->GetWindowText(pathstring);
doc.path=pathstring;
doc.key=key;
CFile file("c:\\windows\\key.dat",CFile::modeCreate|CFile::modeWrite);
CArchive arstore(&file,CArchive::store);
doc.Serialize(arstore);
arstore.Close();
file.Close();
}
CDialog::OnOK();
}
BOOL CSetDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
//创建不规则窗口
rgna.CreateRoundRectRgn(5,5,258,310,30,30);
rgnb.CreateRoundRectRgn(15,15,265,315,30,30);
rgnc.CreateRoundRectRgn(5,5,500,315,30,30);
rgnc.CombineRgn(&rgnb,&rgna,RGN_OR);
SetWindowRgn(rgnc,TRUE);
btnok.Create("确定",WS_CHILD|WS_VISIBLE|BS_OWNERDRAW,CRect(50,250,115,275),this,IDOK);
btncancel.Create("退出",WS_CHILD|WS_VISIBLE|BS_OWNERDRAW,CRect(145,250,210,275),this,IDCANCEL);
btnlist.Create("浏览",WS_CHILD|WS_VISIBLE|BS_OWNERDRAW,CRect(170,172,235,197),this,IDC_LIST);
//初始化读
CFile file("c:\\windows\\key.dat",CFile::modeRead);
CArchive ar(&file,CArchive::load);
doc.Serialize(ar);
m_path=doc.path;
key=doc.key;
ar.Close();
file.Close();
CEdit *pathedit=(CEdit *)GetDlgItem(IDC_PATH);
CEdit *keyedit=(CEdit *)GetDlgItem(IDC_EDITKEY);
CEdit *rekeyedit=(CEdit *)GetDlgItem(IDC_EDITREKEY);
pathedit->SetWindowText(m_path);
keyedit->SetWindowText("");
rekeyedit->SetWindowText("");
m_check.SetCheck(1);
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
BOOL CSetDlg::OnEraseBkgnd(CDC *dc)
{
return true;
}
void CSetDlg::OnDestroy()
{
CDialog::OnDestroy();
// TODO: Add your message handler code here
rgna.DeleteObject();
rgnb.DeleteObject();
rgnc.DeleteObject();
}
HBRUSH CSetDlg::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_EDIT)
{
pDC->SetBkColor(RGB(0,255,255));
CBrush br(RGB(0,255,255));
hbr=br;
}
// TODO: Return a different brush if the default is not desired
return hbr;
}
void CSetDlg::OnList()
{
BROWSEINFO bi;
char dispname[MAX_PATH], path[MAX_PATH];
ITEMIDLIST * pidl;
bi.hwndOwner = 0;
bi.pidlRoot = 0;
bi.pszDisplayName = dispname;
bi.lpszTitle = "请选择要保存的文件夹";
bi.ulFlags = BIF_RETURNONLYFSDIRS;
bi.lpfn = 0;
bi.lParam = 0;
bi.iImage = 0;
if (pidl = SHBrowseForFolder(&bi))
{
SHGetPathFromIDList(pidl, path);
m_path=path;
if(m_path.Right(1)!="\\")
m_path+="\\";
UpdateData(FALSE);
}
}
void CSetDlg::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,267,315,30,40);
rgnb.CreateRoundRectRgn(0,0,254,304,30,40);
rgnc.CreateRoundRectRgn(0,0,510,310,40,40);
rgnc.CombineRgn(&rgna,&rgnb,RGN_DIFF);
memdc.FillRgn(&rgnc,&br);
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 + -