首页
学习
活动
专区
圈层
工具
发布
    • 综合排序
    • 最热优先
    • 最新优先
    时间不限
  • 来自专栏全栈程序员必看

    BringWindowToTop(), SetForegroundWindow(), SetActiveWindow()「建议收藏」

    SetForegroundWindow() 原型: BOOL SetForegroundWindow(); BOOL SetForegroundWindow SetForegroundWindow窗体函数激活一个窗体并将其强制为前台的。当应用程序要显示关键错误或须要用户马上注意的信息时。应仅仅能调用SetForegroundWindow函数。 假设应用程序不在前台中而想设置在前台中,能够调用SetForegroundWindow函数。

    86720编辑于 2022-07-10
  • 来自专栏蔻丁杂记

    C#/WPF 仅启动一个进程实例

    processes) { ShowWindowAsync(process.MainWindowHandle, SW_SHOWNOMAL); SetForegroundWindow param>/// <returns>如果窗口设入了前台,返回值为非零;如果窗口未被设入前台,返回值为零</returns>[DllImport("User32.dll", EntryPoint = "SetForegroundWindow ")]private static extern bool SetForegroundWindow(IntPtr hWnd); [DllImport("user32.dll")]public static <returns>如果窗口设入了前台,返回值为非零;如果窗口未被设入前台,返回值为零</returns> [DllImport("User32.dll", EntryPoint = "SetForegroundWindow ")] private static extern bool SetForegroundWindow(IntPtr hWnd); [DllImport("user32.dll

    56710编辑于 2024-12-25
  • 来自专栏林德熙的博客

    WPF 让窗口激活作为前台最上层窗口的方法

    Show 的方法显示 但是某些设备窗口被盖在其他的窗口的下面,此时的窗口的 window.IsActive 还是 true 但是调用 Activate 不会让窗口放在上层 我在网上看到好多小伙伴调用了 SetForegroundWindow ) { return false; } return UnsafeNativeMethods.SetForegroundWindow (new HandleRef(null, CriticalHandle)); } 源代码请看 github 也就是调用 SetForegroundWindow 和调用 Activate 方法是差不多的,如果调用 Activate 没有用那么应该调用 SetForegroundWindow 也差不多 通过大佬的 SetForegroundWindow的正确用法 - 子坞 - 博客园 可以了解到 显示窗口ShowWindow(有些窗口被最小化/隐藏了)     4.更改窗口的Zorder,SetWindowPos使之最上,为了不影响后续窗口的Zorder,改完之后,再还原     5.最后SetForegroundWindow

    3.7K11发布于 2020-04-26
  • 来自专栏码客

    WPF程序开发-保证程序启动唯一

    FindWindow(String ClassName, String WindowName); [DllImport("user32.dll")] public static extern bool SetForegroundWindow Process proc = allProcs[0]; int hWnd = FindWindow(null, proc.MainWindowTitle.ToString()); SetForegroundWindow FindWindow(String ClassName, String WindowName); [DllImport("user32.dll")] public static extern bool SetForegroundWindow continue; int hWnd = FindWindow(null, process.MainWindowTitle.ToString()); SetForegroundWindow

    96610发布于 2021-11-29
  • 来自专栏码客

    WPF只运行一个实例

    FindWindow(string ClassName, string WindowName); [DllImport("user32.dll")] public static extern bool SetForegroundWindow current.Id) continue; int hWnd = FindWindow(null, process.MainWindowTitle.ToString()); SetForegroundWindow

    89070编辑于 2022-03-13
  • 来自专栏源懒由码

    Python中设置指定窗口为前台活动窗口(最顶层窗口)win32gui

    105042145 Win32 API之EnumWindows详解: http://blog.sina.com.cn/s/blog_e5f00a490101w1yc.html 测试1:SetForegroundWindow -----') # 设置TIM为活动窗口 shell = win32com.client.Dispatch("WScript.Shell") shell.SendKeys('%') win32gui.SetForegroundWindow -----') # 设置TIM为活动窗口 shell = win32com.client.Dispatch("WScript.Shell") shell.SendKeys('%') win32gui.SetForegroundWindow

    9.1K52发布于 2020-10-10
  • 来自专栏林德熙的博客

    WPF 弹出 popup 里面的 TextBox 无法输入汉字

    当然还有另一个方法,使用SetForegroundWindow方法。 [DllImport("USER32.DLL")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool SetForegroundWindow = (HwndSource)PresentationSource.FromVisual(popup.Child); IntPtr handle = source.Handle; SetForegroundWindow

    2.2K30发布于 2018-09-18
  • 来自专栏DotNet NB && CloudNative

    .NET桌面应用保持程序唯一性打开的一种方式

    FindWindow(null, "唯一程序"); } ShowWindowAsync(mainWindowHandle, ); // 显示窗口 SetForegroundWindow bool ShowWindowAsync(IntPtr hWnd, int nCmdShow); [DllImport("user32.dll ")] public static extern bool SetForegroundWindow SetForegroundWindow: 将窗口设置为前台窗口。 注意事项 窗口名称匹配问题 如果窗口标题动态变化,FindWindow 的效果可能不佳,需保证窗口标题唯一或改用其他识别方法。 权限问题 如果以管理员权限运行程序,SetForegroundWindow 操作可能会被限制。需要确保权限一致。 多线程问题 如果程序使用了多线程,需注意线程间的窗口操作同步。

    30610编辑于 2025-01-02
  • 来自专栏c#Winform自定义控件系列

    c# 控制职能运行单一实例,再次运行显示已经运行的实例

    IntPtr i = new IntPtr(handle); 44 bool isok = ShowWindow(i, 1); 45 SetForegroundWindow (i); 46 // SetForegroundWindow(hWnd); 47 // MessageBox.Show(null, "有一个和本程序相同的应用程序已经在运行 } 51 } 52 53 [DllImport("user32.dll")] 54 private static extern bool SetForegroundWindow

    87520发布于 2019-09-11
  • 来自专栏walterlv - 吕毅的博客

    Win32 程序在启动时激活前一个启动程序的窗口

    在前面的 ShowWindow 之后,再调用一下 SetForegroundWindow 即可将其激活到最前面来。如果在其他桌面,则会切换到对应的桌面。 [DllImport("USER32.DLL")] public static extern bool SetForegroundWindow(IntPtr hWnd); var hwnd = process.MainWindowHandle ; ShowWindow(hwnd, 9); SetForegroundWindow(hwnd); 找到并激活窗口 以上方法适用于普通的主窗口。

    1.3K20发布于 2018-09-18
  • 来自专栏码客

    WPF应用单实例

    FindWindow(string className, string windowName); [DllImport("user32.dll")] public static extern bool SetForegroundWindow current.Id) continue; int hWnd = FindWindow(null, process.MainWindowTitle); SetForegroundWindow

    49020编辑于 2023-07-24
  • 来自专栏Java架构师必看

    保证应用程序只有一个实例在运行

    ShowWindowAsync (instance.MainWindowHandle , WS_SHOWNORMAL); //Set the real intance to foreground window SetForegroundWindow bool ShowWindowAsync( IntPtr hWnd, int cmdShow); [DllImport("User32.dll")] private static extern bool SetForegroundWindow

    1.1K40发布于 2021-03-22
  • 来自专栏全栈程序员必看

    python更新pip失败_findwindow函数

    = INVALID_HANDLE_VALUE) SetForegroundWindow(h); return 0; } 效果很好.与python相同: import win32gui h = win32gui.FindWindow (None, “SomeApp”) if h: win32gui.SetForegroundWindow(h) else: print “SomeApp not found” 失败,找不到SomeApp

    1.1K40编辑于 2022-09-21
  • 来自专栏全栈程序员必看

    python获取软件窗口句柄_python获取窗口句柄并将指定应用置顶

    hwnd, win32con.SW_SHOWNORMAL) # 窗口需要最大化且在后台,不能最小化 # ctypes.windll.user32.ShowWindow(hwnd,3) # win32gui.SetForegroundWindow (hwnd) # # win32gui.SetActiveWindow(hwnd) # win32gui.SetForegroundWindow(hwnd) win32gui.SetWindowPos(

    2.9K30编辑于 2022-09-16
  • 来自专栏呆呆敲代码的小Y 公众号

    Unity实战篇 | 使Unity打包的exe程序始终保持屏幕最前端【文末送书】

    Unity打包的exe程序始终保持屏幕最前端 一、编写核心脚本代码 实现该功能主要是使用了几个关键的Windows的API,分别是下面几个函数: ShowWindow 函数 SetWindowPos函数 SetForegroundWindow ; public class WindowActive : MonoBehaviour { [DllImport("User32.dll")] extern static bool SetForegroundWindow void Active() { if (KeepForeground) { ShowWindow(hWnd, 1); SetForegroundWindow

    3K30编辑于 2023-04-09
  • 来自专栏全栈程序员必看

    java 刷屏器「建议收藏」

    Native.loadLibrary("user32", User32.class); boolean ShowWindow(HWND hWnd, int nCmdShow); boolean SetForegroundWindow 的聊天窗口,并将其置顶 HWND hWnd = user32.FindWindowA(null, "Criyson"); user32.ShowWindow(hWnd,1); user32.SetForegroundWindow

    45610编辑于 2022-09-03
  • 来自专栏林德熙的博客

    WPF 弹出 popup 里面的 TextBox 无法输入汉字

    当然还有另一个方法,使用SetForegroundWindow方法。 [DllImport("USER32.DLL")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool SetForegroundWindow = (HwndSource)PresentationSource.FromVisual(popup.Child); IntPtr handle = source.Handle; SetForegroundWindow

    2.4K10编辑于 2022-08-04
  • 来自专栏林德熙的博客

    记腾讯微信输入法导致 WPF 应用卡住 窗口无法激活和显示

    本文记录我远程一位老师的设备,这位老师使用的是 Win7 Sp1 系统,现象是 WPF 应用的窗口无法激活,在 user32 的 SetForegroundWindow 或 NtUserShowWindow _SetForegroundWindow@4() 未知 [托管到本机的转换] PresentationFramework.dll!

    49010编辑于 2024-11-21
  • 来自专栏python3

    多窗口下的批量操作脚本 - 利用win3

    #利用方法,通过类名找到窗体句柄 7 ctjb = win32gui.FindWindow(cla,None) 8 #利用方法,通过窗体句柄前置窗体 9 win32gui.SetForegroundWindow 9 cla = 'Photo_Lightweight_Viewer' 10 hld = win32gui.FindWindow(cla,None) 11 win32gui.SetForegroundWindow def fore_text(): 14 cla = 'Notepad' 15 hld = win32gui.FindWindow(cla,None) 16 win32gui.SetForegroundWindow

    2.6K10发布于 2020-01-15
  • 来自专栏林德熙的博客

    WPF 弹出 popup 里面的 TextBox 无法输入汉字 修复在 Popup 输入法不跟随在 WinForms 弹出的 WPF 的 TextBox 无法输入问题

    当然还有另一个方法,使用SetForegroundWindow方法。 [DllImport("USER32.DLL")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool SetForegroundWindow = (HwndSource)PresentationSource.FromVisual(popup.Child); IntPtr handle = source.Handle; SetForegroundWindow

    3.5K20发布于 2019-03-13
领券