public static void ForceForegroundWindow(IntPtr hWnd) { uint foreThread = GetWindowThreadProcessId(GetForegroundWindow(), IntPtr.Zero); uint appThread = GetCurrentThreadId(); int windowPlacementFlagMaxized = 2; WindowPlacement currentPlacement = new WindowPlacement(); GetWindowPlacement(hWnd, out currentPlacement); ShowWindowCommands showCommand = currentPlacement.showCmd != ShowWindowCommands.ShowMinimized ? ShowWindowCommands.Show : currentPlacement.flags == windowPlacementFlagMaxized ? ShowWindowCommands.ShowMaximized : ShowWindowCommands.ShowDefault; if (foreThread != appThread) { AttachThreadInput(foreThread, appThread, true); BringWindowToTop(hWnd); ShowWindow(hWnd, showCommand); AttachThreadInput(foreThread, appThread, false); } else { BringWindowToTop(hWnd); ShowWindow(hWnd, showCommand); } }
public static extern IntPtr ShellExecute( IntPtr hwnd, string lpszOp, string lpszFile, string lpszParams, string lpszDir, ShowWindowCommands FsShowCmd );
//////////////////////////////////////////////////////////////////////////////////////////////////// /// <summary> /// Hook function which corresponds to ShowWIndow. It seems osu minimize own window after /// ShellExecuteEx during fullscreen mode. So it's necessary. /// </summary> /// /// <param name="hWnd"> Window handle. </param> /// <param name="nCmdShow"> ShowWindowCommands. </param> /// /// <returns> Always true. </returns> //////////////////////////////////////////////////////////////////////////////////////////////////// static bool ShowWindow_Hooked(IntPtr hWnd, ShowWindowCommands nCmdShow) { if (nCmdShow == ShowWindowCommands.Minimize) { return(true); } return(ShowWindow(hWnd, nCmdShow)); }
public ShellExecute(IntPtr _ownerHandle, string _path) { OwnerHandle = _ownerHandle; Verb = OpenFile; Path = _path; Parameters = ""; WorkingFolder = ""; ShowMode = ShowWindowCommands.SW_SHOWNORMAL; }
public ShellExecute(IntPtr _ownerHandle, string _verb, string _path, string _parameters, string _workingFolder, ShowWindowCommands _showMode) { OwnerHandle = _ownerHandle; Verb = _verb; Path = _path; Parameters = _parameters; WorkingFolder = _workingFolder; ShowMode = _showMode; }
public string WorkingFolder; // pecifies the default directory #endregion Fields #region Constructors // when it is opened. public ShellExecute() { // Set default values OwnerHandle = IntPtr.Zero; Verb = OpenFile; Path = ""; Parameters = ""; WorkingFolder = ""; ShowMode = ShowWindowCommands.SW_SHOWNORMAL; }
public ShowWindowCommands ShowMode; // Flags that specify how an application is to be displayed // when it is opened. public ShellExecute() { // Set default values OwnerHandle = IntPtr.Zero; Verb = OpenFile; Path = ""; Parameters = ""; WorkingFolder = ""; ShowMode = ShowWindowCommands.SW_SHOWNORMAL; }
private void SetWindowVisible(bool visible) { if (!this.Handle.IsValid) { return; } ShowWindowCommands cmd = ShowWindowCommands.Show; if (visible == false) { cmd = ShowWindowCommands.Hide; } User32.ShowWindow(this.Handle, (int)cmd); }
public static bool LastWindowShow(ShowWindowCommands i_swc) { IntPtr lastWindowHandle = getLastWindow(); bool validOp = checkIfWindowValid(lastWindowHandle); if (lastWindowHandle.Equals(GetDesktopWindow()) == false && validOp) { ShowWindow(lastWindowHandle, i_swc); SetForegroundWindow(lastWindowHandle); } return(validOp); }
public static WindowInfo GetWindowInfo(IntPtr hwnd) { WindowInfo result = null; Platform.WindowInfo windowInfo = new Platform.WindowInfo(); Platform.User32.GetWindowInfo(hwnd, ref windowInfo); Rectangle bounds = windowInfo.rcWindow.ToRectangle(); string title = GetWindowText(hwnd); bool isVisible = Platform.User32.IsWindowVisible(hwnd); WindowPlacement placement = WindowPlacement.Default; User32.GetWindowPlacement(hwnd, ref placement); ShowWindowCommands windowCommands = placement.ShowCmd; Rectangle normalBounds = placement.NormalPosition.ToRectangle(); int zOrder = GetZOrder(hwnd); //result = new WindowInfo(hwnd, title, isVisible, bounds); result = new WindowInfo { Handle = hwnd, Title = title, Visible = isVisible, Bounds = bounds, State = windowCommands, NormalBounds = normalBounds, MinimizedPosition = placement.MinPosition.ToPoint(), MaximizedPosition = placement.MaxPosition.ToPoint(), PlacementFlags = placement.Flags, ZOrder = zOrder, }; return(result); }
protected static extern bool ShowWindow(IntPtr hWnd, ShowWindowCommands nCmdShow);
public static extern bool ShowWindow([In] HWnd hWnd, [In][MarshalAs(UnmanagedType.I4)] ShowWindowCommands cmdShow);
internal static extern bool ShowWindowAsync(IntPtr hWnd, ShowWindowCommands cmdShow);
/// <summary> /// The ShowWindow function sets the specified window's show state. /// </summary> public static bool ShowWindow(IntPtr hWnd, ShowWindowCommands nCmdShow) { return(User32Dll.ShowWindow((void *)hWnd, (int)nCmdShow) != 0); }
public static extern bool ShowWindow(Hwnd hwnd, ShowWindowCommands nCmdShow);
public static extern bool ShowWindow(IntPtr hWnd, ShowWindowCommands flags);
public static void SetWindowPlacement(IntPtr handle, System.Drawing.Rectangle r, ShowWindowCommands state) { WINDOWPLACEMENT windowPlacement = new WINDOWPLACEMENT(); if (!NativeMethods.GetWindowPlacement(handle, ref windowPlacement)) { throw new System.ComponentModel.Win32Exception(Marshal.GetLastWin32Error()); } RECT rect = new RECT(); rect.left = r.Left; rect.top = r.Top; rect.right = r.Right; rect.bottom = r.Bottom; windowPlacement.rcNormalPosition = rect; windowPlacement.showCmd = state; if (!NativeMethods.SetWindowPlacement(handle, ref windowPlacement)) { throw new System.ComponentModel.Win32Exception(Marshal.GetLastWin32Error()); } }
public static extern bool ShowWindowAsync(IntPtr window, ShowWindowCommands command);
public bool SetState(ShowWindowCommands flags) { return(User32Methods.ShowWindow(this.Handle, flags)); }
/// <summary> /// Sets the window's bounds relative to the desktop's working area /// </summary> public static void SetWindowPlacement(Process p, System.Drawing.Rectangle r, ShowWindowCommands state) { SetWindowPlacement(Windows.FindWindow.FindMainWindow(p), r, state); }
/// <summary> /// 打开文件或链接 /// </summary> /// <param name="hwnd">用于指定父窗口句柄。当函数调用过程出现错误时,它将作为Windows消息窗口的父窗口。</param> /// <param name="lpOperation">用于指定要进行的操作 /// <para>“open” 执行由lpFile参数指定的程序,或打开由lpFile参数指定的文件或文件夹</para> /// <para>“print” 打印由lpFile参数指定的文件</para> /// <para>“explore” 浏览由lpFile参数指定的文件夹</para> /// <para>当参数设为NULL时,表示执行默认操作“open”</para></param> /// <param name="lpFile">用于指定要打开的文件名、要执行的程序文件名或要浏览的文件夹名。</param> /// <param name="lpParameters">若lpFile参数是一个可执行程序,则此参数指定命令行参数,否则此参数应为NULL.</param> /// <param name="lpDirectory">用于指定默认目录.</param> /// <param name="nShowCmd">若lpFile参数是一个可执行程序,则此参数指定程序窗口的初始显示方式,否则此参数应设置为0。</param> /// <returns>执行成功会返回应用程序句柄, /// 返回的HINSTANCE可以将它转换为一个整数(%d),并比较它的值大于还是小于32或比较它的错误代码 /// 返回值大于32表示执行成功 返回值小于32表示执行错误 /// 返回值可能的错误有: = 0 {内存不足} /// ERROR_FILE_NOT_FOUND = 2; {文件名错误 /// ERROR_PATH_NOT_FOUND = 3; {路径名错误 /// ERROR_BAD_FORMAT = 11; {EXE 文件无效} /// SE_ERR_SHARE = 26; {发生共享错误} /// SE_ERR_ASSOCINCOMPLETE = 27; {文件名不完全或无效} /// SE_ERR_DDETIMEOUT = 28; {超时} /// SE_ERR_DDEFAIL = 29; {DDE 事务失败} /// SE_ERR_DDEBUSY = 30; {正在处理其他 DDE 事务而不能完成该 DDE 事务} /// SE_ERR_NOASSOC = 31; {没有相关联的应用程序} /// </returns> public static IntPtr OpenWinForm(int hwnd, string lpOperation, string lpFile, string lpParameters, string lpDirectory, ShowWindowCommands nShowCmd) { return(ShellExecute(hwnd, lpOperation, lpFile, lpParameters, lpDirectory, (int)nShowCmd)); }
extern static bool ShowWindow(IntPtr hWnd, ShowWindowCommands nCmdShow);
public static bool ChangeWindowState(IntPtr handle, ShowWindowCommands state) { return(ShowWindow(handle, (int)state)); }
internal static extern bool ShowWindow(IntPtr hwnd, ShowWindowCommands nCmdShow);
public static void SetWindowPlacement(Process p, System.Drawing.Rectangle r, ShowWindowCommands state) { SetWindowPlacement(p.MainWindowHandle, r, state); }
[DllImport("user32.dll")] public static extern bool ShowWindow(IntPtr hWnd, ShowWindowCommands nCmdShow);
public static void SetWindowState(IntPtr hWnd, ShowWindowCommands state) { ShowWindow(hWnd, (int) state); }
public static extern bool ShowWindow(IntPtr hWnd, ShowWindowCommands nCmdShow);
[DllImport("user32.dll")] public static extern bool ShowWindow (IntPtr hWnd, ShowWindowCommands nCmdShow);
public static extern int ShowWindow(IntPtr hwnd, ShowWindowCommands nCmdShow);
private static extern Boolean ShowWindow(IntPtr hWnd, ShowWindowCommands nCmdShow);
public bool Show(ShowWindowCommands cmdShow) => User32.ShowWindow(Hwnd, cmdShow);
// public static void SetWindowState(string title, ShowWindowCommands cmd) { IntPtr hwnd = FindWindowByCaption(IntPtr.Zero, title); ShowWindow(hwnd, cmd); }