代码之家  ›  专栏  ›  技术社区  ›  Ali Tarhini

如何使用vb.net或c.net关闭回收站

  •  0
  • Ali Tarhini  · 技术社区  · 14 年前

    我想调用一个关闭回收站窗口的函数。这是打开回收站的代码,但是我找不到关闭回收站的代码:

    Process.Start("explorer.exe", "/n, ::{645FF040-5081-101B-9F08-00AA002F954E}")
    
    3 回复  |  直到 14 年前
        1
  •  1
  •   Community CDub    7 年前

    以及作为 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工具提供的类名和windowname。

        2
  •  1
  •   Adam Butler    14 年前

    如果它已被其他人打开,您可能需要使用win32 API-例如findwindow,然后send message发送关闭消息。

        3
  •  0
  •   TheVillageIdiot    14 年前

    Process.Start 还给你 Process 起动。试试这个:

    Process p=Process.Start("explorer.exe", 
                  "/n, ::{645FF040-5081-101B-9F08-00AA002F954E}");
    p.CloseMainWindow();
    //OR
    p.Close();