Главная страница
    Top.Mail.Ru    Яндекс.Метрика
Форум: "WinAPI";
Текущий архив: 2002.01.14;
Скачать: [xml.tar.bz2];

Вниз

HOOK   Найти похожие ветки 

 
Oleg Gashev   (2001-11-13 22:20) [2]

Monitoring System Events

The following example uses a variety of thread-specific hook procedures to monitor the system for events affecting a thread. It demonstrates how to process events for the following types of hook procedures:

WH_CALLWNDPROC
WH_CBT
WH_DEBUG
WH_GETMESSAGE
WH_KEYBOARD
WH_MOUSE
WH_MSGFILTER
The user can install and remove a hook procedure by using the menu. When a hook procedure is installed and an event that is monitored by the procedure occurs, the procedure writes information about the event to the client area of the application"s main window.

#define NUMHOOKS 7

// Global variables

typedef struct _MYHOOKDATA
{
int nType;
HOOKPROC hkprc;
HHOOK hhook;
} MYHOOKDATA;

MYHOOKDATA myhookdata[NUMHOOKS];

LRESULT WINAPI MainWndProc(HWND hwndMain, UINT uMsg, WPARAM wParam,
LPARAM lParam)
{
static BOOL afHooks[NUMHOOKS];
int index;
static HMENU hmenu;

switch (uMsg)
{
case WM_CREATE:

// Save the menu handle.

hmenu = GetMenu(hwndMain);


// Initialize structures with hook data. The menu-item
// identifiers are defined as 0 through 6 in the
// header file. They can be used to identify array
// elements both here and during the WM_COMMAND
// message.

myhookdata[IDM_CALLWNDPROC].nType = WH_CALLWNDPROC;
myhookdata[IDM_CALLWNDPROC].hkprc = CallWndProc;
myhookdata[IDM_CBT].nType = WH_CBT;
myhookdata[IDM_CBT].hkprc = CBTProc;

myhookdata[IDM_DEBUG].nType = WH_DEBUG;
myhookdata[IDM_DEBUG].hkprc = DebugProc;
myhookdata[IDM_GETMESSAGE].nType = WH_GETMESSAGE;
myhookdata[IDM_GETMESSAGE].hkprc = GetMsgProc;
myhookdata[IDM_KEYBOARD].nType = WH_KEYBOARD;
myhookdata[IDM_KEYBOARD].hkprc = KeyboardProc;
myhookdata[IDM_MOUSE].nType = WH_MOUSE;
myhookdata[IDM_MOUSE].hkprc = MouseProc;
myhookdata[IDM_MSGFILTER].nType = WH_MSGFILTER;

myhookdata[IDM_MSGFILTER].hkprc = MessageProc;

// Initialize all flags in the array to FALSE.

memset(afHooks, FALSE, sizeof(afHooks));

return 0;

case WM_COMMAND:
switch (LOWORD(wParam))
{
// The user selected a hook command from the menu.

case IDM_CALLWNDPROC:
case IDM_CBT:
case IDM_DEBUG:
case IDM_GETMESSAGE:

case IDM_KEYBOARD:
case IDM_MOUSE:
case IDM_MSGFILTER:

// Use the menu-item identifier as an index
// into the array of structures with hook data.

index = LOWORD(wParam);

// If the selected type of hook procedure isn"t
// installed yet, install it and check the
// associated menu item.


if (!afHooks[index])
{
myhookdata[index].hhook = SetWindowsHookEx(
myhookdata[index].nType,
myhookdata[index].hkprc,
(HINSTANCE) NULL, GetCurrentThreadId());
CheckMenuItem(hmenu, index,
MF_BYCOMMAND | MF_CHECKED);
afHooks[index] = TRUE;

}

// If the selected type of hook procedure is
// already installed, remove it and remove the
// check mark from the associated menu item.

else
{
UnhookWindowsHookEx(myhookdata[index].hhook);
CheckMenuItem(hmenu, index,
MF_BYCOMMAND | MF_UNCHECKED);
afHooks[index] = FALSE;

}

default:
return (DefWindowProc(hwndMain, uMsg, wParam,
lParam));
}
break;

//
// Process other messages.
//

default:
return DefWindowProc(hwndMain, uMsg, wParam, lParam);
}
return NULL;
}

Help



Страницы: 1 вся ветка

Форум: "WinAPI";
Текущий архив: 2002.01.14;
Скачать: [xml.tar.bz2];

Наверх





Память: 0.45 MB
Время: 0.004 c
14-42567
Anatoly Podgoretsky
2001-11-18 17:08
2002.01.14
TOP TEN


6-42532
yuger
2001-10-19 17:56
2002.01.14
Доступ к компьютеру из сети


4-42602
Shmel
2001-11-06 01:07
2002.01.14
Как получить текст из ячеек TstringGrid в чужом окне? Handle я знаю.


1-42496
Ron1
2001-12-25 23:52
2002.01.14
Реестр


1-42488
Анатолий
2001-12-24 05:39
2002.01.14
Метка





Afrikaans Albanian Arabic Armenian Azerbaijani Basque Belarusian Bulgarian Catalan Chinese (Simplified) Chinese (Traditional) Croatian Czech Danish Dutch English Estonian Filipino Finnish French
Galician Georgian German Greek Haitian Creole Hebrew Hindi Hungarian Icelandic Indonesian Irish Italian Japanese Korean Latvian Lithuanian Macedonian Malay Maltese Norwegian
Persian Polish Portuguese Romanian Russian Serbian Slovak Slovenian Spanish Swahili Swedish Thai Turkish Ukrainian Urdu Vietnamese Welsh Yiddish Bengali Bosnian
Cebuano Esperanto Gujarati Hausa Hmong Igbo Javanese Kannada Khmer Lao Latin Maori Marathi Mongolian Nepali Punjabi Somali Tamil Telugu Yoruba
Zulu
Английский Французский Немецкий Итальянский Португальский Русский Испанский