我想调用一个关闭回收站窗口的函数。这是打开回收站的代码,但是我找不到关闭它的代码:
Process.Start("explorer.exe", "/n, ::{645FF040-5081-101B-9F08-00AA002F954E}")发布于 2010-08-31 02:14:27
正如Adam所指定的,您需要使用findwindow和sendmessage API来查找并关闭窗口。
下面是一个示例代码
Imports System.Runtime.InteropServices
Public Class Form1
<DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Auto)> _
Private Shared Function FindWindow(ByVal lpClassName As String, ByVal lpWindowName As String) As IntPtr
End Function
<DllImport("user32.dll", SetLastError:=True)> _
Public Shared Function SendMessage(ByVal hWnd As IntPtr, ByVal Msg As Integer, ByVal wParam As IntPtr, ByVal lParam As IntPtr) As IntPtr
End Function
Public Const WM_SYSCOMMAND As Integer = &H112
Public Const SC_CLOSE As Integer = &HF060
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim hwnd As IntPtr
hwnd = FindWindow("CabinetWClass", "Recycle Bin")
if hwnd = Nothing then
MessageBox.Show("Recycle Bin not found.")
else
SendMessage(hwnd, WM_SYSCOMMAND, SC_CLOSE, 0)
end if
End Sub
End Class将代码转换为c#非常简单,如果您在转换代码时遇到任何问题,请让我知道。
来源:Code Project
编辑1 :您可以使用Spy++查找.net工具提供的类名和窗口名。
发布于 2010-08-30 16:44:33
如果它已经被其他人打开了,你可能需要使用win32 api -例如。findwindow然后发送消息以发送关闭消息。
发布于 2010-08-30 16:37:07
Process.Start将返回启动的Process。试试这个:
Process p=Process.Start("explorer.exe",
"/n, ::{645FF040-5081-101B-9F08-00AA002F954E}");
p.CloseMainWindow();
//OR
p.Close();https://stackoverflow.com/questions/3598947
复制相似问题