Solved

Using CPictureHolder

Posted on 2002-05-04
2
579 Views
Last Modified: 2008-03-17
How to use this class to load a jpg to a Picture clip control ver 6.0 ? I need to load the file path, say C:\photos\myphoto.jpg and get it to display in the Microsoft Picture CLip Control, or another control.Any body have experience ? Thanks!
0
Comment
Question by:pigeonbr
2 Comments
 
LVL 22

Accepted Solution

by:
ambience earned 200 total points
Comment Utility
we meet again ..
you didnt try that clip control did you ? if you need a picture holder its shown below , as i had mentioned you use CPicClip too.
here is how to load a picture from a path

// On_Click()

IPicture *lPic = 0;
if(FAILED(OleLoadPicturePath(L"e:\\test.jpg", 0,0,0, IID_IPicture,(VOID**) &lPic)))
{
  AfxMessageBox ("failed to load picture");
  return ;
}

// CPicClip     m_clip;

m_clip.SetPicture((LPDISPATCH)lPic);
Invalidate();

// On_Paint

1) using picture holder


void CsomeDlg::OnPaint()
{
CPaintDC dc(this); // device context for painting
CPictureHolder hldr;
hldr.SetPictureDispatch ((IPictureDisp*)m_clip.GetPicture ().m_lpDispatch);
hldr.Render (&dc, CRect(0,0,100,100),  CRect(0,0,100,100));
}

2) without picture holder

long hmWidth;
long hmHeight;
     
hmWidth = m_clip.GetPicture ().GetWidth();
hmHeight = m_clip.GetPicture ().GetHeight();

CRect rct(0,0,100,100);
CPicture pic = m_clip.GetPicture ();

// unfortunaltely, class wizard fails to import Render so we have to resort to the following

IPicture* ipc = 0;
pic.m_lpDispatch->QueryInterface(IID_IPicture, (void**)& ipc);

ipc->Render(
     dc.GetSafeHdc (),
     0,
     0,
     100,
     100,
     0,
     0,
     hmWidth,
     hmHeight,
     (LPCRECT)rct);
ipc->Release();


this should help. note this is just to give you an idea, and placing the image or resiszing should be obvious to you.
0
 

Author Comment

by:pigeonbr
Comment Utility
ambience:
hi...sorry I don't get back to you too regularly. Ok...I looked at your code. Like I said in the previous question I'm in an ODBC dialog based app, no OnPaint etc...how do I fit in the code for creating a DC? And if there is a way, will the CRect class work, putting the rectangle of the desired sizeat the desired spot in the dialog box just like that?
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…

771 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now