我想调用一个关闭回收站窗口的函数。这是打开回收站的代码,但我找不到关闭它的代码:
Process.Start("explorer.exe", "/n, ::{645FF040-5081-101B-9F08-00AA002F954E}")
答案 0 :(得分:1)
如果已被其他人打开,您可能需要使用win32 api - 例如。 findwindow然后sendmessage发送关闭消息。
答案 1 :(得分:1)
正如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工具提供的classname和windowname。
答案 2 :(得分:0)
Process.Start
会返回Process
已启动的内容。试试这个:
Process p=Process.Start("explorer.exe",
"/n, ::{645FF040-5081-101B-9F08-00AA002F954E}");
p.CloseMainWindow();
//OR
p.Close();