1

多くの場合、[スタート] メニューにある [実行] ダイアログ ボックスを呼び出そうとしています - いくつかの調査を行ったところ、アクセスする方法が 1 つしか見つかりませんでした ([Windows キー] + R を使用)。

したがって、キーストロークをシミュレートすると仮定します。

SendKeys.Send("{TEST}") 

仕事をしますか?キーボードの「Windows」キーをどのようにシミュレートできますか?

これを行う簡単な方法があると確信しています-sendkeysを使用せずに-誰かアイデアがありますか?

4

1 に答える 1

1

PInvoke を使用して実行ダイアログを呼び出すことができます。

[Flags()]
public enum RunFileDialogFlags : uint
{

    /// <summary>
    /// Don't use any of the flags (only works alone)
    /// </summary>
    None = 0x0000,    

    /// <summary>
    /// Removes the browse button
    /// </summary>
    NoBrowse = 0x0001,

    /// <summary>
    /// No default item selected
    /// </summary>
    NoDefault = 0x0002,

    /// <summary>
    /// Calculates the working directory from the file name
    /// </summary>
    CalcDirectory = 0x0004,

    /// <summary>
    /// Removes the edit box label
    /// </summary>
    NoLabel = 0x0008,

    /// <summary>
    /// Removes the separate memory space checkbox (Windows NT only)
    /// </summary>
    NoSeperateMemory = 0x0020
}

DllImport 属性を使用して DLL をインポートする必要があります。

[DllImport("shell32.dll", CharSet = CharSet.Auto, EntryPoint = "#61", SetLastError = true)]

static extern bool SHRunFileDialog(IntPtr hwndOwner, 
                                   IntPtr hIcon, 
                                   string lpszPath,
                                   string lpszDialogTitle, 
                                   string lpszDialogTextBody, 
                                   RunFileDialogFlags uflags);

実装:

private void ShowRunDialog(object sender, RoutedEventArgs e)
{
    SHRunFileDialog(IntPtr.Zero, 
                    IntPtr.Zero, 
                    "c:\\",
                    "Run Dialog using PInvoke",
                    "Type the name of a program, folder or internet address 
            and Windows will open that for you.",
                    RunFileDialogFlags.CalcDirectory);

}

于 2012-09-09T11:08:29.760 に答える