<?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[Im Hintergrund Mausklicks zählen]]></title><description><![CDATA[<p>Hallo,<br />
ich will ein Programm schreiben, das die Mausklicks zählt, während es im Hintergrund läuft.<br />
Wenn das Fenster geöffnet ist und ich darauf klicke funktioniert das wunderbar, aber wie kann ich die klicks zählen, wenn das Fenster nur im Hintergrund läuft?</p>
<p>MfG<br />
Burger</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/166281/im-hintergrund-mausklicks-zählen</link><generator>RSS for Node</generator><lastBuildDate>Fri, 17 Jul 2026 01:49:42 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/166281.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 27 Nov 2006 19:10:05 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Im Hintergrund Mausklicks zählen on Mon, 27 Nov 2006 19:10:05 GMT]]></title><description><![CDATA[<p>Hallo,<br />
ich will ein Programm schreiben, das die Mausklicks zählt, während es im Hintergrund läuft.<br />
Wenn das Fenster geöffnet ist und ich darauf klicke funktioniert das wunderbar, aber wie kann ich die klicks zählen, wenn das Fenster nur im Hintergrund läuft?</p>
<p>MfG<br />
Burger</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1182640</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1182640</guid><dc:creator><![CDATA[Burger007]]></dc:creator><pubDate>Mon, 27 Nov 2006 19:10:05 GMT</pubDate></item><item><title><![CDATA[Reply to Im Hintergrund Mausklicks zählen on Mon, 27 Nov 2006 20:00:14 GMT]]></title><description><![CDATA[<p>Mit einem Mouse-Hook in einer DLL...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1182673</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1182673</guid><dc:creator><![CDATA[flenders]]></dc:creator><pubDate>Mon, 27 Nov 2006 20:00:14 GMT</pubDate></item><item><title><![CDATA[Reply to Im Hintergrund Mausklicks zählen on Mon, 27 Nov 2006 21:55:04 GMT]]></title><description><![CDATA[<p>Hier ein <a href="http://www.c-plusplus.net/forum/viewtopic-var-t-is-39383.html" rel="nofollow">Beispiel für die Tastatur</a>... Ist aber leicht auf Mäuse übertragbar <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f603.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--grinning_face_with_big_eyes"
      title=":D"
      alt="😃"
    /> ...</p>
<p>Du brauchst auch wieder <a href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui/windowsuserinterface/windowing/hooks/hookreference/hookfunctions/setwindowshookex.asp" rel="nofollow">SetWindowsHookEx</a> mit dem Flag WH_MOUSE.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1182752</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1182752</guid><dc:creator><![CDATA[CodeFinder]]></dc:creator><pubDate>Mon, 27 Nov 2006 21:55:04 GMT</pubDate></item><item><title><![CDATA[Reply to Im Hintergrund Mausklicks zählen on Thu, 30 Nov 2006 21:46:51 GMT]]></title><description><![CDATA[<p>danke erstmals für den hinweis</p>
<p>ich benutze Dev-C++ und habe dazu hier ein Tutorial zu Mousehooks gefunden:<br />
<a href="http://elearning.tutorials.de/flashpaper/c_c++/c-Mouse-Systemhook.swf" rel="nofollow">http://elearning.tutorials.de/flashpaper/c_c++/c-Mouse-Systemhook.swf</a></p>
<p>Es wird beschrieben, wie man ein &quot;Pipetten&quot;-Programm schreibt, das Farben auf dem Bildschrim erkennen kann.<br />
Darin stehen folgende Codes:</p>
<p>1. die Header-Datei der DLL (dll.h):</p>
<pre><code class="language-cpp">#ifndef _DLL_H_
#define _DLL_H_

#include &lt;windows.h&gt;

#if BUILDING_DLL
# define DLLIMPORT __declspec (dllexport)
#else /* Not BUILDING_DLL */
# define DLLIMPORT __declspec (dllimport)
#endif /* Not BUILDING_DLL */

#define SHARED __attribute__((section(&quot;.shr&quot;), shared)) 

DLLIMPORT BOOL InstallHook(); 
DLLIMPORT BOOL UninstallHook(); 

LRESULT CALLBACK MouseProc(int nCode, WPARAM wParam, LPARAM lParam);

#endif /* _DLL_H_ */
</code></pre>
<p>hier hatte ich zuerst Probleme, weil auf der Seite das letzte #endif angeschnitten war, konnte ich aber noch leicht korrigieren</p>
<p>2. der main-coder der DLL (dllmail.c):</p>
<pre><code class="language-cpp">/* Replace &quot;dll.h&quot; with the name of your header */ 
#include &quot;dll.h&quot; 

// Globale Variablen 
HHOOK g_hMouseHook SHARED = NULL; // Handle unseres Hooks (als &quot;shared&quot; Deklariert) 
HINSTANCE g_hInst SHARED = NULL;     // Handle der DLL selbst 

BOOL APIENTRY DllMain (HINSTANCE hInst     /* Library instance handle. */ , 
                       DWORD reason        /* Reason this function is being called. */ , 
                       LPVOID reserved     /* Not used. */ ) 
{ 
  g_hInst = hInst; 
  return TRUE; 
}
DLLIMPORT BOOL InstallHook() 
{ 
  if(g_hMouseHook != NULL) 
    return TRUE; 
  g_hMouseHook = SetWindowsHookEx(WH_MOUSE, MouseProc, g_hInst, 0); 
  if(g_hMouseHook == NULL) 
    return FALSE; 
  return TRUE; 
} 
DLLIMPORT BOOL UninstallHook() 
{ 
  if(g_hMouseHook != NULL) 
  { 
    UnhookWindowsHookEx(g_hMouseHook); 
    g_hMouseHook = NULL; 
  }
  return TRUE;  
}

LRESULT CALLBACK MouseProc(int nCode, WPARAM wParam, LPARAM lParam) 
{ 
  if (nCode &lt; 0) 
    return CallNextHookEx(g_hMouseHook, nCode, wParam, lParam); 
  if(nCode == HC_ACTION) 
  { 
    if ( (wParam == WM_LBUTTONDOWN)||(wParam == WM_NCLBUTTONDOWN) ) 
    { 
      MOUSEHOOKSTRUCT *mhs = (MOUSEHOOKSTRUCT*)lParam; 
      HWND caller = FindWindow(&quot;Pipette&quot;, NULL); 
      if(caller != NULL) 
        PostMessage(caller, WM_USER+123, 0, MAKELPARAM(mhs-&gt;pt.x, mhs-&gt;pt.y)); 
    } 
    return CallNextHookEx(g_hMouseHook, nCode, wParam, lParam); 
  }
}
</code></pre>
<p>3. die Headerdatei vom Pipetten-Programm (main.h)</p>
<pre><code class="language-cpp">#include &lt;windows.h&gt; 
#include &lt;stdio.h&gt; 

/* DEFINES */ 

#define WINDOW_WIDTH 310 
#define WINDOW_HEIGHT 200 

#ifndef GET_X_LPARAM 
#define GET_X_LPARAM(lp)   ((int)(short)LOWORD(lp)) 
#endif 
#ifndef GET_Y_LPARAM 
#define GET_Y_LPARAM(lp)   ((int)(short)HIWORD(lp)) 
#endif 

typedef bool (CALLBACK *MYFUNC)(void); 

/* Prototypen */ 

void Init(); 
void DrawColor(POINT &amp;p, HWND &amp;mainWindow); 
void DrawDialog(HWND &amp;parent, HINSTANCE &amp;inst); 
void ToHTML(); 
void ToRGB(); 
bool IsPointInApp(POINT &amp;p, HWND &amp;mainWindow); 
LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM); 

/* Globale Variablen */ 

MYFUNC InstallHook; 
MYFUNC UninstallHook;

HWND hInstallHookBtn; 
HWND hUninstallHookBtn; 
HWND hEditRGB; 
HWND hEditHTML; 
HWND hStaticFrame; 

COLORREF col; 
RECT ColorRect; 

char szClassName[ ] = &quot;Pipette&quot;;
</code></pre>
<p>4. der main-code vom Programm (main.cpp):</p>
<pre><code class="language-cpp">#include &quot;main.h&quot; 

int WINAPI WinMain (HINSTANCE hThisInstance, 
HINSTANCE hPrevInstance, 
LPSTR lpszArgument, 
int nFunsterStil) 

{ 
  HWND hwnd;               /* This is the handle for our window */ 
  MSG messages;            /* Here messages to the application are saved */ 
  WNDCLASSEX wincl;        /* Data structure for the windowclass */
  Init(); 
  /* The Window structure */ 
  wincl.hInstance = hThisInstance; 
  wincl.lpszClassName = szClassName; 
  wincl.lpfnWndProc = WindowProcedure;      /* This function is called by windows */ 
  wincl.style = CS_DBLCLKS;                 /* Catch double-clicks */ 
  wincl.cbSize = sizeof (WNDCLASSEX); 
  /* Use default icon and mouse-pointer */ 
  wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION); 
  wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION); 
  wincl.hCursor = LoadCursor (NULL, IDC_ARROW); 
  wincl.lpszMenuName = NULL;                 /* No menu */ 
  wincl.cbClsExtra = 0;                      /* No extra bytes after the window class */ 
  wincl.cbWndExtra = 0;                      /* structure or the window instance */ 
  /* Use Windows's default color as the background of the window */ 
  wincl.hbrBackground = (HBRUSH) COLOR_BACKGROUND; 
  /* Register the window class, and if it fails quit the program */ 
  if (!RegisterClassEx (&amp;wincl)) 
    return 0; 
  /* The class is registered, let's create the program*/ 
  hwnd = CreateWindowEx ( 0,                   /* Extended possibilites for variation */ 
                          szClassName,         /* Classname */ 
                          &quot;Pipette&quot;,           /* Title Text */ 
                          WS_SYSMENU|WS_MINIMIZEBOX, /* default window */ 
                          CW_USEDEFAULT,       /* Windows decides the position */ 
                          CW_USEDEFAULT, /* where the window ends up on the screen */ 
                          WINDOW_WIDTH,                 /* The programs width */                
                          WINDOW_HEIGHT,                 /* and height in pixels */             
                          HWND_DESKTOP,        /* The window is a child-window to desktop */ 
                          NULL,                /* No menu */ 
                          hThisInstance,       /* Program Instance handler */ 
                          NULL                 /* No Window Creation data */ 
                        ); 
  DrawDialog(hwnd, hThisInstance); 
  /* Make the window visible on the screen */ 
  ShowWindow (hwnd, nFunsterStil); 
  HINSTANCE hDLL = LoadLibrary(&quot;mousehook.dll&quot;); 

  if(hDLL == NULL) 
  { 
    MessageBox(NULL, &quot;Fehler beim Laden der DLL: mousehook.dll&quot;, &quot;Fehler&quot;, MB_OK); 
    return FALSE; 
  } 
  InstallHook = (MYFUNC) GetProcAddress(hDLL, &quot;InstallHook&quot;); 
  if(InstallHook == NULL) 
  { 
    MessageBox(NULL, &quot;Fehler: InstallHook nicht gefunden in: mousehook.dll&quot;, &quot;Fehler&quot;, MB_OK);
    return FALSE; 
  } 
  UninstallHook = (MYFUNC) GetProcAddress(hDLL, &quot;UninstallHook&quot;); 
  if(UninstallHook == NULL) 
  { 
    MessageBox(NULL, &quot;Fehler: UninstallHook nicht gefunden in: mousehook.dll&quot;, &quot;Fehler&quot;, MB_OK); 
    return FALSE; 
  } 
  /* Run the message loop. It will run until GetMessage() returns 0 */ 
  while (GetMessage (&amp;messages, NULL, 0, 0)) 
  { 
    /* Translate virtual-key messages into character messages */ 
    TranslateMessage(&amp;messages); 
    /* Send message to WindowProcedure */ 
    DispatchMessage(&amp;messages); 
  } 
  /* The program return-value is 0 - The value that PostQuitMessage() gave */ 
  FreeLibrary(hDLL); 
  return messages.wParam; 
} 

void Init() 
{ 
  InstallHook = NULL; 
  UninstallHook = NULL; 
  hInstallHookBtn = NULL; 
  hUninstallHookBtn = NULL; 
  hEditRGB = NULL; 
  hEditHTML = NULL; 
  hStaticFrame = NULL; 
  col = RGB(0,0,0); 
  ColorRect.left = 10; 
  ColorRect.top = 120; 
  ColorRect.right = 290; 
  ColorRect.bottom = 160; 
}

void DrawDialog(HWND &amp;parent, HINSTANCE &amp;inst) 
{ 
  hInstallHookBtn = CreateWindow(&quot;BUTTON&quot;, 0, WS_CHILD|WS_VISIBLE, 10, 10, 120, 30, parent, 0, inst, 0);
  SetWindowText(hInstallHookBtn, &quot;Install Hook&quot;); 
  hUninstallHookBtn = CreateWindow(&quot;BUTTON&quot;, 0, WS_CHILD|WS_VISIBLE, 170, 10, 120, 30, parent, 0, inst, 0); 
  SetWindowText(hUninstallHookBtn, &quot;Uninstall Hook&quot;); 
  HWND tmp; 
  tmp = CreateWindow(&quot;STATIC&quot;, 0, WS_CHILD|WS_VISIBLE, 10, 60, 100, 18, parent, 0, inst, 0); 
  SetWindowText(tmp, &quot;RGB Farbe:&quot;); 
  tmp = CreateWindow(&quot;STATIC&quot;, 0, WS_CHILD|WS_VISIBLE, 10, 90, 100, 18, parent, 0, inst, 0); 
  SetWindowText(tmp, &quot;HTML Farbe:&quot;); 
  hEditRGB = CreateWindow(&quot;EDIT&quot;, 0, WS_BORDER|WS_CHILD|WS_VISIBLE|ES_READONLY, 120, 59, 100, 20, parent, 0, inst, 0); 
  hEditHTML = CreateWindow(&quot;EDIT&quot;, 0, WS_BORDER|WS_CHILD|WS_VISIBLE|ES_READONLY, 120, 89, 100, 20, parent, 0, inst, 0); 
  //hStaticFrame = CreateWindow(&quot;STATIC&quot;, 0, WS_BORDER|WS_CHILD|WS_VISIBLE, 10, 120, 280, 40, parent, 0, inst, 0); 
} 

LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) 
{ 
  HWND hBut; 
  static HBRUSH brush; 
  switch (message)                  /* handle the messages */ 
  { 
    case WM_COMMAND: 
      if(HIWORD(wParam) == BN_CLICKED) 
      { 
        hBut = (HWND)lParam; 
        if(hBut == hInstallHookBtn) 
        { 
          BOOL ret = InstallHook(); 
          if(ret == FALSE) 
            MessageBox(NULL, &quot;InstallHook fehlgeschlagen&quot;, &quot;Fehler&quot;, MB_OK); 
          else
            SetWindowPos(hwnd,  HWND_TOPMOST , 0, 0, 0, 0, SWP_NOSIZE |SWP_SHOWWINDOW); 
        } 
        else if(hBut == hUninstallHookBtn) 
        { 
          if(UninstallHook() == FALSE) 
            MessageBox(NULL, &quot;UninstallHook fehlgeschlagen&quot;, &quot;Fehler&quot;, MB_OK); 
        } 
      } 
      break; 

    case WM_USER+123: 
      POINT p; 
      p.x = GET_X_LPARAM(lParam); 
      p.y = GET_Y_LPARAM(lParam); 
      DrawColor(p, hwnd); 
      break;

    case WM_PAINT: 
      PAINTSTRUCT ps; 
      brush = CreateSolidBrush(col); 
      HDC dc; 
      dc = NULL; 
      dc = BeginPaint(hwnd, &amp;ps); 
      SelectObject(dc, brush); 
      FillRect(dc, &amp;ColorRect, brush);
      EndPaint(hwnd, &amp;ps); 
      return 0; 

    case WM_DESTROY: 
      DeleteObject(brush); 
      if(!UninstallHook()) 
        MessageBox(NULL, &quot;UninstallHook fehlgeschlagen&quot;, &quot;Fehler&quot;, MB_OK); 
      PostQuitMessage (0);       /* send a WM_QUIT to the message queue */ 
      break; 

    default:                      /* for messages that we don't deal with */ 
      return DefWindowProc (hwnd, message, wParam, lParam); 
  } 
  return 0; 
} 

void DrawColor(POINT &amp;p, HWND &amp;mainWindow) 
{ 
  HWND owner = WindowFromPoint(p); 
  if(owner) 
  { 
    HDC ownerDC = GetDC(owner); 
    if(ownerDC &amp;&amp; !IsPointInApp(p, mainWindow)) 
    {
      ScreenToClient(owner, &amp;p); 
      col = GetPixel(ownerDC, p.x, p.y); 
      ToHTML(); 
      ToRGB(); 
      InvalidateRect(mainWindow, &amp;ColorRect, TRUE); 
    } 
  } 
} 

void ToHTML() 
{ 
  char sHtml[8]; sHtml[0] = 0; 
  sprintf(sHtml, &quot;#%.2X%.2X%.2X&quot;, GetRValue(col), 
  GetGValue(col), 
  GetBValue(col)); 
  SetWindowText(hEditHTML, sHtml); 
} 

void ToRGB() 
{ 
  char sRGB[12]; sRGB[0] = 0; 
  sprintf(sRGB, &quot;%d,%d,%d&quot;, GetRValue(col), 
  GetGValue(col), 
  GetBValue(col)); 
  SetWindowText(hEditRGB, sRGB); 
} 

bool IsPointInApp(POINT &amp;p, HWND &amp;mainWindow) 
{ 
  RECT rect; 
  GetWindowRect(mainWindow, &amp;rect); 
  if(p.x &gt;= rect.left &amp;&amp; 
     p.x &lt;= rect.right &amp;&amp; 
     p.y &gt;= rect.top &amp;&amp; 
     p.y &lt;= rect.bottom) 
  { 
    return true; 
  } 
  else 
    return false; 
}
</code></pre>
<p>Jetzt aber zu meinem Problem:<br />
ich kann dieses Programm problemlos kompilieren, allerdings kommt dann vo Programm die Meldung &quot;Fehler: InstallHook nicht gefunden in: mousehook.dll&quot;. Dann hab ich die DLL mit dem Dependency Walker von Microsoft Visual C++ geöffnet und gesehen, dass es die Fuktionen &quot;InstallHook&quot; und &quot;UninstallHook&quot; nicht gibt, sondern nur &quot;_Z11InstallHookv&quot; und &quot;Z_13UninstallHookv&quot;.<br />
Also hab ich sie im Code ersetzt:</p>
<pre><code class="language-cpp">HINSTANCE hDLL = LoadLibrary(&quot;mousehook.dll&quot;); 

  if(hDLL == NULL) 
  { 
    MessageBox(NULL, &quot;Fehler beim Laden der DLL: mousehook.dll&quot;, &quot;Fehler&quot;, MB_OK); 
    return FALSE; 
  } 
  InstallHook = (MYFUNC) GetProcAddress(hDLL, &quot;_Z11InstallHookv&quot;); 
  if(InstallHook == NULL) 
  { 
    MessageBox(NULL, &quot;Fehler: InstallHook nicht gefunden in: mousehook.dll&quot;, &quot;Fehler&quot;, MB_OK);
    return FALSE; 
  } 
  UninstallHook = (MYFUNC) GetProcAddress(hDLL, &quot;_Z13UninstallHookv&quot;); 
  if(UninstallHook == NULL) 
  { 
    MessageBox(NULL, &quot;Fehler: UninstallHook nicht gefunden in: mousehook.dll&quot;, &quot;Fehler&quot;, MB_OK); 
    return FALSE; 
  }
</code></pre>
<p>Danach schien das Programm zu laufen, aber sobals ich auf &quot;installHook&quot; klicke, erscheint die Meldung &quot;InstallHook fehlgeschlagen&quot;, welche so zustande kommt:</p>
<pre><code class="language-cpp">case WM_COMMAND: 
      if(HIWORD(wParam) == BN_CLICKED) 
      { 
        hBut = (HWND)lParam; 
        if(hBut == hInstallHookBtn) 
        { 
          BOOL ret = InstallHook(); 
          if(ret == FALSE) 
            MessageBox(NULL, &quot;InstallHook fehlgeschlagen&quot;, &quot;Fehler&quot;, MB_OK); 
          else
            SetWindowPos(hwnd,  HWND_TOPMOST , 0, 0, 0, 0, SWP_NOSIZE |SWP_SHOWWINDOW); 
        } 
        else if(hBut == hUninstallHookBtn) 
        { 
          if(UninstallHook() == FALSE) 
            MessageBox(NULL, &quot;UninstallHook fehlgeschlagen&quot;, &quot;Fehler&quot;, MB_OK); 
        } 
      } 
      break;
</code></pre>
<p>Aber wo liegt nun der Fehler? Kann mir jemand dabei helfen?<br />
Danke im vorraus</p>
<p>Burger</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1184966</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1184966</guid><dc:creator><![CDATA[Burger007]]></dc:creator><pubDate>Thu, 30 Nov 2006 21:46:51 GMT</pubDate></item><item><title><![CDATA[Reply to Im Hintergrund Mausklicks zählen on Sat, 02 Dec 2006 11:31:03 GMT]]></title><description><![CDATA[<p>extern C Block verwenden, siehe google.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1185735</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1185735</guid><dc:creator><![CDATA[CodeFinder]]></dc:creator><pubDate>Sat, 02 Dec 2006 11:31:03 GMT</pubDate></item></channel></rss>