DOCUMENT:Q315849 14-MAR-2002 [mspress] TITLE :Programming Microsoft Windows With C# Comments And Corrections PRODUCT :Microsoft Press PROD/VER:: OPER/SYS: KEYWORDS:kbinfo kbfix ====================================================================== ------------------------------------------------------------------------------- The information in this article applies to: - MSPRESS Programming Microsoft Windows With C# ISBN 0-7356-1370-2 ------------------------------------------------------------------------------- SUMMARY ======= This article contains comments, corrections, and information about known errors relating to the Microsoft Press book Programming Microsoft Windows With C#, ISBN 0-7356-1370-2. The following topics are covered: - CD-ROM: New ImageIO.cs And MetafileConvert.cs Files - Page 12: Typographical Error - Page 14: Correction To AddFive Routine - Page 298: OnPage Should Be DoPage - Page 416: Typographical Error - Page 515: Correction To Save Method - Pages 779 and 780: Correction To ImageIO.cs Code - Pages 1112 and 1113: Correction to MetafileConvert.cs Code MORE INFORMATION ================ CD-ROM: New ImageIO.cs And MetafileConvert.cs Files --------------------------------------------------- On the companion CD, files ImageIO.cs (\Code\Dialog Boxes\ImageIO) and MetafileConvert.cs (\Code\Metafiles\MetafileConvert) contain errors in their code. The files with the corrected code are available now for download. The following file is available for download from the Microsoft Download Center: Code.exe (http://download.microsoft.com/download/MSPressPub/Update/1.0/NT5XP/EN-US/code.exe) For additional information about how to download Microsoft Support files, click the article number below to view the article in the Microsoft Knowledge Base: Q119591 How to Obtain Microsoft Support Files from Online Services Microsoft used the most current virus detection software available on the date of posting to scan this file for viruses. Once posted, the file is housed on secure servers that prevent any unauthorized changes to the file. Page 12: Typographical Error ---------------------------- There is a typographical error on page 12 in the second-to-the-last paragraph. Change: "Date types don't need..." To: "Data types don't need..." Page 14: Correction To AddFive Routine -------------------------------------- On page 14, in the AddFive routine, Change: "i + 5;" To: "i += 5;" Page 298: OnPage Should Be DoPage --------------------------------- There are two typographical errors at the bottom of page 298. Change: "The OnPage method changes..." To: "The DoPage method changes..." Change: "OnPage then switches..." To: "DoPage then switches..." Page 416: Typographical Error ----------------------------- There is a typographical error in the middle of page 298. Change: "How the DrawString call interprets ampersands?" To: "How does the DrawString call interpret ampersands?" Page 515: Correction To Save Method ----------------------------------- On page 515, in first paragraph under "More on the Image Class", remove: "The first version of Save in the following list uses the filename extension to determine the file Format, but you can be more explicit in the next two versions: ... void Save(string strFilename)" Pages 779 and 780: Correction To ImageIO.cs Code ------------------------------------------------ On pages 779 and 780, replace the ImageIO.cs code with the following: //-------------------------------------- // ImageIO.cs © 2001 by Charles Petzold //-------------------------------------- using System; using System.Drawing; using System.Drawing.Imaging; using System.IO; using System.Windows.Forms; class ImageIO: ImageOpen { MenuItem miSaveAs; public new static void Main() { Application.Run(new ImageIO()); } public ImageIO() { Text = strProgName = "Image I/O"; Menu.MenuItems[0].Popup += new EventHandler(MenuFileOnPopup); miSaveAs = new MenuItem("Save &As..."); miSaveAs.Click += new EventHandler(MenuFileSaveAsOnClick); Menu.MenuItems[0].MenuItems.Add(miSaveAs); } void MenuFileOnPopup(object obj, EventArgs ea) { miSaveAs.Enabled = (image != null); } void MenuFileSaveAsOnClick(object obj, EventArgs ea) { SaveFileDialog savedlg = new SaveFileDialog(); savedlg.InitialDirectory = Path.GetDirectoryName(strFileName); savedlg.FileName = Path.GetFileNameWithoutExtension(strFileName); savedlg.AddExtension = true; savedlg.Filter = "Windows Bitmap (*.bmp)|*.bmp|" + "Graphics Interchange Format (*.gif)|*.gif|" + "JPEG File Interchange Format (*.jpg)|" + "*.jpg;*.jpeg;*.jfif|" + "Portable Network Graphics (*.png)|*.png|" + "Tagged Imaged File Format (*.tif)|*.tif;*.tiff"; ImageFormat[] aif = { ImageFormat.Bmp, ImageFormat.Gif, ImageFormat.Jpeg, ImageFormat.Png, ImageFormat.Tiff }; if (savedlg.ShowDialog() == DialogResult.OK) { try { image.Save(savedlg.FileName, aif[savedlg.FilterIndex - 1]); } catch (Exception exc) { MessageBox.Show(exc.Message, Text); return; } strFileName = savedlg.FileName; Text = strProgName + " - " + Path.GetFileName(strFileName); } } } Pages 1112 and 1113: Correction to MetafileConvert.cs Code ---------------------------------------------------------- On pages 1112 and 1113, replace the MetafileConvert.cs code with the following: //---------------------------------------------- // MetafileConvert.cs © 2001 by Charles Petzold //---------------------------------------------- using System; using System.Drawing; using System.Drawing.Imaging; using System.IO; // For Path class using System.Windows.Forms; class MetafileConvert: MetafileViewer { public new static void Main() { Application.Run(new MetafileConvert()); } public MetafileConvert() { Text = strProgName = "Metafile Convert"; } protected override void MenuFileSaveAsOnClick(object obj, EventArgs ea) { SaveFileDialog dlg = new SaveFileDialog(); if (strFileName != null && strFileName.Length > 0) dlg.InitialDirectory = Path.GetDirectoryName(strFileName); dlg.FileName = Path.GetFileNameWithoutExtension(strFileName); dlg.AddExtension = true; dlg.Filter = "Windows Bitmap (*.bmp)|*.bmp|" + "Graphics Interchange Format (*.gif)|*.gif|" + "JPEG File Interchange Format (*.jpg)|" + "*.jpg;*.jpeg;*.jfif|" + "Portable Network Graphics (*.png)|*.png|" + "Tagged Image File Format (*.tif)|*.tif;*.tiff"; ImageFormat[] aif = { ImageFormat.Bmp, ImageFormat.Gif, ImageFormat.Jpeg, ImageFormat.Png, ImageFormat.Tiff }; if (dlg.ShowDialog() == DialogResult.OK) { Bitmap bm = MetafileToBitmap(mf); try { bm.Save(dlg.FileName, aif[dlg.FilterIndex - 1]); // bm.Save(dlg.FileName); } catch (Exception exc) { MessageBox.Show(exc.Message, Text); } } } Bitmap MetafileToBitmap(Metafile mf) { Graphics grfx = CreateGraphics(); int cx = (int) (grfx.DpiX * mf.Width / mf.HorizontalResolution); int cy = (int) (grfx.DpiY * mf.Height / mf.VerticalResolution); Bitmap bm = new Bitmap(cx, cy, grfx); grfx.Dispose(); grfx = Graphics.FromImage(bm); grfx.DrawImage(mf, 0, 0, cx, cy); grfx.Dispose(); return bm; } } Microsoft Press is committed to providing informative and accurate books. All comments and corrections listed above are ready for inclusion in future printings of this book. If you have a later printing of this book, it may already contain most or all of the above corrections. Additional query words: DEVBOOK Petzold 0-7356-1370-2 ====================================================================== Keywords : kbinfo kbfix Technology : kbMSPressSearch Version : : Issue type : kbinfo ============================================================================= THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY. Copyright Microsoft Corporation 2002.