home *** CD-ROM | disk | FTP | other *** search
/ Planet Source Code Jumbo …e CD Visual Basic 1 to 7 / 4_2005-2006.ISO / data / Zips / CodeHelp_A1935969282005.psc / CHCore / cSubclass.cls < prev   
Text File  |  2005-09-08  |  6KB  |  97 lines

  1. VERSION 1.0 CLASS
  2. BEGIN
  3.   MultiUse = -1  'True
  4.   Persistable = 0  'NotPersistable
  5.   DataBindingBehavior = 0  'vbNone
  6.   DataSourceBehavior  = 0  'vbNone
  7.   MTSTransactionMode  = 0  'NotAnMTSObject
  8. END
  9. Attribute VB_Name = "cSubclass"
  10. Attribute VB_GlobalNameSpace = False
  11. Attribute VB_Creatable = True
  12. Attribute VB_PredeclaredId = False
  13. Attribute VB_Exposed = False
  14. Attribute VB_Ext_KEY = "SavedWithClassBuilder6" ,"Yes"
  15. Attribute VB_Ext_KEY = "Top_Level" ,"Yes"
  16. '==================================================================================================
  17. 'cSubclass - module-less, IDE safe, machine code subclassing thunk
  18. '
  19. 'Paul_Caton@hotmail.com
  20. 'Copyright free, use and abuse as you see fit.
  21. '
  22. 'v1.00 20030107 First cut..........................................................................
  23. 'v1.01 20031118 Allow control over callback gating
  24. '               Use global memory for the machine code buffer
  25. '               Reform the assembler...............................................................
  26. 'v1.02 20040118 Use EbMode for breakpoint/stop detection rather than callback gating
  27. '               Further reform the assembler for greater speed and smaller size
  28. '               Made InIDE public..................................................................
  29. '
  30. '==================================================================================================
  31. Option Explicit
  32. Private Declare Function IsBadReadPtr _
  33.                 Lib "kernel32.dll" (lp As Any, _
  34.                                     ByVal ucb As Long) As Long
  35.  
  36. Private Const PATCH_05  As Long = 93                        'Table B (before) entry count
  37. Private Const PATCH_09  As Long = 137                       'Table A (after) entry count
  38.  
  39. Private nMsgCntB        As Long                             'Before msg table entry count
  40. Private nMsgCntA        As Long                             'After msg table entry count
  41. Private aMsgTblB()      As Long                 'Before msg table array
  42. Private aMsgTblA()      As Long                 'After msg table array
  43. Private hWndSub         As Long                             'Handle of the window being subclassed
  44. Private nAddrSubclass   As Long                             'The address of our WndProc
  45. Private nAddrOriginal   As Long                             'The address of the existing WndProc
  46.  
  47. Public Enum enMsgWhen
  48.     MSG_AFTER = 1&
  49.     MSG_BEFORE = 2&
  50.     MSG_BEFORE_AND_AFTER = 3&
  51.     ALL_MESSAGES = &HFFFFFFFF
  52. End Enum
  53.  
  54. '============================================
  55. 'Class creation/destruction
  56. '============================================
  57.  
  58. 'Build the subclass thunk into allocated memory
  59. Private Sub Class_Initialize()
  60.     Const PATCH_01 As Long = 18                                 'Code buffer offset to the location of the relative address to EbMode
  61.     Const PATCH_03 As Long = 78                                 'Relative address of SetWindowsLong
  62.     Const PATCH_07 As Long = 121                                'Relative address of CallWindowProc
  63.     Const FUNC_EBM As String = "EbMode"                         'VBA's EbMode function allows the machine code thunk to know if the IDE has stopped or is on a breakpoint
  64.     Const FUNC_SWL As String = "SetWindowLongA"                 'SetWindowLong allows the cSubclasser machine code thunk to unsubclass the subclasser itself if it detects via the EbMode function that the IDE has stopped
  65.     Const FUNC_CWP As String = "CallWindowProcA"                'We use CallWindowProc to call the original WndProc
  66.     Const MOD_VBA5 As String = "vba5"                           'Location of the EbMode function if running VB5
  67.     Const MOD_VBA6 As String = "vba6"                           'Location of the EbMode function if running VB6
  68.     Const MOD_USER As String = "user32"                         'Location of the SetWindowLong & CallWindowProc functions
  69.     Dim i        As Long                                      'Loop index
  70.     Dim nLen     As Long                                      'String lengths
  71.     Dim sHex     As String                                    'Hex code string
  72.     Dim sCode    As String                                    'Binary code string
  73.   
  74.     'Store the hex pair machine code representation in sHex
  75.     sHex = "5589E583C4F85731C08945FC8945F8EB0EE8xxxxx01x83F802742185C07424E830000000837DF800750AE838000000E84D0000005F8B45FCC9C21000E826000000EBF168xxxxx02x6AFCFF7508E8xxxxx03xEBE031D24ABFxxxxx04xB9xxxxx05xE82D000000C3FF7514FF7510FF750CFF750868xxxxx06xE8xxxxx07x8945FCC331D2BFxxxxx08xB9xxxxx09xE801000000C3E32F09C978078B450CF2AF75248D4514508D4510508D450C508D4508508D45FC508D45F85052B8xxxxx0Ax508B00FF501CC3"
  76.     nLen = Len(sHex)                                          'Length of hex pair string
  77.   
  78.     'Convert the string from hex pairs to bytes and store in the ASCII string opcode buffer
  79.     For i = 1 To nLen Step 2                                  'For each pair of hex characters
  80.         sCode = sCode & ChrB$(Val("&H" & Mid$(sHex, i, 2)))     'Convert a pair of hex characters to a byte and append to the ASCII string
  81.     Next i                                                    'Next pair
  82.   
  83.     nLen = LenB(sCode)                                        'Get the machine code length
  84.     nAddrSubclass = GlobalAlloc(0, nLen)                      'Allocate fixed memory for machine code buffer
  85.  
  86.     'Copyhe exibcode buffer
  87.  
  88.     'Copy))      'Allockffer
  89.  
  90.     'Copy))   tocatuode th    'Copy))      e        nAddrSubclass = GlobalAlloc(0, nLen)                      'Allocate fixed memor'FlvR5eBopy)0  'vbNone
  91. bclassg
  92.  
  93. Priv
  94. End Enum
  95.  
  96. '==Sa-edIdE 'CopyPaul_Catr2String   (
  97.