Solved

Painting dialog background

Posted on 2000-05-14
21
438 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
  • 11
  • 4
  • 3
  • +1
21 Comments
 

Accepted Solution

by:
ekinee earned 15 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
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Removing Flash from Website 6 68
What is Codeanywhere used for and can EE provide example of use 9 220
Lines Not Lining Up 2 78
Problem to ToolkitScriptManager 2 67
When you work with shopping cart / ecommerce relates web sites, you need to pass the certain form post details to the payment gateway process page with required details for the products items you give to order. Also you may need to track the ordered…
It's sometimes a bit tricky to use date functions in Oracle BPEL. I'll explain quickly how you can add N days to the current date. In a BPEL process this can be useful, and you can adapt it to fit your needs. First of all, let's see how to add 1 …
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…

789 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