救命呀!如何在CScrollVIew中显示比屏幕还大的图片?

sungp5211 2003-11-30 08:37:50
众位大虾帮帮忙!我想在CScrollView中显示一个比屏幕大的图片,通过拖动Scrollbar来看。我该如何做?如果能提供源码或链接更好!急呀!
...全文
180 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
osborn 2003-12-01
  • 打赏
  • 举报
回复

// ImageEditDoc.h : interface of the CImageEditDoc class
//
/////////////////////////////////////////////////////////////////////////////

#if !defined(AFX_IMAGEEDITDOC_H__9D77AEEA_AA14_11D2_8E53_006008A82731__INCLUDED_)
#define AFX_IMAGEEDITDOC_H__9D77AEEA_AA14_11D2_8E53_006008A82731__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

UINT ThreadFunc (LPVOID pParam);
LOGPALETTE* CreateGrayScale ();

class CImageEditDoc : public CDocument
{
protected: // create from serialization only
CImageEditDoc();
DECLARE_DYNCREATE(CImageEditDoc)

// Attributes
public:

// Operations
public:

// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CImageEditDoc)
public:
virtual BOOL OnNewDocument();
virtual BOOL OnOpenDocument(LPCTSTR lpszPathName);
virtual void DeleteContents();
//}}AFX_VIRTUAL

// Implementation
public:
void ThreadAborted();
void ThreadFinished();
CPalette* GetPalette();
CBitmap* GetBitmap();
virtual ~CImageEditDoc();
#ifdef _DEBUG
virtual void AssertValid() const;
virtual void Dump(CDumpContext& dc) const;
#endif

protected:

// Generated message map functions
protected:
CCriticalSection m_cs;
CEvent m_event;
HANDLE m_hThread;
BOOL m_bWorking;
CPalette m_palette;
CBitmap m_bitmap;
//{{AFX_MSG(CImageEditDoc)
afx_msg void OnGrayScale();
afx_msg void OnUpdateGrayScale(CCmdUI* pCmdUI);
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};

/////////////////////////////////////////////////////////////////////////////

//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.

#endif // !defined(AFX_IMAGEEDITDOC_H__9D77AEEA_AA14_11D2_8E53_006008A82731__INCLUDED_)




osborn 2003-12-01
  • 打赏
  • 举报
回复
// ImageEditView.h : interface of the CImageEditView class
//
/////////////////////////////////////////////////////////////////////////////

#if !defined(AFX_IMAGEEDITVIEW_H__9D77AEEC_AA14_11D2_8E53_006008A82731__INCLUDED_)
#define AFX_IMAGEEDITVIEW_H__9D77AEEC_AA14_11D2_8E53_006008A82731__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000


class CImageEditView : public CScrollView
{
protected: // create from serialization only
CImageEditView();
DECLARE_DYNCREATE(CImageEditView)

// Attributes
public:
CImageEditDoc* GetDocument();

// Operations
public:

// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CImageEditView)
public:
virtual void OnDraw(CDC* pDC); // overridden to draw this view
virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
protected:
virtual void OnInitialUpdate(); // called first time after construct
//}}AFX_VIRTUAL

// Implementation
public:
virtual ~CImageEditView();
#ifdef _DEBUG
virtual void AssertValid() const;
virtual void Dump(CDumpContext& dc) const;
#endif

protected:

// Generated message map functions
protected:
//{{AFX_MSG(CImageEditView)
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};

#ifndef _DEBUG // debug version in ImageEditView.cpp
inline CImageEditDoc* CImageEditView::GetDocument()
{ return (CImageEditDoc*)m_pDocument; }
#endif

/////////////////////////////////////////////////////////////////////////////

//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.

#endif // !defined(AFX_IMAGEEDITVIEW_H__9D77AEEC_AA14_11D2_8E53_006008A82731__INCLUDED_)




// ImageEditView.cpp : implementation of the CImageEditView class
//

#include "stdafx.h"
#include "ImageEdit.h"

#include "ImageEditDoc.h"
#include "ImageEditView.h"

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

/////////////////////////////////////////////////////////////////////////////
// CImageEditView

IMPLEMENT_DYNCREATE(CImageEditView, CScrollView)

BEGIN_MESSAGE_MAP(CImageEditView, CScrollView)
//{{AFX_MSG_MAP(CImageEditView)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CImageEditView construction/destruction

CImageEditView::CImageEditView()
{
}

CImageEditView::~CImageEditView()
{
}

BOOL CImageEditView::PreCreateWindow(CREATESTRUCT& cs)
{
return CScrollView::PreCreateWindow(cs);
}

/////////////////////////////////////////////////////////////////////////////
// CImageEditView drawing

void CImageEditView::OnDraw(CDC* pDC)
{
CImageEditDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);

CBitmap* pBitmap = pDoc->GetBitmap ();

if (pBitmap != NULL) {
CPalette* pOldPalette;
CPalette* pPalette = pDoc->GetPalette ();

if (pPalette != NULL) {
pOldPalette = pDC->SelectPalette (pPalette, FALSE);
pDC->RealizePalette ();
}

DIBSECTION ds;
pBitmap->GetObject (sizeof (DIBSECTION), &ds);

CDC memDC;
memDC.CreateCompatibleDC (pDC);
CBitmap* pOldBitmap = memDC.SelectObject (pBitmap);

pDC->BitBlt (0, 0, ds.dsBm.bmWidth, ds.dsBm.bmHeight, &memDC,
0, 0, SRCCOPY);

memDC.SelectObject (pOldBitmap);

if (pPalette != NULL)
pDC->SelectPalette (pOldPalette, FALSE);
}
//Sleep(1000);
}

void CImageEditView::OnInitialUpdate()
{
CScrollView::OnInitialUpdate ();

CString string;
CSize sizeTotal;
CBitmap* pBitmap = GetDocument ()->GetBitmap ();

//
// If a bitmap is loaded, set the view size equal to the bitmap size.
// Otherwise, set the view's width and height to 0.
//
if (pBitmap != NULL) {
DIBSECTION ds;
pBitmap->GetObject (sizeof (DIBSECTION), &ds);
sizeTotal.cx = ds.dsBm.bmWidth;
sizeTotal.cy = ds.dsBm.bmHeight;
string.Format (_T ("\t%d x %d, %d bpp"), ds.dsBm.bmWidth,
ds.dsBm.bmHeight, ds.dsBmih.biBitCount);
}
else {
sizeTotal.cx = sizeTotal.cy = 0;
string.Empty ();
}

AfxGetMainWnd ()->SendMessage (WM_USER_UPDATE_STATS, 0,
(LPARAM) (LPCTSTR) string);
SetScrollSizes (MM_TEXT, sizeTotal);
}

/////////////////////////////////////////////////////////////////////////////
// CImageEditView diagnostics

#ifdef _DEBUG
void CImageEditView::AssertValid() const
{
CScrollView::AssertValid();
}

void CImageEditView::Dump(CDumpContext& dc) const
{
CScrollView::Dump(dc);
}

CImageEditDoc* CImageEditView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CImageEditDoc)));
return (CImageEditDoc*)m_pDocument;
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CImageEditView message handlers

osborn 2003-12-01
  • 打赏
  • 举报
回复
以下是CMainFrame,View,Doc的.h与.cpp

#define WM_USER_UPDATE_STATS WM_USER+0x100
#define WM_USER_THREAD_UPDATE WM_USER+0x101
#define WM_USER_THREAD_FINISHED WM_USER+0x102
#define WM_USER_THREAD_ABORTED WM_USER+0x103

typedef struct tagTHREADPARMS {
CWnd* pWnd;
CBitmap* pBitmap;
CPalette* pPalette;
CCriticalSection* pCriticalSection;
CEvent* pEvent;
} THREADPARMS;

// MainFrm.h : interface of the CMainFrame class
//
/////////////////////////////////////////////////////////////////////////////

#if !defined(AFX_MAINFRM_H__9D77AEE8_AA14_11D2_8E53_006008A82731__INCLUDED_)
#define AFX_MAINFRM_H__9D77AEE8_AA14_11D2_8E53_006008A82731__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

class CMainFrame : public CFrameWnd
{

protected: // create from serialization only
CMainFrame();
DECLARE_DYNCREATE(CMainFrame)

// Attributes
public:

// Operations
public:

// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CMainFrame)
virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
//}}AFX_VIRTUAL

// Implementation
public:
virtual ~CMainFrame();
#ifdef _DEBUG
virtual void AssertValid() const;
virtual void Dump(CDumpContext& dc) const;
#endif

// Generated message map functions
protected:
int m_nPercentDone;
//{{AFX_MSG(CMainFrame)
afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
afx_msg BOOL OnQueryNewPalette();
afx_msg void OnPaletteChanged(CWnd* pFocusWnd);
//}}AFX_MSG
afx_msg LRESULT OnUpdateImageStats (WPARAM wParam, LPARAM lParam);
afx_msg LRESULT OnThreadUpdate (WPARAM wParam, LPARAM lParam);
afx_msg LRESULT OnThreadFinished (WPARAM wParam, LPARAM lParam);
afx_msg LRESULT OnThreadAborted (WPARAM wParam, LPARAM lParam);
DECLARE_MESSAGE_MAP()
};

/////////////////////////////////////////////////////////////////////////////

//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.

#endif // !defined(AFX_MAINFRM_H__9D77AEE8_AA14_11D2_8E53_006008A82731__INCLUDED_)




// MainFrm.cpp : implementation of the CMainFrame class
//

#include "stdafx.h"
#include "ImageEdit.h"
#include "ImageEditDoc.h"

#include "MainFrm.h"

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

/////////////////////////////////////////////////////////////////////////////
// CMainFrame

IMPLEMENT_DYNCREATE(CMainFrame, CFrameWnd)

BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
//{{AFX_MSG_MAP(CMainFrame)
ON_WM_CREATE()
ON_WM_QUERYNEWPALETTE()
ON_WM_PALETTECHANGED()
//}}AFX_MSG_MAP
ON_MESSAGE (WM_USER_UPDATE_STATS, OnUpdateImageStats)
ON_MESSAGE (WM_USER_THREAD_UPDATE, OnThreadUpdate)
ON_MESSAGE (WM_USER_THREAD_FINISHED, OnThreadFinished)
ON_MESSAGE (WM_USER_THREAD_ABORTED, OnThreadAborted)
END_MESSAGE_MAP()

static UINT indicators[] =
{
ID_SEPARATOR,
ID_SEPARATOR,
ID_SEPARATOR
};

/////////////////////////////////////////////////////////////////////////////
// CMainFrame construction/destruction

CMainFrame::CMainFrame()
{
m_nPercentDone = -1;
}

CMainFrame::~CMainFrame()
{
}

int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
return -1;

if (!m_wndStatusBar.Create(this))
{
TRACE0("Failed to create status bar\n");
return -1; // fail to create
}
return 0;
}

BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
{
if( !CFrameWnd::PreCreateWindow(cs) )
return FALSE;
return TRUE;
}

/////////////////////////////////////////////////////////////////////////////
// CMainFrame diagnostics

#ifdef _DEBUG
void CMainFrame::AssertValid() const
{
CFrameWnd::AssertValid();
}

void CMainFrame::Dump(CDumpContext& dc) const
{
CFrameWnd::Dump(dc);
}

#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CMainFrame message handlers

BOOL CMainFrame::OnQueryNewPalette()
{
CDocument* pDoc = GetActiveDocument ();
if (pDoc != NULL)
GetActiveDocument ()->UpdateAllViews (NULL);
return TRUE;
}

void CMainFrame::OnPaletteChanged(CWnd* pFocusWnd)
{
if (pFocusWnd != this) {
CDocument* pDoc = GetActiveDocument ();
if (pDoc != NULL)
GetActiveDocument ()->UpdateAllViews (NULL);
}
}

LRESULT CMainFrame::OnUpdateImageStats (WPARAM wParam, LPARAM lParam)
{
m_wndStatusBar.SetImageStats ((LPCTSTR) lParam);
return 0;
}

LRESULT CMainFrame::OnThreadUpdate (WPARAM wParam, LPARAM lParam)
{
int nPercentDone = ((int) wParam * 100) / (int) lParam;
if (nPercentDone != m_nPercentDone) {
m_wndStatusBar.SetProgress (nPercentDone);
m_nPercentDone = nPercentDone;
}
return 0;
}

LRESULT CMainFrame::OnThreadFinished (WPARAM wParam, LPARAM lParam)
{
CImageEditDoc* pDoc = (CImageEditDoc*) GetActiveDocument ();
if (pDoc != NULL) {
pDoc->ThreadFinished ();
m_wndStatusBar.SetProgress (0);
m_nPercentDone = -1;
}
return 0;
}

LRESULT CMainFrame::OnThreadAborted (WPARAM wParam, LPARAM lParam)
{
CImageEditDoc* pDoc = (CImageEditDoc*) GetActiveDocument ();
if (pDoc != NULL)
{
pDoc->ThreadAborted ();
m_wndStatusBar.SetProgress (0);
m_nPercentDone = -1;
}
return 0;
}

15,979

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 界面
社区管理员
  • 界面
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧