?
Solved

Displaying a TBitmap

Posted on 1998-11-10
7
Medium Priority
?
434 Views
Last Modified: 2008-01-09
I am trying to display a bitmap using TBitmap.
The program runs fine,the window is displayed,
but it does not display the bitmap. Would
someone please show me what I have done wrong.

Thanks in advance,

John.

----- Splash.h -----------
class TSplash {
protected:
    TWindow *parent;
    TBitmap *SplashBmp;
};

----- Splash.cpp --------
TSplash::TSplash(TWindow *p)
{
   parent = p;
   SplashBmp = new TBitmap(*p->GetModule(), IDB_BITMAP1);
} // Constructor

----- main.cpp -------
TCameraWindow::TCameraWindow(const char *title) :
TFrameWindow(0,title)
{
... etc
   Splash = new TSplash(this);
... etc
}

void
TCameraWindow::SetupWindow ()
{
    TFrameWindow::SetupWindow ();
    Splash->ShowWindow (SW_SHOW);

}
0
Comment
Question by:jturpin
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 
LVL 14

Accepted Solution

by:
AlexVirochovsky earned 400 total points
ID: 1177444
You Paint function must be something else:

      dc.FillRect(rect,TBrush(lColorBackClear)); //Gray
                         //display Bitmap
      TMemoryDC tdc(dc);
      RECT rectMain;
      tdc.SelectObject(SplashBmp);
      TPoint point(0, 0);
      GetClientRect(rectMain);
      dc.BitBlt(rectMain, tdc,point,SRCCOPY);
      tdc.RestoreBitmap();

Regards, Alex
0
 
LVL 14

Expert Comment

by:AlexVirochovsky
ID: 1177445
Sorry, not
  RECT rectMain; but
 TRect  rectMain; of couse!
0
 
LVL 1

Author Comment

by:jturpin
ID: 1177446
Would you please give me a bit more info, (I am just getting into c).

Would you show me how you setup dc and rect. I assume
something like:
   hdc dc;
   dc = GetDC( what do I put for hwnd ?)
   TRect rect;
   rect.x = etc......

John.

0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 14

Expert Comment

by:AlexVirochovsky
ID: 1177447
Usually, i make it in Paint function:
void TMyWin::Paint(TDC& dc, BOOL erase, TRect& rect)
{
}
Thus you can get dc and rect from Parameters.
If i must print from other place:
TDC *cdc = new TClientDC(*this);
.... //using *cdc as dc
delete cdc;
Rect can ,as in REPLY, get from  GetClientRect()
Regards, Alex
0
 
LVL 1

Author Comment

by:jturpin
ID: 1177448
Hello Alex:
I tried to implement the code you gave me. Howerver,
my TFrame window still displays correctly, but I only get a white
window that does not display a bitmap.

Can you show me what I have done wrong ?

Here is the complete splash.cpp file excluding #includes etc,
and the splash.h

---- splash.h -----
class TSplash
{
   public:
   TSplash (TWindow *p);
   ~TSplash ();
   void ShowWindow(int cmdShow);

protected:
   TWindow *parent;
   TBitmap *SplashBmp;
};

---- splash.cpp -----
TSplash::TSplash(TWindow *p)
{
   parent = p;
   SplashBmp = new TBitmap(*p->GetModule(), IDB_BITMAP1);
} // Constructor


TSplash::~TSplash ()
{
   //
} // Destructor


void
TSplash::ShowWindow(int cmdShow)
{
   TDC *cdc = new TClientDC(*parent);
   TRect rect;
   parent->GetClientRect(rect);
   TColor TC;
   cdc->FillRect(rect, TBrush(TC.LtRed)); // lColorBackClear not found
   TMemoryDC Memdc(*cdc);
   TRect rectMain;
   Memdc.SelectObject(*SplashBmp);
   TPoint point(0,0);
   parent->GetClientRect(rectMain);
   cdc->BitBlt(rectMain, Memdc, point, SRCCOPY);
   Memdc.RestoreBitmap();
//   delete dc;

} // Show Window

----------------------------

0
 
LVL 14

Expert Comment

by:AlexVirochovsky
ID: 1177449
In you text i don't see function Paint.
It must be:
class TSplash
{
   public:
   TSplash (TWindow *p);
   ~TSplash ();
   void Paint(TDC& dc, BOOL erase, TRect& rect);//bc4
   void Paint(TDC& dc, bool erase, TRect& rect);//bc5
   void MyShowWindow(void);

protected:
   TWindow *parent;
   TBitmap *SplashBmp;
};

---- splash.cpp -----
TSplash::TSplash(TWindow *p)
{
   parent = p;
   SplashBmp = new TBitmap(*p->GetModule(), IDB_BITMAP1);
} // Constructor


TSplash::~TSplash ()
{
   //
} // Destructor
   void
TSplash::Paint(TDC& /*dc*/, BOOL /*erase*/, TRect& /*rect*/)
{
  My ShowWindow();
}


void
TSplash::MyShowWindow(void)
{
   TDC *cdc = new TClientDC(*parent);
   TRect rect;
   parent->GetClientRect(rect);
   TColor TC;
   cdc->FillRect(rect, TBrush(TC.LtRed)); // lColorBackClear not found
   TMemoryDC Memdc(*cdc);
   TRect rectMain;
   Memdc.SelectObject(*SplashBmp);
   TPoint point(0,0);
   parent->GetClientRect(rectMain);
   cdc->BitBlt(rectMain, Memdc, point, SRCCOPY);
   Memdc.RestoreBitmap();
   delete cdc; //changed

} // Show Window

NOTE : see book: Tom Swan   Mastering Programming
             with Borland C++.
Regards, Alex
0
 
LVL 1

Author Comment

by:jturpin
ID: 1177450
Thank you very much Alex for your help.

I finally have it working.

I did not realize that I had to link into paint. I thought TBitmap would
be handled more like TStatic, and draw itself. I suppose TStatic
can draw itself because it descends from TWindow, whereas
TBitmap descends from TGDIObject.

Thanks again,

John.
0

Featured Post

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
Suggested Courses

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question