view.h文件
#include "Doc.h"
/
// Picture view is a typical scroll view.
//
class CPictureView : public CScrollView {
public:
virtual ~CPictureView();
CPictureDoc* GetDocument() { return (CPictureDoc*)m_pDocument; }
protected:
BOOL m_rcImage; // rect to display image in
UINT m_iHowScale; // how to scale image
CPictureView();
void GetImageRect(CRect& rc);
void SetScrollSizes();
virtual void OnDraw(CDC* pDC); // overridden to draw this view
virtual void OnInitialUpdate(); // called first time after construct
// command/message handlers
afx_msg void OnViewScale(UINT nID);
afx_msg void OnUpdateViewScale(CCmdUI* pCmdUI);
afx_msg BOOL OnEraseBkgnd(CDC* pDC);
afx_msg void OnSize(UINT nType, int cx, int cy);
DECLARE_DYNCREATE(CPictureView)
DECLARE_MESSAGE_MAP()
};
view.cpp
/
// View.cpp : implementation of the CPictureView class
//
#include "StdAfx.h"
#include "View.h"
#include "resource.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
// CPictureView
//
IMPLEMENT_DYNCREATE(CPictureView, CScrollView)
BEGIN_MESSAGE_MAP(CPictureView, CScrollView)
ON_WM_ERASEBKGND()
ON_WM_SIZE()
ON_COMMAND_RANGE(ID_VIEW_TOFIT, ID_VIEW100, OnViewScale)
ON_UPDATE_COMMAND_UI_RANGE(ID_VIEW_TOFIT, ID_VIEW100, OnUpdateViewScale)
END_MESSAGE_MAP()
CPictureView::CPictureView()
{
m_iHowScale = ID_VIEW_TOFIT;
}
CPictureView::~CPictureView()
{
}
void CPictureView::OnInitialUpdate()
{
SetScrollSizes();
}
//
// Set scroll sizes based on picture. Page size = client hieight/width;
// line size = 1/10 of this.
//
void CPictureView::SetScrollSizes()
{
CRect rcClient;
GetClientRect(&rcClient);
CRect rcImage;
GetImageRect(rcImage);
CSize szTotal = rcImage.Size();
CSize szPage = rcClient.Size();
CSize szLine = szPage;
szLine.cx /= 10;
szLine.cy /= 10;
CScrollView::SetScrollSizes(MM_TEXT, szTotal, szPage, szLine);
Invalidate();
}
//
// View was sized: readjust scroll sizes if I'm in "zoom to fit" mode
//
void CPictureView::OnSize(UINT nType, int cx, int cy)
{
CScrollView::OnSize(nType, cx, cy);
if (m_iHowScale==ID_VIEW_TOFIT) {
SetScrollSizes();
}
}
//
// Erase the background. This is required in case the image is smaller than
// the client area, to paint the extra background. Use clipping to avoid
// flicker.
//
BOOL CPictureView::OnEraseBkgnd(CDC* pDC)
{
CPictureDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// get client rectangle
CRect rcClient;
GetClientRect(&rcClient);
CRect rc = rcClient;
// get image rectangle
CRect rcImage;
GetImageRect(rcImage);
rc = rcImage;
CPoint pt = pDC->GetViewportOrg();
CSize sz = GetTotalSize();
// create clipping region
CRgn clipRgn;
clipRgn.CreateRectRgnIndirect(&rcClient);
pDC->SelectClipRgn(&clipRgn);
pDC->ExcludeClipRect(&rcImage);
CBrush brush(RGB(0,0,0)); // black
pDC->FillRect(&rcClient, &brush);
pDC->SelectClipRgn(NULL);
return TRUE;
}
//
// Draw the picture -- call CPicture to do it.
//
void CPictureView::OnDraw(CDC* pDC)
{
CPictureDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
CPicture* ppic = pDoc->GetPicture();
ASSERT(ppic);
if (*ppic) {
CRect rc;
GetImageRect(rc);
ppic->Render(pDC,rc);
}
}
//
// Get image rectangle, scaled for current zoom factor.
//
void CPictureView::GetImageRect(CRect& rc)
{
CPictureDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
CPicture* ppic = pDoc->GetPicture();
ASSERT(ppic);
if (!ppic || !*ppic) {
rc.SetRect(0,0,0,0);
} else if (m_iHowScale==ID_VIEW_TOFIT) {
GetClientRect(&rc);
} else {
CSize sz = ppic->GetImageSize();
switch (m_iHowScale) {
case ID_VIEW25:
sz.cx >>= 2;
sz.cy >>= 2;
break;
case ID_VIEW33:
sz.cx /= 3;
sz.cy /= 3;
break;
case ID_VIEW50:
sz.cx >>= 1;
sz.cy >>= 1;
break;
case ID_VIEW75:
sz.cx = (sz.cx * 3)/4;
sz.cy = (sz.cy * 3)/4;
break;
// case ID_VIEW100:
// sz.cx = (sz.cx * 3)/4;
// sz.cy = (sz.cy * 3)/4;
// sz.cx >>= 2;
// sz.cy >>= 2;
// break;
}
rc.SetRect(0,0,sz.cx,sz.cy);
}
}
//
// Handle zoom command.
//
void CPictureView::OnViewScale(UINT nID)
{
if (m_iHowScale != nID) {
m_iHowScale = nID;
ScrollToPosition(CPoint(0,0));
OnInitialUpdate();
}
}
//
// Update zoom menu -- check the whichever zoom factor I'm at now.
//
void CPictureView::OnUpdateViewScale(CCmdUI* pCmdUI)
{
pCmdUI->SetCheck(pCmdUI->m_nID == m_iHowScale);
}
statlink.h
// VCKBASE -- August 2000
// Compiles with Visual C++ 6.0, runs on Windows 98 and probably NT too.
//
#pragma once
//
// Simple text hyperlink derived from CString
//
class CHyperlink : public CString {
public:
CHyperlink(LPCTSTR lpLink = NULL) : CString(lpLink) { }
~CHyperlink() { }
const CHyperlink& operator=(LPCTSTR lpsz) {
CString::operator=(lpsz);
return *this;
}
operator LPCTSTR() {
return CString::operator LPCTSTR();
}
virtual HINSTANCE Navigate() {
return IsEmpty() ? NULL :
ShellExecute(0, _T("open"), *this, 0, 0, SW_SHOWNORMAL);
}
};
//
// CStaticLink implements a static control that's a hyperlink
// to any file on your desktop or web. You can use it in dialog boxes
// to create hyperlinks to web sites. When clicked, opens the file/URL
//
class CStaticLink : public CStatic {
public:
DECLARE_DYNAMIC(CStaticLink)
CStaticLink(LPCTSTR lpText = NULL, BOOL bDeleteOnDestroy=FALSE);
~CStaticLink() { }
void SetNoLink(BOOL bNoLink) {
m_bNoLink = bNoLink;
}
// Hyperlink contains URL/filename. If NULL, I will use the window text.
// (GetWindowText) to get the target.
CHyperlink m_link;
COLORREF m_color;
// Default colors you can change
// These are global, so they're the same for all links.
static COLORREF g_colorUnvisited;
static COLORREF g_colorVisited;
static COLORREF g_colorOver;
// Cursor used when mouse is on a link--you can set, or
// it will default to the standard hand with pointing finger.
// This is global, so it's the same for all links.
static HCURSOR g_hCursorLink;
protected:
CFont m_font; // underline font for text control
BOOL m_bDeleteOnDestroy; // delete object when window destroyed?
BOOL m_bOverControl; // cursor over control?
UINT m_nTimerID;
BOOL m_bNoLink;
virtual void PostNcDestroy();
// message handlers
DECLARE_MESSAGE_MAP()
afx_msg UINT OnNcHitTest(CPoint point);
afx_msg HBRUSH CtlColor(CDC* pDC, UINT nCtlColor);
afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
afx_msg BOOL OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message);
afx_msg void OnTimer( UINT nIDEvent );
};
statlink.cpp
// VCKBASE -- August 2000
// Compiles with Visual C++ 6.0, runs on Windows 98 and probably NT too.
//
// CStaticLink implements a static control that's a hyperlink
// to any file on your desktop or web. You can use it in dialog boxes
// to create hyperlinks to web sites. When clicked, opens the file/URL
//
#include "StdAfx.h"
#include "StatLink.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
COLORREF CStaticLink::g_colorUnvisited = RGB(0,0,255); // blue
COLORREF CStaticLink::g_colorVisited = RGB(128,0,128); // purple
COLORREF CStaticLink::g_colorOver = RGB(255,0,0); // Red
HCURSOR CStaticLink::g_hCursorLink = NULL;
IMPLEMENT_DYNAMIC(CStaticLink, CStatic)
BEGIN_MESSAGE_MAP(CStaticLink, CStatic)
ON_WM_NCHITTEST()
ON_WM_CTLCOLOR_REFLECT()
ON_WM_LBUTTONDOWN()
ON_WM_SETCURSOR()
ON_WM_TIMER()
END_MESSAGE_MAP()
///
// Constructor sets default colors = blue/purple.
// bDeleteOnDestroy is used internally by PixieLib in CPixieDlg.
//
CStaticLink::CStaticLink(LPCTSTR lpText, BOOL bDeleteOnDestroy)
{
m_link = lpText; // link text (NULL ==> window text)
m_color = g_colorUnvisited; // not visited yet
m_bDeleteOnDestroy = bDeleteOnDestroy; // delete object with window?
m_bOverControl = FALSE; // Cursor not yet over control
m_nTimerID = 1;
}
//
// Normally, a static control does not get mouse events unless it has
// SS_NOTIFY. This achieves the same effect as SS_NOTIFY, but it's fewer
// lines of code and more reliable than turning on SS_NOTIFY in OnCtlColor
// because Windows doesn't send WM_CTLCOLOR to bitmap static controls.
//
UINT CStaticLink::OnNcHitTest(CPoint point)
{
if (!m_bOverControl) // Cursor has just moved over control
{
m_bOverControl = TRUE;
/*
CDC* pDC = GetDC();
LOGFONT lf;
GetFont()->GetObject(sizeof(lf), &lf);
lf.lfUnderline = TRUE;
m_font.DeleteObject();
m_font.CreateFontIndirect(&lf);
// use underline font and visited/unvisited colors
pDC->SelectObject(&m_font);
*/
m_color = g_colorOver; // change color
Invalidate(); // repaint
SetTimer(m_nTimerID, 100, NULL);
}
return HTCLIENT;
}
//
// Handle reflected WM_CTLCOLOR to set custom control color.
// For a text control, use visited/unvisited colors and underline font.
// For non-text controls, do nothing. Also ensures SS_NOTIFY is on.
//
HBRUSH CStaticLink::CtlColor(CDC* pDC, UINT nCtlColor)
{
ASSERT(nCtlColor == CTLCOLOR_STATIC);
DWORD dwStyle = GetStyle();
HBRUSH hbr = NULL;
if ((dwStyle & 0xFF) <= SS_RIGHT) {
// this is a text control: set up font and colors
if (!(HFONT)m_font) {
// first time init: create font
LOGFONT lf;
GetFont()->GetObject(sizeof(lf), &lf);
// lf.lfUnderline = TRUE;
m_font.CreateFontIndirect(&lf);
}
// use underline font and visited/unvisited colors
pDC->SelectObject(&m_font);
pDC->SetTextColor(m_color);
pDC->SetBkMode(TRANSPARENT);
// return hollow brush to preserve parent background color
hbr = (HBRUSH)::GetStockObject(HOLLOW_BRUSH);
}
return hbr;
}
/
// Handle mouse click: navigate link
//
void CStaticLink::OnLButtonDown(UINT nFlags, CPoint point)
{
if (m_link.IsEmpty()) {
// no link: try to load from resource string or window text
m_link.LoadString(GetDlgCtrlID()) || (GetWindowText(m_link),1);
if (m_link.IsEmpty())
return;
}
// Call ShellExecute to run the file.
// For an URL, this means opening it in the browser.
//
HINSTANCE h = m_link.Navigate();
if ((UINT)h > 32) { // success!
m_color = g_colorVisited; // change color
Invalidate(); // repaint
} else {
MessageBeep(0); // unable to execute file!
TRACE(_T("*** WARNING: CStaticLink: unable to navigate link %s\n"),
(LPCTSTR)m_link);
}
}
void CStaticLink::OnTimer(UINT nIDEvent)
{
CPoint p(GetMessagePos());
ScreenToClient(&p);
HBRUSH hbr = NULL;
CRect rect;
GetClientRect(rect);
if (!rect.PtInRect(p))
{
m_bOverControl = FALSE;
KillTimer(m_nTimerID);
/*
CDC* pDC = GetDC();
LOGFONT lf;
GetFont()->GetObject(sizeof(lf), &lf);
lf.lfUnderline = FALSE;
m_font.DeleteObject();
m_font.CreateFontIndirect(&lf);
// use underline font and visited/unvisited colors
pDC->SelectObject(&m_font);
*/
m_color = g_colorUnvisited; // change color
Invalidate(); // repaint
rect.bottom+=10;
InvalidateRect(rect);
}
CStatic::OnTimer(nIDEvent);
}
//
// Set "hand" cursor to cue user that this is a link. If app has not set
// g_hCursorLink, then try to get the cursor from winhlp32.exe,
// resource 106, which is a pointing finger. This is a bit of a kludge,
// but it works.
//
BOOL CStaticLink::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
{
if (g_hCursorLink == NULL) {
static bTriedOnce = FALSE;
if (!bTriedOnce) {
CString windir;
//for XP
// GetSystemWindowsDirectory(windir.GetBuffer(MAX_PATH), MAX_PATH);
//for Windows 2000
GetWindowsDirectory(windir.GetBuffer(MAX_PATH), MAX_PATH);
windir.ReleaseBuffer();
windir += _T("\\winhlp32.exe");
HMODULE hModule = LoadLibrary(windir);
if (hModule) {
g_hCursorLink =
CopyCursor(::LoadCursor(hModule, MAKEINTRESOURCE(106)));
}
FreeLibrary(hModule);
bTriedOnce = TRUE;
}
}
if (g_hCursorLink) {
::SetCursor(g_hCursorLink);
return TRUE;
}
return FALSE;
}
//
// Normally, a control class is not destoyed when the window is;
// however, CPixieDlg creates static controls with "new" instead of
// as class members, so it's convenient to allow the option of destroying
// object with window. In applications where you want the object to be
// destoyed along with the window, you can call constructor with
// bDeleteOnDestroy=TRUE.
//
void CStaticLink::PostNcDestroy()
{
if (m_bDeleteOnDestroy)
delete this;
}
picture.h
// If this code works, it was written by Paul DiLascia.
// If not, I don't know who wrote it.
// Compiles with Visual C++ 6.0 for Windows 98 and probably Windows 2000 too.
// Set tabsize = 3 in your editor.
//
#pragma once
#include <atlbase.h>
//
// Picture object--encapsulates IPicture
//
class CPicture {
public:
CPicture();
~CPicture();
// Load frm various sosurces
BOOL Load(UINT nIDRes);
BOOL Load(LPCTSTR pszPathName);
BOOL Load(CFile& file);
BOOL Load(CArchive& ar);
BOOL Load(IStream* pstm);
// render to device context
BOOL Render(CDC* pDC, CRect rc=CRect(0,0,0,0),
LPCRECT prcMFBounds=NULL) const;
CSize GetImageSize(CDC* pDC=NULL) const;
operator IPicture*() {
return m_spIPicture;
}
void GetHIMETRICSize(OLE_XSIZE_HIMETRIC& cx, OLE_YSIZE_HIMETRIC& cy) const {
cx = cy = 0;
const_cast<CPicture*>(this)->m_hr = m_spIPicture->get_Width(&cx);
ASSERT(SUCCEEDED(m_hr));
const_cast<CPicture*>(this)->m_hr = m_spIPicture->get_Height(&cy);
ASSERT(SUCCEEDED(m_hr));
}
void Free() {
if (m_spIPicture) {
m_spIPicture.Release();
}
}
protected:
CComQIPtr<IPicture>m_spIPicture; // ATL smart pointer to IPicture
HRESULT m_hr; // last error code
};
picture.cpp
// If this code works, it was written by Paul DiLascia.
// If not, I don't know who wrote it.
// Compiles with Visual C++ 6.0 for Windows 98 and probably Windows 2000 too.
// Set tabsize = 3 in your editor.
//
#include "StdAfx.h"
#include "Picture.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
// CPicture implementation
//
CPicture::CPicture()
{
}
CPicture::~CPicture()
{
}
//
// Load from resource. Looks for "IMAGE" type.
//
BOOL CPicture::Load(UINT nIDRes)
{
// find resource in resource file
HINSTANCE hInst = AfxGetResourceHandle();
HRSRC hRsrc = ::FindResource(hInst,
MAKEINTRESOURCE(nIDRes),
"IMAGE"); // type
if (!hRsrc)
return FALSE;
// load resource into memory
DWORD len = SizeofResource(hInst, hRsrc);
BYTE* lpRsrc = (BYTE*)LoadResource(hInst, hRsrc);
if (!lpRsrc)
return FALSE;
// create memory file and load it
CMemFile file(lpRsrc, len);
BOOL bRet = Load(file);
FreeResource(hRsrc);
GlobalFree(lpRsrc);
return bRet;
}
//
// Load from path name.
//
BOOL CPicture::Load(LPCTSTR pszPathName)
{
CFile file;
if (!file.Open(pszPathName, CFile::modeRead|CFile::shareDenyWrite))
return FALSE;
BOOL bRet = Load(file);
file.Close();
return bRet;
}
//
// Load from CFile
//
BOOL CPicture::Load(CFile& file)
{
CArchive ar(&file, CArchive::load | CArchive::bNoFlushOnDelete);
return Load(ar);
}
//
// Load from archive--create stream and load from stream.
//
BOOL CPicture::Load(CArchive& ar)
{
CArchiveStream arcstream(&ar);
return Load((IStream*)&arcstream);
}
//
// Load from stream (IStream). This is the one that really does it: call
// OleLoadPicture to do the work.
//
BOOL CPicture::Load(IStream* pstm)
{
Free();
HRESULT hr = OleLoadPicture(pstm, 0, FALSE,
IID_IPicture, (void**)&m_spIPicture);
ASSERT(SUCCEEDED(hr) && m_spIPicture);
return TRUE;
}
//
// Render to device context. Covert to HIMETRIC for IPicture.
//
BOOL CPicture::Render(CDC* pDC, CRect rc, LPCRECT prcMFBounds) const
{
ASSERT(pDC);
if (rc.IsRectNull()) {
CSize sz = GetImageSize(pDC);
rc.right = sz.cx;
rc.bottom = sz.cy;
}
long hmWidth,hmHeight; // HIMETRIC units
GetHIMETRICSize(hmWidth, hmHeight);
m_spIPicture->Render(*pDC, rc.left, rc.top, rc.Width(), rc.Height(),
0, hmHeight, hmWidth, -hmHeight, prcMFBounds);
return TRUE;
}
//
// Get image size in pixels. Converts from HIMETRIC to device coords.
//
CSize CPicture::GetImageSize(CDC* pDC) const
{
if (!m_spIPicture)
return CSize(0,0);
LONG hmWidth, hmHeight; // HIMETRIC units
m_spIPicture->get_Width(&hmWidth);
m_spIPicture->get_Height(&hmHeight);
CSize sz(hmWidth,hmHeight);
if (pDC==NULL) {
CWindowDC dc(NULL);
dc.HIMETRICtoDP(&sz); // convert to pixels
} else {
pDC->HIMETRICtoDP(&sz);
}
return sz;
}
pictctrl.h
// If this code works, it was written by Paul DiLascia.
// If not, I don't know who wrote it.
// Compiles with Visual C++ 6.0 for Windows 98 and probably Windows 2000 too.
// Set tabsize = 3 in your editor.
//
#include "picture.h"
#include "StatLink.h"
#pragma once
//
// Class to encapsulate IPicture. This does not wrap all IPicture methods,
// only the ones I needed to implement ImgView -- feel free to add the others
// yourself.
//
class CPictureCtrl : public CStaticLink {
public:
CPictureCtrl(BOOL bAutoLoadImage=TRUE);
~CPictureCtrl();
// brainless wrappers call CPicture
BOOL LoadImage(UINT nIDRes) {
Invalidate();
return m_pict.Load(nIDRes);
}
BOOL LoadImage(LPCTSTR pszPathName) {
Invalidate();
return m_pict.Load(pszPathName);
}
BOOL LoadImage(CArchive& ar) {
Invalidate();
return m_pict.Load(ar);
}
BOOL LoadImage(IStream* pstm) {
Invalidate();
return m_pict.Load(pstm);
}
CSize GetImageSize() {
return m_pict.GetImageSize();
}
const CPicture* GetPicture() {
return &m_pict;
}
protected:
CPicture m_pict; // picture
BOOL m_bAutoLoadImage; // automatically load image w/same Ctrl ID
virtual void PreSubclassWindow();
// message handlers
afx_msg void OnPaint();
afx_msg int OnCreate(LPCREATESTRUCT lpcs);
afx_msg BOOL OnEraseBkgnd(CDC* pDC);
DECLARE_DYNAMIC(CPictureCtrl)
DECLARE_MESSAGE_MAP()
};
pictCtrl.cpp
// If this code works, it was written by Paul DiLascia.
// If not, I don't know who wrote it.
// Compiles with Visual C++ 6.0 for Windows 98 and probably Windows 2000 too.
// Set tabsize = 3 in your editor.
//
#include "StdAfx.h"
#include "PictCtrl.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
// CPictureCtrl is like a static bitmap, but displays any kind of
// image -- BMP, JPG, or GIF.
//
IMPLEMENT_DYNAMIC(CPictureCtrl, CStaticLink)
BEGIN_MESSAGE_MAP(CPictureCtrl, CStaticLink)
ON_WM_CREATE()
ON_WM_PAINT()
ON_WM_ERASEBKGND()
END_MESSAGE_MAP()
CPictureCtrl::CPictureCtrl(BOOL bAutoLoadImage)
: m_bAutoLoadImage(bAutoLoadImage)
{
}
CPictureCtrl::~CPictureCtrl()
{
}
//
// Created: load picture with same ID as me, if there is one. In theory, this
// should not be required because PreSubclassWindow is called whether the
// control is created directly or subclassed from a dialog--but for some odd
// reason unbeknowst to me, GetDlgCtrlID always returns 0 in OnCreate. Go
// figure.
//
int CPictureCtrl::OnCreate(LPCREATESTRUCT lpcs)
{
if (CStaticLink::OnCreate(lpcs)!=0)
return -1;
int nID = GetDlgCtrlID();
if (m_bAutoLoadImage && nID > 0 && !m_pict) {
LoadImage(nID);
}
return 0;
}
//
// Subclassed: load picture with same ID as me, if there is one.
//
void CPictureCtrl::PreSubclassWindow()
{
int nID = GetDlgCtrlID();
if (m_bAutoLoadImage && nID > 0 && !m_pict) {
LoadImage(nID);
}
CString s;
SetNoLink(!s.LoadString(GetDlgCtrlID()));
}
//
// Paint the picture -- override static stuff and do my own thing.
// Call CPicture to to the work.
//
void CPictureCtrl::OnPaint()
{
CPaintDC dc(this);
if (m_pict) {
CRect rcClient;
GetClientRect(&rcClient);
CRect rcImage(CPoint(0,0),m_pict.GetImageSize());
CRect rc;
rc.IntersectRect(&rcImage, &rcClient);
m_pict.Render(&dc, rc);
}
}
//
// If picture is smaller than client area, paint extra with background color.
//
BOOL CPictureCtrl::OnEraseBkgnd(CDC* pDC)
{
// get client rectangle
CRect rcClient;
GetClientRect(&rcClient);
CRect rc = rcClient;
// get image rectangle
CRect rcImage(CPoint(0,0), m_pict.GetImageSize());
// create clipping region
CRgn clipRgn;
clipRgn.CreateRectRgnIndirect(&rcClient);
pDC->SelectClipRgn(&clipRgn);
pDC->ExcludeClipRect(&rcImage);
CBrush *pBrush =
CBrush::FromHandle((HBRUSH)GetWindowLong(m_hWnd, GCL_HBRBACKGROUND));
pDC->FillRect(&rcClient, pBrush);
pDC->SelectClipRgn(NULL);
return TRUE;
}
doc.h
/
// Project:MYIMGAPP
// Author:NorthTibet
// Date:星期四, 九月 26, 2002
// Description:通过定制的C++类在MFC框架中轻松显示多种格式的图象
//
/
// Doc.h : interface of the CPictureDoc class
//
/
#pragma once
#include "Picture.h"
/
// Typical MFC doc class. Holds the picture in CPicture.
//
class CPictureDoc : public CDocument {
public:
virtual ~CPictureDoc();
virtual void Serialize(CArchive& ar);
virtual BOOL OnNewDocument();
CPicture* GetPicture() {
return &m_pict;
}
protected:
CPicture m_pict; // the picture
CPictureDoc();
DECLARE_DYNCREATE(CPictureDoc)
DECLARE_MESSAGE_MAP()
};
doc.cpp
/
// Project:MYIMGAPP
// Author:NorthTibet
// Date:星期四, 九月 26, 2002
// Description:通过定制的C++类在MFC框架中轻松显示多种格式的图象
//
/
// Doc.cpp : implementation of the CPictureDoc class
//
#include "StdAfx.h"
#include "resource.h"
#include <afxdisp.h>
#include <afxpriv2.h>
#include "Doc.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
IMPLEMENT_DYNCREATE(CPictureDoc, CDocument)
BEGIN_MESSAGE_MAP(CPictureDoc, CDocument)
END_MESSAGE_MAP()
CPictureDoc::CPictureDoc()
{
}
CPictureDoc::~CPictureDoc()
{
}
void CPictureDoc::Serialize(CArchive& ar)
{
if (ar.IsLoading()) {
VERIFY(m_pict.Load(ar));
} else {
}
}
//
// Load initial picture from resource
//
BOOL CPictureDoc::OnNewDocument()
{
m_pict.Load(IDR_MAINFRAME);
return TRUE;
}