VB的问题--高手请进!如何在VB中控制窗体最大化、最小化的大小!如Delphi的主窗体在最大化的时候并不覆盖整个屏幕(30分)

  • 主题发起人 主题发起人 sgxia
  • 开始时间 开始时间
S

sgxia

Unregistered / Unconfirmed
GUEST, unregistred user!
在Delphi中可以用<br>procedure WMGetMinMaxInfo( var Message:TWMGetMinMaxInfo ); message WM_GETMINMAXINFO;<br>&nbsp;<br>procedure TForm1.WMGetMinMaxInfo(var Message: TWMGetMinMaxInfo);<br>begin<br>with Message.MinMaxInfo^ do<br>begin<br>ptMaxSize.X := 200; {最大化时宽度}<br>ptMaxSize.Y := 200; {最大化时高度}<br>ptMaxPosition.X := 99; {最大化时左上角横坐标}<br>ptMaxPosition.Y := 99; {最大化时左上角纵坐标}<br>end;<br>Message.Result := 0; {告诉Windows你改变了 minmaxinfo}<br>inherited;<br>end; <br><br>来控制最大化、最小化时窗体的大小!如Delphi的主窗体在最大化的时候并不覆盖整个屏幕!<br>在Vb中如何实现!
 
我倒是知道答案,可是实在太麻烦了,<br>又得GetWindowLong,SetWindowLong
 
强分了~~<br>:)
 
稍微麻烦一点。以下代码什么消息都能处理<br><br>主题:VB中消息的处理<br>建一模块,把以下代码放入模块中:<br>Option Explicit<br><br>Private Const GWL_WNDPROC = -4<br>Public Const GWL_USERDATA = (-21)<br>Public Const WM_SIZE = &amp;H5<br>Public Const WM_USER = &amp;H400<br>Public Const WM_GETMINMAXINFO = &amp;H24<br><br>Type POINTAPI<br>&nbsp; x As Long<br>&nbsp; y As Long<br>End Type<br><br>Type MINMAXINFO<br>&nbsp; ptReserved As POINTAPI<br>&nbsp; ptMaxSize As POINTAPI<br>&nbsp; ptMaxPosition As POINTAPI<br>&nbsp; ptMinTrackSize As POINTAPI<br>&nbsp; ptMaxTrackSize As POINTAPI<br>End Type<br><br>Private Declare Function CallWindowProc Lib "user32" Alias _<br>&nbsp; &nbsp; &nbsp; &nbsp;"CallWindowProcA" (ByVal lpPrevWndFunc As Long, _<br>&nbsp; &nbsp; &nbsp; &nbsp; ByVal hwnd As Long, ByVal Msg As Long, _<br>&nbsp; &nbsp; &nbsp; &nbsp; ByVal wParam As Long, ByVal lParam As Long) As Long<br><br>Public Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" _<br>&nbsp; &nbsp; &nbsp; (ByVal hwnd As Long, ByVal nIndex As Long) As Long<br>Private Declare Function SetWindowLong Lib "user32" Alias _<br>&nbsp; &nbsp; &nbsp; "SetWindowLongA" (ByVal hwnd As Long, _<br>&nbsp; &nbsp; &nbsp; &nbsp; ByVal nIndex As Long, ByVal dwNewLong As Long) As Long<br>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<br>Public Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)<br>&nbsp; &nbsp; <br>Public Function Hook(ByVal hwnd As Long) As Long<br>&nbsp; &nbsp; &nbsp; Dim pOld As Long<br>&nbsp; &nbsp; '指定自定义的窗口过程<br>&nbsp; &nbsp; &nbsp; pOld = SetWindowLong(hwnd, GWL_WNDPROC, _<br>&nbsp; &nbsp; &nbsp; AddressOf WindowProc)<br>&nbsp; &nbsp; '保存原来默认的窗口过程指针<br>&nbsp; &nbsp; &nbsp; SetWindowLong hwnd, GWL_USERDATA, pOld<br>&nbsp; &nbsp; &nbsp; Hook = pOld<br>End Function<br><br>Public Sub Unhook(ByVal hwnd As Long, ByVal lpWndProc As Long)<br>&nbsp; &nbsp; &nbsp; Dim temp As Long<br>&nbsp; &nbsp; &nbsp; 'Cease subclassing.<br>&nbsp; &nbsp; &nbsp; temp = SetWindowLong(hwnd, GWL_WNDPROC, lpWndProc)<br>End Sub<br><br>Function WindowProc(ByVal hw As Long, ByVal uMsg As Long, _<br>&nbsp; &nbsp; &nbsp; ByVal wParam As Long, ByVal lParam As Long) As Long<br>&nbsp; &nbsp; &nbsp; If uMsg = WM_SIZE Then<br>&nbsp; &nbsp; &nbsp; &nbsp; '处理WM_SIZE消息<br>&nbsp; &nbsp; &nbsp; &nbsp; 'MsgBox "SIZE"<br>&nbsp; &nbsp; &nbsp; End If<br>&nbsp; &nbsp; &nbsp; If uMsg = WM_USER + 1 Then<br>&nbsp; &nbsp; &nbsp; &nbsp; MsgBox wParam<br>&nbsp; &nbsp; &nbsp; End If<br>&nbsp; &nbsp; &nbsp; <br>&nbsp; &nbsp; &nbsp; If uMsg = WM_GETMINMAXINFO Then &nbsp;'你的设置在这个if 中进行<br>&nbsp; &nbsp; &nbsp; &nbsp; Dim MinMax As MINMAXINFO<br>&nbsp; &nbsp; &nbsp; &nbsp; <br>&nbsp; &nbsp; &nbsp; &nbsp; CopyMemory MinMax, ByVal lParam, Len(MinMax)<br>&nbsp; &nbsp; &nbsp; &nbsp; MinMax.ptMinTrackSize.x = 3975 / Screen.TwipsPerPixelX<br>&nbsp; &nbsp; &nbsp; &nbsp; MinMax.ptMinTrackSize.y = 1740 / Screen.TwipsPerPixelY<br>&nbsp; &nbsp; &nbsp; &nbsp; MinMax.ptMaxTrackSize.x = Screen.Width / Screen.TwipsPerPixelX / 2<br>&nbsp; &nbsp; &nbsp; &nbsp; MinMax.ptMaxTrackSize.y = 3480 / Screen.TwipsPerPixelY<br>&nbsp; &nbsp; &nbsp; &nbsp; CopyMemory ByVal lParam, MinMax, Len(MinMax)<br>&nbsp; &nbsp; &nbsp; &nbsp; WindowProc = 1<br>&nbsp; &nbsp; &nbsp; &nbsp; Exit Function<br>&nbsp; &nbsp; &nbsp; End If<br>&nbsp; &nbsp; &nbsp; <br>&nbsp; &nbsp; &nbsp;Dim lpPrevWndProc As Long<br>&nbsp; &nbsp; '查询原来默认的窗口过程指针<br>&nbsp; &nbsp; &nbsp;lpPrevWndProc = GetWindowLong(hw, GWL_USERDATA)<br>&nbsp; &nbsp; '调用原来的窗口过程<br>&nbsp; &nbsp; &nbsp; WindowProc = CallWindowProc(lpPrevWndProc, hw, uMsg, wParam, lParam)<br>End Function<br><br><br>Form单元中:<br><br>Option Explicit<br>Dim wParam As Long<br>&nbsp; &nbsp; Dim lParam As Long<br>&nbsp; &nbsp; Dim lResult As Long<br><br>Private Sub Command1_Click()<br>&nbsp; &nbsp; &nbsp; wParam = 12345<br>&nbsp; &nbsp; &nbsp; lResult = SendMessage(Me.hwnd, WM_USER + 1, wParam, lParam)<br>&nbsp; &nbsp; End Sub<br><br>&nbsp; &nbsp; Private Sub Form_Load()<br>&nbsp; &nbsp; &nbsp; Me.Tag = Hook(Me.hwnd)<br>&nbsp; &nbsp; End Sub<br>&nbsp; &nbsp; Private Sub Form_Unload(Cancel As Integer)<br>&nbsp; &nbsp; &nbsp; Unhook Me.hwnd, Me.Tag<br>&nbsp; &nbsp; End Sub<br><br>
 
感谢 jsxjd,darksmile!
 
多人接受答案了。
 
后退
顶部