0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

ShellExecuteExを使ってファイルのプロパティダイアログを表示する際の注意点。

Last updated at Posted at 2020-01-23

SHELLEXECUTEINFO構造体のlpVerbメンバに"properties"を指定するのですが、
これだけだと、そんな動作はありません、と実行時にエラーがでます。

ShellExecuteExはhInstAppメンバに31をセットしていることから、どうやら、
・「open」句はファイルに関連付けられたアプリケーションで起動、
・「print」句は既定の印刷プログラムを起動、
と同じ意味で、
「properties」句に関連付けられた動作を行おうとし、それが定義されていないからエラーとなった模様。

ここで、fMaskメンバに「SEE_MASK_INVOKEIDLIST」を指定すると、
「properties」句は「プロパティダイアログを開く」ことだと分かってくれるようです。

※エクスプローラの右クリックメニューの「プロパティ」と同じ動作をするよう指定したってこと?
"INVOKE"とか"IDLIST"とかいう言葉がそれを匂わせる。

※ウェブ上には
ShellExecuteExを使ってプロパティダイアログを表示する方法として
「SEE_MASK_INVOKEIDLIST」マスク指定なしのソースを書いている記事がいくつかあったけど、
一体どうやって実現したのか教えて欲しい。

:
;
しかし。
ShellExecuteExであっても、プロパティダイアログは瞬時に表示して閉じてしまう。
プロパティダイアログを永続的に表示しておくには、
ShellExecuteExを実行した後に何らかのpauseをかけておかなくてはならない...

showProperty.cpp
# include <stdio.h>
# include <windows.h>
# include <shellapi.h>

int main(int argc, char** argv)
{
    int ret;
    char buf[1];
    if( argc < 2 ){
        printf("  [×] ファイルを指定してくださぃ\n");
        return -1;
    }

    SHELLEXECUTEINFO sei = {0};
    sei.cbSize = sizeof(SHELLEXECUTEINFO);
    sei.fMask = SEE_MASK_NOCLOSEPROCESS | SEE_MASK_INVOKEIDLIST;
    sei.lpVerb = "properties";
    sei.lpFile = argv[1];
    sei.nShow = SW_SHOWNORMAL;

    if( ShellExecuteEx(&sei) == TRUE ){
        if( (int)sei.hInstApp > 32 ){
            printf("  [〇] ShellExecuteEX succeeded. %d\n", sei.hInstApp);
            ret = 0;
        }
    }
    else{
        printf("  [×] ShellExecuteEX failed. %d\n", sei.hInstApp);
        ret = -2;
    }

    //※入力待ちを作ってこのプロセスを止めておかないとプロパティダイアログが閉じてしまう。
    printf("enter any key...");
    gets_s(buf, 1);

    return ret;
}
0
1
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?