hi,
how can i have a bitmap with user defined background color and a rectangle drawn on that? I have created a memorydc and bitmap using CreateCompatibleDc and CreateCompatibleBitmap. Irrespective of any color, it is taking black as bitmap's bkcolor. I tried to assign the color by using FillRect. But got the same result (blak as bkcolor). My coding is given below.
class TDrawWindow : public TWindow {
public:
HDC hDC;
HDC dcMem;
HBITMAP bmMem;
TRect rcClient,r1;
TDrawWindow(TWindow* parent = 0);
protected:
bool EvEraseBkgnd(HDC);
DECLARE_RESPONSE_TABLE(TDr
awWindow);
};
DEFINE_RESPONSE_TABLE1(TDr
awWindow,T
Window)
EV_WM_PAINT,
EV_WM_ERASEBKGND,
END_RESPONSE_TABLE;
TDrawWindow::TDrawWindow(T
Window* parent) {
r1.left = 100;
r1.top = 100;
r1.bottom = 200;
r1.right = 200;
rcClient.top = 0;
rcClient.left = 0;
rcClient.bottom = 1000;
rcClient.right = 1000;
}
bool TDrawWindow::EvEraseBkgnd(
HDC) {
return true;
}
void TDrawWindow :: Paint(TDC& dc,bool,TRect &r) {
TBrush newbrush(TColor(255,0,0));
dcMem = CreateCompatibleDC(hDC);
if ((bmMem = CreateCompatibleBitmap(dc,
rcClient.Width(),rcClient.
Height()))
== NULL)
MessageBox("Cannot create compatiblebitmap","Error",
MB_OK);
SelectObject(dcMem, bmMem);
TBrush tb(RGB(255,0,0));
FillRect(dcMem,&rcClient,&
tb);
SelectObject(dcMem,newbrus
h);
Rectangle (dcMem,r1.top,r1.left,r1.b
ottom,r1.r
ight);
BitBlt(dc,rcClient.left, rcClient.top, rcClient.Width(), rcClient.Height(), dcMem, 0, 0, SRCCOPY);
}
class TDrawApp:public TApplication{
public:
TDrawApp():TApplication(){
}
void InitMainWindow(){
SetMainWindow(new TFrameWindow(0,"Test",new TDrawWindow));
}
};
int OwlMain(int,char* []){
return TDrawApp().Run();
}
Start Free Trial