c#在Top Most窗口顶部运行批处理文件

时间:2016-11-28 08:30:35

标签: c# batch-file topmost

我知道这个问题已被问过几次,但我仍然无法使其发挥作用。

我有一个最顶层的全屏幕窗口,点击按钮需要运行包含大量命令的批处理文件,其中一些命令打开用户交互窗口。

作为首发,只是为了检查我是否正确,我尝试使用call notepad命令运行批处理文件。
我的目标是记事本将位于我的来电窗口之上。

现在这主要是试错,所以请原谅我的奇怪代码。

声明和争议:

[DllImport("user32.dll")]
static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int X, int Y, int cx, int cy, uint uFlags);
[DllImport("user32.dll")]
private static extern bool SetForegroundWindow(IntPtr hWnd);
[DllImport("user32.dll")]
static extern IntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent);

static readonly IntPtr HWND_TOPMOST = new IntPtr(-1);
const UInt32 SWP_NOSIZE = 0x0001;
const UInt32 SWP_NOMOVE = 0x0002;
const UInt32 SWP_SHOWWINDOW = 0x0040;

执行:

static void ExecuteCommand(string command)
{
    Process process = new Process();
    process = Process.Start("c:\\TestFolder\\runNotepad.bat");

    SetForegroundWindow(process.MainWindowHandle);
    SetWindowPos(process.MainWindowHandle, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW);
    SetParent(process.MainWindowHandle, Process.GetCurrentProcess().MainWindowHandle);
}   

runNotepad.bat:

call notepad

我查看过的链接:

谢谢!

0 个答案:

没有答案