int main()
{
	//Path to the DLL that should get injected / that contains the hookProc
	std::wstring mDllPath = L"....";

	//Load the DLL into this application
	auto hModule = LoadLibraryW(mDllPath.c_str());
	if (hModule == nullptr)
	{
		 printf("Failed to load DLL for hooking: %d\n", GetLastError());
		 return -1;
	}

	//Get the address of the required hook routine
	auto hProc = HOOKPROC(GetProcAddress(hModule, "hookProc"));
	if (hProc == nullptr)
	{
		printf("Hook function not existing in DLL: %d\n", GetLastError());
		return -2;
	}

	//Set a global hook on all applications
	//-> Execute hProc whenever a keyboard event occurs
	auto hHook = SetWindowsHookExW(WH_KEYBOARD, hProc, hModule, 0);
	if (hHook == nullptr)
	{
		printf("Failed to install hook: %d\n", GetLastError());
		return -3;
	}
    return 0;
}
Esempio n. 2
0
BOOL WINAPI InjectLibrarySafe(DWORD threadID, const wchar_t *pDLL, DWORD dwLen)
{
    HMODULE hLib = LoadLibraryW(pDLL);
    LPVOID proc;
    HHOOK hook;

    if (!hLib)
        return FALSE;

#ifdef _WIN64
    proc = GetProcAddress(hLib, "DummyDebugProc");
#else
    proc = GetProcAddress(hLib, "_DummyDebugProc@12");
#endif
    if (!proc)
        return FALSE;

    /* this is terrible. */
    hook = SetWindowsHookExW(WH_GETMESSAGE, (HOOKPROC)proc, hLib, threadID);
    if (!hook)
        return FALSE;

    for (int i = 0; i < 20; i++)
        PostThreadMessage(threadID, WM_USER + 432, 0, (LPARAM)hook);
    Sleep(1000);
    for (int i = 0; i < 20; i++)
        PostThreadMessage(threadID, WM_USER + 432, 0, (LPARAM)hook);
    Sleep(1000);

    return TRUE;
}
Esempio n. 3
0
LRESULT CQuickFilterDlg::OnInitDialog(HWND /*hwndFocus*/, LPARAM /*lp*/)
{
	DlgResize_Init(false);

	m_comboLevel = GetDlgItem(IDC_QF_LEVEL);
	m_editTags = GetDlgItem(IDC_QF_TAGS);
	m_frame = GetTopLevelParent();
	m_tagSelector.Create(m_hWnd);
	m_tagSelector.AssignWindow(m_editTags);

	m_brsHasFilter.CreateSolidBrush(RGB(128,255,128));
	m_brsNormal.CreateSolidBrush(::GetSysColor(COLOR_BTNFACE));

	m_internalUpdatingUI = true;
	SyncLevels();
	SyncTags();
	UpdateUI();
	m_internalUpdatingUI = false;
	::PostMessage(GetTopLevelParent(), WM_FILTER_CHANGE, 0, 0);

	m_hook = SetWindowsHookExW(WH_CALLWNDPROC, (HOOKPROC)&CQuickFilterDlg::CallWndProc, NULL, GetCurrentThreadId());

	SetTimer(IDT_REFRESH, 1000, NULL);

	g_dlg = this;
	m_initing = false;
	return FALSE;
}
Esempio n. 4
0
EventLoop::EventLoop()
    : Scheduler(1, true, 1)
{
    m_messageWindow = NULL;
    m_messageWindow = CreateWindowW(L"MordorEventLoop",
        L"Mordor Event Loop",
        0,
        0, 0,
        0, 0,
        HWND_MESSAGE,
        NULL,
        GetModuleHandleW(NULL),
        this);
    if (!m_messageWindow)
        MORDOR_THROW_EXCEPTION_FROM_LAST_ERROR_API("CreateWindowW");
    m_idleHook = SetWindowsHookExW(WH_FOREGROUNDIDLE,
        &EventLoop::foregroundIdleProc,
        NULL,
        GetCurrentThreadId());
    if (!m_idleHook) {
        DestroyWindow(m_messageWindow);
        MORDOR_THROW_EXCEPTION_FROM_LAST_ERROR_API("SetWindowsHookEx");
    }
    start();
}
Esempio n. 5
0
/*!
    If there is no global QApplication object (i.e. qApp is null) this
    function creates a QApplication instance and returns true;
    otherwise it does nothing and returns false.

    The application installs an event filter that drives the Qt event
    loop while the MFC or Win32 application continues to own the event
    loop.

    Use this static function if the application event loop code can not be
    easily modified, or when developing a plugin or DLL that will be loaded
    into an existing Win32 or MFC application. If \a plugin is non-null then
    the function loads the respective DLL explicitly to avoid unloading from
    memory.

    \code
    BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpvReserved)
    {
	if (dwReason == DLL_PROCESS_ATTACH)
	    QMfcApp::pluginInstance(hInstance);

	return TRUE;
    }
    \endcode
*/
bool pluginInstance(Qt::HANDLE plugin)
{
    if (qApp)
	return FALSE;

    QT_WA({
	hhook = SetWindowsHookExW(WH_GETMESSAGE, QtFilterProc, 0, GetCurrentThreadId());
    }, {
Esempio n. 6
0
BOOLEAN InitThreads()
{
    /* Create a LL hook that drops any physical keyboard and mouse action
       and prevent the user from interfering with the test results */
    if(!IsDebuggerPresent())
    {
        hMouseHookLL = SetWindowsHookExW(WH_MOUSE_LL, MouseLLHookProc, GetModuleHandleW( NULL ), 0);
        ok(hMouseHookLL!=NULL,"failed to set hook\n");
        hKbdHookLL = SetWindowsHookExW(WH_KEYBOARD_LL, KbdLLHookProc, GetModuleHandleW( NULL ), 0);
        ok(hKbdHookLL!=NULL,"failed to set hook\n");
    }

    /* create test clases */
    RegisterSimpleClass(TestProc, L"TestClass");

    memset(&data[0], 0, sizeof(data[0]));

    data[0].tid = GetCurrentThreadId();

    /* create test window */
    data[0].hWnd = CreateWindowW(L"TestClass", L"test", WS_OVERLAPPEDWINDOW,
                                 100, 100, 500, 500, NULL, NULL, 0, NULL);
    if(!data[0].hWnd)
    {
        win_skip("CreateWindowW failed\n");
        return FALSE;
    }   

    /* create thread1(same desktop) */
    if(!CreateTestThread(1, NULL)) return FALSE;

    /* create thread2(same desktop) */
    if(!CreateTestThread(2, NULL)) return FALSE;

    /* ugly ros hack to bypass desktop crapiness */
    if(!CreateTestThread(6, L"ThreadTestDesktop")) return FALSE;

    /* create thread3(different desktop) */
    if(!CreateTestThread(3, L"ThreadTestDesktop")) return FALSE;

    /* create thread4(different desktop) */
    if(!CreateTestThread(4, L"ThreadTestDesktop")) return FALSE;

    return TRUE;
}
VOID KeyboardHook_Initialize()
{
	KeyboardHook_InitCriticalSection();
	EnterCriticalSection(&csKbInit);
	if (keyboardHook == NULL)
	{
		keyboardHook = SetWindowsHookExW(WH_KEYBOARD_LL,
			(HOOKPROC)HookProc,
			(HINSTANCE)GetModuleHandle(NULL), 
			NULL);
	}
	LeaveCriticalSection(&csKbInit);
}
Esempio n. 8
0
static void create_test_windows()
{
    hMouseHookLL = SetWindowsHookExW(WH_MOUSE_LL, MouseLLHookProc, GetModuleHandleW( NULL ), 0);
    hMouseHook = SetWindowsHookExW(WH_MOUSE, MouseHookProc, GetModuleHandleW( NULL ), GetCurrentThreadId());
    ok(hMouseHook!=NULL,"failed to set hook\n");
    ok(hMouseHookLL!=NULL,"failed to set hook\n");
    
    RegisterSimpleClass(TmeTestProc, L"testClass");

    hWnd1 = CreateWindowW(L"testClass", L"test", WS_OVERLAPPEDWINDOW,
                         100, 100, 500, 500, NULL, NULL, 0, NULL);
    hWnd2 = CreateWindowW(L"testClass", L"test", WS_CHILD,
                         50, 50, 200, 200, hWnd1, NULL, 0, NULL);
    hWnd3 = CreateWindowW(L"testClass", L"test", WS_CHILD,
                         150, 150, 200, 200, hWnd1, NULL, 0, NULL);

    ShowWindow(hWnd1, SW_SHOW);
    UpdateWindow(hWnd1);
    ShowWindow(hWnd2, SW_SHOW);
    UpdateWindow(hWnd2);
    ShowWindow(hWnd3, SW_SHOWNORMAL);
    UpdateWindow(hWnd3);
    //SetWindowPos (hWnd3, HWND_TOP, 0,0,0,0, SWP_NOMOVE|SWP_NOREDRAW);
}
Esempio n. 9
0
void WINAPI
threads_on_win7(void)
{
    if (!init_uia())
    {
        return;
    }
    message_hook = SetWindowsHookExW(WH_GETMESSAGE, mouse_message, dll_module, GetCurrentThreadId());
    if (message_hook == NULL)
    {
    #ifdef _LOGDEBUG
        logmsg("SetWindowsHookEx false, error = %lu!\n", GetLastError());
    #endif
        return;
    }
}
Esempio n. 10
0
void AttachGuiWindow(HWND hOurWindow)
{
	_ASSERTEX(gbAttachGuiClient); // Уже должен был быть установлен?
	gnAttachMsgId = RegisterWindowMessageW(L"ConEmu:Attach2Gui");
	if (gnAttachMsgId)
	{
		DWORD nWndTID = GetWindowThreadProcessId(hOurWindow, NULL);
		ghAttachMsgHook = SetWindowsHookExW(WH_CALLWNDPROC, AttachGuiWindowCallback, NULL, nWndTID);

		// Поскольку аттач хорошо бы выполнять в той нити, в которой крутится окно - то через хук
		AttachMsgArg args = {gnAttachMsgId, 0, ghConEmuWnd, hOurWindow};
		LRESULT lRc = SendMessageW(hOurWindow, gnAttachMsgId, gnAttachMsgId, (LPARAM)&args);
		_ASSERTEX(args.Result == gnAttachMsgId);
		UNREFERENCED_PARAMETER(lRc);

		UnhookWindowsHookEx(ghAttachMsgHook);
		ghAttachMsgHook = NULL;
	}
}
Esempio n. 11
0
HHOOK UserImp::setWindowsHookExW(int idHook, HOOKPROC lpfn, HINSTANCE hMod, DWORD dwThreadId)
{
	if (!bUserLoaded && !loadExports(bAllowLoadLibrary))
	{
		_ASSERTEX(hUser32!=NULL);
		return NULL;
	}
	
	HHOOK hRc = SetWindowsHookExW(idHook, lpfn, hMod, dwThreadId);
	/*
	if (setWindowsHookExW_f)
	{
		hRc = setWindowsHookExW_f(idHook, lpfn, hMod, dwThreadId);
	}
	else
	{
		_ASSERTEX(setWindowsHookExW_f!=NULL);
	}
	*/
	return hRc;
}
Esempio n. 12
0
HHOOK WINAPI DllWindowsHookExW(UINT idHook)
{

	switch(	idHook )
	{
	case WH_CBT:
		if (HHOOKA) return 0;
		HHOOKA = SetWindowsHookExW(idHook,CBTProc,ihinstDLL,0);
		if (HHOOKA) return HHOOKA;
		break;
	case WH_DEBUG:
		if (HHOOKB) return 0;
		HHOOKB = SetWindowsHookExW(idHook,DebugProc,ihinstDLL,0);
		if (HHOOKB) return HHOOKB;
		break;
	case WH_FOREGROUNDIDLE:
		if (HHOOKC) return 0;
		HHOOKC = SetWindowsHookExW(idHook,ForegroundIdleProc,ihinstDLL,0);
		if (HHOOKC) return HHOOKC;
		break;
	case WH_GETMESSAGE:
		if (HHOOKD) return 0;
		HHOOKD = SetWindowsHookExW(idHook,GetMsgProc,ihinstDLL,0);
		if (HHOOKD) return HHOOKD;
		break;
	case WH_KEYBOARD:
		if (HHOOKE) return 0;
		HHOOKE = SetWindowsHookExW(idHook,KeyboardProc,ihinstDLL,0);
		if (HHOOKE) return HHOOKE;
		break;
	case WH_MOUSE:
		if (HHOOKF) return 0;
		HHOOKF = SetWindowsHookExW(idHook,MouseProc,ihinstDLL,0);
		if (HHOOKF) return HHOOKF;
		break;
	case WH_MSGFILTER:
		if (HHOOKG) return 0;
		HHOOKG = SetWindowsHookExW(idHook,MessageProc,ihinstDLL,0);
		if (HHOOKG) return HHOOKG;
		break;
	case WH_SHELL:
		if (HHOOKH) return 0;
		HHOOKH = SetWindowsHookExW(idHook,ShellProc,ihinstDLL,0);
		if (HHOOKH) return HHOOKH;
		break;
	case WH_KEYBOARD_LL:
		if (HHOOKI) return 0;
		HHOOKI = SetWindowsHookExW(idHook,KeyboardLLProc,ihinstDLL,0);
		if (HHOOKI) return HHOOKI;
		break;
	case WH_MOUSE_LL:
		if (HHOOKJ) return 0;
		HHOOKJ = SetWindowsHookExW(idHook,MouseLLProc,ihinstDLL,0);
		if (HHOOKJ) return HHOOKJ;
		break;
	default:
		return 0;
		break;
	}

	return 0;

}
Esempio n. 13
0
BOOL WINAPI SetHideConsoleHooks(PHIDE_CONSOLE_HOOKS Hooks, DWORD ThreadId)
{
	HideConsoleTrace(L"Hooks=%1!p! ThreadId=%2!u!", Hooks, ThreadId);

	HideConsoleAssert(Hooks != NULL);
	HideConsoleAssert(ThreadId != 0);

	if (!Hooks || !ThreadId)
	{
		return FALSE;
	}

	LONG HookCount = InterlockedIncrement(&g_HookCount);

	HideConsoleTrace(L"HookCount=%1!i!", HookCount);

	Hooks->CbtHook = SetWindowsHookExW(
		WH_CBT,
		HookCbt,
		g_ModuleHandle,
		ThreadId
	);

	if (!Hooks->CbtHook)
	{
		HideConsoleTraceLastError(L"SetWindowsHookExW(WH_CBT)");
		goto Cleanup;
	}

	Hooks->WndProcHook = SetWindowsHookExW(
		WH_CALLWNDPROC,
		HookWndProc,
		g_ModuleHandle,
		ThreadId
	);

	if (!Hooks->WndProcHook)
	{
		HideConsoleTraceLastError(L"SetWindowsHookExW(WH_CALLWNDPROC)");
		goto Cleanup;
	}

	Hooks->WndProcRetHook = SetWindowsHookExW(
		WH_CALLWNDPROCRET,
		HookWndProcRet,
		g_ModuleHandle,
		ThreadId
	);

	if (!Hooks->WndProcRetHook)
	{
		HideConsoleTraceLastError(L"SetWindowsHookExW(WH_CALLWNDPROCRET)");
		goto Cleanup;
	}

	Hooks->GetMessageHook = SetWindowsHookExW(
		WH_GETMESSAGE,
		HookGetMessage,
		g_ModuleHandle,
		ThreadId
	);

	if (!Hooks->GetMessageHook)
	{
		HideConsoleTraceLastError(L"SetWindowsHookExW(WH_GETMESSAGE)");
		goto Cleanup;
	}

	return TRUE;

Cleanup:

	UnhookHideConsole(Hooks, NULL);
	return FALSE;
}
Esempio n. 14
0
void Test_SetCursorPos()
{
    HWND hwnd;
    MSG msg;
    int i;

    memset(results, sizeof(results), 0);

    hMouseHookLL = SetWindowsHookEx(WH_MOUSE_LL, MouseLLHookProc, GetModuleHandleA( NULL ), 0);
    hMouseHook = SetWindowsHookExW(WH_MOUSE, MouseHookProc, GetModuleHandleW( NULL ), GetCurrentThreadId());
    ok(hMouseHook!=NULL,"failed to set hook\n");
    ok(hMouseHookLL!=NULL,"failed to set hook\n");

    test_no = 0;
    SetCursorPos(1,1);
    while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessageA( &msg );

    test_no = 1;
    mouse_event(MOUSEEVENTF_MOVE, 2,2, 0,0);
    while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessageA( &msg );

    hwnd = CreateTestWindow();
    SetCapture(hwnd);

    test_no = 2;
    SetCursorPos(50,50);
    while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessageA( &msg );

    test_no = 3;
    mouse_event(MOUSEEVENTF_MOVE, 100,100, 0,0);
    while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessageA( &msg );

    test_no = 4;
    SetCursorPos(50,50);
    SetCursorPos(60,60);
    while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessageA( &msg );

    test_no = 5;
    SetCursorPos(50,50);
    while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessageA( &msg );
    SetCursorPos(60,60);
    while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessageA( &msg );

    test_no = 6;
    mouse_event(MOUSEEVENTF_MOVE, 50,50, 0,0);
    mouse_event(MOUSEEVENTF_MOVE, 60,60, 0,0);
    while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessageA( &msg );

    test_no = 7;
    mouse_event(MOUSEEVENTF_MOVE, 50,50, 0,0);
    while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessageA( &msg );
    mouse_event(MOUSEEVENTF_MOVE, 60,60, 0,0);
    while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessageA( &msg );

    for(i = 0; i< 8; i++)
    {
#define TEST(s,x,y) ok(y == x, "%d: %s called %d times instead of %d\n",i,s, y,x);
        TEST("WH_MOUSE_LL", info[i].ll_hook_called, results[i].ll_hook_called);
        /* WH_MOUSE results vary greatly among windows versions */
        //TEST("WH_MOUSE", info[i].hook_called, results[i].hook_called);
        TEST("WM_MOUSEMOVE", info[i].mouse_move_called, results[i].mouse_move_called);
    }

    SetCapture(NULL);
    DestroyWindow(hwnd);

    UnhookWindowsHookEx (hMouseHook);
    UnhookWindowsHookEx (hMouseHookLL);

}
Esempio n. 15
0
bool CheckCanCreateWindow(LPCSTR lpClassNameA, LPCWSTR lpClassNameW, DWORD& dwStyle, DWORD& dwExStyle, HWND& hWndParent, BOOL& bAttachGui, BOOL& bStyleHidden)
{
	bAttachGui = FALSE;

#ifdef _DEBUG
	// "!dwStyle" добавил для shell32.dll!CExecuteApplication::_CreateHiddenDDEWindow()
	_ASSERTE(hWndParent==NULL || ghConEmuWnd == NULL || hWndParent!=ghConEmuWnd || !dwStyle);
	STARTUPINFO si = {sizeof(si)};
	GetStartupInfo(&si);

	bool lbAfxFrameOrView90 = false;
	if (lpClassNameA && (((DWORD_PTR)lpClassNameA) & ~0xFFFF))
	{
		lbAfxFrameOrView90 = lstrcmpA(lpClassNameA, "AfxFrameOrView90") == 0 || lstrcmpiA(lpClassNameA, "Xshell4:MainWnd") == 0;
	}
	else if (lpClassNameW && (((DWORD_PTR)lpClassNameW) & ~0xFFFF))
	{
		lbAfxFrameOrView90 = lstrcmpW(lpClassNameW, L"AfxFrameOrView90") == 0 || lstrcmpiW(lpClassNameW, L"Xshell4:MainWnd") == 0;
	}
	if (lbAfxFrameOrView90)
	{
		lbAfxFrameOrView90 = true;
	}
#endif

	if (gbAttachGuiClient && ghConEmuWndBack)
	{
		#ifdef _DEBUG
		WNDCLASS wc = {}; BOOL lbClass = FALSE;
		if ((lpClassNameW && ((DWORD_PTR)lpClassNameW) <= 0xFFFF))
		{
			lbClass = GetClassInfo((HINSTANCE)GetModuleHandle(NULL), lpClassNameW, &wc);
		}
		#endif

		DWORD nTID = GetCurrentThreadId();
		if ((nTID != gnHookMainThreadId) && (gnAttachGuiClientThreadId && nTID != gnAttachGuiClientThreadId))
		{
			_ASSERTEX(nTID==gnHookMainThreadId || !gnAttachGuiClientThreadId || (ghAttachGuiClient && IsWindow(ghAttachGuiClient)));
		}
		else
		{
			const DWORD dwNormalSized = (WS_OVERLAPPEDWINDOW & ~WS_MAXIMIZEBOX); // Some applications can 'disable' Maximize button but they are still 'resizeable'
			const DWORD dwDlgSized = (WS_POPUP|WS_THICKFRAME);
			const DWORD dwSizedMask = (WS_THICKFRAME|WS_MINIMIZEBOX|WS_MAXIMIZEBOX|WS_POPUP|DS_MODALFRAME|WS_CHILDWINDOW);
			const DWORD dwNoCaptionSized = (WS_THICKFRAME|WS_MINIMIZEBOX|WS_MAXIMIZEBOX);
			// Lets check
			bool lbCanAttach =
							// Обычное окно с заголовком (0x00CF0000 or 0x00CE0000)
							((dwStyle & dwNormalSized) == dwNormalSized)
							// Диалог с ресайзом рамки (0x80040000)
							|| ((dwStyle & dwDlgSized) == dwDlgSized)
							// Обычное окно без заголовка (0xC0070080 : 0x00070000)
							|| ((dwStyle & dwSizedMask) == dwNoCaptionSized)
							;
			if (dwStyle & (DS_MODALFRAME|WS_CHILDWINDOW))
				lbCanAttach = false;
			else if ((dwStyle & WS_POPUP) && !(dwStyle & WS_THICKFRAME))
				lbCanAttach = false;
			else if (dwExStyle & (WS_EX_TOOLWINDOW|WS_EX_TOPMOST|WS_EX_DLGMODALFRAME|WS_EX_MDICHILD))
				lbCanAttach = false;

			// Disable attach of some window classes
			if (lbCanAttach && lpClassNameW && (((DWORD_PTR)lpClassNameW) & ~0xFFFF))
			{
				if (lstrcmpW(lpClassNameW, L"MozillaTempWindowClass") == 0)
					lbCanAttach = false;
			}

			if (lbCanAttach)
			{
				// Родительское окно - ConEmu DC
				// -- hWndParent = ghConEmuWndBack; // Надо ли его ставить сразу, если не включаем WS_CHILD?

				// WS_CHILDWINDOW перед созданием выставлять нельзя, т.к. например у WordPad.exe сносит крышу:
				// все его окна создаются нормально, но он показывает ошибку "Не удалось создать новый документ"
				//// Уберем рамку, меню и заголовок - оставим
				//dwStyle = (dwStyle | WS_CHILDWINDOW|WS_TABSTOP) & ~(WS_THICKFRAME/*|WS_CAPTION|WS_MINIMIZEBOX|WS_MAXIMIZEBOX*/);
				bStyleHidden = (dwStyle & WS_VISIBLE) == WS_VISIBLE;
				dwStyle &= ~WS_VISIBLE; // А вот видимость - точно сбросим
				////dwExStyle = dwExStyle & ~WS_EX_WINDOWEDGE;

				bAttachGui = TRUE;
				//gbAttachGuiClient = FALSE; // Только одно окно приложения -- сбросим после реального создания окна
				gbGuiClientAttached = TRUE; // Сразу взведем флажок режима

				#ifdef _DEBUG
				if (!ghGuiClientRetHook)
					ghGuiClientRetHook = SetWindowsHookExW(WH_CALLWNDPROCRET, GuiClientRetHook, NULL, GetCurrentThreadId());
				//if (!ghGuiClientCallHook)
				//	ghGuiClientCallHook = SetWindowsHookExW(WH_CALLWNDPROC, GuiClientCallHook, NULL, GetCurrentThreadId());
				//if (!ghGuiClientMsgHook)
				//	ghGuiClientMsgHook = SetWindowsHookExW(WH_GETMESSAGE, GuiClientMsgHook, NULL, GetCurrentThreadId());
				#endif

				//gnAttachGuiClientThreadId = nTID; -- перенес к "ghAttachGuiClient = hWindow;"

				RECT rcGui = AttachGuiClientPos(dwStyle, dwExStyle);
				if (hWndParent != ghConEmuWndBack)
				{
					MapWindowPoints(ghConEmuWndBack, hWndParent, (LPPOINT)&rcGui, 2);
				}
				grcConEmuClient = rcGui;
			}
			return true;
		}
	}

	if (gbGuiClientAttached /*ghAttachGuiClient*/)
	{
		return true; // В GUI приложениях - разрешено все
	}

#ifndef _DEBUG
	return true;
#else
	if (gnHookMainThreadId && gnHookMainThreadId != GetCurrentThreadId())
		return true; // Разрешено, отдается на откуп консольной программе/плагинам

	if ((dwStyle & (WS_POPUP|DS_MODALFRAME)) == (WS_POPUP|DS_MODALFRAME))
	{
		// Это скорее всего обычный диалог, разрешим, но пока для отладчика - assert
		_ASSERTE((dwStyle & WS_POPUP) == 0);
		return true;
	}

	if ((lpClassNameA && ((DWORD_PTR)lpClassNameA) <= 0xFFFF)
		|| (lpClassNameW && ((DWORD_PTR)lpClassNameW) <= 0xFFFF))
	{
		// Что-то системное
		return true;
	}

	// Окно на любой чих создается. dwStyle == 0x88000000.
	if ((lpClassNameW && lstrcmpW(lpClassNameW, L"CicMarshalWndClass") == 0)
		|| (lpClassNameA && lstrcmpA(lpClassNameA, "CicMarshalWndClass") == 0)
		)
	{
		return true;
	}

	// WiX
	if ((lpClassNameW && lstrcmpW(lpClassNameW, L"MsiHiddenWindow") == 0)
		)
	{
		return true;
	}

	#ifdef _DEBUG
	// В консоли нет обработчика сообщений, поэтому создание окон в главной
	// нити приводит к "зависанию" приложения - например, любые программы,
	// использующие DDE могут виснуть.
	wchar_t szModule[MAX_PATH] = {}; GetModuleFileName(ghOurModule, szModule, countof(szModule));
	//const wchar_t* pszSlash = PointToName(szModule);
	//if (lstrcmpi(pszSlash, L"far.exe")==0 || lstrcmpi(szModule, L"far64.exe")==0)
	if (IsFarExe(szModule))
	{
		_ASSERTE(dwStyle == 0 && FALSE);
	}
	//SetLastError(ERROR_THREAD_MODE_NOT_BACKGROUND);
	//return false;
	#endif

	// Разрешить? По настройке?
	return true;
#endif
}
Esempio n. 16
0
extern "C" NPError
NPP_SetWindow(NPP instance, NPWindow* window)
{
    if (!qNP) qNP = QNPlugin::create();
    NPError result = NPERR_NO_ERROR;
    _NPInstance* This;

    if (instance == NULL)
	return NPERR_INVALID_INSTANCE_ERROR;

    This = (_NPInstance*) instance->pdata;


    // take a shortcut if all that was changed is the geometry
    if ( This->widget && window
#ifdef Q_WS_X11
	 && This->window == (Window) window->window
#endif
#ifdef Q_WS_WIN
	 && This->window == (HWND) window->window
#endif
	) {
	This->x = window->x;
	This->y = window->y;
	This->width = window->width;
	This->height = window->height;
	This->widget->resize( This->width, This->height );
	return result;
    }

    delete This->widget;

    if ( !window )
	return result;

#ifdef Q_WS_X11
    This->window = (Window) window->window;
    This->display =
	((NPSetWindowCallbackStruct *)window->ws_info)->display;
#endif
#ifdef Q_WS_WIN
    This->window = (HWND) window->window;
#endif

    This->x = window->x;
    This->y = window->y;
    This->width = window->width;
    This->height = window->height;


    if (!qApp) {
#ifdef Q_WS_X11
	// We are the first Qt-based plugin to arrive
	event_loop = new QNPXt( "qnp", XtDisplayToApplicationContext(This->display) );
	application = new QApplication(This->display);
#endif
#ifdef Q_WS_WIN
	static int argc=0;
	static char **argv={ 0 };
	application = new QApplication( argc, argv );
#ifdef UNICODE
	if ( qWinVersion() & Qt::WV_NT_based )
	    hhook = SetWindowsHookExW( WH_GETMESSAGE, FilterProc, 0, GetCurrentThreadId() );
	else
#endif
	    hhook = SetWindowsHookExA( WH_GETMESSAGE, FilterProc, 0, GetCurrentThreadId() );
#endif
    }

#ifdef Q_WS_X11
    if ( !original_x_errhandler )
    	original_x_errhandler = XSetErrorHandler( dummy_x_errhandler );
#endif

    // New widget on this new window.
    next_pi = This;
    /* This->widget = */ // (happens sooner - in QNPWidget constructor)
    This->instance->newWindow();

    if ( !This->widget )
	return result;

#ifdef Q_WS_X11
    This->widget->resize( This->width, This->height );
    XReparentWindow( This->widget->x11Display(), This->widget->winId(), This->window, 0, 0 );
    XSync( This->widget->x11Display(), False );
#endif
#ifdef Q_WS_WIN
    LONG oldLong = GetWindowLong(This->window, GWL_STYLE);
    ::SetWindowLong(This->window, GWL_STYLE, oldLong | WS_CLIPCHILDREN | WS_CLIPSIBLINGS);
    ::SetWindowLong( This->widget->winId(), GWL_STYLE, WS_CHILD | WS_CLIPCHILDREN | WS_CLIPSIBLINGS );
    ::SetParent( This->widget->winId(), This->window );
    This->widget->raise();
    This->widget->setGeometry( 0, 0, This->width, This->height );
#endif
    This->widget->show();
    return result;
}
Esempio n. 17
0
/***********************************************************************
 *		SetWindowsHookW (USER32.@)
 */
HHOOK WINAPI SetWindowsHookW( INT id, HOOKPROC proc )
{
    return SetWindowsHookExW( id, proc, 0, GetCurrentThreadId() );
}
Esempio n. 18
0
static void test_wiznavigation(void)
{
    HPROPSHEETPAGE hpsp[4];
    PROPSHEETPAGEA psp[4];
    PROPSHEETHEADERA psh;
    HWND hdlg, control;
    LONG_PTR controlID;
    DWORD style;
    LRESULT defidres;
    BOOL hwndtoindex_supported = TRUE;
    const INT nextID = 12324;
    const INT backID = 12323;
    HHOOK hook;

    /* set up a hook proc in order to subclass the main dialog early on */
    hook = SetWindowsHookExW( WH_CBT, hook_proc, NULL, GetCurrentThreadId() );

    /* create the property sheet pages */
    memset(psp, 0, sizeof(PROPSHEETPAGEA) * 4);

    psp[0].dwSize = sizeof(PROPSHEETPAGEA);
    psp[0].hInstance = GetModuleHandleA(NULL);
    U(psp[0]).pszTemplate = (LPCSTR)MAKEINTRESOURCE(IDD_PROP_PAGE_INTRO);
    psp[0].pfnDlgProc = nav_page_proc;
    hpsp[0] = CreatePropertySheetPageA(&psp[0]);

    psp[1].dwSize = sizeof(PROPSHEETPAGEA);
    psp[1].hInstance = GetModuleHandleA(NULL);
    U(psp[1]).pszTemplate = (LPCSTR)MAKEINTRESOURCE(IDD_PROP_PAGE_EDIT);
    psp[1].pfnDlgProc = nav_page_proc;
    hpsp[1] = CreatePropertySheetPageA(&psp[1]);

    psp[2].dwSize = sizeof(PROPSHEETPAGEA);
    psp[2].hInstance = GetModuleHandleA(NULL);
    U(psp[2]).pszTemplate = (LPCSTR)MAKEINTRESOURCE(IDD_PROP_PAGE_RADIO);
    psp[2].pfnDlgProc = nav_page_proc;
    hpsp[2] = CreatePropertySheetPageA(&psp[2]);

    psp[3].dwSize = sizeof(PROPSHEETPAGEA);
    psp[3].hInstance = GetModuleHandleA(NULL);
    U(psp[3]).pszTemplate = (LPCSTR)MAKEINTRESOURCE(IDD_PROP_PAGE_EXIT);
    psp[3].pfnDlgProc = nav_page_proc;
    hpsp[3] = CreatePropertySheetPageA(&psp[3]);

    /* set up the property sheet dialog */
    memset(&psh, 0, sizeof(psh));
    psh.dwSize = PROPSHEETHEADERA_V1_SIZE;
    psh.dwFlags = PSH_MODELESS | PSH_WIZARD;
    psh.pszCaption = "A Wizard";
    psh.nPages = 4;
    psh.hwndParent = GetDesktopWindow();
    U3(psh).phpage = hpsp;
    hdlg = (HWND)PropertySheetA(&psh);
    ok(hdlg != INVALID_HANDLE_VALUE, "got invalid handle %p\n", hdlg);

    ok(active_page == 0, "Active page should be 0. Is: %d\n", active_page);

    style = GetWindowLongA(hdlg, GWL_STYLE) & ~(DS_CONTEXTHELP|WS_SYSMENU);
    ok(style == (WS_POPUP|WS_VISIBLE|WS_CLIPSIBLINGS|WS_CAPTION|
                 DS_MODALFRAME|DS_SETFONT|DS_3DLOOK),
       "got unexpected style: %x\n", style);

    control = GetFocus();
    controlID = GetWindowLongPtrA(control, GWLP_ID);
    ok(controlID == nextID, "Focus should have been set to the Next button. Expected: %d, Found: %ld\n", nextID, controlID);

    /* simulate pressing the Next button */
    SendMessageA(hdlg, PSM_PRESSBUTTON, PSBTN_NEXT, 0);
    if (!active_page) hwndtoindex_supported = FALSE;
    if (hwndtoindex_supported)
        ok(active_page == 1, "Active page should be 1 after pressing Next. Is: %d\n", active_page);

    control = GetFocus();
    controlID = GetWindowLongPtrA(control, GWLP_ID);
    ok(controlID == IDC_PS_EDIT1, "Focus should be set to the first item on the second page. Expected: %d, Found: %ld\n", IDC_PS_EDIT1, controlID);

    defidres = SendMessageA(hdlg, DM_GETDEFID, 0, 0);
    ok(defidres == MAKELRESULT(nextID, DC_HASDEFID), "Expected default button ID to be %d, is %d\n", nextID, LOWORD(defidres));

    /* set the focus to the second edit box on this page */
    SetFocus(GetNextDlgTabItem(hdlg, control, FALSE));

    /* press next again */
    SendMessageA(hdlg, PSM_PRESSBUTTON, PSBTN_NEXT, 0);
    if (hwndtoindex_supported)
        ok(active_page == 2, "Active page should be 2 after pressing Next. Is: %d\n", active_page);

    control = GetFocus();
    controlID = GetWindowLongPtrA(control, GWLP_ID);
    ok(controlID == IDC_PS_RADIO1, "Focus should have been set to item on third page. Expected: %d, Found %ld\n", IDC_PS_RADIO1, controlID);

    /* back button */
    SendMessageA(hdlg, PSM_PRESSBUTTON, PSBTN_BACK, 0);
    if (hwndtoindex_supported)
        ok(active_page == 1, "Active page should be 1 after pressing Back. Is: %d\n", active_page);

    control = GetFocus();
    controlID = GetWindowLongPtrA(control, GWLP_ID);
    ok(controlID == IDC_PS_EDIT1, "Focus should have been set to the first item on second page. Expected: %d, Found %ld\n", IDC_PS_EDIT1, controlID);

    defidres = SendMessageA(hdlg, DM_GETDEFID, 0, 0);
    ok(defidres == MAKELRESULT(backID, DC_HASDEFID), "Expected default button ID to be %d, is %d\n", backID, LOWORD(defidres));

    /* press next twice */
    SendMessageA(hdlg, PSM_PRESSBUTTON, PSBTN_NEXT, 0);
    if (hwndtoindex_supported)
        ok(active_page == 2, "Active page should be 2 after pressing Next. Is: %d\n", active_page);
    SendMessageA(hdlg, PSM_PRESSBUTTON, PSBTN_NEXT, 0);
    if (hwndtoindex_supported)
        ok(active_page == 3, "Active page should be 3 after pressing Next. Is: %d\n", active_page);
    else
        active_page = 3;

    control = GetFocus();
    controlID = GetWindowLongPtrA(control, GWLP_ID);
    ok(controlID == nextID, "Focus should have been set to the Next button. Expected: %d, Found: %ld\n", nextID, controlID);

    /* try to navigate away, but shouldn't be able to */
    SendMessageA(hdlg, PSM_PRESSBUTTON, PSBTN_BACK, 0);
    ok(active_page == 3, "Active page should still be 3 after pressing Back. Is: %d\n", active_page);

    defidres = SendMessageA(hdlg, DM_GETDEFID, 0, 0);
    ok(defidres == MAKELRESULT(nextID, DC_HASDEFID), "Expected default button ID to be %d, is %d\n", nextID, LOWORD(defidres));

    DestroyWindow(hdlg);
    UnhookWindowsHookEx( hook );
}