ShellExecute()打开本地htm问题

Alaska_Lee 2013-01-15 11:22:18
我想在窗体程序中,点击一个item用浏览器打开一个本地的index.htm文件。
看了ShellExecute方法,但是点击了却没有反应。我把ipFile换成一个网址,浏览器就能正确打开。且index.htm在正确的地方。
该引用的头文件和lib都已经连接了。
部分源代码如下:请大牛指点指点,本人不胜感谢!

private: System::Void readMeStripMenuItem_Click(System::Object^ sender, System::EventArgs^ e) {
String^ readmefile = Directory::GetCurrentDirectory() + "//index.htm";
ShellExecute(NULL, NULL, (LPCTSTR)(void*)Marshal::StringToHGlobalAnsi(readmefile), NULL, NULL, SW_SHOWNORMAL);
//ShellExecute((HWND)(this->Handle.ToInt32()), NULL,_T("http://www.csdn.net"), NULL,NULL, SW_SHOWNORMAL);
}
...全文
253 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
threenewbee 2013-01-16
  • 打赏
  • 举报
回复
引用 2 楼 lijie19871108 的回复:
文件名不应该是这样么? String^ readmefile = Directory::GetCurrentDirectory() + "//index.htm";
换成\\
Alaska_Lee 2013-01-16
  • 打赏
  • 举报
回复
文件名不应该是这样么? String^ readmefile = Directory::GetCurrentDirectory() + "//index.htm";
threenewbee 2013-01-16
  • 打赏
  • 举报
回复
HINSTANCE ShellExecute( _In_opt_ HWND hwnd, 窗口句柄,没有的话传0 _In_opt_ LPCTSTR lpOperation, 传 "open" _In_ LPCTSTR lpFile, 文件名 _In_opt_ LPCTSTR lpParameters, 可以忽略 _In_opt_ LPCTSTR lpDirectory, 可以忽略 _In_ INT nShowCmd SW_SHOW );
Alaska_Lee 2013-01-16
  • 打赏
  • 举报
回复
引用 3 楼 caozhy 的回复:
引用 2 楼 lijie19871108 的回复:文件名不应该是这样么? String^ readmefile = Directory::GetCurrentDirectory() + "//index.htm"; 换成\\
把方法换成这个就行:Marshal::StringToHGlobalAuto。 并且\\和//都是可以的,已证实!
真相重于对错 2013-01-16
  • 打赏
  • 举报
回复
Marshal::StringToHGlobalAuto

7,540

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 VC.NET
社区管理员
  • VC.NET社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧