Click here to Skip to main content
15,896,467 members
Articles / Programming Languages / C++

Image Viewer Utility

Rate me:
Please Sign up or sign in to vote.
4.94/5 (50 votes)
10 Mar 2007CPOL18 min read 407.8K   19.2K   200  
A little utility program that allows you to view the contents of memory bitmaps and device contexts while you are stepping through your drawing code.
/****************************************************************************
ImageViewerView.h : Header file for the CImageViewerView class
written by PJ Arends
pja@telus.net

For updates check http://www.codeproject.com/tools/imageviewer.asp

-----------------------------------------------------------------------------
This code is provided as is, with no warranty as to it's suitability or usefulness
in any application in which it may be used.

This code may be used in any way you desire. This file may be redistributed by any
means as long as it is not sold for profit, and providing that this notice and the
authors name are included.

If any bugs are found and fixed, a note to the author explaining the problem and
fix would be nice.
-----------------------------------------------------------------------------
****************************************************************************/

#pragma once
#include "MouseGesture.h"

class CImageViewerView : public CScrollView
{
	DECLARE_DYNCREATE(CImageViewerView)

protected:
	CImageViewerView(); // create from serialization only
	CImageViewerDoc* GetDocument() const;

// Overrides
public:
	virtual ~CImageViewerView();
	virtual void OnDraw(CDC* pDC);  // overridden to draw this view
    virtual void OnUpdate(CView* pSender, LPARAM lHint, CObject* pHint);
	virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
protected:
	virtual void OnInitialUpdate(); // called first time after construct

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

protected:
    bool AutoScrollTimer;
    bool LButtonDown;
    bool ViewGrid;
    size_t CurrentImage;
    size_t CurrentZoomRatio;
    CMouseGesture MouseGesture;
    CBitmap ZoomedBitmap;
    CRect ZoomedBitmapRect;

    CString ErrorText;

protected:
    COLORREF GetPixelColour(CPoint pt);
    CRect GetVisibleRect(void);
    void CalcBitmapRect();
    void SetCaption();
    bool SetCurrentImage(size_t nImage, bool PassLock);
    bool MoveCursor(int x, int y);

// Generated message map functions
protected:
    afx_msg BOOL OnEraseBkgnd(CDC* pDC);
    afx_msg void OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar);
    afx_msg void OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags);
    afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
    afx_msg void OnLButtonUp(UINT nFlags, CPoint point);
    afx_msg void OnMButtonDown(UINT nFlags, CPoint point);
    afx_msg void OnMouseMove(UINT nFlags, CPoint point);
    afx_msg BOOL OnMouseWheel(UINT nFlags, short zDelta, CPoint pt);
    afx_msg void OnSetFocus(CWnd* pOldWnd);
    afx_msg void OnSize(UINT nType, int cx, int cy);
    afx_msg void OnTimer(UINT_PTR nIDEvent);
    afx_msg void OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar);

    afx_msg LRESULT OnGetPointData(WPARAM wp, LPARAM lp);
    afx_msg LRESULT OnMouseGesture(WPARAM wp, LPARAM lp);

    afx_msg void OnFileCloseView();
    afx_msg void OnImageDelete();
    afx_msg void OnUpdateImageDelete(CCmdUI *pCmdUI);
    afx_msg void OnViewCentermouse();
    afx_msg void OnUpdateViewCentermouse(CCmdUI *pCmdUI);
    afx_msg void OnViewFirstimage();
    afx_msg void OnUpdateViewFirstimage(CCmdUI *pCmdUI);
    afx_msg void OnViewPreviousimage();
    afx_msg void OnUpdateViewPreviousimage(CCmdUI *pCmdUI);
    afx_msg void OnViewSelectimage();
    afx_msg void OnUpdateViewSelectimage(CCmdUI *pCmdUI);
    afx_msg void OnViewNextimage();
    afx_msg void OnUpdateViewNextimage(CCmdUI *pCmdUI);
    afx_msg void OnViewLastimage();
    afx_msg void OnUpdateViewLastimage(CCmdUI *pCmdUI);
    afx_msg void OnViewGrid();
    afx_msg void OnUpdateViewGrid(CCmdUI *pCmdUI);
    afx_msg void OnZoomZoomin();
    afx_msg void OnUpdateZoomZoomin(CCmdUI *pCmdUI);
    afx_msg void OnZoomZoomout();
    afx_msg void OnUpdateZoomZoomout(CCmdUI *pCmdUI);

#if !defined NO_GDIPLUS
protected:
    afx_msg void OnImageSave();
    afx_msg void OnUpdateImageSave(CCmdUI *pCmdUI);
#endif // #if !defined NO_GDIPLUS

	DECLARE_MESSAGE_MAP()
};

#ifndef _DEBUG  // debug version in ImageViewerView.cpp
inline CImageViewerDoc* CImageViewerView::GetDocument() const
   { return reinterpret_cast<CImageViewerDoc*>(m_pDocument); }
#endif

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
President
Canada Canada
Father of two, brother of two, child of two.
Spouse to one, uncle to many, friend to lots.
Farmer, carpenter, mechanic, electrician, but definitely not a plumber.
Likes walks with the wife, board games, card games, travel, and camping in the summer.
High school graduate, college drop-out.
Hobby programmer who knows C++ with MFC and the STL.
Has dabbled with BASIC, Pascal, Fortran, COBOL, C#, SQL, ASM, and HTML.
Realized long ago that programming is fun when there is nobody pressuring you with schedules and timelines.

Comments and Discussions