Adding bitmap on the Application Mainframe

 I have an MFC application on which i need to Add a Bitmap image on the CMainFrame Class of the application [this is the requirement] , could not be able to find any relevent refernce. Pls help
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

evilrixSenior Software Engineer (Avast)Commented:
It would appear they describe it here.

Specifically, look at the last code example.

void CMDIClientWnd::OnPaint() 
   CPaintDC dc(this);
   CRect rcClient;

   CDC dcMem1; // memory DC for double buffering
   CBitmap bitmap1;
   bitmap1.CreateCompatibleBitmap(&dc, rcClient.Width(), rcClient.Height());
   CBitmap* pOldBitmap1 = dcMem1.SelectObject(&bitmap1);
   // fill memory device context with the desired brush
   dcMem1.FillRect(rcClient, &m_brush);

   CDC dcMem2; // memory DC for the bitmap to draw
   CBitmap bitmap2;
   CBitmap* pOldBitmap2 = dcMem2.SelectObject(&bitmap2);

   BITMAP bmp;
   int nWidth  = bmp.bmWidth;
   int nHeight = bmp.bmHeight;
   int x       = (rcClient.Width() / 2) - (nWidth / 2);
   int y       = (rcClient.Height() / 2) - (nHeight / 2);
   // copy the bitmap in memory device context 
   dcMem1.BitBlt(x, y, nWidth, nHeight, &dcMem2, 0, 0, SRCCOPY);

   CRect rcClip;

   nWidth  = rcClip.Width();
   nHeight = rcClip.Height();
   x       = rcClip.left;
   y       =;
   // copy memory device context in client device context
   dc.BitBlt(x, y, nWidth, nHeight, &dcMem1, x, y, SRCCOPY); 


Open in new window

I've not tried this - I don't actually have the ability to even test it - but reading through the code it looks quite reasonable and should give you a starting point to work from.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
jkribaHTSAuthor Commented:
Hi Evilrix,
  Thanks for the comment, i have tried this already but i have an existing application with multiple views in it, and i was basically trying to add one Bitmap file on the Mainframe TOP , no clues so far :(

evilrixSenior Software Engineer (Avast)Commented:
Hi jkribaHTS,

I'm really sorry but I'm probably not the best expert to help you out further with this as it's not really my area of expertise. I would suggest that you try clicking the "Request Attention" button and then asking the Moderators to review your zone assignments and to see if they can get any additional expert attention to your question. They have a number of tools they can use to do that.

I truly hope you find the solution you are looking for and I am very sorry I was not the one to be able to give it to you.

Best regards.

do you have an mdi or sdi application?

the CMainFrame is derived from CFrameWnd and normally consists out of a frame with title and system menu, a menu area and a tooltip area. it also could manage other child windows for example a tree window which allows to navigate thru documents and their views (like you have it in visual studio application).

which area do you want to place the bitmap image onto? does the image overlap other windows not belonging to the main frame?

in case of an mdi application, you should be aware that the mainframe window - though still be active - is not necessarily in the foreground but that the CChildFrame class (derived from CMDIClientWnd) which is also a "frame" window would/could take the visualization of a document-specific frame, menu and toolbar.

nevertheless the mainframe window easily could be used for to show an image at the top. you probably would not "paint" it as shown in sample code evilrix has posted, since that would be done only for a background image. a foreground image better would be shown in an own control which is child window of the main frame, if for example you want to show a logo at top-left of the frame window you would define a new area where the picture should be shown and use a frameless window for displaying the image. other areas like the title area, the menu are or the toolbar might be positioned and resized such that they fit right to the new logo image. if you already were using dockable windows, it would be easy to create a new fixed docking window in the top-left area and have an image control which is responsible for to show the image.

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
System Programming

From novice to tech pro — start learning today.