Solved

image as dialog's background

Posted on 2000-04-02
16
457 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
The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

 
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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
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.
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

803 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