📄 porpsheet.cpp
字号:
// PorpSheet.cpp : implementation file
//
#include "stdafx.h"
#include "Currency_CE.h"
#include "PorpSheet.h"
#include "Currency_CEDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
CString g_sInstallDir;
CStringArray m_SettingArray;
CStringArray m_SettingArray2;
/////////////////////////////////////////////////////////////////////////////
// CPorpSheet
IMPLEMENT_DYNAMIC(CPorpSheet, CPropertySheet)
CPorpSheet::CPorpSheet(UINT nIDCaption, CWnd* pParentWnd, UINT iSelectPage)
:CPropertySheet(nIDCaption, pParentWnd, iSelectPage)
{
AddPage(&m_page1);
AddPage(&m_page2);
AddPage(&m_page3);
m_Dlg=(CCurrency_CEDlg*)pParentWnd;
}
CPorpSheet::CPorpSheet(LPCTSTR pszCaption, CWnd* pParentWnd, UINT iSelectPage)
:CPropertySheet(pszCaption, pParentWnd, iSelectPage)
{
AddPage(&m_page1);
AddPage(&m_page2);
AddPage(&m_page3);
m_Dlg=(CCurrency_CEDlg*)pParentWnd;
}
CPorpSheet::~CPorpSheet()
{
}
BEGIN_MESSAGE_MAP(CPorpSheet, CPropertySheet)
//{{AFX_MSG_MAP(CPorpSheet)
ON_WM_DESTROY()
ON_WM_ACTIVATE()
ON_WM_CHAR()
ON_WM_CLOSE()
ON_WM_CANCELMODE()
ON_WM_ENABLE()
ON_WM_KEYDOWN()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CPorpSheet message handlers
BOOL CPorpSheet::OnInitDialog()
{
BOOL bResult = CPropertySheet::OnInitDialog();
// TODO: Add your specialized code here
CTabCtrl* pTAB=GetTabControl( );
TC_ITEM TabCtrlItem;
TabCtrlItem.mask = TCIF_TEXT;
/*
TabCtrlItem.pszText = _T(" 货币换算 ");
pTAB->SetItem(0,&TabCtrlItem);
TabCtrlItem.pszText = _T(" 更改汇率 ");
pTAB->SetItem(1,&TabCtrlItem);
TabCtrlItem.pszText = _T(" 版本信息 ");
pTAB->SetItem(2,&TabCtrlItem);
*/
TabCtrlItem.pszText = _T(" 换算 ");
pTAB->SetItem(0,&TabCtrlItem);
TabCtrlItem.pszText = _T(" 更改 ");
pTAB->SetItem(1,&TabCtrlItem);
TabCtrlItem.pszText = _T(" 版本 ");
pTAB->SetItem(2,&TabCtrlItem);
InitDocument();
ModifyStyleEx(WS_EX_CAPTIONOKBTN,WS_EX_TOPMOST,SWP_NOMOVE);
return bResult;
}
BOOL CPorpSheet::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Add your specialized code here and/or call the base class
cs.style &= ~WS_EX_CAPTIONOKBTN;
return CPropertySheet::PreCreateWindow(cs);
}
BOOL CPorpSheet::DestroyWindow()
{
// TODO: Add your specialized code here and/or call the base class
m_Dlg->EndDialog(1);
return CPropertySheet::DestroyWindow();
}
BOOL CPorpSheet::PreTranslateMessage(MSG* pMsg)
{
// TODO: Add your specialized code here and/or call the base class
return CPropertySheet::PreTranslateMessage(pMsg);
}
void CPorpSheet::PreSubclassWindow()
{
// TODO: Add your specialized code here and/or call the base class
CPropertySheet::PreSubclassWindow();
}
void CPorpSheet::OnDestroy()
{
CPropertySheet::OnDestroy();
// TODO: Add your message handler code here
m_Dlg->EndDialog(1);
}
void CPorpSheet::OnActivate(UINT nState, CWnd* pWndOther, BOOL bMinimized)
{
CPropertySheet::OnActivate(nState, pWndOther, bMinimized);
// TODO: Add your message handler code here
}
CString CPorpSheet::GetExeDir()
{
CString sInstallDir=_T("");
HINSTANCE h= AfxGetInstanceHandle( );
TCHAR szModuleName[260];
int nPathLength = GetModuleFileName (h, szModuleName,sizeof(szModuleName));
CString s1=_T("");
wsprintf(s1.GetBuffer(260),_T("%s"),szModuleName);
s1.ReleaseBuffer();
if(nPathLength)
{
sInstallDir=s1.Left(s1.ReverseFind('\\'));
}
return sInstallDir;
}
CString CPorpSheet::GetInstallDir()
{
CString pszFileName = _T("InstallDir.dat");
CFile initFile;
HINSTANCE h= AfxGetInstanceHandle( );
TCHAR szModuleName[260];
int nPathLength = GetModuleFileName (h, szModuleName,sizeof(szModuleName));
CString s1="";
wsprintf(s1.GetBuffer(260),_T("%s"),szModuleName);
s1.ReleaseBuffer();
if(nPathLength)
{
CString s=s1.Left(s1.ReverseFind('\\'));
s+="\\InstallDir.dat";
pszFileName=s;
}
CString temp,sInstallDir=_T("");
BYTE *pData;
long lDataLen;
DWORD dwFileLen, dwFileLen1;
HANDLE hFile;
hFile = ::CreateFile(pszFileName,
GENERIC_READ, // we just need read access
FILE_SHARE_READ, // allow read access for others
NULL, // security attributes
OPEN_EXISTING, // the file needs to exist
0, // file attribute
NULL ); // handle to a template file
UINT test=(const unsigned int)hFile;
if (hFile&&test!=0xffffffff)
{
dwFileLen=::GetFileSize(hFile,NULL);
pData = ::new BYTE[dwFileLen+1];
memset(pData,0x20,dwFileLen+1);
if (!pData)
{
AfxMessageBox(_T("Not enough memory to open InstallDir.dat."));
return sInstallDir;
}
//Read the ink data to pData.
ReadFile (hFile, pData, dwFileLen, &dwFileLen1, 0);
pData[dwFileLen]='\0';
sInstallDir=(unsigned short*)pData;
//AfxMessageBox(sInstallDir);
temp=sInstallDir.Left(1);
if(temp==0xFEFF)
sInstallDir=sInstallDir.Right(sInstallDir.GetLength()-1);//s=s.Right(s.GetLength()-1);
CloseHandle(hFile);
}
else
{
AfxMessageBox(_T("Cannot find file:InstallDir.dat,exit application! "));
//SendMessage(WM_CLOSE);
}
return sInstallDir;
}
void CPorpSheet::InitDocument()
{
g_sInstallDir=GetExeDir();
CString s1="";
short pos;
CString s;
s=s1="";
pos=0;
CString s2;
int pos2=0;
CString temp;
TCHAR cc[10];
BYTE *pData;
long lDataLen;
DWORD dwFileLen, dwFileLen1;
HANDLE hFile;
hFile = ::CreateFile(g_sInstallDir+_T("\\Currency.dat\0"),
GENERIC_READ, // we just need read access
FILE_SHARE_READ, // allow read access for others
NULL, // security attributes
OPEN_EXISTING, // the file needs to exist
0, // file attribute
NULL ); // handle to a template file
UINT test=(const unsigned int)hFile;
if (hFile&&test!=0xffffffff)
{
BY_HANDLE_FILE_INFORMATION bhfi;
GetFileInformationByHandle (hFile, &bhfi);
if (bhfi.nFileSizeHigh != 0)
{
AfxMessageBox(_T("File is too big"));
}
dwFileLen= bhfi.nFileSizeLow;
if(dwFileLen==0xffffffff)
{
AfxMessageBox(_T("file length error,exit application! "));
SendMessage(WM_CLOSE);
return;
}
//Allocate object pData
pData = ::new BYTE[dwFileLen];
if (!pData)
{
AfxMessageBox(_T("Not enough memory to open Currency.dat."));
return ;
}
//Read the ink data to pData.
ReadFile (hFile, pData, dwFileLen, &dwFileLen1, 0);
s+=(unsigned short*)pData;
temp=s.Left(1);
if(temp==0xFEFF)
s=s.Right(s.GetLength()-1);
pos=s.Find(_T("\r\n"));
while(pos>0)
{
s1=s.Left(pos);
pos2=s1.Find(_T("="));
if(pos2>0)
{
s2=s1.Right(pos-pos2-1);
s1=s1.Left(pos2);
}
m_SettingArray.Add(s1);
m_SettingArray2.Add(s2);
s=s.Right(s.GetLength()-pos-2);
pos=s.Find(_T("\r\n"));
}
CloseHandle(hFile);
}
else
{
AfxMessageBox(_T("Cannot find file:")+g_sInstallDir+_T("\\Currency.dat")+_T(",exit application! "));
SendMessage(WM_CLOSE);
}
}
BOOL CPorpSheet::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
return CWnd::Create(lpszClassName, lpszWindowName, dwStyle, rect, pParentWnd, nID, pContext);
}
int CPorpSheet::DoModal()
{
return CPropertySheet::DoModal();
}
LRESULT CPorpSheet::DefWindowProc(UINT message, WPARAM wParam, LPARAM lParam)
{
// TODO: Add your specialized code here and/or call the base class
int i=0;
switch(message)
{
case WM_KEYDOWN:
i=1;
}
return CPropertySheet::DefWindowProc(message, wParam, lParam);
}
LRESULT CPorpSheet::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
{
// TODO: Add your specialized code here and/or call the base class
int i=0;
switch(message)
{
case WM_KEYDOWN:
i=1;
case WM_LBUTTONDOWN:
i=2;
default:
i=3;
}
return CPropertySheet::WindowProc(message, wParam, lParam);
}
void CPorpSheet::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
{
// TODO: Add your message handler code here and/or call default
CPropertySheet::OnChar(nChar, nRepCnt, nFlags);
}
void CPorpSheet::OnClose()
{
// TODO: Add your message handler code here and/or call default
CPropertySheet::OnClose();
}
void CPorpSheet::OnCancelMode()
{
CPropertySheet::OnCancelMode();
// TODO: Add your message handler code here
}
void CPorpSheet::OnEnable(BOOL bEnable)
{
CPropertySheet::OnEnable(bEnable);
// TODO: Add your message handler code here
}
void CPorpSheet::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
{
// TODO: Add your message handler code here and/or call default
CPropertySheet::OnKeyDown(nChar, nRepCnt, nFlags);
}
void CPorpSheet::OnOK( )
{
int i=0;
}
void CPorpSheet::OnCancel( )
{
int i=0;
}
BOOL CPorpSheet::OnCmdMsg(UINT nID, int nCode, void* pExtra, AFX_CMDHANDLERINFO* pHandlerInfo)
{
return CPropertySheet::OnCmdMsg(nID, nCode, pExtra, pHandlerInfo);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -