⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 showpicturedlg.cpp

📁 wince下显示JPG图像的源代码。EVC编写。
💻 CPP
字号:
// ShowPictureDlg.cpp : implementation file
//

#include "stdafx.h"
#include "ShowPicture.h"
#include "ShowPictureDlg.h"
//#include <aygshell.h>
#include <INITGUID.h> 
#include <imaging.h>

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CShowPictureDlg dialog

CShowPictureDlg::CShowPictureDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CShowPictureDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CShowPictureDlg)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CShowPictureDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CShowPictureDlg)
	DDX_Control(pDX, IDC_PICBK, m_picbk);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CShowPictureDlg, CDialog)
	//{{AFX_MSG_MAP(CShowPictureDlg)
	ON_BN_CLICKED(IDC_BROWSE, OnBrowse)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CShowPictureDlg message handlers

BOOL CShowPictureDlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	// Set the icon for this dialog.  The framework does this automatically
	//  when the application's main window is not a dialog
	SetIcon(m_hIcon, TRUE);			// Set big icon
	SetIcon(m_hIcon, FALSE);		// Set small icon
	
	CenterWindow(GetDesktopWindow());	// center to the hpc screen

	// TODO: Add extra initialization here
	
	return TRUE;  // return TRUE  unless you set the focus to a control
}



void CShowPictureDlg::OnBrowse() 
{
	// TODO: Add your control notification handler code here
	CString strImageFilePath;
	static WCHAR BASED_CODE szFilter[] = L"Support Files(*.bmp;*.jpg;*.jif;*.png)|*.bmp;*.jpg;*.jif;*.png";
	CFileDialog dlg(TRUE,NULL,NULL,OFN_FILEMUSTEXIST|OFN_HIDEREADONLY,szFilter,NULL);
	if(dlg.DoModal()==IDOK)   
	{   
		strImageFilePath =dlg.GetPathName();
	}

// 	CBitmap bitmap;
// 	bitmap.Attach(SHLoadImageFile(strImageFilePath));
// 		
// 	BITMAP bmpInfo;	
// 	bitmap.GetBitmap(&bmpInfo);
// 		
// 	CDC bitmapDC;
// 	CDC* pDC = GetDlgItem(IDC_PICBK)-> GetDC();
// 	bitmapDC.CreateCompatibleDC(pDC);
// 	CBitmap* pOldBitmap = bitmapDC.SelectObject(&bitmap);	
// 	pDC->BitBlt(0, 0, bmpInfo.bmWidth, bmpInfo.bmHeight, &bitmapDC,		
// 		0, 0, SRCCOPY);	
// 	bitmapDC.SelectObject(pOldBitmap);
// 	
//     bitmap.DeleteObject();
// }



	IImagingFactory *pImgFactory = NULL; 
	IImage *pImage = NULL; 
	CoInitializeEx(NULL, COINIT_MULTITHREADED); 
	HBITMAP hResult = 0; 
	if (SUCCEEDED(CoCreateInstance (CLSID_ImagingFactory, 
		NULL, 
		CLSCTX_INPROC_SERVER, 
		IID_IImagingFactory, 
		(void **)&pImgFactory))) 
	{ 
		if (SUCCEEDED(pImgFactory->CreateImageFromFile(strImageFilePath, &pImage))) 
		{ 
			//CWindowDC dc(0);
			CPaintDC dc(this); 
			CDC dcBitmap; 
			dcBitmap.CreateCompatibleDC(&dc); 
			hResult = CreateCompatibleBitmap(dc.GetSafeHdc(), 200, 200); 
			if (hResult) 
			{ 
				HGDIOBJ hOldBitmap = dcBitmap.SelectObject(hResult); 
				//pImage->GetThumbnail(0,0,&pImage); 
				pImage->Draw(dc.GetSafeHdc(), CRect(0, 0, 200, 200), NULL); 
				dcBitmap.SelectObject(hOldBitmap); 
			} 
			pImage->Release(); 
		} 
		pImgFactory->Release(); 
	} 
	CoUninitialize();
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -