<?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[Wenn MainThread aus, alles aus?]]></title><description><![CDATA[<p>Hey!</p>
<p>Warum wird die Anwendung beendet, wenn ich Fenster 1 schließe? Wenn ich Fenster 2 schließe, bleibt Fenster 1 offen!</p>
<p>Dazu noch eine Frage:<br />
Ist es üblich, pro Fenster einen Thread zu erstellen, wenn man mehrere Fenster (zB. wie bei GIMP) hat?<br />
Oder reicht eine GetMessage()-Schleife und zwei verschiedene WindowProc()s?</p>
<pre><code class="language-cpp">#include &lt;windows.h&gt;
#include &lt;process.h&gt;

unsigned int __stdcall Thread2(void* param);
long __stdcall WindowProcess(HWND windowHandle, unsigned message, WPARAM wParam, LPARAM lParam);
long __stdcall WindowProcess2(HWND windowHandle, unsigned message, WPARAM wParam, LPARAM lParam);

int __stdcall WinMain(HINSTANCE, HINSTANCE, char*, int)
{
	WNDCLASS windowClass = { };
	windowClass.lpfnWndProc = WindowProcess;
	windowClass.hCursor = LoadCursor(0, IDC_ARROW);
	windowClass.lpszClassName = &quot;Main&quot;;

	RegisterClass(&amp;windowClass);

	CreateWindow(&quot;Main&quot;, &quot;Window 1&quot;, WS_VISIBLE | WS_SYSMENU | WS_MINIMIZEBOX, 0, 0, 300, 300, 0, 0, 0, 0);

	_beginthreadex(0, 0, Thread2, 0, 0, 0);

	MSG message;
	while(GetMessage(&amp;message, 0 , 0, 0))
	{
		TranslateMessage(&amp;message);
		DispatchMessage(&amp;message);
	}
}

unsigned int __stdcall Thread2(void* param)
{
	WNDCLASS windowClass = { };
	windowClass.lpfnWndProc = WindowProcess2;
	windowClass.hCursor = LoadCursor(0, IDC_ARROW);
	windowClass.lpszClassName = &quot;Main2&quot;;

	RegisterClass(&amp;windowClass);

	CreateWindow(&quot;Main2&quot;, &quot;Window 2&quot;, WS_VISIBLE | WS_SYSMENU | WS_MINIMIZEBOX, 0, 0, 500, 500, 0, 0, 0, 0);

	MSG message;
	while(GetMessage(&amp;message, 0 , 0, 0))
	{
		TranslateMessage(&amp;message);
		DispatchMessage(&amp;message);
	}

	return 0;
}

long __stdcall WindowProcess(HWND windowHandle, unsigned message, WPARAM wParam, LPARAM lParam)
{
	switch(message)
	{
	case WM_DESTROY:
		PostQuitMessage(0);
		return 0;
	}

	return DefWindowProc(windowHandle, message, wParam, lParam);
}

long __stdcall WindowProcess2(HWND windowHandle, unsigned message, WPARAM wParam, LPARAM lParam)
{
	switch(message)
	{
	case WM_DESTROY:
		PostQuitMessage(0);
		return 0;
	}

	return DefWindowProc(windowHandle, message, wParam, lParam);
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/topic/240863/wenn-mainthread-aus-alles-aus</link><generator>RSS for Node</generator><lastBuildDate>Mon, 06 Apr 2026 04:07:34 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/240863.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 12 May 2009 19:04:21 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Wenn MainThread aus, alles aus? on Tue, 12 May 2009 19:04:21 GMT]]></title><description><![CDATA[<p>Hey!</p>
<p>Warum wird die Anwendung beendet, wenn ich Fenster 1 schließe? Wenn ich Fenster 2 schließe, bleibt Fenster 1 offen!</p>
<p>Dazu noch eine Frage:<br />
Ist es üblich, pro Fenster einen Thread zu erstellen, wenn man mehrere Fenster (zB. wie bei GIMP) hat?<br />
Oder reicht eine GetMessage()-Schleife und zwei verschiedene WindowProc()s?</p>
<pre><code class="language-cpp">#include &lt;windows.h&gt;
#include &lt;process.h&gt;

unsigned int __stdcall Thread2(void* param);
long __stdcall WindowProcess(HWND windowHandle, unsigned message, WPARAM wParam, LPARAM lParam);
long __stdcall WindowProcess2(HWND windowHandle, unsigned message, WPARAM wParam, LPARAM lParam);

int __stdcall WinMain(HINSTANCE, HINSTANCE, char*, int)
{
	WNDCLASS windowClass = { };
	windowClass.lpfnWndProc = WindowProcess;
	windowClass.hCursor = LoadCursor(0, IDC_ARROW);
	windowClass.lpszClassName = &quot;Main&quot;;

	RegisterClass(&amp;windowClass);

	CreateWindow(&quot;Main&quot;, &quot;Window 1&quot;, WS_VISIBLE | WS_SYSMENU | WS_MINIMIZEBOX, 0, 0, 300, 300, 0, 0, 0, 0);

	_beginthreadex(0, 0, Thread2, 0, 0, 0);

	MSG message;
	while(GetMessage(&amp;message, 0 , 0, 0))
	{
		TranslateMessage(&amp;message);
		DispatchMessage(&amp;message);
	}
}

unsigned int __stdcall Thread2(void* param)
{
	WNDCLASS windowClass = { };
	windowClass.lpfnWndProc = WindowProcess2;
	windowClass.hCursor = LoadCursor(0, IDC_ARROW);
	windowClass.lpszClassName = &quot;Main2&quot;;

	RegisterClass(&amp;windowClass);

	CreateWindow(&quot;Main2&quot;, &quot;Window 2&quot;, WS_VISIBLE | WS_SYSMENU | WS_MINIMIZEBOX, 0, 0, 500, 500, 0, 0, 0, 0);

	MSG message;
	while(GetMessage(&amp;message, 0 , 0, 0))
	{
		TranslateMessage(&amp;message);
		DispatchMessage(&amp;message);
	}

	return 0;
}

long __stdcall WindowProcess(HWND windowHandle, unsigned message, WPARAM wParam, LPARAM lParam)
{
	switch(message)
	{
	case WM_DESTROY:
		PostQuitMessage(0);
		return 0;
	}

	return DefWindowProc(windowHandle, message, wParam, lParam);
}

long __stdcall WindowProcess2(HWND windowHandle, unsigned message, WPARAM wParam, LPARAM lParam)
{
	switch(message)
	{
	case WM_DESTROY:
		PostQuitMessage(0);
		return 0;
	}

	return DefWindowProc(windowHandle, message, wParam, lParam);
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1709573</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1709573</guid><dc:creator><![CDATA[KlausVorDemAus]]></dc:creator><pubDate>Tue, 12 May 2009 19:04:21 GMT</pubDate></item><item><title><![CDATA[Reply to Wenn MainThread aus, alles aus? on Tue, 12 May 2009 19:39:51 GMT]]></title><description><![CDATA[<p>Ein Thread reicht.<br />
Die CRT beendet die Applikation, wenn der Einstiegspunkt zurückkehrt (in diesem Fall WinMain).<br />
Das ist aber ein Feature der CRT und nicht von Windows:<a href="http://blog.kalmbachnet.de/?postid=65" rel="nofollow">http://blog.kalmbachnet.de/?postid=65</a></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1709598</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1709598</guid><dc:creator><![CDATA[Jochen Kalmbach]]></dc:creator><pubDate>Tue, 12 May 2009 19:39:51 GMT</pubDate></item><item><title><![CDATA[Reply to Wenn MainThread aus, alles aus? on Tue, 12 May 2009 19:49:13 GMT]]></title><description><![CDATA[<p>Ahaa.<br />
Ein Thread reicht in jedem Fall? Auch wenn sich die Fenster unabhängig voneinander schließen lassen sollen? Nimmt man dann in WM_DESTROY das Handle des Fensters und löscht es mit DestroyWindow()?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1709604</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1709604</guid><dc:creator><![CDATA[KlausVorDemAus]]></dc:creator><pubDate>Tue, 12 May 2009 19:49:13 GMT</pubDate></item><item><title><![CDATA[Reply to Wenn MainThread aus, alles aus? on Tue, 12 May 2009 20:06:08 GMT]]></title><description><![CDATA[<p>KlausVorDemAus schrieb:</p>
<blockquote>
<p>Ahaa.<br />
Ein Thread reicht in jedem Fall?</p>
</blockquote>
<p>nur wenn du nicht zu lange in der wndproc des fensters verbleibst. windoofs benutzt eine art 'kooperatives multitasking' (DispatchMessage()) d.h. für jede message wird die wndproc des dazugehörigen fensterchens aufgerufen. hängt's irgendwo länger, dann sind alle fenster des threads eingefroren.<br />
<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/1709608</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1709608</guid><dc:creator><![CDATA[+fricky]]></dc:creator><pubDate>Tue, 12 May 2009 20:06:08 GMT</pubDate></item><item><title><![CDATA[Reply to Wenn MainThread aus, alles aus? on Tue, 12 May 2009 20:54:21 GMT]]></title><description><![CDATA[<p>Aha ok danke!</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1709635</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1709635</guid><dc:creator><![CDATA[KlausVorDemAus]]></dc:creator><pubDate>Tue, 12 May 2009 20:54:21 GMT</pubDate></item></channel></rss>