I'm using the CMUgraphic class and I drew this picture. However if I go to another window and then come back to the graphic windows, everything is white. I was wondering if there was anything like a Refresh function to keep the picture intact.
Draw it every time after WM_PAINT or use
BitBlt (hdcMem, 0, 0, r.right, r.bottom, hdc, 0, 0, SRCCOPY);
after you draw and
BitBlt (hdc, 0, 0, r.right, r.bottom, hdcMem, 0, 0, SRCCOPY);
every time afer WM_PAINT. But if you still have questions, please look at dev-c++ winanim example or read some windows api tutorial, just takes too long to explain everything.
tkorrovi
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
In Windows programming, every window is responsible for updating itself when it receives a WM_PAINT message. As your window gets covered and then gets revealed again your program must respond to the WM_PAINT message it receives and redraw the window.
There are 3 basic techniques:
1) Regenerate the output. Easy if the data is quite simple to reproduce.
2) Keep a record of all events made to update the window and replay them. Not so easy but necessary if the output is based on user input.
3) Maintain a virtual window (which holds a complete copy of your window in memory) and copy it back to your window every time you receive the WM_PAINT message. This is by far the easiest to implement.
BlakJak :]
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Once you have an HDC to your Window, you create a compatible memory device context by using CreateCompatibleDC. You then need to create a bitmap to use for the virtual window. You do that with CreateCompatibleBitmap providing the size of the window you are mirroring. You link the Bitmap to the memory device using SelectObject. Once that is done you can write everything to your virtual window and to your actual window. Whenever you receveive a WM_PAINT message you copy the memory window to the actual window using the BitBlt function.
There are some examples provided in Windows 98 Programming From the Ground Up. You can download the source from:
I'm using the CMUgraphic class and I drew this picture. However if I go to another window and then come back to the graphic windows, everything is white. I was wondering if there was anything like a Refresh function to keep the picture intact.
#include <iostream.h>
#include <math.h>
#include "CMUgraphicsLib\CMUgraphics.h"
//Declarations
void DrawCard();
int main()
{
DrawCard();
return 0;
}
void DrawCard()
//Purpose: Draws a Snowman
//Postcondition: Displays a picture of a snowman
{
//Asigns "card" as member function
window card(500,400,100,50);
//Changes title of the window
card.ChangeTitle("Happy Holidays!");
//Draws blackground
card.SetPen(BLACK);
card.SetBrush(BLUE);
card.DrawRectangle(-500, -400, 500, 400, FILLED);
card.SetBrush(WHITE);
card.DrawRectangle(0, 250, 500, 400, FILLED);
//Draws body of Snowman
card.SetBrush(WHITE);
card.DrawCircle(200, 300, 60, FILLED);
card.DrawCircle(200, 200, 50, FILLED);
card.DrawCircle(200, 120, 40, FILLED);
//Draws hat of Snowman
card.SetBrush(BLACK);
card.DrawRectangle(165, 100, 235, 90, FILLED);
card.DrawRectangle(175, 91, 227, 50, FILLED);
card.SetBrush(ORANGE);
card.DrawRectangle(175, 90, 227, 85, FILLED);
//Draws eyes of Snowman
card.SetBrush(BLACK);
card.DrawCircle(185, 110, 5, FILLED);
card.DrawCircle(218, 110, 5, FILLED);
//Draws nose of Snowman
card.SetBrush(ORANGE);
card.DrawTriangle(200, 130, 200, 120, 215, 125, FILLED);
//Draws smile of snowman
card.SetBrush(BLACK);
card.DrawCircle(175, 130, 5, FILLED);
card.DrawCircle(225, 130, 5, FILLED);
card.DrawCircle(187, 140, 5, FILLED);
card.DrawCircle(213, 140, 5, FILLED);
card.DrawCircle(200, 145, 5, FILLED);
//Draws buttons of Snowman
card.DrawCircle(200, 220, 5, FILLED);
card.DrawCircle(200, 200, 5, FILLED);
card.DrawCircle(200, 180, 5, FILLED);
//Draws arms of Snowman
card.DrawRectangle(250, 200, 300, 195);
card.DrawRectangle(100, 200, 150, 195);
card.DrawRectangle(295, 200, 300, 150);
card.DrawRectangle(100, 200, 105, 250);
}
If the client area needs to be redrawn, for example because the window was obscured by another, Windows sends a WM_PAINT message to the applcation.
Derek
Draw it every time after WM_PAINT or use
BitBlt (hdcMem, 0, 0, r.right, r.bottom, hdc, 0, 0, SRCCOPY);
after you draw and
BitBlt (hdc, 0, 0, r.right, r.bottom, hdcMem, 0, 0, SRCCOPY);
every time afer WM_PAINT. But if you still have questions, please look at dev-c++ winanim example or read some windows api tutorial, just takes too long to explain everything.
tkorrovi
In Windows programming, every window is responsible for updating itself when it receives a WM_PAINT message. As your window gets covered and then gets revealed again your program must respond to the WM_PAINT message it receives and redraw the window.
There are 3 basic techniques:
1) Regenerate the output. Easy if the data is quite simple to reproduce.
2) Keep a record of all events made to update the window and replay them. Not so easy but necessary if the output is based on user input.
3) Maintain a virtual window (which holds a complete copy of your window in memory) and copy it back to your window every time you receive the WM_PAINT message. This is by far the easiest to implement.
BlakJak :]
Hey, BlakJak! How do you maintain a virtual window? All the other options got me SO CONFUSED!
Once you have an HDC to your Window, you create a compatible memory device context by using CreateCompatibleDC. You then need to create a bitmap to use for the virtual window. You do that with CreateCompatibleBitmap providing the size of the window you are mirroring. You link the Bitmap to the memory device using SelectObject. Once that is done you can write everything to your virtual window and to your actual window. Whenever you receveive a WM_PAINT message you copy the memory window to the actual window using the BitBlt function.
There are some examples provided in Windows 98 Programming From the Ground Up. You can download the source from:
http://www.osborne.com/downloads/0078823064_code.zip
(You can also get Windows 2000 and Windows NT 4 examples there.)
You will need to refer to the sources from chapter 8 and search for the example starting with the comment /* Repaint using a virtual window. */
BlakJak :]