Solved

Displaying a TBitmap

Posted on 1998-11-10
7
429 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 100 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

Enroll in June's Course of the Month

June's Course of the Month is now available! Every 10 seconds, a consumer gets hit with ransomware. Refresh your knowledge of ransomware best practices by enrolling in this month's complimentary course for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

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

Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

690 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