コード例 #1
0
ファイル: vmsImage.cpp プロジェクト: naroya/fdm
IImgCtx* vmsImage::LoadImage(LPCSTR pszFile)
{
	IImgCtx* pImage = NULL;

	HRESULT hr = CoCreateInstance (CLSID_IImgCtx, NULL, CLSCTX_ALL,
		IID_IImgCtx, (void**)&pImage);
	if (FAILED (hr))
		return NULL;

	char szPath [MY_MAX_PATH];
	strcpy (szPath, "file://");
	strcat (szPath, pszFile);
	LPSTR psz = szPath;
	while (*psz)
	{
		if (*psz == '\\')
			*psz = '/';
		psz++;
	}

	wchar_t wszPath [MY_MAX_PATH];
	MultiByteToWideChar (CP_ACP, 0, szPath, lstrlen (szPath), wszPath, MY_MAX_PATH);
	wszPath [lstrlen (szPath)] = 0;

	hr = pImage->Load (wszPath, 0);
	if (FAILED (hr))
	{
		pImage->Release ();		
		return NULL;
	}

	DWORD dwState;
	do {

		hr = pImage->GetStateInfo (&dwState, NULL, FALSE);
		if (FAILED (hr))
		{
			pImage->Release ();
			return NULL;
		}
		if (dwState & IMGLOAD_LOADING)
			Sleep (10);

	} while(IMGLOAD_LOADING & dwState);

	if ((dwState & IMGLOAD_COMPLETE) == 0)
	{
		pImage->Release ();
		return NULL;
	}
	
	return pImage;
}
コード例 #2
0
ファイル: slideshow.cpp プロジェクト: gpg/gpg4win
static void
slide_NewImage(LPCTSTR imgPath, LPCTSTR caption, int duration)
{
#ifdef _UNICODE
  LPCWSTR imgPathW = imgPath;
#else
  WCHAR imgPathW[MAX_PATH];
  MultiByteToWideChar(CP_ACP, 0, imgPath, -1, imgPathW, _countof(imgPathW));
#endif
  IImgCtx *pImage = NULL;
  SIZE imgSize = {0, 0};
  if (SUCCEEDED(CoCreateInstance(CLSID_IImgCtx, NULL, CLSCTX_ALL, IID_IImgCtx, (void**)&pImage)))
    {
      if (SUCCEEDED(pImage->Load(imgPathW, 0)))
        {
          DWORD dwState;
          while (SUCCEEDED(pImage->GetStateInfo(&dwState, NULL, true)) && (dwState & (IMGLOAD_COMPLETE|IMGLOAD_ERROR)) == 0)
            Sleep(20);
          pImage->GetStateInfo(&dwState, &imgSize, true);
        }
      if (imgSize.cx == 0 || imgSize.cy == 0) // error path or format (IMGLOAD_ERROR)
        {
          pImage->Release();
          pImage = NULL;
        }
    }
  if (pImage == NULL)
    return;

  // fit image
  wDest = rDest.right - rDest.left;
  hDest = rDest.bottom - rDest.top;
  if (iFit == FIT_BOTH)
    iFit = (wDest*imgSize.cy > imgSize.cx*hDest) ? FIT_HEIGHT : FIT_WIDTH;
  if (iFit == FIT_HEIGHT)
    wDest = (imgSize.cx * hDest) / imgSize.cy;
  else if (iFit == FIT_WIDTH)
    hDest = (imgSize.cy * wDest) / imgSize.cx;

  // align image
  if (iHAlign == HALIGN_CENTER) rDest.left = (rDest.left + rDest.right - wDest) / 2;
  else if (iHAlign == HALIGN_RIGHT) rDest.left = rDest.right - wDest;
  if (iVAlign == VALIGN_CENTER) rDest.top  = (rDest.top + rDest.bottom - hDest) / 2;
  else if (iVAlign == VALIGN_BOTTOM) rDest.top = rDest.bottom - hDest;
  rDest.right = rDest.left + wDest;
  rDest.bottom = rDest.top + hDest;

  // create memory DC & Bitmap compatible with window's DC
  HDC hWndDC = GetDC(g_hWnd);
  g_hdcMem = CreateCompatibleDC(hWndDC);
  g_hbmMem = CreateCompatibleBitmap(hWndDC, wDest, hDest);
  ReleaseDC(g_hWnd, hWndDC);
  SelectObject(g_hdcMem, g_hbmMem);

  // paint image in memory DC
  RECT bounds = { 0, 0, wDest, hDest };
  pImage->Draw(g_hdcMem, &bounds);
  pImage->Release(); // we don't need the image anymore

  if (caption[0] != '\0')
    {
      LOGFONT lf;
      GetObject((HFONT) ::SendMessage(g_hWnd, WM_GETFONT, 0, 0), sizeof(lf), &lf);
      lf.lfHeight += lf.lfHeight/2;
      HFONT hFont = CreateFontIndirect(&lf);
      HGDIOBJ hOldFont = SelectObject(g_hdcMem, hFont);
      SetTextColor(g_hdcMem, captionColor);
      SetBkMode(g_hdcMem, TRANSPARENT);
      SetTextAlign(g_hdcMem, TA_BOTTOM|TA_CENTER|TA_NOUPDATECP);
      TextOut(g_hdcMem, wDest/2, hDest-10, caption, lstrlen(caption));
      DeleteObject(SelectObject(g_hdcMem, hOldFont));
    }

  // replace windows procedure, start time and initiate first step
  if (lpPrevWndFunc == NULL)
    lpPrevWndFunc = (WNDPROC) SetWindowLongPtr(g_hWnd, GWL_WNDPROC, (long) slide_WndProc);
  if (duration == 0)
    {
      g_step = _countof(SCA_Steps);
      InvalidateRect(g_hWnd, NULL, FALSE); // no duration => force a WM_PAINT for immediate draw of picture
      if (g_autoNext && g_autoDelay)
        SetTimer(g_hWnd, 'XFBN', g_autoDelay, NULL);
    }
  else
    {
      g_step = 0;
      slide_WndProc(g_hWnd, WM_TIMER, 'XFBN', 0); // first iteration right now
      SetTimer(g_hWnd, 'XFBN', duration/_countof(SCA_Steps), NULL);
    }
}