<?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[Verstaendnisproblem!, mit &amp;quot;EnumChildWindows + EnumChildProc&amp;quot; ...]]></title><description><![CDATA[<p>hi ich suche schon einige zeit nach einen verstaendnisvollen C++ Quelltext fuer EnumChildWindows() aber alles was ich finde is VB-zeugs...<br />
ich möchte mir alle ChildWindow-Handels, bzw ID's auflisten lassen.</p>
<p>und zwar will ich fuer diesen zweck erstmal ein API-Prog schreiben mit diversen Buttons, EBOXES, LBs ect., wenn diese Anwendung laeuft moechte ich ein Konsolen Prog starten, das erst mal mit FindWindow() den handel zum fenster findet. und dann soll in der konsole untereinander alle childwindows aufgelistet werden....</p>
<p>nur weiss ich nicht wie man mit EnumChildWindos + EnumChildProc umgeht. haettet ihr vieleicht ein Beispielcode oder koenntet mir mit codeschnippseln erklären wie man es macht?</p>
<p>Danke.<br />
Gruß Tobi</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/173573/verstaendnisproblem-mit-quot-enumchildwindows-enumchildproc-quot</link><generator>RSS for Node</generator><lastBuildDate>Sun, 12 Jul 2026 22:43:58 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/173573.rss" rel="self" type="application/rss+xml"/><pubDate>Sat, 17 Feb 2007 12:11:28 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Verstaendnisproblem!, mit &amp;quot;EnumChildWindows + EnumChildProc&amp;quot; ... on Sat, 17 Feb 2007 12:11:28 GMT]]></title><description><![CDATA[<p>hi ich suche schon einige zeit nach einen verstaendnisvollen C++ Quelltext fuer EnumChildWindows() aber alles was ich finde is VB-zeugs...<br />
ich möchte mir alle ChildWindow-Handels, bzw ID's auflisten lassen.</p>
<p>und zwar will ich fuer diesen zweck erstmal ein API-Prog schreiben mit diversen Buttons, EBOXES, LBs ect., wenn diese Anwendung laeuft moechte ich ein Konsolen Prog starten, das erst mal mit FindWindow() den handel zum fenster findet. und dann soll in der konsole untereinander alle childwindows aufgelistet werden....</p>
<p>nur weiss ich nicht wie man mit EnumChildWindos + EnumChildProc umgeht. haettet ihr vieleicht ein Beispielcode oder koenntet mir mit codeschnippseln erklären wie man es macht?</p>
<p>Danke.<br />
Gruß Tobi</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1230044</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1230044</guid><dc:creator><![CDATA[T0bi]]></dc:creator><pubDate>Sat, 17 Feb 2007 12:11:28 GMT</pubDate></item><item><title><![CDATA[Reply to Verstaendnisproblem!, mit &amp;quot;EnumChildWindows + EnumChildProc&amp;quot; ... on Sat, 17 Feb 2007 13:21:27 GMT]]></title><description><![CDATA[<p>Zufällig hab ich da was vorbereitet...</p>
<pre><code class="language-cpp">#include &lt;windows.h&gt;
#include &lt;stdio.h&gt;

struct tWinList
{ HWND hwnd;
  int cnt;
  long processid;
  long threadid;
  RECT wr;
  char wtext[80];
};
struct tWinListBase
{ struct tWinList *wl;
  int cnt;
};
struct tWinListBase WinListBase;

int useparms(int a, ...)
{
  return a;
}

char *fbprint(char *format, ...)
{
  static char buf[1000];

  vsnprintf(buf, sizeof(buf), format, (&amp;format)+1);
  return (char *)buf;
}

long TextOutStr(HDC hdc, int x, int y, char *s)
{
  return TextOut(hdc, x, y, s, strlen(s));
}

int ReturnValue = 19;

int ChildCounter;

int _stdcall enumchildproc(HWND hwnd, long lParam)
{
  ChildCounter++;
  return 1;
}

int _stdcall enumwindowsproc(HWND hwnd, long lParam)
{
  struct tWinListBase *wlb;
  unsigned long processid;
  long threadid;
  RECT wr;
  char wtext[80];

  wlb = (struct tWinListBase *)lParam;
  wlb-&gt;wl = (struct tWinList *)realloc(wlb-&gt;wl, (wlb-&gt;cnt+1)*sizeof(struct tWinList));
  memset(wlb-&gt;wl+wlb-&gt;cnt, 0, sizeof(struct tWinList));
  wlb-&gt;wl[wlb-&gt;cnt].hwnd = hwnd;
  wlb-&gt;cnt++;

  ChildCounter = 0;
  EnumChildWindows(hwnd, enumchildproc, 0);
  wlb-&gt;wl[wlb-&gt;cnt-1].cnt = ChildCounter;

  threadid = GetWindowThreadProcessId(hwnd, &amp;processid);
  wlb-&gt;wl[wlb-&gt;cnt-1].processid = processid;
  wlb-&gt;wl[wlb-&gt;cnt-1].threadid = threadid;

  GetWindowRect(hwnd, &amp;wr);
  memmove(&amp;(wlb-&gt;wl[wlb-&gt;cnt-1].wr), &amp;wr, sizeof(RECT));

  GetWindowText(hwnd, wtext, sizeof(wtext));
  strcpy(wlb-&gt;wl[wlb-&gt;cnt-1].wtext, wtext);
  return 1;
}

void DoEnumWindows(void)
{
  free(WinListBase.wl);
  memset(&amp;WinListBase, 0, sizeof(struct tWinListBase));
  ReturnValue = EnumWindows(enumwindowsproc, (long)&amp;WinListBase);
}

long _stdcall WndProc(HWND hwnd, unsigned int message, unsigned int wParam, long lParam)
{
  HDC hdc;
  PAINTSTRUCT ps;
  int KEYDOWN_nVirtKey;
  int i;

  switch(message)
    { case WM_PAINT:
          hdc = BeginPaint(hwnd, &amp;ps);
          TextOutStr(hdc, 10, 10, fbprint(&quot;ReturnValue %i&quot;, ReturnValue));
          TextOutStr(hdc, 10, 30, fbprint(&quot;WinListBase.cnt %i&quot;, WinListBase.cnt));
          for (i = 0; i &lt; WinListBase.cnt; i++)
              TextOutStr(hdc, 10, 50+i*20,
                         fbprint(&quot;%u %04X %u th %04X pr %04X %i %i %i %i \&quot;%s\&quot;&quot;,
                      i, WinListBase.wl[i].hwnd,
                         WinListBase.wl[i].cnt,
                         WinListBase.wl[i].threadid,
                         WinListBase.wl[i].processid,
                         WinListBase.wl[i].wr.left,
                         WinListBase.wl[i].wr.top,
                         WinListBase.wl[i].wr.right,
                         WinListBase.wl[i].wr.bottom,
                         WinListBase.wl[i].wtext));
          EndPaint(hwnd, &amp;ps);
          return 0;
      case WM_KEYDOWN:
          KEYDOWN_nVirtKey = wParam;
          if (KEYDOWN_nVirtKey == VK_RETURN)
            { DoEnumWindows();
              InvalidateRect(hwnd, 0, TRUE);
              UpdateWindow(hwnd);
            }
          return 0;
      case WM_DESTROY:
          free(WinListBase.wl);
          PostQuitMessage(0);
    }
  return DefWindowProc(hwnd, message, wParam, lParam);
}

int _stdcall WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
                                          char *szCmdLine, int iCmdShow)
{
  HWND hwnd;
  MSG msg;
  WNDCLASS wc;
  char *cln = &quot;mbclass&quot;;

  memset(&amp;wc, 0, sizeof(WNDCLASS));
  wc.style         = CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS;
  wc.lpfnWndProc   = WndProc;
  wc.hInstance     = hInstance;
  wc.hIcon         = LoadIcon(0, IDI_INFORMATION);
  wc.hCursor       = LoadCursor(0, IDC_ARROW);
  wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
  wc.lpszClassName = cln;

  RegisterClass(&amp;wc);
  hwnd = CreateWindow(cln, &quot;Titel&quot;, WS_OVERLAPPEDWINDOW,
                                    CW_USEDEFAULT, CW_USEDEFAULT,
                                    CW_USEDEFAULT, CW_USEDEFAULT,
                                    0, 0, hInstance, 0);
  ShowWindow(hwnd, iCmdShow);
  UpdateWindow(hwnd);

  useparms(0, hPrevInstance, szCmdLine);
  while(GetMessage(&amp;msg, 0, 0, 0))
    { TranslateMessage(&amp;msg);
      DispatchMessage(&amp;msg);
    }

  return msg.wParam;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1230072</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1230072</guid><dc:creator><![CDATA[keksekekse]]></dc:creator><pubDate>Sat, 17 Feb 2007 13:21:27 GMT</pubDate></item><item><title><![CDATA[Reply to Verstaendnisproblem!, mit &amp;quot;EnumChildWindows + EnumChildProc&amp;quot; ... on Sat, 17 Feb 2007 15:20:53 GMT]]></title><description><![CDATA[<p>aehm jaaa? und wie, was passiert da jetzt? ich steig da irgendwie net ganz durch</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1230147</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1230147</guid><dc:creator><![CDATA[T0bi]]></dc:creator><pubDate>Sat, 17 Feb 2007 15:20:53 GMT</pubDate></item><item><title><![CDATA[Reply to Verstaendnisproblem!, mit &amp;quot;EnumChildWindows + EnumChildProc&amp;quot; ... on Sat, 17 Feb 2007 19:26:12 GMT]]></title><description><![CDATA[<p>Das geht weitaus einfacher mit der Fubktion GetWindow (GW_CHILD, GW_NEXT)!</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1230291</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1230291</guid><dc:creator><![CDATA[Martin Richter]]></dc:creator><pubDate>Sat, 17 Feb 2007 19:26:12 GMT</pubDate></item><item><title><![CDATA[Reply to Verstaendnisproblem!, mit &amp;quot;EnumChildWindows + EnumChildProc&amp;quot; ... on Sun, 18 Feb 2007 16:39:01 GMT]]></title><description><![CDATA[<p>ja und wie?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1230699</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1230699</guid><dc:creator><![CDATA[T0bi]]></dc:creator><pubDate>Sun, 18 Feb 2007 16:39:01 GMT</pubDate></item><item><title><![CDATA[Reply to Verstaendnisproblem!, mit &amp;quot;EnumChildWindows + EnumChildProc&amp;quot; ... on Sun, 18 Feb 2007 17:33:30 GMT]]></title><description><![CDATA[<p>Win32 Programmer's Reference</p>
<p>Guggst Du hier: <a href="http://www.codingcrew.de/programmierung/win32hlp.php" rel="nofollow">http://www.codingcrew.de/programmierung/win32hlp.php</a></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1230722</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1230722</guid><dc:creator><![CDATA[keksekekse]]></dc:creator><pubDate>Sun, 18 Feb 2007 17:33:30 GMT</pubDate></item><item><title><![CDATA[Reply to Verstaendnisproblem!, mit &amp;quot;EnumChildWindows + EnumChildProc&amp;quot; ... on Mon, 19 Feb 2007 08:31:20 GMT]]></title><description><![CDATA[<p>T0bi schrieb:</p>
<blockquote>
<p>ja und wie?</p>
</blockquote>
<p>In dem man anfängt zum Beispiel die Doku zu lesen:</p>
<pre><code class="language-cpp">for (HWND hWnd=::GetWindow(hWndParent,GW_CHILD); hWnd; hWnd = ::GetWindow(hWnd,GW_HWNDNEXT))
{
...
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1230919</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1230919</guid><dc:creator><![CDATA[Martin Richter]]></dc:creator><pubDate>Mon, 19 Feb 2007 08:31:20 GMT</pubDate></item><item><title><![CDATA[Reply to Verstaendnisproblem!, mit &amp;quot;EnumChildWindows + EnumChildProc&amp;quot; ... on Mon, 19 Feb 2007 20:53:48 GMT]]></title><description><![CDATA[<p>also ich habe des jetzt mal so versucht wies der martin vorgeschlagen hat, und er erkännt schon mal das ich 9Childs habe, doch will ich mir den text noch ausgeben lassen den das jeweilige child besitzt.<br />
Hier mein Ansatz</p>
<pre><code class="language-cpp">int main( int argc, char* argv[] ) {

    HWND hWnd;
    string sWindow;             // searched window
    string Window_text;         // childwindows text
    char *szBuffer;
    int iLength = 0;
    int i = 1;

    cout &lt;&lt; &quot;\n Please enter here the windowname, witch one you want: &quot;;
    cin &gt;&gt; sWindow;
    cout &lt;&lt; endl;
    cin.sync();

        hWnd = FindWindow( 0, sWindow.c_str() );
            if( !( hWnd ) ) {

                textcolor( LIGHTRED );
                cprintf( &quot;\n Error, couldn't found window.\n&quot; );
                getchar();
                return 0;
            }
            else {

                textcolor( LIGHTGREEN );
                cprintf( &quot;\n Ok, the window could found.\n&quot; );
            }

    for( hWnd = GetWindow( hWnd, GW_CHILD ); hWnd;
         hWnd = GetWindow( hWnd, GW_HWNDNEXT ) ) {

        iLength = GetWindowTextLength( hWnd );
        Window_text = GetWindowText( hWnd, szBuffer, iLength );

        cout &lt;&lt; &quot;\n Childwindow[ &quot; &lt;&lt; i &lt;&lt; &quot; ]  -  &quot; &lt;&lt; *szBuffer;
        i++;
    }
    getchar();
    return 0;
}
</code></pre>
<p>doch jedes mal listet er mir nur &quot;Y&quot; auf statt, Butto01 ... wieso???</p>
<p>[EDIT] Ok... wenn ich statt pointer nen array nehm gehts... hmm</p>
<p>Gruß Tobi</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1231537</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1231537</guid><dc:creator><![CDATA[T0bi]]></dc:creator><pubDate>Mon, 19 Feb 2007 20:53:48 GMT</pubDate></item><item><title><![CDATA[Reply to Verstaendnisproblem!, mit &amp;quot;EnumChildWindows + EnumChildProc&amp;quot; ... on Tue, 20 Feb 2007 06:23:00 GMT]]></title><description><![CDATA[<p>Wenn du mit einem Pointer arbeitest und sogar schon die Länge in iLength ermittelst, dann musst du nur noch entsprechend Speicher reservieren (new, malloc) - und am Ende diesen wieder freigeben (delete[], free)</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1231622</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1231622</guid><dc:creator><![CDATA[flenders]]></dc:creator><pubDate>Tue, 20 Feb 2007 06:23:00 GMT</pubDate></item><item><title><![CDATA[Reply to Verstaendnisproblem!, mit &amp;quot;EnumChildWindows + EnumChildProc&amp;quot; ... on Tue, 20 Feb 2007 09:28:34 GMT]]></title><description><![CDATA[<p>Ach komm ... machen wirs ordentlich <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f609.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--winking_face"
      title=";)"
      alt="😉"
    /></p>
<pre><code class="language-cpp">int main() 
{
	std::string window_name;
	std::cout &lt;&lt; &quot;Please enter the Windowname: &quot; &lt;&lt; std::flush;
	std::getline(std::cin, window_name);

	HWND hWnd = FindWindow(NULL, window_name.c_str());

	if (hWnd == NULL || IsWindow(hWnd) == FALSE)
	{
		std::cout &lt;&lt; &quot;ERROR! Could not find window!&quot; &lt;&lt; std::endl;
		std::cin.clear();
		std::cin.ignore(std::cin.rdbuf()-&gt;in_avail());
		std::cin.get();	

		return 1;
	}

	std::cout &lt;&lt; &quot;The window could be found!&quot; &lt;&lt; std::endl;

	unsigned short child_windows = 0;
    for (hWnd = GetWindow(hWnd, GW_CHILD ); hWnd; hWnd = GetWindow(hWnd, GW_HWNDNEXT), ++child_windows) 
	{
        int nLen	= GetWindowTextLength(hWnd);
		char* szBuffer = new char[nLen];
        GetWindowText(hWnd, szBuffer, nLen);
		std::cout &lt;&lt; &quot;\tChildwindow [&quot; &lt;&lt; child_windows &lt;&lt; &quot;]  -&gt;  &quot; &lt;&lt; szBuffer &lt;&lt; std::endl;
		delete [] szBuffer;
    }

	std::cin.clear();
	std::cin.ignore(std::cin.rdbuf()-&gt;in_avail());
	std::cin.get();	

	return 0;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1231729</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1231729</guid><dc:creator><![CDATA[*D*Evil]]></dc:creator><pubDate>Tue, 20 Feb 2007 09:28:34 GMT</pubDate></item><item><title><![CDATA[Reply to Verstaendnisproblem!, mit &amp;quot;EnumChildWindows + EnumChildProc&amp;quot; ... on Tue, 20 Feb 2007 11:07:46 GMT]]></title><description><![CDATA[<blockquote>
<pre><code class="language-cpp">unsigned short child_windows = 0; 
    for (hWnd = GetWindow(hWnd, GW_CHILD ); hWnd; hWnd = GetWindow(hWnd, GW_HWNDNEXT), ++child_windows) 
    { 
        int nLen    = GetWindowTextLength(hWnd); 
        char* szBuffer = new char[nLen]; 
        GetWindowText(hWnd, szBuffer, nLen); 
        std::cout &lt;&lt; &quot;\tChildwindow [&quot; &lt;&lt; child_windows &lt;&lt; &quot;]  -&gt;  &quot; &lt;&lt; szBuffer &lt;&lt; std::endl; 
        delete [] szBuffer; 
    }
</code></pre>
</blockquote>
<p>Jedesmal ein alloc? Muss den wirklich so etwas sein?<br />
Vo rallem hast Du auch keinen Platz für das '\0' Zeichen reserviert.</p>
<pre><code class="language-cpp">unsigned short child_windows = 0; 
    int nMaxLen = 1024;
    char* szBuffer = new char[nMaxLen];
    for (hWnd = GetWindow(hWnd, GW_CHILD ); hWnd; hWnd = GetWindow(hWnd, GW_HWNDNEXT), ++child_windows) 
    { 
        int nLen = GetWindowTextLength(hWnd)+1; 
        if (nLen&gt;nMaxLen)
        {
            delete [] szBuffer;
            szBuffer = new char[nMaxLen=max(nMaxLen*2,nLen)];    
        }
        GetWindowText(hWnd, szBuffer, nLen); 
        std::cout &lt;&lt; &quot;\tChildwindow [&quot; &lt;&lt; child_windows &lt;&lt; &quot;]  -&gt;  &quot; &lt;&lt; szBuffer &lt;&lt; std::endl; 
    } 
    delete [] szBuffer;
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1231807</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1231807</guid><dc:creator><![CDATA[Martin Richter]]></dc:creator><pubDate>Tue, 20 Feb 2007 11:07:46 GMT</pubDate></item><item><title><![CDATA[Reply to Verstaendnisproblem!, mit &amp;quot;EnumChildWindows + EnumChildProc&amp;quot; ... on Tue, 20 Feb 2007 11:16:40 GMT]]></title><description><![CDATA[<p>Hmm stimmt war mir nicht sicher ob GetWindowTextLength jetzt den Terminator einbezieht ... naja ... hmm ok ist vllt so etwas performanter, allerdings hast du so selbst wenn es nur ein ganz kurzer String ist direkt 1024 reserviert ...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1231813</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1231813</guid><dc:creator><![CDATA[*D*Evil]]></dc:creator><pubDate>Tue, 20 Feb 2007 11:16:40 GMT</pubDate></item><item><title><![CDATA[Reply to Verstaendnisproblem!, mit &amp;quot;EnumChildWindows + EnumChildProc&amp;quot; ... on Tue, 20 Feb 2007 12:39:04 GMT]]></title><description><![CDATA[<p>(D)Evil schrieb:</p>
<blockquote>
<p>hmm ok ist vllt so etwas performanter, allerdings hast du so selbst wenn es nur ein ganz kurzer String ist direkt 1024 reserviert ...</p>
</blockquote>
<p>Was ja immerhin 0,0001% der heutzutage üblichen 1 GB Hauptspeicher sind <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f642.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--slightly_smiling_face"
      title=":)"
      alt="🙂"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1231899</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1231899</guid><dc:creator><![CDATA[pock]]></dc:creator><pubDate>Tue, 20 Feb 2007 12:39:04 GMT</pubDate></item></channel></rss>