gpt4 book ai didi

.net - 在 VB.NET Windows 窗体中显示桌面按钮

转载 作者:行者123 更新时间:2023-12-04 00:45:47 24 4
gpt4 key购买 nike

在我的 vb.net windows 窗体应用程序中,我想制作一个按钮,当用户点击该按钮时,应显示桌面(显示桌面按钮)。

考虑一个名为 form1 的表单,它有一个像“显示桌面”这样的按钮,当用户单击时,所有应用程序都应该最小化并且它应该显示桌面,是否有任何 VB.NET Windows 窗体应用程序的代码。

最佳答案

编辑

虽然我提出的解决方案有效,但我建议使用Code Gray's answer下面,因为这是正确的方法。


在 C# 中它是这样的:

using System;
using System.Runtime.InteropServices;

namespace ConsoleApplication1 {
class Program {
[DllImport("user32.dll", EntryPoint = "FindWindow", SetLastError = true)]
static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
[DllImport("user32.dll", EntryPoint = "SendMessage", SetLastError = true)]
static extern IntPtr SendMessage(IntPtr hWnd, Int32 Msg, IntPtr wParam, IntPtr lParam);

const int WM_COMMAND = 0x111;
const int MIN_ALL = 419;
const int MIN_ALL_UNDO = 416;

static void Main(string[] args) {
IntPtr lHwnd = FindWindow("Shell_TrayWnd", null);
SendMessage(lHwnd, WM_COMMAND, (IntPtr)MIN_ALL, IntPtr.Zero);
System.Threading.Thread.Sleep(2000);
SendMessage(lHwnd, WM_COMMAND, (IntPtr)MIN_ALL_UNDO, IntPtr.Zero);
}
}
}

我使用了 online converter tool转换以上代码,请验证是否有效

Imports System
Imports System.Runtime.InteropServices

Namespace ConsoleApplication1
Class Program
<DllImport("user32.dll", EntryPoint := "FindWindow", SetLastError := True)> _
Private Shared Function FindWindow(lpClassName As String, lpWindowName As String) As IntPtr
End Function
<DllImport("user32.dll", EntryPoint := "SendMessage", SetLastError := True)> _
Private Shared Function SendMessage(hWnd As IntPtr, Msg As Int32, wParam As IntPtr, lParam As IntPtr) As IntPtr
End Function

Const WM_COMMAND As Integer = &H111
Const MIN_ALL As Integer = 419
Const MIN_ALL_UNDO As Integer = 416

Private Shared Sub Main(args As String())
Dim lHwnd As IntPtr = FindWindow("Shell_TrayWnd", Nothing)
SendMessage(lHwnd, WM_COMMAND, DirectCast(MIN_ALL, IntPtr), IntPtr.Zero)
System.Threading.Thread.Sleep(2000)
SendMessage(lHwnd, WM_COMMAND, DirectCast(MIN_ALL_UNDO, IntPtr), IntPtr.Zero)
End Sub
End Class
End Namespace

关于.net - 在 VB.NET Windows 窗体中显示桌面按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10361069/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com