Using the Magnifying Glass (Visual C++ 5.0 or later)
Take the following steps to enable the generation of the MagGlassExt event and update the zoomed image using the LEADTOOLS Internet toolkit methods.
1. |
Start a new project as follows: |
|
|
Run Microsoft Visual C++ 5.0, select the File >New menu option, and do the following: |
|
|
a. |
Click the Projects tab. |
|
b. |
Select MFC AppWizard (exe) as the project type |
|
c. |
In the Project name text box, specify MagGlsNtCom. |
|
d. |
In the Location text box, specify the path of the project. |
|
e. |
Click the OK button. |
2. |
In the Step 1 dialog box, do the following: |
|
|
a. |
Select Dialog based. |
|
b. |
Click the Next button. |
3. |
In the Step 2 of 4 dialog box, do the following: |
|
|
a. |
Ensure that About Box is selected. |
|
b. |
Ensure that 3D Controls is selected. |
|
c. |
Select ActiveX Controls. |
|
d. |
Click the Next button. |
4. |
In the Step 3 of 4 dialog box, do the following: |
|
|
a. |
For comments, ensure that Yes, Please is selected. |
|
b. |
For how to use the MFC library, select As a shared DLL. |
|
c. |
Click the Next button. |
5. |
In the Step 4 of 4 dialog box, just click Finish. |
|
6. |
Read New Project Information, and click OK. (The AppWizard creates the project files and opens the project.) |
|
7. |
Add the L_OcxErr.h file to your project as follows: |
|
|
a. |
Copy the L_OcxErr.h file to your project directory from the \lead\include directory. |
|
b. |
In the Project Workspace, click the FileView tab. |
|
c. |
Double-click the MagGlsNtCom files folder to open it. |
|
d. |
Double-click the Dependencies folder (the Header Files folder in 5.0) to open it. |
|
e. |
Double-click the StdAfx.h file to edit it. |
|
f. |
Add the following lines to the end of the file: |
#include "L_OcxErr.h"
8. |
Add #import and #include statements to your program so you can access the LEAD COM constants and classes: |
|
|
a. |
In the Project Workspace, click the FileView tab. |
|
b. |
Double-click the MagGlsNtCom files folder to open it. |
|
c. |
Double-click the Header Files folder to open it. |
|
d. |
Double-click the StdAfx.h file to edit it. |
|
e. |
Add the following lines to the end of the file (keep in mind, you may have to change the path to where the dll's reside): |
#import "c:\\winnt\\system32\\ltrvr14n.dll" no_namespace, named_guids
#import "c:\windows\system\ltr14n.dll" no_namespace, named_guids
#import "c:\windows\system\ltrvw14n.ocx" no_namespace, named_guids
#import "c:\windows\system\ltrio14n.dll" no_namespace, named_guids
#import "c:\windows\system\ltrpr14n.dll" no_namespace, named_guids
#import "c:\windows\system\ltrnt14n.dll" no_namespace, named_guids
#include "leadraster.h"
9. |
Add a LEAD RasterView Control to the main window as follows: |
|
|
a. |
In the Project Workspace, click the ResourceView tab. |
|
b. |
Double-click the MagGlsNtCom resources folder to open it. |
|
c. |
Double-click the Dialog folder to open it. |
|
d. |
Double-click IDD_MAGGLSNTCOM_DIALOG to design the dialog box. |
|
e. |
Select the TODO... text control; then press the Delete key to delete it. |
|
f. |
Select also the OK button; then press the Delete key to delete it. |
|
g. |
From the main menu, select Project > Add To Project > Components and Controls. |
|
h. |
Select Registered ActiveX Controls. |
|
i. |
Double-click the LEAD RasterView Control (14.5) icon. (The Confirm Classes dialog box appears.) |
|
j. |
Ensure that CLEADRasterView, CLEADRaster, and CPicture are checked. |
|
k. |
Click OK to complete the selection; then click Close to close the Component Gallery. (The LEAD RasterView Control appears in the Controls toolbar.) |
|
l. |
Click the LEAD RasterView Control icon; then size and position the control as you want it to appear at run time. |
|
m. |
Use the right mouse button to edit the properties of the new LEAD RasterView Control. |
|
n. |
Change the ID to IDC_LEADRASTERVIEW1. |
10. |
Add seven command buttons to your form and name them as follows: |
|
|
ID |
Caption |
|
IDC_STARTUP_SERVER |
Start Up Server |
|
IDC_SHUTDOWN_SERVER |
Shut Down Server |
|
IDC_CONNECT |
Connect To Remote Server |
|
IDC_DISCONNECT |
Disconnect From Remote Server |
|
IDC_LOAD_REMOTE |
Load Remote Image |
|
IDC_START_MAG_GLASS |
Start Magnifying Glass |
|
IDC_STOP_MAG_GLASS |
Stop Magnifying Glass |
11. |
Add an Edit Box Control to the main window and give it the following ID: |
|
|
ID |
|
|
IDC_REMOTE_ADDRESS |
|
12. |
Press Ctrl-F4 to close all windows back to the Project Workspace. |
|
13. |
Do the following to add m_LEADRasterView1 and m_RemoteAddress to the CMagGlsNtComDlg class and link the variables to its control using dynamic data exchange: |
|
|
a. |
Press Ctrl-W. (The MFC ClassWizard dialog box appears.) |
|
b. |
Click the Member Variables tab. |
|
c. |
In the Class Name box, select CMagGlsNtComDlg. |
|
d. |
In the Control IDs list, select IDC_LEADRASTERVIEW1. |
|
e. |
Click the Add Variable... button. |
|
f. |
Specify m_LEADRasterView1 as the variable name, and Control as the category. |
|
g. |
Click OK to close the dialog box. |
|
h. |
Back in MFC Wizard, go to the Member Variables tab, and ensure CMagGlsNtComDlg is in the Class Name box. |
|
i. |
In the Control IDs list, select IDC_Remote. |
|
j. |
Click the Add Variable... button. |
|
k. |
Specify m_RemoteAddress as the variable name, and control as the category. |
|
l. |
Click OK to close the dialog box, and click OK to close the MFC ClassWizard. |
14. |
Edit the MagGlsNtComDlg.h file and change the definition of CMagGlsNtComDlg : CDialog by inserting the following lines after DECLARE_MESSAGE_MAP: |
public:
short m_hServer;
long m_nCommandID;
BOOL m_bMagGlass;
ILEADRasterInet *m_pRasterInet;
CRasterInetSink *m_pRasterInetSink;
IConnectionPoint *m_pInetCP;
DWORD m_dwInetCookie;
15. |
Go to the OnInitDialog() function as follows: |
|
|
a. |
In the Project Workspace, click the ClassView tab. |
|
b. |
Double-click the MagGlsNtCom classes folder to open it. |
|
c. |
Expand the CMagGlsNtComDlg class. |
|
d. |
Double-click the OnInitDialog() function to edit it. |
16. |
Edit the OnInitDialog() function to add the following code after the line that says //TODO: Add extra initialization here: |
// Initialize some variables
m_hServer = 0;
m_nCommandID = 0;
m_bMagGlass = FALSE;
// Set defaults for displaying the image.
// These are all persistent properties that can be set in the properties box.
m_LEADRasterView1.SetAppearance (RASTERVIEW_APPEARANCE_FLAT);
m_LEADRasterView1.SetBorderStyle (1);
m_LEADRasterView1.SetBackColor (RGB(255, 255, 125));
m_LEADRasterView1.SetPaintDither (PAINTDITHER_DIFFUSION);
m_LEADRasterView1.SetPaintPalette (PAINTPALETTE_AUTO);
m_LEADRasterView1.SetAutoRepaint (TRUE);
m_LEADRasterView1.SetAutoSize (FALSE);
m_LEADRasterView1.SetAutoSetRects (TRUE);
m_LEADRasterView1.SetPaintSizeMode(PAINTSIZEMODE_FIT);
// Create the RasterInet object
CoCreateInstance(CLSID_LEADRasterInet, NULL, CLSCTX_ALL,
IID_ILEADRasterInet, (void**)&m_pRasterInet);
// Create a temp LEADRaster object and use it
// to unlock support for the Inet object
IClassFactory2 *pCF2=NULL;
CLSID clsid;
ILEADRaster *pRaster=NULL;
static const WCHAR BASED_CODE _szID[] = L"LEADRaster.LEADRaster";
CLSIDFromProgID(_szID, &clsid);
CoGetClassObject(clsid, CLSCTX_ALL, NULL, IID_IClassFactory2, (void**)&pCF2);
// This object is licensed, so we need to pass a license key
static const WCHAR BASED_CODE _szLic[] = L"LEADTOOLS OCX Copyright (c) 1991-2005 LEAD Technologies, Inc.";
BSTR lpLic = SysAllocString(_szLic);
pCF2->CreateInstanceLic(NULL, NULL, IID_IUnknown, lpLic, (void**)&pRaster);
SysFreeString(lpLic);
pCF2->Release();
// Unlock the Internet features.
// Note that TestKey is a sample key and will not work in your toolkit.
pRaster->UnlockSupport(L_SUPPORT_INTERNET, "TestKey");
pRaster->Release();
// Stop runtime exceptions generation for LEAD RasterView
// Control and LEAD Raster Internet object.
m_LEADRasterView1.SetEnableMethodErrors (FALSE);
m_pRasterInet->EnableMethodErrors = FALSE;
//Instantiate the sink class and hold a pointer to it.
m_pRasterInetSink = new CRasterInetSink;
m_pRasterInetSink->m_pDlg = this;
//Establish a connection between source and sink.
LPUNKNOWN pInetUnkSink = m_pRasterInetSink->GetIDispatch(FALSE);
AfxConnectionAdvise(m_pRasterInet, DIID__LTRASINETEvents, pInetUnkSink, FALSE, &m_dwInetCookie);
17. |
Press Ctrl-W to go to the MFC Class Wizard; then do the following: |
|
|
a. |
Click the Add Class button. |
|
b. |
Click New.... |
|
c. |
Type CRasterInetSink for the name of the class |
|
d. |
Select CCmdTarget for the base class of the new class. |
|
e. |
Under Automation, click the Automation radio button. |
|
f. |
Click OK to create the class, and click OK to close the MFC ClassWizard. |
|
g. |
In the RasterInetSink.h file, move the destructor so that it is public: |
virtual ~CRasterInetSink();
// Implementation
protected:
|
h. |
In the RasterInetSink.h file, add the following to the top of the file: |
|
|
class CMagGlsNtComDlg; |
|
i. |
In the RasterInetSink.h file, add the following to the CRasterInetSink class in the //Attributes public section: |
|
|
// Attributes |
|
|
public: |
|
|
CMagGlsNtComDlg *m_pDlg; |
|
j. |
In the RasterInetSink.cpp file, add the following to the top of the file (after the #include "RasterInetSink.h") |
#include " MagGlsNtComDlg.h"
18. |
Add #include statements so you can access the new class: |
|
|
a. |
In the Project Workspace, click the FileView tab. |
|
b. |
Double-click the MagGlsNtCom files folder to open it. |
|
c. |
Double-click the Header Files folder to open it. |
|
d. |
Double-click the StdAfx.h file to edit it. |
|
e. |
Add the following lines to the end of the file: |
|
|
#include <AFXCTL.H> |
|
|
#include "RasterInetSink.h" |
19. |
Edit the header for the Sink class: |
|
|
a. |
In the Project Workspace, click the FileView tab. |
|
b. |
Double-click the MagGlsNtCom files folder to open it. |
|
c. |
Double-click the Header Files folder to open it. |
|
d. |
Double-click the RasterInetSink.h file to edit it. |
|
e. |
Add the following just before //}}AFX_MSG: |
afx_msg void OnInetReceiveBitmap(short, long);
afx_msg void OnInetConnected(short);
afx_msg void OnInetDisconnected(short);
afx_msg void OnInetAccept(short);
afx_msg void OnInetReceiveCmd(short, short, long, short, struct ILEADRasterInetPacket*, long, const _variant_t &);
afx_msg void OnInetReceiveRsp(short, short, long, short, short, struct ILEADRasterInetPacket*, long, const _variant_t &);
20. |
Edit the source for the Sink class: |
|
|
a. |
In the Project Workspace, click the FileView tab. |
|
b. |
Double-click the MagGlsNtCom files folder to open it. |
|
c. |
Double-click the Source Files folder. |
|
d. |
Double-click the RasterInetSink.cpp file to edit it. |
|
e. |
Add the following to the DISPATCH_MAP just before //}}AFX_DISPATCH_MAP: |
DISP_FUNCTION_ID(CRasterInetSink,"InetReceiveBitmap",1,OnInetReceiveBitmap,VT_EMPTY,VTS_I2 VTS_I4)
DISP_FUNCTION_ID(CRasterInetSink,"InetConnected",3,OnInetConnected,VT_EMPTY,VTS_I2)
DISP_FUNCTION_ID(CRasterInetSink,"InetDisconnected",4,OnInetDisconnected,VT_EMPTY,VTS_I2)
DISP_FUNCTION_ID(CRasterInetSink,"InetAccept",5,OnInetAccept,VT_EMPTY,VTS_I2)
DISP_FUNCTION_ID(CRasterInetSink,"InetReceiveCmd",12,OnInetReceiveCmd,VT_EMPTY,VTS_I2 VTS_I2 VTS_I4 VTS_I2 VTS_DISPATCH VTS_I4 VTS_VARIANT)
DISP_FUNCTION_ID(CRasterInetSink,"InetReceiveRsp",13,OnInetReceiveRsp,VT_EMPTY,VTS_I2 VTS_I2 VTS_I4 VTS_I2 VTS_I2 VTS_DISPATCH VTS_I4 VTS_VARIANT)
|
f. |
Inside the BEGIN_INTERFACE_MAP section, change the INTERFACE_PART to the following: |
INTERFACE_PART(CRasterInetSink, DIID__LTRASINETEvents, Dispatch)
|
g. |
Add the following to the end of the file: |
void CRasterInetSink::OnInetReceiveBitmap(short iComputer, long hBitmap)
{
m_pDlg->m_LEADRasterView1.GetRaster().SetBitmap(hBitmap);
}
void CRasterInetSink::OnInetConnected(short iComputer)
{
BSTR sRemote;
/* Get the name of the remote host */
m_pDlg->m_pRasterInet->InetGetHostName(iComputer, HOST_NAME_DESCRP);
sRemote = m_pDlg->m_pRasterInet->GetInetHostName();
/* Add this connection to our SendList. */
m_pDlg->m_pRasterInet->PutSendList(m_pDlg->m_pRasterInet->GetSendListNum(), iComputer);
AfxMessageBox(TEXT("Successfully connected to server."));
}
void CRasterInetSink::OnInetDisconnected(short iComputer)
{
if(m_pDlg->m_hServer == 0)
AfxMessageBox(TEXT("Disconnect from remote server."));
else
AfxMessageBox(TEXT("Connection to remote computer closed."));
}
void CRasterInetSink::OnInetAccept(short iServer)
{
int nRet;
short hComputer;
BSTR hName;
CString cs;
nRet = m_pDlg->m_pRasterInet->InetAcceptConnect(m_pDlg->m_hServer);
hComputer = m_pDlg->m_pRasterInet->GetInetConnectedComputer();
if (nRet != 0)
{
cs.Format(TEXT("%s %d\n"), TEXT("Error accepting connection:"), nRet);
AfxMessageBox(cs);
}
m_pDlg->m_pRasterInet->InetGetHostName(hComputer, HOST_NAME_DESCRP);
hName = m_pDlg->m_pRasterInet->GetInetHostName();
/* add to our send list */
m_pDlg->m_pRasterInet->PutSendList(m_pDlg->m_pRasterInet->GetSendListNum(), hComputer);
AfxMessageBox(TEXT("Connection accepted."));
}
void CRasterInetSink::OnInetReceiveCmd(short iComputer, short InetCommand, long nCommandID, short nError, struct ILEADRasterInetPacket * Params, long nExtraDataSize,ILEADRasterVariant * ExtraData)
{
short nStatus;
CString szMsg;
ILEADRasterInetPacket * Packet = NULL;
ILEADRasterIO *pRasterIO=NULL;
CString szTemp;
BSTR strFileName;
ILEADRasterVariant * vColorBuffer = NULL;
HRESULT hr = ::CoCreateInstance(CLSID_LEADRasterVariant, NULL, CLSCTX_ALL,
IID_ILEADRasterVariant, (void **)&vColorBuffer);
Params->QueryInterface (IID_ILEADRasterInetPacket, (void **)&Packet);
if (!Packet)
return;
nStatus = ERROR_FEATURE_NOT_SUPPORTED;
if(nError != 0)
nStatus = ERROR_TRANSFER_ABORTED;
else
{
switch(InetCommand)
{
case INETCMD_LOAD:
// check the validity of the parameters
if((Packet->GetParamCount() == 4) && (Packet->GetParamType(0) == PARAM_TYPE_STRING) &&
(Packet->GetParamType(1) == PARAM_TYPE_INT32) && (Packet->GetParamType(2) == PARAM_TYPE_INT32) &&
(Packet->GetParamType(3) == PARAM_TYPE_UINT32))
{
CoCreateInstance(CLSID_LEADRasterIO, NULL, CLSCTX_ALL, IID_ILEADRasterIO, (void**)&pRasterIO);
szTemp = (CString)Packet->GetParamValue(0)->StringValue ;
strFileName =szTemp .AllocSysString();
nStatus = pRasterIO->Load(m_pDlg->m_LEADRasterView1.GetRaster(),
strFileName,
(short)Packet->GetParamValue(1)->LongValue ,
1, 1);
pRasterIO->Release();
if(nStatus != 0)
{
szMsg.Format(TEXT("Load Bitmap failed with error code %d"), nStatus);
AfxMessageBox(szMsg);
}
else
{
nStatus = m_pDlg->m_pRasterInet->InetSendBitmap(m_pDlg->m_LEADRasterView1.GetRaster().m_lpDispatch,
FILE_CMP, 0, QFACTOR_PQ2);
if(nStatus != 0)
{
szMsg.Format(TEXT("SendBitmap failed with error code %d"), nStatus);
AfxMessageBox(szMsg);
}
}
}
else
nStatus = ERROR_INV_PARAMETER; // Invalid parameter
m_pDlg->m_pRasterInet->InetSendLoadRsp(nCommandID, 0, 0, NULL, nStatus);
return;
break;
case INETCMD_GET_MAGGLASS_DATA:
// check the validity of the parameters
if((Packet->GetParamCount() == 5) && (Packet->GetParamType(0) == PARAM_TYPE_UINT32) &&
(Packet->GetParamType(1) == PARAM_TYPE_UINT32) && (Packet->GetParamType(2) == PARAM_TYPE_USTRING) &&
(Packet->GetParamType(3) == PARAM_TYPE_INT32) && (Packet->GetParamType(4) == PARAM_TYPE_INT32))
{
if(m_pDlg->m_LEADRasterView1.GetRaster().GetBitmap() != 0)
{
nStatus = m_pDlg->m_pRasterInet->InetGetMagGlassData(m_pDlg->m_LEADRasterView1.GetRaster().m_lpDispatch,
vColorBuffer,
Packet->GetParamValue(2),
Packet->GetParamValue(3)->LongValue,
Packet->GetParamValue(4)->LongValue);
if(nStatus != 0)
{
szMsg.Format(TEXT("InetGetMagGlassData failed with error code %d"), nStatus);
AfxMessageBox(szMsg);
}
}
else
nStatus = ERROR_INV_PARAMETER; // Invalid parameter
}
else
nStatus = ERROR_INV_PARAMETER; // Invalid parameter
m_pDlg->m_pRasterInet->InetSendGetMagGlassDataRsp(nCommandID,
vColorBuffer,
Packet->GetParamValue(2),
Packet->GetParamValue(3)->LongValue ,
Packet->GetParamValue(4)->LongValue ,
0, NULL, nStatus);
return;
break;
}
}
m_pDlg->m_pRasterInet->InetSendRsp((InetCmdType)InetCommand, nCommandID, Params, 0, NULL, nStatus);
vColorBuffer->Release();
}
void CRasterInetSink::OnInetReceiveRsp(short iComputer, short InetCommand, long nCommandID, short nError, short nStatus, struct ILEADRasterInetPacket * Params, long nExtraDataSize, ILEADRasterVariant * ExtraData)
{
short nRet;
CString szMsg;
ILEADRasterInetPacket * Packet = NULL;
Params->QueryInterface (IID_ILEADRasterInetPacket, (void **)&Packet);
if (!Packet)
return;
if(nError != 0)
return;
switch(InetCommand)
{
case INETCMD_LOAD:
if(nStatus != 0)
{
szMsg.Format(TEXT("Load failed with error code %d"), nStatus);
AfxMessageBox(szMsg);
}
break;
case INETCMD_GET_MAGGLASS_DATA:
if(nStatus == 0)
{
if((Packet->GetParamCount() == 6) && (Packet->GetParamType(0) == PARAM_TYPE_UINT32) &&
(Packet->GetParamType(1) == PARAM_TYPE_USTRING) && (Packet->GetParamType(2) == PARAM_TYPE_UINT32) &&
(Packet->GetParamType(3) == PARAM_TYPE_USTRING) && (Packet->GetParamType(4) == PARAM_TYPE_INT32) &&
(Packet->GetParamType(5) == PARAM_TYPE_INT32))
{
nRet = m_pDlg->m_LEADRasterView1.UpdateMagGlass(Packet->GetParamValue(1),
Packet->GetParamValue(3),
Packet->GetParamValue(4)->LongValue ,
Packet->GetParamValue(5)->LongValue ,
TRUE);
if(nRet != 0)
{
szMsg.Format(TEXT("UpdateMagGlass failed with error code %d"), nRet);
AfxMessageBox(szMsg);
}
}
else
AfxMessageBox(TEXT("Invalid parameter passed to INETCMD_GET_MAGGLASS_DATA response"));
}
else
{
szMsg.Format(TEXT("Get MagGlass Data from sever failed with error code %d"), nStatus);
AfxMessageBox(szMsg);
}
break;
}
}
21. |
Press Ctrl-W to go to the MFC Class Wizard; then do the following: |
|
|
a. |
Click the Message Maps tab. |
|
b. |
In the Class name combo box, select CMagGlsNtComDlg. |
|
c. |
In the Object IDs list box, select CMagGlsNtComDlg. |
|
d. |
In the Messages list box, select WM_DESTROY. |
|
e. |
Click the Add function button. Choose OK for the default function name (OnDestroy). |
|
f. |
Click the Edit Code button to start entering the code. |
22. |
Enter new code for OnDestroy function, so it becomes as follows: |
//Terminate a connection between source and sink.
LPUNKNOWN pInetUnkSink = m_pRasterInetSink->GetIDispatch(FALSE);
AfxConnectionUnadvise(m_pRasterInet, DIID__LTRASINETEvents,
pInetUnkSink, FALSE, m_dwInetCookie);
delete m_pRasterInetSink;
m_pRasterInet->Release();
CDialog::OnDestroy();
23. |
Press Ctrl-W to go to the MFC Class Wizard; then do the following: |
|
|
a. |
Click the Message Maps tab. |
|
b. |
In the Class Name combo box, select CMagGlsNtComDlg. |
|
c. |
In the Object IDs list box, select IDCANCEL. |
|
d. |
In the Messages list box, select BN_CLICKED. |
|
e. |
Click the Add function button. Choose OK for the default function name (OnCancel). |
|
f. |
Click the Edit Code button and add the following code after the line that says //TODO: Add extra cleanup here: |
// TODO: Add extra cleanup here
int i, num;
/* disconnect all connections */
num = m_pRasterInet->GetConnectListNum();
for (i = 0; i < num; i++)
{
m_pRasterInet->InetDisconnect(m_pRasterInet->GetConnectList(i));
}
if(m_bMagGlass)
m_LEADRasterView1.StopMagGlass();
CDialog::OnCancel();
24. |
To add code for the Start Up Server button, press Ctrl-W to go to the MFC Class Wizard; then do the following: |
|
|
a. |
Click the Message Maps tab. |
|
b. |
In the Class Name combo box, select CMagGlsNtComDlg. |
|
c. |
In the Object IDs list box, select IDC_STARTUP_SERVER. |
|
d. |
In the Messages list box, select BN_CLICKED. |
|
e. |
Click the Add function button. Choose OK for the default function name (OnStartupServer). |
|
f. |
Click the Edit Code button and code the OnStartupServer procedure as follows: |
int nRet;
CString cs;
/* initialize server on port 1000 */
nRet = m_pRasterInet->InetServerInit(&m_hServer, 1000);
if (nRet != 0)
{
cs.Format(TEXT("%s %d\n"), TEXT("Error initializing server:"), nRet);
AfxMessageBox(cs);
}
25. |
To add code for the Shut Down Server button, press Ctrl-W to go to the MFC Class Wizard; then do the following: |
|
|
a. |
Click the Message Maps tab. |
|
b. |
In the Class Name combo box, select CMagGlsNtComDlg. |
|
c. |
In the Object IDs list box, select IDC_SHUTDOWN_SERVER. |
|
d. |
In the Messages list box, select BN_CLICKED. |
|
e. |
Click the Add function button. Choose OK for the default function name (OnShutdownServer). |
|
f. |
Click the Edit Code button and code the OnShutdownServer procedure as follows: |
short nRet;
CString cs;
if (m_hServer != 0)
{
nRet = m_pRasterInet->InetServerClose(m_hServer);
if(nRet != 0)
{
cs.Format(TEXT("%s %d\n"), TEXT("Error Shutting Down server:"), nRet);
AfxMessageBox(cs);
}
else
m_hServer = 0;
}
26. |
To add code for the Connect To Remote Server button, press Ctrl-W to go to the MFC Class Wizard; then do the following: |
|
|
a. |
Click the Message Maps tab. |
|
b. |
In the Class Name combo box, select CMagGlsNtComDlg. |
|
c. |
In the Object IDs list box, select IDC_CONNECT. |
|
d. |
In the Messages list box, select BN_CLICKED. |
|
e. |
Click the Add function button. Choose OK for the default function name (OnConnect). |
|
f. |
Click the Edit Code button and code the OnConnect procedure as follows: |
int nRet;
CString cs,text;
/* get the name of the computer entered in the edit box control */
m_RemoteAddress.GetWindowText(text);
/* Connect to remote computer on port 1000 */
nRet = m_pRasterInet->InetConnect(text.AllocSysString(), 1000);
if (nRet != 0)
{
cs.Format(TEXT(" %s\n %s\n"), TEXT("Error connecting to :"), text);
AfxMessageBox(cs);
}
27. |
Press Ctrl-W to go to the MFC Class Wizard; then do the following: |
|
|
a. |
Click the Message Maps tab. |
|
b. |
In the Class Name combo box, select CMagGlsNtComDlg. |
|
c. |
In the Object IDs list box, select IDC_DISCONNECT. |
|
d. |
In the Messages list box, select BN_CLICKED. |
|
e. |
Click the Add function button. Choose OK for the default function name (OnDisconnect). |
|
f. |
Click the Edit Code button and code the OnDisconnect procedure as follows: |
int nRet;
CString cs;
/* We are assuming only one connection in this example.
Therefore, the handle to the remote computer will be
in the first position in the SendList.
*/
nRet = m_pRasterInet->InetDisconnect(m_pRasterInet->GetSendList(0));
if (nRet != 0)
{
cs.Format(TEXT("%s %d\n"), TEXT("Error disconnecting from the server:"),nRet);
AfxMessageBox(cs);
}
28. |
To add code for the Load Remote Image button, press Ctrl-W to go to the MFC Class Wizard; then do the following: |
|
|
a. |
Click the Message Maps tab. |
|
b. |
In the Class Name combo box, select CMagGlsNtComDlg. |
|
c. |
In the Object IDs list box, select IDC_LOAD_REMOTE. |
|
d. |
In the Messages list box, select BN_CLICKED. |
|
e. |
Click the Add function button. Choose OK for the default function name (OnLoadRemote). |
|
f. |
Click the Edit Code button and code the OnLoadRemote procedure as follows: |
short nRet;
CString csOut;
nRet = m_pRasterInet->InetSendLoadCmd(m_nCommandID++, "v:\\images\\eagle.cmp", 0, 1);
if((nRet != 0) && (nRet != ERROR_DATA_QUEUED))
{
csOut.Format(TEXT("ERROR %d calling InetSendLoadCmd."), nRet);
AfxMessageBox(csOut);
}
29. |
To add code for the Start Magnifying Glass button, press Ctrl-W to go to the MFC Class Wizard; then do the following: |
|
|
a. |
Click the Message Maps tab. |
|
b. |
In the Class Name combo box, select CMagGlsNtComDlg. |
|
c. |
In the Object IDs list box, select IDC_START_MAG_GLASS. |
|
d. |
In the Messages list box, select BN_CLICKED. |
|
e. |
Click the Add function button. Choose OK for the default function name (OnStartMagGlass). |
|
f. |
Click the Edit Code button and code the OnStartMagGlass procedure as follows: |
if(m_LEADRasterView1.GetRaster().GetBitmap() != 0 && m_hServer == 0)
{
// Enable MagGlassExt event.
if(!m_LEADRasterView1. GetEnableMagGlassEvent())
m_LEADRasterView1. SetEnableMagGlassEvent(TRUE);
m_LEADRasterView1.SetRgnFrameType(0);
// Start the Magnifying Glass
int nRet = m_LEADRasterView1.StartMagGlass(150.0f, 100.0f, 200,
0, m_LEADRasterView1.GetBackColor(),
FALSE, 1.0f, TRUE, CROSSHAIR_FINE,
TRUE, TRUE);
if(nRet == 0)
m_bMagGlass = TRUE;
}
30. |
To add code for the Stop Magnifying Glass button, press Ctrl-W to go to the MFC Class Wizard; then do the following: |
|
|
a. |
Click the Message Maps tab. |
|
b. |
In the Class Name combo box, select CMagGlsNtComDlg. |
|
c. |
In the Object IDs list box, select IDC_STOP_MAG_GLASS. |
|
d. |
In the Messages list box, select BN_CLICKED. |
|
e. |
Click the Add function button. Choose OK for the default function name (OnStopMagGlass). |
|
f. |
Click the Edit Code button and code the OnStopMagGlass procedure as follows: |
if(m_LEADRasterView1.GetRaster().GetBitmap() != 0 && m_hServer == 0)
{
int nRet = m_LEADRasterView1.StopMagGlass();
if(nRet == 0)
m_bMagGlass = FALSE;
}
31. |
Press Ctrl-W to go to the MFC Class Wizard; then do the following: |
|
|
a. |
In the Class name combo box, select CMagGlsNtComDlg. |
|
b. |
In the Object IDs list box, select IDC_LEADRASTERVIEW1. |
|
c. |
In the Messages list box, select MagGlassExt. |
|
d. |
Click the Add function button. Choose OK for the default function name (OnMagGlassExtLeadrasterview1). |
|
e. |
Click the Edit Code button and code the OnMagGlassExtLeadrasterview1 procedure as follows: |
short nRet;
CString csOut;
nRet = m_pRasterInet->InetSendGetMagGlassDataCmd(m_nCommandID++, 0, vMaskPlane, nMaskPlaneStart, nMaskPlaneEnd);
if((nRet != 0) && (nRet != ERROR_DATA_QUEUED))
{
csOut.Format(TEXT("ERROR %d calling InetSendGetMagGlassDataCmd."), nRet);
AfxMessageBox(csOut);
}
32. |
Edit the MagGlsNtCom.cpp file and add the following code as the first line in the InitInstance function: |
CoInitialize(NULL);
33. |
Edit the MagGlsNtCom.cpp file and add the following code as the next to last line in the InitInstance function (before the return)!: |
CoUninitialize();
34. |
To accommodate a 256-color display driver, continue with the remaining steps, which send WM_QUERYNEWPALETTE and WM_PALETTECHANGED messages to the LEADTOOLS RasterView COM Control. |
35. |
In the Project Workspace, click the FileView tab. |
36. |
Edit the MagGlsNtComDlg.h file and insert the following lines in the definition of CMagGlsNtComDlg class, just before DECLARE_MESSAGE_MAP(): |
afx_msg BOOL OnQueryNewPalette();
afx_msg void OnPaletteChanged( CWnd *pwin );
37. |
Edit the MagGlsNtComDlg.cpp file and insert the following lines between the lines: BEGIN_MESSAGE_MAP(CMagGlsNtComDlg, CDialog) and END_MESSAGE_MAP(): |
ON_WM_QUERYNEWPALETTE()
ON_WM_PALETTECHANGED()
38. |
Go to the end of MagGlsNtComDlg.cpp file and insert the following two functions: |
BOOL CMagGlsNtComDlg::OnQueryNewPalette()
{
if(!IsWindow(m_LEADRasterView1.m_hWnd))
return FALSE;
return m_LEADRasterView1.SendMessage(WM_QUERYNEWPALETTE);
}
void CMagGlsNtComDlg::OnPaletteChanged(CWnd* pFocusWnd)
{
if(pFocusWnd->m_hWnd == m_hWnd || !IsWindow(m_LEADRasterView1.m_hWnd))
return;
m_LEADRasterView1.SendMessage(WM_PALETTECHANGED, (WPARAM) pFocusWnd->m_hWnd);
}
39. |
On the main menu, select Build > Build MagGlsNtCom.exe to build the project. |
40. |
On the main menu, select Build > Execute MagGlsNtCom.exe twice, to run two projects. |
41. |
In the first project press the Start Up Server button. |
42. |
In the second project fill the edit box with the IP address of the remote computer on which you started the first project as a server. Then, press the Connect To Remote Server button to connect to the specified address. |
43. |
Press the Load Remote Image button of the second project started, to load an image on the server. Then press the Start Magnifying Glass button to start the Magnifying Glass with Internet support. Press the left mouse button and move over the image to see the zoomed area using the Magnifying Glass with Internet support. |