-
July 14th, 2010, 02:24 PM
#1
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.
-
July 14th, 2010, 03:30 PM
#2
Re: CPictureHolder
Where are you calling GetDC() from?
There are at least two different GetDC():
Windows APIand CWnd::GetDC Which one are you using?
Victor Nijegorodov
-
July 14th, 2010, 03:38 PM
#3
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.
-
July 15th, 2010, 05:01 AM
#4
Re: CPictureHolder
try to use this->GetDC()
or GetDC(this->hwnd)
-
July 15th, 2010, 05:07 AM
#5
Re: CPictureHolder
Originally Posted by syg19
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:
Originally Posted by VictorN
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
-
July 15th, 2010, 08:33 AM
#6
Re: CPictureHolder
"class DownloadCommand : public Command" so I would think it's not a CWnd derived class..right?
-
July 15th, 2010, 08:42 AM
#7
Re: CPictureHolder
Originally Posted by vcdebugger
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
-
July 15th, 2010, 08:42 AM
#8
Re: CPictureHolder
Originally Posted by syg19
"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
-
July 15th, 2010, 08:52 AM
#9
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
-
July 15th, 2010, 08:55 AM
#10
Re: CPictureHolder
Originally Posted by syg19
this is the command:
[code]
Where?
Victor Nijegorodov
-
July 15th, 2010, 09:31 AM
#11
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);
}
-
July 15th, 2010, 10:11 AM
#12
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.
-
July 15th, 2010, 10:17 AM
#13
Re: CPictureHolder
You must implement the message handler for WM_PAINT message in your 'CCameraControlDlg' class.
Victor Nijegorodov
-
July 15th, 2010, 10:21 AM
#14
Re: CPictureHolder
Originally Posted by VictorN
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?
-
July 15th, 2010, 10:35 AM
#15
Re: CPictureHolder
Originally Posted by syg19
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|