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

📄 imageviewdlg.cpp

📁 wince 图片浏览
💻 CPP
字号:
// ImageViewDlg.cpp : implementation file
//

#include "stdafx.h"
#include "ImageView.h"
#include "ImageViewDlg.h"
#include "Imaging.h"
#include <imgguids.h>
#include <objbase.h>
#include "Afxdlgs.h"
#define INITGUID
#include <initguid.h>
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
IImagingFactory * pImagingFactory = NULL;
IImage * pImage = NULL;
/////////////////////////////////////////////////////////////////////////////
// CImageViewDlg dialog
DEFINE_GUID(IID_IImagingFactory, 0x327abda7,0x072b,0x11d3,0x9d,0x7b,0x00,0x00,0xf8,0x1e,0xf3,0x2e);
DEFINE_GUID(CLSID_ImagingFactory, 0x327abda8,0x072b,0x11d3,0x9d,0x7b,0x00,0x00,0xf8,0x1e,0xf3,0x2e);

CImageViewDlg::CImageViewDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CImageViewDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CImageViewDlg)
		// 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 CImageViewDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CImageViewDlg)
		// NOTE: the ClassWizard will add DDX and DDV calls here
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CImageViewDlg, CDialog)
	//{{AFX_MSG_MAP(CImageViewDlg)

	ON_BN_CLICKED(IDC_LOAD, OnLoad)
	ON_BN_CLICKED(IDC_QUIT, OnQuit)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CImageViewDlg message handlers

BOOL CImageViewDlg::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
	int cx = GetSystemMetrics(SM_CXSCREEN);
	int cy = GetSystemMetrics(SM_CYSCREEN);
	RECT rect;
	rect.left = 0;
	rect.top = 0;
	rect.right = cx;
	rect.bottom = cy;
	MoveWindow(&rect);
	HWND hwnd;
	GetDlgItem(IDC_LOAD,&hwnd);
	::MoveWindow(hwnd,cx - 50,20,40,20,TRUE);
	GetDlgItem(IDC_QUIT,&hwnd);
	::MoveWindow(hwnd,cx - 50,50,40,20,TRUE);

HRESULT hr;
	// TODO: Add extra initialization here
	if (FAILED(CoInitializeEx(NULL, COINIT_MULTITHREADED)))
	{
		return FALSE;
	}	
	   hr = CoCreateInstance(CLSID_ImagingFactory,
		   NULL,
		   CLSCTX_INPROC_SERVER,
		   IID_IImagingFactory,
		   (void**) &pImagingFactory);

	if (FAILED(hr))
		return FALSE;
	return TRUE;  // return TRUE  unless you set the focus to a control
}



LRESULT CImageViewDlg::WindowProc(UINT message, WPARAM wParam, LPARAM lParam) 
{
	// TODO: Add your specialized code here and/or call the base class
   HDC hdc;
    RECT rc;
    PAINTSTRUCT ps;
    switch(message)
    {
    case WM_PAINT:
        GetClientRect(&rc);
        hdc = ::BeginPaint(m_hWnd, &ps);
		if(pImage)
	      pImage->Draw(hdc, &rc, NULL);
        ::EndPaint(m_hWnd, &ps);
        return 0;
    case WM_DESTROY:
        PostQuitMessage(0);
        return 0;
    }
//    g_hWnd = hWnd;	
	return CDialog::WindowProc(message, wParam, lParam);
}

void CImageViewDlg::OnButton1() 
{

}

void CImageViewDlg::OnButton2() 
{

}

void CImageViewDlg::OnLoad() 
{
	// TODO: Add your control notification handler code here
	CString   strFilter = L"BMP jpg File (*.bmp)|*.bmp|(*.jpg)|*.jpg";
	CFileDialog dlgOpen(FALSE, L".bmp", NULL, OFN_HIDEREADONLY, strFilter, NULL);
	if (IDOK == dlgOpen.DoModal()) 
	{
		CString strName = dlgOpen.GetPathName();
		if (pImage)
		{
			pImage->Release();
			pImage = NULL;
		}
	HRESULT	hr = pImagingFactory->CreateImageFromFile(strName,(IImage **)&pImage);
	Invalidate();
	UpdateWindow();
	}
	
	
}

void CImageViewDlg::OnQuit() 
{
	// TODO: Add your control notification handler code here
	PostQuitMessage(0);
}

⌨️ 快捷键说明

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