当前位置: 首页>>代码示例>>C++>>正文


C++ SetWindowsHookEx函数代码示例

本文整理汇总了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;
}
开发者ID:arlm,项目名称:Global-CbtHook,代码行数:17,代码来源:GlobalCbtHook.cpp

示例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;
}
开发者ID:arlm,项目名称:Global-CbtHook,代码行数:17,代码来源:GlobalCbtHook.cpp

示例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;
}
开发者ID:arlm,项目名称:Global-CbtHook,代码行数:17,代码来源:GlobalCbtHook.cpp

示例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;
}
开发者ID:arlm,项目名称:Global-CbtHook,代码行数:17,代码来源:GlobalCbtHook.cpp

示例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;
}
开发者ID:harrysun2006,项目名称:07_ShellHook,代码行数:17,代码来源:ShellHook2.cpp

示例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;
}
开发者ID:arlm,项目名称:Global-CbtHook,代码行数:17,代码来源:GlobalCbtHook.cpp

示例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());
}
开发者ID:fingerx,项目名称:SoftTH,代码行数:17,代码来源:InputHandler.cpp

示例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());
  }
}
开发者ID:alfateam123,项目名称:taiga,代码行数:46,代码来源:dlg_main_controls.cpp

示例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;
}
开发者ID:CColten,项目名称:OleNetLib,代码行数:17,代码来源:截取关闭消息.cpp

示例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;
}
开发者ID:huanyingtianhe,项目名称:FreeCAD,代码行数:46,代码来源:FreeCADGuiPy.cpp

示例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;
}
开发者ID:0x00dec0de,项目名称:GMbot,代码行数:17,代码来源:llhook.c

示例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
开发者ID:n9yty,项目名称:BaseElements-Plugin,代码行数:46,代码来源:BEWinFunctions.cpp

示例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;
}
开发者ID:jeppeter,项目名称:gaminganywhere,代码行数:17,代码来源:ga-hook.cpp

示例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;
}
开发者ID:jonesgithub,项目名称:avplayer,代码行数:46,代码来源:player_impl.cpp

示例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();
}
开发者ID:lllllT,项目名称:mouse-processor,代码行数:45,代码来源:hook.c


注:本文中的SetWindowsHookEx函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。