Solved

Displaying a TBitmap

Posted on 1998-11-10
7
418 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
  • 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
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

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

Suggested Solutions

  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
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 viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
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.

820 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