API高手請進,關于用WM_GETMINMAXINFO控制最小窗口SIZE的問題

leon7909 2002-07-01 05:37:40
已知在VC中在WM_GETMINMAXINFO里修改MINMAXINFO FAR* lpMMI可以實現控制窗口最小尺寸,現在想轉到VB中來做,利用CALLBACK函式,截下WM_GETMINMAXINFO消息,可lParam 和wParam又分別傳入了什麼呢?應該怎麼修改?

多謝,在線等待.................
...全文
272 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
junwhj 2002-07-02
  • 打赏
  • 举报
回复
对于WM_GETMINMAXINFO消息,用不到wParam,lParam是MINMAXINFO结构的内存地址。

'==========================================
'在模块中:
'==========================================
Option Explicit

Private Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" ( _
ByVal lpPrevWndFunc As Long, _
ByVal hwnd As Long, _
ByVal Msg As Long, _
ByVal wParam As Long, _
ByVal lParam As Long) As Long

Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" ( _
ByVal hwnd As Long, _
ByVal nIndex As Long, _
ByVal dwNewLong As Long) As Long

Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" ( _
Destination As Any, _
Source As Any, _
ByVal Length As Long)

Private Type POINTAPI
x As Long
y As Long
End Type

Private Type MINMAXINFO
ptReserved As POINTAPI
ptMaxSize As POINTAPI
ptMaxPosition As POINTAPI
ptMinTrackSize As POINTAPI
ptMaxTrackSize As POINTAPI
End Type

Private Const GWL_WNDPROC = (-4)
Private Const WM_GETMINMAXINFO = &H24

Private m_Hook As Boolean
Private m_hWnd As Long
Private m_PrevWndProc As Long


Public Sub SetSubClass(lpHwnd As Long)
If Not m_Hook Then
m_hWnd = lpHwnd
m_PrevWndProc = SetWindowLong(lpHwnd, GWL_WNDPROC, AddressOf WindowProc)
m_Hook = True
End If
End Sub


Public Sub Restore()
If m_Hook Then
Call SetWindowLong(m_hWnd, GWL_WNDPROC, m_PrevWndProc)
m_Hook = False
End If
End Sub


Private Function WindowProc(ByVal hw As Long, _
ByVal uMsg As Long, _
ByVal wParam As Long, _
ByVal lParam As Long) As Long
Dim mmiInfo As MINMAXINFO

Select Case uMsg
Case WM_GETMINMAXINFO
Call CopyMemory(mmiInfo, ByVal lParam, Len(mmiInfo))
mmiInfo.ptMinTrackSize.x = 300 '最小尺寸: 300相素
mmiInfo.ptMinTrackSize.y = 300 '最小尺寸: 300相素
Call CopyMemory(ByVal lParam, mmiInfo, Len(mmiInfo))
Case Else
WindowProc = CallWindowProc(m_PrevWndProc, hw, uMsg, wParam, lParam)
End Select
End Function




'==========================================
'在窗体中:
'==========================================
Private Sub Form_Load()
Call SetSubClass(Me.hwnd)
End Sub


Private Sub Form_Unload(Cancel As Integer)
Call Restore
End Sub
leon7909 2002-07-02
  • 打赏
  • 举报
回复
多謝多謝!

1,487

社区成员

发帖
与我相关
我的任务
社区描述
VB API
社区管理员
  • API
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧