Receiving and Displaying Images from a Remote Computer (Visual C++ 5.0 and later)

Take the following steps to add some code that will let you receive and display images received from a computer acting as a server.

1.

Run the exe you created in Sending Images to a Remote Computer.

2.

Start Visual C++.

3.

Start with the project you created in Connecting to a Remote Computer.

4.

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 remote resources folder to open it.

 

c.

Double-click the Dialog folder to open it.

 

d.

Double-click IDD_REMOTE_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.

5.

Add some #include statements to your program:

 

a.

In the Project Workspace, click the FileView tab.

 

b.

Double-click the remote 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"

6.

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

 

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.

7.

Edit the header for the Sink class:

 

a.

In the Project Workspace, click the FileView tab.

 

b.

Double-click the remote 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);

8.

Edit the source for the Sink class:

 

a.

In the Project Workspace, click the FileView tab.

 

b.

Double-click the remote 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:

DISP_FUNCTION_ID(CRasterInetSink,"InetReceiveBitmap",1,OnInetReceiveBitmap,VT_EMPTY,VTS_I2 VTS_I4)

 

f.

Add the following to the end of the file:

void CRasterInetSink::OnInetReceiveBitmap(short iComputer, long hBitmap)
{
   //assign bitmap to LEAD RasterView control
   m_pDlg->m_LEADRasterView1.GetRaster().SetBitmap(hBitmap);
   /* Are there any messages in the queue? */
   MSG msg;
   while(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
   {
   /* Translate virtual key codes */
   TranslateMessage(&msg);
   /* Dispatches message to window. */
   DispatchMessage(&msg);
   }
}

9.

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

10.

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