Attribute VB_Name = "Module1"
Option Explicit
Public Const WM_NCHITTEST = &H84 '移动鼠标,按住或释放鼠标时产生此消息
Public Const HTCAPTION = 2 '不返回给系统
Public Const HTCLIENT = 1 '正常返回给系统
Public Const WM_NCACTIVATE = &H86 '通过改变某个窗口的非客户区来表示窗口是处于激活还是非激活状态时,此消息被发送给该窗口
Public Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
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 Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Public Const GWL_WNDPROC = -4 '为窗口设定一个新的处理函数。
Global lpPrevWndProc As Long
Private ab As Boolean
' 这里是关键,我自定义了一个窗口函数(回调函数),以替代 VB 窗体自己的默认窗口函数。' 窗口函数是干什么的?它就是负责处理 Windows 发送给它的消息,并加以过滤,筛选出它感兴趣' 的消息,映射成为事件供我们使用。VB 中每个窗口都有一个默认的窗口函数,我们是看不到的。' 有很多消息都被 VB 的默认窗口函数过滤掉了。了解 C/C++/Delphi 程序设计的朋友应该知道这些。
Function WindowProc(ByVal hw As Long, ByVal uMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
' 我们也进行消息过滤,不过我们指拦截我们感兴趣的消息
' 其他消息我们懒得处理,交给 VB 默认的窗口函数去处理吧。
If uMsg <> "307" Then
'frmChild.Text1 = frmChild.Text1 & "," & uMsg
End If
Select Case uMsg
Case WM_NCACTIVATE ' 拦截 通过改变某个窗口的非客户区来表示窗口是处于激活还是非激活状态时,此消息被发送给该窗口
If ab = False Then
'ab = True
frmChild.Text1 = frmChild.Text1 & "," & uMsg
frm3.Show vbModal
End If
WindowProc = HTCLIENT
Exit Function '不返回给系统
' Else
' ' 其他的我们不管,还是规规矩矩的该怎么样就怎么样
' WindowProc = HTCLIENT
' Exit Function
' End If
End Select
' 这里又是关键,因为其他我们不关心的消息我们自己不处理,所以必须由 VB 的默认处理函数处理
' lpPrevWndProc 其实就是一个函数指针,它指向 VB 默认窗口函数
WindowProc = CallWindowProc(lpPrevWndProc, hw, uMsg, wParam, lParam)
End Function
VERSION 5.00
Begin VB.Form frmMain
Caption = "Form1"
ClientHeight = 4575
ClientLeft = 120
ClientTop = 450
ClientWidth = 8235
LinkTopic = "Form1"
ScaleHeight = 4575
ScaleWidth = 8235
StartUpPosition = 3 '窗口缺省
Begin VB.CommandButton Command1
Caption = "Command1"
Height = 615
Left = 1560
TabIndex = 0
Top = 360
Width = 1455
End
End
Attribute VB_Name = "frmMain"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private Sub Command1_Click()
frmChild.Show 1
End Sub
VERSION 5.00
Begin VB.Form frmChild
Caption = "Form1"
ClientHeight = 6660
ClientLeft = 120
ClientTop = 450
ClientWidth = 11385
LinkTopic = "Form1"
ScaleHeight = 6660
ScaleWidth = 11385
StartUpPosition = 3 '窗口缺省
Begin VB.TextBox Text1
Height = 6615
Left = 0
MultiLine = -1 'True
TabIndex = 0
Top = 0
Width = 11415
End
End
Attribute VB_Name = "frmChild"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private Sub Form_Load()
'gHW = Me.hwnd ' 保存窗体的句柄
' 下面是关键,完成两个工作:1、将我们自己的全局函数替换为新的窗体回调函数
' 2、保存原来的 VB 默认窗户口函数地址
lpPrevWndProc = SetWindowLong(Me.hwnd, GWL_WNDPROC, AddressOf WindowProc)
End Sub
下载地址源于:http://www.gycehuags.com/news/670.html
标签:Function,VB,窗口,frmChild,处理,ByVal,Long,VB6.0,window From: https://www.cnblogs.com/gycehuags/p/17207667.html