注册 登录
编程论坛 VB6论坛

这个程序,用户定义类型如何定义?

yuma 发布于 2023-02-09 15:14, 1216 次点击
这个程序,用户定义类型如何定义?

这个程序是通过API的方法,最小化窗口。用于操作第三方程序的最大化、最小化、还原?


Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function GetWindowPlacement Lib "user32" (ByVal hwnd As Long, lpwndpl As WINDOWPLACEMENT) As Long
    Private Const SW_SHOWMINIMIZED = 2
    Private Const SW_SHOWMAXIMIZED = 3
    Private Const SW_SHOWNORMAL = 1
   

Private Sub Form_Load()
Dim hwnd As Long, Thwnd As Long
Shell "notepad.exe", 1 '打开一个记事本
hwnd = FindWindow("Notepad", "无标题 - 记事本") '得到记事本句柄
SetWindowPlacement hwnd, 2
End Sub

[此贴子已经被作者于2023-2-9 15:15编辑过]

4 回复
#2
风吹过b2023-02-09 16:21
VB6 自带的 API 阅读器带该结构 定义
我一般是按子结构放前面的原则 排列代码(C 要求)

Public Type POINTAPI
        x As Long
        y As Long
End Type

Public Type RECT
        Left As Long
        Top As Long
        Right As Long
        Bottom As Long
End Type

Public Type WINDOWPLACEMENT
        Length As Long
        flags As Long
        showCmd As Long
        ptMinPosition As POINTAPI
        ptMaxPosition As POINTAPI
        rcNormalPosition As Rect
End Type

具体 每个参数是什么意思,自己百度一下。
#3
yuma2023-02-09 19:02
代码废了。

Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function GetWindowPlacement Lib "user32" (ByVal hwnd As Integer, ByRef lpwndpl As WINDOWPLACEMENT) As Integer
Private Declare Function SetWindowPlacement Lib "user32" (ByVal hwnd As Long, lpwndpl As WINDOWPLACEMENT) As Long
Private Const SW_SHOWMINIMIZED = 2
Private Const SW_SHOWMAXIMIZED = 3
Private Const SW_SHOWNORMAL = 1
   
Private Type POINTAPI
        x As Long
        y As Long
End Type

Private Type RECT
        Left As Long
        Top As Long
        Right As Long
        Bottom As Long
End Type

Private Type WINDOWPLACEMENT
        Length As Long
        flags As Long
        showCmd As Long
        ptMinPosition As POINTAPI
        ptMaxPosition As POINTAPI
        rcNormalPosition As RECT
End Type

Private Sub Form_Load()
Dim app_hwnd As Long
Dim wp As WINDOWPLACEMENT
Shell "notepad.exe", 1 '打开一个记事本
app_hwnd = FindWindow("Notepad", "无标题 - 记事本") '得到记事本句柄
wp.showCmd = SW_SHOWMINIMIZED
SetWindowPlacement app_hwnd, wp.showCmd
End Sub


#4
风吹过b2023-02-09 19:34
SetWindowPlacement app_hwnd, wp.showCmd

要求传入 一个结构,你还只传一个值干嘛?

'-----WINXP+VB6测试通过----------
Dim app_hwnd As Long
Dim wp As WINDOWPLACEMENT
Shell "notepad.exe", 1 '打开一个记事本
app_hwnd = FindWindow("Notepad", "无标题 - 记事本") '得到记事本句柄
wp.showCmd = SW_SHOWMAXIMIZED        '最大化
wp.Length = Len(wp)                  '结构体长度
SetWindowPlacement app_hwnd, wp      '传入结构体
#5
yuma2023-02-09 20:55
可以,WIN10下测试通过。
1