|
-
August 22nd, 2008, 09:16 AM
#1
bitblt and bitmaps
i want to make a bitmap class where i can draw a bitmap on screen
but i also want to be able to undraw the bitmap, so therefore i also want to know whats underneath the bitmap
Code:
#pragma once
#include <windows.h>
class bitmap{
public:
bitmap(HWND hwnd,HINSTANCE hinstance, LPCTSTR str):
_hwnd(hwnd),
_hdc(GetDC(_hwnd)),
_hbitmap(LoadBitmap(hinstance,str)),
_hdcmem(CreateCompatibleDC(_hdc)),
_hdcunder(CreateCompatibleDC(_hdc)),
x_pos(0),
y_pos(0){
SelectObject(_hdcmem,_hbitmap);
BITMAP bitmap;
GetObject(_hbitmap,sizeof(BITMAP),&bitmap);
x_size = bitmap.bmWidth;
y_size = bitmap.bmHeight;
}
~bitmap(){
DeleteDC(_hdcmem);
ReleaseDC(_hwnd,_hdc);
}
void draw(int x, int y){
BitBlt(_hdcunder,x_pos=x,y_pos=y,x_size,y_size,_hdc,0,0,SRCCOPY);
BitBlt(_hdc,x_pos,y_pos,x_size,y_size,_hdcmem,0,0,SRCCOPY);
}
void undraw(){
BitBlt(_hdc,x_pos,y_pos,x_size,y_size,_hdcunder,0,0,SRCCOPY);
}
private:
HWND _hwnd; //windows handle
HDC _hdc; //dc for painting
HBITMAP _hbitmap; //bitmap handle
HDC _hdcmem; //bitmap memory
HDC _hdcunder; //memory fro what was under the bitmap that i drew
int x_size, //metrics of bitmap
y_size;
int x_pos,//position of bitmap for undrawing it
y_pos;
};
/what i'm trying to do is store what is underneath the position where the bitmap will be drawin to be put in _hdcunder, the draw the bitmap, then when undraw() is called it will putback the original imiage, why doesn't this work?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|