Problem mit Zeichnen(GDI+)



  • Hallo ich hab ein problem mit der GDI+:
    Wenn ich etwas zeichnen will bleibt der Bildschirm weiß

    #define WIN32_LEAN_AND_MEAN
    #include <windows.h>
    #include <ole2.h>
    #include <gdiplus.h>
    
    #pragma comment(lib, "kernel32.lib")
    #pragma comment(lib, "user32.lib")
    #pragma comment(lib, "gdiplus.lib")
    #define _T(x) TEXT(x)
    
    LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
    
    INT CALLBACK WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCommandLine, INT nCmdShow)
    {
       WNDCLASSEX wndc = {0};
       wndc.cbSize = sizeof(wndc);
       wndc.lpszClassName = _T("TestClass");
       wndc.lpfnWndProc = WndProc;
       wndc.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
       wndc.hIcon = LoadIcon(0, IDI_APPLICATION);
        wndc.hCursor = LoadCursor (NULL, IDC_ARROW);
    
       ULONG ul1;
       Gdiplus::GdiplusStartupInput gsi;
       gsi.GdiplusVersion = 1;
       Gdiplus::GdiplusStartupOutput gso = {0};
       Gdiplus::GdiplusStartup(&ul1, &gsi, &gso);
    
       RegisterClassEx(&wndc);
       HWND hWnd = CreateWindowEx(WS_EX_APPWINDOW, _T("TestClass"), _T("TestWindow"), WS_OVERLAPPEDWINDOW,
          CW_USEDEFAULT, CW_USEDEFAULT, 600, 600, NULL, NULL, NULL, NULL);
       ShowWindow(hWnd, SW_NORMAL);
       InvalidateRect(hWnd, NULL, TRUE);
       UpdateWindow(hWnd);
       MSG msg;
       while(GetMessage(&msg, NULL, 0, 0))
       {
          TranslateMessage(&msg);
          DispatchMessage(&msg);
       }
       UnregisterClass(wndc.lpszClassName, NULL);
    
       Gdiplus::GdiplusShutdown(ul1);
       return 0;
    }
    
    LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
    {
       using namespace Gdiplus;
       switch(msg)
       {
       case WM_CLOSE:
          DestroyWindow(hWnd);
          return 0;
       case WM_QUIT:
          PostQuitMessage(0);
          return 0;
       case WM_PAINT:
          {
             PAINTSTRUCT ps;
             BeginPaint(hWnd, &ps);
    
             Graphics* gr = new Graphics(hWnd);
             SolidBrush* br1 = new SolidBrush(Color::Red);
             SolidBrush* br2 = new SolidBrush(Color::Green);
             SolidBrush* br3 = new SolidBrush(Color::Yellow);
             SolidBrush* br4 = new SolidBrush(Color::Blue);
             gr->Clear(Color::White);
             // Nummer 1
             Rect rects1[] =
             {
                Rect(25, 25, 25, 150),
                Rect(50, 25, 50, 25),
                Rect(75, 50, 25, 50),
                Rect(50, 75, 25, 25)
             };
             gr->FillRectangles(br1, rects1, sizeof(rects1) / sizeof(Rect));
             // Nummer 2
             Rect rects2[] =
             {
                Rect(125, 25, 25, 25),
                Rect(125, 75, 25, 100)
             };
             gr->FillRectangles(br2, rects2, sizeof(rects2) / sizeof(Rect));
             // Nummer 3
             Rect rects3[] =
             {
                Rect(175, 25, 25, 100),
                Rect(200, 125, 25, 50),
                Rect(225, 25, 25, 100)
             };
             gr->FillRectangles(br3, rects3, sizeof(rects3) / sizeof(Rect));
             // Nummer 4
             Rect rects4[] =
             {
                Rect(275, 25, 25, 150)
             };
             gr->FillRectangles(br4, rects4, sizeof(rects4) / sizeof(Rect));
             PointF pts[] =
             {
                PointF(300, 75),
                PointF(300, 100),
                PointF(350, 50),
                PointF(350, 25)
             };
             gr->FillPolygon(br4, pts, sizeof(pts) / sizeof(PointF));
             pts[0].Y += 25;
             pts[1].Y += 25;
             pts[2].Y += 125;
             pts[3].Y += 125;
             gr->FillPolygon(br4, pts, sizeof(pts) / sizeof(PointF));
             // Nummer 5
             RectF rects5[] =
             {
                RectF(375, 25, 25, 150),
                RectF(400, 25, 50, 25),
                RectF(400, 87.5f, 50, 25),
                RectF(400, 150, 50, 25)
             };
             gr->FillRectangles(br1, rects5, sizeof(rects1) / sizeof(Rect));
    
             // Nummer 6
             Rect rects6[] =
             {
                Rect(25, 200, 25, 150)
             };
             gr->FillRectangles(br2, rects6, sizeof(rects4) / sizeof(Rect));
             for(int i = 0; i < 4; i++)
                pts[i].Y += 175, pts[i].X -= 250;
             gr->FillPolygon(br2, pts, sizeof(pts) / sizeof(PointF));
             pts[0].Y -= 25;
             pts[1].Y -= 25;
             pts[2].Y -= 125;
             pts[3].Y -= 125;
             gr->FillPolygon(br2, pts, sizeof(pts) / sizeof(PointF));
             // Nummer 7
             Rect rects7[] =
             {
                Rect(125, 200, 25, 150),
                Rect(150, 200, 25, 25),
                Rect(175, 200, 25, 150),
                Rect(150, 250, 25, 25)
             };
             gr->FillRectangles(br3, rects7, sizeof(rects7) / sizeof(Rect));
             // Nummer 8
             Rect rects8[] =
             {
                Rect(225, 200, 25, 150),
                Rect(300, 200, 25, 150)
             };
             gr->FillRectangles(br4, rects8, sizeof(rects8) / sizeof(Rect));
             PointF pts1[] =
             {
                PointF(250, 200),
                PointF(300, 300),
                PointF(300, 350),
                PointF(250, 250)
             };
             gr->FillPolygon(br4, pts1, sizeof(pts1) / sizeof(PointF));
             // Nummer 9
             rects8[0].X += 125;
             rects8[1].X += 125;
             for(int i = 0; i < 4; i++)
                pts1[i].X += 125;
             gr->FillRectangles(br4, rects8, sizeof(rects8) / sizeof(Rect));
             gr->FillPolygon(br4, pts1, sizeof(pts1) / sizeof(PointF));
    
             // Nummer 10
             rects8[0].X = 25;
             rects8[1].X = 100;
             rects8[0].Y += 175;
             rects8[1].Y += 175;
             for(int i = 0; i < 4; i++)
                pts1[i].X -= 325, pts1[i].Y += 175;
             gr->FillRectangles(br1, rects8, sizeof(rects8) / sizeof(Rect));
             gr->FillPolygon(br1, pts1, sizeof(pts1) / sizeof(PointF));
             // Nummer 11
             rects2[0].X = 150;
             rects2[1].X = 150;
             rects2[0].Y += 350;
             rects2[1].Y += 350;
             gr->FillRectangles(br2, rects2, sizeof(rects2) / sizeof(Rect));
             // Nummer 12
             RectF rects9[] =
             {
                RectF(200, 375, 25, 150),
                RectF(225, 375, 50, 25),
                RectF(225, 500, 50, 25)
             };
             gr->FillRectangles(br3, rects9, sizeof(rects9) / sizeof(Rect));
             // Nummer 13
             RectF rects10[] =
             {
                RectF(300, 375, 25, 150),
                RectF(325, 437, 25, 25),
                RectF(350, 375, 25, 150)
             };
             gr->FillRectangles(br4, rects10, sizeof(rects9) / sizeof(Rect));
             // Nummer 14
             RectF rects11[] =
             {
                RectF(400, 375, 75, 25),
                RectF(425, 375, 25, 150)
             };
             gr->FillRectangles(br1, rects11, sizeof(rects11) / sizeof(Rect));
             // Nummer 15
             RectF rects12[] =
             {
                RectF(500, 375, 75, 25),
                RectF(500, 400, 25, 50),
                RectF(525, 425, 50, 25),
                RectF(550, 450, 25, 50),
                RectF(500, 500, 75, 25)
             };
             gr->FillRectangles(br2, rects12, sizeof(rects12) / sizeof(Rect));
    
             delete gr;
             delete br1;
             delete br2;
             delete br3;
             delete br4;
    
             EndPaint(hWnd, &ps);
             return 0;
          }
       default:
          break;
       }
       return DefWindowProc(hWnd, msg, wParam, lParam);
    }
    

    Ich bin für jede hilfe dankbar


Anmelden zum Antworten