473,396 Members | 1,784 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,396 developers and data experts.

How To Handle More events Visual Basic 6.0 Not Support

AHMEDYO
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

Module1.bas

Expand|Select|Wrap|Line Numbers
  1. Option Explicit
  2.  
  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)
  8.  
  9.  
  10. Private Const GWL_USERDATA = (-21)
  11. Private Const GWL_WNDPROC = (-4)
  12.  
  13.  
  14. Private Const WM_MOUSEWHEEL As Long = &H20A
  15. Private Const WM_MOUSEHOVER As Long = &H21A
  16.  
  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
  30.  
  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
  37.  
  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
'================================================= =======
Form1.frm

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

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

Similar topics

0
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...
26
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...
3
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...
3
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...
4
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...
97
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...
4
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. -...
3
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.