Hi,

> I tried to use the IPicture interface, but I have faced a problem.
> OleLoadPicture( ) returns CTL_E_INVALIDPICTURE, and it doesn't matter what
> kind of input file is used (jpg, gif, bmp).  What can be the problem?
MSDN
> doesn't seem to show any results...

Are you using Paul Dilascia' class? Does his sample app fail to open the
pictures or just your own implementation?

You can also try this code that uses OleLoadPicturePath:


SIZE m_sizeInPix;
 SIZE m_sizeInHiMetric;
 LPPICTURE m_pPicture;


bool LoadPicture(LPCTSTR lpszPathName)
{
 // The previous image should be unloaded.
 ASSERT(m_pPicture == NULL);

 USES_CONVERSION;
 HRESULT hr =
::OleLoadPicturePath(const_cast<LPOLESTR>(T2COLE(lpszPathName)),
  NULL,
  0,
  0,
  IID_IPicture,
  reinterpret_cast<LPVOID *>(&m_pPicture));

 TRACE(_T("LoadPicturePath(\"%s\"): ")
  _T("hr = 0x%08X, m_pPicture = 0x%08X\n"), lpszPathName, hr, m_pPicture);

 if (SUCCEEDED(hr) && m_pPicture != NULL)
 {
  // get width and height of picture
  m_pPicture->get_Width(&m_sizeInHiMetric.cx);
  m_pPicture->get_Height(&m_sizeInHiMetric.cy);

  const int HIMETRIC_PER_INCH = 2540;

  HDC hDCScreen = ::GetDC(NULL);
  ASSERT(hDCScreen != NULL);
  // Pixels per logical inch along width
  const int nPixelsPerInchX = ::GetDeviceCaps(hDCScreen, LOGPIXELSX);
  // Pixels per logical inch along height
  const int nPixelsPerInchY = ::GetDeviceCaps(hDCScreen, LOGPIXELSY);
  ::ReleaseDC(NULL, hDCScreen);

  // convert himetric to pixels
  m_sizeInPix.cx = (nPixelsPerInchX * m_sizeInHiMetric.cx +
   HIMETRIC_PER_INCH / 2) / HIMETRIC_PER_INCH;
  m_sizeInPix.cy = (nPixelsPerInchY * m_sizeInHiMetric.cy +
   HIMETRIC_PER_INCH / 2) / HIMETRIC_PER_INCH;


  return TRUE;
 }
 else
 {
  // OleLoadPicturePath failed.
  CString strErrMsg;
  strErrMsg.Format(IDS_ERRLOADPIC, lpszPathName);
  ::AfxMessageBox(strErrMsg, MB_OK | MB_ICONEXCLAMATION);

  // Back to initial state

  ASSERT(m_pPicture == NULL);

  return FALSE;
 }



HTH,
Carlos






Reply via email to