473,756 Members | 9,576 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How To Handle More events Visual Basic 6.0 Not Support

AHMEDYO
112 New Member
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.a dd("vb.CommandB utton","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 6848

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

Similar topics

0
1320
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 Project and I can call the methods from the object I instanced . However I cannot raise the events from this library with my object , I already made a sub in the vb 6.0 in the form : Private Sub object_Event() 'Some code here End Sub
26
10879
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 compiles the same solution much faster (about 10 seconds for the first project). My home computer is only marginally faster than the one I have at the office (P4 2.53 vs. P4 2.4, same amount of RAM). On the slow machine, the CPU usage is very low,...
3
1159
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 make them do something for a living: how do we dynamically create events that the controls respond to? TEA for any pointers.
3
1804
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 Form2 to handle the event "Button1.Click" . My problem is how to handle the Button1.click event in Form1 as Form2's owner. Is there any way to achieve this demand??? ================================================================= owner and...
4
2161
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 problem. Can they not just post the fix. I see no reason to contact MS since I have most likely sent about 1500 dumps to them and I would think this would get their attention.
97
5537
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 the first place. Anyone else heard about this development? The Master
4
2646
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. - Why is this happening? - Can I disable automatic declaration and have everything be declared manually? - Any other options to fix this? Thanks in advance. Goran Djuranovic
3
3118
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 can't find it. i'm used to Visual Basic 2005, so some help would be appriciated. i need to find the build events tag because i'm creating a screen saver. perhaps there was an error with my installation. PLEASE HELP!!!
0
9482
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9292
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9901
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9878
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8733
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6551
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5322
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3392
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2694
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.