<?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[WndProc in Klasse, ShowWindow stürzt ab]]></title><description><![CDATA[<p>Wenn ich folgenden Code ausführe, blitzt kurz das Fenster auf, danach wird das Programm beendet.</p>
<p>Anhand der Ausgabe habe ich herausgefunden das ShowWindow abstürzt, allerdings warum?</p>
<pre><code>Nachricht: 1 (WM_CREATE)
Vor ShowWindow
Nachricht: 24 (WM_SHOWWINDOW)
Nachricht: 70 (WM_WINDOWPOSCHANGING)
</code></pre>
<p>Die betreffenden Teile im Code der Fenster Klasse sehen so aus:</p>
<pre><code class="language-cpp">class Window
{
private:
	HDC deviceContext_;
	HWND windowHandle_;
	HINSTANCE windowInstance_;

public:
	// ...

	static LRESULT CALLBACK CallbackProxy(HWND, unsigned int, WPARAM, LPARAM);
	LRESULT Callback(HWND, unsigned int, WPARAM, LPARAM);
};
</code></pre>
<pre><code class="language-cpp">LRESULT CALLBACK Window::CallbackProxy(HWND windowHandle, unsigned int message, WPARAM wParam, LPARAM lParam)
{
	Window *instance = (Window*)GetWindowLong(windowHandle, GWL_USERDATA);

	if (message == WM_CREATE)
	{
		instance = (Window*)((CREATESTRUCT*)lParam)-&gt;lpCreateParams;
		SetWindowLong(windowHandle, GWL_USERDATA, (long) instance);
	}

	if (instance == 0)
	{
		return DefWindowProc(windowHandle, message, wParam, lParam);
	}

	return instance-&gt;Callback(windowHandle, message, wParam, lParam);
}

LRESULT Window::Callback(HWND windowHandle, unsigned int message, WPARAM wParam, LPARAM lParam)
{
	cerr &lt;&lt; &quot;Nachricht:&quot; &lt;&lt; message &lt;&lt; endl;

	// ...
}
</code></pre>
<pre><code class="language-cpp">windowClass.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
windowClass.lpfnWndProc = (WNDPROC) Window::CallbackProxy;
windowClass.cbClsExtra = 0;
windowClass.cbWndExtra = 0;
windowClass.hInstance = windowInstance_;
windowClass.hIcon = LoadIcon(0, IDI_WINLOGO);
windowClass.hCursor = LoadCursor(0, IDC_ARROW);
windowClass.hbrBackground = 0;
windowClass.lpszMenuName = 0;
windowClass.lpszClassName = &quot;testklasse&quot;;
</code></pre>
<pre><code class="language-cpp">windowRect.left = posX_;
windowRect.top = posY_;
windowRect.right = width_;
windowRect.bottom = height_;

AdjustWindowRectEx(&amp;windowRect, WS_OVERLAPPEDWINDOW, false, WS_EX_APPWINDOW);

windowHandle_ = CreateWindowEx(WS_EX_APPWINDOW, &quot;testklasse&quot;, &quot;Test Fenster&quot;,
		WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_OVERLAPPEDWINDOW,
		windowRect.left, windowRect.top,
		windowRect.right - windowRect.left,
		windowRect.bottom - windowRect.top,
		0, 0, windowInstance_, this);
</code></pre>
<pre><code class="language-cpp">cerr &lt;&lt; &quot;Vor ShowWindow&quot; &lt;&lt; endl;
ShowWindow(windowHandle_, SW_SHOW);
cerr &lt;&lt; &quot;Nach ShowWindow&quot; &lt;&lt; endl;
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/topic/100694/wndproc-in-klasse-showwindow-stürzt-ab</link><generator>RSS for Node</generator><lastBuildDate>Tue, 28 Apr 2026 17:50:08 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/100694.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 09 Feb 2005 14:36:41 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to WndProc in Klasse, ShowWindow stürzt ab on Wed, 09 Feb 2005 14:36:41 GMT]]></title><description><![CDATA[<p>Wenn ich folgenden Code ausführe, blitzt kurz das Fenster auf, danach wird das Programm beendet.</p>
<p>Anhand der Ausgabe habe ich herausgefunden das ShowWindow abstürzt, allerdings warum?</p>
<pre><code>Nachricht: 1 (WM_CREATE)
Vor ShowWindow
Nachricht: 24 (WM_SHOWWINDOW)
Nachricht: 70 (WM_WINDOWPOSCHANGING)
</code></pre>
<p>Die betreffenden Teile im Code der Fenster Klasse sehen so aus:</p>
<pre><code class="language-cpp">class Window
{
private:
	HDC deviceContext_;
	HWND windowHandle_;
	HINSTANCE windowInstance_;

public:
	// ...

	static LRESULT CALLBACK CallbackProxy(HWND, unsigned int, WPARAM, LPARAM);
	LRESULT Callback(HWND, unsigned int, WPARAM, LPARAM);
};
</code></pre>
<pre><code class="language-cpp">LRESULT CALLBACK Window::CallbackProxy(HWND windowHandle, unsigned int message, WPARAM wParam, LPARAM lParam)
{
	Window *instance = (Window*)GetWindowLong(windowHandle, GWL_USERDATA);

	if (message == WM_CREATE)
	{
		instance = (Window*)((CREATESTRUCT*)lParam)-&gt;lpCreateParams;
		SetWindowLong(windowHandle, GWL_USERDATA, (long) instance);
	}

	if (instance == 0)
	{
		return DefWindowProc(windowHandle, message, wParam, lParam);
	}

	return instance-&gt;Callback(windowHandle, message, wParam, lParam);
}

LRESULT Window::Callback(HWND windowHandle, unsigned int message, WPARAM wParam, LPARAM lParam)
{
	cerr &lt;&lt; &quot;Nachricht:&quot; &lt;&lt; message &lt;&lt; endl;

	// ...
}
</code></pre>
<pre><code class="language-cpp">windowClass.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
windowClass.lpfnWndProc = (WNDPROC) Window::CallbackProxy;
windowClass.cbClsExtra = 0;
windowClass.cbWndExtra = 0;
windowClass.hInstance = windowInstance_;
windowClass.hIcon = LoadIcon(0, IDI_WINLOGO);
windowClass.hCursor = LoadCursor(0, IDC_ARROW);
windowClass.hbrBackground = 0;
windowClass.lpszMenuName = 0;
windowClass.lpszClassName = &quot;testklasse&quot;;
</code></pre>
<pre><code class="language-cpp">windowRect.left = posX_;
windowRect.top = posY_;
windowRect.right = width_;
windowRect.bottom = height_;

AdjustWindowRectEx(&amp;windowRect, WS_OVERLAPPEDWINDOW, false, WS_EX_APPWINDOW);

windowHandle_ = CreateWindowEx(WS_EX_APPWINDOW, &quot;testklasse&quot;, &quot;Test Fenster&quot;,
		WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_OVERLAPPEDWINDOW,
		windowRect.left, windowRect.top,
		windowRect.right - windowRect.left,
		windowRect.bottom - windowRect.top,
		0, 0, windowInstance_, this);
</code></pre>
<pre><code class="language-cpp">cerr &lt;&lt; &quot;Vor ShowWindow&quot; &lt;&lt; endl;
ShowWindow(windowHandle_, SW_SHOW);
cerr &lt;&lt; &quot;Nach ShowWindow&quot; &lt;&lt; endl;
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/718720</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/718720</guid><dc:creator><![CDATA[.Callback]]></dc:creator><pubDate>Wed, 09 Feb 2005 14:36:41 GMT</pubDate></item><item><title><![CDATA[Reply to WndProc in Klasse, ShowWindow stürzt ab on Wed, 09 Feb 2005 16:58:47 GMT]]></title><description><![CDATA[<p>Was sagt denn der Debugger ?! <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f644.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--face_with_rolling_eyes"
      title=":rolling_eyes:"
      alt="🙄"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/718880</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/718880</guid><dc:creator><![CDATA[flenders]]></dc:creator><pubDate>Wed, 09 Feb 2005 16:58:47 GMT</pubDate></item><item><title><![CDATA[Reply to WndProc in Klasse, ShowWindow stürzt ab on Wed, 09 Feb 2005 17:03:31 GMT]]></title><description><![CDATA[<p>Debugger ist keiner vorhanden weil ich das Visual C++ 2003 Toolkit verwende <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>
]]></description><link>https://www.c-plusplus.net/forum/post/718884</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/718884</guid><dc:creator><![CDATA[.Callback]]></dc:creator><pubDate>Wed, 09 Feb 2005 17:03:31 GMT</pubDate></item><item><title><![CDATA[Reply to WndProc in Klasse, ShowWindow stürzt ab on Wed, 09 Feb 2005 17:15:59 GMT]]></title><description><![CDATA[<p>Dann lad Dir doch einen runter:<br />
<a href="http://www.microsoft.com/whdc/devtools/debugging/default.mspx" rel="nofollow">Microsoft Debugging Tools for Windows</a></p>
]]></description><link>https://www.c-plusplus.net/forum/post/718899</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/718899</guid><dc:creator><![CDATA[Hepi]]></dc:creator><pubDate>Wed, 09 Feb 2005 17:15:59 GMT</pubDate></item><item><title><![CDATA[Reply to WndProc in Klasse, ShowWindow stürzt ab on Thu, 10 Feb 2005 12:23:21 GMT]]></title><description><![CDATA[<p>nehme nicht CREATESTRUCT für den this Pointer, ich hatte damit auch Probleme, ich hatte das so (unelegant) gelöst, in dem ich den this wert als string in classname schrieb und in der WndProc ausgelesen und zu einem long wert rückgewandelt hatte, hatte auch den Vorteil das ich immer andere classnamen hatte bei mehren Fenstern.</p>
<pre><code class="language-cpp">char szClassname[24];
sprintf(szClassname,&quot;%i&quot;,long(this));
//...
RegisterClassEx(...
//...in WndProc ...
long Pointer;
char t[24];
GetClassName(hwnd,t,24);
sscanf(t,&quot;%i&quot;,&amp;Pointer);
//...etc.
</code></pre>
<p>für Controls kannste den this bei Menu speichern, da es da nicht benutzt wird.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/719587</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/719587</guid><dc:creator><![CDATA[MiC++ha]]></dc:creator><pubDate>Thu, 10 Feb 2005 12:23:21 GMT</pubDate></item><item><title><![CDATA[Reply to WndProc in Klasse, ShowWindow stürzt ab on Thu, 10 Feb 2005 12:41:56 GMT]]></title><description><![CDATA[<p>MiC++ha schrieb:</p>
<blockquote>
<p>nehme nicht CREATESTRUCT für den this Pointer, ich hatte damit auch Probleme, ich hatte das so (unelegant) gelöst, in dem ich den this wert als string in classname schrieb und in der WndProc ausgelesen und zu einem long wert rückgewandelt hatte, hatte auch den Vorteil das ich immer andere classnamen hatte bei mehren Fenstern.</p>
</blockquote>
<p>auch ein übeler häck <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>was spricht eigentlich dagegen nach dem erstellen des fensters<br />
den this pointer an das fenster du binden (SetWindowLong(..))<br />
und in der statischen wndproc einfach sich wieder den pointer holen.<br />
habe schon öfter diese art der lösung gesehen und benutze sie auch selber.</p>
<p>[offtopic]<br />
wieder reg. fertig mit deinem projekt?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/719618</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/719618</guid><dc:creator><![CDATA[miller_m]]></dc:creator><pubDate>Thu, 10 Feb 2005 12:41:56 GMT</pubDate></item><item><title><![CDATA[Reply to WndProc in Klasse, ShowWindow stürzt ab on Thu, 10 Feb 2005 12:48:58 GMT]]></title><description><![CDATA[<p>miller_m schrieb:</p>
<blockquote>
<p>was spricht eigentlich dagegen nach dem erstellen des fensters<br />
den this pointer an das fenster du binden (SetWindowLong(..))<br />
und in der statischen wndproc einfach sich wieder den pointer holen.<br />
habe schon öfter diese art der lösung gesehen und benutze sie auch selber.</p>
</blockquote>
<p>Es spricht dagegen, wenn man WM_CREATE bearbeitet, den das wird gesendet bei CreateWindow..., und da ist noch kein Zeiger in GWL_USERDATA <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>
<p>Er benutzt USERDATA ja auch, aber erst nach dem das Fenster erstellt ist, bis dahin verwendet er CREATESTRUCT und das ist nichts gut.</p>
<p>&lt;OT&gt; Jo, ich bin fertig, zum glück &lt;/OT&gt;</p>
]]></description><link>https://www.c-plusplus.net/forum/post/719628</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/719628</guid><dc:creator><![CDATA[MiC++ha]]></dc:creator><pubDate>Thu, 10 Feb 2005 12:48:58 GMT</pubDate></item><item><title><![CDATA[Reply to WndProc in Klasse, ShowWindow stürzt ab on Thu, 10 Feb 2005 12:58:32 GMT]]></title><description><![CDATA[<p>MiC++ha schrieb:</p>
<blockquote>
<p>Es spricht dagegen, wenn man WM_CREATE bearbeitet, den das wird gesendet bei CreateWindow..., und da ist noch kein Zeiger in GWL_USERDATA <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>
</blockquote>
<p>schon klar, deswegen returne ich wm_create einfach und erstelle die childs (unüberlicher weise) an anderer stelle.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/719642</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/719642</guid><dc:creator><![CDATA[miller_m]]></dc:creator><pubDate>Thu, 10 Feb 2005 12:58:32 GMT</pubDate></item><item><title><![CDATA[Reply to WndProc in Klasse, ShowWindow stürzt ab on Thu, 10 Feb 2005 13:48:30 GMT]]></title><description><![CDATA[<p>MiC++ha schrieb:</p>
<blockquote>
<p>nehme nicht CREATESTRUCT für den this Pointer, ich hatte damit auch Probleme</p>
</blockquote>
<p>Schwachsinn, warum sollte das nicht gehen, da hast du nen Fehler gemacht.</p>
<p>Bei .Callback wird der Zeiger ausserdem richtig gesetzt, sonst würde er doch nicht die beiden Nachrichten anzeigen, sondern schon vorher abstürtzen.</p>
<p>@.Callback: Zeig doch mal deine ganze Window::Callback Methode, da müsste der Fehler sein.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/719708</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/719708</guid><dc:creator><![CDATA[D*niel *chumann]]></dc:creator><pubDate>Thu, 10 Feb 2005 13:48:30 GMT</pubDate></item><item><title><![CDATA[Reply to WndProc in Klasse, ShowWindow stürzt ab on Thu, 10 Feb 2005 14:19:31 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">LRESULT Window::Callback(HWND windowHandle, unsigned int message, WPARAM wParam, LPARAM lParam)
{
	switch (message)
	{
	case WM_ACTIVATE:
		if (!HIWORD(wParam))
		{
			active_ = true;
		}
		else
		{
			active_ = false;
		}

		return 0;

	case WM_KEYDOWN:
	case WM_CLOSE:
		PostQuitMessage(0);
		return 0;
	}

	return DefWindowProc(windowHandle, message, wParam, lParam);
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/719755</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/719755</guid><dc:creator><![CDATA[.Callback]]></dc:creator><pubDate>Thu, 10 Feb 2005 14:19:31 GMT</pubDate></item><item><title><![CDATA[Reply to WndProc in Klasse, ShowWindow stürzt ab on Thu, 10 Feb 2005 17:05:57 GMT]]></title><description><![CDATA[<p>D@niel $chumann schrieb:</p>
<blockquote>
<p>MiC++ha schrieb:</p>
<blockquote>
<p>nehme nicht CREATESTRUCT für den this Pointer, ich hatte damit auch Probleme</p>
</blockquote>
<p>Schwachsinn, warum sollte das nicht gehen, da hast du nen Fehler gemacht.</p>
<p>Bei .Callback wird der Zeiger ausserdem richtig gesetzt, sonst würde er doch nicht die beiden Nachrichten anzeigen, sondern schon vorher abstürtzen.</p>
</blockquote>
<p>Ich hatte nicht gesagt das es nicht geht, ich sagte das Probleme auftauchten</p>
]]></description><link>https://www.c-plusplus.net/forum/post/719921</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/719921</guid><dc:creator><![CDATA[MiC++ha]]></dc:creator><pubDate>Thu, 10 Feb 2005 17:05:57 GMT</pubDate></item></channel></rss>