Hooking And Subclassing
What is Hooking and Subclassing, i read alot about people using it on the forum, but i am not sure what it is.
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
Subclassing, Hooking, Or Other?
What is the correct terminology when I do the following?
Code:
Private Sub Form_Load()
lpPrevWndProc = SetWindowLong(Me.hWnd, GWL_WNDPROC, AddressOf WindowProc)
End Sub
Function WindowProc(ByVal hw As Long, ByVal uMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
' Do my stuff
WindowProc = CallWindowProc(lpPrevWndProc, hw, uMsg, wParam, lParam)
End Function
Subclassing Or Hooking
ok i no its hardly posible to subclass in vb without a dll but i was woundering if there was a way ive got close but what happens msn menus dont work or nuffin
ummcan somone show me a tutorial for making a packet sniffer that works in xp and AND lower
:P
i have made 1 for msn messenger but it only works for xp and 20 users
no not www.rentacoder.com Unless ur gonna pay :P
Subclassing/hooking Help??
im tryin to find a solution to a post in the general discussion area about being able to navigate through items on a popup menu thats shown from the system tray. i impliment subclassing to tell me when the popup is showing or not, no errors.
I create a hook to "try" to capture keyboard events while the menu is visible. the hook gets set when the menu is showing, and I remove the hook when its not showing, I have made sure that the hooks/subclassing is working the way it should be, but i can never get input in my message filter for the hook.
Will someone please take a look at this and see if they provide some insight as to how I can make this work? im aware that my hooking method might not be the implimented in the best way but it doesnt error at all, so im happy for the moment, jyst nothing fires in it.
if not its still a kool little example on the subject(s)
SubClassing Or Hooking
Well i got this problem...
I want my window to intercept messages, WM_KEYDOWN for example. If there is no control on the form that has got focus, subclassing is working fine. But when a control got focus my program does no longer intercept WM_KEYDOWN message cause they are send to the control.
Now is there another way to do it with subclassing or do i need to hook my window.....
code sofar...
Code:
Public Function SubClass(lHwnd As Long) As Boolean
lpPrevWndProc = SetWindowLong(lHwnd, GWL_WNDPROC, AddressOf WndProc)
End Function
Public Function WndProc(ByVal hwnd As Long, ByVal msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Select Case msg
Case WM_DESTROY
Call UnClass(hwnd)
Case WM_KEYDOWN
MsgBox "WM_KEYDOWN: wParam = " & wParam & " & lParam=" & lParam
Case WM_KEYUP
MsgBox "WM_KEYUP: wParam = " & wParam & " & lParam=" & lParam
Case WM_CHAR
MsgBox "WM_CHAR: wParam = " & wParam & " & lParam=" & lParam
Case Else
WndProc = CallWindowProc(lpPrevWndProc, hwnd, msg, wParam, lParam)
End Select
End Function
Public Function UnClass(lHwnd As Long)
SetWindowLong lHwnd, GWL_WNDPROC, lpPrevWndProc
End Function
Subclassing Or Hooking (again)
For the 1000th, subclassing or hooking. I've been looking here and there for over an hour trying to find out a way to handle messages sent to a particular running application (or window). For simplicity, assume I want to receive all messages sent to Notepad (sort of like tracking what's happening to it).
First, subclassing. This is a bolded line taken from the MSDN article Safe Subclassing in Win32
Quote:
Subclassing is allowed only within a process. An application cannot subclass a window or class that belongs to another process.
How do people go around this rule and use subclassing globally with other windows?
Unless I want to do "superclassing", which I think is not what I need.
(a questoin on the side, I use SetWindowLong(), right?)
Now, hooking. Also discussed in About Hooks . I tried it, it works fine, but I need the "application handle" (rather than the "window handle") which I can't get a hold of given a window handle. I can get the app handle of MY application, but that's not what I need.
Also, hooking is kind of limited. It limits you to these "callback procedures" (rather than all WM messages):
Quote:
WH_CALLWNDPROC
WH_CALLWNDPROCRET
WH_CBT
WH_FOREGROUNDIDLE
WH_GETMESSAGE
WH_JOURNALPLAYBACK
WH_JOURNALRECORD
WH_KEYBOARD
WH_MOUSE
WH_MSGFILTER
WH_SHELL
WH_SYSMSGFILTER
(of course these are used with SetWindowsHookEx())
Come to think of it again, WH_CALLWNDPROC, WH_CALLWNDPROCRET, and WH_GETMESSAGE sound very very useful (at least for my "Notepad" example), but how can I get an app handle?
For my case, which was similar to some, some people prefer subclassing, and some prefer hooking. I want to know the ups and downs for both. Much appreciated. Much much appreciated!
IDE-Safe Subclassing, Hooking And More
For those that use subclassing, hooking, callbacks, and registration of custom window classes, know these can be fatal when trying to troubleshoot in IDE. Crashes occur quite often. Also if one were to execute an END statement or hit the VB toolbar's STOP button, crashes occur. Generally, external subclassing DLLs are required to add safety to IDE, but....
Well, Paul Caton, a friend of mine, left me some of his ingenious code. He no longer works with VB and I am taking the initiative to improve and enhance the code he left behind. Because of how well it works, I want to contribute it to this forum.
What does it do? It makes subclassing, hooking, and callbacks fun and safe to use in IDE while requiring no additional modifications when the application is compiled. This is accomplished by creating assembler executable code on the fly that can exist outside of the project, reroute messages to the project, and bypass the project if IDE is no longer available.
1) 99.99% IDE safe
2) Any VB code object can host the callback procedure: form, class, user control, and/or property page. Very little restrictions exist.
3) Already used/tested over the past couple years by myself and others. Even used in some of vbAccelerator's projects.
You should be familiar on what subclassing and hooking are. If you are, then dive right in. The original code by Paul Caton exists on PlanetSourceCode along with the source included in this zip file. The links are provided in the comments within the project's class. The ASM code in NASM format is also included should you care to see what instructions are being called/used.
Hooking Or Subclassing A Treeview?
My goal is to pull node data from an existing Treeview in another program.
I've examined a number of subclassing articles. Most of which deal with hooking into something like the Textbox of a program to simply pull or alter the text there. A few articles I found that, "claim," subclassing treeviews fake it, such as ones I found for adding right click to a Treeview inside your own app. Not what I want.
What it appears that I don't understand is that once I get the window handle of the TreeView, there doesn't seem to be any way to access anything from that Treeview. Most of the examples I see use GetMessage and SendMessage to get or set the information in the text box. I examined as many documents I could find and they don't really have any information about applying this API to the Treeview.
I did a search on Subclassing Treeviews here, but most of those discussions just appear to peter out.
Is there any way... at all... anything. Some method I'm not aware of. Some tutorial, article, anything at all that I haven't found that gives an example of how to examine the nodes of a Treeview.
Anything... want to see a penguin get down on his non-existent chubby knees and beg? You got it.... Throw me a bone, a fish scale... anything.
Little Task With Hooking/subclassing
I'll code it myself because i have experience of coding in vb but i left vb in 2003 or 2002 so lot of things are forgotten.
So please help me now.
There is a small software installed on my pc for which i have no support now.It has some errors so it ask for debugging when it gets error while executing and if i click NO then it keeps on working.
It is really a headache for me to click NO various times in a day.
I want to write small vb program so that it can check this application's message box and click NO so that i can avoid this annoying situation.
Is it possible ? ( i think yes thru hooking or subcalssing which i have forgotten now).
Please help me about solving this problem
Thanks a lot for you coming help.
Hooking And/or SubClassing. What Are My Options?
I'm writing an addin for the IDE which needs to know about changes of focus in the project window treeview. I first thought to subclass the window,but couldn't get it to work. I thought this was because you wre limited to subclassing in your own process. But a compiled addin would run in the same process as the IDE, would it not? And therefore subclassing should be possible?
If not, can I use Hooking? If I can, how do I do it? (I know less about hooking than I do about subclassing and I hardly know a thing about that!).
I can use SendMessage to get to text of the selected node in an external treeview, but I need to be informed when a new item is selected (TVN_SELCHANGED notify for example).
Please, Please, Please, Please, Please, Please, Please, Please, Please, Please, Please, Please, Please, Please, Please, Please, help.
Thank you.
Hooking, Subclassing, Append Menu Etc
please can someone help me i have search for hours and cant find any code that works for this.
basically i want to write an addon for another program, for example i want to create my own menu on another application e.g. notepad lie after the help menu in notepad have "MyMenu" or something with a list and then when clicked it will execute a piece of code ??
i have looked on planetsourcecode and cant find a way that actully works without problems can someone please help :S
thanks in advanced
if poss post sample code :S i am so puzzled
Is It Possible To Alter De Appearance Of A Control Subclassing It? Or Hooking It?
hello everybody,
i am currently modifying an extense application developed in VB6.0, one of the new requirements i am workin' it, is to provide a new "skin" (aka Look N Feel) to the whole app...
well, i know i can program a new usercontrol for each control i'd like to alter (its graphic appearance), mapping all the events and properties... but that implies to change the controls in each form and before that make a lot of functionality tests...
so, i want to know if there is some way to "intercept" the paint message from a control and make it some "graphical arrangements" using windows APIs ... is this possible???
Thanx in advance.
Have an excellent day.
Frojask.
Hooking Into Another App
i am a hobby vb'er, but love experimenting with it. i have written some useful stuff to no one but me and a few select co-workers.
problem:i want to hook into an app, not written by me, and make menu, toolbar, and context menu items that will launch or switch to my app, allow manipulation of data (flexgrid text cells), and pass it back to the other app as if the user had typed the data. i want to add some functionality to the other app as an addon/addin. however, the other app is not like an ms office app with a template (normal.dot) that i can insert any vba code into. additionally, the other app is not probably written in vb.
i would really like to add a registry setting that would load my hook anytime the other app is loaded and add my buttons/menus to it on its initialization. anything that will adversely affect the other app is unacceptable. zero fault tolerance.
so from reading numerous vb forums and surfing knowledge bases, i haven't found something that just stands out as the answer.
i understand the terms and purposes of subclassing, hooks, callbacks, and API, but being a hobbiest, have usually found a way around using such things or just do without that functionality. therefore, my knowledge of these issues is nill for all intents and purposes.
but i fear there is no other way. i am using vb6 enterprise, and don't see getting into vb.net anytime soon.
fixing this problem has some real-world functionality, if for no other purpose that to present an idea to the devlopers of the app i am hooking into.
any help and direction is appreciated.
Run Hooking
Basically, I'm creating a new 'Run' dialog and have got to the stage where I need to find a way to actually replace the old one. I've got an idea, but I'm not sure if it's the best way to do it:
Setup a system wide CBT hook to detect activated windows with the class '#32770 (Dialog)' and caption 'Run', then destroy it and show my own Run dialog.
If anyone can think of any other method, please, let me know.
Thanks in advance,
Ed
Hooking
Hi there every1...
i wanna make a program that has a main form with buttons, which have code to start a program such as msn messenger, solitaire, internet explorer etc.(basically anything installed on the computer.)
can ne1 help me on this pls i have no clue on how to start but i know it needs API and registry of sum kind in the code... im just not sure wat goes where...
API Hooking
Hi there!
I've a question, please, can you help me?
Question: How can i 'hook' an API??
I'll try to clarify a little. You know that API, GetAsyncKeyState. Would i like to monitor that API in real time. Print on my screen what program is using that API, Process name, path, blablabla... But the main question, HOW to monitor the API? Anybody have a clue, or, did something like it?
Thanks!!
MSN (hooking?)
Hello,
I'm trying to develop a program which has the following purpose:
- Alter data sent and received from the MSN program;
- Block data sent and received from the MSN program;
- Create (fake) data sent and received by the MSN program.
With this, I can create a plugin which makes advanced messaging possible, such as sending nudges and things as often as you wish, generating custom automessages, advanced logging, etcetera.
I've thought of a few ways to do this:
- create a proxy app, through wich I tunnel all the data of MSN;
- create a proxy-like app, through which all the data of MSN is tunneled when I route the DNS to localhost
- create a socket/MSN hook, to intercept dll-calls
The first two ways weren't as successful as I hoped (for an unknown reason it did work for my browser, but msn screwed up when routing it's traffic through my home-made program), so I read something about hooking up programs. After googling for a while, it seemed to be the way to help me out. I've been trying to find some visual-basic source for this, but that's really hard to find.. I did find some source for hooking-up keystrokes, but I'm too unfamiliar with this hooking thing to alter this for my purpose.
Does anyone have some experience with hooking, and knows how to hook up MSN or it's socket? Please help, because I don't know where to start.
API Hooking
Is there a way to hook an API function using VB?
If so, how?
any examples?
API Hooking
I have a source code in C++ that shows you how API Hooking is done but I don't have C++. So I was wondering if it can be generated into VB somehow ?
The source code is attached.
Hooking?
Ok here is my question, I havent dabbled with it much and I havent seen any real documentation on it but does anyone know how to check to see if a program is hooking into another program (if that makes sense)
example:
program1.exe hooks into programb.exe to intercept data being sent to a dll then it takes that data sends it to the dll and gets the return, then it manipulates the return and sends it back to program1.exe
System Hooking In Vb
hi there,
I am new this forum.Hope to get some help.
Is there any way in vb ,that I can hook the printscreen for all activateed application.
That means as long as my application is is active the printscreen button should be disabled for all application.
Any kind of help is highly appriciated.
Thank you in advence
sandy
Hooking The Mouse
Here is an example I made of using hooking (similar to subclassing)
the mouse to get its messages. The program will detect mouse
clicks and movement from anywhere within the program's thread.
Don't stop the program with the stop button, use the 'X' or
the 'Done' button.
Enjoy! Report any bugs to me by way of Private Message.
Process Hooking
Hello!
Is it possible to "hook" a process in VB? I mean, is it possible to put a whole VB-program into another process(program) and execute it inside?
If this is possible, I'd really like to know how?
Q:Hooking, Please Give Me Some Help.
I am trying to create a hook for a game using vb. What I want to do is intercept it's messages and execute if "CTRL+R" is pressed, maybe even multiple hotkeys.What i need is how i would start and finish this. Please inform about anything regarding this. I already know the basics, i just need to know how to do the following.
"2. Hooking into another process is not so easy in VB - your hook function (KeyboardProc) must be in a DLL, the DLL needs to be loaded in your process, and the hInstance value you pass must be the module handle of the loaded DLL."
any idea on how to do that?
Hooking Windows
My delima:
I'm writting a program that will copy and send RTTY over ham radio. There is an RTTY engine that I load via a module and send messages back and forth to it via window calls. I have this part work fine from one form but what I need to do is be able to load 2 copies of this engine and have the second copy hook to another form and send message back and forth to it.
I'm new to using windows messages and hookig windows so this is why I need the help
thanks
Rick
Hooking DragDrop
OK I posted this question before but never got exactly what I was looking for and settled for a work around which is a little cowboyish to say the least, I have a webbrowser and a DHTMLEdit control and I want to intercept drag drop events from the browser to the DHTMLEdit the problem being there is no events in either of these controls to tell you when this happens
I know the basics of subclassing but on all the sites I have searched have not found the Windows Message for dragdrops, if anybody can tell me this I would be very grateful
VB Hooking Utopia
Hi there,
it is possible in Visual Basic to "hook" wich file or application an user decided to "doubleclick"?
I'll try to explain better, like in an antivrus app (for eg. Norton) i would "track" what application an user lunch or what file try to open, all in real time.
It is possible ?
Thanks
Problems With Hooking
Let me describe what I'm trying to do and then I'll post the code I'm working with.....
There is a RTTY engine called MMTTY that decodes RTTY signals via a radio. Inthe code that I will post this allworks fine with just one copy of MMTTY running. the program I am working on has a text box to take the text outputtted my MMTTY and places them on the screen. I want to have 2 windows for text and 2 copies of MMTTY.
here is an example of some of the code that is in a module. to start MMTTY the routine StartMMTTY is called.
Like i said if I have 1 window and 1 MMTTY engine everything works fine if I load the second window and call the StartMMTTY routine I get the message bx pop up that says window is already hooked. How do I go about this so I dont get the message and allow things to work correctly???? If I'm not explaing enough please let me know.....
Code:
Public Sub StartMMTTY(meHostForm As Form)
Set HostForm = meHostForm
InitMMTTY HostForm.hWnd
End Sub
Private Sub InitMMTTY(hWnd As Long)
'Procedure to Initialize MMTTY
Dim window As String
Dim x As Long
Dim MMTTYhWnd As Long
Dim HexHwnd As String
HookWindow hWnd
MMTTY_MSG = RegisterWindowMessage("MMTTY")
Shell (App.path & "mmtty.exe " + window + " -h" & HexHwnd)
MMTTYhWnd = FindWindow(vbNullString, SharedMemory.title)
MMTY_HWND = MMTTYhWnd
SetAlwaysOnTop MMTTYonTop, MMTY_HWND, val(mwx), val(mwy), val(mwcx), val(mwcy)
PostMessage MMTY_HWND, MMTTY_MSG, RXM_HANDLE, hWnd
End Sub
This sub is used to Hook..
Code:
Private Sub HookWindow(hWnd As Long)
If OldWndProc <> 0 And HookedhWnd <> hWnd Then
MsgBox ("Procedure allready hooked!")
Exit Sub
ElseIf OldWndProc <> 0 Then
SetWindowLong hWnd, GWL_WNDPROC, OldWndProc
End If
OldWndProc = GetWindowLong(hWnd, GWL_WNDPROC)
SetWindowLong hWnd, GWL_WNDPROC, AddressOf NewWndProc
HookedhWnd = hWnd
End Sub
This sub is called when the program ends..
Code:
Private Sub UnHookWindow(hWnd As Long)
If HookedhWnd <> hWnd Then
MsgBox ("Window Not Hooked!")
Else
SetWindowLong hWnd, GWL_WNDPROC, OldWndProc
End If
HookedhWnd = 0
OldWndProc = 0
End Sub
Thanks.......
Edit: "Indents" weren't showing up b/c you didn't use the [vb][/vb] tags.
Hooking A Window
What mean Hook Window, I think that is something like catch the window messages and I must do the operation that the message indicates ! Is this hook a window ??
Hooking Other Programs
This is like "injecting" your app into other app's isn't it? Can someone direct me on where to go to get started with this?
Problem With Hooking!
VB Code:
I have a problem when attempting to hook something.Here's my code: Public Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As LongPublic Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As LongPublic 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 LongPublic DiabloWindow As LongPublic DiabloHook As LongPublic Const GWL_WNDPROC As Long = (-4) Public Function WindowProc(ByVal hw As Long, ByVal uMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long WindowProc = CallWindowProc(DiabloHook, hw, uMsg, wParam, lParam) Select Case uMsg Case WM_SIZE Debug.Print lParam & " " & wParam End SelectEnd Function Public Sub FindDiablo() If DiabloWindow = 0 Then DiabloWindow = FindWindowEx(0&, 0&, "Diablo II", vbNullString) Debug.Print "WINDOW VALUE " & DiabloWindow End If If DiabloHook = 0 And Not DiabloWindow = 0 Then DiabloHook = SetWindowLong(DiabloWindow, GWL_WNDPROC, AddressOf WindowProc) Debug.Print "HOOKED VALUE " & DiabloHook End IfEnd Sub
Now, the problem resides in function FindDiablo. It says the correct handle, but it says "HOOKED VALUE 0" in the debug, always!
I tried replacing "DiabloWindow" with Form1.hWnd, and it worked just fine. Is Diablo II somehow blocking incomming messages?
Hooking Menu
Hi experts!
I did this:
http://www.vbforums.com/showpost.php...39&postcount=1
Everything worked fine.
Except for 1 thing. When I add a submenu in a program(in this case Swift 3D)
the submenu is disabled
When I do it with notepad, everything works fine!
thanx
Hooking HTML Help To VB 6
Hi all,
Can anyone give the code for hooking a chm (compiled HTML help) file to my VB project?
The chm file is in the same directory as the project, I want the help contents to show up everytime Help >> Contents (mnuHelpContents) is clicked in the main menu.
I have associated F1 keypress with mnuHelpContents through menu editor.
Thanks in advance.
Yet Another Hooking Question
dear all,
i've searched these forums and around the net for this, i hope there's a way to do it (i've seen programs do it, i just need to create my own).
i'd like to get and modify existing captions and text boxes of an external program.
for instance, let's say a simple program has caption1 with 'wildcat' in it and a text1 box with 'my text here'.
i need a program able to read 'wildcat' from caption1 (almost done on this one), but especially i need to modify 'my text here' from my program.
does someone know where to start this?...
thanks,
wc.
DirectX Hooking
How to hook direct x graphics from a game. Im basically trying to develope a window mode for a game.( Make it in my window)
Hooking Using WH_GetMessage
Hi,
I am trying to hook MSN Messenger and wait for the WM_Close message in order to execute some code. The problem is, I have little experience with Hooks. I tried a couple of times and ended up crashing my PC, LOL. Can someone point me in the right direction on how to create a WH_GetMessage hook and wait for the WM_Close message from the MSN Messenger window?
Thank you for your time,
VIP3R
Hooking Other Windows ?
It is possible to hook or subclass another window? For example, when another window is clicked, my program carries out an action. Is this possible ?
Thanks....
Hooking Question
on my html page, i have a print button, when it is pressed i want to open page setup dialog box, set values in paper size listbox and margins text box and close the dialog. It may be done either in JavaScript or ActiveX Control.
Thanks in advance
Hooking Controls?
hey all
anyone got any idea how to hook a control in vb6 so i can capture its events?
what i want to do is monitor a control in another program (also written in vb oddly enough), to see when the user presses enter, and before it sends i want to capture the text entered.
any ideas?
thanks in anticipation
Hooking A Window???
How can I hook a window to intercept all messages sent to it, and is there a way to blobk certian messages from getting through???
Any help greatly appreciated
Hooking Listview
Greetings and Salutations!
I am looking for a way to tap in to a listview control and known when the first item has entered or when the last item has been removed.
The adding and removing will be done from several areas so I was hoping for one location that can take action when the list count has been changed.
Looking for a was other then calling a sub to do the checking. Is there a way to Hook it?
Thanks!!
Question About Hooking....
Can someone provide me with some insight or code that will explain to me a little more about hooking a window?
basically this is my goal.. i want to hook a window to a program that is not one of my applications and view all the windows messages that are sent to it... i would have the class name or window handle of the target window... how could this be accomplished?
Hooking Up My FlexGrid
I'm trying to populate an MSFlexGrid with data from a database.
Ideally I would like to do this in the click event to a command button - ie once I press ok, the grid is populated.
Could anyone help me with the code for moving my query/recordset into the grid?
Thanks, in advance for your help
Sam
Hooking IDE TreeView
I'm trying to hook the VB6 IDE project treeview. I can get it working with a WH_CALLWNDPROC SetWindowsHookEx call, but only in'debug' i.e. I haven't made a C dll for it.
So, I was trying to use the WH_JOURNALRECORD hook, as per other threads in these forums, to avoid the C dll, but I can't make it work (I don't get a hook!).
Can some one in the know look at my code and tell me what's up with it?
Cheers
Hooking The Keyboard
Hey,
Can someone please tell me how to disable the Microsoft Keys on the new keyboards. I wrote a program that can only be exited by the admins (password), but it is useless if I cannot disable those keys.
It's kind of urgent
|