Thanks VladimirF

I've taken your advice and re-wrote the code as shown below:

Code:
void CNucPlot::SaveFile()
{
	CPaintDC dc(this); // device context for painting
	//  Set pictures size;
	int Width = 700;
	int Height = 700;

  //  get the area to draw in.
	CRect rcClient;
	rcClient.top = 0;
	rcClient.left = 0;
	rcClient.bottom = Height;
	rcClient.right = Width;

  //  create a memory dc for double buffering.
	CMemDC myDC(&dc, &rcClient);

	myDC.SetBkColor(RGB(255,255,255)); 
	int nFontHeight = Height / 80.0f;
	CBrush newColour(RGB(255,199,10));
	myDC.SelectObject(newColour);
	CPen lColourPen (PS_SOLID, 5,RGB(50,100,150));
	myDC.SelectObject(&lColourPen); // 100

	myDC.Rectangle(10,10,Width-10,Height-10);
	myDC.Ellipse(10,10,Width-10,Height-10);

	// JPEG Saving ..
	struct jpeg_compress_struct cinfo;
	struct jpeg_error_mgr jerr;
	FILE * outfile;
	JSAMPLE* scanline;
	COLORREF pixel;

	cinfo.err = jpeg_std_error(&jerr);
	jpeg_create_compress(&cinfo);

	outfile = fopen("robbie.jpg", "wb");
	if(outfile == NULL) return;

	jpeg_stdio_dest(&cinfo, outfile);
	cinfo.image_width = Width;
	cinfo.image_height = Height;
	cinfo.input_components = 3;
	cinfo.in_color_space = JCS_RGB;	
	jpeg_set_defaults(&cinfo);

	int quality = 90;
	if(quality < 0) quality = 0;
	if(quality > 100) quality = 100;

	jpeg_set_quality(&cinfo, quality, FALSE);
	jpeg_start_compress(&cinfo, TRUE);
	scanline = new JSAMPLE[Width*3];
//	MessageBox("Finished setting up JPEG - now go through each JPEG line\n");

	for(int posy = 0; posy < Height; posy++) 
	{
		for(int posx = 0; posx < Width; posx++)
		{
			pixel = GetPixel(myDC, posx, posy);
			scanline[posx*3+0] = GetRValue(pixel);
			scanline[posx*3+1] = GetGValue(pixel);
			scanline[posx*3+2] = GetBValue(pixel);

		}
		jpeg_write_scanlines(&cinfo, &scanline, 1);
	}
	jpeg_finish_compress(&cinfo);
	jpeg_destroy_compress(&cinfo);

	delete scanline;
	fclose(outfile);
}
Now it writes correctly to a JPEG file. My problem with this code is that the picture displays on screen as well. Does anyone know how I can modify the code so that it only generates the JPEG file?

Also, when I try to generate a really big JPEG (say 2000 x 2000), it takes along time to complete. It might just be that it is a CPU intensive task to create a big JPEG. However does anyone know a better way of reading the CDC and dumping it to a JPEG file?

Thanks

Robbie