Removing an object

This is a discussion on Removing an object within the Windows Programming forums, part of the Platform Specific Boards category; ok the problem isn't that simple. 1st thing first, i had a bitmap mapped onto my client area. When i ...

  1. #1
    rEtaRD r HUMANS TOO !!! rEtard's Avatar
    Join Date
    Feb 2005
    Posts
    80

    Removing an object

    ok the problem isn't that simple.
    1st thing first, i had a bitmap mapped onto my client area. When i click a button, it will draw a text onto the bitmap and when i click another button, it will remove that text away. How can i do this without fillrect() which will create a disgusting a rectangle over my coloured bitmap. So how can i remove the text without reloading the bitmap because i realise it will cause flicker on my other buttons if pressed continuously. I don't wan to use fillrect() because the colours will collide. Can someone give me a better option ? or all the available options.
    P/S ironically, when i minimize the window and reopen it, the text disappears, so if i want to keep that text from disappearing, do i use invalidaterect() to do the job ?
    /* Have a nice day */

  2. #2
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,246
    Yes, call InvalidateRect(), and make sure you are not drawing the text in the WM_PAINT message handler. This should make your text disappear.

  3. #3
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,859
    how are you drawing the bmp to the screen?

    Have you looked at a BitBLt() with only the area the text was in?

    Have you looked at CreatePatternBrush() ?

    Or best....
    Create a buffer DC to hold the screen (create a t start, free at close).
    When you want to draw modify this DC and call for a paint (InvalidateRect(), UpdateWindow() )
    In the paint BitBlt() the buffer DC to the DC returned in the PAINTSTRUCT (over the rect flagged for painting in the PAINTSTRUCT)
    "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

  4. #4
    rEtaRD r HUMANS TOO !!! rEtard's Avatar
    Join Date
    Feb 2005
    Posts
    80
    novacain - i bitblt the bitmap onto the entire client area, i created the bitmap to be the exact size as the client are and i made a temporary DC from GetDC() to draw the text.
    Create a buffer DC to hold the screen (create a t start, free at close).
    Are you toking abt OwnDC ? at the window style or something, im sure i read about something like a global DC. is this what you meant ?
    bithub - can you tell me when do i call the invalidateRect() ? and yea i drew the text out of the WM_PAINT case. Do i call the invalidateRect() in the same function i had with the DrawText() and followed by UpdateWindow() or is there a specific UNIT msg to intercept ? i tried searching for msdn on all possible situation for restoring window as focus, but cant find anything that will help.
    /* Have a nice day */

  5. #5
    rEtaRD r HUMANS TOO !!! rEtard's Avatar
    Join Date
    Feb 2005
    Posts
    80
    Alrite Guys, i took a screenshot of my program, pls review.
    Http://geocities.com/parentaladv/uro.html
    Task1 - The main screen
    Task2 - Add Entry screen, the problem ? for instance, if i wish to display a new screen like View Entries, i wish to remove that text without ruining my Bitmap background behind, because i tried using FillRect() and it smudged an ugly white rect onto my bg, i tried something like SetBkMode(), not valid, Any ideas ??
    Task3 - View Entries screen, Same problem as Task2
    /* Have a nice day */

  6. #6
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,859
    >>Any ideas ??

    Use a static and hide it when it is not needed. ShowWindow()

    >>i created the bitmap to be the exact size as the client are and i made a temporary DC from GetDC() to draw the text.

    create the bitmap DC in the WM_CREATE or INITDIALOG msg. Make it staic or global.

    Clean it up in the WM_CLOSE msg

    Before drawing the text BitBlt() the bitmap DC to the screen (only for the area covered by the text)

    I use two DCs (plus the screen DC)

    One holds the background (DCBack)
    One holds the current screen (DCFront)
    I get one from the PAINTSTRUCT in a WM_PAINT msg (DCScreen)

    When I need to change the screen I copy the DCBack -> DCFront to reset the current screen.
    Then I draw what ever is required to the DCFront
    Then I call for a paint (InvalidateRect() UpdateWindow() )
    In the paint I copy the DCFront to the DCscreen

    >>can you tell me when do i call the invalidateRect()

    when you need a paint. Do not call in the paint handler (as it will create an infinite loop)
    "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
    rEtaRD r HUMANS TOO !!! rEtard's Avatar
    Join Date
    Feb 2005
    Posts
    80
    ok novacain, so the API doesn't offer a straightforward method of removing Text but we would have to
    1) Create a global DC for the bitmap
    2) create a temporary DC for the text
    3) when needed, BitBlt the bitmap back to "remove" the text.
    Geesh, this is gonna be troublesome.
    /* Have a nice day */

  8. #8
    rEtaRD r HUMANS TOO !!! rEtard's Avatar
    Join Date
    Feb 2005
    Posts
    80
    Alrite Novacain, im done with the problem of removing the text. Now last question for this thread, how do i redraw the lost text when i minimized the window or when the window loses its focus ( kinda like when i click any area out of my window, and it goes into a "minimized" state )
    /* Have a nice day */

  9. #9
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,859
    Close...

    1) Create a global DC for the bitmap background
    2) create a global DC for the current screen
    3) when needed, BitBlt the bitmap back and redraw the current screen.

    Then when needed you can redraw the current screen. This is done by calling for a paint. InvalidateRect() which generates a paint msg followed by UpdateWindow() which posts the msg to the app que not the OS que.

    In the paint call BeginPaint()
    Use the HDC and rect in the PAINTSTRUCT as params in a BitBlt() with the screen DC.
    Call EndPaint() to tell windows we have finished and to clean up.
    "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

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. using this as synchronization object
    By George2 in forum C# Programming
    Replies: 0
    Last Post: 03-22-2008, 08:49 AM
  2. synchronization object choosing
    By George2 in forum C# Programming
    Replies: 0
    Last Post: 03-22-2008, 05:33 AM
  3. circular doubly linked list help
    By gunnerz in forum C++ Programming
    Replies: 5
    Last Post: 04-28-2007, 09:38 PM
  4. Question on l-values.
    By Hulag in forum C++ Programming
    Replies: 6
    Last Post: 10-13-2005, 05:33 PM
  5. A question about constructors...
    By Wolve in forum C++ Programming
    Replies: 9
    Last Post: 05-04-2005, 05:24 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21