<?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[WM_SIZE wird vor WM_CREATE aufgerufen?]]></title><description><![CDATA[<p>Ich verfolge die Tutorials hier: <a href="http://www.relisoft.com/win32/generic.html" rel="nofollow">http://www.relisoft.com/win32/generic.html</a><br />
Das Programm soll nach dem MVC - Prinzip funktionieren.<br />
In dem Beispiel werden controller und auch model und view im WndProc im WM_CREATE generiert.<br />
Ich würde gerne ganz früher im Programm diese Objekte erstellen. Deshalb dachte ich mir die LPARAM-Methode zu benutzen. Leider scheint WM_CREATE nicht die erste Message sein, denn WM_SIZE funzt nicht korrekt.</p>
<pre><code class="language-cpp">template &lt;class T&gt;
inline T get_data(HWND hwnd, int what = GWL_USERDATA)
{
	return reinterpret_cast&lt;T&gt; (GetWindowLong (hwnd, what));
}

template &lt;class T&gt;
inline void set_data(HWND hwnd, T value, int what = GWL_USERDATA)
{
	SetWindowLong(hwnd, what, reinterpret_cast&lt;long&gt; (value));
}

void save_controller(HWND h, LPARAM p)
{
	CREATESTRUCT* pcs = reinterpret_cast&lt;CREATESTRUCT*&gt;(p);
	void* d = pcs-&gt;lpCreateParams;
	controller* pc = reinterpret_cast&lt;controller*&gt;(d);
	pc-&gt;set_hwnd(h);
	set_data(h, pc);
}

LRESULT CALLBACK wndproc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
{
	controller* pc = get_data&lt;controller*&gt;(hwnd);

	switch (msg)
	{

	case WM_CREATE:
		save_controller(hwnd, lparam);
		return 0;

	case WM_SIZE:
		// hier ist pc nicht gültig!?
		return 0;

	case WM_DESTROY:
		set_data&lt;controller*&gt;(hwnd, 0);
		delete pc;
		return 0;
	}

	return DefWindowProc(hwnd, msg, wparam, lparam);
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/topic/195771/wm_size-wird-vor-wm_create-aufgerufen</link><generator>RSS for Node</generator><lastBuildDate>Wed, 29 Apr 2026 03:56:42 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/195771.rss" rel="self" type="application/rss+xml"/><pubDate>Sun, 21 Oct 2007 18:54:49 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to WM_SIZE wird vor WM_CREATE aufgerufen? on Sun, 21 Oct 2007 18:54:49 GMT]]></title><description><![CDATA[<p>Ich verfolge die Tutorials hier: <a href="http://www.relisoft.com/win32/generic.html" rel="nofollow">http://www.relisoft.com/win32/generic.html</a><br />
Das Programm soll nach dem MVC - Prinzip funktionieren.<br />
In dem Beispiel werden controller und auch model und view im WndProc im WM_CREATE generiert.<br />
Ich würde gerne ganz früher im Programm diese Objekte erstellen. Deshalb dachte ich mir die LPARAM-Methode zu benutzen. Leider scheint WM_CREATE nicht die erste Message sein, denn WM_SIZE funzt nicht korrekt.</p>
<pre><code class="language-cpp">template &lt;class T&gt;
inline T get_data(HWND hwnd, int what = GWL_USERDATA)
{
	return reinterpret_cast&lt;T&gt; (GetWindowLong (hwnd, what));
}

template &lt;class T&gt;
inline void set_data(HWND hwnd, T value, int what = GWL_USERDATA)
{
	SetWindowLong(hwnd, what, reinterpret_cast&lt;long&gt; (value));
}

void save_controller(HWND h, LPARAM p)
{
	CREATESTRUCT* pcs = reinterpret_cast&lt;CREATESTRUCT*&gt;(p);
	void* d = pcs-&gt;lpCreateParams;
	controller* pc = reinterpret_cast&lt;controller*&gt;(d);
	pc-&gt;set_hwnd(h);
	set_data(h, pc);
}

LRESULT CALLBACK wndproc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
{
	controller* pc = get_data&lt;controller*&gt;(hwnd);

	switch (msg)
	{

	case WM_CREATE:
		save_controller(hwnd, lparam);
		return 0;

	case WM_SIZE:
		// hier ist pc nicht gültig!?
		return 0;

	case WM_DESTROY:
		set_data&lt;controller*&gt;(hwnd, 0);
		delete pc;
		return 0;
	}

	return DefWindowProc(hwnd, msg, wparam, lparam);
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1389531</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1389531</guid><dc:creator><![CDATA[khalderon]]></dc:creator><pubDate>Sun, 21 Oct 2007 18:54:49 GMT</pubDate></item><item><title><![CDATA[Reply to WM_SIZE wird vor WM_CREATE aufgerufen? on Sun, 21 Oct 2007 19:15:45 GMT]]></title><description><![CDATA[<p>wie wärs mit static ...</p>
<p>schirrmie</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1389553</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1389553</guid><dc:creator><![CDATA[schirrmie]]></dc:creator><pubDate>Sun, 21 Oct 2007 19:15:45 GMT</pubDate></item><item><title><![CDATA[Reply to WM_SIZE wird vor WM_CREATE aufgerufen? on Sun, 21 Oct 2007 19:27:58 GMT]]></title><description><![CDATA[<p>static sollte keinen großen Einfluß dabei haben. Wenn WM_CREATE erstens aufgerufen wird, wird den controller-Zeiger vom lparam entnommen und direkt in die Fensterstruktur mittels set_data gespeichert. Dann sollte alles ok sein, oder denke ich falsch?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1389561</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1389561</guid><dc:creator><![CDATA[khalderon]]></dc:creator><pubDate>Sun, 21 Oct 2007 19:27:58 GMT</pubDate></item><item><title><![CDATA[Reply to WM_SIZE wird vor WM_CREATE aufgerufen? on Sun, 21 Oct 2007 20:15:26 GMT]]></title><description><![CDATA[<p>yop WM_CREATE muss ned die erste Message sein, die ein Fenster bekommt.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1389610</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1389610</guid><dc:creator><![CDATA[tenchou]]></dc:creator><pubDate>Sun, 21 Oct 2007 20:15:26 GMT</pubDate></item><item><title><![CDATA[Reply to WM_SIZE wird vor WM_CREATE aufgerufen? on Sun, 21 Oct 2007 20:18:27 GMT]]></title><description><![CDATA[<p>Hmm. Eine Ahnung wie man das überwinden kann?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1389614</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1389614</guid><dc:creator><![CDATA[khalderon]]></dc:creator><pubDate>Sun, 21 Oct 2007 20:18:27 GMT</pubDate></item><item><title><![CDATA[Reply to WM_SIZE wird vor WM_CREATE aufgerufen? on Sun, 21 Oct 2007 21:09:05 GMT]]></title><description><![CDATA[<p>Zdravko schrieb:</p>
<blockquote>
<p>static sollte keinen großen Einfluß dabei haben. Wenn WM_CREATE erstens aufgerufen wird, wird den controller-Zeiger vom lparam entnommen und direkt in die Fensterstruktur mittels set_data gespeichert. Dann sollte alles ok sein, oder denke ich falsch?</p>
</blockquote>
<p>Also so wie ich das sehe schon wieso probierst du es nicht einfach mal aus <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/1389656</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1389656</guid><dc:creator><![CDATA[schirrmie]]></dc:creator><pubDate>Sun, 21 Oct 2007 21:09:05 GMT</pubDate></item><item><title><![CDATA[Reply to WM_SIZE wird vor WM_CREATE aufgerufen? on Mon, 22 Oct 2007 06:06:33 GMT]]></title><description><![CDATA[<p>WM_SIZE und WM_GETMINMAXINFO werden zum Teil vor WM_CREATE gesendet.</p>
<p>Ignoriere einfach alle Nachrichten bei denen Dein Datenzeige noch NULL ist und leite sie an DefWindowProc weiter. Alles vor WM_CREATE ist erstmal uninteressant für Dich!<br />
In WM_CREATE wird der Datenzeiger ja gesetzt. Später wird WM_SIZE noch einmal gesendet...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1389708</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1389708</guid><dc:creator><![CDATA[Martin Richter]]></dc:creator><pubDate>Mon, 22 Oct 2007 06:06:33 GMT</pubDate></item><item><title><![CDATA[Reply to WM_SIZE wird vor WM_CREATE aufgerufen? on Mon, 22 Oct 2007 06:09:47 GMT]]></title><description><![CDATA[<p>Martin Richter, vielen Dank!</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1389710</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1389710</guid><dc:creator><![CDATA[khalderon]]></dc:creator><pubDate>Mon, 22 Oct 2007 06:09:47 GMT</pubDate></item><item><title><![CDATA[Reply to WM_SIZE wird vor WM_CREATE aufgerufen? on Mon, 22 Oct 2007 08:24:25 GMT]]></title><description><![CDATA[<p>Nee, das funzt wieder nicht.<br />
Es scheint zu sein, dass:</p>
<pre><code class="language-cpp">controller* pc = get_data&lt;controller*&gt;(hwnd);
</code></pre>
<p>nicht 0 zurückgibt. Kann man es im Voraus auf 0 setzen?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1389757</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1389757</guid><dc:creator><![CDATA[khalderon]]></dc:creator><pubDate>Mon, 22 Oct 2007 08:24:25 GMT</pubDate></item><item><title><![CDATA[Reply to WM_SIZE wird vor WM_CREATE aufgerufen? on Mon, 22 Oct 2007 08:52:12 GMT]]></title><description><![CDATA[<p>Kann nicht sein:</p>
<p>Siehe Doku zu GetWindowLong:</p>
<blockquote>
<p>If the function succeeds, the return value is the requested 32-bit value.</p>
<p>If the function fails, the return value is zero. To get extended error information, call GetLastError.</p>
<p>If SetWindowLong has not been called previously, GetWindowLong returns zero for values in the extra window or class memory.</p>
</blockquote>
]]></description><link>https://www.c-plusplus.net/forum/post/1389772</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1389772</guid><dc:creator><![CDATA[Martin Richter]]></dc:creator><pubDate>Mon, 22 Oct 2007 08:52:12 GMT</pubDate></item><item><title><![CDATA[Reply to WM_SIZE wird vor WM_CREATE aufgerufen? on Mon, 22 Oct 2007 08:59:05 GMT]]></title><description><![CDATA[<p>Kann es sein, dass die WNDCLASS Struktur oder CreateWindow nicht korrekt initializiert werden?</p>
<pre><code class="language-cpp">wc_.cbClsExtra = 0;
wc_.cbWndExtra = 0;
</code></pre>
<pre><code class="language-cpp">hwnd_ = CreateWindow(
		classname_,
		windowname_,
		style_,
		x_, y_, w_, h_,
		hparent_,
		hmenu_,
		hInstance,
		new controller());
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1389777</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1389777</guid><dc:creator><![CDATA[khalderon]]></dc:creator><pubDate>Mon, 22 Oct 2007 08:59:05 GMT</pubDate></item><item><title><![CDATA[Reply to WM_SIZE wird vor WM_CREATE aufgerufen? on Mon, 22 Oct 2007 10:02:01 GMT]]></title><description><![CDATA[<p>Hat damit nichts zu tun.<br />
1. Dein Fenster wir dja erzegt, Du bekommst ja Nachrichten.<br />
2. GWL_USERDATA ist immer vorhanden.</p>
<p>Laut Doku: Selbst wenn es einen Fehler gibt müsstest Du NULL bekommen!</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1389823</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1389823</guid><dc:creator><![CDATA[Martin Richter]]></dc:creator><pubDate>Mon, 22 Oct 2007 10:02:01 GMT</pubDate></item><item><title><![CDATA[Reply to WM_SIZE wird vor WM_CREATE aufgerufen? on Mon, 22 Oct 2007 14:40:49 GMT]]></title><description><![CDATA[<p>Kann das Problem sein, dass die controller Methoden virtual sind?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1390031</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1390031</guid><dc:creator><![CDATA[khalderon]]></dc:creator><pubDate>Mon, 22 Oct 2007 14:40:49 GMT</pubDate></item><item><title><![CDATA[Reply to WM_SIZE wird vor WM_CREATE aufgerufen? on Mon, 22 Oct 2007 15:16:35 GMT]]></title><description><![CDATA[<p>Also das Problem ist irgendwo hier:</p>
<pre><code class="language-cpp">case WM_SIZE:
		if (pc)
			pc-&gt;resize(0, 0);
		return 0;
</code></pre>
<p>Die Fehlermeldung ist:</p>
<blockquote>
<p>First-chance exception at 0x00000000 in generic2.exe: 0xC0000005: Access violation reading location 0x00000000.<br />
Unhandled exception at 0x00000000 in generic2.exe: 0xC0000005: Access violation reading location 0x00000000.</p>
</blockquote>
<p>Das Objekt controller sieht so aus:</p>
<pre><code class="language-cpp">class controller
	{
		HWND hwnd_;
	public:
		controller();
		virtual ~controller();

		virtual void command(UINT what) {}
		virtual void resize(int new_x, int new_y) {}
		virtual void paint() {}

		void set_hwnd(HWND h)
		{
			hwnd_ = h;
		}

controller::controller()
:hwnd_(0)
{
}

controller::~controller()
{
	PostQuitMessage(0);
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1390052</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1390052</guid><dc:creator><![CDATA[khalderon]]></dc:creator><pubDate>Mon, 22 Oct 2007 15:16:35 GMT</pubDate></item><item><title><![CDATA[Reply to WM_SIZE wird vor WM_CREATE aufgerufen? on Mon, 22 Oct 2007 15:57:22 GMT]]></title><description><![CDATA[<p>Zeig mal wie Du Dein Fenster erzeugst!</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1390075</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1390075</guid><dc:creator><![CDATA[Martin Richter]]></dc:creator><pubDate>Mon, 22 Oct 2007 15:57:22 GMT</pubDate></item><item><title><![CDATA[Reply to WM_SIZE wird vor WM_CREATE aufgerufen? on Mon, 22 Oct 2007 16:01:21 GMT]]></title><description><![CDATA[<p>Zdravko schrieb:</p>
<blockquote>
<pre><code class="language-cpp">hwnd_ = CreateWindow(
		classname_,
		windowname_,
		style_,
		x_, y_, w_, h_,
		hparent_,
		hmenu_,
		hInstance,
		new controller());
</code></pre>
</blockquote>
<p>Reicht das, oder soll ich das ganzes hier posten?<br />
Das Fenster wird richtig gezeigt. Aber gleichzeitig kriege ich diese seltsame Fehlermeldung...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1390077</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1390077</guid><dc:creator><![CDATA[khalderon]]></dc:creator><pubDate>Mon, 22 Oct 2007 16:01:21 GMT</pubDate></item><item><title><![CDATA[Reply to WM_SIZE wird vor WM_CREATE aufgerufen? on Tue, 23 Oct 2007 06:07:19 GMT]]></title><description><![CDATA[<p>Also so kann ich jetzt auf Anhieb kein Problem sehen.<br />
Wird denn der Zeiger korrekt gesetzt? Hast Du Den Wert nach WM_CREATE mal geprüft, as Du eingetragen hast?<br />
Hast Du ein kleines Demo, das Du mir senden kannst?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1390301</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1390301</guid><dc:creator><![CDATA[Martin Richter]]></dc:creator><pubDate>Tue, 23 Oct 2007 06:07:19 GMT</pubDate></item><item><title><![CDATA[Reply to WM_SIZE wird vor WM_CREATE aufgerufen? on Tue, 23 Oct 2007 08:49:31 GMT]]></title><description><![CDATA[<p>Ich habe das ganze Projekt neu rebuilt und auf ein mal ist alles ok gegangen!<br />
Vielen Dank!</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1390393</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1390393</guid><dc:creator><![CDATA[khalderon]]></dc:creator><pubDate>Tue, 23 Oct 2007 08:49:31 GMT</pubDate></item></channel></rss>