CPictureHolder
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 16

Thread: CPictureHolder

  1. #1
    Join Date
    Jul 2010
    Posts
    14

    Question CPictureHolder

    Hello everyone,

    I see that many people have posted threads about using CPictureHolder and none of them have helped me. I would like to use this class to load a jpg from a file path and display it on my dialog. I have been trying to use the extended class that was created by someone here on codeguru and was put in an article:

    "http://www.codeguru.com/cpp/g-m/multimedia/imaging/article.php/c1589"

    Code:
    HDC hdc;
    CDC* pDC = GetDC();
    CPictureHolderEx pict;
    pict.CreateFromFile(userFileName);
    pict.Render(pDC, CRect(10,10,100,100),CRect(9,9,110,110));

    1>c:\2.7\sample\vc\cameracontrol\command\downloadcommand.h(137) : error C2660: 'GetDC' : function does not take 0 arguments

    1>c:\2.7\sample\vc\cameracontrol\command\downloadcommand.h(139) : error C2039: 'CreateFromFile' : is not a member of 'CPictureHolderEx'

    These are the two errors I have been receiving. Am I correct in thinking it is possible to load an image from a file path with this class? Can anyone offer any guidance please really need to display an image from a filepath have been trying for a week and a half now and failing.
    Last edited by syg19; July 14th, 2010 at 02:30 PM.

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    17,011

    Re: CPictureHolder

    Where are you calling GetDC() from?
    There are at least two different GetDC():
    Windows API
    HDC GetDC(HWND hWnd);
    and CWnd::GetDC
    CDC* GetDC( );
    Which one are you using?
    Victor Nijegorodov

  3. #3
    Join Date
    Jul 2010
    Posts
    14

    Re: CPictureHolder

    I'm sorry I'm pretty new to C++ so I don't really know if I had to guess I would say the 2nd one I'm developing in Microsoft Visual studio 2008 using MFC. From the code sample I'm using that I posted it looks like the CDC* one.

  4. #4
    Join Date
    May 2009
    Location
    Bengaluru, India
    Posts
    422

    Re: CPictureHolder

    try to use this->GetDC()

    or GetDC(this->hwnd)

  5. #5
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    17,011

    Re: CPictureHolder

    Quote Originally Posted by syg19 View Post
    I'm sorry I'm pretty new to C++ so I don't really know if I had to guess I would say the 2nd one I'm developing in Microsoft Visual studio 2008 using MFC. From the code sample I'm using that I posted it looks like the CDC* one.
    You haven't answer my question:
    Quote Originally Posted by VictorN View Post
    Where are you calling GetDC() from?
    In what class are you using the code you had posted? Isn't it a CWnd derived class?
    Victor Nijegorodov

  6. #6
    Join Date
    Jul 2010
    Posts
    14

    Re: CPictureHolder

    "class DownloadCommand : public Command" so I would think it's not a CWnd derived class..right?

  7. #7
    Join Date
    Jul 2010
    Posts
    14

    Re: CPictureHolder

    Quote Originally Posted by vcdebugger View Post
    try to use this->GetDC()

    or GetDC(this->hwnd)
    Those produced different errors respectively:

    GetDC() is not a member of DownloadCommand

    hwnd is not a member of DownloadCommand

  8. #8
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    17,011

    Re: CPictureHolder

    Quote Originally Posted by syg19 View Post
    "class DownloadCommand : public Command" so I would think it's not a CWnd derived class..right?
    How can we know it?
    This class Command appears to be some non-Microsoft class, so I have no idea what it is.

    But if it is not CWnd derived - then using either CDC::GetDC or ::GetDC API does not make any sense unless the correct HWND (window handle) is used (passed in ::GetDC API.
    Victor Nijegorodov

  9. #9
    Join Date
    Jul 2010
    Posts
    14

    Re: CPictureHolder

    this is the command:

    Code:
    class Command {
    
    protected:
    	..
    
    public:
    	..
    };
    Last edited by syg19; July 15th, 2010 at 09:59 AM. Reason: sorry got pulled away for a second

  10. #10
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    17,011

    Re: CPictureHolder

    Quote Originally Posted by syg19 View Post
    this is the command:

    [code]
    Where?
    Victor Nijegorodov

  11. #11
    Join Date
    Feb 2005
    Posts
    2,160

    Re: CPictureHolder

    If you're using MFC and VS2008, then you can use the built-in CImage class to do this more seamlessly.

    Highly simplified but works:

    Code:
    //in class definition:
    class CDlgAppDlg : CDialog
    {
      //...
    public:
      CImage m_MyImage;
      //...
    };
    
    
    BOOL CDlgAppDlg::OnInitDlg()
    {
      //...
      m_MyImage.Load(L"C:\\test.jpg");
      //...
    }
    
    void CDlgAppDlg::OnPaint()
    {
        CPaintDC dc(this);
        m_MyImage.BitBlt(dc,0,0);
    }

  12. #12
    Join Date
    Jul 2010
    Posts
    14

    Re: CPictureHolder

    hosie I tried usingwhat you showed but got this error

    error C2509: 'OnPaint' : member function not declared in 'CCameraControlDlg'

    Is there a specific header I need for OnPaint?
    Last edited by syg19; July 15th, 2010 at 10:14 AM.

  13. #13
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    17,011

    Re: CPictureHolder

    You must implement the message handler for WM_PAINT message in your 'CCameraControlDlg' class.
    Victor Nijegorodov

  14. #14
    Join Date
    Jul 2010
    Posts
    14

    Re: CPictureHolder

    Quote Originally Posted by VictorN View Post
    You must implement the message handler for WM_PAINT message in your 'CCameraControlDlg' class.
    First of all, thank you both for this help I really appreciate it sorry for so many questions.
    Secondly how do I implement the message handler for WM_PAINT?

  15. #15
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Posts
    11,980

    Re: CPictureHolder

    Quote Originally Posted by syg19 View Post
    First of all, thank you both for this help I really appreciate it sorry for so many questions.
    Secondly how do I implement the message handler for WM_PAINT?
    These questions indicate that your knowledge of C++, Windows and C++ is pretty sparse. You're not going to get very far just asking a bulletin board random questions because there will be a lot of them.

    I'd recommend you work through a good tutorial to get a handle on C++ and MFC basics. You're trying to run before you can walk.

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center