I have made this code
(it is just test code)
Everything is fine inside my apps (i call StartHook within Vb6)
But it doesn't seem to trap when other apps windows are activate
nore it add's My User-Made Menu...
Can Anybody Help?
I've read in MSDN that Hook placed in Standard DLL
Were System-Wide!
-------------
Daniel
(it is just test code)
Code:
#Compile Dll #Dim All #Include "WIN32API.INC" Global hHook As Long Global gWH As Long Global lpPrevWndProc As Long Sub StartHook Alias "StartHook"(ByVal Hwnd As Long)Export Dim hInst As Long Dim Thrd As Long Dim Address As Long hInst = GetWindowLong(Hwnd, %GWL_HINSTANCE) Thrd = GetCurrentThreadId() Address = CodePtr(HookProc) hHook = SetWindowsHookEx(%WH_CBT, Address, hInst, 0) End Sub '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Sub StopHook Alias "StopHook"()Export UnhookWindowsHookEx hHook End Sub '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Function HookProc(ByVal lMsg As Long, ByVal wparam As Long, ByVal lparam As Long) As Long Dim hw As Long Dim Address As Long Dim hMenu As Long Dim X As Long Dim S As Asciiz * 20 Dim rt As Long If lMsg < 0 Then HookProc = CallNextHookEx(hHook, lMsg, wparam, lparam) Exit Function End If '»If lMsg < 0 Then If lMsg = %HCBT_ACTIVATE Then 'MsgBox "Activate Window" gWH = wparam hMenu = GetSystemMenu(gWH, %False) S = "&Our Function" X = AppendMenu(hMenu, %MF_STRING, %SC_NEWMENU, S) rt = GetLastError Address = CodePtr(WindowProc) lpPrevWndProc = SetWindowLong(gWH, %GWL_WNDPROC, Address) End If HookProc = 0 End Function '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Function WindowProc(ByVal hw As Long, ByVal uMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long 'We need to trap the WM_SYSCOMMAND message to 'determine when the user has clicked on our 'new menu item. The message is stored in uMsg. 'Our new menu item is identified as SC_NEWMENU Dim xx As Long If uMsg = %WM_SYSCOMMAND Then Select Case wParam And &HFFFF& Case %SC_NEWMENU xx = SetWindowPos(gWH, %HWND_TOPMOST, 0, 0, 0, 0, %FLAGS) End Select End If 'Always call the original handler when done WindowProc = CallWindowProc(lpPrevWndProc, hw, uMsg, wParam, lParam) End Function
But it doesn't seem to trap when other apps windows are activate
nore it add's My User-Made Menu...
Can Anybody Help?
I've read in MSDN that Hook placed in Standard DLL
Were System-Wide!
-------------
Daniel
Comment