Blueprint Help Send comments on this topic.
Additional Code

Glossary Item Box

GUI.rc

// Microsoft Visual C++ generated resource script.
//
#include "resource.h"

#define APSTUDIO_READONLY_SYMBOLS

/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 2 resource.
//
#include "afxres.h"

/////////////////////////////////////////////////////////////////////////////
#undef APSTUDIO_READONLY_SYMBOLS

/////////////////////////////////////////////////////////////////////////////
// English (U.K.) resources

#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENG)
#ifdef _WIN32
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_UK
#pragma code_page(1252)
#endif //_WIN32

#ifdef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// TEXTINCLUDE
//

1 TEXTINCLUDE
BEGIN
   "resource.h\0"
END

2 TEXTINCLUDE
BEGIN
   "#include ""afxres.h""\r\n"
   "\0"
END

3 TEXTINCLUDE
BEGIN
   "#define _AFX_NO_SPLITTER_RESOURCES\r\n"
   "#define _AFX_NO_OLE_RESOURCES\r\n"
   "#define _AFX_NO_TRACKER_RESOURCES\r\n"
   "#define _AFX_NO_PROPERTY_RESOURCES\r\n"
   "\r\n"
   "#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENG)\r\n"
   "LANGUAGE 9, 2\r\n"
   "#pragma code_page(1252)\r\n"
   "#include ""res\\GUI.rc2"" // non-Microsoft Visual C++ edited resources\r\n"
   "#include ""afxres.rc"" // Standard components\r\n"
   "#endif\r\n"
   "\0"
END

#endif // APSTUDIO_INVOKED

/////////////////////////////////////////////////////////////////////////////
//
// Icon
//

// Icon with lowest ID value placed first to ensure application icon
// remains consistent on all systems.
IDR_MAINFRAME ICON "res\\GUI.ico"

/////////////////////////////////////////////////////////////////////////////
//
// Dialog
//

IDD_ABOUTBOX DIALOGEX 0, 0, 235, 55
STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "About GUI"
FONT 8, "MS Shell Dlg", 0, 0, 0x1
BEGIN
   ICON IDR_MAINFRAME,IDC_STATIC,11,17,20,20
   LTEXT "GUI Version 1.0",IDC_STATIC,40,10,119,8,SS_NOPREFIX
   LTEXT "Copyright (C) 2007",IDC_STATIC,40,25,119,8
   DEFPUSHBUTTON "OK",IDOK,178,7,50,16,WS_GROUP
END

IDD_GUI_DIALOG DIALOGEX 0, 0, 110, 50
STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "GUI"
FONT 8, "MS Shell Dlg", 0, 0, 0x1
BEGIN
   PUSHBUTTON "Start",IDC_BUTTON1,30,20,50,14
   GROUPBOX "",IDC_STATIC,7,7,96,36
END

IDD_OUTPUT_DIALOG DIALOGEX 0, 0, 186, 90
STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "Dialog"
FONT 8, "MS Shell Dlg", 400, 0, 0x1
BEGIN
END

/////////////////////////////////////////////////////////////////////////////
//
// Version
//

VS_VERSION_INFO VERSIONINFO
 FILEVERSION 1,0,0,1
 PRODUCTVERSION 1,0,0,1
 FILEFLAGSMASK 0x3fL
#ifdef _DEBUG
 FILEFLAGS 0x1L
#else
 FILEFLAGS 0x0L
#endif
 FILEOS 0x4L
 FILETYPE 0x1L
 FILESUBTYPE 0x0L
BEGIN
   BLOCK "StringFileInfo"
   BEGIN
      BLOCK "040904e4"
      BEGIN
         VALUE "CompanyName", "TODO: <Company name>"
         VALUE "FileDescription", "TODO: <File description>"
         VALUE "FileVersion", "1.0.0.1"
         VALUE "InternalName", "GUI.exe"
         VALUE "LegalCopyright", "TODO: (c) <Company name>. All rights reserved."
         VALUE "OriginalFilename", "GUI.exe"
         VALUE "ProductName", "TODO: <Product name>"
         VALUE "ProductVersion", "1.0.0.1"
      END
   END
   BLOCK "VarFileInfo"
   BEGIN
      VALUE "Translation", 0x409, 1252
   END
END

/////////////////////////////////////////////////////////////////////////////
//
// DESIGNINFO
//

#ifdef APSTUDIO_INVOKED
GUIDELINES DESIGNINFO
BEGIN
   IDD_ABOUTBOX, DIALOG
   BEGIN
      LEFTMARGIN, 7
      RIGHTMARGIN, 228
      TOPMARGIN, 7
      BOTTOMMARGIN, 48
   END

   IDD_GUI_DIALOG, DIALOG
   BEGIN
      LEFTMARGIN, 7
      RIGHTMARGIN, 103
      TOPMARGIN, 7
      BOTTOMMARGIN, 43
   END

   IDD_OUTPUT_DIALOG, DIALOG
   BEGIN
      LEFTMARGIN, 7
      RIGHTMARGIN, 179
      TOPMARGIN, 7
      BOTTOMMARGIN, 83
   END
END
#endif // APSTUDIO_INVOKED

/////////////////////////////////////////////////////////////////////////////
//
// String Table
//

STRINGTABLE
BEGIN
   IDS_ABOUTBOX "&About GUI..."
END

#endif // English (U.K.) resources
/////////////////////////////////////////////////////////////////////////////

#ifndef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 3 resource.
//
#define _AFX_NO_SPLITTER_RESOURCES
#define _AFX_NO_OLE_RESOURCES
#define _AFX_NO_TRACKER_RESOURCES
#define _AFX_NO_PROPERTY_RESOURCES

#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENG)
LANGUAGE 9, 2
#pragma code_page(1252)
#include "res\GUI.rc2" // non-Microsoft Visual C++ edited resources
#include "afxres.rc" // Standard components
#endif

/////////////////////////////////////////////////////////////////////////////
#endif // not APSTUDIO_INVOKED


Resource.h

//{{NO_DEPENDENCIES}}
// Microsoft Visual C++ generated include file.
// Used by GUI.rc
//
#define IDM_ABOUTBOX 0x0010
#define IDD_ABOUTBOX 100
#define IDS_ABOUTBOX 101
#define IDD_GUI_DIALOG 102
#define IDR_MAINFRAME 128
#define IDD_DIALOG1 129
#define IDD_OUTPUT_DIALOG 129
#define IDC_BUTTON1 1001

// Next default values for new objects
// #ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 130
#define _APS_NEXT_COMMAND_VALUE 32771
#define _APS_NEXT_CONTROL_VALUE 1003
#define _APS_NEXT_SYMED_VALUE 101
#endif
#endif


OutputDialog.h

#pragma once

///////////////////////////////////////////////////////////////////////////////
class COutputDialog : public CDialog
{
   DECLARE_DYNAMIC(COutputDialog)

public:
   COutputDialog(CWnd* pParent = NULL); // standard constructor
   virtual ~COutputDialog();
   // Dialog Data
   enum { IDD = IDD_OUTPUT_DIALOG };

protected:
   virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support

   DECLARE_MESSAGE_MAP()
};


OutputDialog.cpp

// OutputDialog.cpp : implementation file
//
#include "stdafx.h"
#include "GUI.h"
#include "OutputDialog.h"

///////////////////////////////////////////////////////////////////////////////
IMPLEMENT_DYNAMIC(COutputDialog, CDialog)

COutputDialog::COutputDialog(CWnd* pParent /*=NULL*/)
: CDialog(COutputDialog::IDD, pParent)
{
}

///////////////////////////////////////////////////////////////////////////////
COutputDialog::~COutputDialog()
{
}

void test::DoDataExchange(CDataExchange* pDX)
{
   CDialog::DoDataExchange(pDX);
}

///////////////////////////////////////////////////////////////////////////////
BEGIN_MESSAGE_MAP(COutputDialog, CDialog)
END_MESSAGE_MAP()

CPixmap.h

//////////////////////////////////////////////////////////////////////////////
//
// MODULE NAME : Pixmap Class
//
// FILENAME : CPixmap.h
//
// AUTHORS : D. J. Churchill
//
// CREATED : 10/06/2005
//
// COPYRIGHT : D. J. Churchill
//
// VERSION : 1.0
//
//////////////////////////////////////////////////////////////////////////////
#ifndef C_PIXAMP_H
#define C_PIXMAP_H

#include <windows.h>

class CPixmap
{
public:
   CPixmap( HDC HandleDeviceContext, int Width, int Height );
   virtual ~CPixmap();
   unsigned char* GetBitmapData();
   void CommitBitmapData();
   void Update();

protected:
   virtual void Draw( HDC Hdc ){;}

private:
   int mWidth, mHeight;
   HDC mDeviceContextHandle;
   HDC mMemDeviceContextHandle;
   HBITMAP mMemBitmap;
   HBITMAP mPreviousBitmap;
   unsigned char* mBitmapData;
   unsigned int mBitmapDataSizeBytes;
};

#endif


CPixmap.cpp

#include "CPixmap.h"

/////////////////////////////////////////////////////////////////////////////
CPixmap::CPixmap(HDC DeviceContextHandle, int Width, int Height )
{
   mDeviceContextHandle = DeviceContextHandle;
   mWidth = Width;
   mHeight = Height;
   mMemDeviceContextHandle = ::CreateCompatibleDC( DeviceContextHandle );
   mMemBitmap = ::CreateCompatibleBitmap( DeviceContextHandle,
                                          Width,
                                          Height );
   mPreviousBitmap = (HBITMAP)::SelectObject( mMemDeviceContextHandle,
                                              mMemBitmap );
   mBitmapDataSizeBytes = sizeof( unsigned char* ) * Width * Height * 4;
   mBitmapData = (unsigned char*)malloc( mBitmapDataSizeBytes );
}

/////////////////////////////////////////////////////////////////////////////
CPixmap::~CPixmap()
{
   if ( mMemBitmap )
   {
      ::SelectObject( mMemDeviceContextHandle, mPreviousBitmap );
      ::DeleteObject( mMemBitmap );
   }
   ::DeleteDC( mMemDeviceContextHandle );
   if ( mBitmapData )
   {
      free( mBitmapData );
   }
}

/////////////////////////////////////////////////////////////////////////////
unsigned char* CPixmap::GetBitmapData()
{
   return mBitmapData;
}

/////////////////////////////////////////////////////////////////////////////
void CPixmap::CommitBitmapData()
{
   SetBitmapBits( mMemBitmap,
                  mBitmapDataSizeBytes,
                  mBitmapData );
}

/////////////////////////////////////////////////////////////////////////////
void CPixmap::Update()
{
   ::BitBlt( mDeviceContextHandle,
             0,
             0, 
             mWidth,
             mHeight,
             mMemDeviceContextHandle,
             0,
             0, 
             SRCCOPY );

   Draw( mDeviceContextHandle );
}


CViewerPixmap.h

//////////////////////////////////////////////////////////////////////////////
//
// MODULE NAME : Viewer Pixmap Class
//
// FILENAME : CViewerPixmap.h
//
// AUTHORS : D. J. Churchill
//
// CREATED : 10/06/2005
//
// COPYRIGHT : D. J. Churchill
//
// VERSION : 1.0
//
//////////////////////////////////////////////////////////////////////////////

#ifndef C_VIEWER_PIXAMP_H
#define C_VIEWER_PIXMAP_H

#include "CPixmap.h"

class CViewerPixmap : public CPixmap
{
public:
   CViewerPixmap( HDC HandleDeviceContext, int Width, int Height );
   void SetBoundingRect( int ZoomInitialXPos,
                         int ZoomInitialYPos,
                         int Width,
                         int Height );
   void ShowBoundingRect( bool Show );
   void MakeGreyScale();

protected:
   virtual void Draw( HDC Hdc );

private:
   bool mShowBoundingRect;
   int mZoomInitialXPos;
   int mZoomInitialYPos;
   int mZoomWidth;
   int mZoomHeight;
   int mWidth;
   int mHeight;
   HPEN mWhitePen;
};

#endif


 CViewerPixmap.cpp

#include "CViewerPixmap.h"

/////////////////////////////////////////////////////////////////////////////
CViewerPixmap::CViewerPixmap(HDC DeviceContextHandle, int Width, int Height ) : CPixmap ( DeviceContextHandle, Width, Height )
{
   mWhitePen = ::CreatePen( PS_SOLID, 1, RGB( 255, 255, 255 ) );
   mShowBoundingRect = false;
   mZoomInitialXPos = 0;
   mZoomInitialYPos = 0;
   mWidth = Width;
   mHeight = Height;
}

/////////////////////////////////////////////////////////////////////////////
void CViewerPixmap::Draw( HDC Hdc )
{
}

/////////////////////////////////////////////////////////////////////////////
void CViewerPixmap::SetBoundingRect( int ZoomInitialXPos,
                                     int ZoomInitialYPos,
                                     int Width,
                                     int Height )
{
   mZoomInitialXPos = ZoomInitialXPos;
   mZoomInitialYPos = ZoomInitialYPos;
   mZoomWidth = Width;
   mZoomHeight = Height;
}

/////////////////////////////////////////////////////////////////////////////
void CViewerPixmap::ShowBoundingRect( bool Show )
{
   mShowBoundingRect = Show;
}

/////////////////////////////////////////////////////////////////////////////
void CViewerPixmap::MakeGreyScale()
{
   unsigned char* BitmapData = GetBitmapData();
   int NumBytes = mWidth * mHeight * 4;
   int BytesPerLine = mWidth * 4;
   int NumLines = NumBytes / BytesPerLine;
   int PixelCount = BytesPerLine / 4;
   int ByteCount = 0;

   for( int Line = 0; Line < NumLines; Line++ )
   {
      for( int Pixel = 0; Pixel < PixelCount; Pixel++ )
      {
         unsigned char Red = BitmapData[ByteCount];
         unsigned char Green = BitmapData[ByteCount+1];
         unsigned char Blue = BitmapData[ByteCount+2];
         unsigned int Average = ( Red + Green + Blue ) / 3;

         BitmapData[ByteCount] = Average;
         BitmapData[ByteCount+1] = Average;
         BitmapData[ByteCount+2] = Average;
         ByteCount += 4;
      }
   }
   CommitBitmapData();
}