ImageGear Professional v18.2 > User Guide > Getting Started > MS Visual Studio .NET 2008 C++ Application > Developing the Application |
Before completing the steps in this section, complete the following setup:
C++ |
Copy Code
|
---|---|
BOOL CIGSampleApp::InitInstance() { // ... AfxEnableControlContainer(); // Standard initialization // If you are not using these features and wish to reduce the size // of your final executable, you should remove from the following // the specific initialization routines you do not need. /* To unlock the toolkit for deployment you must call the IG_lic_solution_name_set, IG_lic_solution_key_set() and possibly the IG_lic_OEM_license_key_set() functions. See Licensing section in ImageGear User Manual for more details. */ // ... return TRUE; } |
C++ |
Copy Code
|
---|---|
#include "gear.h"
|
This provides access to the ImageGear functions for use in our application.
C++ |
Copy Code
|
---|---|
HIGEAR hIGear; |
This declares an ImageGear handle that will be used to hold the loaded image, which will be passed to the different ImageGear functions that are called.
C++ |
Copy Code
|
---|---|
hIGear = (HIGEAR)NULL; |
Then add the following code to the CIGSampleDoc::~CIGSampleDoc() function:
C++ |
Copy Code
|
---|---|
if( IG_image_is_valid( hIGear ) )
IG_image_delete( hIGear );
|
The code above utilizes:
Called to determine if the HIGEAR variable hIGear contains a handle of a valid ImageGear image. |
|
Removes the HIGEAR handle of hIGear, and frees the memory of the associated HIGEAR structure. This function also frees the memory associated with the image's DIB, if ImageGear allocated the DIB memory. If ImageGear did not allocate the DIB memory, the DIB continues to exist, and it is the responsibility of your application to free this memory when done with it. |
C++ |
Copy Code
|
---|---|
if( IG_load_file( CT2A(lpszPathName), &hIGear )==0 ) return TRUE; else { //ErrorReport return FALSE; } |
The code above utilizes:
Loads the specified file into the HIGEAR. |
Note the use of the CT2A macro, which converts lpszPathName into an ANSI string so it can be passed to IG_load_file.
Type |
Name |
CView * |
v |
AT_MODE |
nZoomMode |
DOUBLE |
dHZoom |
DOUBLE |
dVZoom |
The Function signature should now look like this:
C++ |
Copy Code
|
---|---|
AT_ERRCOUNT dsplZoomSet(CView * v, AT_MODE nZoomMode, double dHZoom, double dVZoom) |
Click Finish to add the function.
Next insert code under the member function in IGSampleDoc.cpp so that the final code looks like the following:
C++ |
Copy Code
|
---|---|
AT_ERRCOUNT CIGSampleDoc::dsplZoomSet(CView * v, AT_MODE nZoomMode, double dHZoom, double dVZoom) { DWORD dwGrpID=0; AT_ERRCOUNT nErrCount; nErrCount = IG_dspl_zoom_set( hIGear, dwGrpID, nZoomMode, dHZoom, dVZoom ); if( nErrCount!=NULL ) { //ErrorReport } return nErrCount; } |
C++ |
Copy Code
|
---|---|
AT_ERRCOUNT CIGSampleDoc::dsplZoomGet(CView *v, LPAT_MODE lpnZoomMode, LPDOUBLE lpdHZoom, LPDOUBLE lpdVZoom) { DWORD dwGrpID=0; AT_ERRCOUNT nErrCount; nErrCount = IG_dspl_zoom_get( hIGear, dwGrpID, v->GetSafeHwnd(), lpnZoomMode, lpdHZoom, lpdVZoom ); if( nErrCount!=NULL ) { //ErrorReport } return nErrCount; } void CIGSampleDoc::DrawImage( CView *v, CDC *dc, CPrintInfo *pInfo ) { if( IG_image_is_valid( hIGear ) ) { DWORD dwGrpID=0; POINT p; SIZE s; DWORD nMapMode; AT_RECTANGLE Viewport; AT_RECTANGLE Window; /* get current mapping parameters */ nMapMode = ::GetMapMode( dc->m_hDC ); ::GetViewportOrgEx( dc->m_hDC, &p ); Viewport.x = p.x; Viewport.y = p.y; ::GetViewportExtEx( dc->m_hDC, &s ); Viewport.width = s.cx; Viewport.height = s.cy; ::GetWindowOrgEx( dc->m_hDC, &p ); Window.x = p.x; Window.y = p.y; ::GetWindowExtEx( dc->m_hDC, &s ); Window.width = s.cx; Window.height = s.cy; IG_dspl_mapmode_set( hIGear, dwGrpID, nMapMode, &Viewport, &Window ); IG_dspl_image_draw( hIGear, dwGrpID, v->GetSafeHwnd(), dc->GetSafeHdc(), NULL ); } } |
The code for these member functions includes:
Sets the current map mode and logical coordinate system. |
|
Draws an image onto a destination device context. |
|
Sets the zoom value. |
|
Gets the current zoom value. |
C++ |
Copy Code
|
---|---|
void CIGSampleView::OnDraw(CDC* pDC)
|
Then add the following code to the OnDraw function:
C++ |
Copy Code
|
---|---|
pDoc->DrawImage( this, pDC, NULL );
|
This calls the DrawImage function defined in IGSampleDoc.cpp and ensures that the image will be properly drawn when the window is redrawn.
C++ |
Copy Code
|
---|---|
DOUBLE dHZoom, dVZoom; CIGSampleDoc* pDoc = GetDocument(); ASSERT_VALID(pDoc); pDoc->dsplZoomGet( this, NULL, &dHZoom, &dVZoom ); dHZoom *= 1.25; dVZoom *= 1.25; pDoc->dsplZoomSet( this, IG_DSPL_ZOOM_H_FIXED|IG_DSPL_ZOOM_V_FIXED, dHZoom, dVZoom ); InvalidateRect( NULL, FALSE ); //force redraw UpdateWindow(); |
The above code zooms the image to 125 percent, or 5/4ths, of its size (zoom in by 25 percent).
Finally, insert the following code into the OnZout() function:
C++ |
Copy Code
|
---|---|
DOUBLE dHZoom, dVZoom; CIGSampleDoc* pDoc = GetDocument(); ASSERT_VALID(pDoc); pDoc->dsplZoomGet( this, NULL, &dHZoom, &dVZoom ); dHZoom /= 1.25; dVZoom /= 1.25; pDoc->dsplZoomSet( this, IG_DSPL_ZOOM_H_FIXED|IG_DSPL_ZOOM_V_FIXED, dHZoom, dVZoom ); InvalidateRect( NULL, FALSE ); //force redraw UpdateWindow(); |
The above code zooms "out", decreasing the image to 4/5ths of its size, thereby canceling the effect of the zoom in above.