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

x
?
Solved

Painting dialog background

Posted on 2000-05-14
21
Medium Priority
?
443 Views
Last Modified: 2013-12-26
Hi, I want to know the code that I should use to fill the background of a dialog with a tiled bitmap. I want the static text's background to be transparent, and I want the dialog to paint itself without flaws. Since I can't use Paint, what is the code that I should use to paint a dialog box's background with a bitmap?
0
Comment
Question by:Owlguru
[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
  • 11
  • 4
  • 3
  • +1
21 Comments
 

Accepted Solution

by:
ekinee earned 45 total points
ID: 2810245
Why don't you use EV_WM_PAINT ...
  void EvPaint();

You get the HDC by TClientDC(*this);
Then work with your bitmaps.

To get your statics transparent you may use EV_WM_CTLCOLOR message like...

::EvCtlColor(HDC hDc,HWND hWndChild,uint ctlType)
{
   switch(ctlType) {
      case CTLCOLOR_STATIC:
          SetBkMode(hDc,TRANSPARENT);
          return (HBRUSH)GetStockObject(NULL_BRUSH);
      default:
          return TDialog::EvCtlColor(hDc,hWndChild,ctlType);
   }
}

Hope it helps to get the results.
0
 

Author Comment

by:Owlguru
ID: 2812282
ekinee:
The suggestion for EvCtlColor was good, but I'd also like to know what is the best way of displaying a bitmapped background on a dialog box.
0
 

Expert Comment

by:ekinee
ID: 2816367
OK. Here is on way to do it.
I don't know what is exactly the best way.

::EvCtlColor(HDC hDC, HWND hWndChild, uint ctlType)
{
    switch(ctlType) {
       case CTLCOLOR_DLG:
           SetBkMode(hDC, TRANSPARENT);
           return (HBRUSH)GetStockObject(WHITE_BRUSH);
       default:
               return TDialog::EvCtlColor(hDC, hWndChild, ctlType);
    }
}

::EvPaint()
{
    TBitmap bitmap1(*GetModule(), "IDB_BITMAP1");
    TMemoryDC MemDC;
    MemDC.SelectObject(bitmap1);
    TClientDC hdc(*this);
    int startX;
    int startY=0;
    int bitmapX = bitmap1.Width();
    int bitmapY = bitmap1.Height();
    int endX=GetClientRect().Width();
    int endY=GetClientRect().Height();
    while(startY<endY) {
        startX=0;
         while(startX<endX) {
          hdc.BitBlt(startX, startY, bitmapX,bitmapY, MemDC, 0, 0,SRCAND);
            startX+=bitmapX;
        }
        startY+=bitmapY;
     }
     // Send All Your Controls WM_PAINT
     static->HandleMessage(WM_PAINT);
}

NOTE that by doing this way, you don't have to do anything special with your statics. Background is set to white because if it is not, bitmaps will lose their intensity. This is because of SRCAND.
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!

 

Expert Comment

by:ekinee
ID: 2816392
.. Sorry, you have to make statics transparent also. You can do it the way I have described earlier.

Just combine them.
0
 

Expert Comment

by:ekinee
ID: 2857298
Owlguru still there. Have a comment.
0
 

Author Comment

by:Owlguru
ID: 2859879
This question is still open. You can place any comments you like. By the way, the answer you gave me does not work with my dialogs, so I'm rejecting your answer. It does weird things with bitmaps, etc.
0
 

Author Comment

by:Owlguru
ID: 2859882
Is there a way to dynamically create a mask bitmap for another bitmap using a certain colour as the transparent colour?
0
 

Expert Comment

by:SirHenry
ID: 2861038
I am convinced it works the way ekinee has pointed out. If you get weird results either there is a small oversight in the example or you have mistyped something. The principle is correct.
0
 
LVL 3

Expert Comment

by:JPM
ID: 2861635
here is some stuff not so different from ekinee 's.
example :

BmpDlg::BmpDlg(TWindow *parent, TResId resId)
      : TDialog(parent, resId)
{
  bitmap = new TBitmap(GetApplication()->GetInstance(), BITMAP_1);
}
//----------------------------------------------------------
bool BmpDlg::EvEraseBkgnd(HDC hDC)
{
//  TDC dc(hDC);
//  TBrush black(TColor::White);
//  dc.SelectObject(white);
//  dc.PatBlt(0, 0, TWindow::Attr.W, TWindow::Attr.H);
  PaintBmp();
  return true;
}
//-----------------------------------------------------
void BmpDlg::EvPaint()
{
  TWindow::EvPaint();
}
//-----------------------------------------------
void BmpDlg::PaintBmp()
{
   TClientDC dc(HWindow);
  TMemoryDC memdc(dc);
  memdc.SelectObject(*bitmap);
  // BitBlt if the sizes of the bmp are well-known
  // StrechBlt if not
  dc.BitBlt(
   0, 0,                       //destination x, y
   BITMAP_W, BITMAP_H,            //bitmap width & height
   memdc,                        //source device context
   0, 0,                         //source X,Y
   SRCCOPY);                     //raster display operation
 
  memdc.RestoreBitmap();
}
//----------------------------------------------
void BmpDlg::Paint(TDC &dc, BOOL erase, TRect& rect)
{
  TWindow::Paint(dc, erase, rect);      
}
//--------------------------------------------------------------
HBRUSH BmpDlg::EvCtlColor (HDC hdc, HWND hwndChild, UINT ctlType)
{
 TDC dc(hdc);
 switch (ctlType)
 {
   case CTLCOLOR_STATIC :
           SetBkColor ( dc , COLOR1 );
       SetTextColor( dc , TColor::White );
       SetBkMode( dc , TRANSPARENT );
      return (HBRUSH) GetStockObject( NULL_BRUSH );
   case CTLCOLOR_BTN :
           SetBkColor ( dc , COLOR1 );
           SetTextColor( dc , TColor::White );
           SetBkMode(dc , TRANSPARENT);
           return TBrush( COLOR2 );
  default :
         return TDialog::EvCtlColor( hdc, hwndChild, ctlType);
 }
}
0
 

Author Comment

by:Owlguru
ID: 2864985
Hey! Ekinee never told me about EvEraseBkgnd()!
0
 
LVL 3

Expert Comment

by:JPM
ID: 3038410
I confrm you should manage WM_ERASEBKGND to draw the bitmap.
but before, when registering your window class, use a NULL brush
WNDCLASS wc;
wc.hbrBackground = NULL; // for the background

Jean-Paul




0
 
LVL 3

Expert Comment

by:JPM
ID: 3039210
also, have a look to the TPictureWindow class and the example
examples/owl/pictwind

Jean-Paul
0
 

Author Comment

by:Owlguru
ID: 3333954
I need a method that does not screw up icons and bitmaps on the dialog box.
0
 

Author Comment

by:Owlguru
ID: 3384810
Sorry guys, I found the answer myself! It works beautifully. All you have to do is implement EvCtlColor like in the comments and suggested answer and implement EvEraseBkgnd but NOT call the default TDialog::EvEraseBkgnd as you normally would. If you leave EvEraseBkgnd blank and returns TRUE, the window's background will be transparent(using the things in the background upon creation) and no background will be painted. This leaves you with your option of painting the background. I found this out after trying out all kinds of methods (almost desperately).
0
 

Author Comment

by:Owlguru
ID: 3384830
Now I need to give someone credit... Who will it be? JPM, you've contributed with the EvEraseBkgnd. On the other hand, ekinee has also contributed with EvCtlColor... I'm waiting for your suggestions...
0
 

Expert Comment

by:SirHenry
ID: 3392433
Ask the expert exchange people to share the points.
0
 

Author Comment

by:Owlguru
ID: 3408517
SirHenry: How do I do that?
0
 

Expert Comment

by:SirHenry
ID: 3412891
Click on "Help Desk" in the top menu and look for "Community Support". There are already some other "split points" topics.
0
 

Author Comment

by:Owlguru
ID: 3418514
Comment accepted as answer
0
 

Author Comment

by:Owlguru
ID: 3418515
I have awarded you 15 points but also I'm awarding JPM 15 points (I'm splitting the points). This is just to let you know.
0
 

Author Comment

by:Owlguru
ID: 3418675
JPM, look for the split-points question (For JPM -- Q10350206)
0

Featured Post

Independent Software Vendors: 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

Most of the sites are being standardized with W3C Web Standards. W3C provides lot of web standard services to the web. They have the web specification, process and documentation for all the web standards. You can apply HTML, CSS and Accessibility st…
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

610 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