<?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[Kürzester Code zur Fenstererzeugung?]]></title><description><![CDATA[<p>Hey!</p>
<p>Würde dieser Code ausreichen, um ein Fenster sauber zu erstellen und wieder freizugeben? Habe insbesondere HINSTANCE weggelassen, wann wäre das wichtig? Scheint ohne Probleme zu funktionieren:</p>
<pre><code class="language-cpp">int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
{
	WNDCLASS windowClass;

	memset(&amp;windowClass, 0, sizeof(windowClass));

	windowClass.lpfnWndProc = MsgProc;
    windowClass.lpszClassName = &quot;Main&quot;;

	RegisterClass(&amp;windowClass);

	CreateWindow(&quot;Main&quot;, &quot;Test&quot;, WS_SYSMENU | WS_VISIBLE, 100, 100, 200, 200, 0, 0, 0, 0);

	MSG message = { 0 };

	while(message.message != WM_QUIT)
    {
        if(PeekMessage(&amp;message, 0, 0, 0, PM_REMOVE))
        {
            TranslateMessage(&amp;message); 
            DispatchMessage(&amp;message); 
        }
    }

	UnregisterClass(&quot;Main&quot;, 0);
}

LRESULT WINAPI MsgProc(HWND windowHandle, UINT message, WPARAM wParam, LPARAM lParam) 
{
	switch(message)
	{
	case WM_DESTROY:
		PostQuitMessage(0);
		break;
	default:
		return DefWindowProc(windowHandle, message, wParam, lParam);
	}

	return 0L;
}
</code></pre>
<p>MfG</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/195110/kürzester-code-zur-fenstererzeugung</link><generator>RSS for Node</generator><lastBuildDate>Tue, 30 Jun 2026 02:14:35 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/195110.rss" rel="self" type="application/rss+xml"/><pubDate>Sun, 14 Oct 2007 12:23:42 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Kürzester Code zur Fenstererzeugung? on Sun, 14 Oct 2007 12:23:42 GMT]]></title><description><![CDATA[<p>Hey!</p>
<p>Würde dieser Code ausreichen, um ein Fenster sauber zu erstellen und wieder freizugeben? Habe insbesondere HINSTANCE weggelassen, wann wäre das wichtig? Scheint ohne Probleme zu funktionieren:</p>
<pre><code class="language-cpp">int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
{
	WNDCLASS windowClass;

	memset(&amp;windowClass, 0, sizeof(windowClass));

	windowClass.lpfnWndProc = MsgProc;
    windowClass.lpszClassName = &quot;Main&quot;;

	RegisterClass(&amp;windowClass);

	CreateWindow(&quot;Main&quot;, &quot;Test&quot;, WS_SYSMENU | WS_VISIBLE, 100, 100, 200, 200, 0, 0, 0, 0);

	MSG message = { 0 };

	while(message.message != WM_QUIT)
    {
        if(PeekMessage(&amp;message, 0, 0, 0, PM_REMOVE))
        {
            TranslateMessage(&amp;message); 
            DispatchMessage(&amp;message); 
        }
    }

	UnregisterClass(&quot;Main&quot;, 0);
}

LRESULT WINAPI MsgProc(HWND windowHandle, UINT message, WPARAM wParam, LPARAM lParam) 
{
	switch(message)
	{
	case WM_DESTROY:
		PostQuitMessage(0);
		break;
	default:
		return DefWindowProc(windowHandle, message, wParam, lParam);
	}

	return 0L;
}
</code></pre>
<p>MfG</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1384844</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1384844</guid><dc:creator><![CDATA[ceplusplus@loggedoff]]></dc:creator><pubDate>Sun, 14 Oct 2007 12:23:42 GMT</pubDate></item><item><title><![CDATA[Reply to Kürzester Code zur Fenstererzeugung? on Sun, 14 Oct 2007 13:19:58 GMT]]></title><description><![CDATA[<p>wieso benutzt du bei der WNDCLASS memset, und bei der MSG die {0} initialisation?</p>
<p>das spart 2 zeilen ein!!</p>
<p>Und die auslastung sollte auch auf 100% sein, du musst bei peek message schon ein else einbauen und dort etwas machen(kann auch nur ein sleep sein)</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1384886</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1384886</guid><dc:creator><![CDATA[grerge]]></dc:creator><pubDate>Sun, 14 Oct 2007 13:19:58 GMT</pubDate></item><item><title><![CDATA[Reply to Kürzester Code zur Fenstererzeugung? on Sun, 14 Oct 2007 15:21:21 GMT]]></title><description><![CDATA[<p>1. MSG muss nicht initialisiert werden.<br />
2.</p>
<pre><code class="language-cpp">while(!GetMessage(&amp;message, 0, 0, 0))
{
    TranslateMessage(&amp;message); 
    DispatchMessage(&amp;message); 
}
</code></pre>
<p>Ist noch kürzer und erspart die 100% Prozessorlast!<br />
3. UnregisterClass kannst Du Dir bei Prozessende sparen.<br />
4. Es fehlt ein</p>
<pre><code class="language-cpp">return msg.wParam;
</code></pre>
<p>in WinMain</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1384964</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1384964</guid><dc:creator><![CDATA[Martin Richter]]></dc:creator><pubDate>Sun, 14 Oct 2007 15:21:21 GMT</pubDate></item><item><title><![CDATA[Reply to Kürzester Code zur Fenstererzeugung? on Sun, 14 Oct 2007 15:30:52 GMT]]></title><description><![CDATA[<p>hmm</p>
<pre><code class="language-cpp">#include &lt;windows.h&gt;

LRESULT WINAPI MsgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
	if (message == WM_DESTROY) 
	{ 
        PostQuitMessage(0);
		return S_OK;
	}
	return DefWindowProc(hWnd, msg, wParam, lParam);
} 	

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, LPSTR, int)
{
	::WNDCLASSEX wcex = { 0 };
	wcex.lpfnWndProc = MsgProc;
    wcex.lpszClassName = TEXT(&quot;wnd&quot;);
	if (RegisterClassEx(&amp;wcex) == 0 || CreateWindowEx(0, TEXT(&quot;wnd&quot;), TEXT(&quot;Test&quot;), WS_SYSMENU | WS_VISIBLE, -1, -1, 400, 400, NULL, NULL, hInstance, NULL) == NULL)
		return -1;

	MSG msg;
	while (GetMessage(&amp;msg, NULL, 0, 0) == FALSE)
    {
		TranslateMessage(&amp;msg);
		DispatchMessage(&amp;msg);
    }
}
</code></pre>
<p>solltest schon die Ex-Funktionen nutzen ... und ansonsten sollte nicht viel kürzer gehen ...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1384970</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1384970</guid><dc:creator><![CDATA[*D*Evil]]></dc:creator><pubDate>Sun, 14 Oct 2007 15:30:52 GMT</pubDate></item><item><title><![CDATA[Reply to Kürzester Code zur Fenstererzeugung? on Sun, 14 Oct 2007 16:25:11 GMT]]></title><description><![CDATA[<p>@(D)Evil:<br />
1. Warum sollte man die Ex Funktionen verwenden, wenn man diese nicht benötigt? Sie sind ja nicht deprecated!<br />
2. Warum der return in WM_DESTROY.<br />
3. Warum S_OK, der hat hier gar nichts zu suchen. S_OK ist ein HRESULT returncode bzw. dem Standard Error Handling. Eher müsste hier 1 returniert werden oder irgendwas !=0. S_OK ist 0. Die Doku sagt aber:<br />
If an application processes this message, it should return zero.<br />
Dann kann man aber auch gleich in die DefWindowProc weiterlaufen.<br />
4. Auch bei Dir fehlt ein return aus dem WinMain. Diese Funktion returniert ein int.<br />
5. ==FALSE ist sicher, aber in meinen Augen verwirrend. !GetMessage ist in meinen Augen klarer.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1385009</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1385009</guid><dc:creator><![CDATA[Martin Richter]]></dc:creator><pubDate>Sun, 14 Oct 2007 16:25:11 GMT</pubDate></item><item><title><![CDATA[Reply to Kürzester Code zur Fenstererzeugung? on Sun, 14 Oct 2007 16:50:51 GMT]]></title><description><![CDATA[<p>Meine gelesen zu haben, man solle eher PeekMessage verwenden.<br />
In main() oder WinMain() wird ein return doch impliziert? Ansonsten, wozu? Gibt ja nichtmal ne Warnung wenn ichs weglass.</p>
<p>Und bei while(!GetMessage(&amp;message, 0, 0, 0)) schließt das Programm sofort wieder. Der Negationsoperator muss doch weggelassen werden.</p>
<p>Und... muss man hInstance nun überhaupt verwenden oder kann man es gleich weglassen, sowohl für die windowClass als auch bei CreateWindow?</p>
<p>MfG</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1385039</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1385039</guid><dc:creator><![CDATA[ceplusplus@loggedoff]]></dc:creator><pubDate>Sun, 14 Oct 2007 16:50:51 GMT</pubDate></item><item><title><![CDATA[Reply to Kürzester Code zur Fenstererzeugung? on Sun, 14 Oct 2007 21:05:03 GMT]]></title><description><![CDATA[<p>ceplusplus@loggedoff schrieb:</p>
<blockquote>
<p>Meine gelesen zu haben, man solle eher PeekMessage verwenden.</p>
</blockquote>
<p>Falsch. Das benötigt man nur, wenn man noch anderes zwischen drin braucht!</p>
<p>ceplusplus@loggedoff schrieb:</p>
<blockquote>
<p>In main() oder WinMain() wird ein return doch impliziert? Ansonsten, wozu? Gibt ja nichtmal ne Warnung wenn ichs weglass.</p>
</blockquote>
<p>Ich bekomme sofort eine Compiler Warnung. Implizit ist hier nichts!</p>
<p>ceplusplus@loggedoff schrieb:</p>
<blockquote>
<p>Und bei while(!GetMessage(&amp;message, 0, 0, 0)) schließt das Programm sofort wieder. Der Negationsoperator muss doch weggelassen werden.</p>
</blockquote>
<p>Korrekt. Da habe ich mich vertan. Also wird es noch kürzer.</p>
<p>ceplusplus@loggedoff schrieb:</p>
<blockquote>
<p>Und... muss man hInstance nun überhaupt verwenden oder kann man es gleich weglassen, sowohl für die windowClass als auch bei CreateWindow?</p>
</blockquote>
<p>Müsste IMHO definiert sein. Weil eine Fensterklasse als auch ein Fenster mit einem Modul zusammen definiert wird. Ist aber evtl. auch ein Relikt aus alten 16bit Zeiten. Da weder ein Menu noch sonstige Ressourcen im Spiel sind, würde ich sagen es geht auch ohne hInstance, aber gemäß Doku (wenn man es richtig machen will) müsste man hInstance schon setzen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1385197</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1385197</guid><dc:creator><![CDATA[Martin Richter]]></dc:creator><pubDate>Sun, 14 Oct 2007 21:05:03 GMT</pubDate></item></channel></rss>