<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Mousehook funktioniert nicht]]></title><description><![CDATA[<p>Ich hab versucht einen Mousehook zu erstellen, aber ich bekomm nur Nachrichten wenn die Maus über meinem Fenster ist:</p>
<pre><code class="language-cpp">#include &lt;windows.h&gt;

#define WM_MOUSEHOOK WM_USER+100

HINSTANCE tInstance;
HWND thwnd;
HHOOK hook;

LRESULT CALLBACK MouseProc(int nCode, WPARAM wParam, LPARAM lParam)
{
	if(nCode &gt;= 0)
	{
		SendMessage(thwnd, WM_MOUSEHOOK, wParam, lParam);
	}
	return CallNextHookEx(NULL, nCode, wParam, lParam);
}

extern &quot;C&quot; _declspec(dllexport) void _stdcall SetHook(HWND hwnd)
{
	thwnd = hwnd;
	hook = SetWindowsHookEx(WH_MOUSE, MouseProc, tInstance, NULL);
}

extern &quot;C&quot; _declspec(dllexport) void _stdcall UnSetHook()
{
	UnhookWindowsHookEx(hook);
}

BOOL WINAPI DllMain (HINSTANCE hInst, DWORD reason, LPVOID reserved)
{
    tInstance = hInst;
    return TRUE;
}
</code></pre>
<pre><code class="language-cpp">extern &quot;C&quot; _declspec(dllimport) void _stdcall SetHook(HWND list);
extern &quot;C&quot; _declspec(dllimport) void _stdcall UnSetHook();

#define WM_MOUSEHOOK WM_USER+100

BOOL CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	switch(message)
	{
	case WM_INITDIALOG:
		SetHook(hwnd);
		return TRUE; //WM_INITDIALOG
	case WM_CLOSE:
		UnSetHook();
		EndDialog(hwnd, 0);
		return TRUE; //WM_CLOSE
	case WM_MOUSEHOOK:
                [...]
		return TRUE; //WM_MOUSEHOOK
	}
	return FALSE;
}
</code></pre>
<p>Woran könnte das liegen?</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/168425/mousehook-funktioniert-nicht</link><generator>RSS for Node</generator><lastBuildDate>Thu, 16 Jul 2026 13:20:20 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/168425.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 22 Dec 2006 00:45:50 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Mousehook funktioniert nicht on Fri, 22 Dec 2006 00:45:50 GMT]]></title><description><![CDATA[<p>Ich hab versucht einen Mousehook zu erstellen, aber ich bekomm nur Nachrichten wenn die Maus über meinem Fenster ist:</p>
<pre><code class="language-cpp">#include &lt;windows.h&gt;

#define WM_MOUSEHOOK WM_USER+100

HINSTANCE tInstance;
HWND thwnd;
HHOOK hook;

LRESULT CALLBACK MouseProc(int nCode, WPARAM wParam, LPARAM lParam)
{
	if(nCode &gt;= 0)
	{
		SendMessage(thwnd, WM_MOUSEHOOK, wParam, lParam);
	}
	return CallNextHookEx(NULL, nCode, wParam, lParam);
}

extern &quot;C&quot; _declspec(dllexport) void _stdcall SetHook(HWND hwnd)
{
	thwnd = hwnd;
	hook = SetWindowsHookEx(WH_MOUSE, MouseProc, tInstance, NULL);
}

extern &quot;C&quot; _declspec(dllexport) void _stdcall UnSetHook()
{
	UnhookWindowsHookEx(hook);
}

BOOL WINAPI DllMain (HINSTANCE hInst, DWORD reason, LPVOID reserved)
{
    tInstance = hInst;
    return TRUE;
}
</code></pre>
<pre><code class="language-cpp">extern &quot;C&quot; _declspec(dllimport) void _stdcall SetHook(HWND list);
extern &quot;C&quot; _declspec(dllimport) void _stdcall UnSetHook();

#define WM_MOUSEHOOK WM_USER+100

BOOL CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	switch(message)
	{
	case WM_INITDIALOG:
		SetHook(hwnd);
		return TRUE; //WM_INITDIALOG
	case WM_CLOSE:
		UnSetHook();
		EndDialog(hwnd, 0);
		return TRUE; //WM_CLOSE
	case WM_MOUSEHOOK:
                [...]
		return TRUE; //WM_MOUSEHOOK
	}
	return FALSE;
}
</code></pre>
<p>Woran könnte das liegen?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1196402</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1196402</guid><dc:creator><![CDATA[Macher]]></dc:creator><pubDate>Fri, 22 Dec 2006 00:45:50 GMT</pubDate></item><item><title><![CDATA[Reply to Mousehook funktioniert nicht on Fri, 22 Dec 2006 07:05:33 GMT]]></title><description><![CDATA[<p>Dass Deine Hook-Funktion in keiner DLL ist?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1196426</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1196426</guid><dc:creator><![CDATA[Jochen Kalmbach]]></dc:creator><pubDate>Fri, 22 Dec 2006 07:05:33 GMT</pubDate></item><item><title><![CDATA[Reply to Mousehook funktioniert nicht on Fri, 22 Dec 2006 12:20:03 GMT]]></title><description><![CDATA[<p>Der obere Code befindet sich in einer DLL</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1196620</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1196620</guid><dc:creator><![CDATA[Macher]]></dc:creator><pubDate>Fri, 22 Dec 2006 12:20:03 GMT</pubDate></item><item><title><![CDATA[Reply to Mousehook funktioniert nicht on Fri, 22 Dec 2006 13:17:19 GMT]]></title><description><![CDATA[<p>In allen anderen Prozessen ist wohl thwnd nicht initialisiert.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1196649</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1196649</guid><dc:creator><![CDATA[MFK]]></dc:creator><pubDate>Fri, 22 Dec 2006 13:17:19 GMT</pubDate></item><item><title><![CDATA[Reply to Mousehook funktioniert nicht on Fri, 22 Dec 2006 22:29:03 GMT]]></title><description><![CDATA[<p>Du kannst &quot;thwnd&quot; und &quot;hook&quot; in eine &quot;shared&quot; Section packen, dann gibts die Variablen bloss 1x für alle Prozesse die die DLL geladen haben.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1196830</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1196830</guid><dc:creator><![CDATA[hustbaer]]></dc:creator><pubDate>Fri, 22 Dec 2006 22:29:03 GMT</pubDate></item><item><title><![CDATA[Reply to Mousehook funktioniert nicht on Sat, 23 Dec 2006 10:39:19 GMT]]></title><description><![CDATA[<p>Am besten ist es, wenn du WH_MOUSE_LL hookst, da dieser Hook immer global ist.</p>
<p>Hier mal ein kleines Beispiel:</p>
<pre><code class="language-cpp">#include &lt;stdio.h&gt;
#include &lt;windows.h&gt;

HHOOK maus;
int i=0;

__declspec (dllexport) LRESULT CALLBACK mausaktion(int  nCode, WPARAM wParam, LPARAM lParam)
{
	if (nCode &lt; 0)
		return -1;

	if (nCode == HC_ACTION)
		{
			printf(&quot;%d: maus aktion\n&quot;, i);
			i++;
		}

	return(CallNextHookEx(maus, nCode, wParam, lParam));
}

void hook(void)
{
	maus=SetWindowsHookEx(WH_MOUSE_LL,(HOOKPROC)mausaktion,GetModuleHandle(0),0);
}

void unhook(void)
{
	UnhookWindowsHookEx(maus);
}

int main(int argc,char *argv[])
{
	MSG msg;

	hook();
	while (GetMessage(&amp;msg,NULL,0,0))
		{
			TranslateMessage(&amp;msg);
			DispatchMessage(&amp;msg);
		}
	unhook();
	return(0);
}
</code></pre>
<p>Alles weitere steht in der MSDN Library:<br />
<a href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui/windowsuserinterface/windowing/hooks/hookreference/hookfunctions/mouseproc.asp" rel="nofollow">http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui/windowsuserinterface/windowing/hooks/hookreference/hookfunctions/mouseproc.asp</a><br />
<a href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui/windowsuserinterface/windowing/hooks/hookreference/hookstructures/msllhookstruct.asp" rel="nofollow">http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui/windowsuserinterface/windowing/hooks/hookreference/hookstructures/msllhookstruct.asp</a></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1196917</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1196917</guid><dc:creator><![CDATA[dmesg]]></dc:creator><pubDate>Sat, 23 Dec 2006 10:39:19 GMT</pubDate></item></channel></rss>