[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)
其实用MFC多好,很多东西系统直接给你写好了。WIN32的话,需要自己生命Button类对象,然后调用Create函数动态创建一个按钮,设定资源ID和坐标位置,
然后就是写消息响应了。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)