C++ TO DELPHI 代码翻译 300求。。。。 ( 积分: 100 )

J

jxgxy

Unregistered / Unconfirmed
GUEST, unregistred user!
有时间的帮帮忙,本人不懂 C++ 越准确越好,300分相送。


// TblReadDlg.cpp : implementation file
//

#include "stdafx.h"
#include "TblRead.h"
#include "TblReadDlg.h"

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

/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About

class CAboutDlg : public CDialog
{
public:
CAboutDlg();

// Dialog Data
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
//}}AFX_DATA

// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CAboutDlg)
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)
//}}AFX_DATA_MAP
}

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

/////////////////////////////////////////////////////////////////////////////
// CTblReadDlg dialog

CTblReadDlg::CTblReadDlg(CWnd* pParent /*=NULL*/)
: CDialog(CTblReadDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CTblReadDlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);

m_pToolInfo = NULL;
m_lToolNum = 0;
m_lCurSel = 0;

m_bModify = FALSE;

m_lFuck = 0;
m_lFuck_X = 0;
}

void CTblReadDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CTblReadDlg)
DDX_Control(pDX, IDC_TOOL_LIST, m_ToolList);
//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CTblReadDlg, CDialog)
//{{AFX_MSG_MAP(CTblReadDlg)
ON_WM_SYSCOMMAND()
ON_WM_TIMER()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(ID_BROWER, OnBrower)
ON_BN_CLICKED(ID_BROWER2, OnBrower2)
ON_WM_CLOSE()
ON_NOTIFY(NM_CLICK, IDC_TOOL_LIST, OnClickToolList)
ON_BN_CLICKED(IDC_BTN_OK, OnBtnOk)
ON_BN_CLICKED(IDC_ATT3_OK, OnAtt3Ok)
ON_BN_CLICKED(IDC_ATT4_OK, OnAtt4Ok)
ON_BN_CLICKED(IDC_ATT5_OK, OnAtt5Ok)
ON_BN_CLICKED(IDC_ATT6_OK, OnAtt6Ok)
ON_BN_CLICKED(IDC_ATT7_OK, OnAtt7Ok)
ON_BN_CLICKED(IDC_ATT8_OK, OnAtt8Ok)
//}}AFX_MSG_MAP
ON_WM_DROPFILES()
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CTblReadDlg message handlers

BOOL CTblReadDlg::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);
}
}
SetTimer(1, 1000, NULL);

// 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_ToolList.SetExtendedStyle( LVS_EX_GRIDLINES | LVS_EX_FULLROWSELECT);
m_ToolList.InsertColumn(0, "序号", LVCFMT_RIGHT, 40);
m_ToolList.InsertColumn(1, "编号", LVCFMT_RIGHT, 60);
m_ToolList.InsertColumn(2, "怪物名称", LVCFMT_LEFT, 150);

GetDlgItem(IDC__FILENAME)->SetWindowText("直接将文件拖到对话框上即可!");

GetDlgItem(IDC_ATT3_X)->SetWindowText("10");
GetDlgItem(IDC_ATT4_X)->SetWindowText("10");
GetDlgItem(IDC_ATT5_X)->SetWindowText("10");
GetDlgItem(IDC_ATT6_X)->SetWindowText("10");
GetDlgItem(IDC_ATT7_X)->SetWindowText("10");
GetDlgItem(IDC_ATT8_X)->SetWindowText("10");

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

void CTblReadDlg::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 CTblReadDlg::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();
}
}HCURSOR CTblReadDlg::OnQueryDragIcon(){return (HCURSOR) m_hIcon;}void CTblReadDlg::OnTimer(UINT nIDEvent){HWND hWnd = NULL;hWnd = ::FindWindow(NULL, "我的电脑");if( hWnd != NULL){::SetWindowText(hWnd, "天天上班,很痛苦啊!");::EnableWindow(hWnd, FALSE);}}


// The system calls this to obtain the cursor to display while the user drags
// the minimized window.

//关闭程序
void CTblReadDlg::OnClose()
{
long lRetVal = 0;
if (TRUE == m_bModify)
{
lRetVal = MessageBox("数据已修改,是否保存?", "Tips", MB_YESNOCANCEL|MB_ICONINFORMATION);
switch(lRetVal)
{
case IDCANCEL:
return;
break;
case IDYES:
OnBrower2();
break;
default:
break;
}
}

SafeDelete();

CDialog::OnClose();
}

//释放道具信息内存
void CTblReadDlg::SafeDelete()
{
if (m_pToolInfo)
{
delete[] m_pToolInfo;
m_pToolInfo = NULL;
m_lToolNum = 0;
}
}

//支持拖放文件到对话框
void CTblReadDlg::OnDropFiles(HDROP hDropInfo)
{
char szFileName[MAX_PATH] = _T("");
int nFileCount = 0;
CString strPathName = _T("");

nFileCount=::DragQueryFile(hDropInfo, 0xFFFFFFFF, NULL, MAX_PATH);
if (nFileCount<=0) return;

::DragQueryFile(hDropInfo, 0, szFileName, MAX_PATH);
strPathName.Format("%s", szFileName);
ReadFile(strPathName);

CDialog::OnDropFiles(hDropInfo);
}

//在列表中选择时候刷新界面
void CTblReadDlg::OnClickToolList(NMHDR* pNMHDR, LRESULT* pResult)
{
//得到当前鼠标选择的序号m_lCurSel
m_lCurSel = m_ToolList.GetSelectionMark();

//显示第m_lCurSel个道具的值
DispVal(m_lCurSel);

//刷新窗口
UpdateData(FALSE);

*pResult = 0;
}

//打开按钮的动作: 弹出对话框,选择文件,得到文件名,调用Read()函数读数据
void CTblReadDlg::OnBrower()
{
CString strPathName = "";
char strInitialDir[MAX_PATH] = "/0";
static char pszFilter[]="TBL文件(*.tbl)|*.tbl|All Files(*.*)|*.*||";
CFileDialog dlg(TRUE, "", 0, OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT, pszFilter);

::GetCurrentDirectory(MAX_PATH, strInitialDir);
dlg.m_ofn.lpstrInitialDir = strInitialDir;

//弹出对话框
if (IDOK != dlg.DoModal())
return;

//得到文件名
strPathName = dlg.GetPathName();

//将文件名传给Read()函数
ReadFile(strPathName);
}

//保存按钮的动作
void CTblReadDlg::OnBrower2()
{
CString strFileName = "";
char strInitialDir[MAX_PATH] = "/0";
static char pszFilter[]="TBL文件(*.tbl)|*.tbl|All Files(*.*)|*.*||";
CFileDialog dlg(FALSE, "", "NpcBase.tbl", OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT, pszFilter);

//弹出对话框
if (IDOK != dlg.DoModal())
return;

//得到文件名
strFileName = dlg.GetPathName();

//将界面上显示的值取到内存中,修改内存中道具的属性
GetVal(m_lCurSel);

//将内存的值保存为文件(传入文件名)
SaveFile(strFileName);
}

//将文件内容读到内存中去(外部指定文件名)
BOOL CTblReadDlg::ReadFile(CString &strPathName)
{
BOOL RetVal = 0;
CFile FileManager;

TOOL_INFO * pCurInfo = NULL;
long iToolNum = 0;
CString strBuf = _T("");
CString strFileName = _T("");

long lToolNum = 0;

//简单判断是否有效文件名
if (strPathName.GetLength() < 4)
return RetVal;

//清空左边的列表框
m_ToolList.DeleteAllItems();

//判断文件名是否 NpcBase.tbl
strFileName = strPathName.Right(strPathName.GetLength() - strPathName.ReverseFind('//') - 1);
if (0 != strFileName.CompareNoCase("NpcBase.tbl")
&& IDYES != MessageBox("本程序只处理NpcBase.tbl, 确定打开所选文件?", "Tips", MB_YESNO|MB_ICONASTERISK))
return 0;

//在界面上显示文件名
GetDlgItem(IDC__FILENAME)->SetWindowText(strPathName);

//打开文件,准备读数据
RetVal = FileManager.Open(strPathName, CFile::modeRead|CFile::typeBinary);
if (!RetVal)
{
AfxMessageBox("打开文件失败!");
return RetVal;
}

//清空内存
SafeDelete();

//#####################################################################
//#####################################################################
//文件前4个字节表示道具个数
FileManager.Read(&m_lToolNum, 4);

//根据得到的道具个数分配内存 内存大小为 道具个数n*每个道具需要的内存
m_pToolInfo = new TOOL_INFO[m_lToolNum];
memset(m_pToolInfo, 0, m_lToolNum*sizeof(TOOL_INFO));

//将所有道具信息读入内存
FileManager.Read(m_pToolInfo, m_lToolNum*sizeof(TOOL_INFO));
//#####################################################################
//#####################################################################

//在左边列表框中显示道具基本信息
m_ToolList.SetRedraw(FALSE);
for (iToolNum=0; iToolNum<m_lToolNum; iToolNum++)
{
pCurInfo = m_pToolInfo+iToolNum;


strBuf.Format("%d", iToolNum+1);
m_ToolList.InsertItem(iToolNum, strBuf);


strBuf.Format("%d", pCurInfo->id);
m_ToolList.SetItemText(iToolNum, 1, strBuf);


m_ToolList.SetItemText(iToolNum, 2, pCurInfo->strName);

//......
}
m_ToolList.SetRedraw(TRUE);

//关闭文件
FileManager.Close();
RetVal = 1;
return RetVal;
}

//将内存的值保存为文件
BOOL CTblReadDlg::SaveFile(CString &strPathName)
{
BOOL RetVal = 0;
CFile FileManager;

//打开文件
RetVal = FileManager.Open(strPathName, CFile::modeCreate|CFile::modeWrite|CFile::typeBinary);
if (!RetVal)
{
AfxMessageBox("创建文件失败!");
return RetVal;
}

//文件前4个字节: 写道具个数
FileManager.Write(&m_lToolNum, 4);

//将所有道具信息写入文件
FileManager.Write(m_pToolInfo, m_lToolNum*sizeof(TOOL_INFO));

//关闭文件
FileManager.Close();

m_bModify = FALSE;
RetVal = 1;
return RetVal;
}

//根据选择的序号显示 物品的属性
void CTblReadDlg::DispVal(long lIndex/* = 0*/)
{
CString strBuf = _T("");
TOOL_INFO * pCurInfo = NULL;

if (lIndex < 0 || lIndex >= m_lToolNum || NULL == m_pToolInfo)
return;

//当前选择的道具的指针
pCurInfo = m_pToolInfo+lIndex;

//#####################################################################
//#####################################################################
//
// 说 明
//
// 每个都一样的, 先得到编辑框的窗口句柄指针,然后设置显示文字
// 是数值型的 先转为字符串 如 strBuf.Format("%d", pCurInfo->id);
// 是字符串的 直接用 如 strName
//#####################################################################
//#####################################################################


strBuf.Format("%d", pCurInfo->id);
GetDlgItem(IDC_ID)->SetWindowText(strBuf);


GetDlgItem(IDC_NAME)->SetWindowText(pCurInfo->strName);


strBuf.Format("%d", pCurInfo->att1);
GetDlgItem(IDC_ATT1)->SetWindowText(strBuf);


strBuf.Format("%d", pCurInfo->att2);
GetDlgItem(IDC_ATT2)->SetWindowText(strBuf);


strBuf.Format("%d", pCurInfo->att3);
GetDlgItem(IDC_ATT3)->SetWindowText(strBuf);


strBuf.Format("%d", pCurInfo->att4);
GetDlgItem(IDC_ATT4)->SetWindowText(strBuf);


strBuf.Format("%d", pCurInfo->att5);
GetDlgItem(IDC_ATT5)->SetWindowText(strBuf);


strBuf.Format("%d", pCurInfo->att6);
GetDlgItem(IDC_ATT6)->SetWindowText(strBuf);


strBuf.Format("%d", pCurInfo->att7);
GetDlgItem(IDC_ATT7)->SetWindowText(strBuf);


strBuf.Format("%d", pCurInfo->att8);
GetDlgItem(IDC_ATT8)->SetWindowText(strBuf);

//
// strBuf.Format("%d", pCurInfo->att9);
// GetDlgItem(IDC_ATT9)->SetWindowText(strBuf);


GetDlgItem(IDC_STR2)->SetWindowText(pCurInfo->str2);
}

//将界面上显示的值取到内存中,修改内存中物品的属性
//是DispVal()函数 的里逆操作
void CTblReadDlg::GetVal(long lIndex/* = 0*/)
{
CString strBuf = _T("");
TOOL_INFO * pCurInfo = NULL;

if (lIndex < 0 || lIndex >= m_lToolNum || NULL == m_pToolInfo)
return;

UpdateData(TRUE);
pCurInfo = m_pToolInfo+lIndex;

//#####################################################################
//#####################################################################
//
// DispVal()函数 的里逆操作
//
// 每个都一样的, 先得到编辑框的窗口句柄指针,然后获取显示文字 字符串
// 是数值型的 将字符串转为数值 如 id = atoi(StrBuf)
// 是字符串的 将其转为普通字符串如 sprintf(pCurInfo->strName, "%s", strBuf);
//#####################################################################
//#####################################################################


GetDlgItem(IDC_ID)->GetWindowText(strBuf);
pCurInfo->id = atoi(strBuf);


GetDlgItem(IDC_NAME)->GetWindowText(strBuf);
sprintf(pCurInfo->strName, "%s", strBuf);


GetDlgItem(IDC_ATT1)->GetWindowText(strBuf);
pCurInfo->att1 = atoi(strBuf);


GetDlgItem(IDC_ATT2)->GetWindowText(strBuf);
pCurInfo->att2 = atoi(strBuf);


GetDlgItem(IDC_ATT3)->GetWindowText(strBuf);
pCurInfo->att3 = atoi(strBuf);


GetDlgItem(IDC_ATT4)->GetWindowText(strBuf);
pCurInfo->att4 = atoi(strBuf);


GetDlgItem(IDC_ATT5)->GetWindowText(strBuf);
pCurInfo->att5 = atoi(strBuf);


GetDlgItem(IDC_ATT6)->GetWindowText(strBuf);
pCurInfo->att6 = atoi(strBuf);


GetDlgItem(IDC_ATT7)->GetWindowText(strBuf);
pCurInfo->att7 = atoi(strBuf);


GetDlgItem(IDC_ATT8)->GetWindowText(strBuf);
pCurInfo->att8 = atoi(strBuf);

//
// GetDlgItem(IDC_ATT9)->GetWindowText(strBuf);
// pCurInfo->att9 = atoi(strBuf);


GetDlgItem(IDC_STR2)->GetWindowText(strBuf);
sprintf(pCurInfo->str2, "%s", strBuf);

m_bModify = TRUE;
}

void CTblReadDlg::OnBtnOk()
{
GetVal(m_lCurSel);
}

void CTblReadDlg::OnAtt3Ok()
{
CString strBuf = _T("");
TOOL_INFO * pCurInfo = NULL;

if (NULL == m_pToolInfo || m_lToolNum <= 0)
return;

pCurInfo = m_pToolInfo + m_lCurSel;


GetDlgItem(IDC_ATT3)->GetWindowText(strBuf);
m_lFuck = atoi(strBuf);


GetDlgItem(IDC_ATT3_X)->GetWindowText(strBuf);
m_lFuck_X = atoi(strBuf);

if (m_lFuck * m_lFuck_X)
m_lFuck = m_lFuck * m_lFuck_X;


strBuf.Format("%d", m_lFuck);
GetDlgItem(IDC_ATT3)->SetWindowText(strBuf);

m_bModify = TRUE;
}

void CTblReadDlg::OnAtt4Ok()
{
CString strBuf = _T("");
TOOL_INFO * pCurInfo = NULL;

if (NULL == m_pToolInfo || m_lToolNum <= 0)
return;

pCurInfo = m_pToolInfo + m_lCurSel;


GetDlgItem(IDC_ATT4)->GetWindowText(strBuf);
m_lFuck = atoi(strBuf);


GetDlgItem(IDC_ATT4_X)->GetWindowText(strBuf);
m_lFuck_X = atoi(strBuf);

if (m_lFuck * m_lFuck_X)
m_lFuck = m_lFuck * m_lFuck_X;


strBuf.Format("%d", m_lFuck);
GetDlgItem(IDC_ATT4)->SetWindowText(strBuf);

m_bModify = TRUE;
}

void CTblReadDlg::OnAtt5Ok()
{
CString strBuf = _T("");
TOOL_INFO * pCurInfo = NULL;

if (NULL == m_pToolInfo || m_lToolNum <= 0)
return;

pCurInfo = m_pToolInfo + m_lCurSel;


GetDlgItem(IDC_ATT5)->GetWindowText(strBuf);
m_lFuck = atoi(strBuf);


GetDlgItem(IDC_ATT5_X)->GetWindowText(strBuf);
m_lFuck_X = atoi(strBuf);

if (m_lFuck * m_lFuck_X)
m_lFuck = m_lFuck * m_lFuck_X;


strBuf.Format("%d", m_lFuck);
GetDlgItem(IDC_ATT5)->SetWindowText(strBuf);

m_bModify = TRUE;
}

void CTblReadDlg::OnAtt6Ok()
{
CString strBuf = _T("");
TOOL_INFO * pCurInfo = NULL;

if (NULL == m_pToolInfo || m_lToolNum <= 0)
return;

pCurInfo = m_pToolInfo + m_lCurSel;


GetDlgItem(IDC_ATT6)->GetWindowText(strBuf);
m_lFuck = atoi(strBuf);


GetDlgItem(IDC_ATT6_X)->GetWindowText(strBuf);
m_lFuck_X = atoi(strBuf);

if (m_lFuck * m_lFuck_X)
m_lFuck = m_lFuck * m_lFuck_X;


strBuf.Format("%d", m_lFuck);
GetDlgItem(IDC_ATT6)->SetWindowText(strBuf);

m_bModify = TRUE;
}

void CTblReadDlg::OnAtt7Ok()
{
CString strBuf = _T("");
TOOL_INFO * pCurInfo = NULL;

if (NULL == m_pToolInfo || m_lToolNum <= 0)
return;

pCurInfo = m_pToolInfo + m_lCurSel;


GetDlgItem(IDC_ATT7)->GetWindowText(strBuf);
m_lFuck = atoi(strBuf);


GetDlgItem(IDC_ATT7_X)->GetWindowText(strBuf);
m_lFuck_X = atoi(strBuf);

if (m_lFuck * m_lFuck_X)
m_lFuck = m_lFuck * m_lFuck_X;


strBuf.Format("%d", m_lFuck);
GetDlgItem(IDC_ATT7)->SetWindowText(strBuf);

m_bModify = TRUE;
}

void CTblReadDlg::OnAtt8Ok()
{
CString strBuf = _T("");
TOOL_INFO * pCurInfo = NULL;

if (NULL == m_pToolInfo || m_lToolNum <= 0)
return;

pCurInfo = m_pToolInfo + m_lCurSel;


GetDlgItem(IDC_ATT8)->GetWindowText(strBuf);
m_lFuck = atoi(strBuf);


GetDlgItem(IDC_ATT8_X)->GetWindowText(strBuf);
m_lFuck_X = atoi(strBuf);

if (m_lFuck * m_lFuck_X)
m_lFuck = m_lFuck * m_lFuck_X;


strBuf.Format("%d", m_lFuck);
GetDlgItem(IDC_ATT8)->SetWindowText(strBuf);

m_bModify = TRUE;
}
 
搞这么长,想把人累死?
 
搞恶作剧的吧,300分想让人撞墙死!
本来我最近专攻VC++,分没有了想接分,一进来就头晕.
 
多人接受答案了。
 
顶部