Atlanta Custom Software Development 

 
   Search        Code/Page
 

User Login
Email

Password

 

Forgot the Password?
Services
» Web Development
» Maintenance
» Data Integration/BI
» Information Management
Programming
  Database
Automation
OS/Networking
Graphics
Links
Tools
» Regular Expr Tester
» Free Tools

How to Subclass a Form

Total Hit ( 3751)

Rate this article:     Poor     Excellent 

 Submit Your Question/Comment about this article

Rating


 


Click here to copy the following block
'==============inside a MODULE
Option Explicit
'************************************************************
'API
'************************************************************

Private Declare Function CallWindowProc Lib "user32.dll" Alias "CallWindowProcA" ( _
  ByVal lpPrevWndFunc As Long, _
  ByVal hWnd As Long, _
  ByVal Msg As Long, _
  ByVal wParam As Long, _
  ByVal lParam As Long) As Long
Private Declare Function SetWindowLong Lib "user32.dll" Alias "SetWindowLongA" ( _
  ByVal hWnd As Long, _
  ByVal nIndex As Long, _
  ByVal dwNewLong As Long) As Long

'************************************************************
'Constants
'************************************************************

Private Const GWL_WNDPROC = -4
Private Const WM_MOUSEMOVE = &H200

'************************************************************
'Variables
'************************************************************

Private hControl As Long
Private lPrevWndProc As Long

Module

Click here to copy the following block
'*************************************************************
'WindowProc
'*************************************************************
Private Function WindowProc(ByVal lWnd As Long, ByVal lMsg As Long, _
  ByVal wParam As Long, ByVal lParam As Long) As Long
  'Selects which messages you want to detect
  Select Case lMsg
    'Example:
    Case WM_MOUSEMOVE
      Form1.Label1.Caption = "MouseMove(" & lMsg & ") Buttons=" & wParam & _
      " Y=" & (lParam Mod 65536) & " X=" & (lParam \ 65535)
  End Select
  'Sends message to previous procedure
  'This is VERY IMPORTANT!!!
  WindowProc = CallWindowProc(lPrevWndProc, lWnd, lMsg, wParam, lParam)
End Function

'*************************************************************
'Hook
'*************************************************************
Public Sub Hook(ByVal hControl_ As Long)
  hControl = hControl_
  lPrevWndProc = SetWindowLong(hControl, GWL_WNDPROC, AddressOf WindowProc)
End Sub

'*************************************************************
'Unhook
'*************************************************************
Public Sub Unhook()
  Call SetWindowLong(hControl, GWL_WNDPROC, lPrevWndProc)
End Sub

Usage

Click here to copy the following block
'Create a Form with a label
Option Explicit

'===========inside a form
'*************************
'USAGE
'*************************

Private Sub Form_Load()
  Hook Form1.hWnd
End Sub

Private Sub Form_Unload(Cancel As Integer)
  Unhook
End Sub


Submitted By : Nayan Patel  (Member Since : 5/26/2004 12:23:06 PM)

Job Description : He is the moderator of this site and currently working as an independent consultant. He works with VB.net/ASP.net, SQL Server and other MS technologies. He is MCSD.net, MCDBA and MCSE. In his free time he likes to watch funny movies and doing oil painting.
View all (893) submissions by this author  (Birth Date : 7/14/1981 )


Home   |  Comment   |  Contact Us   |  Privacy Policy   |  Terms & Conditions   |  BlogsZappySys

© 2008 BinaryWorld LLC. All rights reserved.