<?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[Linien und Pixel]]></title><description><![CDATA[<p>Hallo.</p>
<p>Muß ein Programm schreiben, dass ähnlich wie Paint Linien zieht, d.h. bei gedrückter Maustaste damit startet, die Linie in Richtung der Mausbewegung zieht und beim Loslassen der Taste abschließt.</p>
<p>Das funktioniert auch. Nun möchte ich, dass bei Drücken und Loslassen der Maustaste an der gleichen Stelle, ein Pixel gezeichnet wird (ebenfalls wie in Paint). Wie kann ich das mit meinem vorhandenen Programmcode am besten umsetzen?</p>
<p>Gruß</p>
<p>seventh_son</p>
<pre><code class="language-cpp">LRESULT CALLBACK WndProc(HWND hWnd, UINT uiMessage, WPARAM wParam, LPARAM lParam) {

	static int iZaehler=0;
    struct KoordStruct {
	   int iXKoord;
	   int iYKoord;
   } static Koords [250];

	HDC hdc;
	RECT rect;
	PAINTSTRUCT ps;
	int i;

	switch (uiMessage) 
	{
	case WM_PAINT:

		hdc=BeginPaint(hWnd, &amp;ps);

		for (i=1; i&lt;=iZaehler;i=i+2)
		{	

			MoveToEx(hdc,Koords[i].iXKoord,Koords[i].iYKoord, NULL);
			LineTo(hdc,Koords[i+1].iXKoord,Koords[i+1].iYKoord);

		}
		EndPaint(hWnd, &amp;ps);
		return 0;

	 case WM_LBUTTONDOWN:
		if(iZaehler&lt;251)
		{
			iZaehler++;
			Koords[iZaehler].iXKoord=LOWORD(lParam);
			Koords[iZaehler].iYKoord=HIWORD(lParam);

			iZaehler++;

		}
		return 0;

	case WM_MOUSEMOVE:
		if (wParam &amp; MK_LBUTTON)
		{
			Koords[iZaehler].iXKoord=LOWORD(lParam);
			Koords[iZaehler].iYKoord=HIWORD(lParam);
			GetClientRect(hWnd,&amp;rect);
			InvalidateRect(hWnd,&amp;rect,TRUE);

		}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/topic/129063/linien-und-pixel</link><generator>RSS for Node</generator><lastBuildDate>Fri, 10 Jul 2026 02:46:55 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/129063.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 09 Dec 2005 19:02:22 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Linien und Pixel on Fri, 09 Dec 2005 19:02:22 GMT]]></title><description><![CDATA[<p>Hallo.</p>
<p>Muß ein Programm schreiben, dass ähnlich wie Paint Linien zieht, d.h. bei gedrückter Maustaste damit startet, die Linie in Richtung der Mausbewegung zieht und beim Loslassen der Taste abschließt.</p>
<p>Das funktioniert auch. Nun möchte ich, dass bei Drücken und Loslassen der Maustaste an der gleichen Stelle, ein Pixel gezeichnet wird (ebenfalls wie in Paint). Wie kann ich das mit meinem vorhandenen Programmcode am besten umsetzen?</p>
<p>Gruß</p>
<p>seventh_son</p>
<pre><code class="language-cpp">LRESULT CALLBACK WndProc(HWND hWnd, UINT uiMessage, WPARAM wParam, LPARAM lParam) {

	static int iZaehler=0;
    struct KoordStruct {
	   int iXKoord;
	   int iYKoord;
   } static Koords [250];

	HDC hdc;
	RECT rect;
	PAINTSTRUCT ps;
	int i;

	switch (uiMessage) 
	{
	case WM_PAINT:

		hdc=BeginPaint(hWnd, &amp;ps);

		for (i=1; i&lt;=iZaehler;i=i+2)
		{	

			MoveToEx(hdc,Koords[i].iXKoord,Koords[i].iYKoord, NULL);
			LineTo(hdc,Koords[i+1].iXKoord,Koords[i+1].iYKoord);

		}
		EndPaint(hWnd, &amp;ps);
		return 0;

	 case WM_LBUTTONDOWN:
		if(iZaehler&lt;251)
		{
			iZaehler++;
			Koords[iZaehler].iXKoord=LOWORD(lParam);
			Koords[iZaehler].iYKoord=HIWORD(lParam);

			iZaehler++;

		}
		return 0;

	case WM_MOUSEMOVE:
		if (wParam &amp; MK_LBUTTON)
		{
			Koords[iZaehler].iXKoord=LOWORD(lParam);
			Koords[iZaehler].iYKoord=HIWORD(lParam);
			GetClientRect(hWnd,&amp;rect);
			InvalidateRect(hWnd,&amp;rect,TRUE);

		}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/938404</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/938404</guid><dc:creator><![CDATA[seventh_son]]></dc:creator><pubDate>Fri, 09 Dec 2005 19:02:22 GMT</pubDate></item><item><title><![CDATA[Reply to Linien und Pixel on Sun, 11 Dec 2005 16:32:32 GMT]]></title><description><![CDATA[<p>Du könntest entweder in WM_LBUTTONDOWN nach dem zweiten iZaehler++; schon die Koordinaten für den Endpunkt setzen, oder du fängst eben auch noch WM_LBUTTONUP ab und machst das dann dort...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/939643</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/939643</guid><dc:creator><![CDATA[flenders]]></dc:creator><pubDate>Sun, 11 Dec 2005 16:32:32 GMT</pubDate></item></channel></rss>