Solved

image as dialog's background

Posted on 2000-04-02
16
454 Views
Last Modified: 2013-11-20
I urgently need detailed sample code w/ instructions on how to set an image (bmp or whatever else) as a dialog's background.

Best regards
-Stavi-
0
Comment
Question by:mitrakis
  • 9
  • 3
  • 2
  • +2
16 Comments
 

Expert Comment

by:krisp
Comment Utility
Hi mitrakis,

Say u have a dialog class CMyDlg and a bitmap added to ur resource with the ID :IDB_BITMAP1 . In the OnPaint() function of the dialog class add the following code in the else part of IsIconic loop.

--------------------------------------
void CClpbrdDlg::OnPaint()
{
   if (IsIconic())
   {
   }
   else
   {
    CPaintDC dc(this);
    int width = 100, hieght = 100;
    HBITMAP hbitmap = ::LoadBitmap  (::AfxGetInstanceHandle(), MAKEINTRESOURCE(IDB_BITMAP1));

   HDC hMemDC = ::CreateCompatibleDC (NULL);

   SelectObject(hMemDC, hbitmap);

   ::StretchBlt(dc.m_hDC, 0, 0, width, hieght, hMemDC, 0, 0, 250,250, SRCCOPY);

   ::DeleteDC(hMemDC);
   }
}

---------------------------------------
Here "width" and "hieght" can be varied to change the size of the bitmap displayed on the dialog.

Hope this will help u.

cheers

0
 
LVL 3

Author Comment

by:mitrakis
Comment Utility
Compiled without any errors...though no bitmap displayed.

Do I have to modify the dialog's properties ? (transparency or something like that ?)

-Stavi-
0
 
LVL 23

Expert Comment

by:chensu
Comment Utility
0
 
LVL 3

Author Comment

by:mitrakis
Comment Utility
chensu,

thanks for the hint at codeguru.
Though I don't want to add another 6 files to my project...
There's an alternative provided at codeguru which worked fine for me:
http://www.codeguru.com/mfc/comments/13528.shtml

Unfortunately, the dialog elements are hidden now.
Could you guys help me to solve this ?

I really appreciate the codeguru thing, but I don't want to add these files (at least not yet).

If there's no other way to manage it I'll get back to you chensu.

Thanks a lot
-Stavi-

P.S.:
Don't misunderstand me please.
Although I got an answer from chensu (which might work) I want to solve it with "a few lines" as started by krisp.
0
 
LVL 3

Author Comment

by:mitrakis
Comment Utility
This what I got so far.
It works, except that my push buttons are not shown after using the bitmap on the dialog:

BOOL CRasDemoDlg::OnInitDialog()
{
      CDialog::OnInitDialog();
      CRect rect;
      GetClientRect(&rect);
      m_static.Create(NULL,WS_VISIBLE| SS_BITMAP| SS_CENTERIMAGE, rect, this, NULL);
      m_bmp.LoadBitmap(IDB_BITMAP2);
      m_static.SetBitmap(m_bmp);
      
      SetIcon(m_hIcon, TRUE);                  // Set big icon
      SetIcon(m_hIcon, FALSE);            // Set small icon
      
      m_pRas = new CRasClient;
      UpdateData(FALSE);

      if(!FillModemCombo())
            GetDlgItem(IDC_CONNECT_BTN)->EnableWindow(FALSE);

      GetDlgItem(IDC_DISCONN_BTN)->EnableWindow(FALSE);

      return TRUE;
}

Can I redraw/refresh all the dialog's elements after setting the background ?
0
 
LVL 23

Expert Comment

by:chensu
Comment Utility
The problem of this method is that the static control occupies the entire client area of the dialog box. All the other controls and the static control are the child windows of the dialog box.

You might want to try redraw the dialog box with

RedrawWindow(&rect, NULL, RDW_INVALIDATE | RDW_UPDATENOW | RDW_ERASE);

But I doubt it will work.
0
 
LVL 3

Author Comment

by:mitrakis
Comment Utility
chensu:
Already tried RedrawWindow but it didn't work (exception occured).

I want to keep this Q open to others for a short while to get some more suggestions.
If no alternative/solution will be provided, I'll check out chensu's suggestion where I have to add some classes offered at codeguru.

Best regards
-Stavi-
0
 

Expert Comment

by:kishk91
Comment Utility
Hi...
i just use WM_ERASEBKGND message (you have to add it manualy)

in H file:
afx_msg BOOL OnEraseBkgnd(CDC* pDC) ;

in CPP:
BEGIN_MESSAGE_MAP(CFXDialog, CDialog)
      //{{AFX_MSG_MAP(CFXDialog)
       //other claass wizard messages
      //}}AFX_MSG_MAP

      ON_WM_ERASEBKGND() //your manualy added messages
END_MESSAGE_MAP()

BOOL CYourDialog::OnEraseBkgnd(CDC* pDC) //Sets the bitmap on the background
{                                                                   //draw your bitmap here...
      //use the pDC to draw
       pDC->BitBlt(.............) ;                       
      
      return TRUE;
}

just as easy....
Good luck
kishk91
0
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
LVL 3

Author Comment

by:mitrakis
Comment Utility
This is really annoying !
Added kishk's suggestion with the same result:
Bitmap is displayed correctly but other controls are hidden.

I'll appreciate any hints you can give me on this.
Or maybe I should choose chensu's way ?
-> Lost a lot of time while fiddling around with this f... bitmap ;(

Best regards
-Stavi-

<----snip---->
BOOL CRasDemoDlg::OnEraseBkgnd(CDC* pDC)
{
      pDC->BitBlt(0, 0, 0, 0, NULL, 0, 0, NULL);
      return TRUE;
}
<----snap---->
0
 
LVL 3

Author Comment

by:mitrakis
Comment Utility
Aehm...my project is annoying me...not you guys !
Just to be sure you got me :-)
0
 
LVL 1

Accepted Solution

by:
kkarunakar earned 75 total points
Comment Utility
hi there,
I am putting a bullshit idea to u..But it may work..but u have to do much things in design time...
Sorry if it looks funny..
Just put a bitmap on the dialog in design time. Put ur all controls...and make their property to transparent..if u can't see them use tab control to move and size it..it will work perfect in run time....
keshav
0
 
LVL 3

Author Comment

by:mitrakis
Comment Utility
Well, it seems that the easiest solution is always the best.
It worked !
There was not "much to do".
Adding a bitmap in ressources, adding a bitmap element in dialog, voilá...everything is visible with the bitmap set as dialog background.

I must admit that I have no idea why I tried the complicated ways first instead of beginning with the easiest one ;)

Best regards
-Stavi-

P.S.:
Of course, the static text controls are displayed with a grey background now, but this is another story...
0
 
LVL 1

Expert Comment

by:kkarunakar
Comment Utility
Hi there..
Thanks for accepting my answer..I was knowing this will work.But I think u might have enjoyed the idea..
With regards..
keshav
0
 
LVL 3

Author Comment

by:mitrakis
Comment Utility
BTW, welcome to EE keshav... :)
0
 
LVL 1

Expert Comment

by:kkarunakar
Comment Utility
what is BTW??
0
 
LVL 3

Author Comment

by:mitrakis
Comment Utility
Uh, sorry:

BTW --> "By The Way"
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

762 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

9 Experts available now in Live!

Get 1:1 Help Now