<?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[GDI zeichnet die Objecte nicht an der richtigen Stelle ???!!!???]]></title><description><![CDATA[<p>hi,<br />
ich hab mir nen Fenster mit der allg. Formel gebastelt, und wollte nun per zufall 10 Rechtecke rein zeichen.<br />
Soweit sieht das ganze so aus</p>
<pre><code class="language-cpp">LRESULT CALLBACK WinProc( HWND hWnd, UINT message, WPARAM wParam,
                          LPARAM lParam ) {

    static int clientx, clienty;
    HDC hDC;
    PAINTSTRUCT ps;

    struct Cubes {

        bool tCrash;
        bool lCrash;
        bool rCrash;
        bool bCrash;
        int createX, createY;
    } iCubes[ NUM_RECT ];

    switch( message ) {

        case WM_CREATE: {

           clientx = LOWORD( lParam );  // get window width (450)
           clienty = HIWORD( lParam );  // get window height (300)

            for( int i = 0; i &lt; NUM_RECT; i++ ) {

                iCubes[ i ].createX = rand() % clientx;
                iCubes[ i ].createY = rand() % clienty;
            }
            return 0;
        }

        case WM_TIMER: {

            return 0;
        }

        case WM_SIZE: {

            return 0;
        }

        case WM_COMMAND: {

            return 0;
        }

        case WM_PAINT: {

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

                for( int i = 0; i &lt; NUM_RECT; i++ ) {

                        Rectangle( hDC,
                                   iCubes[ i ].createX,
                                   iCubes[ i ].createY,
                                   iCubes[ i ].createX + RECT_WIDTH,
                                   iCubes[ i ].createY + RECT_HEIGHT );
                }
                EndPaint( hWnd, &amp;ps );
            return 0;
        }

        case WM_DESTROY: {

            PostQuitMessage( 0 );
            return 0;
        }
    }
    return( DefWindowProc( hWnd, message, wParam, lParam ) );
}
</code></pre>
<p>doch irgendwie werden alle Rechtecke immer oben in der linken-ecke auf einem Haufen gezeichnet, immer an der selben Stelle. Wieso? was ist falsch?</p>
<p>Gruß Tobi.</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/172923/gdi-zeichnet-die-objecte-nicht-an-der-richtigen-stelle</link><generator>RSS for Node</generator><lastBuildDate>Mon, 13 Jul 2026 12:32:19 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/172923.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 09 Feb 2007 16:49:37 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to GDI zeichnet die Objecte nicht an der richtigen Stelle ???!!!??? on Fri, 09 Feb 2007 16:49:37 GMT]]></title><description><![CDATA[<p>hi,<br />
ich hab mir nen Fenster mit der allg. Formel gebastelt, und wollte nun per zufall 10 Rechtecke rein zeichen.<br />
Soweit sieht das ganze so aus</p>
<pre><code class="language-cpp">LRESULT CALLBACK WinProc( HWND hWnd, UINT message, WPARAM wParam,
                          LPARAM lParam ) {

    static int clientx, clienty;
    HDC hDC;
    PAINTSTRUCT ps;

    struct Cubes {

        bool tCrash;
        bool lCrash;
        bool rCrash;
        bool bCrash;
        int createX, createY;
    } iCubes[ NUM_RECT ];

    switch( message ) {

        case WM_CREATE: {

           clientx = LOWORD( lParam );  // get window width (450)
           clienty = HIWORD( lParam );  // get window height (300)

            for( int i = 0; i &lt; NUM_RECT; i++ ) {

                iCubes[ i ].createX = rand() % clientx;
                iCubes[ i ].createY = rand() % clienty;
            }
            return 0;
        }

        case WM_TIMER: {

            return 0;
        }

        case WM_SIZE: {

            return 0;
        }

        case WM_COMMAND: {

            return 0;
        }

        case WM_PAINT: {

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

                for( int i = 0; i &lt; NUM_RECT; i++ ) {

                        Rectangle( hDC,
                                   iCubes[ i ].createX,
                                   iCubes[ i ].createY,
                                   iCubes[ i ].createX + RECT_WIDTH,
                                   iCubes[ i ].createY + RECT_HEIGHT );
                }
                EndPaint( hWnd, &amp;ps );
            return 0;
        }

        case WM_DESTROY: {

            PostQuitMessage( 0 );
            return 0;
        }
    }
    return( DefWindowProc( hWnd, message, wParam, lParam ) );
}
</code></pre>
<p>doch irgendwie werden alle Rechtecke immer oben in der linken-ecke auf einem Haufen gezeichnet, immer an der selben Stelle. Wieso? was ist falsch?</p>
<p>Gruß Tobi.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1225793</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1225793</guid><dc:creator><![CDATA[T0bi]]></dc:creator><pubDate>Fri, 09 Feb 2007 16:49:37 GMT</pubDate></item><item><title><![CDATA[Reply to GDI zeichnet die Objecte nicht an der richtigen Stelle ???!!!??? on Fri, 09 Feb 2007 17:38:29 GMT]]></title><description><![CDATA[<p>In High- bzw. Low-Word von <em>WM_CREATE</em> stehen NICHT die Abmessungen Deines Client-Bereichs. Die gibts bei <em>WM_SIZE</em> (Dein WindowProc bekommt aber direkt am Anfang, nach der Bearbeitung von <em>WM_CREATE</em> eine Nachricht <em>WM_SIZE</em>).<br />
Also hier ist der Fehler:</p>
<p>T0bi schrieb:</p>
<blockquote>
<pre><code class="language-cpp">clientx = LOWORD( lParam );  // get window width (450)
clienty = HIWORD( lParam );  // get window height (300)
</code></pre>
</blockquote>
<p>Desweiteren solltest Du den Zufallsgenerator durch einen korrekten Aufruf von <em>srand()</em> initialisieren.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1225819</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1225819</guid><dc:creator><![CDATA[CodeFinder]]></dc:creator><pubDate>Fri, 09 Feb 2007 17:38:29 GMT</pubDate></item><item><title><![CDATA[Reply to GDI zeichnet die Objecte nicht an der richtigen Stelle ???!!!??? on Fri, 09 Feb 2007 18:25:20 GMT]]></title><description><![CDATA[<p>sorry des is der alpha code *g*, in meiner beta *lols* habe ich den zufallsgen bei WM_CREATE mit srand( time( 0 ) ); initialisiert. und danke so gehts jetzt.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1225834</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1225834</guid><dc:creator><![CDATA[T0bi]]></dc:creator><pubDate>Fri, 09 Feb 2007 18:25:20 GMT</pubDate></item></channel></rss>