本文整理汇总了C++中SetWindowsHookEx函数的典型用法代码示例。如果您正苦于以下问题:C++ SetWindowsHookEx函数的具体用法?C++ SetWindowsHookEx怎么用?C++ SetWindowsHookEx使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了SetWindowsHookEx函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: InitializeCallWndProcHook
bool InitializeCallWndProcHook(int threadID, HWND destination)
{
if (g_appInstance == NULL)
{
return false;
}
if (GetProp(GetDesktopWindow(), "WILSON_HOOK_HWND_CALLWNDPROC") != NULL)
{
SendNotifyMessage((HWND)GetProp(GetDesktopWindow(), "WILSON_HOOK_HWND_CALLWNDPROC"), RegisterWindowMessage("WILSON_HOOK_CALLWNDPROC_REPLACED"), 0, 0);
}
SetProp(GetDesktopWindow(), "WILSON_HOOK_HWND_CALLWNDPROC", destination);
hookCallWndProc = SetWindowsHookEx(WH_CALLWNDPROC, (HOOKPROC)CallWndProcHookCallback, g_appInstance, threadID);
return hookCallWndProc != NULL;
}
示例2: InitializeGetMsgHook
bool InitializeGetMsgHook(int threadID, HWND destination)
{
if (g_appInstance == NULL)
{
return false;
}
if (GetProp(GetDesktopWindow(), "WILSON_HOOK_HWND_GETMSG") != NULL)
{
SendNotifyMessage((HWND)GetProp(GetDesktopWindow(), "WILSON_HOOK_HWND_GETMSG"), RegisterWindowMessage("WILSON_HOOK_GETMSG_REPLACED"), 0, 0);
}
SetProp(GetDesktopWindow(), "WILSON_HOOK_HWND_GETMSG", destination);
hookGetMsg = SetWindowsHookEx(WH_GETMESSAGE, (HOOKPROC)GetMsgHookCallback, g_appInstance, threadID);
return hookGetMsg != NULL;
}
示例3: InitializeMouseHook
bool InitializeMouseHook(int threadID, HWND destination)
{
if (g_appInstance == NULL)
{
return false;
}
if (GetProp(GetDesktopWindow(), "WILSON_HOOK_HWND_MOUSE") != NULL)
{
SendNotifyMessage((HWND)GetProp(GetDesktopWindow(), "WILSON_HOOK_HWND_MOUSE"), RegisterWindowMessage("WILSON_HOOK_MOUSE_REPLACED"), 0, 0);
}
SetProp(GetDesktopWindow(), "WILSON_HOOK_HWND_MOUSE", destination);
hookMouse = SetWindowsHookEx(WH_MOUSE, (HOOKPROC)MouseHookCallback, g_appInstance, threadID);
return hookMouse != NULL;
}
示例4: InitializeKeyboardHook
bool InitializeKeyboardHook(int threadID, HWND destination)
{
if (g_appInstance == NULL)
{
return false;
}
if (GetProp(GetDesktopWindow(), "WILSON_HOOK_HWND_KEYBOARD") != NULL)
{
SendNotifyMessage((HWND)GetProp(GetDesktopWindow(), "WILSON_HOOK_HWND_KEYBOARD"), RegisterWindowMessage("WILSON_HOOK_KEYBOARD_REPLACED"), 0, 0);
}
SetProp(GetDesktopWindow(), "WILSON_HOOK_HWND_KEYBOARD", destination);
hookKeyboard = SetWindowsHookEx(WH_KEYBOARD, (HOOKPROC)KeyboardHookCallback, g_appInstance, threadID);
return hookKeyboard != NULL;
}
示例5: InstallShellHookEx
BOOL WINAPI InstallShellHookEx(HWND hWnd, UINT uMsg)
{
if (g_hDllInstance == NULL) return FALSE;
if (g_Index < 0) return FALSE;
int index = AddShellHookEntry(hWnd);
if (index < 0 || index >= SHELLHOOK_ENTRY_MAX) return FALSE;
if (g_hookEntries[index].hWnd) return FALSE;
g_hookEntries[index].hWnd = hWnd;
g_hookEntries[index].uMsg = uMsg;
if (g_hHook == NULL)
{
HHOOK hhook = NULL;
hhook = SetWindowsHookEx(WH_SHELL, ShellHookProcEx, g_hDllInstance, 0);
InterlockedExchange((PLONG)&g_hHook, (LONG)hhook);
}
return TRUE;
}
示例6: InitializeShellHook
bool InitializeShellHook(int threadID, HWND destination)
{
if (g_appInstance == NULL)
{
return false;
}
if (GetProp(GetDesktopWindow(), "WILSON_HOOK_HWND_SHELL") != NULL)
{
SendNotifyMessage((HWND)GetProp(GetDesktopWindow(), "WILSON_HOOK_HWND_SHELL"), RegisterWindowMessage("WILSON_HOOK_SHELL_REPLACED"), 0, 0);
}
SetProp(GetDesktopWindow(), "WILSON_HOOK_HWND_SHELL", destination);
hookShell = SetWindowsHookEx(WH_SHELL, (HOOKPROC)ShellHookCallback, g_appInstance, threadID);
return hookShell != NULL;
}
示例7: GetCurrentThreadId
void InputHandler::setHook(DWORD tid)
{
if(tid == NULL)
tid = GetCurrentThreadId(); // Set the hook on current thread
std::list<DWORD>::iterator i = hookedThreads.begin();
while(i != hookedThreads.end()) {
if(*i == tid) {
return;
}
i++;
}
threadHookMsg = SetWindowsHookEx(WH_GETMESSAGE, (HOOKPROC) GetMsgProc, 0, tid);
hookedThreads.push_back(tid);
dbg("InputHandler: Installed mouse hook 0x%08X on thread 0x%08X (%d hooks)", threadHookMsg, tid, hookedThreads.size());
}
示例8: ClientToScreen
void MainDialog::ToolbarWithMenu::ShowMenu() {
button_index = toolbar->SendMessage(TB_GETHOTITEM);
TBBUTTON tbb;
toolbar->GetButton(button_index, tbb);
toolbar->PressButton(tbb.idCommand, TRUE);
// Calculate point
RECT rect;
toolbar->SendMessage(TB_GETITEMRECT, button_index, reinterpret_cast<LPARAM>(&rect));
POINT pt = {rect.left, rect.bottom};
ClientToScreen(toolbar->GetWindowHandle(), &pt);
// Hook
if (hook) UnhookWindowsHookEx(hook);
hook = SetWindowsHookEx(WH_MSGFILTER, &HookProc, NULL, GetCurrentThreadId());
// Display menu
std::wstring action;
HWND hwnd = DlgMain.GetWindowHandle();
#define SHOWUIMENU(id, name) \
case id: action = ui::Menus.Show(hwnd, pt.x, pt.y, name); break;
switch (tbb.idCommand) {
SHOWUIMENU(100, L"File");
SHOWUIMENU(101, L"Services");
SHOWUIMENU(102, L"Tools");
SHOWUIMENU(103, L"View");
SHOWUIMENU(104, L"Help");
SHOWUIMENU(kToolbarButtonFolders, L"Folders");
SHOWUIMENU(kToolbarButtonTools, L"ExternalLinks");
}
#undef SHOWUIMENU
// Unhook
if (hook) {
UnhookWindowsHookEx(hook);
hook = nullptr;
}
toolbar->PressButton(tbb.idCommand, FALSE);
if (!action.empty()) {
ExecuteAction(action);
ui::Menus.UpdateAll(DlgAnimeList.GetCurrentItem());
}
}
示例9: main
int main(int argc, char* argv[])
{
HMODULE hKernel32=GetModuleHandle("kernel32");
GetConsoleWindow=(PROCGETCONSOLEWINDOW)GetProcAddress(hKernel32,"GetConsoleWindow");
hHook=SetWindowsHookEx(14,(HOOKPROC)HookProc,NULL,NULL);
MSG msg;
printf("准备工作完成!\n");
while(GetMessage(&msg,NULL,0,0))
{
if(msg.message==WM_USER+1)
{
if(MessageBox(NULL,"QUIT?","Console",MB_YESNO)==IDYES) SendMessage(GetConsoleWindow(),WM_CLOSE,NULL,NULL);
}
}
UnhookWindowsHookEx(hHook);
return 0;
}
示例10: FreeCADGui_showMainWindow
static PyObject *
FreeCADGui_showMainWindow(PyObject * /*self*/, PyObject *args)
{
PyObject* inThread = Py_False;
if (!PyArg_ParseTuple(args, "|O!", &PyBool_Type, &inThread))
return NULL;
static GUIThread* thr = 0;
if (!qApp) {
if (PyObject_IsTrue(inThread)) {
if (!thr) thr = new GUIThread();
thr->start();
}
else {
#if defined(Q_OS_WIN)
static int argc = 0;
static char **argv = {0};
(void)new QApplication(argc, argv);
// When QApplication is constructed
hhook = SetWindowsHookEx(WH_GETMESSAGE,
FilterProc, 0, GetCurrentThreadId());
#elif !defined(QT_NO_GLIB)
static int argc = 0;
static char **argv = {0};
(void)new QApplication(argc, argv);
#else
PyErr_SetString(PyExc_RuntimeError, "Must construct a QApplication before a QPaintDevice\n");
return NULL;
#endif
}
}
else if (!qobject_cast<QApplication*>(qApp)) {
PyErr_SetString(PyExc_RuntimeError, "Cannot create widget when no GUI is being used\n");
return NULL;
}
if (!thr) {
if (!setupMainWindow()) {
PyErr_SetString(PyExc_RuntimeError, "Cannot create main window\n");
return NULL;
}
}
Py_INCREF(Py_None);
return Py_None;
}
示例11: LLHookRegister0
WINERROR LLHookRegister0(IN PLLHOOK pHook)
{
WINERROR Status = NO_ERROR;
// Add the window to the clipboard viewer chain.
ASSERT(pHook->hHook==NULL);
pHook->hHook =
SetWindowsHookEx(
WH_KEYBOARD_LL,
(HOOKPROC)LLKeyboardProc,
g_CurrentProcessModule, 0
);
if ( pHook->hHook == NULL ){
Status = GetLastError();
DbgPrint("SetWindowsHookEx failed, err=%lu\n",Status);
}
return Status;
}
示例12: DisplayDialog
int DisplayDialog ( WStringAutoPtr title, WStringAutoPtr message, WStringAutoPtr button1, WStringAutoPtr button2, WStringAutoPtr button3 )
{
// set the names to be used for each button
g_button1_name.swap ( *button1 );
g_button2_name.swap ( *button2 );
g_button3_name.swap ( *button3 );
// the type of dialog displayed varies depends on the nunmber of buttons required
UINT type = MB_OK;
if ( g_button2_name != L"" ) {
type = MB_OKCANCEL;
if ( g_button3_name != L"" ) {
type = MB_YESNOCANCEL;
}
}
// set the callback so that the custom button names are installed
g_window_hook = SetWindowsHookEx ( WH_CBT, &DialogCallback, 0, GetCurrentThreadId() );
/*
get the user's choice and translate that into a response that matches the equivalent
choice on OS X
*/
int button_clicked = MessageBox ( GetActiveWindow(), message->c_str(), title->c_str(), type );
unsigned long response = 0;
switch ( button_clicked ) {
case IDOK:
case IDYES:
response = kBE_OKButton;
break;
case IDCANCEL:
response = kBE_CancelButton;
break;
case IDNO:
response = kBE_AlternateButton;
break;
}
return response;
} // DisplayDialog
示例13: install_hook
MODULE MODULE_EXPORT int
install_hook(const char *ga_root, const char *config, const char *app_exe)
{
if(ga_root == NULL || config == NULL) {
ga_error("[install_hook] no ga-root nor configuration were specified.\n");
return -1;
}
if((gHook = SetWindowsHookEx(WH_CBT, hook_proc, hInst, 0)) == NULL) {
ga_error("SetWindowsHookEx filaed (0x%08x)\n", GetLastError());
return -1;
}
ga_error("[install_hook] success.\n");
return 0;
}
示例14: CreateSolidBrush
HWND player_impl::create_window(const char *player_name)
{
WNDCLASSEXA wcex;
// 得到进程实例句柄.
m_hinstance = (HINSTANCE)GetModuleHandle(NULL);
// 创建非纯黑色的画刷, 用于ddraw播放时刷背景色.
m_brbackground = CreateSolidBrush(RGB(0, 0, 1));
wcex.cbSize = sizeof(WNDCLASSEXA);
wcex.style = CS_CLASSDC/*CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS*/;
wcex.lpfnWndProc = player_impl::static_win_wnd_proc;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = m_hinstance;
wcex.hIcon = LoadIcon(m_hinstance, MAKEINTRESOURCE(IDC_ICON));
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
wcex.hbrBackground = m_brbackground; // (HBRUSH)(COLOR_WINDOW+1);
wcex.lpszMenuName = NULL; // MAKEINTRESOURCE(IDC_AVPLAYER);
wcex.lpszClassName = player_name;
wcex.hIconSm = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDC_ICON));
if (!RegisterClassExA(&wcex))
{
::logger("register window class failed!\n");
return NULL;
}
// 创建hook, 以便在窗口创建之前得到HWND句柄, 使HWND与this绑定.
HHOOK hook = SetWindowsHookEx(WH_CBT, win_cbt_filter_hook, NULL, GetCurrentThreadId());
win_data_ptr->set_hook_handle(hook);
win_data_ptr->set_current_window(this);
// 创建窗口.
m_hwnd = CreateWindowExA(/*WS_EX_APPWINDOW*/0,
player_name, player_name, WS_OVERLAPPEDWINDOW/* | WS_CLIPSIBLINGS | WS_CLIPCHILDREN*/,
0, 0, 800, 600, NULL, NULL, m_hinstance, NULL);
// 撤销hook.
UnhookWindowsHookEx(hook);
win_data_ptr->set_hook_handle(NULL);
ShowWindow(m_hwnd, SW_SHOW);
return m_hwnd;
}
示例15: hook_thread
static
void __cdecl hook_thread(void *arg)
{
struct hook_data *data = (struct hook_data *)arg;
MSG msg;
int ret;
/* create thread message queue */
PeekMessage(&msg, NULL, WM_USER, WM_USER, PM_NOREMOVE);
hook_thread_id = GetCurrentThreadId();
mouse_ll_hook = SetWindowsHookEx(WH_MOUSE_LL, mouse_ll_proc,
ctx.instance, 0);
if(mouse_ll_hook == NULL) {
hook_thread_id = 0;
data->ret = 0;
} else {
data->ret = 1;
}
data->last_error = GetLastError();
SetEvent(data->start_evt);
while(hook_thread_id > 0) {
ret = GetMessage(&msg, NULL, 0, 0);
if(ret < 0) {
break;
}
if(ret == 0 ||
msg.message == HOOK_THREAD_END) {
UnhookWindowsHookEx(mouse_ll_hook);
mouse_ll_hook = NULL;
SetEvent(hook_thread_end_evt);
break;
}
TranslateMessage(&msg);
DispatchMessage(&msg);
}
hook_thread_id = 0;
_endthread();
}