<?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[WM_PAINT Problem]]></title><description><![CDATA[<p>hi leute,</p>
<p>hab mir ein kleines tool geschrieben, welches mir farbwerte ausgibt und pixel vergrößert darstellt.</p>
<p>Nun funktioniert es für 30 - 90 sekunden, hört dann aber auf werte zu übermitteln.</p>
<p>kann mir jmd sagen woran das liegt?</p>
<p>Hab im taskmanager beobachtet, dass das programm mit der zeit immer größer wird.<br />
Was bedeutet das, was kann ich tun?</p>
<p>danke schonmal<br />
mfg brums</p>
<p>ps: schuldigung für den codesalat <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>
<pre><code class="language-cpp">#include&lt;windows.h&gt;
#include&lt;stdlib.h&gt;
#include&lt;stdio.h&gt;
using namespace std;
/*  Declare Windows procedure  */
LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);

const int size = 30;
const int posx=194, posy=69;
HBRUSH brush;
HWND hwnd; 
POINT pos;
PAINTSTRUCT pinfo;
HDC hdc;
char szClassName[ ] = &quot;WindowsApp&quot;;
RECT rect[30];

union
{
 unsigned int 		alle;
	struct
 	{
    unsigned int    red: 8,
                    green: 8,
                    blue: 8;
	};
}BGr;

struct
{
			int 	x,
					y;
   unsigned int 	farbe;
			int		rot,
					blau, 
					gruen;
} poos[30];

inline unsigned int pgc( int x, int y, int Nr_struct)// default RGB, else ( bsp. mode = 1 ) BGR;
{

    HDC screen = GetDC(NULL);
    COLORREF farbescreen = GetPixel(screen, x , y ); // pos sollte in jedem programm sein!
	poos[Nr_struct].x = x;
	poos[Nr_struct].y = y;
	poos[Nr_struct].farbe = farbescreen;

	ReleaseDC(NULL,screen);
	return farbescreen;

}
inline unsigned int pgc_main( int x, int y, int Nr_struct)// default RGB, else ( bsp. mode = 1 ) BGR;
{

    HDC screen = GetDC(NULL);
    COLORREF farbescreen = GetPixel(screen, x , y ); // pos sollte in jedem programm sein!
	BGr.alle = farbescreen;
	poos[Nr_struct].x = x;
	poos[Nr_struct].y = y;

	poos[Nr_struct].farbe = farbescreen;
	poos[Nr_struct].rot = BGr.red;
	poos[Nr_struct].gruen = BGr.green;
	poos[Nr_struct].blau = BGr.blue;

	ReleaseDC(NULL,screen);
	return farbescreen;

}
POINT pointprev;

/*  Make the class name into a global variable  */

int WINAPI WinMain (HINSTANCE hThisInstance,
                    HINSTANCE hPrevInstance,
                    LPSTR lpszArgument,
                    int nFunsterStil)

{
                  /* This is the handle for our window */
    MSG messages;            /* Here messages to the application are saved */
    WNDCLASSEX wincl;        /* Data structure for the windowclass */

    /* The Window structure */
    wincl.hInstance = hThisInstance;
    wincl.lpszClassName = szClassName;
    wincl.lpfnWndProc = WindowProcedure;      /* This function is called by windows */
    wincl.style = CS_BYTEALIGNWINDOW	;                 /* Catch double-clicks */
    wincl.cbSize = sizeof (WNDCLASSEX);

    /* Use default icon and mouse-pointer */
    wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION);
    wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
    wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
    wincl.lpszMenuName = NULL;                 /* No menu */
    wincl.cbClsExtra = 0;                      /* No extra bytes after the window class */
    wincl.cbWndExtra = 0;                      /* structure or the window instance */
    /* Use Windows's default color as the background of the window */
    wincl.hbrBackground = (HBRUSH) COLOR_WINDOW
;

    /* Register the window class, and if it fails quit the program */
    if (!RegisterClassEx (&amp;wincl))
        return 0;

    /* The class is registered, let's create the program*/
    hwnd = CreateWindowEx (
           0,                   /* Extended possibilites for variation */
           szClassName	,         /* Classname */
           &quot;Windows App&quot;,       /* Title Text */
           WS_OVERLAPPEDWINDOW, /* default window */
           CW_USEDEFAULT,       /* Windows decides the position */
           CW_USEDEFAULT,       /* where the window ends up on the screen */
           300,                 /* The programs width */
           201,                 /* and height in pixels */
           HWND_DESKTOP,        /* The window is a child-window to desktop */
           NULL,                /* No menu */
           hThisInstance,       /* Program Instance handler */
           NULL                 /* No Window Creation data */
           );

    /* Make the window visible on the screen */
    ShowWindow (hwnd, nFunsterStil);

    /* Run the message loop. It will run until GetMessage() returns 0 */
    while (GetMessage (&amp;messages, NULL, 0, 0))
    {
        /* Translate virtual-key messages into character messages */
        TranslateMessage(&amp;messages);
        /* Send message to WindowProcedure */
        DispatchMessage(&amp;messages);
    }

    /* The program return-value is 0 - The value that PostQuitMessage() gave */
    return messages.wParam;
}

/*  This function is called by the Windows function DispatchMessage()  */

LRESULT CALLBACK WindowProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    switch (message)                  /* handle the messages */
    {
		case WM_PAINT:			

			GetCursorPos( &amp;pos );

			//---------- Mittelpunkt-----

			pgc_main( pos.x	, pos.y , 8);

			//---------- Andere ---------
			pgc( pos.x-1, pos.y-1	, 0);
			pgc( pos.x  , pos.y-1 	, 1);
			pgc( pos.x+1, pos.y-1 	, 2);
			pgc( pos.x+1, pos.y		, 3);
			pgc( pos.x+1, pos.y+1 	, 4);
			pgc( pos.x  , pos.y+1 	, 5);
			pgc( pos.x-1, pos.y+1 	, 6);
			pgc( pos.x-1, pos.y 	, 7);			

			pgc( pos.x-1, pos.y-2	, 9);
			pgc( pos.x+0, pos.y-2	, 10);
			pgc( pos.x+1, pos.y-2	, 11);
			pgc( pos.x+2, pos.y-2	, 12);
			pgc( pos.x+2, pos.y-1	, 13);
			pgc( pos.x+2, pos.y-0	, 14);
			pgc( pos.x+2, pos.y+1	, 15);
			pgc( pos.x+2, pos.y+2	, 16);
			pgc( pos.x+1, pos.y+2	, 17);
			pgc( pos.x+0, pos.y+2	, 18);
			pgc( pos.x-1, pos.y+2	, 19);
			pgc( pos.x-2, pos.y+2	, 20);
			pgc( pos.x-2, pos.y+1	, 21);
			pgc( pos.x-2, pos.y+0	, 22);
			pgc( pos.x-2, pos.y-1	, 23);
			pgc( pos.x-2, pos.y-2	, 24);

			rect[8].left = posx+1;
			rect[8].top  = posy+1;
			rect[8].right = posx+size-1;
			rect[8].bottom= posy+size-1;

			//Koordinaten
			for( int u = 0; u &lt;8; ++u)
			{				
				rect[u].left 	=posx+ (poos[8].x-poos[u].x)*-size;
				rect[u].top 	=posy+  (poos[8].y-poos[u].y)*-size;
				rect[u].right 	=rect[u].left + size ;
				rect[u].bottom 	=rect[u].top + size ;
			}			
			for( int pe = 9; pe &lt; 25; ++pe)
			{
				rect[pe].left 	=posx+ (poos[8].x-poos[pe].x)*-size;
				rect[pe].top 	=posy+  (poos[8].y-poos[pe].y)*-size;
				rect[pe].right 	=rect[pe].left + size ;
				rect[pe].bottom 	=rect[pe].top + size ;
			}

			//Bereite text vor
			char all[50],red[50], gruen[50], blau[50];
			sprintf( all, &quot;Farbe: %i                   &quot;, BGr.alle);
			sprintf( red, &quot;Rot: %i                 &quot;, BGr.red);
			sprintf( gruen, &quot;Gruen: %i                 &quot;, BGr.green);
			sprintf( blau, &quot;Blau: %i                &quot;, BGr.blue);

			 hdc= GetDC( hwnd );

			//Schreib Text
			TextOut( hdc, 10, 10, all, strlen(all));
			TextOut( hdc, 10, 30, red, strlen(red));
			TextOut( hdc, 10, 50, gruen, strlen(gruen));
			TextOut( hdc, 10, 70, blau, strlen(blau));	

			//Male Rechtecke
			for( int popo = 0; popo &lt; 25; ++popo)
			{
				brush = CreateSolidBrush( poos[popo].farbe );
				FillRect( hdc, &amp;rect[popo], brush );
			}

			//Viereck in der mitte
			for( int k = 0; k &lt; size; ++k)
			{
				SetPixel( hdc, posx, posy+k, 0);
				SetPixel( hdc, posx+k, posy, 0);
				SetPixel( hdc, posx+size-k-1, posy+size-1, 0);
				SetPixel( hdc, posx+size-1, posy+size-1-k, 0);
			}

			ReleaseDC( hwnd, hdc);
			Sleep(80);	
			return 0;

        case WM_DESTROY:
            PostQuitMessage (0);       /* send a WM_QUIT to the message queue */
            break;
        default:                      /* for messages that we don't deal with */
            return DefWindowProc(hwnd, message, wParam, lParam);
    }

    return 0;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/topic/177180/wm_paint-problem</link><generator>RSS for Node</generator><lastBuildDate>Sat, 11 Jul 2026 19:40:25 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/177180.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 28 Mar 2007 19:19:32 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to WM_PAINT Problem on Wed, 28 Mar 2007 19:19:32 GMT]]></title><description><![CDATA[<p>hi leute,</p>
<p>hab mir ein kleines tool geschrieben, welches mir farbwerte ausgibt und pixel vergrößert darstellt.</p>
<p>Nun funktioniert es für 30 - 90 sekunden, hört dann aber auf werte zu übermitteln.</p>
<p>kann mir jmd sagen woran das liegt?</p>
<p>Hab im taskmanager beobachtet, dass das programm mit der zeit immer größer wird.<br />
Was bedeutet das, was kann ich tun?</p>
<p>danke schonmal<br />
mfg brums</p>
<p>ps: schuldigung für den codesalat <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>
<pre><code class="language-cpp">#include&lt;windows.h&gt;
#include&lt;stdlib.h&gt;
#include&lt;stdio.h&gt;
using namespace std;
/*  Declare Windows procedure  */
LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);

const int size = 30;
const int posx=194, posy=69;
HBRUSH brush;
HWND hwnd; 
POINT pos;
PAINTSTRUCT pinfo;
HDC hdc;
char szClassName[ ] = &quot;WindowsApp&quot;;
RECT rect[30];

union
{
 unsigned int 		alle;
	struct
 	{
    unsigned int    red: 8,
                    green: 8,
                    blue: 8;
	};
}BGr;

struct
{
			int 	x,
					y;
   unsigned int 	farbe;
			int		rot,
					blau, 
					gruen;
} poos[30];

inline unsigned int pgc( int x, int y, int Nr_struct)// default RGB, else ( bsp. mode = 1 ) BGR;
{

    HDC screen = GetDC(NULL);
    COLORREF farbescreen = GetPixel(screen, x , y ); // pos sollte in jedem programm sein!
	poos[Nr_struct].x = x;
	poos[Nr_struct].y = y;
	poos[Nr_struct].farbe = farbescreen;

	ReleaseDC(NULL,screen);
	return farbescreen;

}
inline unsigned int pgc_main( int x, int y, int Nr_struct)// default RGB, else ( bsp. mode = 1 ) BGR;
{

    HDC screen = GetDC(NULL);
    COLORREF farbescreen = GetPixel(screen, x , y ); // pos sollte in jedem programm sein!
	BGr.alle = farbescreen;
	poos[Nr_struct].x = x;
	poos[Nr_struct].y = y;

	poos[Nr_struct].farbe = farbescreen;
	poos[Nr_struct].rot = BGr.red;
	poos[Nr_struct].gruen = BGr.green;
	poos[Nr_struct].blau = BGr.blue;

	ReleaseDC(NULL,screen);
	return farbescreen;

}
POINT pointprev;

/*  Make the class name into a global variable  */

int WINAPI WinMain (HINSTANCE hThisInstance,
                    HINSTANCE hPrevInstance,
                    LPSTR lpszArgument,
                    int nFunsterStil)

{
                  /* This is the handle for our window */
    MSG messages;            /* Here messages to the application are saved */
    WNDCLASSEX wincl;        /* Data structure for the windowclass */

    /* The Window structure */
    wincl.hInstance = hThisInstance;
    wincl.lpszClassName = szClassName;
    wincl.lpfnWndProc = WindowProcedure;      /* This function is called by windows */
    wincl.style = CS_BYTEALIGNWINDOW	;                 /* Catch double-clicks */
    wincl.cbSize = sizeof (WNDCLASSEX);

    /* Use default icon and mouse-pointer */
    wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION);
    wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
    wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
    wincl.lpszMenuName = NULL;                 /* No menu */
    wincl.cbClsExtra = 0;                      /* No extra bytes after the window class */
    wincl.cbWndExtra = 0;                      /* structure or the window instance */
    /* Use Windows's default color as the background of the window */
    wincl.hbrBackground = (HBRUSH) COLOR_WINDOW
;

    /* Register the window class, and if it fails quit the program */
    if (!RegisterClassEx (&amp;wincl))
        return 0;

    /* The class is registered, let's create the program*/
    hwnd = CreateWindowEx (
           0,                   /* Extended possibilites for variation */
           szClassName	,         /* Classname */
           &quot;Windows App&quot;,       /* Title Text */
           WS_OVERLAPPEDWINDOW, /* default window */
           CW_USEDEFAULT,       /* Windows decides the position */
           CW_USEDEFAULT,       /* where the window ends up on the screen */
           300,                 /* The programs width */
           201,                 /* and height in pixels */
           HWND_DESKTOP,        /* The window is a child-window to desktop */
           NULL,                /* No menu */
           hThisInstance,       /* Program Instance handler */
           NULL                 /* No Window Creation data */
           );

    /* Make the window visible on the screen */
    ShowWindow (hwnd, nFunsterStil);

    /* Run the message loop. It will run until GetMessage() returns 0 */
    while (GetMessage (&amp;messages, NULL, 0, 0))
    {
        /* Translate virtual-key messages into character messages */
        TranslateMessage(&amp;messages);
        /* Send message to WindowProcedure */
        DispatchMessage(&amp;messages);
    }

    /* The program return-value is 0 - The value that PostQuitMessage() gave */
    return messages.wParam;
}

/*  This function is called by the Windows function DispatchMessage()  */

LRESULT CALLBACK WindowProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    switch (message)                  /* handle the messages */
    {
		case WM_PAINT:			

			GetCursorPos( &amp;pos );

			//---------- Mittelpunkt-----

			pgc_main( pos.x	, pos.y , 8);

			//---------- Andere ---------
			pgc( pos.x-1, pos.y-1	, 0);
			pgc( pos.x  , pos.y-1 	, 1);
			pgc( pos.x+1, pos.y-1 	, 2);
			pgc( pos.x+1, pos.y		, 3);
			pgc( pos.x+1, pos.y+1 	, 4);
			pgc( pos.x  , pos.y+1 	, 5);
			pgc( pos.x-1, pos.y+1 	, 6);
			pgc( pos.x-1, pos.y 	, 7);			

			pgc( pos.x-1, pos.y-2	, 9);
			pgc( pos.x+0, pos.y-2	, 10);
			pgc( pos.x+1, pos.y-2	, 11);
			pgc( pos.x+2, pos.y-2	, 12);
			pgc( pos.x+2, pos.y-1	, 13);
			pgc( pos.x+2, pos.y-0	, 14);
			pgc( pos.x+2, pos.y+1	, 15);
			pgc( pos.x+2, pos.y+2	, 16);
			pgc( pos.x+1, pos.y+2	, 17);
			pgc( pos.x+0, pos.y+2	, 18);
			pgc( pos.x-1, pos.y+2	, 19);
			pgc( pos.x-2, pos.y+2	, 20);
			pgc( pos.x-2, pos.y+1	, 21);
			pgc( pos.x-2, pos.y+0	, 22);
			pgc( pos.x-2, pos.y-1	, 23);
			pgc( pos.x-2, pos.y-2	, 24);

			rect[8].left = posx+1;
			rect[8].top  = posy+1;
			rect[8].right = posx+size-1;
			rect[8].bottom= posy+size-1;

			//Koordinaten
			for( int u = 0; u &lt;8; ++u)
			{				
				rect[u].left 	=posx+ (poos[8].x-poos[u].x)*-size;
				rect[u].top 	=posy+  (poos[8].y-poos[u].y)*-size;
				rect[u].right 	=rect[u].left + size ;
				rect[u].bottom 	=rect[u].top + size ;
			}			
			for( int pe = 9; pe &lt; 25; ++pe)
			{
				rect[pe].left 	=posx+ (poos[8].x-poos[pe].x)*-size;
				rect[pe].top 	=posy+  (poos[8].y-poos[pe].y)*-size;
				rect[pe].right 	=rect[pe].left + size ;
				rect[pe].bottom 	=rect[pe].top + size ;
			}

			//Bereite text vor
			char all[50],red[50], gruen[50], blau[50];
			sprintf( all, &quot;Farbe: %i                   &quot;, BGr.alle);
			sprintf( red, &quot;Rot: %i                 &quot;, BGr.red);
			sprintf( gruen, &quot;Gruen: %i                 &quot;, BGr.green);
			sprintf( blau, &quot;Blau: %i                &quot;, BGr.blue);

			 hdc= GetDC( hwnd );

			//Schreib Text
			TextOut( hdc, 10, 10, all, strlen(all));
			TextOut( hdc, 10, 30, red, strlen(red));
			TextOut( hdc, 10, 50, gruen, strlen(gruen));
			TextOut( hdc, 10, 70, blau, strlen(blau));	

			//Male Rechtecke
			for( int popo = 0; popo &lt; 25; ++popo)
			{
				brush = CreateSolidBrush( poos[popo].farbe );
				FillRect( hdc, &amp;rect[popo], brush );
			}

			//Viereck in der mitte
			for( int k = 0; k &lt; size; ++k)
			{
				SetPixel( hdc, posx, posy+k, 0);
				SetPixel( hdc, posx+k, posy, 0);
				SetPixel( hdc, posx+size-k-1, posy+size-1, 0);
				SetPixel( hdc, posx+size-1, posy+size-1-k, 0);
			}

			ReleaseDC( hwnd, hdc);
			Sleep(80);	
			return 0;

        case WM_DESTROY:
            PostQuitMessage (0);       /* send a WM_QUIT to the message queue */
            break;
        default:                      /* for messages that we don't deal with */
            return DefWindowProc(hwnd, message, wParam, lParam);
    }

    return 0;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1254948</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1254948</guid><dc:creator><![CDATA[brums]]></dc:creator><pubDate>Wed, 28 Mar 2007 19:19:32 GMT</pubDate></item><item><title><![CDATA[Reply to WM_PAINT Problem on Wed, 28 Mar 2007 21:01:50 GMT]]></title><description><![CDATA[<p>Der mit CreateSolidBrush () erzeugte Brush muss nach Gebrauch wieder freigegeben werden :</p>
<pre><code class="language-cpp">//Male Rechtecke
for( int popo = 0; popo &lt; 25; ++popo)
{
 brush = CreateSolidBrush( poos[popo].farbe );
 FillRect( hdc, &amp;rect[popo], brush );
 DeleteObject (brush); // &lt;- freigeben !
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1255012</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1255012</guid><dc:creator><![CDATA[[[global:guest]]]]></dc:creator><pubDate>Wed, 28 Mar 2007 21:01:50 GMT</pubDate></item></channel></rss>