| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 670 人关注过本帖
标题:API实现限制From的大小
取消只看楼主 加入收藏
yuk_yu
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:334
专家分:134
注 册:2009-3-16
结帖率:85.71%
收藏
已结贴  问题点数:20 回复次数:1 
API实现限制From的大小
Option Explicit
Public Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Public Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
Public 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
Public Declare Sub CopyMemory Lib "KERNEL32" Alias "RtlMoveMemory" (lpvDest As Any, lpvSource As Any, ByVal cbCopy As Long)
Public 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)
Public Const GWL_winsize = (-4)
Public Const WM_GETMINMAXINFO = &H24
Type POINTAPI
    x As Long
    y As Long
End Type
Type MINMAXINFO
    ptReserved As POINTAPI
    ptMaxSize As POINTAPI
    ptMaxPosition As POINTAPI
    ptMinTrackSize As POINTAPI
    ptMaxTrackSize As POINTAPI
End Type
Public Prewinsize As Long
Public Function winsize(ByVal hwnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
    Dim lwd As Long, hwd As Long
    Dim maxwin As MINMAXINFO
    If Msg = WM_GETMINMAXINFO Then
        CopyMemory maxwin, ByVal lParam, Len(maxwin)
        maxwin.ptMaxTrackSize.x = 14820 '设定最大Resize的宽度
        maxwin.ptMaxTrackSize.y = 8325 '设定最大Resize的高度

        CopyMemory ByVal lParam, maxwin, Len(maxwin)
    End If
    winsize = CallWindowProc(Prewinsize, hwnd, Msg, wParam, lParam)
 End Function



Private Sub Command1_Click()
    Dim ret As Long
    '为何将Resize的宽度设置为14820和8325就不可以实现?
    Prewinsize = GetWindowLong(Me.hwnd, GWL_winsize)
    ret = SetWindowLong(Me.hwnd, GWL_winsize, AddressOf winsize)
End Sub
2012-06-19 15:56
yuk_yu
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:334
专家分:134
注 册:2009-3-16
收藏
得分:0 
回复 2楼 bczgvip
我在学习API,所以想看看问题出在什么地方。谢谢

以下代码是可以解决的:
Private Sub Form_Resize()
    If Me.Height > 8640 Then Me.Height = 8640: Enabled = False
    If Me.Width > 15030 Then Me.Width = 15030: Enabled = False
    Enabled = True
End Sub

[ 本帖最后由 yuk_yu 于 2012-6-20 14:39 编辑 ]
2012-06-20 13:49
快速回复:API实现限制From的大小
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.017385 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved