Welcome to the CSIG, a Special Interest Group of the ACGNJ. We will be discussing Windows Programming using Visual C++ from Microsoft.
For this month we will be continuing the discussion about the email program started last month. Emphasis will be on programming challenges as well as additional features. Here's the introduction from last month.
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
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: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
===========
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();
}
// ===========