473,246 Members | 1,492 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes and contribute your articles to a community of 473,246 developers and data experts.

How To Handle More events Visual Basic 6.0 Not Support

112 100+
Hi Every one...

With this visual Basic 6.0 Code you can handle more event that visual basic Support as Mouse wheel and hover or you can control event before VB IDE Default Windows proc as WM_CREATE when windows start creation, this task is useful for some application , for example you can create new UI Control at run time using Form1.Control.add("vb.CommandButton","Cmd1") Function and you can handle command button event by WM_COMMAND Message and Command ID


Expand|Select|Wrap|Line Numbers
  1. Option Explicit
  3. Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
  4. Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
  5. Private 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
  6. Private Declare Sub CopyPtrToObj Lib "kernel32" Alias "RtlMoveMemory" (ByRef Destination As Object, ByRef Source As Long, Optional ByVal Length As Long = 4)
  7. Private Declare Sub CopyObjToPtr Lib "kernel32" Alias "RtlMoveMemory" (ByRef Destination As Long, ByRef Source As Object, Optional ByVal Length As Long = 4)
  10. Private Const GWL_USERDATA = (-21)
  11. Private Const GWL_WNDPROC = (-4)
  14. Private Const WM_MOUSEWHEEL As Long = &H20A
  15. Private Const WM_MOUSEHOVER As Long = &H21A
  17. Public Sub ChangeWindowProc(ByVal WindowObject As Object)
  18. Dim LastFormProc As Long
  19. Dim WindowObjectPointer As Long
  20.     'Get Proc Address assigned by VB IDE
  21.     LastFormProc = GetWindowLong(WindowObject.hwnd, GWL_WNDPROC)
  22.     Call CopyObjToPtr(WindowObjectPointer, WindowObject)        'Copy Object memory Pointer to Long variable
  23.     WindowObject.Tag = LastFormProc                             'hold lastProc in tag property u can create public variable in each window and assign this value to it and use tag for ur work
  24.     'Save Last Window Object Pointer in Window Class User Extedned Data,now u can change proc for multiple form at one time
  25.     'sure user cant active 2 forms in same time, but because of timer event and winsock
  26.     Call SetWindowLong(WindowObject.hwnd, GWL_USERDATA, WindowObjectPointer)
  27.     'change VB IDE proc by new our Proc Address
  28.     Call SetWindowLong(WindowObject.hwnd, GWL_WNDPROC, AddressOf WindowExtendedEventProc)
  29. End Sub
  31. 'Reset Window Proc To Orignal VB IDE Proc.
  32. Public Sub ResetWindowProc(ByVal WindowObject As Object)
  33. Dim LastFormProc As Long
  34.     LastFormProc = Val(WindowObject.Tag)
  35.     Call SetWindowLong(WindowObject.hwnd, GWL_USERDATA, LastFormProc)
  36. End Sub
  38. 'Our New Window Defined proc
  39. Public Function WindowExtendedEventProc(ByVal hwnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
  40. 'this variable is static because visual basic will unallocate all objects and variables within function after excution complete
  41. 'try to change it to Dim FormObject as object your application will crash
  42. Static FormObject As Object
  43. Dim LastFormProc As Long
  44. Dim FormObjectPointer As Long
  45.     'get Object Pointer Again in long var
  46.     FormObjectPointer = GetWindowLong(hwnd, GWL_USERDATA)
  47.     Call CopyPtrToObj(FormObject, FormObjectPointer)    'this line seems as "Set FormObject=Form1" !!!!
  48.     LastFormProc = Val(FormObject.Tag)                  'retrieve LastProc Address From tag
  49.     Select Case Msg
  50.         Case WM_MOUSEWHEEL                  'if user Roll Mouse Wheel
  51.             Call FormObject.Form_MouseWheel
  52.             WindowExtendedEventProc = 0
  53.             Exit Function
  54.         Case WM_MOUSEHOVER
  55.             Call FormObject.Form_MouseWheel
  56.             WindowExtendedEventProc = 0
  57.             Exit Function
  58.     End Select
  59.     'call orignal VB IDE Proc with other windows messages
  60.     WindowExtendedEventProc = CallWindowProc(LastFormProc, hwnd, Msg, wParam, lParam)
  61. End Function
'================================================= =======

Expand|Select|Wrap|Line Numbers
  1. Option Explicit
  3. Private Sub Form_Activate()
  4.    Call ChangeWindowProc(Me)
  5. End Sub
  7. Private Sub Form_Deactivate()
  8.    Call ResetWindowProc(Me)
  9. End Sub
  11. Public Sub Form_MouseWheel()
  12.     MsgBox "mouse Wheel"
  13. End Sub
  15. Public Sub Form_MouseHover()
  16.     MsgBox "mouse Wheel"
  17. End Sub
Good Luck
Nov 16 '07 #1
0 6798

Sign in to post your reply or Sign up for a free account.

Similar topics

by: askingBoy | last post by:
Hello , I would like to know how to make this : I have a library written in Visual Basic .Net that has some events for its class , I am making an instance of this class in a Visual basic 6.0...
by: Bruno Jouhier [MVP] | last post by:
I'm currently experiencing a strange phenomenon: At my Office, Visual Studio takes a very long time to compile our solution (more than 1 minute for the first project). At home, Visual Studio...
by: Assaf | last post by:
Hi all. In response to user selections, our app adds controls (buttons, image buttons) dynamically to a page with Controls.Add(myNewButtonControl). Now that we gotten on the page we want to...
by: Jerry Wei | last post by:
Dear all: I have a problem about how to handle the events. For example, there are two forms, Form1 and Form2. Form2 is owned by Form1 and there is a button,Button1, in Form2. It is no problem for...
by: sqlguy | last post by:
Why do we have to contact MS for a problem that has been with this compiler from at least the beta of VS 20005. I am so sick and tired of the 30 - 40 clicks it takes to dismiss VS when there is a...
by: Master Programmer | last post by:
An friend insider told me that VB is to be killled off within 18 months. I guess this makes sence now that C# is here. I believe it and am actualy surprised they ever even included it in VS 2003 in...
by: Goran Djuranovic | last post by:
Hi all, I am experiencing a strange thing happening with a "designer.vb" page. Controls I manually declare in this page are automatically deleted after I drop another control on a ".aspx" page. -...
by: =?Utf-8?B?Rmxhc2hwcm8=?= | last post by:
i have googled this question but cannot find an answer. i'm running windows vista and i'm using Visual Basic Express 2008. i know the build event button SHOULD be in under the compile tag but i...
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.