<?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[Subclassing]]></title><description><![CDATA[<p>Hallo,</p>
<p>ich versuche gerade einen Button zu subclassen (sagt man so?), aber irgendwo ist wohl der Wurm drin. Die ButtonProc wird nicht aufgerufen.<br />
Vielleicht sieht ja jemand wo mein Fehler ist <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>Hier mal der Code:</p>
<pre><code>#include &lt;windows.h&gt;

LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM) ;
LRESULT CALLBACK ButtonProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);

static LONG PrevWndProc;

int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
                    PSTR szCmdLine, int iCmdShow)
{
	HWND     hwnd ;
	MSG      msg ;
	WNDCLASS wndclass ;

	wndclass.style         = CS_HREDRAW | CS_VREDRAW ;
	wndclass.lpfnWndProc   = WndProc ;
	wndclass.cbClsExtra    = 0 ;
	wndclass.cbWndExtra    = 0 ;
	wndclass.hInstance     = hInstance ;
	wndclass.hIcon         = NULL ;
	wndclass.hCursor       = LoadCursor (NULL, IDC_ARROW) ;
	wndclass.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH) ;
	wndclass.lpszMenuName  = NULL;
	wndclass.lpszClassName = &quot;Test&quot; ;

	if (!RegisterClass (&amp;wndclass))
	{    
		return 0 ;
	}

	hwnd = CreateWindow (&quot;Test&quot;, &quot;Test&quot;,
                         WS_OVERLAPPEDWINDOW,
                         CW_USEDEFAULT, CW_USEDEFAULT,
                         400, 250,
                         NULL, NULL, hInstance, NULL) ;

	ShowWindow (hwnd, iCmdShow) ;
	UpdateWindow (hwnd) ;

	while (GetMessage (&amp;msg, NULL, 0, 0))
	{
		TranslateMessage (&amp;msg) ;
		DispatchMessage (&amp;msg) ;
	}
	return msg.wParam ;
}

LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    static HWND hButton;

	switch (message)
	{
        case WM_CREATE:
        {
            hButton = CreateWindow (&quot;BUTTON&quot;, &quot;Test&quot;, 
                                    WS_CHILD | WS_VISIBLE | BS_DEFPUSHBUTTON,
                                    20, 20, 100, 40,
                                    hwnd, NULL, ((LPCREATESTRUCT)lParam)-&gt;hInstance, NULL);

            PrevWndProc = SetWindowLong(hButton, GWL_WNDPROC, (LONG)ButtonProc); 
            return 0;
        }

		case WM_DESTROY :
		{
            SetWindowLong(hButton, GWL_WNDPROC, PrevWndProc);
			PostQuitMessage (0) ;
			return 0;
		}
	}
	return DefWindowProc (hwnd, message, wParam, lParam) ;
}

LRESULT CALLBACK ButtonProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
    switch (msg)
    {
        case WM_COMMAND:
        {
            if (HIWORD(wParam) == BN_CLICKED)
            {
                MessageBox(0, &quot;Test&quot;, &quot;Clicked&quot;, MB_OK);
            }
        }
        break;
    }

    return CallWindowProc((WNDPROC)PrevWndProc, hWnd, msg, wParam, lParam);
}
</code></pre>
<p>Danke.</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/127561/subclassing</link><generator>RSS for Node</generator><lastBuildDate>Wed, 08 Jul 2026 09:26:06 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/127561.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 25 Nov 2005 11:41:43 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Subclassing on Fri, 25 Nov 2005 11:41:43 GMT]]></title><description><![CDATA[<p>Hallo,</p>
<p>ich versuche gerade einen Button zu subclassen (sagt man so?), aber irgendwo ist wohl der Wurm drin. Die ButtonProc wird nicht aufgerufen.<br />
Vielleicht sieht ja jemand wo mein Fehler ist <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>Hier mal der Code:</p>
<pre><code>#include &lt;windows.h&gt;

LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM) ;
LRESULT CALLBACK ButtonProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);

static LONG PrevWndProc;

int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
                    PSTR szCmdLine, int iCmdShow)
{
	HWND     hwnd ;
	MSG      msg ;
	WNDCLASS wndclass ;

	wndclass.style         = CS_HREDRAW | CS_VREDRAW ;
	wndclass.lpfnWndProc   = WndProc ;
	wndclass.cbClsExtra    = 0 ;
	wndclass.cbWndExtra    = 0 ;
	wndclass.hInstance     = hInstance ;
	wndclass.hIcon         = NULL ;
	wndclass.hCursor       = LoadCursor (NULL, IDC_ARROW) ;
	wndclass.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH) ;
	wndclass.lpszMenuName  = NULL;
	wndclass.lpszClassName = &quot;Test&quot; ;

	if (!RegisterClass (&amp;wndclass))
	{    
		return 0 ;
	}

	hwnd = CreateWindow (&quot;Test&quot;, &quot;Test&quot;,
                         WS_OVERLAPPEDWINDOW,
                         CW_USEDEFAULT, CW_USEDEFAULT,
                         400, 250,
                         NULL, NULL, hInstance, NULL) ;

	ShowWindow (hwnd, iCmdShow) ;
	UpdateWindow (hwnd) ;

	while (GetMessage (&amp;msg, NULL, 0, 0))
	{
		TranslateMessage (&amp;msg) ;
		DispatchMessage (&amp;msg) ;
	}
	return msg.wParam ;
}

LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    static HWND hButton;

	switch (message)
	{
        case WM_CREATE:
        {
            hButton = CreateWindow (&quot;BUTTON&quot;, &quot;Test&quot;, 
                                    WS_CHILD | WS_VISIBLE | BS_DEFPUSHBUTTON,
                                    20, 20, 100, 40,
                                    hwnd, NULL, ((LPCREATESTRUCT)lParam)-&gt;hInstance, NULL);

            PrevWndProc = SetWindowLong(hButton, GWL_WNDPROC, (LONG)ButtonProc); 
            return 0;
        }

		case WM_DESTROY :
		{
            SetWindowLong(hButton, GWL_WNDPROC, PrevWndProc);
			PostQuitMessage (0) ;
			return 0;
		}
	}
	return DefWindowProc (hwnd, message, wParam, lParam) ;
}

LRESULT CALLBACK ButtonProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
    switch (msg)
    {
        case WM_COMMAND:
        {
            if (HIWORD(wParam) == BN_CLICKED)
            {
                MessageBox(0, &quot;Test&quot;, &quot;Clicked&quot;, MB_OK);
            }
        }
        break;
    }

    return CallWindowProc((WNDPROC)PrevWndProc, hWnd, msg, wParam, lParam);
}
</code></pre>
<p>Danke.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/926882</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/926882</guid><dc:creator><![CDATA[luxx]]></dc:creator><pubDate>Fri, 25 Nov 2005 11:41:43 GMT</pubDate></item><item><title><![CDATA[Reply to Subclassing on Fri, 25 Nov 2005 11:48:01 GMT]]></title><description><![CDATA[<p>Du könntest mal schauen, ob SetWindowLong überhaupt erfolgreich ist.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/926885</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/926885</guid><dc:creator><![CDATA[dEUs]]></dc:creator><pubDate>Fri, 25 Nov 2005 11:48:01 GMT</pubDate></item><item><title><![CDATA[Reply to Subclassing on Fri, 25 Nov 2005 11:53:19 GMT]]></title><description><![CDATA[<p>luxx schrieb:</p>
<blockquote>
<p>Die ButtonProc wird nicht aufgerufen.</p>
</blockquote>
<p>Bist du dir da wirklich sicher? Oder wird nur keine MessageBox ausgegeben?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/926888</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/926888</guid><dc:creator><![CDATA[...................]]></dc:creator><pubDate>Fri, 25 Nov 2005 11:53:19 GMT</pubDate></item><item><title><![CDATA[Reply to Subclassing on Fri, 25 Nov 2005 13:13:20 GMT]]></title><description><![CDATA[<p>Ok, ihr habt recht <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="🙂"
    /><br />
Die ButtonProc wird aufgerufen, aber es kommt nie ein WM_COMMAND.</p>
<p>Wenn ich die Abfrage in der WndProc mache, dann erscheint die MessageBox.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/926962</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/926962</guid><dc:creator><![CDATA[luxx]]></dc:creator><pubDate>Fri, 25 Nov 2005 13:13:20 GMT</pubDate></item><item><title><![CDATA[Reply to Subclassing on Sat, 26 Nov 2005 08:23:43 GMT]]></title><description><![CDATA[<p>BN_CLICKED bekommst du als Benachrichtigung an das Parent, also nicht in der ButtonProc selbst. Dort musst du wohl direkt die Nachrichten wie WM_LBUTTONDOWN &amp; Co. abfangen...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/927444</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/927444</guid><dc:creator><![CDATA[flenders]]></dc:creator><pubDate>Sat, 26 Nov 2005 08:23:43 GMT</pubDate></item></channel></rss>