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
Solved

image as dialog's background

Posted on 2000-04-02
16
460 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
ID: 2677496
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
ID: 2677728
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
ID: 2677924
0
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
LVL 3

Author Comment

by:mitrakis
ID: 2678054
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
ID: 2678066
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
ID: 2678143
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
ID: 2679333
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
ID: 2679487
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
 
LVL 3

Author Comment

by:mitrakis
ID: 2680957
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
ID: 2680990
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
ID: 2681661
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
ID: 2684130
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
ID: 2684384
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
ID: 2684658
BTW, welcome to EE keshav... :)
0
 
LVL 1

Expert Comment

by:kkarunakar
ID: 2684687
what is BTW??
0
 
LVL 3

Author Comment

by:mitrakis
ID: 2684787
Uh, sorry:

BTW --> "By The Way"
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone 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
Installing Microsoft R server on REDHAT or SUSE Linux 4 147
how do i create updater to My Activex application? 3 96
sum13 challenge 24 123
mapAB Challlenge 35 158
This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
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…
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.

829 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