<?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[Child-Window korrekt freigeben]]></title><description><![CDATA[<p>Hallo miteinander,</p>
<p>ich hab da mal eine vieleicht naive Frage. Ich erzeuge ein Anwendungsfenster und in der WM_CREATE-Nachricht dessen Fenster-Prozedur erzeuge ich ein Child Fenster. Das funktioniert soweit ganz gut. Um das ganze am Ende wieder abzubauen, konnte ich der Dokumentation von VS <a href="http://2003.net" rel="nofollow">2003.net</a> entnehmen, dass es ausreicht eine DestroyWindow(hWnd) and das Parent-Window zu senden und diese dafür sorgt dass zunächst die Child-Windows abgebaut werden.</p>
<p>Ich bin also davon ausgegangen, dass auch das Child-Window eine WM_DESTROY-Message erhält und habe in der ChildWndProc(...) in der nachricht WM_DESTROY code zum Aufräumen untergebracht. Dieser wird jedoch niemals ausgeführt.</p>
<p>Nun zur Frage. Bekommnen Child-Windows eine WM_DESTROY-Message? Wo muss ich sonst den Code für Speicherfreigaben, ReleaseDC etc. platziertn?</p>
<p>Danke für eure Hilfe.</p>
<p>Mfg<br />
Knecht</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/152567/child-window-korrekt-freigeben</link><generator>RSS for Node</generator><lastBuildDate>Wed, 22 Jul 2026 16:19:20 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/152567.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 07 Jul 2006 11:50:15 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Child-Window korrekt freigeben on Fri, 07 Jul 2006 11:50:15 GMT]]></title><description><![CDATA[<p>Hallo miteinander,</p>
<p>ich hab da mal eine vieleicht naive Frage. Ich erzeuge ein Anwendungsfenster und in der WM_CREATE-Nachricht dessen Fenster-Prozedur erzeuge ich ein Child Fenster. Das funktioniert soweit ganz gut. Um das ganze am Ende wieder abzubauen, konnte ich der Dokumentation von VS <a href="http://2003.net" rel="nofollow">2003.net</a> entnehmen, dass es ausreicht eine DestroyWindow(hWnd) and das Parent-Window zu senden und diese dafür sorgt dass zunächst die Child-Windows abgebaut werden.</p>
<p>Ich bin also davon ausgegangen, dass auch das Child-Window eine WM_DESTROY-Message erhält und habe in der ChildWndProc(...) in der nachricht WM_DESTROY code zum Aufräumen untergebracht. Dieser wird jedoch niemals ausgeführt.</p>
<p>Nun zur Frage. Bekommnen Child-Windows eine WM_DESTROY-Message? Wo muss ich sonst den Code für Speicherfreigaben, ReleaseDC etc. platziertn?</p>
<p>Danke für eure Hilfe.</p>
<p>Mfg<br />
Knecht</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1093190</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1093190</guid><dc:creator><![CDATA[Knecht]]></dc:creator><pubDate>Fri, 07 Jul 2006 11:50:15 GMT</pubDate></item><item><title><![CDATA[Reply to Child-Window korrekt freigeben on Fri, 07 Jul 2006 11:52:01 GMT]]></title><description><![CDATA[<blockquote>
<p>Bekommnen Child-Windows eine WM_DESTROY-Message?</p>
</blockquote>
<p>Ja.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1093194</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1093194</guid><dc:creator><![CDATA[......]]></dc:creator><pubDate>Fri, 07 Jul 2006 11:52:01 GMT</pubDate></item><item><title><![CDATA[Reply to Child-Window korrekt freigeben on Fri, 07 Jul 2006 12:52:04 GMT]]></title><description><![CDATA[<p>mal ne andere naive Frage. Was ist das für ein ChildWindow Wo reagierst du auf die WM_DESTROY Message von deinem Child-Window?<br />
evtl. ein bissel code posten.</p>
<p>MfG schirrmie</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1093252</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1093252</guid><dc:creator><![CDATA[schirrmie]]></dc:creator><pubDate>Fri, 07 Jul 2006 12:52:04 GMT</pubDate></item><item><title><![CDATA[Reply to Child-Window korrekt freigeben on Fri, 07 Jul 2006 13:50:12 GMT]]></title><description><![CDATA[<p>Hallo miteinander,</p>
<p>der Code sieht etwa so aus...</p>
<pre><code class="language-cpp">int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
	WNDCLASSEX wndclass;
	wndclass.cbSize			= sizeof(WNDCLASSEX);
	wndclass.cbClsExtra		= 0;
	wndclass.cbWndExtra		= 0;
	wndclass.hbrBackground	= (HBRUSH)GetStockObject(WHITE_BRUSH);
	wndclass.hCursor		= LoadCursor(NULL, IDC_ARROW);
	wndclass.hIcon			= LoadIcon(NULL, IDI_APPLICATION);
	wndclass.hIconSm		= LoadIcon(NULL, IDI_APPLICATION);
	wndclass.hInstance		= hInstance;
	wndclass.lpfnWndProc	= MainWndProc;
	wndclass.lpszClassName	= TEXT(&quot;3dTest_OpenGL&quot;);
	wndclass.lpszMenuName	= TEXT(&quot;TestProg&quot;);
	wndclass.style			= CS_HREDRAW | CS_VREDRAW;

	if (!RegisterClassEx(&amp;wndclass))
	{
		MessageBox(0, &quot;Programm arbeitet mit Unicode und setzt windows NT voraus!&quot;, &quot;3dTest_OpenGL&quot;, MB_OK | MB_SYSTEMMODAL | MB_ICONERROR);
		return 0;
	}

	wndclass.hIcon			= 0;
	wndclass.hIconSm		= 0;
	wndclass.lpfnWndProc	= GLWndProc;
	wndclass.lpszClassName	= TEXT(&quot;GL_Window&quot;);
	wndclass.style			= CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
	wndclass.hbrBackground	= 0;

	if (!RegisterClassEx(&amp;wndclass))
	{
		MessageBox(0, &quot;Programm arbeitet mit Unicode und setzt windows NT voraus!&quot;, &quot;GL_Window&quot;, MB_OK | MB_SYSTEMMODAL | MB_ICONERROR);
		return 0;
	}

	HWND hWnd = CreateWindow(TEXT(&quot;3dTest_OpenGL&quot;), TEXT(&quot;3d Test OpenGL&quot;), WS_OVERLAPPEDWINDOW, 
		CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, 0, 0, hInstance, 0);

	if (!hWnd)
	{
		MessageBox(0, TEXT(&quot;Die Erzeugung des Anwendungsfensters ist fehlgeschlagen!&quot;), TEXT(&quot;3d Test OpenGL&quot;), MB_OK | MB_SYSTEMMODAL | MB_ICONERROR);
		return 0;
	}

	ShowWindow(hWnd, nCmdShow);
	UpdateWindow(hWnd);

	MSG msg;
	BOOL bRet = false;
	HACCEL hAccel = LoadAccelerators(hInstance, TEXT(&quot;TestProg&quot;));

	while (bRet = GetMessage(&amp;msg, 0, 0, 0))
	{
		if (bRet == -1)
		{
			MessageBox(hWnd, TEXT(&quot;Fehler in der Nachrichtenschlange!&quot;), TEXT(&quot;3d Test OpenGL&quot;), MB_OK | MB_ICONERROR);
			return 0;
		}
		else if (hDlgRefine == 0 || !IsDialogMessage(hDlgRefine, &amp;msg))
		{
			if (!TranslateAccelerator(hWnd, hAccel, &amp;msg))
			{
				TranslateMessage(&amp;msg);
				DispatchMessage(&amp;msg);
			}
		}
	}
	return int(msg.wParam);
}
</code></pre>
<pre><code class="language-cpp">LRESULT CALLBACK MainWndProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
{
	static HWND hGLWnd;
	static HINSTANCE	hInst;							// handle to the main-window
	static int			cxClient, cyClient;				// Window client size
	static int			numElements;					// anzahl an elementen

	switch(Msg)
	{
	case WM_CREATE:
		hInst = ((LPCREATESTRUCT)lParam)-&gt;hInstance;

		hGLWnd = CreateWindow(TEXT(&quot;GL_Window&quot;), 0, WS_CHILDWINDOW | WS_VISIBLE, 
			0, 0, 0, 0, hWnd, (HMENU)1, hInst, 0);

		// ... Weiterer Code ...
		return 0;
	case WM_SIZE:
		cxClient = LOWORD(lParam)/2;					// set new client width
		cyClient = HIWORD(lParam);						// set new client hight
		MoveWindow(hGLWnd, LOWORD(lParam)/2, 0, LOWORD(lParam)/2, HIWORD(lParam), TRUE);
		return 0;

	// ... weitere Messages ...

	case WM_DESTROY:
		PostQuitMessage(0);
		return 0;
	}
	return DefWindowProc(hWnd, Msg, wParam, lParam);
}
</code></pre>
<pre><code class="language-cpp">LRESULT CALLBACK GLWndProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
{
	static PIXELFORMATDESCRIPTOR pdf;
	pdf.nSize			= sizeof(PIXELFORMATDESCRIPTOR);
	pdf.nVersion		= 1;
	pdf.dwFlags			= PFD_DOUBLEBUFFER | PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL;
	pdf.iPixelType		= PFD_TYPE_RGBA;
	pdf.cColorBits		= 16;
	pdf.cRedBits		= 0;
	pdf.cRedShift		= 0;
	pdf.cGreenBits		= 0;
	pdf.cGreenShift		= 0;
	pdf.cBlueBits		= 0;
	pdf.cBlueShift		= 0;
	pdf.cAlphaBits		= 0;
	pdf.cAlphaShift		= 0;
	pdf.cAccumBits		= 0;
	pdf.cAccumRedBits	= 0;
	pdf.cAccumGreenBits = 0;
	pdf.cAccumBlueBits	= 0;
	pdf.cAccumAlphaBits	= 0;
	pdf.cDepthBits		= 16;
	pdf.cStencilBits	= 0;
	pdf.cAuxBuffers		= 0;
	pdf.iLayerType		= PFD_MAIN_PLANE;
	pdf.bReserved		= 0;
	pdf.dwLayerMask		= 0;
	pdf.dwVisibleMask	= 0;
	pdf.dwDamageMask	= 0;

	static HDC		hdc = 0;
	static HGLRC	rc	= 0;

	static int PixelFormat = 0;

	switch(Msg)
	{
	case WM_CREATE:
		if (!(hdc = GetDC(hWnd)))
		{
			MessageBox(hWnd, TEXT(&quot;Unable to create a device context for the GL window!&quot;), 
				TEXT(&quot;Error&quot;), MB_OK | MB_ICONERROR);
			DestroyWindow(GetParent(hWnd));
		}
		if (!(PixelFormat = ChoosePixelFormat(hdc, &amp;pdf)))
		{
			MessageBox(hWnd, TEXT(&quot;Unable to find a suitable pixel format!&quot;), 
				TEXT(&quot;Error&quot;), MB_OK | MB_ICONERROR);
			DestroyWindow(GetParent(hWnd));
		}
		if (!SetPixelFormat(hdc, PixelFormat, &amp;pdf))
		{
			MessageBox(hWnd, TEXT(&quot;Unable to set the pixel format!&quot;), 
				TEXT(&quot;Error&quot;), MB_OK | MB_ICONERROR);
			DestroyWindow(GetParent(hWnd));
		}
		if (!(rc = wglCreateContext(hdc)))
		{
			MessageBox(hWnd, TEXT(&quot;Unable to get a rendering context!&quot;),
				TEXT(&quot;Error&quot;), MB_OK | MB_ICONERROR);
			DestroyWindow(GetParent(hWnd));
		}
		if (!wglMakeCurrent(hdc, rc))
		{
			MessageBox(hWnd, TEXT(&quot;Unable to make the rendering context current!&quot;), 
				TEXT(&quot;Error&quot;), MB_OK | MB_ICONERROR);
			DestroyWindow(hWnd);
		}
		if (!InitGL())
		{
			MessageBox(hWnd, TEXT(&quot;Initialization failed.&quot;), 
				TEXT(&quot;Error&quot;), MB_OK | MB_ICONEXCLAMATION);
			DestroyWindow(GetParent(hWnd));
		}
		return 0;
	case WM_SIZE:
		ResizeGlScene(LOWORD(lParam), HIWORD(lParam));
		return 0;
	case WM_PAINT:
		DrawGLScene();
		SwapBuffers(hdc);
		return 0;
	case WM_DESTROY:
		KillGlWindow(hWnd, hdc, rc);
	}
	return DefWindowProc(hWnd, Msg, wParam, lParam);
}
</code></pre>
<pre><code class="language-cpp">void KillGlWindow(HWND hWnd, HDC hdc, HGLRC rc)
{
	if (rc)
	{
		if (!wglMakeCurrent(0, 0))
			MessageBox(0, TEXT(&quot;Release of dc and rc failed.&quot;), 
				TEXT(&quot;SHUTDOWN ERROR&quot;), MB_OK | MB_ICONINFORMATION);
		if (!wglDeleteContext(rc))
			MessageBox(0, TEXT(&quot;Release rendering context failed.&quot;), 
				TEXT(&quot;SHUTDOWN ERROR&quot;), MB_OK | MB_ICONINFORMATION);
		rc = 0;
	}
	if (hdc &amp;&amp; !ReleaseDC(hWnd, hdc))
	{
		MessageBox(0, TEXT(&quot;Release device context failed.&quot;), 
			TEXT(&quot;SHUTDOWN ERROR&quot;), MB_OK | MB_ICONINFORMATION);
		hdc = 0;
	}
}
</code></pre>
<p>hilft das weiter ?</p>
<p>Danke im Voraus</p>
<p>Mfg<br />
Knecht</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1093293</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1093293</guid><dc:creator><![CDATA[Knecht]]></dc:creator><pubDate>Fri, 07 Jul 2006 13:50:12 GMT</pubDate></item></channel></rss>