module1.bas

来自「这里有很多很实用的VB编程案例,方便大家学习VB.」· BAS 代码 · 共 61 行

BAS
61
字号
Attribute VB_Name = "Module1"

Option Explicit

Declare Function EnumChildWindows Lib "user32" _
   (ByVal hWndParent As Long, ByVal lpEnumFunc As Long, _
   ByVal lParam As Long) As Long
Declare Function GetClassName Lib "user32" Alias "GetClassNameA" _
       (ByVal hwnd As Long, ByVal lpClassName As String, _
        ByVal nMaxCount As Long) As Long
Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" _
  (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" _
  (ByVal hwnd As Long, ByVal nIndex As Long) As Long
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 Const GWL_WNDPROC = (-4)
Public Const WM_MOUSEMOVE = &H200
Public Const WM_RBUTTONDOWN = &H204
Public preWinProc As Long
Private hEditWnd As Long

Public Function wndproc(ByVal hwnd As Long, ByVal Msg As Long, _
                         ByVal wParam As Long, ByVal lParam As Long) As Long
 '以下会截取mouse Rbutton Down。
 If Msg = WM_RBUTTONDOWN Then
    Debug.Print "Combol Mouse RButton Down "
 Else
 '将之送往原来的Window Procedure。
    wndproc = CallWindowProc(preWinProc, hwnd, Msg, wParam, lParam)
 End If
 End Function
Public Function FindEditInCombo(ctl As ComboBox) As Long
 Call EnumChildWindows(ctl.hwnd, AddressOf EnumFunc, 0)
 FindEditInCombo = hEditWnd
End Function

Public Function EnumFunc(ByVal hwnd As Long, ByVal lParam As Long) As Long
Dim ClsName As String
Dim lentxt As Long
If hwnd = 0 Then
   EnumFunc = 0
Else
   ClsName = String(255, 0)
   lentxt = GetClassName(hwnd, ClsName, 256)
   ClsName = Left(ClsName, lentxt)
   If ClsName = "Edit" Then
      hEditWnd = hwnd
      EnumFunc = 0
   Else
      EnumFunc = 1
   End If
End If
End Function




⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?