В этом уроке мы добавим свою кнопку в проводник!
Для начала декларация функций:
Private Declare Ansi Function SetParent Lib "user32" (hWndChild As Integer, hWndNewParent As Integer) As Integer
Private Declare Ansi Function FindWindow Lib "user32" Alias "FindWindowA" (lpClassName As Integer, lpWindowName As Integer) As Integer
Private Declare Ansi Function GetDesktopWindow Lib "user32" () As Integer
Private Declare Ansi Function GetWindow Lib "user32.dll" (hwnd As Integer, wCmd As Integer) As Integer
Private Declare Ansi Function GetClassName Lib "user32.dll" Alias "GetClassNameA" (hwnd As Integer, ByRef lpClassName As String, nMaxCount As Integer) As Integer
Private Declare Ansi Function SetWindowPos Lib "user32.dll" (hwnd As Integer, hWndInsertAfter As Integer, X As Integer, Y As Integer, cx As Integer, cy As Integer, wFlags As Integer) As Integer
Private Function FindWindows(wClass As String) As Long
Dim result As Long = 0L
Dim num As Long = CLng(Form1.GetDesktopWindow())
num = CLng(Form1.GetWindow(CInt(num), 5))
While num <> 0L
Dim text As String = Strings.Space(256)
Dim num2 As Long = CLng(Form1.GetClassName(CInt(num), text, 256))
text = Strings.Left(text, CInt(num2))
If Operators.CompareString(text, wClass, False) = 0 Then
result = num
Exit While
End If
num = CLng(Form1.GetWindow(CInt(num), 2))
End While
Return result
End Function
На форму кидаем кнопку и:
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
Dim hWnd = CInt(GetDesktopWindow)
Form1.SetParent(CInt(Me.Button1.Handle), hWnd)
Button1.Location = New Point(100, 0)
End Sub
И вот, наша кнопка теперь в окне проводника (можно "засунуть" кнопку в любое окно)!
Скачать проект
P.S.S. Тестил на Win 8 x64, на других возможно не актуально