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 - Option Explicit
-
-
Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
-
Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
-
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
-
Private Declare Sub CopyPtrToObj Lib "kernel32" Alias "RtlMoveMemory" (ByRef Destination As Object, ByRef Source As Long, Optional ByVal Length As Long = 4)
-
Private Declare Sub CopyObjToPtr Lib "kernel32" Alias "RtlMoveMemory" (ByRef Destination As Long, ByRef Source As Object, Optional ByVal Length As Long = 4)
-
-
-
Private Const GWL_USERDATA = (-21)
-
Private Const GWL_WNDPROC = (-4)
-
-
-
Private Const WM_MOUSEWHEEL As Long = &H20A
-
Private Const WM_MOUSEHOVER As Long = &H21A
-
-
Public Sub ChangeWindowProc(ByVal WindowObject As Object)
-
Dim LastFormProc As Long
-
Dim WindowObjectPointer As Long
-
'Get Proc Address assigned by VB IDE
-
LastFormProc = GetWindowLong(WindowObject.hwnd, GWL_WNDPROC)
-
Call CopyObjToPtr(WindowObjectPointer, WindowObject) 'Copy Object memory Pointer to Long variable
-
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
-
'Save Last Window Object Pointer in Window Class User Extedned Data,now u can change proc for multiple form at one time
-
'sure user cant active 2 forms in same time, but because of timer event and winsock
-
Call SetWindowLong(WindowObject.hwnd, GWL_USERDATA, WindowObjectPointer)
-
'change VB IDE proc by new our Proc Address
-
Call SetWindowLong(WindowObject.hwnd, GWL_WNDPROC, AddressOf WindowExtendedEventProc)
-
End Sub
-
-
'Reset Window Proc To Orignal VB IDE Proc.
-
Public Sub ResetWindowProc(ByVal WindowObject As Object)
-
Dim LastFormProc As Long
-
LastFormProc = Val(WindowObject.Tag)
-
Call SetWindowLong(WindowObject.hwnd, GWL_USERDATA, LastFormProc)
-
End Sub
-
-
'Our New Window Defined proc
-
Public Function WindowExtendedEventProc(ByVal hwnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
-
'this variable is static because visual basic will unallocate all objects and variables within function after excution complete
-
'try to change it to Dim FormObject as object your application will crash
-
Static FormObject As Object
-
Dim LastFormProc As Long
-
Dim FormObjectPointer As Long
-
'get Object Pointer Again in long var
-
FormObjectPointer = GetWindowLong(hwnd, GWL_USERDATA)
-
Call CopyPtrToObj(FormObject, FormObjectPointer) 'this line seems as "Set FormObject=Form1" !!!!
-
LastFormProc = Val(FormObject.Tag) 'retrieve LastProc Address From tag
-
Select Case Msg
-
Case WM_MOUSEWHEEL 'if user Roll Mouse Wheel
-
Call FormObject.Form_MouseWheel
-
WindowExtendedEventProc = 0
-
Exit Function
-
Case WM_MOUSEHOVER
-
Call FormObject.Form_MouseWheel
-
WindowExtendedEventProc = 0
-
Exit Function
-
End Select
-
'call orignal VB IDE Proc with other windows messages
-
WindowExtendedEventProc = CallWindowProc(LastFormProc, hwnd, Msg, wParam, lParam)
-
End Function
'============== =============== =============== ============
Form1.frm - Option Explicit
-
-
Private Sub Form_Activate()
-
Call ChangeWindowProc(Me)
-
End Sub
-
-
Private Sub Form_Deactivate()
-
Call ResetWindowProc(Me)
-
End Sub
-
-
Public Sub Form_MouseWheel()
-
MsgBox "mouse Wheel"
-
End Sub
-
-
Public Sub Form_MouseHover()
-
MsgBox "mouse Wheel"
-
End Sub
Good Luck
0 6848 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 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
|
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,...
|
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.
|
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...
|
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.
| |
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
|
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
|
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!!!
|
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...
|
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,...
|
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...
| |
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,...
|
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...
|
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();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
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...
| |