Thread: drawing outside client area

  1. #1
    Registered User
    Join Date
    Dec 2005
    Location
    Canada
    Posts
    267

    drawing outside client area

    I'm working on a "breakout" game and everything worked fine until i tried to add in double buffering.
    I tried to take out double buffering since i couldn't get it to work and now, it draws everything from the top left corner of the screen instead of in the client area. If i leave it on for a while, things start disapearing from my screen. Any idea what could have caused this?

    [edit]ok, i found out why it was leaking GDI objects... now, how come it draws on the corner?[/edit]
    Last edited by h_howee; 03-23-2007 at 08:50 PM.

    OS: Windows 7, XUbuntu 11.10, Arch Linux
    IDE: CodeBlocks
    Compiler: GCC

  2. #2
    Captain - Lover of the C
    Join Date
    May 2005
    Posts
    341
    Show the code that draws the objects.
    Don't quote me on that... ...seriously

  3. #3
    Registered User
    Join Date
    Dec 2005
    Location
    Canada
    Posts
    267
    Code:
    void C_Graphics::DrawAll(C_Brick Bricks[])
    {
        hbr = CreateSolidBrush(RGB(0,0,0));
        RECT r;
        r = Player.Get_BallInfo();
        Ellipse(hdc, r.left, r.top, r.right, r.bottom);
        FillRect(hdc, Player.Get_PlankInfo(), hbr);
        for(int i = 0; i < 20; i++)
        {
            if (Bricks[i].Get_Life() > 0)
                FillRect(hdc, Bricks[i].Get_Info_ptr(), hbr);
        }
        DeleteObject(hbr);
    }
    
    void C_Graphics::ClearScreen()
    {
        hbr = CreateSolidBrush(RGB(255, 255, 255));
        RECT r;
        GetClientRect(g_hwnd, &r);
        FillRect(hdc, &r, hbr);
        DeleteObject(hbr);
    }

    OS: Windows 7, XUbuntu 11.10, Arch Linux
    IDE: CodeBlocks
    Compiler: GCC

  4. #4
    Captain - Lover of the C
    Join Date
    May 2005
    Posts
    341
    If g_hwnd is 0, it will not draw in your window but rather the screen as a whole.
    [edit] Actually, hdc would have to have been obtained by using 0 as the window[/edit]
    Don't quote me on that... ...seriously

  5. #5
    Registered User
    Join Date
    Dec 2005
    Location
    Canada
    Posts
    267
    Code:
        if (!g_hwnd)
            MessageBox(g_hwnd, "ERROR", "g_hwnd", MB_OK);
    Code:
        itoa((int)g_hwnd, sz_temp, 10);
        TextOut(hdc, 260, 130, sz_temp, sizeof(sz_temp));
    its not 0

    OS: Windows 7, XUbuntu 11.10, Arch Linux
    IDE: CodeBlocks
    Compiler: GCC

  6. #6
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    Please post the code where you get/create 'hdc'.

    Please post the code where you get the rectangle to draw on.

    Otherwise, guessing from the limited code supplied, you are drawing on the main screen not your apps screen.

    A conversion using ClientToScreen() might hide the problem.
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  7. #7
    Registered User
    Join Date
    Dec 2005
    Location
    Canada
    Posts
    267
    Code:
    C_Graphics::C_Graphics()
    {
        RECT ClientRect;
        GetClientRect(g_hwnd, &ClientRect); //i forgot what these were for...
        hdc = GetDC(g_hwnd);
        if (!hdc)
            MessageBox(g_hwnd, "GetDC(g_hwnd);", "ERROR", MB_OK);
    }

    OS: Windows 7, XUbuntu 11.10, Arch Linux
    IDE: CodeBlocks
    Compiler: GCC

  8. #8
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    What value is in the g_hwnd when the constructor is called?

    ie has the window/dialog been created at this point or is it still being created?

    What values are in the Client rect?

    If you use NULL (or g_hwnd == NULL) then you will get the screen rect and hdc. This would explain your drawing on the top left of the screen.

    GetDC(NULL) will not return an empty hdc, it will return the mainscreen hdc.
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  9. #9
    Registered User
    Join Date
    Dec 2005
    Location
    Canada
    Posts
    267
    Oh... I called the constructor before g_hwnd was defined
    thanks

    OS: Windows 7, XUbuntu 11.10, Arch Linux
    IDE: CodeBlocks
    Compiler: GCC

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Drawing two or more rectangles on client area.. HELP!
    By csonx_p in forum Windows Programming
    Replies: 2
    Last Post: 05-12-2008, 01:43 AM
  2. MFC: Clear Client Area
    By mrafcho001 in forum Windows Programming
    Replies: 2
    Last Post: 06-27-2005, 01:35 PM
  3. Displaying more shapes in the same client Area
    By sajeev_js in forum Windows Programming
    Replies: 1
    Last Post: 06-11-2005, 01:52 PM
  4. Problems Drawing OpenGL to the Client Area
    By Niytaan in forum Windows Programming
    Replies: 3
    Last Post: 10-27-2002, 07:15 PM
  5. Clearing the client area
    By Isometric in forum Windows Programming
    Replies: 15
    Last Post: 01-29-2002, 10:07 PM