( Index )
Month
 

Brief Information about the February '12 CSIG Meeting

KindleRead - Programing Razzle Dazzle - by B.Arnold

Microsoft C++ and Visual Studio

Welcome to the CSIG, a Special Interest Group of the ACGNJ. We will be discussing Windows Programming using Visual C++  from Microsoft.

Sample Screen  Sample Screen 2

And Now For Something Different ...

I've continued developing the Kindle Read program and thought that it would be good to discuss the changes that I made in the area of "Razzle Dazzle". This month's meeting will concentrate only on the additions that I made to the application. These additions can be valid for any application. Their purpose is to make the application more friendly and easier to use. For example, how about a Splash Screen so that the user understands that he/she has just started the most fantastic program in the world! How about some Help Screens so the user can find more information without reading a manual. How about some Checks and Balances in the program to help the user if the data that they enter may cause problems in the output. Often these types of changes are left unwritten because they are not "functional" in the algorithmic sense of the program. They mostly affect the human interaction of the program. For those of you who missed the original lecture, here's an outline:

The subject for this month is a simple Windows based email program. Discussion: Kindle Readers are now selling at $75.  As shown in the above, the reader is designed mostly for text. (It does that very well.) Wouldn't it be nice if you could take information from your browser, word documents, emails, etc. and transfer the data to your Kindle for reading when you are away from your computer. That's what this application facilitates.

Here's how it works:  The program opens an empty window very much like Notepad.  When you see something from another application that you want to read later, just "Select", "Copy", and "Paste" the data into KindleRead. As shown above, I have pasted the data from the CSIG web site on my browser to the KindleRead window. Next, I click the "Send eMail" button to transfer the data to the Kindle. The Kindle gets updated whenever it is turned on. You don't even have to have it with you. As you browse through you documents or web sites you can copy and paste snippets to be read at a later time.

A file is created with the Pasted Data and then send directly to your SMTP provider. It next goes to the Kindle website to be forwarded to your Kindle. Note: there are a number of safeguards that Kindle provides to eliminate Spam. I'll have more information at the meeting.  The code uses the C++ compiler in Microsoft's Visual Studio 2008 and may also be compiled using the free C++ Express compiler. Some of the items that we will discuss are as follows.

Windows Programming with Microsoft Managed code
Microsoft Visual Studio 2008
Debugging
Text and Window I/O
OOP - Object Oriented Programming
Mail, email and SMTP

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 ! I see also that Microsoft is advertising a still newer version, Visual Studio 2010. Additionally, there are other companies making free and almost free compilers. Here's a link with many compilers: http://www.willus.com/ccomp.shtml

Microsoft .NET Framework

This is a large package, over 24 Megs. Most people running updated versions of Windows will already have it on their computer. If not, it may be downloaded from Microsoft.

Here's the download address for the Microsoft Framework:
Microsoft Software
Or, just look for: Microsoft .NET Framework Version x.x Redistributable Package (x86)

There are a number of ways to refer to this compiler and code.

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 -

Sample Code
===========
private: System::Void SendButton_Click(System::Object^  sender, System::EventArgs^  e) {
             sender; e;     // Suppress Warning C4100

             String ^server = "smtp.embarqmail.com";
             String ^account = "********@embarqmail.com";
             String ^password = "*****";
             NetworkCredential ^ myCred = gcnew NetworkCredential(account, password);

             // Create a message and set up. (from,to)
             Mail::MailMessage^ message = gcnew Mail::MailMessage("barnold@ieee.org", "********@free.kindle.com");

             message->Body = gcnew String("Kindle message attached.");
             message->Subject = gcnew String("Message Transfer to Kindle.");

             String ^fname = gcnew String("");
             if (SubjectBox->Text->Length > 0)
                 {
                 bool abort = false;
                 String ^bad = "\"*/:<>?\\|"  ;                 // Check for any bad characters since
                 String ^str = gcnew String(SubjectBox->Text);  // this will become the filename.

                 for(int i=0; i<bad->Length; i++)
                     for(int j=0; j<str->Length; j++)
                         if (str[j]==bad[i])
                             {
                             abort = true;   i = bad->Length; break;
                             }
                 if (abort)
                     {
                     MessageBox::Show(bad + " These characters are forbidden in the Subject");
                     return;
                     }

                 fname += Path::GetTempPath();
                 fname += SubjectBox->Text;
                 fname += ".txt";
                 StreamWriter ^sw = gcnew StreamWriter(fname);
                 sw->Write(TransferData->Text);
                 sw->Close();
                 }
             else
                 {
                 MessageBox::Show("No subject has been provided.");
                 return;
                 }

             // Create  the file attachment for this e-mail message.
             Mail::Attachment^ data = gcnew Mail::Attachment(fname, Mime::MediaTypeNames::Application::Octet);

             // Add the file attachment to this e-mail message.
             message->Attachments->Add( data );

             //Send the message.
             Mail::SmtpClient^ client = gcnew Mail::SmtpClient( server );
             client->Credentials = myCred;

             try
                 {
                 client->Send( message );
                 MessageBox::Show(" DATA has been EMAILED to the Kindle.");
                 }
             catch (...)
                {
                MessageBox::Show(" Failed.");
                }

             data->~Attachment();
             client->~SmtpClient();
             }
// ===========



"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