<?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[Beispielprogramm funzt nicht? Threads]]></title><description><![CDATA[<p>Hi, ich bin ja gerade am lernen. Hier ein Beispielprogramm aus einem Lehrbuch das nicht compiliert.<br />
Der Compiler findet den Beizeichner hWindow nicht.<br />
Ich habe leider noch keine Erfahrung mit Threads, deshalb habe ich auch keine Ahnung, was da nicht stimmt.<br />
Kann mir jemand helfen?</p>
<pre><code>#include &lt;windows.h&gt;

LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM);
DWORD WINAPI ThreadProc (LPVOID);

int APIENTRY WinMain(HINSTANCE hInstance,
					 HINSTANCE hPrevInstance,
					 LPSTR lpCmdLine,
					 int nCmdShow)

{
    WNDCLASS WndClass;
	WndClass.style =0;
    WndClass.cbClsExtra =0;
    WndClass.cbWndExtra =0;
    WndClass.lpfnWndProc = WndProc;
    WndClass.hInstance = hInstance;
	WndClass.hbrBackground = (HBRUSH) (COLOR_WINDOW+1);
	WndClass.hCursor = LoadCursor (NULL, IDC_ARROW);
	WndClass.hIcon = LoadIcon (NULL, IDI_APPLICATION);
	WndClass.lpszMenuName =0;
	WndClass.lpszClassName = &quot;Thread2&quot;;

	RegisterClass(&amp;WndClass);

	HWND hWindow,hButton;

	hWindow = CreateWindow(&quot;Thread2&quot;,&quot;Thread-Fenster&quot;,
		                    WS_OVERLAPPEDWINDOW,
							0,0,400,400,NULL,NULL,
							hInstance,NULL);

	hButton = CreateWindow(&quot;BUTTON&quot;,&quot;Start Thread 2&quot;,WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON,
							10,200,200,20,hWindow,(HMENU) 1,hInstance,NULL);
	hButton = CreateWindow(&quot;BUTTON&quot;,&quot;Ende Thread 2&quot;,WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON,
							10,240,200,20,hWindow,(HMENU) 2,hInstance,NULL);

	ShowWindow (hWindow, nCmdShow);

	UpdateWindow (hWindow);

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

}
DWORD WINAPI ThreadProc(LPVOID pvoid)
{
	int wert = 2;
	while(wert==2)
	{
		HDC hdc1;
		hdc1 = GetDC(hWindow);
		Rectangle(hdc1,rand()%200,rand()%200,rand()%200,rand()%200);
		ReleaseDC(hWindow,hdc1);
	}
	return 0;
}

LRESULT CALLBACK WndProc(HWND hWnd, UINT uiMessage,
						 WPARAM wParam,LPARAM lParam)
{
	static HANDLE hThread;
	switch(uiMessage)
	{
	case WM_COMMAND:
		if (HIWORD(wParam)==BN_CLICKED)
		{
			if (LOWORD(wParam)==1)
			{
				DWORD dwThreadParam = 1;
				DWORD dwThreadID;
				hThread = CreateThread(NULL,0,ThreadProc,&amp;dwThreadParam,0,&amp;dwThreadID);
			}
			if (LOWORD(wParam) == 2)
			{
				TerminateThread(hThread,0);
			}

		}
		return 0;

    case WM_DESTROY:
		PostQuitMessage(0);
		return 0;
	default:
		return DefWindowProc (hWnd, uiMessage,
								wParam, lParam);
}
}
</code></pre>
<p>P.S.: Bitte nicht zu schwierig erklären!</p>
<p>Gruß</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/107510/beispielprogramm-funzt-nicht-threads</link><generator>RSS for Node</generator><lastBuildDate>Tue, 30 Jun 2026 02:14:18 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/107510.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 20 Apr 2005 09:46:45 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Beispielprogramm funzt nicht? Threads on Wed, 20 Apr 2005 09:47:56 GMT]]></title><description><![CDATA[<p>Hi, ich bin ja gerade am lernen. Hier ein Beispielprogramm aus einem Lehrbuch das nicht compiliert.<br />
Der Compiler findet den Beizeichner hWindow nicht.<br />
Ich habe leider noch keine Erfahrung mit Threads, deshalb habe ich auch keine Ahnung, was da nicht stimmt.<br />
Kann mir jemand helfen?</p>
<pre><code>#include &lt;windows.h&gt;

LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM);
DWORD WINAPI ThreadProc (LPVOID);

int APIENTRY WinMain(HINSTANCE hInstance,
					 HINSTANCE hPrevInstance,
					 LPSTR lpCmdLine,
					 int nCmdShow)

{
    WNDCLASS WndClass;
	WndClass.style =0;
    WndClass.cbClsExtra =0;
    WndClass.cbWndExtra =0;
    WndClass.lpfnWndProc = WndProc;
    WndClass.hInstance = hInstance;
	WndClass.hbrBackground = (HBRUSH) (COLOR_WINDOW+1);
	WndClass.hCursor = LoadCursor (NULL, IDC_ARROW);
	WndClass.hIcon = LoadIcon (NULL, IDI_APPLICATION);
	WndClass.lpszMenuName =0;
	WndClass.lpszClassName = &quot;Thread2&quot;;

	RegisterClass(&amp;WndClass);

	HWND hWindow,hButton;

	hWindow = CreateWindow(&quot;Thread2&quot;,&quot;Thread-Fenster&quot;,
		                    WS_OVERLAPPEDWINDOW,
							0,0,400,400,NULL,NULL,
							hInstance,NULL);

	hButton = CreateWindow(&quot;BUTTON&quot;,&quot;Start Thread 2&quot;,WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON,
							10,200,200,20,hWindow,(HMENU) 1,hInstance,NULL);
	hButton = CreateWindow(&quot;BUTTON&quot;,&quot;Ende Thread 2&quot;,WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON,
							10,240,200,20,hWindow,(HMENU) 2,hInstance,NULL);

	ShowWindow (hWindow, nCmdShow);

	UpdateWindow (hWindow);

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

}
DWORD WINAPI ThreadProc(LPVOID pvoid)
{
	int wert = 2;
	while(wert==2)
	{
		HDC hdc1;
		hdc1 = GetDC(hWindow);
		Rectangle(hdc1,rand()%200,rand()%200,rand()%200,rand()%200);
		ReleaseDC(hWindow,hdc1);
	}
	return 0;
}

LRESULT CALLBACK WndProc(HWND hWnd, UINT uiMessage,
						 WPARAM wParam,LPARAM lParam)
{
	static HANDLE hThread;
	switch(uiMessage)
	{
	case WM_COMMAND:
		if (HIWORD(wParam)==BN_CLICKED)
		{
			if (LOWORD(wParam)==1)
			{
				DWORD dwThreadParam = 1;
				DWORD dwThreadID;
				hThread = CreateThread(NULL,0,ThreadProc,&amp;dwThreadParam,0,&amp;dwThreadID);
			}
			if (LOWORD(wParam) == 2)
			{
				TerminateThread(hThread,0);
			}

		}
		return 0;

    case WM_DESTROY:
		PostQuitMessage(0);
		return 0;
	default:
		return DefWindowProc (hWnd, uiMessage,
								wParam, lParam);
}
}
</code></pre>
<p>P.S.: Bitte nicht zu schwierig erklären!</p>
<p>Gruß</p>
]]></description><link>https://www.c-plusplus.net/forum/post/771025</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/771025</guid><dc:creator><![CDATA[evil-peter]]></dc:creator><pubDate>Wed, 20 Apr 2005 09:47:56 GMT</pubDate></item><item><title><![CDATA[Reply to Beispielprogramm funzt nicht? Threads on Wed, 20 Apr 2005 10:08:13 GMT]]></title><description><![CDATA[<pre><code>HWND hWindow;
</code></pre>
<p>sollte global sein oder parameter mit an den thread übergeben werden.<br />
wobei zweite variante die schönere und imho die bessere ist.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/771044</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/771044</guid><dc:creator><![CDATA[miller_m]]></dc:creator><pubDate>Wed, 20 Apr 2005 10:08:13 GMT</pubDate></item><item><title><![CDATA[Reply to Beispielprogramm funzt nicht? Threads on Wed, 20 Apr 2005 11:22:17 GMT]]></title><description><![CDATA[<p>Danke für den Hinweiß. Müsste man eigentlich auch selber drauf kommen, aber wenn es aus einem Lehrbuch stammt, kommt man einfach nicht auf so einen &quot;blöden&quot; Fehler.</p>
<p>Aber wie soll ich hWindow als Parameter übergeben. Ich habe das mal versucht, aber er macht es irgendwie nicht.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/771118</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/771118</guid><dc:creator><![CDATA[evil-peter]]></dc:creator><pubDate>Wed, 20 Apr 2005 11:22:17 GMT</pubDate></item><item><title><![CDATA[Reply to Beispielprogramm funzt nicht? Threads on Wed, 20 Apr 2005 11:41:50 GMT]]></title><description><![CDATA[<p>[cpp]<br />
// wndproc<br />
hThread = CreateThread(NULL,0,ThreadProc,**hWnd,**0,&amp;dwThreadID);</p>
<p>DWORD WINAPI ThreadProc(LPVOID pvoid)<br />
{<br />
HWND hWindow = (HWND)pvoid;<br />
}<br />
[/cpp]</p>
]]></description><link>https://www.c-plusplus.net/forum/post/771130</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/771130</guid><dc:creator><![CDATA[miller_m]]></dc:creator><pubDate>Wed, 20 Apr 2005 11:41:50 GMT</pubDate></item><item><title><![CDATA[Reply to Beispielprogramm funzt nicht? Threads on Wed, 20 Apr 2005 15:48:29 GMT]]></title><description><![CDATA[<p>Danke, hat geklappt!</p>
<p>Gruß</p>
]]></description><link>https://www.c-plusplus.net/forum/post/771430</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/771430</guid><dc:creator><![CDATA[evil-peter]]></dc:creator><pubDate>Wed, 20 Apr 2005 15:48:29 GMT</pubDate></item></channel></rss>