怎么在已经写好的mfc程序中增加一个按钮功能?
1个回答
展开全部
在Test.cpp中添加如下代码:
[cpp] view plain copy print?
CString CTestDlg::brow(LPCTSTR filter)
{
OPENFILENAME ofn;
TCHAR szFilename[512]=_T("");
ZeroMemory(&ofn, sizeof(OPENFILENAME));
ofn.lStructSize = sizeof(OPENFILENAME);
ofn.hwndOwner = ::AfxGetMainWnd()->m_hWnd;
ofn.lpstrFile = szFilename;
ofn.nMaxFile = sizeof(szFilename);
ofn.lpstrFilter = filter ;
ofn.nFilterIndex = 1;
ofn.lpstrFileTitle = NULL;
ofn.nMaxFileTitle = 0;
ofn.lpstrInitialDir = NULL;
ofn.lpstrDefExt=NULL;
ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
GetOpenFileName(&ofn);
if(lstrlen(ofn.lpstrFile)>0)
{
return ofn.lpstrFile;
}
return _T("");
}
[cpp] view plain copy print?
void CTestDlg::OnClickedButton1()
{
// TODO: 在此添加控件通知处理程序代码
UpdateData(TRUE);
m_File=brow(_T("所有文件(*.*)|*.*\0\0"));
UpdateData(false);
}
[cpp] view plain copy print?
在TestDlg.h添加如下代码:
[cpp] view plain copy print?
CString brow(LPCTSTR filter) ;
[cpp] view plain copy print?
CString CTestDlg::brow(LPCTSTR filter)
{
OPENFILENAME ofn;
TCHAR szFilename[512]=_T("");
ZeroMemory(&ofn, sizeof(OPENFILENAME));
ofn.lStructSize = sizeof(OPENFILENAME);
ofn.hwndOwner = ::AfxGetMainWnd()->m_hWnd;
ofn.lpstrFile = szFilename;
ofn.nMaxFile = sizeof(szFilename);
ofn.lpstrFilter = filter ;
ofn.nFilterIndex = 1;
ofn.lpstrFileTitle = NULL;
ofn.nMaxFileTitle = 0;
ofn.lpstrInitialDir = NULL;
ofn.lpstrDefExt=NULL;
ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
GetOpenFileName(&ofn);
if(lstrlen(ofn.lpstrFile)>0)
{
return ofn.lpstrFile;
}
return _T("");
}
[cpp] view plain copy print?
void CTestDlg::OnClickedButton1()
{
// TODO: 在此添加控件通知处理程序代码
UpdateData(TRUE);
m_File=brow(_T("所有文件(*.*)|*.*\0\0"));
UpdateData(false);
}
[cpp] view plain copy print?
在TestDlg.h添加如下代码:
[cpp] view plain copy print?
CString brow(LPCTSTR filter) ;
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询