<?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[Pointer auf WndProc]]></title><description><![CDATA[<p>Ich versuche gerade, zu Übungszwecken (Methoden, Objekte und deren Freunde sind mir nicht so nahe...), die WinAPI-Funktionen in Klassen &quot;abzufüllen&quot;. <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>
<p>Ich habe nun aber ein kleines Problem geortet, das ich bisher nicht lösen konnte:</p>
<p>Normalerweise gehört zu einem Fenster ja auch eine entsprechende Nachrichten-Funktion (WndProc). Bei der Registrierung der Fensterklasse wird diese Funktion in wc.lpfnWndProc mit einer Referenz definiert.</p>
<pre><code class="language-cpp">wclpfnWndProc=WndProc;
</code></pre>
<p>Nun ist bei mir diese Funktion in der selben Klasse enthalten wie auch die Funktion welche das Fenster registriert. Ich muss also einen Pointer auf diese Methode(WndProc) der Klasse(CFenster) angeben.<br />
Ich dachte das ginge so:</p>
<pre><code class="language-cpp">wWndclass.lpfnWndProc=(WNDPROC)(&amp;CFenster::WndProc);
</code></pre>
<p>Leider läuft diese Tour aber nicht, was mache ich falsch?</p>
<p><strong>fenster.h:</strong></p>
<pre><code class="language-cpp">// * fenster.h * //

#ifndef _WINDOWS_
	#include &lt;windows.h&gt;
#endif

class CFenster
{
public:
	bool bAborted;
	HWND hHandle;
	MSG mMsg;
	WNDCLASS wWndclass;
	struct{int iX;int iY;}sDimension,sPosition;

	//Konstruktor
	CMJ_Fenster(void)
	{
		this-&gt;sDimension.iX=100;
		this-&gt;sDimension.iY=100;
		this-&gt;sPosition.iX=0;
		this-&gt;sPosition.iY=0;
		this-&gt;bAborted=false;
	}

	LRESULT CALLBACK WndProc(HWND hWnd,UINT message,WPARAM wParam,LPARAM lParam)
	{
		switch(message)
		{
			case WM_DESTROY : PostQuitMessage(0); this-&gt;Aborted=true; return 0;

		}

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

	void FensterErstellen(void)
	{

		wWndclass.style		= CS_HREDRAW|CS_VREDRAW;
		wWndclass.lpfnWndProc	= (WNDPROC)(&amp;CFenster::WndProc);
		wWndclass.cbClsExtra	= 0;
		wWndclass.cbWndExtra	= 0;
		wWndclass.hInstance	= 0;
		wWndclass.hCursor	= LoadCursor(NULL,IDC_ARROW);
		wWndclass.hIcon		= LoadIcon(NULL,IDI_APPLICATION);
		wWndclass.hbrBackground	= (HBRUSH)GetStockObject(WHITE_BRUSH);
		wWndclass.lpszClassName	= TEXT(&quot;Testprogramm&quot;);
		wWndclass.lpszMenuName	= NULL;
		RegisterClass(&amp;wWndclass);

		hHandle=CreateWindow(	TEXT(&quot;Testprogramm&quot;),
					TEXT(&quot;Testprogramm&quot;),
					WS_OVERLAPPEDWINDOW,
					CW_USEDEFAULT,
					CW_USEDEFAULT,
					CW_USEDEFAULT,
					CW_USEDEFAULT,
					NULL,
					NULL,
					0,
					NULL);

		ShowWindow(this-&gt;hHandle,SW_SHOWNORMAL);
		UpdateWindow(this-&gt;hHandle);
	}
};
</code></pre>
<p><strong>main.cpp:</strong></p>
<pre><code class="language-cpp">#include &quot;fenster.h&quot;

int main(void)
{
	CFenster Fenster1,Fenster2;

	Fenster1.FensterErstellen();
	Fenster2.FensterErstellen();

	while(GetMessage(&amp;Fenster1.mMsg,NULL,0,0)||GetMessage(&amp;Fenster2.mMsg,NULL,0,0))
	{
		TranslateMessage(&amp;Fenster1.mMsg);
		DispatchMessage(&amp;Fenster1.mMsg);
		TranslateMessage(&amp;Fenster2.mMsg);
		DispatchMessage(&amp;Fenster2.mMsg);

		if(Fenster1.bAborted==true&amp;&amp;Fenster2.bAborted==true)
			break;
	}
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/topic/201603/pointer-auf-wndproc</link><generator>RSS for Node</generator><lastBuildDate>Tue, 28 Apr 2026 05:33:20 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/201603.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 01 Jan 2008 23:26:13 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Pointer auf WndProc on Tue, 01 Jan 2008 23:26:13 GMT]]></title><description><![CDATA[<p>Ich versuche gerade, zu Übungszwecken (Methoden, Objekte und deren Freunde sind mir nicht so nahe...), die WinAPI-Funktionen in Klassen &quot;abzufüllen&quot;. <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>
<p>Ich habe nun aber ein kleines Problem geortet, das ich bisher nicht lösen konnte:</p>
<p>Normalerweise gehört zu einem Fenster ja auch eine entsprechende Nachrichten-Funktion (WndProc). Bei der Registrierung der Fensterklasse wird diese Funktion in wc.lpfnWndProc mit einer Referenz definiert.</p>
<pre><code class="language-cpp">wclpfnWndProc=WndProc;
</code></pre>
<p>Nun ist bei mir diese Funktion in der selben Klasse enthalten wie auch die Funktion welche das Fenster registriert. Ich muss also einen Pointer auf diese Methode(WndProc) der Klasse(CFenster) angeben.<br />
Ich dachte das ginge so:</p>
<pre><code class="language-cpp">wWndclass.lpfnWndProc=(WNDPROC)(&amp;CFenster::WndProc);
</code></pre>
<p>Leider läuft diese Tour aber nicht, was mache ich falsch?</p>
<p><strong>fenster.h:</strong></p>
<pre><code class="language-cpp">// * fenster.h * //

#ifndef _WINDOWS_
	#include &lt;windows.h&gt;
#endif

class CFenster
{
public:
	bool bAborted;
	HWND hHandle;
	MSG mMsg;
	WNDCLASS wWndclass;
	struct{int iX;int iY;}sDimension,sPosition;

	//Konstruktor
	CMJ_Fenster(void)
	{
		this-&gt;sDimension.iX=100;
		this-&gt;sDimension.iY=100;
		this-&gt;sPosition.iX=0;
		this-&gt;sPosition.iY=0;
		this-&gt;bAborted=false;
	}

	LRESULT CALLBACK WndProc(HWND hWnd,UINT message,WPARAM wParam,LPARAM lParam)
	{
		switch(message)
		{
			case WM_DESTROY : PostQuitMessage(0); this-&gt;Aborted=true; return 0;

		}

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

	void FensterErstellen(void)
	{

		wWndclass.style		= CS_HREDRAW|CS_VREDRAW;
		wWndclass.lpfnWndProc	= (WNDPROC)(&amp;CFenster::WndProc);
		wWndclass.cbClsExtra	= 0;
		wWndclass.cbWndExtra	= 0;
		wWndclass.hInstance	= 0;
		wWndclass.hCursor	= LoadCursor(NULL,IDC_ARROW);
		wWndclass.hIcon		= LoadIcon(NULL,IDI_APPLICATION);
		wWndclass.hbrBackground	= (HBRUSH)GetStockObject(WHITE_BRUSH);
		wWndclass.lpszClassName	= TEXT(&quot;Testprogramm&quot;);
		wWndclass.lpszMenuName	= NULL;
		RegisterClass(&amp;wWndclass);

		hHandle=CreateWindow(	TEXT(&quot;Testprogramm&quot;),
					TEXT(&quot;Testprogramm&quot;),
					WS_OVERLAPPEDWINDOW,
					CW_USEDEFAULT,
					CW_USEDEFAULT,
					CW_USEDEFAULT,
					CW_USEDEFAULT,
					NULL,
					NULL,
					0,
					NULL);

		ShowWindow(this-&gt;hHandle,SW_SHOWNORMAL);
		UpdateWindow(this-&gt;hHandle);
	}
};
</code></pre>
<p><strong>main.cpp:</strong></p>
<pre><code class="language-cpp">#include &quot;fenster.h&quot;

int main(void)
{
	CFenster Fenster1,Fenster2;

	Fenster1.FensterErstellen();
	Fenster2.FensterErstellen();

	while(GetMessage(&amp;Fenster1.mMsg,NULL,0,0)||GetMessage(&amp;Fenster2.mMsg,NULL,0,0))
	{
		TranslateMessage(&amp;Fenster1.mMsg);
		DispatchMessage(&amp;Fenster1.mMsg);
		TranslateMessage(&amp;Fenster2.mMsg);
		DispatchMessage(&amp;Fenster2.mMsg);

		if(Fenster1.bAborted==true&amp;&amp;Fenster2.bAborted==true)
			break;
	}
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1429023</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1429023</guid><dc:creator><![CDATA[der_krasse]]></dc:creator><pubDate>Tue, 01 Jan 2008 23:26:13 GMT</pubDate></item><item><title><![CDATA[Reply to Pointer auf WndProc on Wed, 02 Jan 2008 01:10:13 GMT]]></title><description><![CDATA[<p>Suchfunktion</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1429049</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1429049</guid><dc:creator><![CDATA[der_nutzlose]]></dc:creator><pubDate>Wed, 02 Jan 2008 01:10:13 GMT</pubDate></item><item><title><![CDATA[Reply to Pointer auf WndProc on Wed, 02 Jan 2008 17:51:28 GMT]]></title><description><![CDATA[<p>@Der_NUTzLoSe:<br />
Öhm gute Antwort. Nette kompetente Hilfe <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f61b.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--face_with_tongue"
      title=":P"
      alt="😛"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1429505</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1429505</guid><dc:creator><![CDATA[der nutzhafte(You ll.....]]></dc:creator><pubDate>Wed, 02 Jan 2008 17:51:28 GMT</pubDate></item><item><title><![CDATA[Reply to Pointer auf WndProc on Thu, 03 Jan 2008 00:02:57 GMT]]></title><description><![CDATA[<p><em>Naja...-Ich habe zumindest die Antwort jetzt raus:</em><br />
Die Nachrichten-Schleife muss offenbar immer static sein. Dummerweise ist in einer Methode, welche als static deklariert ist, jeweils kein This-Pointer verfügbar, aber auch der lässt sich nachbilden...</p>
<p><strong>fenster.h:</strong></p>
<pre><code class="language-cpp">#include &lt;windows.h&gt;

class CFenster
{
public:
	HWND hHandle;
	WNDCLASS wWndclass;
	MSG mMsg;
	bool bDestroyed;

	LRESULT CALLBACK WndProc(HWND hWnd,UINT message,WPARAM wParam,LPARAM lParam)
	{
		switch(message)
		{
			case WM_DESTROY:
			{
				PostQuitMessage(0);
				this-&gt;bDestroyed=true;
				return 0;
			}
		}

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

	static LRESULT CALLBACK WndProc_static(HWND hWnd,UINT message,WPARAM wParam,LPARAM lParam)
	{
		if(message==WM_CREATE)
		{
			SetWindowLong(hWnd,GWL_USERDATA,(LONG)((LPCREATESTRUCT)lParam)-&gt;lpCreateParams);
		}

		CFenster *pThis=(CFenster*)GetWindowLong(hWnd,GWL_USERDATA);

		if(pThis==0)
		{
			return DefWindowProc (hWnd,message,wParam,lParam);
		}
		else
		{
			return pThis-&gt;WndProc(hWnd,message,wParam,lParam);
		}
	}

	void FensterErstellen(void)
	{
		wWndclass.style		= CS_HREDRAW|CS_VREDRAW;
		wWndclass.lpfnWndProc	= WndProc_static;
		wWndclass.cbClsExtra	= 0;
		wWndclass.cbWndExtra	= 0;
		wWndclass.hInstance	= 0;
		wWndclass.hCursor	= LoadCursor(NULL,IDC_ARROW);
		wWndclass.hIcon		= LoadIcon(NULL,IDI_APPLICATION);
		wWndclass.hbrBackground	= (HBRUSH)GetStockObject(WHITE_BRUSH);
		wWndclass.lpszClassName	= TEXT(&quot;Name-der-Fensterklasse&quot;);
		wWndclass.lpszMenuName	= NULL;
		RegisterClass(&amp;wWndclass);

		hHandle=CreateWindow(	TEXT(&quot;Name-der-Fensterklasse&quot;),
					TEXT(&quot;Fenstertitel&quot;),
					WS_OVERLAPPEDWINDOW,
					0,
					0,
					500,
					500,
					NULL,
					NULL,
					0,
					this);

		this-&gt;bDestroyed=false;

		ShowWindow(this-&gt;hHandle,SW_SHOW);
		UpdateWindow(this-&gt;hHandle);
	}
};
</code></pre>
<p><strong>main.cpp:</strong></p>
<pre><code class="language-cpp">#include &quot;fenster.h&quot;

void main(void)
{
	CFenster MeinFenster;

	MeinFenster.FensterErstellen();

	while(!MeinFenster.bDestroyed)
	{
		if(PeekMessage(&amp;MeinFenster.mMsg,NULL,0,0,PM_REMOVE))
		{
			TranslateMessage(&amp;MeinFenster.mMsg);
			DispatchMessage(&amp;MeinFenster.mMsg);
		}
	}
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1429661</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1429661</guid><dc:creator><![CDATA[der_krasse]]></dc:creator><pubDate>Thu, 03 Jan 2008 00:02:57 GMT</pubDate></item></channel></rss>