Solved

Using CPictureHolder

Posted on 2002-05-04
2
594 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
ID: 6990906
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
ID: 6994461
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

840 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