Solved

Displaying a TBitmap

Posted on 1998-11-10
7
401 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
Comment Utility
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
Comment Utility
Sorry, not
  RECT rectMain; but
 TRect  rectMain; of couse!
0
 
LVL 1

Author Comment

by:jturpin
Comment Utility
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 14

Expert Comment

by:AlexVirochovsky
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
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…
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.

772 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now