已知一个窗体的句柄,怎么让它最大化?
如果,使用了SendMessage winHwnd, WM_SYSCOMMAND, SC_MAXIMIZE, ByVal 0&没反应 --------------------编程问答-------------------- 代码没有问题,可能是句柄不对。
下面的代码,可以将记事本最大化:
Option Explicit
Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Public Const WM_SYSCOMMAND = &H112
Public Const SC_MAXIMIZE = &HF030&
Option Explicit--------------------编程问答-------------------- 有几个问题你要明确:
Private Sub Command1_Click()
Dim hwnd As Long
hwnd = FindWindow("Notepad", vbNullString)
SendMessage hwnd, WM_SYSCOMMAND, SC_MAXIMIZE, ByVal 0&
End Sub
1、你的窗口句柄对了没有?
2、怎么可以确认你是找对了窗口句柄?
3、目标窗口是不是你自己程序的窗口?
如果不是你程序的窗口会不会对方拦截了这类消息就是为了防止你这么干? --------------------编程问答-------------------- 没那么复杂,简单一点,用ShowWindow:
Option Explicit
Private Declare Function ShowWindow Lib "user32.dll" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
Private Const SW_MAXIMIZE As Long = 3
Private Sub Form_Load()
ShowWindow lHwnd,SW_MAXIMIZE'lHwnd是已知一个窗体的句柄
End Sub
补充:VB , 基础类