Sending Images to a Remote Computer (Visual C++ 5.0 and later)

Take the following steps to add some code that will let you send images to a remote computer.

1.

Start with the project you created in Initializing a Computer as a Server and Accepting Connections.

2.

Add the LEAD RasterView Control to your main window as follows:

 

For C++ 5.0:

 

a.

In the Project Workspace, click the ResourceView tab.

 

b.

Double-click the server resources folder to open it.

 

c.

Double-click the Dialog folder to open it.

 

d.

Double-click IDD_SERVER_DIALOG to design the dialog box.

 

e.

From the main menu, select Project > Add To Project > Components and controls.

 

f.

Select Registered ActiveX controls.

 

g.

Double-click the LEAD RasterView Control (14.0) icon. (The Confirm Classes dialog box appears.)

 

h.

Ensure that CLEADRasterView, CLEADRaster and CPicture are checked.

 

i.

Click OK to complete the selection; then click Close to close the Component Gallery. (The LEAD RasterView Control appears in the controls toolbar.)

 

j.

Click the LEAD RasterView Control icon; then size and position the control as you want it to appear at run time.

 

k.

Use the right mouse button to edit the properties of the new LEAD RasterView Control.

 

l.

Change the ID to IDC_LEADRASTERVIEW1.

3.

Add some #include statements to your program:

 

a.

In the Project Workspace, click the FileView tab.

 

b.

Double-click the server 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, just after the #import statments:

#include "LEADRasterView.h"

#include "LEADRaster.h"

4.

Add a command button to the main window and set the ID and Caption properties as follows:

 

ID

Caption

 

IDC_SEND

Send Bitmap

5.

Do the following to add m_LEADRasterView1 to the CServerDlg class and link the variable to the LEAD RasterView 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 CServerDlg.

 

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 and click OK to close the MFC ClassWizard.

6.

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 CServerDlg.

 

c.

In the Object IDs list box, select IDC_SEND.

 

d.

In the Messages list box, select BN_CLICKED.

 

e.

Click the Add function button. Choose OK for the default function name (OnSend).

 

f.

Click the Edit Code button and code the OnSend procedure as follows:

ILEADRasterIO *pRasterIO=NULL;
ILEADRasterProcess *pRasterProc=NULL;
long hDIB;

if(m_LEADRasterView1.GetRaster().GetBitmap() == 0)
{
   CoCreateInstance(CLSID_LEADRasterIO, NULL, CLSCTX_ALL, IID_ILEADRasterIO, (void**)&pRasterIO);
   pRasterIO->Load(m_LEADRasterView1.GetRaster(), "o:\\images\\new\\001.jpg", 0, 1, 1);
   pRasterIO->Release();
}

CoCreateInstance(CLSID_LEADRasterProcess, NULL, CLSCTX_ALL, IID_ILEADRasterProcess, (void**)&pRasterProc);
pRasterProc->Flip(m_LEADRasterView1.GetRaster());
pRasterProc->Release();

//send the images to the remote computer
hDIB = m_LEADRasterView1.GetRaster().GetDIB();
m_pRasterInet->InetSendDIB(hDIB, FILE_CMP, 24, (QFactorConstants)75);
GlobalFree((HGLOBAL)hDIB);

7.

On the main menu, select Build> Build server.exe to build the project.

8.

On the main menu, select Build> Execute server.exe to run the project.

9.

The exe generated from this project will be used as a server for other tasks in the tutorial.