Archive for the ‘Hook’ Tag
Vb Net – Low Level Mouse Hook (Global)
This blog has moved
New location: http://sim0n.wordpress.com/
Posts matching query:
[VB.Net] Mouse Hook Class
[VB.Net] Keyboard Hook Class
Vb Net – Low Level Keyboard Hook (Global)
This blog has moved
New location: http://sim0n.wordpress.com/
Posts matching query:
[VB.Net] Keyboard Hook Class
[VB.Net] Mouse Hook Class
C# – MSN Conversation Window Blocking
using System;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace MSN_Event_Hooker
//Blocks the opening of any MSN conversation window
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
MessengerAPI.Messenger MSN = new MessengerAPI.Messenger();
MSN.OnIMWindowCreated += new MessengerAPI.DMessengerEvents_OnIMWindowCreatedEventHandler(OnIMWindowCreated);
}
void OnIMWindowCreated(object plMWindow)
{
MessengerAPI.IMessengerWindow theWindow = (MessengerAPI.IMessengerWindow)plMWindow;
int wHwnd = theWindow.HWND;
IntPtr cwHwnd;
cwHwnd = new IntPtr(wHwnd);
theWindow.Close();
}
}
}
VB Net – Add Menus To Minesweeper
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
‘*********************************************************************************’
‘***********************************Add Menus*************************************’
‘*********************************************************************************’
MenuHook.SetHook(“Minesweeper”)
Dim menus As New Collection
menus.Add(“Stats”)
menus.Add(“Cheats”)
menus.Add(“About”)
MenuHook.AddMenus(“Other”, menus)
End Sub
Then, for the menuhook class, these are the functions:
Public Class MenuHook
Private Const MF_BYCOMMAND As Integer = &H0
Private Const MF_BYPOSITION As Integer = &H400
Private Const MF_POPUP As Integer = &H10
Private Const MF_STRING As Integer = &H0
Shared Offset As Integer = 2000
Private Const WM_COMMAND As Integer = &H111S
Private Const PROCESS_ALL_ACCESS = &H1F0FFF
Private Declare Function AppendMenu Lib “user32″ Alias “AppendMenuA” (ByVal hMenu As Integer, ByVal wFlags As Integer, ByVal wIDNewItem As Integer, ByVal lpNewItem As String) As Integer
Private Declare Function CreatePopupMenu Lib “user32″ () As Integer
Private Declare Function DrawMenuBar Lib “user32″ (ByVal hwnd As Integer) As Integer
Public Declare Function FindWindow Lib “user32″ Alias “FindWindowA” (ByVal lpClassName As String, ByVal lpWindowName As String) As Integer
Private Declare Function GetMenu Lib “user32″ (ByVal hwnd As Integer) As Integer
Private Declare Function GetSubMenu Lib “user32″ (ByVal hMenu As Integer, ByVal nPos As Integer) As Integer
Private Declare Function GetMenuState Lib “user32″ (ByVal hMenu As Integer, ByVal wID As Integer, ByVal wFlags As Integer) As Integer
Private Declare Function GetMenuItemCount Lib “user32″ (ByVal hMenu As Integer) As Integer
Private Declare Function InsertMenu Lib “user32″ Alias “InsertMenuA” (ByVal hMenu As Integer, ByVal nPosition As Integer, ByVal wFlags As Integer, ByVal wIDNewItem As Integer, ByVal lpNewItem As String) As Integer
Private Declare Function IsWindow Lib “user32″ (ByVal hwnd As Integer) As Integer
Private Delegate Function SubClassProcDelegate(ByVal hwnd As Integer, ByVal msg As Integer, ByVal wParam As Integer, ByVal lParam As Integer) As Integer
Private Declare Function SetCWPMSGHook Lib “dscwpmsg” (ByVal hwnd As Integer, ByVal AdrCWP As Integer, ByVal AdrMSG As SubClassProcDelegate) As Integer
Declare Function OpenProcess Lib “kernel32″ (ByVal dwDesiredAccess As Integer, ByVal bInheritHandle As Integer, ByVal dwProcessId As Integer) As Integer
Declare Function CloseHandle Lib “kernel32″ Alias “CloseHandle” (ByVal hObject As Integer) As Integer
Declare Function ReadProcessMemory Lib “kernel32″ (ByVal hProcess As Integer, ByVal lpBaseAddress As Integer, ByVal lpBuffer As String, ByVal nSize As Integer, ByRef lpNumberOfBytesWritten As Integer) As Integer
Private Shared hmen, hNote, hsub As Integer
Private Enum WindowStyles
WS_OVERLAPPED = &H0
WS_POPUP = &H80000000
WS_CHILD = &H40000000
WS_MINIMIZE = &H20000000
WS_VISIBLE = &H10000000
WS_DISABLED = &H8000000
WS_CLIPSIBLINGS = &H4000000
WS_CLIPCHILDREN = &H2000000
WS_MAXIMIZE = &H1000000
WS_BORDER = &H800000
WS_DLGFRAME = &H400000
WS_VSCROLL = &H200000
WS_HSCROLL = &H100000
WS_SYSMENU = &H80000
WS_THICKFRAME = &H40000
WS_GROUP = &H20000
WS_TABSTOP = &H10000
WS_MINIMIZEBOX = &H20000
WS_MAXIMIZEBOX = &H10000
WS_CAPTION = WS_BORDER Or WS_DLGFRAME
WS_TILED = WS_OVERLAPPED
WS_ICONIC = WS_MINIMIZE
WS_SIZEBOX = WS_THICKFRAME
WS_TILEDWINDOW = WS_OVERLAPPEDWINDOW
WS_OVERLAPPEDWINDOW = WS_OVERLAPPED Or WS_CAPTION Or WS_SYSMENU Or WS_THICKFRAME Or WS_MINIMIZEBOX Or WS_MAXIMIZEBOX
WS_POPUPWINDOW = WS_POPUP Or WS_BORDER Or WS_SYSMENU
WS_CHILDWINDOW = WS_CHILD
End Enum
Public Enum Gameover
WON = 1
LOST = 2
End Enum
Public Shared Sub AddMenus(ByVal MenuTitle As String, ByVal MenuItems As Collection)
hmen = GetMenu(hNote)
hsub = CreatePopupMenu
For Each menuitem As String In MenuItems
Offset += 1
AppendMenu(hsub, MF_STRING, Offset, menuitem)
Next
InsertMenu(hmen, 10, MF_BYPOSITION Or MF_POPUP, hsub, MenuTitle)
DrawMenuBar(hNote)
Offset = 2000
End Sub
Public Shared Sub SetHook(ByVal WindowTitle As String)
hNote = FindWindow(vbNullString, WindowTitle)
If IsWindow(hNote) = 0 Then
Do Until IsWindow(hNote)
hNote = FindWindow(WindowTitle, vbNullString)
System.Windows.Forms.Application.DoEvents()
Loop
End If
Call SetCWPMSGHook(hNote, 0, AddressOf Callback)
End Sub
Private Shared Function Callback(ByVal hwnd As Integer, ByVal wMsg As Integer, ByVal wParam As Integer, ByVal lParam As Integer) As Integer
Select Case wMsg
Case WM_COMMAND
Debug.Print(wParam)
If wParam = 2001 Then
MsgBox(“a”)
ElseIf wParam = 2002 Then
MsgBox(“b”)
ElseIf wParam = 2003 Then
MsgBox(“c”)
ElseIf wParam = 2004 Then
MsgBox(“d”)
End If
End Select
End Function
End Class
Comments (1)
Comments (13)
Comments (1)