Click here to Skip to main content
15,885,366 members
Articles / Desktop Programming / MFC

Thumbnails viewer and image processing using GDI+ and MFC

Rate me:
Please Sign up or sign in to vote.
4.93/5 (78 votes)
24 Sep 20034 min read 371.9K   24.8K   232  
Using GDI+ and MFC to create a thumbnail image viewer and some processing functions
// ImageTool.cpp : Defines the class behaviors for the application.
//

#include "stdafx.h"
#include "ImageTool.h"
#include "MainFrm.h"
#include "ImageToolDoc.h"
#include "ImageToolView.h"
#include "myGdiPlus.h" 

using namespace Gdiplus; 
#pragma comment(lib, "gdiplus.lib")

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

ULONG_PTR gdiplusToken;

/////////////////////////////////////////////////////////////////////////////
// CImageToolApp

BEGIN_MESSAGE_MAP(CImageToolApp, CWinApp)
	//{{AFX_MSG_MAP(CImageToolApp)
	//}}AFX_MSG_MAP
	ON_COMMAND( ID_FILE_NEW,         CWinApp::OnFileNew        )
	ON_COMMAND( ID_FILE_OPEN,        CWinApp::OnFileOpen       )
	ON_COMMAND( ID_FILE_PRINT_SETUP, CWinApp::OnFilePrintSetup )
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CImageToolApp construction
CImageToolApp::CImageToolApp()
{
}

/////////////////////////////////////////////////////////////////////////////
// The one and only CImageToolApp object
CImageToolApp theApp;

/////////////////////////////////////////////////////////////////////////////
// CImageToolApp initialization
BOOL CImageToolApp::InitInstance()
{
	AfxEnableControlContainer();

//begin: initialize GDI+  
	GdiplusStartupInput gdiplusStartupInput;
    VERIFY(GdiplusStartup( &gdiplusToken, &gdiplusStartupInput, NULL ) == Ok );
//end: initialize GDI+

#ifdef _AFXDLL
	Enable3dControls();			// Call this when using MFC in a shared DLL
#else
	Enable3dControlsStatic();	// Call this when linking to MFC statically
#endif

	SetRegistryKey(_T("Local AppWizard-Generated Applications"));

	LoadStdProfileSettings();

	CSingleDocTemplate* pDocTemplate;
	pDocTemplate = new CSingleDocTemplate( IDR_MAINFRAME,
		                                   RUNTIME_CLASS(CImageToolDoc),
										   RUNTIME_CLASS(CMainFrame),
										   RUNTIME_CLASS(CImageToolView) );
	AddDocTemplate(pDocTemplate);

	CCommandLineInfo cmdInfo;
	ParseCommandLine(cmdInfo);

	if (!ProcessShellCommand(cmdInfo))
	{
		return FALSE;
	}

	m_pMainWnd->ShowWindow(SW_SHOW);
	m_pMainWnd->UpdateWindow();

	return TRUE;
}

int CImageToolApp::ExitInstance() 
{
//begin: shutdown GDI+ 
	GdiplusShutdown(gdiplusToken);
//end: shutdown GDI+
	
	return CWinApp::ExitInstance();
}

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


Written By
Software Developer (Senior) IBI Group
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions