xx7*_*aBs 3 vb.net windows visual-studio-2012
我有一个只在后台运行的小程序(没有任何窗口).它监控按键,当满足某些要求时,它会打开特定的程序.问题是程序的窗口没有在前台打开 - 它在当前活动窗口后面打开.如何强制它在前台打开?
我正在使用Visual Basic .NET(.NET framework 4.5),这是我目前的代码:
Dim temp As New Process
temp = Process.Start("C:\cygwin\bin\mintty.exe", "-")
temp.WaitForInputIdle(10000)
Run Code Online (Sandbox Code Playgroud)
试试这个(它在C#中):取自这个网站.
internal class Program
{
[DllImport("user32.dll", SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
private static extern bool SetWindowPos(IntPtr hWnd,
int hWndInsertAfter, int x, int y, int cx, int cy, int uFlags);
private const int HWND_TOPMOST = -1;
private const int SWP_NOMOVE = 0x0002;
private const int SWP_NOSIZE = 0x0001;
public static void Main()
{
Process process = Process.Start(@"notepad.exe", "");
if (null != process)
{
SetWindowPos(process.MainWindowHandle, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
}
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1755 次 |
| 最近记录: |