<?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[Threads unter Win32 API]]></title><description><![CDATA[<p>Hi Leute,</p>
<p>ich bin eher programmierschwach und soll ein Programm schreiben, was einen Cursor innerhalb eines Rechtecks auf Tastendruck hin und her scheucht. Das ganze soll unter dem Passus &quot;Multithreading&quot; laufen. Ich habe mich mal versucht und das ist mein Code:</p>
<p>#include &lt;iostream&gt;<br />
#include &lt;stdio.h&gt;<br />
#include &lt;Windows.h&gt;<br />
#include &lt;stdlib.h&gt;</p>
<p>using namespace std;</p>
<p>typedef struct _tblock<br />
{<br />
int x_pos, y_pos, x_bew, y_bew;<br />
}<br />
TBlock;</p>
<p>typedef struct _tbox<br />
{<br />
int links, oben, breite, hoehe;<br />
}<br />
TBox;</p>
<p>TBlock block;<br />
TBox box;</p>
<p>void gotoxy(int x, int y)<br />
{<br />
{<br />
COORD p = { x, y };<br />
SetConsoleCursorPosition( GetStdHandle( STD_OUTPUT_HANDLE ), p );<br />
}</p>
<p>void Blinkerimplementierung();<br />
{<br />
for (int y = box.oben; y &lt; box.oben + box.hoehe; y++)<br />
for (int x = box.links; x &lt; box.links + box.breite; x++)<br />
{<br />
gotoxy(x,y);<br />
printf(&quot;%c&quot;,176);<br />
}<br />
}</p>
<p>DWORD WINAPI block_bewegung (LPVOID Param);</p>
<p>{<br />
gotoxy(box.links+block.x_pos, box.oben+block.y_pos);<br />
printf(&quot;%c&quot;,176);</p>
<p>block.x_pos += block.x_bew;<br />
block.y_pos += block.y_bew;</p>
<p>if (block.x_pos &gt; box.breite-1) block.x_pos -= box.breite;<br />
if (block.x_pos &lt; 0) block.x_pos += box.breite;<br />
if (block.y_pos &gt; box.hoehe-1) block.y_pos -= box.hoehe;<br />
if (block.y_pos &lt; 0) block.y_pos += box.hoehe;</p>
<p>gotoxy(box.links+block.x_pos, box.oben+block.y_pos);<br />
printf(&quot;%c&quot;,219);</p>
<p>Sleep(70);</p>
<p>return ;<br />
}<br />
int main();<br />
DWORD ThreadId;<br />
HANDLE ThreadHandle;<br />
VOID ExitThread(DWORD status);</p>
<p>{<br />
char taste;</p>
<p>block.x_pos = 0;<br />
block.y_pos = 0;<br />
block.x_bew = 0;<br />
block.y_bew = 0;</p>
<p>box.links = 15;<br />
box.oben = 5;<br />
box.breite = 25;<br />
box.hoehe = 15;</p>
<p>Blinkerimplementierung();</p>
<p>gotoxy(0,0);<br />
printf(&quot;Richtung: Hoch | Runter | Links | Rechts Halt: Leertaste Exit: Esc&quot;);<br />
CreateThread(NULL, 0, block_bewegung, NULL, 0, NULL);</p>
<p>{</p>
<p>taste = getchar();<br />
if (taste == 27)<br />
{<br />
ExitThread(DWORD status);<br />
}</p>
<p>if (taste==-32)<br />
{<br />
taste = getchar();<br />
switch (taste)<br />
{<br />
case 75:<br />
block.x_bew = -1;<br />
block.y_bew = 0;<br />
break;<br />
case 77:<br />
block.x_bew = 1;<br />
block.y_bew = 0;<br />
break;<br />
case 72:<br />
block.x_bew = 0;<br />
block.y_bew = -1;<br />
break;<br />
case 80:<br />
block.x_bew = 0;<br />
block.y_bew = 1;<br />
break;<br />
}<br />
}<br />
if (taste==32)<br />
{<br />
block.x_bew = 0;<br />
block.y_bew = 0;<br />
}</p>
<p>}</p>
<p>gotoxy(0,20);<br />
return ;<br />
}<br />
}#include &lt;iostream&gt;<br />
#include &lt;stdio.h&gt;<br />
#include &lt;Windows.h&gt;<br />
#include &lt;stdlib.h&gt;</p>
<p>using namespace std;</p>
<p>typedef struct _tblock<br />
{<br />
int x_pos, y_pos, x_bew, y_bew;<br />
}<br />
TBlock;</p>
<p>typedef struct _tbox<br />
{<br />
int links, oben, breite, hoehe;<br />
}<br />
TBox;</p>
<p>TBlock block;<br />
TBox box;</p>
<p>void gotoxy(int x, int y)<br />
{<br />
{<br />
COORD p = { x, y };<br />
SetConsoleCursorPosition( GetStdHandle( STD_OUTPUT_HANDLE ), p );<br />
}</p>
<p>void Blinkerimplementierung();<br />
{<br />
for (int y = box.oben; y &lt; box.oben + box.hoehe; y++)<br />
for (int x = box.links; x &lt; box.links + box.breite; x++)<br />
{<br />
gotoxy(x,y);<br />
printf(&quot;%c&quot;,176);<br />
}<br />
}</p>
<p>DWORD WINAPI block_bewegung (LPVOID Param);</p>
<p>{<br />
gotoxy(box.links+block.x_pos, box.oben+block.y_pos);<br />
printf(&quot;%c&quot;,176);</p>
<p>block.x_pos += block.x_bew;<br />
block.y_pos += block.y_bew;</p>
<p>if (block.x_pos &gt; box.breite-1) block.x_pos -= box.breite;<br />
if (block.x_pos &lt; 0) block.x_pos += box.breite;<br />
if (block.y_pos &gt; box.hoehe-1) block.y_pos -= box.hoehe;<br />
if (block.y_pos &lt; 0) block.y_pos += box.hoehe;</p>
<p>gotoxy(box.links+block.x_pos, box.oben+block.y_pos);<br />
printf(&quot;%c&quot;,219);</p>
<p>Sleep(70);</p>
<p>return ;<br />
}<br />
int main();<br />
DWORD ThreadId;<br />
HANDLE ThreadHandle;<br />
VOID ExitThread(DWORD status);</p>
<p>{<br />
char taste;</p>
<p>block.x_pos = 0;<br />
block.y_pos = 0;<br />
block.x_bew = 0;<br />
block.y_bew = 0;</p>
<p>box.links = 15;<br />
box.oben = 5;<br />
box.breite = 25;<br />
box.hoehe = 15;</p>
<p>Blinkerimplementierung();</p>
<p>gotoxy(0,0);<br />
printf(&quot;Richtung: Hoch | Runter | Links | Rechts Halt: Leertaste Exit: Esc&quot;);<br />
CreateThread(NULL, 0, block_bewegung, NULL, 0, NULL);</p>
<p>{</p>
<p>taste = getchar();<br />
if (taste == 27)<br />
{<br />
ExitThread(DWORD status);<br />
}</p>
<p>if (taste==-32)<br />
{<br />
taste = getchar();<br />
switch (taste)<br />
{<br />
case 75:<br />
block.x_bew = -1;<br />
block.y_bew = 0;<br />
break;<br />
case 77:<br />
block.x_bew = 1;<br />
block.y_bew = 0;<br />
break;<br />
case 72:<br />
block.x_bew = 0;<br />
block.y_bew = -1;<br />
break;<br />
case 80:<br />
block.x_bew = 0;<br />
block.y_bew = 1;<br />
break;<br />
}<br />
}<br />
if (taste==32)<br />
{<br />
block.x_bew = 0;<br />
block.y_bew = 0;<br />
}</p>
<p>}</p>
<p>gotoxy(0,20);<br />
return ;<br />
}<br />
}</p>
<p>Diese Zeile scheint i-wie verkehrt zu sein:</p>
<p>ExitThread(DWORD status);</p>
<p>Kann mir jemand helfen? Ich wollte das hin und her des Cursors durch Tastendruck &quot;Esc&quot; beenden.</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/302937/threads-unter-win32-api</link><generator>RSS for Node</generator><lastBuildDate>Tue, 11 Aug 2026 00:51:33 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/302937.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 01 May 2012 13:29:02 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Threads unter Win32 API on Tue, 01 May 2012 13:29:02 GMT]]></title><description><![CDATA[<p>Hi Leute,</p>
<p>ich bin eher programmierschwach und soll ein Programm schreiben, was einen Cursor innerhalb eines Rechtecks auf Tastendruck hin und her scheucht. Das ganze soll unter dem Passus &quot;Multithreading&quot; laufen. Ich habe mich mal versucht und das ist mein Code:</p>
<p>#include &lt;iostream&gt;<br />
#include &lt;stdio.h&gt;<br />
#include &lt;Windows.h&gt;<br />
#include &lt;stdlib.h&gt;</p>
<p>using namespace std;</p>
<p>typedef struct _tblock<br />
{<br />
int x_pos, y_pos, x_bew, y_bew;<br />
}<br />
TBlock;</p>
<p>typedef struct _tbox<br />
{<br />
int links, oben, breite, hoehe;<br />
}<br />
TBox;</p>
<p>TBlock block;<br />
TBox box;</p>
<p>void gotoxy(int x, int y)<br />
{<br />
{<br />
COORD p = { x, y };<br />
SetConsoleCursorPosition( GetStdHandle( STD_OUTPUT_HANDLE ), p );<br />
}</p>
<p>void Blinkerimplementierung();<br />
{<br />
for (int y = box.oben; y &lt; box.oben + box.hoehe; y++)<br />
for (int x = box.links; x &lt; box.links + box.breite; x++)<br />
{<br />
gotoxy(x,y);<br />
printf(&quot;%c&quot;,176);<br />
}<br />
}</p>
<p>DWORD WINAPI block_bewegung (LPVOID Param);</p>
<p>{<br />
gotoxy(box.links+block.x_pos, box.oben+block.y_pos);<br />
printf(&quot;%c&quot;,176);</p>
<p>block.x_pos += block.x_bew;<br />
block.y_pos += block.y_bew;</p>
<p>if (block.x_pos &gt; box.breite-1) block.x_pos -= box.breite;<br />
if (block.x_pos &lt; 0) block.x_pos += box.breite;<br />
if (block.y_pos &gt; box.hoehe-1) block.y_pos -= box.hoehe;<br />
if (block.y_pos &lt; 0) block.y_pos += box.hoehe;</p>
<p>gotoxy(box.links+block.x_pos, box.oben+block.y_pos);<br />
printf(&quot;%c&quot;,219);</p>
<p>Sleep(70);</p>
<p>return ;<br />
}<br />
int main();<br />
DWORD ThreadId;<br />
HANDLE ThreadHandle;<br />
VOID ExitThread(DWORD status);</p>
<p>{<br />
char taste;</p>
<p>block.x_pos = 0;<br />
block.y_pos = 0;<br />
block.x_bew = 0;<br />
block.y_bew = 0;</p>
<p>box.links = 15;<br />
box.oben = 5;<br />
box.breite = 25;<br />
box.hoehe = 15;</p>
<p>Blinkerimplementierung();</p>
<p>gotoxy(0,0);<br />
printf(&quot;Richtung: Hoch | Runter | Links | Rechts Halt: Leertaste Exit: Esc&quot;);<br />
CreateThread(NULL, 0, block_bewegung, NULL, 0, NULL);</p>
<p>{</p>
<p>taste = getchar();<br />
if (taste == 27)<br />
{<br />
ExitThread(DWORD status);<br />
}</p>
<p>if (taste==-32)<br />
{<br />
taste = getchar();<br />
switch (taste)<br />
{<br />
case 75:<br />
block.x_bew = -1;<br />
block.y_bew = 0;<br />
break;<br />
case 77:<br />
block.x_bew = 1;<br />
block.y_bew = 0;<br />
break;<br />
case 72:<br />
block.x_bew = 0;<br />
block.y_bew = -1;<br />
break;<br />
case 80:<br />
block.x_bew = 0;<br />
block.y_bew = 1;<br />
break;<br />
}<br />
}<br />
if (taste==32)<br />
{<br />
block.x_bew = 0;<br />
block.y_bew = 0;<br />
}</p>
<p>}</p>
<p>gotoxy(0,20);<br />
return ;<br />
}<br />
}#include &lt;iostream&gt;<br />
#include &lt;stdio.h&gt;<br />
#include &lt;Windows.h&gt;<br />
#include &lt;stdlib.h&gt;</p>
<p>using namespace std;</p>
<p>typedef struct _tblock<br />
{<br />
int x_pos, y_pos, x_bew, y_bew;<br />
}<br />
TBlock;</p>
<p>typedef struct _tbox<br />
{<br />
int links, oben, breite, hoehe;<br />
}<br />
TBox;</p>
<p>TBlock block;<br />
TBox box;</p>
<p>void gotoxy(int x, int y)<br />
{<br />
{<br />
COORD p = { x, y };<br />
SetConsoleCursorPosition( GetStdHandle( STD_OUTPUT_HANDLE ), p );<br />
}</p>
<p>void Blinkerimplementierung();<br />
{<br />
for (int y = box.oben; y &lt; box.oben + box.hoehe; y++)<br />
for (int x = box.links; x &lt; box.links + box.breite; x++)<br />
{<br />
gotoxy(x,y);<br />
printf(&quot;%c&quot;,176);<br />
}<br />
}</p>
<p>DWORD WINAPI block_bewegung (LPVOID Param);</p>
<p>{<br />
gotoxy(box.links+block.x_pos, box.oben+block.y_pos);<br />
printf(&quot;%c&quot;,176);</p>
<p>block.x_pos += block.x_bew;<br />
block.y_pos += block.y_bew;</p>
<p>if (block.x_pos &gt; box.breite-1) block.x_pos -= box.breite;<br />
if (block.x_pos &lt; 0) block.x_pos += box.breite;<br />
if (block.y_pos &gt; box.hoehe-1) block.y_pos -= box.hoehe;<br />
if (block.y_pos &lt; 0) block.y_pos += box.hoehe;</p>
<p>gotoxy(box.links+block.x_pos, box.oben+block.y_pos);<br />
printf(&quot;%c&quot;,219);</p>
<p>Sleep(70);</p>
<p>return ;<br />
}<br />
int main();<br />
DWORD ThreadId;<br />
HANDLE ThreadHandle;<br />
VOID ExitThread(DWORD status);</p>
<p>{<br />
char taste;</p>
<p>block.x_pos = 0;<br />
block.y_pos = 0;<br />
block.x_bew = 0;<br />
block.y_bew = 0;</p>
<p>box.links = 15;<br />
box.oben = 5;<br />
box.breite = 25;<br />
box.hoehe = 15;</p>
<p>Blinkerimplementierung();</p>
<p>gotoxy(0,0);<br />
printf(&quot;Richtung: Hoch | Runter | Links | Rechts Halt: Leertaste Exit: Esc&quot;);<br />
CreateThread(NULL, 0, block_bewegung, NULL, 0, NULL);</p>
<p>{</p>
<p>taste = getchar();<br />
if (taste == 27)<br />
{<br />
ExitThread(DWORD status);<br />
}</p>
<p>if (taste==-32)<br />
{<br />
taste = getchar();<br />
switch (taste)<br />
{<br />
case 75:<br />
block.x_bew = -1;<br />
block.y_bew = 0;<br />
break;<br />
case 77:<br />
block.x_bew = 1;<br />
block.y_bew = 0;<br />
break;<br />
case 72:<br />
block.x_bew = 0;<br />
block.y_bew = -1;<br />
break;<br />
case 80:<br />
block.x_bew = 0;<br />
block.y_bew = 1;<br />
break;<br />
}<br />
}<br />
if (taste==32)<br />
{<br />
block.x_bew = 0;<br />
block.y_bew = 0;<br />
}</p>
<p>}</p>
<p>gotoxy(0,20);<br />
return ;<br />
}<br />
}</p>
<p>Diese Zeile scheint i-wie verkehrt zu sein:</p>
<p>ExitThread(DWORD status);</p>
<p>Kann mir jemand helfen? Ich wollte das hin und her des Cursors durch Tastendruck &quot;Esc&quot; beenden.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2207227</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2207227</guid><dc:creator><![CDATA[Dalice66]]></dc:creator><pubDate>Tue, 01 May 2012 13:29:02 GMT</pubDate></item><item><title><![CDATA[Reply to Threads unter Win32 API on Tue, 01 May 2012 14:20:03 GMT]]></title><description><![CDATA[<p>ohne cpp-tags wird sich das wohl niemand durchlesen. wenn du deinen quellcode lesbar machst, hast du wenigstens ne chance</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2207242</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2207242</guid><dc:creator><![CDATA[unskilled]]></dc:creator><pubDate>Tue, 01 May 2012 14:20:03 GMT</pubDate></item><item><title><![CDATA[Reply to Threads unter Win32 API on Wed, 02 May 2012 08:47:08 GMT]]></title><description><![CDATA[<blockquote>
<p>was einen Cursor innerhalb eines Rechtecks auf Tastendruck hin und her scheucht. Das ganze soll unter dem Passus &quot;Multithreading&quot; laufen.</p>
</blockquote>
<p>Wer bitte vergibt solche Aufgaben ???<br />
Multithreading macht nur &quot;Sinn&quot;, wenn:<br />
- Du langwierige Jobs von der Oberflaeche entkoppeln willst,<br />
- langwierige Jobs nicht durch kontinuierliches Unterbrechen und Fortsetzen im Code verschandeln willst,<br />
- oder mehrere Kerne nutzen willst / musst.</p>
<p>Bei dem beispiel ist nix dabei ^^</p>
<p>Meistens hasst noch das Problem, das deine &quot;GUI&quot; Bibliothek aufgrund einfachem (performantem) Event Implementeirung gar nicht Multithreading faehig ist, also Du gar nicht mit einem anderen thread GUI funktionen aufrufen darfst !</p>
<p>Was du verwendest sieht aus wie ne curses Biblio ... keine Ahnung wo du deren Funktionen einblendest, den Header seh ich ned ^^<br />
Und bist dir sicher das die multithreaded verwendet werden kann ?</p>
<p>Du umgehst das eigentliche Problem des multithreadings, der gemeinsammen nutzung der Daten &lt;sarkasmus on&gt; elegant &lt;sarkasmus off&gt; mit globalen variablen ^^<br />
Das die schlechteste Loesung die man haben kann ^^<br />
Und nicht mal geschuetzt. Wenn dein Programm so mal laufen sollte, wird es an und ab paar ganz putzige nicht nachvollziehbare DInge tun ^^ Wenn Glueck hasst, nur auf ganz speziellen Platformen (race conditions)</p>
<p>Mein Tipp:<br />
Fang multithreading mit was anderen an als mit zeugs was sofort auf die GUI zurueckschreiben will. Irgend ne langwierige berechnung .. oder dateien konvertieren oder sowas ...</p>
<p>Threading / Multiprozessing / assynchronitaet generell sind eher (sprachunabhaengig) komplexere Themen der Programmierung. Da sollt man sich ranwagen, wenn man richtig sattelfest beim rest ist.<br />
Es gibt viele Loesungen die sehen einfach aus, aber zu verstehen iss ne andere Sache ^^</p>
<p>Und wie gesagt, threads die nur auf andere Threads warten und selber nix langwieriges machen schaden mehr als das sie nuetzen ...</p>
<p>Ciao ...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2207452</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2207452</guid><dc:creator><![CDATA[RHBaum]]></dc:creator><pubDate>Wed, 02 May 2012 08:47:08 GMT</pubDate></item></channel></rss>