宝峰科技

 找回密码
 注册

QQ登录

只需一步,快速开始

智能终端设备维修查询系统注册会员邮箱认证须知!
查看: 3228|回复: 2

[VB例程源码] VB6实现的自动停靠窗体

[复制链接]
  • TA的每日心情
    开心
    2024-12-9 18:45
  • 签到天数: 124 天

    [LV.7]常住居民III

    admin 发表于 2009-12-18 00:42:48 | 显示全部楼层 |阅读模式

    欢迎您注册加入!这里有您将更精采!

    您需要 登录 才可以下载或查看,没有账号?注册

    x
    1、新建EXE工程。
    2、添加模块,键入以下代码:
    1. '------------------- Module ---------------------------------------
    2. ' 2003-9-10
    3. ' 作者:任兀(DSclub)
    4. '
    5. '如果有问题
    6. '请E-Mail:dsclub@hotmail.com
    7. '
    8. '--------------------------------------------------------
    9. '--------------------------------------------------------
    10. '----------- 说明 -----------------
    11. '修改Private Const Margin As Long 的值可以改变吸附距离
    12. '将本模块考入你的程序,然后在你的代码中写入Hook和Unhook即可
    13. '
    14. '----------------------------------------------------------------

    15. Public Declare Function SystemParametersInfo Lib "user32.dll" Alias "SystemParametersInfoA" ( _
    16.      ByVal uAction As Long, _
    17.      ByVal uParam As Long, _
    18.      lpvParam As Any, _
    19.      ByVal fuWinIni As Long) As Long '去掉lpvParam的Byval修饰符才可以正常工作
    20.      
    21. Public Declare Function SetWindowLong Lib "user32.dll" Alias "SetWindowLongA" ( _
    22.      ByVal hwnd As Long, _
    23.      ByVal nIndex As Long, _
    24.      ByVal dwNewLong As Long) As Long
    25. Public Declare Function GetWindowLong Lib "user32.dll" Alias "GetWindowLongA" ( _
    26.      ByVal hwnd As Long, _
    27.      ByVal nIndex As Long) As Long
    28. Public Declare Function CallWindowProc Lib "user32.dll" Alias "CallWindowProcA" ( _
    29.      ByVal lpPrevWndFunc As Long, _
    30.      ByVal hwnd As Long, _
    31.      ByVal msg As Long, _
    32.      ByVal wParam As Long, _
    33.      ByVal lParam As Long) As Long
    34. Public Declare Sub CopyMemory Lib "kernel32.dll" Alias "RtlMoveMemory" ( _
    35.    Destination As Any, _
    36.    Source As Any, _
    37.    ByVal Length As Long)
    38.      
    39.      
    40. Public Type WINDOWPOS
    41.     hwnd As Long
    42.     hWndInsertAfter As Long
    43.     x As Long
    44.     y As Long
    45.     cx As Long
    46.     cy As Long
    47.     flags As Long
    48. End Type

    49. Public Type RECT
    50.     Left As Long
    51.     Top As Long
    52.     Right As Long
    53.     Bottom As Long
    54. End Type

    55. Public Const SPI_GETWORKAREA As Long = 48
    56. Public Const GWL_WNDPROC As Long = -4
    57. Public Const WM_WINDOWPOSCHANGING As Long = &H46

    58. Global lpPrevWndProc As Long
    59. Global gHW As Long
    60. Private Const Margin As Long = 20

    61. Public Sub Hook()
    62.    lpPrevWndProc = SetWindowLong(gHW, GWL_WNDPROC, AddressOf WindowProc)
    63. End Sub

    64. Public Sub Unhook()
    65.    Dim temp As Long
    66.    temp = SetWindowLong(gHW, GWL_WNDPROC, lpPrevWndProc)
    67. End Sub

    68. Function WindowProc(ByVal hw As Long, ByVal uMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
    69. Dim lpwndpos As WINDOWPOS
    70. Dim WorkArea As RECT

    71.     If uMsg = WM_WINDOWPOSCHANGING Then
    72.       SystemParametersInfo SPI_GETWORKAREA, 0, WorkArea, 0
    73.       CopyMemory lpwndpos, ByVal lParam, Len(lpwndpos)
    74.       
    75.       If lpwndpos.x - WorkArea.Left < Margin And WorkArea.Left - lpwndpos.x < Margin Then lpwndpos.x = 0
    76.       If lpwndpos.y - WorkArea.Top < Margin And WorkArea.Top - lpwndpos.y < Margin Then lpwndpos.y = 0
    77.       If WorkArea.Right - lpwndpos.x - lpwndpos.cx < Margin And lpwndpos.x + lpwndpos.cx - WorkArea.Right < Margin Then lpwndpos.x = WorkArea.Right - lpwndpos.cx
    78.       If WorkArea.Bottom - lpwndpos.y - lpwndpos.cy < Margin And lpwndpos.y + lpwndpos.cy - WorkArea.Bottom < Margin Then lpwndpos.y = WorkArea.Bottom - lpwndpos.cy
    79.       
    80.       CopyMemory ByVal lParam, lpwndpos, Len(lpwndpos)
    81.     End If
    82.    
    83.     WindowProc = CallWindowProc(lpPrevWndProc, hw, uMsg, wParam, lParam)
    84. End Function
    复制代码
    3、在Form1的代码中键入:
    1. Private Sub Form_Load()
    2.   gHW = Me.hwnd
    3.   Hook
    4. End Sub

    5. Private Sub Form_Unload(Cancel As Integer)
    6.   Unhook
    7. End Sub
    复制代码
    4、运行。

    该用户从未签到

    xueming 发表于 2010-4-10 17:28:58 | 显示全部楼层
    COPY去看看

    该用户从未签到

    maowei 发表于 2010-9-29 11:54:18 | 显示全部楼层
    看看!!!!!!!!!!!!!!!!
    您需要登录后才可以回帖 登录 | 注册

    本版积分规则

    免责声明

    本站中所有被研究的素材与信息全部来源于互联网,版权争议与本站无关。本站所发布的任何软件编程开发或软件的逆向分析文章、逆向分析视频、补丁、注册机和注册信息,仅限用于学习和研究软件安全的目的。全体用户必须在下载后的24个小时之内,从您的电脑中彻底删除上述内容。学习编程开发技术或逆向分析技术是为了更好的完善软件可能存在的不安全因素,提升软件安全意识。所以您如果喜欢某程序,请购买注册正版软件,获得正版优质服务!不得将上述内容私自传播、销售或者用于商业用途!否则,一切后果请用户自负!

    QQ|Archiver|手机版|小黑屋|联系我们|宝峰科技 ( 滇公网安备 53050202000040号 | 滇ICP备09007156号-2 )

    Copyright © 2001-2023 Discuz! Team. GMT+8, 2024-12-22 19:50 , File On Powered by Discuz! X3.49

    快速回复 返回顶部 返回列表