Click here to Skip to main content
12,454,104 members (55,752 online)
Click here to Skip to main content

Stats

137.5K views
3.1K downloads
55 bookmarked
Posted

An Image Decoder Based on IImgCtx

, 25 May 2004
This article shows how to decode image with IImgCtx interface provided by IE
// MainFrm.cpp : implementation of the CMainFrame class
//

#include "stdafx.h"
#include "ImgViewer.h"

#include "MainFrm.h"
#include "DirMng.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_COMMAND(ID_VIEW_PRE, OnViewPre)
	ON_COMMAND(ID_VIEW_NEXT, OnViewNext)
	ON_COMMAND(ID_VIEW_DIR_FIRST, OnViewDirFirst)
	ON_COMMAND(ID_VIEW_DIR_END, OnViewDirEnd)
	ON_UPDATE_COMMAND_UI(ID_VIEW_NEXT, OnUpdateViewPage)
	ON_UPDATE_COMMAND_UI(ID_VIEW_PRE, OnUpdateViewPage)
	ON_UPDATE_COMMAND_UI(ID_VIEW_DIR_FIRST, OnUpdateViewPage)
	ON_UPDATE_COMMAND_UI(ID_VIEW_DIR_END, OnUpdateViewPage)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

static UINT indicators[] =
{
	ID_SEPARATOR,           // status line indicator
	ID_INDICATOR_PAGE,
	ID_INDICATOR_FILE_NAME,
	ID_INDICATOR_CAPS,
	ID_INDICATOR_NUM,
	ID_INDICATOR_SCRL,
};

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

CMainFrame::CMainFrame()
{
	// TODO: add member initialization code here
	
}

CMainFrame::~CMainFrame()
{
}

int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
	if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
		return -1;
	
	if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP
		| CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
		!m_wndToolBar.LoadToolBar(IDR_MAINFRAME))
	{
		TRACE0("Failed to create toolbar\n");
		return -1;      // fail to create
	}

	if (!m_wndStatusBar.Create(this) ||
		!m_wndStatusBar.SetIndicators(indicators,
		  sizeof(indicators)/sizeof(UINT)))
	{
		TRACE0("Failed to create status bar\n");
		return -1;      // fail to create
	}

	// TODO: Delete these three lines if you don't want the toolbar to
	//  be dockable
	m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
	EnableDocking(CBRS_ALIGN_ANY);
	DockControlBar(&m_wndToolBar);
	
	SetStatusInfo(ID_INDICATOR_PAGE, NULL);
	SetStatusInfo(ID_INDICATOR_FILE_NAME, NULL);

	return 0;
}

BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
{
	if( !CFrameWnd::PreCreateWindow(cs) )
		return FALSE;
	// TODO: Modify the Window class or styles here by modifying
	//  the CREATESTRUCT cs

	cs.style = WS_OVERLAPPED | WS_CAPTION | FWS_ADDTOTITLE
		| WS_THICKFRAME | WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_MAXIMIZE;

	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

void CMainFrame::SetStatusInfo(UINT id, const char* pszInfo) 
{
	if (id < 0) return;

	int index;
	if (id == 0)
		index = 0;
	else
		index = m_wndStatusBar.CommandToIndex(id);
	if (index < 0) return;

	if (pszInfo)
		m_wndStatusBar.SetPaneText(index, pszInfo);
	else
		m_wndStatusBar.SetPaneText(index, "");
}

void CMainFrame::OnUpdateViewPage(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	pCmdUI->Enable(g_DirManager.TotalFilesInDir() > 0);
}

void CMainFrame::OnViewPre() 
{
	// TODO: Add your command handler code here
	OpenFile(g_DirManager.PreFile());
}

void CMainFrame::OnViewNext() 
{
	// TODO: Add your command handler code here
	OpenFile(g_DirManager.NextFile());
}

void CMainFrame::OnViewDirFirst() 
{
	// TODO: Add your command handler code here
	OpenFile(g_DirManager.FirstFile());
}

void CMainFrame::OnViewDirEnd() 
{
	// TODO: Add your command handler code here
	OpenFile(g_DirManager.LastFile());
}

void CMainFrame::OpenFile(const char* pszPath) 
{
	if (pszPath)
	{
		AfxGetApp()->OpenDocumentFile(pszPath);
		SetStatusInfo(ID_INDICATOR_FILE_NAME, pszPath);

		char szBuffer[16];
		sprintf(szBuffer, "%d/%d", g_DirManager.GetCurrentFileIndex(), g_DirManager.TotalFilesInDir());
		SetStatusInfo(ID_INDICATOR_PAGE, szBuffer);
	}
}

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 has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

Share

About the Author

strnghrs
Web Developer
China China
No Biography provided

You may also be interested in...

Pro
Pro
| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.160826.1 | Last Updated 26 May 2004
Article Copyright 2004 by strnghrs
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid