Display Bitmap in a Picture Box using MFC from a file

Discussion in 'MFC' started by shabbir, Jun 9, 2005.

  1. Nishant Desai

    Nishant Desai New Member

    Joined:
    Jan 19, 2007
    Messages:
    9
    Likes Received:
    0
    Trophy Points:
    0
    Another thing i want to ask is as you wrote to change the Cstatic type to CPicture, but i dont know how to do that? please tell me how to change the variable type from CStatic to CPicture?
    Thanks,
    Nishant
     
  2. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
    I would request you to put queries into a seperate thread rather than jumping into an old thread with the queries.
     
  3. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
    By opening the .h file and renaming it.
     
  4. Nishant Desai

    Nishant Desai New Member

    Joined:
    Jan 19, 2007
    Messages:
    9
    Likes Received:
    0
    Trophy Points:
    0
    I will create the new post for my main query but just replying here for this problem, as you told me, i had change the data type of the variable to the CPictureBox, but it gave me so many errors, main of those is Storage value missing. what should i do?
     
  5. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
    You probably missed the step 4 I mentioned in the article.

    4. Change the CStatic to CPictureBox. Don't forget to add the header files at the top.

    Adding the header files should shred off your errors.
     
  6. Nishant Desai

    Nishant Desai New Member

    Joined:
    Jan 19, 2007
    Messages:
    9
    Likes Received:
    0
    Trophy Points:
    0
    Ya, i was missing that step, so when i did it, i had run it successfully.

    Thanks,
    Nishant
     
  7. lplover2k

    lplover2k New Member

    Joined:
    Feb 4, 2007
    Messages:
    15
    Likes Received:
    0
    Trophy Points:
    0
    hi there .. this tuto is intended for what version of vc++?? 6.0?? cus i don't have hte "ownerdrawn" option for the picture control..
     
  8. lplover2k

    lplover2k New Member

    Joined:
    Feb 4, 2007
    Messages:
    15
    Likes Received:
    0
    Trophy Points:
    0
    and the include in picturebox.cpp

    #include "stdafx.h"
    #include "Wallpaper.h"
    #include "PictureBox.h"
    #include ".\picturebox.h"

    -----------------------------------
    #include "Wallpaper.h"
    #include ".\picturebox.h"

    where are these 2 headers found?
     
  9. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
    The Wallpaper header files will be generated by the MS VC compiler. PictureBox.h is in the attachmet.
     
  10. lplover2k

    lplover2k New Member

    Joined:
    Feb 4, 2007
    Messages:
    15
    Likes Received:
    0
    Trophy Points:
    0
    it's not generated... i am getting error that it is missing :(
     
  11. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
    If its not generated delete the line wallpaper.h
     
  12. lplover2k

    lplover2k New Member

    Joined:
    Feb 4, 2007
    Messages:
    15
    Likes Received:
    0
    Trophy Points:
    0
    when u say "Add a picture Box to your application"
    is it the "picture" control??

    the types available for are "frame","icon","bitmap","rectangle"Enhanced metafile"... still don't see "ownerdrawn"..... and where do i inlcude "picture.h" in my dialog class?
     
  13. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
    Yes.

    Go through the tabs of the property window and you will see a checkbox of ownerdraw.
     
  14. lplover2k

    lplover2k New Member

    Joined:
    Feb 4, 2007
    Messages:
    15
    Likes Received:
    0
    Trophy Points:
    0
    there's no "ownerdraw"... neither in styles nor extended styles too...:(

    [​IMG]


    thanks for quick responses btw
     
  15. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
    You dont need to convert the style to owner draw and it will work perfectly fine. I have edited the article for the errors. Thanks for pointing that out.
     
  16. lplover2k

    lplover2k New Member

    Joined:
    Feb 4, 2007
    Messages:
    15
    Likes Received:
    0
    Trophy Points:
    0
    thanks very much!!! i have finally managed to use it!!! this is a great piece of code !!! it's the simplest method to load bitmap!!! thanks !!!

    i am glad i was helpful for your code correction :)

    one question is there a way to load jpeg??
     
  17. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
    You need GDI for that. I am planning to write one article on that but its lack of time at this moment.
     
  18. lplover2k

    lplover2k New Member

    Joined:
    Feb 4, 2007
    Messages:
    15
    Likes Received:
    0
    Trophy Points:
    0
    cool i am impatient :) and thaNKs again
     
  19. abdul_khathar

    abdul_khathar New Member

    Joined:
    Nov 28, 2006
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    software Engineer
    Location:
    coimbatore, INDIA
    how Display jpeg Picture in MFC dialog?

    hi Shabbir!

    In MFC application (Dialog based or Cform view), if i load bitmap image in the background, its taking more memory.. here is my coding..
    Code:
    void CDlg_Splash::OnPaint() 
    {
    	CPaintDC dc(this); // device context for painting
    	
    	HBITMAP m_Bmap;
    	CRect rect;
    	HDC memdc;
    	
    	CString m_ifilename1;
    	
    	m_ifilename1 = "C:\\test.bmp";
    	
    	GetClientRect(&rect);
    	
    	m_Bmap=(HBITMAP)::LoadImage(NULL,m_ifilename1,IMAGE_BITMAP,0,0,LR_LOADFROMFILE);
    	memdc=::CreateCompatibleDC(dc.m_hDC);
    	::SelectObject(memdc,m_Bmap);
    	
    	BitBlt(dc.m_hDC,0,0,rect.right,rect.bottom,memdc,0,0,SRCCOPY); 
    	DeleteObject(m_Bmap);
    	DeleteObject(memdc);
    }
    is it correct ? and also let me know is there any memory leakage?
    is it possible to load jpeg image in MFC dialog? (to avoid more memory usage)

    Thanks in Advance...





    Abdul Khathar A
     
    Last edited by a moderator: Aug 9, 2007
  20. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
    You don't need to load the image in the Paint but can have the image loaded in the constructor and just display / Paint in the OnPaint
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice