vb api 修改指定窗口大小 要怎么操作用哪个api?
发布网友
发布时间:2023-03-24 19:11
我来回答
共2个回答
热心网友
时间:2023-10-17 12:32
给你一个很简单的API 参数简单,用起来简单。。
第一个:
FindWindow 用来找到窗口句柄。
第二个:
MoveWindow 用来设置窗体坐标及宽高。
-------------------------------------分割线---------------------------------------
exmple:
窗体标题:Test
具体实现
' API调用声明
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
'API调用声明
Private Declare Function MoveWindow Lib "user32" (ByVal hwnd As Long, _
ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, _
ByVal bRepaint As Long) As Long
Private sub Command_Click()
Dim HW as long
HW=FindWindow(VBNULLSTRING,"Test")
MoveWindow HW,0,0,200,300 ' 将该窗口X变为200 ,Y变为300
LZ需要多了解windows消息机制和API的熟练、
大家五一快乐。
热心网友
时间:2023-10-17 12:33
Private Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Sub Command1_Click()
Myhwnd = FindWindow(vbNullString, "计算器") '得到计算器的句柄
SetWindowPos Myhwnd, -1, 400, 100, Me.Width \ 15, Me.Height \ 15, &H400 '设置计算器的大小和位置
End Sub
Private Sub Form_Load()
Shell "calc.exe", vbNormalNoFocus '打开计算器
End Sub