Written by B. Arnold
Welcome to the CSIG, a Special Interest Group of the ACGNJ. The subject for this month is a deluxe screen printing program derived from the program presented last month. It uses the latest C++ compiler in Microsoft's Visual Studio 2005.
There are a number of ways to refer to this compiler and code.
This Print Screen Utility demonstrates generalized printing, printing logic and graphical routines for the screen with the new compiler. The program may also be compiled using the free C++ Express compiler.
Version 1.10 for January 2007 Meeting.
Here are some of the details ...
Object: to transfer an image from the clipboard and print it.
Typically used after hitting the Print-Screen key. (If the Alt-Print-Screen key
is hit, only the current application window is printed.)
The output is automatically scaled to the printer and
rotated if desired. As shown above, the preview screen shows
how the image will look when it's printed. A Print Setup
options allows changing the printer, margins, and/or
orientation.
Compile with Microsoft C++ .net 2005 or C++ express.
This is an exciting time for the C Language programming since Microsoft now has 4 different language compilers: C++, C++ Express, C-Sharp, and C-Sharp Express. These are all capable of creating Windows (tm) programs and the "Express" versions are free ! Additionally, Borland has just announced that it also has four new programs that are also available in free versions. These are Turbo C++, Turbo C-Sharp, Turbo Delphi and Turbo Delpi for .NET. You may also want to check with Intel and others for their generally free evaluation versions.
The beginning of the evening (starting at 7:30pm) will be a RANDOM ACCESS discussion. The main presentation will discuss the program.
Our download site has code and programs from most of our meetings. ( Source Code Files )
// The user clicks the "Paste Clipboard" button to initiate transfer of data. // private: System::Void GetImage_Click(System::Object^ sender, System::EventArgs^ e) { // Create a new instance of the DataObject interface. // IDataObject ^pData = Clipboard::GetDataObject(); // If data is bitmap, set the Image of the Picture Box to the Clipboard // if (pData->GetDataPresent(DataFormats::Bitmap)) { pictureBox1->Image = (System::Drawing::Image ^)pData->GetData(DataFormats::Bitmap); EnableControls(true); } else if (timer1->Enabled == false) MessageBox::Show("There is no Bitmap picture in the Clipboard"); } // The user clicks the "Page Setup" to customize the printer. // private: System::Void Setup_Click(System::Object^ sender, System::EventArgs^ e) { pageSetupDialog1->Document = printDocument1; if (System::Windows::Forms::DialogResult::OK == pageSetupDialog1->ShowDialog()) { FixMargins(printDocument1->DefaultPageSettings); // Check inappropriate margins } } // The user clicks the "Print Preview" button. // private: System::Void PrintPreview_Click(System::Object^ sender, System::EventArgs^ e) { printPreviewDialog1->Document = printDocument1; printPreviewDialog1->ShowDialog(); // Following statement is not needed. Just use Print button in Preview. // printDocument1->Print(); } // The user clicks the "Print" button. // private: System::Void Print_Click(System::Object^ sender, System::EventArgs^ e) { printPreviewDialog1->Document = printDocument1; //printPreviewDialog1->ShowDialog(); printDocument1->Print(); } // The "PrintPage event" is raised for each page to be printed. // public: void PrintPageEventHandler1 (Object^ sender, PrintPageEventArgs^ e) { float xOrg, yOrg, fieldWidth, fieldHeight, calcWidth, calcHeight, BmpAspectRatio; fieldWidth = (float)e->MarginBounds.Width; fieldHeight = (float)e->MarginBounds.Height; xOrg = (float)e->MarginBounds.Left; yOrg = (float)e->MarginBounds.Top; if ( printDocument1->PrintController->IsPreview == false ) // Correct printer margin { xOrg -= e->PageSettings->HardMarginX; // about a quarter inch on ink jets. yOrg -= e->PageSettings->HardMarginY; // about a half inch on ink jets. } // example: 6.5" wide x 9" high field has an aspect ratio of 0.72 BmpAspectRatio = (float)pictureBox1->Image->Width / (float)pictureBox1->Image->Height; calcWidth = fieldWidth; calcHeight = fieldWidth / BmpAspectRatio; if (calcHeight > fieldHeight) // It's a tall & narrow image, therefore recalculate. { calcHeight = fieldHeight; calcWidth = fieldHeight * BmpAspectRatio; } // Print the picture box here. e->Graphics->DrawImage(pictureBox1->Image, xOrg, yOrg, calcWidth, calcHeight ); e->HasMorePages = false; // That's all folks. }