Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
 
  HOME    TRACKER    Visual Basic




System Wide Hook To Capture Window Hook Creation On XP


I have a following code:

dim uRegMsg as long
dim OldProc as long

uRegMsg = RegisterWindowMessage(ByVal "SHELLHOOK")
Call RegisterShellHook(hWnd, RSH_REGISTER) ' Or RSH_REGISTER_TASKMAN Or RSH_REGISTER_PROGMAN)
OldProc = GetWindowLong(hWnd, GWL_WNDPROC)
SetWindowLong hWnd, GWL_WNDPROC, AddressOf WndProc

It works perfectly fine on NT and Win2K but not on XP. As soon as a window is created, my WndProc function is called. but not on XP.

Does the GetWindowLong and SetWindowLong need to be changed to
GetWindowLongPtr and SetWindowLongPtr, if yes can someone please
give me the function declaration of those functions and changes
in the code.I tried but does not quite work for me. If not then
please let me know if any suggestion you have.

Thanks!




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Putting Systm Wide Window Creation Hook Using The SetWindowsHookEx
Hi,

I am trying to put a system wide hook using the SetWindowsHookEx. The machine crashes the moment i hit on command1 button. Here is the code..Is there a way to do it all in VB? I was able to put the system wide hook of mouse and jeyboard suceessfully without any crash...(WH_MOUSE_LL and WH_KEYBOARD_LL)

In the Form1.frm

Private Sub Command1_Click()

WindoCreationHookHandle = SetWindowsHookEx( _
WH_CALLWNDPROC, AddressOf AppHook, _
App.hInstance, 0&)

Open "C:WindowCreated.txt" For Output As #1

End Sub

Private Sub Command2_Click()

If WindoCreationHookHandle <> 0 Then
UnhookWindowsHookEx WindoCreationHookHandle
End If

Close #1

End Sub

In module1.bas


Public Declare Function UnhookWindowsHookEx Lib "user32" _
(ByVal hHook As Long) As Long

Public Declare Function SetWindowsHookEx Lib "user32" _
Alias "SetWindowsHookExA" (ByVal idHook As Long, _
ByVal lpfn As Long, _
ByVal hmod As Long, _
ByVal dwThreadId As Long) As Long

Public Declare Sub CopyMemory Lib "kernel32" _
Alias "RtlMoveMemory" _
(pDest As Any, _
pSource As Any, _
ByVal cb As Long)

Public Declare Function CallNextHookEx Lib "user32" _
(ByVal hHook As Long, _
ByVal nCode As Long, _
ByVal wParam As Long, _
ByVal lParam As Long) As Long

Public WindoCreationHookHandle As Long

Type CWPSTRUCT
lParam As Long
wParam As Long
message As Long
hwnd As Long
End Type

Public Const WH_CALLWNDPROC = 4

Public Function AppHook(ByVal idHook As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Dim CWP As CWPSTRUCT
CopyMemory CWP, ByVal lParam, Len(CWP)
Select Case CWP.message
Case WM_CREATE
Print #1, "Window Handle Created: ";
Print #1, CStr(CWP.hwnd)
End Select
AppHook = CallNextHookEx(WindoCreationHookHandle, idHook, wParam, ByVal lParam)
End Function

Need A System-Wide Hook DLL
Anyone have a DLL which will handle all the different WH hooks they are willing to post or send me via email?

Thanks
David

System Wide Hook
Hi,

I don't know if I should have posted this one on the C++ forum, but I have a problem with my system wide hook. I made a dll in C++ and the hook is working fine. I hooked inside C++ and in the Proc I made a callback to visual basic where I process the message. Everything works fine until I loose focus on my application. It destroys the hook as soon as I click on another application or if another application pops up, etc. Anyone got any idea why this happens?

LuCkY

How Do I Make This A System Wide Hook?
How do I make this a system wide keyboard hook because this code only traps keys while my application is in focus!


VB Code:
'******* MODULE CODE *******'Option Explicit Declare Function CallNextHookEx Lib "user32" (ByVal hHook As Long, ByVal ncode As Long, ByVal wParam As Long, lParam As Any) As LongDeclare Function GetAsyncKeyState Lib "user32.dll" (ByVal vKey As Long) As IntegerDeclare Function SetWindowsHookEx Lib "user32" Alias "SetWindowsHookExA" (ByVal idHook As Long, ByVal lpfn As Long, ByVal hmod As Long, ByVal dwThreadId As Long) As LongDeclare Function UnhookWindowsHookEx Lib "user32" (ByVal hHook As Long) As Long Public TheHook As Long Public Const WH_KEYBOARD = 2 Const VK_LBUTTON = &H1Const VK_RBUTTON = &H2Const VK_CANCEL = &H3Const VK_MBUTTON = &H4Const VK_BACK = &H8Const VK_TAB = &H9Const VK_CLEAR = &HCConst VK_RETURN = &HDConst VK_SHIFT = &H10Const VK_CONTROL = &H11Const VK_MENU = &H12Const VK_PAUSE = &H13Const VK_CAPITAL = &H14Const VK_ESCAPE = &H1BConst VK_SPACE = &H20Const VK_PRIOR = &H21Const VK_NEXT = &H22Const VK_END = &H23Const VK_HOME = &H24Const VK_LEFT = &H25Const VK_UP = &H26Const VK_RIGHT = &H27Const VK_DOWN = &H28Const VK_SELECT = &H29Const VK_PRINT = &H2AConst VK_EXECUTE = &H2BConst VK_SNAPSHOT = &H2CConst VK_INSERT = &H2DConst VK_DELETE = &H2EConst VK_HELP = &H2FConst VK_0 = &H30Const VK_1 = &H31Const VK_2 = &H32Const VK_3 = &H33Const VK_4 = &H34Const VK_5 = &H35Const VK_6 = &H36Const VK_7 = &H37Const VK_8 = &H38Const VK_9 = &H39Const VK_A = &H41Const VK_B = &H42Const VK_C = &H43Const VK_D = &H44Const VK_E = &H45Const VK_F = &H46Const VK_G = &H47Const VK_H = &H48Const VK_I = &H49Const VK_J = &H4AConst VK_K = &H4BConst VK_L = &H4CConst VK_M = &H4DConst VK_N = &H4EConst VK_O = &H4FConst VK_P = &H50Const VK_Q = &H51Const VK_R = &H52Const VK_S = &H53Const VK_T = &H54Const VK_U = &H55Const VK_V = &H56Const VK_W = &H57Const VK_X = &H58Const VK_Y = &H59Const VK_Z = &H5AConst VK_STARTKEY = &H5BConst VK_CONTEXTKEY = &H5DConst VK_NUMPAD0 = &H60Const VK_NUMPAD1 = &H61Const VK_NUMPAD2 = &H62Const VK_NUMPAD3 = &H63Const VK_NUMPAD4 = &H64Const VK_NUMPAD5 = &H65Const VK_NUMPAD6 = &H66Const VK_NUMPAD7 = &H67Const VK_NUMPAD8 = &H68Const VK_NUMPAD9 = &H69Const VK_MULTIPLY = &H6AConst VK_ADD = &H6BConst VK_SEPARATOR = &H6CConst VK_SUBTRACT = &H6DConst VK_DECIMAL = &H6EConst VK_DIVIDE = &H6FConst VK_F1 = &H70Const VK_F2 = &H71Const VK_F3 = &H72Const VK_F4 = &H73Const VK_F5 = &H74Const VK_F6 = &H75Const VK_F7 = &H76Const VK_F8 = &H77Const VK_F9 = &H78Const VK_F10 = &H79Const VK_F11 = &H7AConst VK_F12 = &H7BConst VK_F13 = &H7CConst VK_F14 = &H7DConst VK_F15 = &H7EConst VK_F16 = &H7FConst VK_F17 = &H80Const VK_F18 = &H81Const VK_F19 = &H82Const VK_F20 = &H83Const VK_F21 = &H84Const VK_F22 = &H85Const VK_F23 = &H86Const VK_F24 = &H87Const VK_NUMLOCK = &H90Const VK_OEM_SCROLL = &H91Const VK_OEM_1 = &HBAConst VK_OEM_PLUS = &HBBConst VK_OEM_COMMA = &HBCConst VK_OEM_MINUS = &HBDConst VK_OEM_PERIOD = &HBEConst VK_OEM_2 = &HBFConst VK_OEM_3 = &HC0Const VK_OEM_4 = &HDBConst VK_OEM_5 = &HDCConst VK_OEM_6 = &HDDConst VK_OEM_7 = &HDEConst VK_OEM_8 = &HDFConst VK_ICO_F17 = &HE0Const VK_ICO_F18 = &HE1Const VK_OEM102 = &HE2Const VK_ICO_HELP = &HE3Const VK_ICO_00 = &HE4Const VK_ICO_CLEAR = &HE6Const VK_OEM_RESET = &HE9Const VK_OEM_JUMP = &HEAConst VK_OEM_PA1 = &HEBConst VK_OEM_PA2 = &HECConst VK_OEM_PA3 = &HEDConst VK_OEM_WSCTRL = &HEEConst VK_OEM_CUSEL = &HEFConst VK_OEM_ATTN = &HF0Const VK_OEM_FINNISH = &HF1Const VK_OEM_COPY = &HF2Const VK_OEM_AUTO = &HF3Const VK_OEM_ENLW = &HF4Const VK_OEM_BACKTAB = &HF5Const VK_ATTN = &HF6Const VK_CRSEL = &HF7Const VK_EXSEL = &HF8Const VK_EREOF = &HF9Const VK_PLAY = &HFAConst VK_ZOOM = &HFBConst VK_NONAME = &HFCConst VK_PA1 = &HFDConst VK_OEM_CLEAR = &HFE Public KeyLog As String Public Function KeyboardProc(ByVal idHook As Long, ByVal wParam As Long, ByVal lParam As Long) As Long    Dim Key As Integer    Dim Shift As Boolean        If idHook < 0 Then        KeyboardProc = CallNextHookEx(TheHook, idHook, wParam, ByVal lParam)    Else                If GetAsyncKeyState(VK_SHIFT) And &H8000 Then            Shift = True        Else            Shift = False        End If                 For Key = 65 To 90            If (GetAsyncKeyState(Key) And &H1) Then                If Shift = True Then                    KeyLog = KeyLog + UCase$(Chr(Key))                Else                    KeyLog = KeyLog + LCase$(Chr(Key))                End If            End If        Next Key         For Key = 48 To 57            If (GetAsyncKeyState(Key) And &H1) Then                If Shift = True Then                    Select Case Key                    Case 49                        KeyLog = KeyLog + "!"                    Case 50                        KeyLog = KeyLog + "@"                    Case 51                        KeyLog = KeyLog + "#"                    Case 52                        KeyLog = KeyLog + "$"                    Case 53                        KeyLog = KeyLog + "%"                    Case 54                        KeyLog = KeyLog + "^"                    Case 55                        KeyLog = KeyLog + "&"                    Case 56                        KeyLog = KeyLog + "*"                    Case 57                        KeyLog = KeyLog + "("                    Case 48                        KeyLog = KeyLog + ")"                    End Select                Else                    KeyLog = KeyLog + Chr(Key)                End If            End If        Next Key         If (GetAsyncKeyState(VK_BACK) And &H1) Then KeyLog = KeyLog & "{BackSpace}"         If (GetAsyncKeyState(VK_SPACE) And &H1) Then KeyLog = KeyLog + " "         If (GetAsyncKeyState(VK_RETURN) And &H1) Then KeyLog = KeyLog + Chr(13)                KeyboardProc = CallNextHookEx(TheHook, idHook, wParam, ByVal lParam)            End IfEnd Function   '******* Form Code *******'Private Sub Form_Load()    TheHook = SetWindowsHookEx(WH_KEYBOARD, AddressOf KeyboardProc, App.hInstance, App.ThreadID)End Sub Private Sub Form_Unload(Cancel As Integer)    UnhookWindowsHookEx TheHookEnd Sub

System-Wide Hook - Example? (WH_CBT)
Do you think anyone could give me a System-Wide hook example? (Like a WH_CBT)

I already know how to implement WH_Keyboard_LL and WH_Mouse_LL since these do not require DLL injection, but all the other do via the SetWindowsHookEx. (I think it is because they are LowLevel that it allows for no DLL, would have been nice if MS did this for every hook)

I could attempt to code the DLL in C++ but I dont know too much about it, and feel somewhat insecure about building a dll that is going to be injected into every process that has the posibility of failing to properly work. So I am wondering if anyone has any good examples, or knows of sites with good examples that will allow the code to be managed in the VB application itself, or in a VB6 DLL (modified of course since vb6 only supports ActiveX by default).

I want to avoid having to recompile a new C++ dll everytime I need to change the code slightly to handle a different window message.

So can anyone help, give any tips, or point to any sites?

Thanks.

-Alt

System Wide Hook Using WH_MOUSE
Hi,

I have successfully implemented a system wide hook for the mouse using WH_MOUSE_LL. But it not supported on windows 98 and below. Hence i was trying to implement the system wide mouse hook using the WH_MOUSE. I am getting a probelm in which when i make a call to the CopyMemory the function does not return back. I dont know whats happening. Here's code:


Code:
Public Type PointAPI
X As Long
Y As Long
End Type

Public Type MOUSEHOOKSTRUCT
pt As PointAPI
hwnd As Long
wHitTestCode As Long
dwExtraInfo As Long
End Type

Public Declare Sub CopyMemory Lib "kernel32" _
Alias "RtlMoveMemory" _
(pDest As Any, _
pSource As Any, _
ByVal cb As Long)


MouseHandle = SetWindowsHookEx( _
WH_MOUSE, AddressOf MouseCallback1, _
App.hInstance, 0&)


Public Function MouseCallback1(ByVal Code As Long, _
ByVal wParam As Long, lParam As Long) As Long

Dim Mousestruct As MOUSEHOOKSTRUCT
Dim tempPoint As PointAPI
MouseIndicator = 1
If (Code = HC_ACTION) Then
Call CopyMemory(Mousestruct, ByVal lParam, Len(Mousestruct))
' Copy the Mouse data out of the lParam (which is a pointer)
If wParam = WM_LBUTTONDOWN Then
' Do the processing
End If
End If
End Function

So whatever processing code i have kept after the CopyMemory never gets executed...Can some body please help..it is very critical for me.
Thanks!

System Wide Hook To Trap Errors
I am presently dealing with a peice of software that has very little error trapping. I will, in the future, recode to handle the errors. Has anyone heard of installing a system wide hook which has a sole purpose of trapping errors. I understand that it will slow performance but if I could use it for a couple of months while I recode I think I might have happier users.
Thanks for the suggestions,
D

How To Install System Wide Wh_cbt Hook?
Hi, I've been trying to install a system wide WH_CBT hook to trap when windows are being minimized. I've tried using the DSCBTSHL.dll dll but it only traps when the WH_CBT message is happening but doesn't seem to trap and details (wParam and lParam) which are crucial to determine if it is the minimize button being pressed or maximize. I;ve looked all over but can't seem to find anything. Would anyone know a good dll that can trap system wide wh_cbt messages and that would also trap the wParam parameter?

System Wide Hotkeys Using Keyboard Hook
I want to create a system-wide hotkey using keyboard hook. It shold also be useful if the dll created can be used in VB, could anyone help, or direct me to a online resource to find help on this.

How To Install A System Wide Wh_cbt Hook?
Hi, I've been trying to install a system wide WH_CBT hook to trap when windows are being minimized. I've tried using the DSCBTSHL.dll dll but it only traps when the WH_CBT message is happening but doesn't seem to trap and details (wParam and lParam) which are crucial to determine if it is the minimize button being pressed or maximize. I;ve looked all over but can't seem to find anything. Would anyone know a good dll that can trap system wide wh_cbt messages and that would also trap the wParam parameter?

System-wide Keyboard Hook Doesn't Work
Moderators, please feel free to delete this thread.

NEVERMIND. I SOLVED IT. I took out the highlighted parts in the coding. Look below.

Can someone tell me why this hook won't prevent the key from being used but applications? Other applications can still use the hooked keys.

For example, Internet Explorer still goes to full screen after pressing F11.

In Form...

Code:
Private Sub Form_Load()
KeyBoardHook = SetWindowsHookEx(WH_KEYBOARD_LL, AddressOf LowLevelKeyboardProc, App.hInstance, 0)
End Sub
Private Sub Form_Unload(Cancel As Integer)
UnhookWindowsHookEx KeyBoardHook
End Sub


In Module...

Code:
Option Explicit

Public Declare Function SetWindowsHookEx Lib "user32" Alias "SetWindowsHookExA" (ByVal idHook As Long, ByVal lpfn As Long, ByVal hmod As Long, ByVal dwThreadId As Long) As Long
Public Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
Public Declare Function UnhookWindowsHookEx Lib "user32" (ByVal hHook As Long) As Long
Public Declare Function CallNextHookEx Lib "user32" (ByVal hHook As Long, ByVal nCode As Long, ByVal wParam As Long, lParam As Any) As Long

Private Declare Function FindWindow Lib "user32" Alias _
"FindWindowA" (ByVal lpClassName As String, _
ByVal lpWindowName As String) As Long
Private Declare Function GetActiveWindow Lib "user32" () As Long

Public Type KBDLLHOOKSTRUCT
vkCode As Long
scanCode As Long
flags As Long
time As Long
dwExtraInfo As Long
End Type

Public Const WH_KEYBOARD = 2
Public Const WH_KEYBOARD_LL = 13
Public Const HC_ACTION = 0
Public Const VK_F9 = &H78
Public Const VK_F10 = &H79
Public Const VK_F11 = &H7A
Public KeyBoardHook As Long


Public Function LowLevelKeyboardProc(ByVal nCode As Long, ByVal wParam As Long, lParam As Long) As Long

Dim xpInfo As KBDLLHOOKSTRUCT

If nCode = HC_ACTION Then
CopyMemory xpInfo, lParam, Len(xpInfo)
If xpInfo.vkCode = VK_F9 Then
If xpInfo.flags = 1 Then
LowLevelKeyboardProc = -1
End If
End If
If xpInfo.vkCode = VK_F10 Then
If xpInfo.flags = 1 Then
LowLevelKeyboardProc = -1
End If
End If
If xpInfo.vkCode = VK_F11 Then
If xpInfo.flags = 1 Then
LowLevelKeyboardProc = -1
End If
End If
Else
LowLevelKeyboardProc = CallNextHookEx(KeyBoardHook, nCode, wParam, lParam) 'this will be called if there are multiple hooks made to the keyboard
End If

End Function

System Wide Hook To Open Windows On Secondary Display
Dear all,

I am making a VB6 application on DualView (Multi Monitor)
environment. where i make TV as Primary and
PC Monitor as Secondary for many reasons.

So the problem is, any new application windows are getting open
only on TV screen (Primary). Which is not correct.

So I have to run a spy program to hook all the windows in
System Wide Hook and move it to the Secondray display by
settings X coordination x=800.

And I need some filters to allow my windows on Secondary.
May be my window's Captions has got signatures (#xxxyyyzzzz#).
when we set the x=800, let us check this sign. and allow it.

Now I need C++ dll and a sample application to do this successfully.

I would appreciate the time u spend for me to make a samples.

And thanks in advance....

pls. mail me if any link is there...

soorya
XXXXXX@XXXl.com

Where Can I Learn More About HOOK And DLL Creation ?
                                     hiiiiiii !

                    Please help me to find tutorails , websites ...
           where i will learn programming HOOK ,object
           programming and DLL creation .

                                               THANKS A LOT


                                              

How Can I Hook A Folder Activity Like New File Creation Or Deletion From Vb
Dear ,
I want to hook a folder to know its activity like folder /file creation or deletion in it. When a file or folder created i recieve a message.
Also I want to know which folder is open in my computer (Explorer). I want it's full path.

System Hook
I have been searching for many many months and trying to figure out how to make a system wide hook. By this, I mean to log files, programs, and websites opened and closed. I have enclosed two vb projects that I found on other VB websites that kind of does this to a certain degree. It logs the captions of opened and closed windows.
Unfortunately, the first vb project attachment (original.zip) does not work on Windows XP nor does it work very well for Internet logging since it will sometimes make multiple logs of the same website that was only opened once.
The second vb project attachment (frmweb.zip) will only record the captions of visited websites.

Anyone help would be greatly appreciated and I would be willing to return the favor

PS
I just discovered this website a few days ago, and it is grand! I will continue posting and try to help others with their problems. Unfortunately, I am not an advanced user, so my help will be limited.

Need Help With Window Hook
I want to be able to keep a window in front of all other windows. This would be done by creating a window hook and then cancelling the message that allows the current window to lose focus.

Which window hook should I use, and how should I implement this hook.???

pleeeeeez

How To Get A Message From A System Hook.
I'm trying to intercept messages to a textbox running in some other app. I want to uses these messages in my VB6 app.

I installed a system hook using a Win32 dll. I'm following the example outlined in chapter 16 "Subclassing and Hooking" by Steven Teilbet.

Here the filter function is in the dll. So the dll traps the message but then how can I get that message back into my VB6 app that set the hook? Is this at all possible?

Hook Another Application's Window
VB Elites,

I want to draw a button on active window's titlebar, so I finish
shell hook to get active window's handler. I want to hook its WndPorc
to process some messages but i failed. GetLastDLLError = 5 , Access denied.

I use API SetWindowLong(GWL_WNDPROC), want to hook its WndProc.
Could you give me some directions, thank you very much in advance.

B.Rgds
Freeda

How Do I Hook A Window In A Different Process
I need to check for the firing of a message in several windows that are in an external application.

From what I read, it appears that native VB subclassing does not do this. It only works for the process that called the hook.

Here is a link I found that is pretty close to what I want:
http://www.mentalis.org/vbexamples/v...&category=MISC

The only problem with this tool is that the Callback function does not give the window that is being hooked. That is, I can trap the message but I don't know which one of the five window's being hooked initiated this message. If anyone knows of a similar control that:

a) hooks windows from EXTERNAL processes
b) lets me know what window called the hook
c) is free

Feel free to enlighten me.

Window Hook Proc
Alright, this is way over my head, but it's what I need to do, so some help would really be appreciated.

I need my app to set a windows hook that will check everytime a class ZafWindow tries to open up on the desktop to set it to invisible.

ShellExecute() with a SW_HIDE doesn't work, because it brings one ZafWindow up and then spawns a second ZafWindow which is Visible.

I don't want to have to loop and wait for a "Business Rules!" caption to appear and then do a showwindow() on it, because then it still flickers on the screen.

The only way I see of doing it is to do a SetWindowsHookEx() and watch for it to display ZafWindows, and keep them from showing up visible.

Any help would be greatly appreciated! Thank you!

Setting Window Hook
can someone give me the code for setting a hook on a specific window that does not belong to my program? i want to know when the text in a window which i don't think is a text box, because the text it holds displays as a webpage

if you didn't already guess im trying to fool with AIM

Adapt Window Hook.
Dmorley really helped me out with window messages. There is only one problem, this script only reads window messages within your project. Is there anyone who can get this to read window messages from other running applications? Anyone who can adapt this module to do so with this form?

The code flashes Form1 and WM_GETICON and WM_GETTEXT are detected. I want to get these from another application, not from one of my own forms.

I included the FindWindow API so that you can get the HWND of the outside application and hook it.

Here's the form...

Code:
Option Explicit

Private Declare Function FindWindow Lib "user32" _
Alias "FindWindowA" ( _
ByVal lpClassName As String, _
ByVal lpWindowName As String) As Long

Const FLASHW_STOP = 0
Const FLASHW_CAPTION = &H1
Const FLASHW_TRAY = &H2
Const FLASHW_ALL = (FLASHW_CAPTION Or FLASHW_TRAY)
Const FLASHW_TIMER = &H4
Const FLASHW_TIMERNOFG = &HC

Private Type FLASHWINFO
cbSize As Long
hwnd As Long
dwFlags As Long
uCount As Long
dwTimeout As Long
End Type

Private Declare Function FlashWindowEx Lib "user32" _
(pfwi As FLASHWINFO) As Boolean

Private Sub Form_Load()

Dim FlashInfo As FLASHWINFO
FlashInfo.cbSize = Len(FlashInfo)
FlashInfo.dwFlags = FLASHW_ALL Or FLASHW_TIMER
FlashInfo.dwTimeout = 0
FlashInfo.hwnd = Me.hwnd
FlashInfo.uCount = 0
FlashWindowEx FlashInfo

Hook Me.hwnd

End Sub

Private Sub Form_Unload(Cancel As Integer)

Unhook

End Sub


Here's the module.

Code:
Option Explicit

Private Declare Function CallWindowProc Lib "user32.dll" _
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 Function SetWindowLong Lib "user32.dll" _
Alias "SetWindowLongA" ( _
ByVal hwnd As Long, _
ByVal nIndex As Long, _
ByVal dwNewLong As Long) As Long

Private Const GWL_WNDPROC = -4

Private hControl As Long
Private lPrevWndProc As Long

Private Const WM_GETICON = &H7F
Private Const WM_GETTEXT = &HD

Private Function WindowProc(ByVal lWnd As Long, ByVal lMsg As Long, _
ByVal wParam As Long, ByVal lParam As Long) As Long

Select Case lMsg
Case WM_GETICON: Form1.List1.AddItem "WM_GETICON"
Case WM_GETTEXT: Form1.List1.AddItem "WM_GETTEXT"
End Select

WindowProc = CallWindowProc(lPrevWndProc, lWnd, lMsg, wParam, lParam)

End Function

Public Sub Hook(ByVal hControl_ As Long)
hControl = hControl_
lPrevWndProc = SetWindowLong(hControl, GWL_WNDPROC, AddressOf WindowProc)
End Sub

Public Sub Unhook()
Call SetWindowLong(hControl, GWL_WNDPROC, lPrevWndProc)
End Sub

[HARD]How To Hook Top Window's Titlebar ?
Everyone,

I was surprised by a program which can draw a button on any window during my win98 system running.

I want to know if i must get all window's handle to hook them
or only need to monitor (maybe) "register window" message?

I think It's very cool, so I hope someone can hack it.

Best Regards
Freeda

Hook A Window And Replace Its Icon.
I'm trying to find a way to change the icon for any window.
I'm doing this because I'll typically have multiple windows of an application. Each window is being used for a different purpose. Accounting, Inventory, Software developent, etc. I know how to change the caption but I want the ability to change the icon as well.

Hook Password Window In MS WORD
Hi all of yu
I would like to be able to hook the password window in MSWORD 2003 when opening an encrypted document ,to bring automation to the doc decryption after having done a strong identification of the user.

Anyone knows how to perform that ?

In other words : I am able to identify any individual, according to this identification I would like to automate the encryption decryption process on PKI scheme RSA MD5.

When I encrypt a Doc , and I try to open it the problems are :
the properties where autorized recipients are stored are unavailable (encrypted)
when trying to open the doc , the password window appears and I can't succeed taking control programmatically ..

I would like to be able to check programmatically if a Doc is encrypted, then if so check programmatically the authorized recipient name, then perform the user Biometric identification (This process I know), then programmatically decrypt the file in RSA PKI sheme.

who can give me a hand ? Any help much appreciated.

Need A Hook To Detect The Closure Of An External Window
I am writing an app that opens a file into its associated program via windows shellexecute. But i need to have a hook that detects when that document has been close or the window in which it resides has been closed.

I have got the code that finds the window handle but rather than continuously calling the window to see if its still there i need a way to just set a hook and wait for the return.

Please please please help, i have been searching but not really understanding all the hook options and don't seem to find any help on this kind of request.

thanks in advance

Ant.

Hook / Unhook A Window &amp; List Processes In Textbox?
hi , i'm doing a test. i have "hooked" in to a textbox ( text1.hWnd ) and am looking at capturing messages ( like WM_PAINT , WM_MOUSEMOVE etc ) , is there a way for me to list all processes without having to know each process and use "Select Case"?
eg:

Code:
Select Case msg
Case WM_PAINT
DefWindowProc hwnd, msg, wParam, lParam
Form1.tbPainted ("WM_PAINT" & lParam)
Case WM_MOUSEMOVE
DefWindowProc hwnd, msg, wParam, lParam
Form1.tbPainted ("WM_MOUSEMOVE" & lParam)
Case WM_RBUTTONDOWN
DefWindowProc hwnd, msg, wParam, lParam
Form1.tbPainted ("WM_RBUTTONDOWN" & lParam)
Case WM_RBUTTONUP
DefWindowProc hwnd, msg, wParam, lParam
Form1.tbPainted ("WM_RBUTTONUP" & lParam)
Case Else
NewWindowProc = CallWindowProc( _
OldWindowProc, hwnd, msg, wParam, _
lParam)
End Select
if i wanted to capture all events it seems like a lot of consts are needed in there and i aint even sure what all the messages are
if i try to tell it just to list the msg etc without select case the app just closes down
thanx

How To Hook An Applicaiton To Run Whever The System Is Connected To Internet Or Disco
can anyone please let me know, how to hook an applicaiton to run whenever the system is connected to internet or disconnected. my aim is to run the application whever the system is connected to interet or disconnected. please tell me is there any way of hooking for this?

Regards
praveenp

How To Hook An Application To Run Whever The System Is Connected To Internet Or Disco
can anyone please let me know how to hook an application to run whenever the system is connected to internet or disconnected. my aim is to run my applicaiton whever the system is connected to interenet or disconnected.
please help me in this regard

regards
praveenp

Api Hook
Hello All,

I'm want to write a plugin for my application that can watch an installation for registry entries created, files created, and files copied. Also, i need to watch the installed program for the same stuff. The end goal here is to be able to repack the installation so that it can be deployed later. I've been creating a bootloader with some recover utilities in assembly for (NT 9X Linux). So, everytime i think it's ready, I get brave move it from the test computer to my good one....and a few days later......OOOPS...Reformat!!! I keep ghost backups now so it's not really a problem.. But i told myself I would write this so i'm going to give it a shot!!

So, how do i hook the api calls in a process so that i can log them?

Thanks very much for past and future responses!

How To Use A Hook ?
Hi,

i want to take over a program for a period of time, to set settings right, but i don't want to let the mouse move and the program doesn't have to be the active window.

So i've heard that i need to use a hook, intercept the messages from the message pump, ignore those (to disable manual input), and put my own message in that program its message pump.

Now can someone give me a general idea how to use such a hook?
I know all the hooks for windows in vb can't go out of the process that creates it, but i just saw there is 1 that can, the Windows Journal PlayBack Hook.

Can anyone help me with that? All i want to do is send messages to the program to alter the options.

Thanks in advance

Hook
I am Using Hook and unHook to avoid right click and paste on my controls especially the password textbox.
This is leading to lot of memory leak....my VB Application keeps closing....
once i comment the code it does not close...
i dont have this problem in the Exe ??????

Any ideas why ???

Public Sub Hook(hwnd As Long)
lngHWnd = hwnd
lpPrevWndProc = SetWindowLong(lngHWnd, GWL_WNDPROC, _
AddressOf WindowProc)
End Sub

Public Sub UnHook()
Dim lngReturnValue As Long
lngReturnValue = SetWindowLong(lngHWnd, GWL_WNDPROC, lpPrevWndProc)
End Sub

Hook Into IE
how can you hook into an active IE window's textfield and get the text in it?

thanks

How To Hook?
im trying to send data from a file to a game called Diablo 2 in the data will be the persons account and password all i really want it to do is login with those txts

API Hook
How would you API Hook WriteProcessMemory on another process?

I have a vague idea but not clear enough for me to overcome.

Hook Help
Ok, so I have the hook in place and it works, but there is a slight problem. I have it so it will send all the keys to a text box, however, upon hitting a single key one time it returns the letter several times.

Does anyone know of a way I could trap it so it will only return it once?

Hook
Hi!
I have a problem with a hook:
Form_Load:
hHook = SetWindowsHookEx(WH_KEYBOARD, AddressOf KeyboardProc, App.hInstance, App.ThreadID)

and in Form_Unload:
UnhookWindowsHookEx hHook

After the program ends the VB crashes...
What's the problem?

DLL Hook
Ok I Am Lookin To Make A DLL Hook Is There A Source Code.Theres A Program That Reads Memory And I want To Unhook It And Hook My Own To Read What I Want i Heard LoadLibraryA If Anyone Give Me A Hand With This I Would Appreciate It Thx

IE Hook
Two-fold Q here:
1.) I am looking to create an IE toolbar/toolbar button for my app.
2.) This app needs to intercept the BeforeNavigate2 Event in IE.

How do i create the button?

And How do i intercept the event


**Bonus** Can anyone do it for netscape too?

Hook Does Not Hook?
Aaron Young's hook program works well on my pc but when i try it on the workstation of my university LAN it doesnot even hook. it just ends after specifying the path of the file to store the logs.

Why???????????
Is there a solution to the problem?

CBT Hook
I am trying to create an program that will hook whenever a new window is opened and be able to tell me the EXE from that windows process. I can do the second part just fine but I'm having trouble with The CBT Hook.

I can't get the hook to be global, it only tells me when windows are opened in my process. Does anyone know how I can make a Global CBT hook, If I can make a global CBT Hook?

I was reading the documentation from msdn on SetWindowsHookEX and it would appear that a CBT Hook can be global unless global means something that I don't think it does. Right now I'm using the hook library availiable on VbAccelerator



Edited by - msg555 on 1/1/2005 11:59:57 AM

Direct3D Hook Dll?
is there a direct3d hook dll available which would allow me to draw text over a directx game through visual basic?

i want to display an ingame clock and maybe an fps counter over ANY direct3d game...

i've found the proxy dll by www.mikoweb.eu after some searching....
it works nice for single games though and allows me todo everything i want
but it doesn't work when injected at runtime and i want my application to work generally in every direct3d game without having to copy a dll file to every games folder...

i want to inject the dll with madcodehook from www.madshi.net (works fine with the example direct3d hook dll that comes with it) but unfortunately C is a complette mystery to me :X

thanks in advance for every point in the right direction

Keyboard Hook
Hello all.

I have this game that uses directx, is it possible to do certain events in a visual basic when a certain button is pressed in the game that is using directx ? I searched these forums and it seems directx input captures all keystrokes, but is it possible to read the pressed keys from the game if i would start the game from visual basic and set the game as a some sort of child window ? Or could this be achieved by keeping the visual basic program as an active window and let it capture the keystrokes, and then pass them to the game, so that the vb program would kind of filter the keystrokes trough it ?

Thanks in advance.
Oltzi

Hook Of Excel
VB6

I'm trying to make a Hook to an Excel Sheet from VB6 by using the following code to find the workbook. The Excel has been set as child to a MDI Form.

My problem is that the callback procedure is not called at all. What is wrong?
All the window handles looks okay. I found this as an example created in VBA which worked allright. This hook worked with the bWnd handle below.

Code:
bWnd = FindWindowEx(MDIForm1.hWnd, 0&, "XLMAIN", mobjXL.Caption)
hWnd = FindWindowEx(bWnd, ByVal 0&, "XLDESK", vbNullString)
twnd = FindWindowEx(hWnd, ByVal 0&, "EXCEL7", "Test1.xls")
Hook
I use the following code to make the hook to the found twnd above.
All the declarations is not included here.

Code:
'Hooking the Left Mouse Click
Public Function Hook() As Long
lpPrevWndProc = SetWindowLong(twnd, GWL_WNDPROC, AddressOf WindowProc)
Hook = 0
End Function

'Call back procedure
Public Function WindowProc(ByVal hw As Long, ByVal uMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
If uMsg = WM_LBUTTONDOWN Then
With ActiveCell
.Value = "X"
.Characters.Font.Bold = True
.HorizontalAlignment = xlCenter
End With
Else
WindowProc = CallWindowProc _
(lpPrevWndProc, hw, uMsg, wParam, lParam)
End If
unHook
End Function

Public Function unHook() As Long
RC = SetWindowLong(ghWnd, GWL_WNDPROC, lpPrevWndProc)
unHook = RC
End Function

Hook A Listbox
I used Volte's example for hooking a listbox so that I can add colors to each item.
If I have a single form and then open it then all works ok.
How can I hook a certain form?
I have a MDI form and my listbox is on a child form. I want to hook that so that it can work there...
The actual code is:


Code:
Public Sub Main()

'hook the app, so we can apply the ownerdrawn style to the list box.
lHook = SetWindowsHookEx(WH_CALLWNDPROC, AddressOf ListHook, App.hInstance, App.ThreadID)

'show the form
frmMain.Show

'unhook the app
UnhookWindowsHookEx lHook

End Sub

' and in the form's load event i have the following code:

Private Sub Form_Load()
'subclass the _parent_ of the listbox (the form in this case).
oldWindowProc = SetWindowLong(GetParent(lstColors.hwnd), GWL_WNDPROC, AddressOf NewWindowProc)
End Sub

This works ok... but if instead of frmMain.Show i put form1.show and on form1 i have a button to open frmmain then the hooking doesn't work anymore.
I think the right place for the code is somewhere around here: lHook = SetWindowsHookEx(WH_CALLWNDPROC, AddressOf ListHook, App.hInstance, App.ThreadID) but sincerely I don't know what to change there.

Sound Hook
Does any body know how can i make a sound hook which trap any sound being sent to the speaker and change it?

Keyboard Hook
Hi everyone.
I am new to this forum, although I’ve found a lot of stuff reading on that forum that helped me a lot of times. So that is my firs post and I hope that somebody could help me.

I have an ADO object and I would like to make the recodset to MoveNext or MovePrevious by pushing “PageUp” abd “PageDown” keys. I putthe folowing code:

Code:
Sub txt1_KeyDown(KeyCode as Integer)
If KeyCode = 38 Then ADODC1.Recordset.MoveNext
But in that case, the txt1 control should be focused… Otherwise it will not work… So I am wondering if there is a way to hook the keyboard and check every pushed button. Or there is another way of browsing the records by PageUp and PageDown keys.

Thanks in advance

Hook Events
can someone point me in the direction of a good tutorial to catching events. i have heard it called hooking but i'm not sure what this means at all.
thanks

How To Hook A Folder When It's Contains Changes?
Dear,
I want to check if a file is added in a folder. I want it in such a way that when the file is added (Anyfile) It fires an event

Copyright © 2005-08 www.BigResource.com, All rights reserved