⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 apiwindow.cls

📁 几个不错的VB例子
💻 CLS
📖 第 1 页 / 共 5 页
字号:
VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
END
Attribute VB_Name = "ApiWindow"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = True
Attribute VB_Ext_KEY = "SavedWithClassBuilder" ,"Yes"
Attribute VB_Ext_KEY = "Top_Level" ,"Yes"
Option Explicit

' ##MODULE_DESCRIPTION This class provides the properties, events and methods used _
to manipulate any given window.

' ##MODULE_DESCRIPTION Using this class and the %subclassed windows collection:EventVB~APIFunctions~SubclassedWindows% _
provides you with access to a large number of new events in addition to those that are _
exposed by Visual basic forms and also allows you to respond to events in windows that _
were not created by Visual Basic using the familiar syntax.

'\\ New window events --------------------------------------------------------------------------------------------------------------------------------------------------------------
' ##EVENT_DESCRIPTION WindowMessageFired Triggered for any message not dealt with by the other more specific events
' ##EVENT_REMARKS WindowMessageFired
Public Event WindowMessageFired(ByVal msg As WindowMessages, ByVal wParam As Long, ByVal lParam As Long, Cancel As Boolean, ProcRet As Long)

' ##EVENT_DESCRIPTION ActiveApplicationChanged Triggered when the subclassed window is a top level window of an application and the user swicthes to or from that application (using ALT+TAB or the mouse)
' ##EVENT_REMARKS ActiveApplicationChanged This event is only fired if the window is in the thread losing the focus or the thread gaining the focus
Public Event ActiveApplicationChanged(ByVal ActivatingThisApp As Boolean, ByVal hThread As Long, Cancel As Boolean)

' ##EVENT_DESCRIPTION LostCapture Triggered when the subclassed window loses the mouse capture. _
In normal operation this occurs when the mouse leaves the window.
' ##EVENT_REMARKS LostCapture This event will not be triggered if a window has explicitly captured the mouse input.
Public Event LostCapture(ByVal hwndNewCapture As Long, Cancel As Boolean)

' ##EVENT_DESCRIPTION KeyPressed Triggered when any key is pressed whle the subclassed window has the input focus.
' ##EVENT_REMARKS KeyPressed This event provides additional information beyond the intrinsic form_Keypressed event.
Public Event KeyPressed(ByVal VKey As Long, ByVal Repetition As Long, ByVal scanCode As Long, ByVal ExtendedKey As Boolean, ByVal AltDown As Boolean, ByVal AlreadyDown As Boolean, ByVal BeingPressed As Boolean, Cancel As Boolean)

' ##EVENT_DESCRIPTION LowMemory Triggered when the available memory on a system is low and the system is required to try and compact the memory to free some space.
' ##EVENT_REMARKS LowMemory The TimeSpentCompacting increases as the memory situation gets worse.  You should free up any possible memory you can _
in response to this event.
Public Event LowMemory(ByVal TimeSpentCompacting As Long)

' ##EVENT_DESCRIPTION Move Triggered when a form is moved, by dragging or through code.
' ##EVENT_REMARKS Move The x and y parameters indicate the position of the top left corner of the window.
Public Event Move(ByVal x As Long, ByVal y As Long, Cancel As Boolean)

' ##EVENT_DESCRIPTION VerticalScroll Triggered when the user interacts with a vertical scrollbar on a window.
' ##EVENT_REMARKS VerticalScroll The message parameter tells you what operation the user performed.
Public Event VerticalScroll(ByVal Message As enScrollMessages, ByVal Position As Long, Cancel As Boolean)

' ##EVENT_DESCRIPTION HorizontalScroll Triggered when the user interacts with a horizontal scrollbar on a window.
' ##EVENT_REMARKS HorizontalScroll The message parameter tells you what operation the user performed.
Public Event HorizontalScroll(ByVal Message As enScrollMessages, ByVal Position As Long, Cancel As Boolean)

' ##EVENT_DESCRIPTION WindowsSettingsChanged Triggered when the system settings changed.
' ##EVENT_REMARKS WindowsSettingsChanged newSetting describes which type of setting changed.
Public Event WindowsSettingsChanged(ByVal newSetting As enSystemParametersInfo)

' ##EVENT_DESCRIPTION WindowsINIChanged Triggered when a setting stored in the WIN.INI is changed.
' ##EVENT_REMARKS WindowsINIChanged Section is the major section e.g. [INTL] that has been changed
Public Event WindowsINIChanged(ByVal Section As String)

' ##EVENT_DESCRIPTION NonClientMouseMove Triggered when the mouse is moved over the non client area of the window.
' ##EVENT_REMARKS NonClientMouseMove The non client area includes the caption bar, menu bar etc.
Public Event NonClientMouseMove(ByVal Location As enHitTestResult, ByVal x As Single, ByVal y As Single)

' ##EVENT_DESCRIPTION NonClientMouseDown Triggered when the mouse button is pressed while the cursor is over a non client part of the window.
' ##EVENT_REMARKS NonClientMouseDown The non client area includes the caption bar, menu bar etc.
Public Event NonClientMouseDown(ByVal Location As enHitTestResult, ByVal Button As Integer, ByVal x As Single, ByVal y As Single)

' ##EVENT_DESCRIPTION NonClientMouseUp Triggered when the mouse button is released while the cursor is over a non client part of the window.
' ##EVENT_REMARKS NonClientMouseUp The non client area includes the caption bar, menu bar etc.
Public Event NonClientMouseUp(ByVal Location As enHitTestResult, ByVal Button As Integer, ByVal x As Single, ByVal y As Single)

' ##EVENT_DESCRIPTION NonClientDblClick Triggered when the mouse button is double-clicked while the cursor is over a non client part of the window.
' ##EVENT_REMARKS NonClientDblClick The non client area includes the caption bar, menu bar etc.
Public Event NonClientDblClick(ByVal Location As enHitTestResult, ByVal Button As Integer, ByVal x As Single, ByVal y As Single)

' ##EVENT_DESCRIPTION MinMaxSize Triggered when the operating system wishes to know the minimum and maximum sizes of the window.
' ##EVENT_REMARKS MinMaxSize Changing any of the min or max values will prevent the window being resized outside of that size. _
This is very useful for creating docking style windows.
Public Event MinMaxSize(MaxHeight As Long, MaxWidth As Long, MaxPositionTop As Long, MaxPositionLeft As Long, MinTrackWidth As Long, MinTrackheight As Long, MaxTrackWidth As Long, MaxTrackHeight As Long)

' ##EVENT_DESCRIPTION MouseOverMenu Triggered when the mouse is moved over a top level menu bar item.
' ##EVENT_REMARKS MouseOverMenu You can use this event to provide feedback to the user about what a given menu is used for.
Public Event MouseOverMenu(ByVal Caption As String)

' ##EVENT_DESCRIPTION Hotkey Triggered when a %hotkey:EventVB~ApiHotkey% that has been registered for this window is pressed.
' ##EVENT_REMARKS Hotkey Currently a window can only have one hotkey registered to it at any time.
Public Event Hotkey(ByVal Hotkey As ApiHotkey)

' ##EVENT_DESCRIPTION Paint Triggered when all or part of the form needs to be repainted.
' ##EVENT_REMARKS Paint Use this event for owner drawn controls, for example.
Public Event Paint(ByVal UpdateRect As APIRect)

' ##EVENT_DESCRIPTION NonClientPaint Triggered when all or part of the non client area needs to be repainted.
' ##EVENT_REMARKS NonClientPaint This event can be used to implement customised non client areas - like skins.
Public Event NonClientPaint(ByVal NonClientDeviceContext As ApiDeviceContext)

' ##EVENT_DESCRIPTION HitTest Triggered when windows wants to know what part of the form the mouse is over (client, caption., menu etc.)
' ##EVENT_REMARKS HitTest Overriding this event alters the way windows behaves.  Using this you can allow a window with no border to be _
moved or resized, for example.
Public Event HitTest(ByVal x As Long, ByVal y As Long, ReturnValue As enHitTestResult, Override As Boolean)


Private m_hwnd As Long

'\\ API Declarations -------------------------------------------------------------------------------------------------------------------------------------------------------
Private Declare Function IsWindowApi Lib "user32" Alias "IsWindow" (ByVal hwnd As Long) As Long
Private Declare Function GetParentApi Lib "user32" Alias "GetParent" (ByVal hwnd As Long) As Long
Private Declare Function WindowFromPointApi Lib "user32" Alias "WindowFromPoint" (ByVal xPoint As Long, ByVal yPoint As Long) As Long
Private Declare Function GetWindowApi Lib "user32" Alias "GetWindow" (ByVal hwnd As Long, ByVal wCmd As Long) As Long
Private Declare Function IsWindowEnabledApi Lib "user32" Alias "IsWindowEnabled" (ByVal hwnd As Long) As Long
Private Declare Function IsWindowUnicodeApi Lib "user32" Alias "IsWindowUnicode" (ByVal hwnd As Long) As Long
Private Declare Function IsWindowVisibleApi Lib "user32" Alias "IsWindowVisible" (ByVal hwnd As Long) As Long
Private Declare Function IsZoomedApi Lib "user32" Alias "IsZoomed" (ByVal hwnd As Long) As Long
'\\ Window specific information
Private Declare Function GetWindowLongApi Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
Private Declare Function SetWindowLongApi Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
'\\ Menu specific....
Private Declare Function GetSystemMenuApi Lib "user32" Alias "GetSystemMenu" (ByVal hwnd As Long, ByVal bRevert As Long) As Long
Private Declare Function GetMenuApi Lib "user32" Alias "GetMenu" (ByVal hwnd As Long) As Long
'\\ Device context specific....
Private Declare Function GetDCApi Lib "user32" Alias "GetDC" (ByVal hwnd As Long) As Long
Private Declare Function GetWindowDC Lib "user32" (ByVal hwnd As Long) As Long
'\\ Window class specific...
Private Declare Function GetClassNameApi Lib "user32" Alias "GetClassNameA" (ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long
'\\ Send message....
Private Declare Function SendMessageLong Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Private Declare Function InvalidateRectByPointerApi Lib "user32" Alias "InvalidateRect" (ByVal hwnd As Long, ByVal lpRect As Long, ByVal bErase As Long) As Long
'\\ Scrolling....
Private Type RECT
    Left As Long
    Top As Long
    Right As Long
    Bottom As Long
End Type
Private Declare Function GetWindowRectApi Lib "user32" Alias "GetWindowRect" (ByVal hwnd As Long, lpRect As RECT) As Long
Private Declare Function ScrollWindowExAPI Lib "user32" Alias "ScrollWindowEx" (ByVal hwnd As Long, ByVal dX As Long, ByVal dY As Long, ByVal lprcScroll As Long, ByVal lprcClip As Long, ByVal hrgnUpdate As Long, lprcUpdate As RECT, ByVal fuScroll As Long) As Long
'\\ Mouse message capture
Private Declare Function SetCaptureApi Lib "user32" Alias "SetCapture" (ByVal hwnd As Long) As Long
Private Declare Function GetCaptureApi Lib "user32" Alias "GetCapture" () As Long
'\\ Windows regions.....
Private Declare Function GetWindowRgn Lib "user32" (ByVal hwnd As Long, ByVal hRgn As Long) As Long
Private Declare Function SetWindowRgn Lib "user32" (ByVal hwnd As Long, ByVal hRgn As Long, ByVal bRedraw As Boolean) As Long
'\\ Refreshing the window states....
Private Declare Function DrawMenuBarApi Lib "user32" Alias "DrawMenuBar" (ByVal hwnd As Long) As Long
'\\ Window text...
Private Declare Function GetWindowTextLengthApi Lib "user32" Alias "GetWindowTextLengthA" (ByVal hwnd As Long) As Long
Private Declare Function GetWindowTextApi Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
'\\ Painting the window,
Private Declare Function GetUpdateRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT, ByVal bErase As Long) As Long
Private Declare Function UpdateWindow Lib "user32" (ByVal hwnd As Long) As Long

'\\ Non-client area painting...
Private Declare Function GetDCEx Lib "user32" (ByVal hwnd As Long, ByVal hrgnclip As Long, ByVal fdwOptions As Long) As Long
Public Enum ExtendedDeviceContextIndexes
    DCX_WINDOW = &H1
    DCX_CACHE = &H2
    DCX_NORESETATTRS = &H4
    DCX_CLIPCHILDREN = &H8
    DCX_CLIPSIBLINGS = &H10
    DCX_PARENTCLIP = &H20
    DCX_EXCLUDERGN = &H40
    DCX_INTERSECTRGN = &H80
    DCX_EXCLUDEUPDATE = &H100
    DCX_INTERSECTUPDATE = &H200
    DCX_LOCKWINDOWUPDATE = &H400
    DCX_VALIDATE = &H200000
End Enum

'\\ Set window pos...
Private 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) As Long
Private Declare Function ScreenToClient Lib "user32" (ByVal hwnd As Long, lpPoint As POINTAPI) As Long

Public Enum enSetWindowPos
    SWP_FRAMECHANGED = &H20        '  The frame changed: send WM_NCCALCSIZE
    SWP_HIDEWINDOW = &H80
    SWP_NOACTIVATE = &H10
    SWP_NOCOPYBITS = &H100
    SWP_NOMOVE = &H2
    SWP_NOOWNERZORDER = &H200      '  Don't do owner Z ordering
    SWP_NOREDRAW = &H8
    SWP_NOSIZE = &H1
    SWP_NOZORDER = &H4
    SWP_SHOWWINDOW = &H40
End Enum

'\\ Getting information about a window's title bar...
Public Enum WindowSystemStates
    STATE_SYSTEM_UNAVAILABLE = &H1                '\\ Disabled
    STATE_SYSTEM_SELECTED = &H2
    STATE_SYSTEM_FOCUSED = &H4
    STATE_SYSTEM_PRESSED = &H8
    STATE_SYSTEM_CHECKED = &H10
    STATE_SYSTEM_MIXED = &H20                     '\\ 3-state checkbox or toolbar button
    STATE_SYSTEM_READONLY = &H40
    STATE_SYSTEM_HOTTRACKED = &H80
    STATE_SYSTEM_DEFAULT = &H100
    STATE_SYSTEM_EXPANDED = &H200
    STATE_SYSTEM_COLLAPSED = &H400
    STATE_SYSTEM_BUSY = &H800
    STATE_SYSTEM_FLOATING = &H1000                '\\ Children "owned" not "contained" by parent
    STATE_SYSTEM_MARQUEED = &H2000
    STATE_SYSTEM_ANIMATED = &H4000
    STATE_SYSTEM_INVISIBLE = &H8000
    STATE_SYSTEM_OFFSCREEN = &H10000
    STATE_SYSTEM_SIZEABLE = &H20000
    STATE_SYSTEM_MOVEABLE = &H40000
    STATE_SYSTEM_SELFVOICING = &H80000
    STATE_SYSTEM_FOCUSABLE = &H100000
    STATE_SYSTEM_SELECTABLE = &H200000
    STATE_SYSTEM_LINKED = &H400000
    STATE_SYSTEM_TRAVERSED = &H800000
    STATE_SYSTEM_MULTISELECTABLE = &H1000000      '\\ Supports multiple selection
    STATE_SYSTEM_EXTSELECTABLE = &H2000000        '\\ Supports extended selection
    STATE_SYSTEM_ALERT_LOW = &H4000000            '\\ This information is of low priority
    STATE_SYSTEM_ALERT_MEDIUM = &H8000000         '\\ This information is of medium priority
    STATE_SYSTEM_ALERT_HIGH = &H10000000          '\\ This information is of high priority
    STATE_SYSTEM_VALID = &H1FFFFFFF
End Enum

Private Type TITLEBARINFO
    cbSize As Long '\\ Size of this structure
    rcTitleBar As RECT '\\ Rectangle of the whole title bar except menu..
    rgstate(0 To 5) As Long '\\ Each is a combination of window_system_states
End Type
Private Declare Function GetTitleBarInfo Lib "user32" (ByVal hwnd As Long, lpTileBarInfo As TITLEBARINFO) As Long




'\\ Private member variables ----------------------------------------------------------------------------------------------------------------------------------------------------------
Private mOldProcAddress As Long
Private mPrevCapture As Long
'\\ Objects....
Private mSystemMenu As ApiMenu
Private mMenu As ApiMenu
Private mWndClass As APIWndClass
Private mRegion As ApiRegion
Private mDeviceContext As ApiDeviceContext
Private mDeviceContextNC As ApiDeviceContext

'\\ Setting of minmaxinfo....
Private Type POINTAPI
    x As Long
    y As Long
End Type

Private Type MINMAXINFO
    ptReserved As POINTAPI
    ptMaxSize As POINTAPI
    ptMaxPosition As POINTAPI
    ptMinTrackSize As POINTAPI
    ptMaxTrackSize As POINTAPI
End Type


'\\ Memory manipulation routines for min/max info
Private Declare Sub CopyMemoryMinMaxInfo Lib "kernel32" Alias "RtlMoveMemory" (Destination As MINMAXINFO, ByVal Source As Long, ByVal Length As Long)
Private Declare Sub CopyMinMaxToMemoryInfo Lib "kernel32" Alias "RtlMoveMemory" (ByVal Destination As Long, Source As MINMAXINFO, ByVal Length As Long)

'\\ message passing
Private Declare Function SendMessageByLong Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Private Declare Function SendMessageByString Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As String) As Long

'\\ Threads...
Private Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As Long, lpdwProcessId As Long) As Long

Public Enum enComboBoxNotifications
    CBN_CLOSEUP = 8
    CBN_DBLCLK = 2
    CBN_DROPDOWN = 7
    CBN_EDITCHANGE = 5
    CBN_EDITUPDATE = 6
    CBN_ERRSPACE = (-1)
    CBN_KILLFOCUS = 4
    CBN_SELCHANGE = 1
    CBN_SELENDCANCEL = 10
    CBN_SELENDOK = 9
    CBN_SETFOCUS = 3
End Enum

Public Enum enListBoxNotifications
    LBN_DBLCLK = 2
    LBN_ERRSPACE = (-2)
    LBN_KILLFOCUS = 5
    LBN_SELCANCEL = 3
    LBN_SELCHANGE = 1
    LBN_SETFOCUS = 4
End Enum

Public Enum enEditBoxNotifications
    EN_CHANGE = &H300
    EN_ERRSPACE = &H500
    EN_HSCROLL = &H601
    EN_KILLFOCUS = &H200
    EN_MAXTEXT = &H501
    EN_SETFOCUS = &H100
    EN_UPDATE = &H400
    EN_VSCROLL = &H602
End Enum

Public Enum enCommonControlGenericNotifications
    NM_OUTOFMEMORY = (-1)
    NM_CLICK = (-2)                  ''\\ uses NMCLICK struct
    NM_DBLCLK = (-3)
    NM_RETURN = (-4)
    NM_RCLICK = (-5)                 ''\\ uses NMCLICK struct
    NM_RDBLCLK = (-6)
    NM_SETFOCUS = (-7)
    NM_KILLFOCUS = (-8)
    NM_CUSTOMDRAW = (-12)
    NM_HOVER = (-13)
    NM_NCHITTEST = (-14)             ''\\ uses NMMOUSE struct
    NM_KEYDOWN = (-15)               ''\\ uses NMKEY struct
    NM_RELEASEDCAPTURE = (-16)
    NM_SETCURSOR = (-17)             ''\\ uses NMMOUSE struct
    NM_CHAR = (-18)                  ''\\ uses NMCHAR struct
End Enum

Private Const LVN_FIRST = -100
Public Enum enListviewNotificationMessages
    LVN_ITEMCHANGING = (LVN_FIRST - 0)
    LVN_ITEMCHANGED = (LVN_FIRST - 1)
    LVN_INSERTITEM = (LVN_FIRST - 2)
    LVN_DELETEITEM = (LVN_FIRST - 3)
    LVN_DELETEALLITEMS = (LVN_FIRST - 4)
    LVN_BEGINLABELEDITA = (LVN_FIRST - 5)
    LVN_BEGINLABELEDITW = (LVN_FIRST - 75)
    LVN_ENDLABELEDITA = (LVN_FIRST - 6)
    LVN_ENDLABELEDITW = (LVN_FIRST - 76)
    LVN_COLUMNCLICK = (LVN_FIRST - 8)
    LVN_BEGINDRAG = (LVN_FIRST - 9)
    LVN_BEGINRDRAG = (LVN_FIRST - 11)
    LVN_ODCACHEHINT = (LVN_FIRST - 13)
    LVN_ODFINDITEMA = (LVN_FIRST - 52)
    LVN_ODFINDITEMW = (LVN_FIRST - 79)
    LVN_ITEMACTIVATE = (LVN_FIRST - 14)
    LVN_ODSTATECHANGED = (LVN_FIRST - 15)
End Enum

Private Const HDN_FIRST = -300
Public Enum enHeaderNotificationMessages
    HDN_ITEMCHANGINGA = (HDN_FIRST - 0)
    HDN_ITEMCHANGINGW = (HDN_FIRST - 20)
    HDN_ITEMCHANGEDA = (HDN_FIRST - 1)
    HDN_ITEMCHANGEDW = (HDN_FIRST - 21)
    HDN_ITEMCLICKA = (HDN_FIRST - 2)
    HDN_ITEMCLICKW = (HDN_FIRST - 22)
    HDN_ITEMDBLCLICKA = (HDN_FIRST - 3)
    HDN_ITEMDBLCLICKW = (HDN_FIRST - 23)
    HDN_DIVIDERDBLCLICKA = (HDN_FIRST - 5)
    HDN_DIVIDERDBLCLICKW = (HDN_FIRST - 25)
    HDN_BEGINTRACKA = (HDN_FIRST - 6)
    HDN_BEGINTRACKW = (HDN_FIRST - 26)
    HDN_ENDTRACKA = (HDN_FIRST - 7)
    HDN_ENDTRACKW = (HDN_FIRST - 27)
    HDN_TRACKA = (HDN_FIRST - 8)
    HDN_TRACKW = (HDN_FIRST - 28)
    HDN_GETDISPINFOA = (HDN_FIRST - 9)
    HDN_GETDISPINFOW = (HDN_FIRST - 29)
    HDN_BEGINDRAG = (HDN_FIRST - 10)

⌨️ 快捷键说明

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