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

📄 imagedlg.cpp

📁 fish——能显示jpg格式图片的程序
💻 CPP
字号:
// imageDlg.cpp : implementation file
//

//
// Created by Douglas H Williams.
// Waterloo, Ontario, Canada
//

#include "stdafx.h"
#include "image.h"
#include "imageDlg.h"

#include <INITGUID.h> 
#include <imaging.h>
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CImageDlg dialog

CImageDlg::CImageDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CImageDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CImageDlg)
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CImageDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CImageDlg)
	DDX_Control(pDX, IDC_show, m_show);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CImageDlg, CDialog)
	//{{AFX_MSG_MAP(CImageDlg)
	ON_WM_PAINT()
	ON_WM_SIZE()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CImageDlg message handlers

BOOL CImageDlg::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

	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CImageDlg::OnPaint() 
{
    CPaintDC dc(this); // device context for painting
	
	// TODO: Add your message handler code here
	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(L"\\40.JPG", &pImage))) 
		{ 
			//CWindowDC dc(0);
			CDC dcBitmap; 
			dcBitmap.CreateCompatibleDC(&dc); 
			hResult = CreateCompatibleBitmap(dc.GetSafeHdc(), m_nWidth, m_nHeight); 
			if (hResult) { 
				HGDIOBJ hOldBitmap = dcBitmap.SelectObject(hResult); 
				//pImage->GetThumbnail(0,0,&pImage); 
				HWND hwnd=m_show.m_hWnd;
				HDC  hdc = ::GetDC(hwnd);
				pImage->Draw(hdc, CRect(0, 0, m_nWidth, m_nHeight), NULL); 
				::ReleaseDC(hwnd,hdc);
			//	pImage->Draw(dc.GetSafeHdc(), CRect(0, 0, m_nWidth, m_nHeight), NULL); 
				dcBitmap.SelectObject(hOldBitmap); 
			} 
			pImage->Release(); 
		} 
		pImgFactory->Release(); 
	} 
	CoUninitialize(); 
	// Do not call CDialog::OnPaint() for painting messages
}

void CImageDlg::OnSize(UINT nType, int cx, int cy) 
{
	CDialog::OnSize(nType, cx, cy);
	
	// TODO: Add your message handler code here
	m_nWidth = cx;
	m_nHeight = cy;

}

⌨️ 快捷键说明

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