如何在vb中使与应用程序无关的窗口最小化或最大化其窗口状态?

发布于 2024-12-20 18:40:14 字数 77 浏览 2 评论 0原文

如果您在任务管理器中注意到,当您右键单击正在运行的任务时,您会看到许多选项,其中包括“最小化”和“最大化”。有没有办法在vb中实现这个目标?

If you have ever noticed in the Task Manager, when you right-click on the running task, you have many options which include 'Minimize' and 'Maximize'. Is there anyway to do achieve this in vb?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

七七 2024-12-27 18:40:14

这是您正在寻找的代码的示例。它将循环遍历所有活动进程并最小化所有窗口。

在您的应用程序中,您可能需要使用类似 Process.GetProcessesByName 的方法来查找要操作的特定窗口。

Imports System.Runtime.InteropServices

Module ManipulateWindows

    Const SW_HIDE As Integer = 0
    Const SW_RESTORE As Integer = 1
    Const SW_MINIMIZE As Integer = 2
    Const SW_MAXIMIZE As Integer = 3

    <DllImport("User32")> _
    Private Function ShowWindow(ByVal hwnd As Integer, ByVal nCmdShow As Integer) As Integer
    End Function

    Public Sub Main()

        'iterate through all the open processes.
        For Each p As Process In Process.GetProcesses    

            'Get the Window Handle
            Dim hWnd as integer = CType(p.MainWindowHandle, Integer)

            'Write out the title of the main window for the process.
            System.Console.WriteLine(p.MainWindowTitle)

            'Minimize the Window
            ShowWindow(hWnd, SW_MINIMIZE)
        Next p    
    End Sub    
End Module

Here is an example of the code you are looking for. It will loop through all the active processes and minimize all the windows.

In your app you will probably want to use something like Process.GetProcessesByName to find the specific window you want to manipulate.

Imports System.Runtime.InteropServices

Module ManipulateWindows

    Const SW_HIDE As Integer = 0
    Const SW_RESTORE As Integer = 1
    Const SW_MINIMIZE As Integer = 2
    Const SW_MAXIMIZE As Integer = 3

    <DllImport("User32")> _
    Private Function ShowWindow(ByVal hwnd As Integer, ByVal nCmdShow As Integer) As Integer
    End Function

    Public Sub Main()

        'iterate through all the open processes.
        For Each p As Process In Process.GetProcesses    

            'Get the Window Handle
            Dim hWnd as integer = CType(p.MainWindowHandle, Integer)

            'Write out the title of the main window for the process.
            System.Console.WriteLine(p.MainWindowTitle)

            'Minimize the Window
            ShowWindow(hWnd, SW_MINIMIZE)
        Next p    
    End Sub    
End Module
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文