0/5 (8 avis)
Vue 8 631 fois - Téléchargée 662 fois
#include <windows.h> HINSTANCE hinst; HWND hmain, hed1, hed2, hed3; HHOOK hhk = 0; char szappname[] = "MsgHook"; char szEDIT[] = "EDIT"; // le HOOK LOCAL est ICI LRESULT CALLBACK GetMsgProc(int nCode, WPARAM wParam, LPARAM lParam) { MSG *lpmsg; lpmsg = (MSG*) lParam; if(nCode < 0) goto defRet; // NE JAMAIS TOUCHER DANS CE CAS if(lpmsg->message == WM_RBUTTONUP) { if(IsChild(hmain, lpmsg->hwnd)) SetWindowText(lpmsg->hwnd, "Y a un HOOK"); else PostMessage(lpmsg->hwnd, WM_CLOSE, 0, 0); return 1; } defRet: return (CallNextHookEx(hhk, nCode, wParam, lParam)); } LRESULT CALLBACK AppWndProc(HWND hwnd, UINT mssg, WPARAM wParam, LPARAM lParam) { switch(mssg) { case WM_CREATE: hed1 = CreateWindow(szEDIT, 0, WS_CHILD | WS_VISIBLE | WS_BORDER, 10, 10, 300, 20, hwnd, (HMENU) 1000, hinst, 0); hed2 = CreateWindow(szEDIT, 0, WS_CHILD | WS_VISIBLE | WS_BORDER, 10, 60, 300, 20, hwnd, (HMENU) 1001, hinst, 0); hed3 = CreateWindow(szEDIT, 0, WS_CHILD | WS_VISIBLE | WS_BORDER, 10, 110, 300, 20, hwnd, (HMENU) 1002, hinst, 0); hhk = SetWindowsHookEx(WH_GETMESSAGE, GetMsgProc, 0, GetCurrentThreadId()); return 0; case WM_SETFOCUS: SetFocus(hed1); return 0; case WM_DESTROY: if(hhk) UnhookWindowsHookEx(hhk); PostQuitMessage(0); return 0; } return DefWindowProc(hwnd, mssg, wParam, lParam); } DWORD InitInstance() { WNDCLASSEX wndcls; RECT rct; memset(&wndcls, 0, sizeof(WNDCLASSEX)); wndcls.cbSize = sizeof(WNDCLASSEX); wndcls.lpfnWndProc = AppWndProc; wndcls.style = CS_HREDRAW | CS_VREDRAW; wndcls.hInstance = hinst; wndcls.lpszClassName = szappname; wndcls.hbrBackground = (HBRUSH) GetStockObject(GRAY_BRUSH); wndcls.hCursor = LoadCursor(0, IDC_ARROW); if(!RegisterClassEx(&wndcls)) return 0; hmain = CreateWindowEx(0, szappname, szappname, WS_OVERLAPPEDWINDOW | WS_VISIBLE, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, 0, 0, hinst, 0); return (hmain != 0); } int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, PSTR, int) { MSG msg; hinst = hInstance; if(!InitInstance()) return 0; ShowWindow(hmain, SW_NORMAL); while(GetMessage(&msg, NULL, 0, 0)) { TranslateMessage(&msg); DispatchMessage(&msg); } return 0; }
10 juin 2007 à 01:17
25 nov. 2006 à 08:09
Et vu que les menus ont leur propre boucles de messages, je ne peux pas récupérer les WM_DRAWITEM, c'est pourquoi j'ai pensé au hook
25 nov. 2006 à 01:15
25 nov. 2006 à 00:24
Je souhaiterais faire la même chose, mais avec WM_DRAWITEM et WM_MEASUREITEM.
Visiblement ils ne sont pas interceptés par ce hook, je vois pas pourquoi...
Tu as une idée?
22 févr. 2006 à 17:52
Je souhaitais hooker aussi la souris dans une de mes application. Grace a toi je vois mieux le principe.
J'etais en train de me fourvoyer et de perdre beaucoup de temps. Je m'interessais au hook de souris au lieu des message. Normalement cela devrait etre suffisant. Si non je reprendrais mon Hook de souris.
Ce que je souhaite faire c'est dans un conteneur ActiveX : IWebBrowser2 popur enpecher le clic droit ou le remplacer par mon propre menu.
Merci de ta participation
Vous n'êtes pas encore membre ?
inscrivez-vous, c'est gratuit et ça prend moins d'une minute !
Les membres obtiennent plus de réponses que les utilisateurs anonymes.
Le fait d'être membre vous permet d'avoir un suivi détaillé de vos demandes et codes sources.
Le fait d'être membre vous permet d'avoir des options supplémentaires.