( Index )
Month

Brief Information about the Dec '06 CSIG Meeting

Clip1 - a Print Screen Utility

C++ Version 7 and Visual Studio 2005

Written by B. Arnold

Form Designer Screen Shot Print Preview Screen

Welcome to the CSIG, a Special Interest Group of the ACGNJ. The subject for this month is a simple screen printing program. 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. Here's what Wikipedia says:

The Common Language Infrastructure (CLI) is an open specification developed by Microsoft that describes the executable code and runtime environment that form the core of the Microsoft .NET Framework. The specification defines an environment that allows multiple high-level languages to be used on different computer platforms without being rewritten for specific architectures.

Microsoft .Net Framework 2.0
C++ 7.0
.Net 2.0
CLI
Common Language Infrastructure
Managed

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.

Here are 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 )

Sample Code - VC7

    // The user clicks the "Page Setup" to customize the printer.
    //
    private: System::Void button3_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" button.  This actually brings up the Preview first.
    //
    private: System::Void button2_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 "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"quot; 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.
             }

"Random Access" questions start at 7:30 Tuesday night.

SOURCE CODE

Source Code Files

For help, email me at b a r n o l d @ i e e e . o r g
Back to C++ Main Page