windows mobile c++ 浏览文件方法

最近转做mobile 下的开发,PC里浏览文件夹我们一般用MFC的CFildDialog类来实现,或者调用SHBrowseForFolder() 也可以,可是在mobile 里CFildDialog 和 SHBrowseForFolder  都没办法用,不会叫我写个文件浏览的树吧,好麻烦 SHBrowseForFolder 是支持win32 wince 但不支持 WM ,无奈只好继续找,找了许久终于在英文网站上找到一个帖子 说可以用GetOpenFileName() 来代替.msdn 里也有这个方法的例子.

Code Example
The following code example demonstrates how to use GetOpenFileNameEx.
Note To make the following code example easier to read, security checking and error handling are not included. This code example should not be used in a release configuration unless it has been modified to include them.
BOOL UseFilePicker(HWND hwndOwner)
{
  TCHAR szFile[MAX_PATH];
  OPENFILENAMEEX ofnex = {0};

  ofnex.lStructSize = sizeof(ofnex);
  ofnex.hwndOwner = hwndOwner;
  ofnex.lpstrFile = szFile;
  ofnex.nMaxFile = sizeof(szFile)/sizeof(szFile[0]);
  ofnex.lpstrFilter = TEXT("All Files (*.*)/0*.*/0");
  ofnex.lpstrTitle = TEXT("Thumbnail View");

  // Show thumbnails of files that are not DRM protected
  ofnex.ExFlags = OFN_EXFLAG_THUMBNAILVIEW | OFN_EXFLAG_HIDEDRMPROTECTED;
  ofnex.lpstrInitialDir = NULL;

  return GetOpenFileNameEx(&ofnex);
}


Code Example
The following code example displays a dialog in which the user may select only files of type *.BMP. The function returns TRUE if the user selects a file, and the buffer is set to the full path and name of the selected file. If the function returns FALSE, the contents of the buffer are undefined.
Note To make the following code example easier to read, security checking and error handling are not included. This code example should not be used in a release configuration unless it has been modified to include them.
BOOL SelectBMP(LPTSTR pszFilename, DWORD cchBufSize)
{
  ASSERT(pszFilename);
  OPENFILENAMEEX ofn = {0};

  ofn.lStructSize = sizeof(ofn);
  ofn.lpstrFilter = _T("BMP Files (*.bmp)/0*.bmp/0");
  ofn.lpstrFile = pszFilename;
  ofn.nMaxFile = cchBufSize;
  ofn.lpstrInitialDir = _T("//Program Files//MyApp");
  ofn.lpstrTitle = _T("Select a bitmap");
  ofn.ExFlags = OFN_EXFLAG_THUMBNAILVIEW;

  return GetOpenFileNameEx(&ofn));
}

==================


void CBrowseFileDlg::OnBnClickedBrowse()
{
 // TODO: 在此添加控件通知处理程序代码
 OPENFILENAMEEX ofn = {0};
 TCHAR szFile[MAX_PATH];

 ofn.lStructSize = sizeof(ofn);
 ofn.lpstrFilter = _T("BMP Files (*.bmp)/0*.bmp/0");
 ofn.lpstrFile = szFile;
 ofn.nMaxFile = sizeof(szFile)/sizeof(szFile[0]);
 ofn.lpstrInitialDir = _T("//Program Files"); // 这里可以指定打开的默认目录
 ofn.lpstrTitle = _T("Select a bitmap");
 ofn.ExFlags = OFN_EXFLAG_THUMBNAILVIEW | OFN_EXFLAG_HIDEDRMPROTECTED;
  GetOpenFileNameEx(&ofn);

  CString strFileName = ofn.lpstrFile;
  MessageBox(strFileName,L"选择的文件");
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值