( Index )
Month

Brief Information about the Jan '07 CSIG Meeting

Clip1.1 - a Deluxe Print Screen Utility

C++ Version 7 and Visual Studio 2005

Written by B. Arnold

Sample Screen Shot

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.

Here's what Wikipedia says about CLI:

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.

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.

New Bells and Whistles added to the original.

Version 1.10 for January 2007 Meeting.

  1. A menu bar has been added to replace the functionality of the buttons.
  2. If needed, the clipboard is automatically copied after 2 seconds.
  3. A "Rubber Band" algorithm now allows selecting (cropping) part of the image.
  4. The image may be copied back to the Clipboard for emailing, etc.
  5. Picture files may be "Dropped" on the GUI. (Graphical User Interface)
  6. A Help button (menu) has been added for user instructions.
  7. As earlier, the GUI image can then be printed with a variety of options.

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 )

Sample Code - VC7

        // 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.
            }

"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