从C打开Windows文件/文件夹属性对话框 [英] Open windows file/folder properties dialog from C

查看:169
本文介绍了从C打开Windows文件/文件夹属性对话框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个小程序,目的是在指定的 info.lpFile 上显示Windows文件/文件夹属性对话框:

I have this tiny programm, which is intened to show windows file/folder properties dialog on the specified info.lpFile:

#include <windows.h>

main() {
   SHELLEXECUTEINFO info = {0};

   info.cbSize = sizeof(SHELLEXECUTEINFO);
   info.lpFile = "C:\\test.txt";
   info.nShow = SW_SHOW;
   info.fMask = 0x00000000;
   info.lpVerb = "properties";

   ShellExecuteEx(&info);
}

当我编译并执行它时,会收到以下错误消息:

When I compile and execute it, I get the following error message:

我正在使用Win7和Mingw gcc编译器。有人知道我的代码有什么问题吗?我错过了什么吗?

I'm using Win7 and Mingw gcc compiler. Does anybody knows what is wrong with my code? Am I missing something?

推荐答案

所示的所有代码中的第1个未正确初始化 info

1st of all the code as shown does not properly initialise info.

要解决此更改

  SHELLEXECUTEINFO info;

成为

  SHELLEXECUTEINFO info = {0};






第二次使用 SEE_MASK_INVOKEIDLIST 表示 SHELLEXECUTEINFO 的成员 fMask

供您参考: https://msdn.microsoft.com/zh-cn/library/windows/desktop/bb759784%28v=vs.85%29.aspx

请注意,要看到打开的属性窗口,调用代码不得立即结束。因此,添加以下内容

Please note that to see the properties window open, the invoking code must not end immediately. So add something like

  Sleep(10000);

到测试代码的末尾,如图所示。

to the end of your test code as shown.

对我有用的完整代码:

#include <windows.h>

int main(void) 
{
  SHELLEXECUTEINFO info = {0};

  info.cbSize = sizeof info;
  info.lpFile = L"C:\\tmp\\tmp.txt";
  info.nShow = SW_SHOW;
  info.fMask = SEE_MASK_INVOKEIDLIST;
  info.lpVerb = L"properties";

  ShellExecuteEx(&info);

  Sleep(10000);
}

构建选项:

/ZI /nologo /W3 /WX- /Od /Oy- /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_UNICODE" /D "UNICODE" /Gm /EHsc /RTC1 /GS /fp:precise /Zc:wchar_t /Zc:forScope /Fp"Debug\SOxyzConsoleEmpty.pch" /Fa"Debug\" /Fo"Debug\" /Fd"Debug\vc100.pdb" /Gd /TC /analyze- /errorReport:queue 

(测试过VS2010,运行Windows 7)

这篇关于从C打开Windows文件/文件夹属性对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆