Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Displaying a TBitmap

Posted on 1998-11-10
7
Medium Priority
?
441 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
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

Technology Partners: 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!

Question has a verified solution.

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

What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
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 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.
Suggested Courses

609 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