话不多说上代码
问题出在userform这个窗体的样式上
需要用到的win32api函数以及常量
Public Declare PtrSafe Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As LongPtr
Public Const WS_POPUP = &H80000000
Public Const GWL_STYLE = (-16)
Public Declare PtrSafe Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As LongPtr, ByVal nIndex As Long) As Long
Public Declare PtrSafe Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As LongPtr, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
用户窗体的初始化
Private Sub UserForm_Initialize()Dim hd, s As Longhd = Win32Api.FindWindow(vbNullString, Me.Caption)s = Win32Api.GetWindowLong(hd, Win32Api.GWL_STYLE)If s And Win32Api.WS_POPUP = Win32Api.WS_POPUP Thens = s Xor Win32Api.WS_POPUPWin32Api.SetWindowLong hd, Win32Api.GWL_STYLE, sEnd If
End Sub
Public Sub Mycmd_测试窗体()UserForm1.show 0
End Sub