Search Tools Links Login

Subclassing without using the AdressOf-Operator

This code simulates subclassing without the AdressOf-Operator. It's much safer than the "SetWindowLong-Method". The code shows a MessageBox when you click on the form (it's only a simple example!)

Original Author: Stephan Kirchmaier

API Declarations

see code, PS: You must press a button to end the programm and the app must start with Sub Main!
PPS: Vote 4 me , pls.!


Option Explicit
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
  PostQuitMessage 0&
End Sub
Option Explicit
Public Declare Function PeekMessage Lib "user32" Alias "PeekMessageA" (lpMsg As msg, ByVal hwnd As Long, ByVal wMsgFilterMin As Long, ByVal wMsgFilterMax As Long, ByVal wRemoveMsg As Long) As Long
Public Declare Function DispatchMessage Lib "user32" Alias "DispatchMessageA" (lpMsg As msg) As Long
Public Declare Function TranslateMessage Lib "user32" (lpMsg As msg) As Long
Public Declare Sub PostQuitMessage Lib "user32" (ByVal nExitCode As Long)
Public Type POINTAPI
  x As Long
  y As Long
End Type
Public Type msg
  hwnd As Long
  message As Long
  wParam As Long
  lParam As Long
  time As Long
End Type
Public Const PM_REMOVE = &H1
Public Const WM_QUIT = &H12
Public Const WM_RBUTTONDOWN = &H204
Private Sub Main()
  Dim tMsg As msg
  Load Form1
    If PeekMessage(tMsg, 0, 0, 0, PM_REMOVE) Then
      If tMsg.message = WM_QUIT Then Exit Do
      If tMsg.message = WM_RBUTTONDOWN Then
        MsgBox "You clicked the right mousebutton!" & vbCr & "Press a key to end the app"
      End If
      TranslateMessage tMsg
      DispatchMessage tMsg
      'There's nothing to do for your App!
      'In a game you could draw a new frame,
      'this is much faster than using the Timer!
    End If
  Loop Until False
  Unload Form1
End Sub

About this post

Posted: 2002-06-01
By: ArchiveBot
Viewed: 94 times


Visual Basic 6


No attachments for this post

Loading Comments ...


No comments have been added for this post.

You must be logged in to make a comment.