Option Explicit
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String,ByVal lpWindowName As String) As Long
Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long,ByVal hWnd2 As Long,ByVal lpsz1 As String,ByVal lpsz2 As String) As Long
Private Declare Function SetParent Lib "user32" (ByVal hWndChild As Long,ByVal hWndNewParent As Long) As Long
Public Sub PinToDesktop(FormToPin As Form)
Dim progman As Long
progman = FindWindow("progman",vbNullString)
SetParent FormToPin.hWnd,progman
End Sub
Public Sub UnPinFromDesktop(FormToUnPin As Form)
Dim lngExplorer As Long
lngExplorer = FindWindow("ExploreWClass",vbNullString)
SetParent FormToUnPin.hWnd,lngExplorer
End Sub
这里改了下
Option Explicit Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String,ByVal lpWindowName As String) As Long Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long,ByVal lpsz2 As String) As Long Private Declare Function SetParent Lib "user32" (ByVal hWndChild As Long,ByVal hWndNewParent As Long) As Long Public Sub PinToDesktop(FormToPin As Form) Dim progman As Long progman = FindWindow("progman",vbNullString) SetParent FormToPin.hWnd,progman End Sub Private Sub Command1_Click() Call PinToDesktop(Form1) End Sub
原文链接:https://www.f2er.com/vb/261119.html