www.it-ebooks.info www.it-ebooks.info ffirs.indd ii 17/09/12 6:32 PM IVOR HORTON’S BEGINNING VISUAL C ++® 2012 INTRODUCTION xxxv CHAPTER Programming with Visual C++ CHAPTER Data, Variables, and Calculations 25 CHAPTER Decisions and Loops 97 CHAPTER Arrays, Strings, and Pointers 135 CHAPTER Introducing Structure into Your Programs 189 CHAPTER More about Program Structure 231 CHAPTER Defining Your Own Data Types 277 CHAPTER More on Classes 333 CHAPTER Class Inheritance and Virtual Functions 441 CHAPTER 10 The Standard Template Library 491 CHAPTER 11 Windows Programming Concepts 601 CHAPTER 12 Windows Programming with the Microsoft Foundation Classes (MFC) 635 CHAPTER 13 Working with Menus and Toolbars 659 CHAPTER 14 Drawing in a Window 685 CHAPTER 15 Improving the View 739 CHAPTER 16 Working with Dialogs and Controls 769 CHAPTER 17 Storing and Printing Documents 815 CHAPTER 18 Programming Windows Apps 849 INDEX 905 www.it-ebooks.info ffirs.indd i 17/09/12 6:32 PM www.it-ebooks.info ffirs.indd ii 17/09/12 6:32 PM IVOR HORTON’S BEGINNING ® Visual C ++ 2012 www.it-ebooks.info ffirs.indd iii 17/09/12 6:32 PM www.it-ebooks.info ffirs.indd iv 17/09/12 6:32 PM IVOR HORTON’S BEGINNING ® Visual C++ 2012 Ivor Horton John Wiley & Sons, Inc www.it-ebooks.info ffirs.indd v 17/09/12 6:32 PM Ivor Horton’s Beginning Visual C++® 2012 Published by John Wiley & Sons, Inc 10475 Crosspoint Boulevard Indianapolis, IN 46256 www.wiley.com Copyright © 2012 by Ivor Horton Published by John Wiley & Sons, Inc., Indianapolis, Indiana Published simultaneously in Canada ISBN: 978-1-118-36808-4 ISBN: 978-1-118-43941-8 (ebk) ISBN: 978-1-118-41703-4 (ebk) ISBN: 978-1-118-43431-4 (ebk) Manufactured in the United States of America 10 No part of this publication may be reproduced, stored in a retrieval system or transmitted in any form or by any means, electronic, mechanical, photocopying, recording, scanning or otherwise, except as permitted under Sections 107 or 108 of the 1976 United States Copyright Act, without either the prior written permission of the Publisher, or authorization through payment of the appropriate per-copy fee to the Copyright Clearance Center, 222 Rosewood Drive, Danvers, MA 01923, (978) 750-8400, fax (978) 646-8600 Requests to the Publisher for permission should be addressed to the Permissions Department, John Wiley & Sons, Inc., 111 River Street, Hoboken, NJ 07030, (201) 748-6011, fax (201) 748-6008, or online at http://www.wiley.com/go/permissions Limit of Liability/Disclaimer of Warranty: The publisher and the author make no representations or warranties with respect to the accuracy or completeness of the contents of this work and specifically disclaim all warranties, including without limitation warranties of fitness for a particular purpose No warranty may be created or extended by sales or promotional materials The advice and strategies contained herein may not be suitable for every situation This work is sold with the understanding that the publisher is not engaged in rendering legal, accounting, or other professional services If professional assistance is required, the services of a competent professional person should be sought Neither the publisher nor the author shall be liable for damages arising herefrom The fact that an organization or Web site is referred to in this work as a citation and/or a potential source of further information does not mean that the author or the publisher endorses the information the organization or Web site may provide or recommendations it may make Further, readers should be aware that Internet Web sites listed in this work may have changed or disappeared between when this work was written and when it is read For general information on our other products and services please contact our Customer Care Department within the United States at (877) 762-2974, outside the United States at (317) 572-3993 or fax (317) 572-4002 Wiley publishes in a variety of print and electronic formats and by print-on-demand Some material included with standard print versions of this book may not be included in e-books or in print-on-demand If this book refers to media such as a CD or DVD that is not included in the version you purchased, you may download this material at http://booksupport.wiley.com For more information about Wiley products, visit www.wiley.com Library of Congress Control Number: 2012946046 Trademarks: Wiley, the Wiley logo, Wrox, the Wrox logo, Wrox Programmer to Programmer, and related trade dress are trademarks or registered trademarks of John Wiley & Sons, Inc and/or its affi liates, in the United States and other countries, and may not be used without written permission Visual C++ is a registered trademark of Microsoft Corporation All other trademarks are the property of their respective owners John Wiley & Sons, Inc., is not associated with any product or vendor mentioned in this book www.it-ebooks.info ffirs.indd vi 17/09/12 6:32 PM This book is for my dear wife, Eve, who for so many years has given me unconditional support and love in whatever I choose to I could not have written this without her www.it-ebooks.info ffirs.indd vii 17/09/12 6:32 PM www.it-ebooks.info ffirs.indd viii 17/09/12 6:32 PM randomValues( ) function template, lambda expressions and – Resource View tab randomValues() function template, lambda expressions and, 598 range-based for loops, 129 iterating characters in strings with, 424 references, using in, 181–182 Raster OPeration (ROP) drawing mode and, 731 trails and, 814 raw pointers, 504 ReadMe.txt fi le, 12 recording document changes, 829–831 RECT objects, 289 RECT structure, 289 rectangles CRectangle constructor, 788 drawing, 707–708, 725, 739 enclosing, creating, 722–725 enclosing, for lines, 723 normalized, 723 Recursion in Lambda Expressions (example), 600–602 recursive functions analyzing arithmetic expressions and, 267 basics of, 228–231 redrawing windows, 616 ref class class types variables (C++/CX), 861 defi ned, 857 object members, accessing, 861 ref class keyword, 858 ref struct types, 857 reference cycles, 502 reference documentation for WinRT namespaces, 856 reference types, function overload selection and, 254 references as arguments to functions, 210–212 basics of, 180 to class objects, 329, 332–334 defi ned, 212 lvalue, declaring and initializing, 180–181 vs pointers, 212 return types, 223–226 rvalue, 182 using in rage-based for loops, 181–182 using with virtual functions, 476–477 referencing members of structs (example), 284–287 regions, clip rectangles and, 852 RegisterClassEx() API function, 617, 618 registering windows classes, 617 registry key (MFC), 658 reinterpret_cast(), 66–69 relational operators, 97 ReleaseCapture() function, 739 releasing programs, 15 Release versions, 31 remainders, calculating, 61 remove() function (lists), 542 remove_if() function (lists), 544 removing toolbar buttons, replace() algorithm, 588–589 replace() function replacing parts of strings with, 427–428 using with pointers, 589 reserve() function, vector containers and, 509, 515 resize() function numbers of elements in lists and, 537 vector containers and, 512 resizing windows, 607, 636 Resource Editor creating MFC applications and, 644 pane, 672, 779, 781–782, 793 resource files basics of, 608 menus and, 671 resource string tables, creating status bar panes and, 804–805 Resource View tab MFC, 651 Windows programming, 13 932 www.it-ebooks.info bindex.indd 932 17/09/12 10:44 AM resources – sequence containers resources console programs and, 13 creating and modifying, 644 defi ned, 671 dialog resources, creating, 776–779 edit box resources, creating, 809–810 menu resources, creating and editing, 671–674 for XAML templates, 883 rethrowing exceptions, 248 return statements, functions and, 197–198 return types of functions, 196 return values of functions, 196 returning references from functions, 223–226 reverse iterators, 511 ribbons (windows), 608 RichTextBlock element, 875–876, 898, 899–900 rollLength const variable, 58 RotateTransform element, 904 rubber-banding, 706 Run() function (MFC), 659 rvalue references basics of, 180, 182 function overload selection and, 254 lvalue references and, 216 passing values to functions and, 212 reference parameters, 214–216, 371, 374–376 rvalues basics of, 76–77 named objects as, 376–379 S scaling document size, setting, 799 mapping modes, setting, 799–801 scalable mapping modes, 797–799 scale menu items, adding, 791 scrolling with, 801–803 UI elements, 901–903 SCARY iterators, 501 schema numbers, 827 scope basics of, 77–78 declared within functions, 197 scope resolution operator (::), 33, 82, 197 screen coordinates, 797 scrolling with scaling, 801–803 scrollbars, 802–803 scrolling views client coordinates, 751–753 coordinate systems, 750–751 getting started, 748–749 sdf extension, 12 SDI (Single Document Interface), 640 See also MFC Application Wizard output SDI applications command message processing and, 670 creating, 645–649 See also MFC Application Wizard output searching algorithms and, 589 for library files, 33 for message handlers, 667 namespaces, 84 null-terminated strings, 187–189 strings, 432–436, 440 SelectObject() function using brushes and, 705 using pens and, 703 semicolons (;) assignment statements and, 55 declarations and, 41, 153 else keywords and, 104 function prototypes and, 199 if statements and, 99 for loops and, 119 macros and, 827 sequence containers See also vector containers array containers, 530–533 basics of, 506–508 double-ended queue containers, 533–536 933 www.it-ebooks.info bindex.indd 933 17/09/12 10:44 AM sequence containers (continued) – sln extension sequence containers (continued) forward_list container templates, 548–550 list containers See list containers priority queue containers basics, 553–554 Priority Queue Containers, Using (example), 554–559 queue containers, 550–553 stack containers, 559–561 serialization basics of, 720, 821–822, 827–828 basics of applying, 829 document changes, recording, 829–831 in document class defi nition, 822–823 in document class implementation, 823–826 documents, serializing, 831–833 element classes, serializing, 833–837 exercising, 837–839 functionality of CObject-based classes, 826–827 implementing for classes, 829 Serialize() Function, 824 set container, 565 SetCheck() function, 683–684 SetModifiedFlag() function, 829–830 SetRegistryKey() function (MFC), 658 sets (containers), 506 SetScrollSizes() function, 748–749, 753 setValues() function template, lambda expressions and, 597–598 SetViewportOrg() member, 695 shape events, handling, 896–898 Shape_Tapped() handler (MemoryTest project), 881, 882 shared_ptr objects, 503–504 shared_ptr type, 501–502 shift operators (bitwise), 74–76 short keyword, 43 shortcut menus See context menus shortcuts for creating game cards, 882 menus and, 670, 672, 674, 755 for viewing h files, 668 Show_How_Tapped() handler (MemoryTest project), 899, 900 showit() function, 242–243 ShowVolume() function, 483 signatures, overloaded functions and, 252 signed keyword, 45 Simulator Debugger, 882–883 Single Document Interface (SDI) See SDI (Single Document Interface) size document size, setting, 799 of documents and printing, 842, 843, 844 of Grid element, 901 paper size, printing and, 843 width and length when printing, 845–847, 849–850 of windows, 607, 618, 636 size() function, containers and, 550, 554, 559, 571 size_t type, 163, 183 sizeof operator operator overloading and, 350 pointers and, 163–165 in Your First Use of Classes (example), 298 Sketcher program adding menus, 670–671 classes, 666–667 controls and See controls creating, 659–661 dialogs and See dialogs drawing and See drawing in windows printing and See printing serialization and See serialization views and See views, improving sketches, drawing, 737–740 slashes (//) comments and, 31 start and end tags and, 864 sln extension, solutions and, 10 934 www.it-ebooks.info bindex.indd 934 17/09/12 10:44 AM smart pointers – static_pointer_cast smart pointers basics of, 176, 501–504 casting, 504 memory leaks and, 223 raw pointers, 504 shared_ptr object, 503–504 unique_ptr object, 502–503 using, 504 SolidColorBrush objects, 861 Solution Explorer pane, new Windows apps and, 855, 871–872 tab (MFC), 651 tab (Windows programming), 12 window, solutions, building (example), 14 sort() algorithm, 505 sort() function, comparing strings and, 430, 431 sort() function template arrays and, 525 vectors and, 525–526 sorting list elements, 539 Sorting Words from Text (example), 436–441 source code, modifying (example), 13–14 spaces, eliminating from strings, 264 spin button controls basics of, 777, 791 CScaleDialog class and, 793–796 scale menu items, adding and, 791 spin buttons, creating, 792–793 spin buttons, displaying, 796–797 toolbar buttons, adding, 791 splice() function (lists), 543 square brackets ( [ ] ) deleting arrays and, 176, 179 function pointer array elements and, 241 as subscript operator, 424 squares, creating, 879–880 stack containers, 559–561 stacks, 78 Standard C++ Library, Standard Template Library algorithms, 504–505, 588–591 associative containers See associative containers basics of, 495–496 components, listed, 496 containers See containers; sequence containers function adapters, 506 function objects in, 505–506, 586–588 iterators See iterators lambda expressions See lambda expressions smart pointers, 501–504 static assertions, 591–592 storing tuples in arrays (example), 563–565 tuple class templates basic, 561–562 type traits, 591–592 Start button (MemoryTest project), 899 start tags (XAML), 863 startup transitions (applications), 903 stateless lambdas, 593, 599 statements assignment statements basics, 35 output statements, 35–36 program statements, 34–36 repeating blocks of See loops statement blocks, 37 static assertions, STL and, 591–592 static members of classes static data members, 326, 329 static function members, 329 static resolution, 470 static storage duration, 81, 84 static variables basics of, 84, 226 in functions, 226–228 static_cast keyword, 68 static_cast operator, 202 static_cast(), 68 static_pointer_cast, 504 935 www.it-ebooks.info bindex.indd 935 17/09/12 10:44 AM status bars, adding to frames – structure, of Windows programs status bars, adding to frames basics of, 803–804 status bar frames, creating, 804–806 status bars, updating, 806–807 std, namespaces and, 90 stdafx.h fi les compilation of fi les and, 16 header fi les, in console programs, 38, 39 modifying source code and, 13–14 std::begin() and std::end() functions, 501 stdcall, 613 std::cout, 14, 90 std::endl, 18 std::forward() function, 393 std::move() function, 381 std::move() library function, 216 std::shared_ptr smart pointer, 718 std::string, 448 storage duration automatic, 78 static, 81, 84 storing class objects in vectors, 520–526 integer values, 45 Multiple Strings, Storing (example), 152–154 objects, map containers and, 566–568 Person objects in vectors, 524, 525 pointers in vectors, 527–529 print data, 844–845 std::string for, 448 tuples in arrays (example), 563–565 storyboard animations transitions, 904–906 strcat() functions, 183–185 strcmp() function, 186–187 strcpy() function, 185–186 strcpy_s() function , 185–186, 449 stream iterators, 579 streams, 35 string class basics of, 183 Perfect Forwarding example and, 393–396 string objects, 394 strings See also library functions for strings; null-terminated strings character arrays and, 147–150 constructors and, 341 eliminating blanks from, 264 eliminating spaces from, 264 length of, 261 pointer notation and, 171–172 std::string for storing, 448 Storing Multiple Strings (example), 152–154 strings, library classes for, 418–441 accessing and modifying, 424–428 comparing, 428–432 concatenating, 420–423 searching, 432–436 Sorting Words from Text (example), 436–441 string objects, creating, 418–420 strings of characters, 44 strlen() function destructors and, 341, 342 string length and, 183 Stroustrup, Bjarne, 147, 293 strspn() function, 187–188 struct keyword, 282, 292 structs basics of, 282 vs classes, 295 classes and, 292 defi ning, 282–283 initializing, 283 IntelliSense and, 287–288 members, accessing, 283 RECT structure, 289 referencing members (example), 284–287 using pointers with, 289–291 structure, of Windows programs See also WinMain() function vs typical console programs, 936 www.it-ebooks.info bindex.indd 936 17/09/12 10:44 AM structure of C++ programs – TrackPopupMenu( ) function structure of C++ programs See C++ program structure structures See also structs vs classes, 292 defi ned, 282 unions in, 349 style members of struct, 615–617 subscript operator ([ ]), 423 substr() function, extracting characters from text and, 440 substrings, extracting, 275–277 subtraction operator (CBox class), 400 sumarray() function, 241 suo extension, solutions and, 10 swap() function strings and, 431 vectors and, 519–520 swap() member function, interchanging strings and, 427 switch statements for comparing numeric values, 111–114 decoding Windows messages and, 626–627 synonyms, defi ning for data types, 49–50 system menus (windows), 607–608 T tab sequence (controls), 792–793 tag names, 347 tags (XAML), 863 template keyword, 255, 384 templates See also class templates document templates (MFC), 641–643 function object templates, 587, 588 for function objects, 392 function templates, 198, 255–258 inserter templates, iterators and, 579 instances of, 382 instantiation and, 385 lambda expressions and, 595 for operator functions, 355 type testing templates, 592 term() function, 263, 266, 267–268 terminology, classes, 294 terms defi ned, 263 value of, 267 ternary operators, for comparing numeric values, 109–110 text Text, Sorting Words from (example), 436–441 text elements, creating, 813–815 text elements, defi ning, 812 Text menu item, adding, 811–812 TextEditor project folder (MFC), 649–650 this pointer, 318–321 throw keyword, 244, 245, 249 throw statements, 245–246 throwing exceptions, 244–246 time, constant and linear, 517 titles creating (MemoryTest project), 874–876 title bar icons (windows), 607 title bars (windows), 607 _tmain() function, 14, 18 toolbar (windows), 608 toolbar buttons adding, 8, 684–687, 791 defi ned, 685 removing, tooltips, adding, 688 toolbars dockable (IDE), 9–10 options (IDE), 8–9 options (MFC applications), 648 Toolbox pane, 865–866, 867, 869 tooltips adding, 688 basics of, top() function, containers and, 559 TrackPopupMenu() function, 756–757 937 www.it-ebooks.info bindex.indd 937 17/09/12 10:44 AM trailing return types – variables trailing return types, 198, 259, 260 trails moving geometric elements and, 816 moving text elements and, 816–817 transform() algorithm, 590 transform()function, 592 transitions, 903–906 tree controls, 777 triangles, design of game cards and, 880 trivial properties, 858 TRUE value, numeric type variables and, 46 truth tables, 71 try blocks exceptions and, 245–246 memory allocation and, 250 nested, 247–248 try keyword, 244, 249 tuple class templates basics of, 561–562 tuples, storing in arrays (example), 563–565 type arguments, using containers and, 496, 557–558, 559 type conversion, 59, 66–69 type modifiers, 58 type of variables, 35 type parameters, function templates and, 255 type testing templates, 592 type traits, STL and, 591–592 typedef keyword, synonyms for data types and, 49–50 typedef statements, tuples and, 562, 564–565 typeid operator, 70 typename keyword, 256 type-safe enumerations, 87–88 U unary minuses, 56 unary predicates, 506 underscore (_), variable names and, 39 Unicode libraries, 16 union keyword, 347 unions anonymous, 348–349 in classes and structures, 349 defi ned, 347 defi ning, 347–348 unique() function (lists), 542–543 unique_ptr objects, 502–503 unique_ptr type, 501 unsigned keyword, 46 update region, 691 UPDATE_COMMAND_UI, 682 UpdateAllViews() function, 746–747, 767–768, 770 UpdateWindow() function, 619 user interfaces (UIs) defining (MemoryTest project), 872–874 for drawing sketches, 739 event handling for UI elements (XAML), 870–871 GUI, vs operation (Windows apps), 855 options (MFC applications), 647 UI elements in XAML, 865–868 Windows programs, 606–608 using declarations, namespaces and, 33–34, 90–91 using directives, defi ned, 90 Using Manipulators (example), 52–53 V va_arg macro, 218 validation dialog data validation, 795 of pointer values, 657 value types (WinRT), 857 variables automatic, 78–80 in body of functions, 197 data types and, 42 declaring, 41 defi ned, 35, 39, 70 defi ning, 39–40 938 www.it-ebooks.info bindex.indd 938 17/09/12 10:44 AM vector containersr – weak_ptr type dynamic memory allocation and, 174 globals, 30, 80–84 increment operators and, 63 initial values for, 41–42 integer, 42–44 modifying in arithmetic operations, 61–62 naming, 39–40 of ref class types (C++/CX), 861 scope and, 77–78 sharing memory between, 346–349 specific, capturing (lambda expressions), 594–595 static variables basics, 84 static variables in functions, 226–228 storage duration and, 77–78 variable declarations, 35, 41, 80 variable defi nition, 41 vector containers accessing elements in, 516–517 capacity vs size of, 511–516 creating, 508–511 vs double-ended queue containers, 534 inserting and deleting elements in, 517–520 sorting elements of, 526–527 storing class objects in, 520–526 storing pointers in, 527–529 vector template, 506–508 vector container, 728 VerticalAlignment property (MemoryTest project), 877, 880 view class menus, associating with, 756–757 MFC, 656–657 views basics of, 640–641 linking to documents, 641–643 views, improving context menus and See context menus elements, moving and deleting, 754 elements in, creating, 789–790 masked elements, 771–772 MM_LOENGLISH mapping mode, 753 mouse cursor and See elements under cursors, identifying scrolling views See scrolling views updating, 746–748, 767 virtual destructors, 483–486 virtual Draw() function, 719 virtual functions abstract classes and, 478–481 adding to classes, 300 basics of, 468–470 correct operation of, 473 defi ned, 471–473 function overriding, preventing, 473–474 indirect base classes and, 481–483 pointers to class objects, 474–476 pure, 477–478 references, using with, 476–477 Using an Inherited Function (example), 470–471 virtual destructors, 483–486 virtual keyword, 471, 472, 485 Visibility property, 871, 888–889, 896 Volume() function CBox class defi nition and, 299–300, 313 CCan class and, 480 CCandyBox class, 451–454 CContainer class, 477–478 function overriding and, 474–475 inherited functions and, 470–471 member function const and, 322–323 operator overloading and, 354–355 protected class members and, 458–460 virtual functions and, 471–473, 477–478 W wchar_t variables, 44 wcslen() function, 183 weak_ptr type, 502 939 www.it-ebooks.info bindex.indd 939 17/09/12 10:44 AM Web sites for further information – Windows programming Web sites for further information Bjarne Stroustrup, 147 constant values for style, 615 constants specifying windows displays, 614 MSDN library, 614, 615 reference documentation, 856 while loops arrays, using and, 143 basics of, 126–128 comparing strings and, 430–431 whitespace, 37 wide character types, 44 width of documents when printing, 845–847, 849–850 of lines, 702 m_PenWidth, 783–785 OnPenWidth() handler, 786 pen widths, 777–778, 781, 786–789 Win32 basics of, 2, 606 See also Windows programming Project for Win32 Console Application, Creating (example), 11–13 Win32 Application Wizard, 11, 13 window class, Windows programming and, 633–634 WindowProc() function basics of, 609, 612, 626 complete, 629–630 messages and, 620, 625–626 vs WinMain() function, 612 Windows apps basics of, 854 C++/CX See C++/CX developing, 855 environment for use of, 854 operation of vs UI of, 855 vs Windows desktop apps, 854 WinRT, 854, 856–857 Windows apps, programming (example) application files, 871–872 application startup transitions, 903 card back events, handling, 894–896 Card class, defi ning, 884–885 card pack, initializing, 888 cards, shuffling, 893 child elements of cardGrid, 888–890 game, initializing, 890–892 game cards See game cards game control button events, handling, 899–901 game controls, adding, 876–878 game operations, implementing, 883–887 MainPage object, initializing, 887–888 MemoryTest project introduced, 871 shape events, handling, 896–898 storyboard animations, 904–906 title, creating, 874–876 UI, defi ning, 872–874 UI cards, highlighting, 893–894 UI elements, scaling, 901–903 wins, recognizing, 898–899 XAML and See XAML (Windows apps and) Windows API basics of, 606, 609–610 vs MFC, 2, 606 Windows messages application, closing, 629 basics of, 609, 625–626, 665 decoding, 626–629 message categories (MFC), 668–669 message maps (MFC), 666–667 message pumps or loops, 620 message type, 675 in programs (MFC), 667–668 WindowProc() function See WindowProc() function Windows programming, 605–636 See also Win32 applications, creating and executing, 20–23 data types, 610–611 event-driven programs, 609 940 www.it-ebooks.info bindex.indd 940 17/09/12 10:44 AM Windows programs – Words, Sorting from Text (example) messages See Windows messages MFC See MFC (Microsoft Foundation Classes) vs MFC, 2, 606 notation in, 611–612 operating system and, 608–609 Simple Windows API Program (example), 630–631 structure of, 612–613 See also WinMain() function user interface elements, 606–608 vs WindowProc() function, 609, 612, 626–630 Windows API, 606, 609–610 windows defined, 608 Windows programs basics of, 4–5, 608–609 vs console programs, Windows::Foundation::Collections namespace, 857, 858 Windows::UI::Xaml::Controls namespace, 869 WinMain() function basics of, 612–614 completed, 624–625 vs main() function, 613 program windows, creating, 617–619 program windows, initializing, 619 program windows, specifying, 615–617 vs WindowProc() function, 612 windows messages, 620–623 WinRT (Windows Runtime) basics of, 854, 856–857 class types, defi ning, 858–860 namespaces, 856 objects, 856–857 wizards Add Member Variable Wizard, 407, 793–794, 810, 811 Application Wizard, 26–28, 822, 824, 839, 845 Class Wizard, 779–780, 812 Event Handler Wizard, 675–678 MFC Application Wizard, 20–23, 659–661 See also MFC Application Wizard output MFC Class Wizard, 806–807 Win32 Application Wizard, 11 WM_ prefi x, for message IDs, 621, 668 WM_LBUTTONDOWN message handler basics of, 709, 710–711 coordinates and, 750 implementing, 711 modifying, 737 revised version, 751 WM_LBUTTONDOWN messages basics of, 709, 710 capturing mouse images and, 739 drawing and, 712, 728 dropping elements and, 770 WM_LBUTTONUP message handler basics of, 710 capturing mouse images and, 739–740 implementing, 737 WM_LBUTTONUP messages basics of, 709, 710, 711 dealing with, 736–737 WM_MOUSEMOVE message handler basics of, 621, 710, 731–732 completing, 714, 730–731 CreateElement() function, 735–736 drawing mode, setting, 731–733 moving elements and, 766–767 outlining code for, 714 WM_MOUSEMOVE messages basics of, 709, 710, 711 capturing mouse messages and, 739 drawing curves and, 728 WM_PAINT messages, 627 WM_QUIT messages, 629 wmain() function, 18, 39 WNDCLASSEX struct type, 615 WndProc() function See WindowProc() function Words, Sorting from Text (example), 436–441 941 www.it-ebooks.info bindex.indd 941 17/09/12 10:44 AM wrappers, for function objects – zeros wrappers, for function objects, 599–600 WRL (WinRT C++ Template Library), 854 wstring class basics of, 183 character strings and, 418 layout elements, 869–870 parent and child elements, 869 UI elements in, 865–868 XAML basics, 863 XML (eXtensible Markup Language), 863 X Z XAML (Windows apps and) attached properties, 868 control elements, 869 elements, 863–865 event handling, 870–871 zeros bitwise AND operator and, 72 decimal integer values and, 46 942 www.it-ebooks.info bindex.indd 942 17/09/12 10:44 AM www.it-ebooks.info badvert.indd 943 17/09/12 6:57 PM Try Safari Books Online FREE for 15 days + 15% off for up to 12 Months* Read this book for free online—along with thousands of others— with this 15-day trial offer With Safari Books Online, you can experience searchable, unlimited access to thousands of technology, digital media and professional development books and videos from dozens of leading publishers With one low monthly or yearly subscription price, you get: • Access to hundreds of expert-led instructional videos on today’s hottest topics • Sample code to help accelerate a wide variety of software projects • Robust organizing features including favorites, highlights, tags, notes, mash-ups and more • Mobile access using any device with a browser • Rough Cuts pre-published manuscripts START YOUR FREE TRIAL TODAY! Visit www.safaribooksonline.com/wrox60 to get started *Available to new subscribers only Discount applies to the Safari Library and is valid for first 12 consecutive monthly billing cycles Safari Library is not available in all countries www.it-ebooks.info badvert.indd 944 17/09/12 6:57 PM Related Wrox Books Beginning ASP.NET 4.5 ISBN: 978-1-118-31180-6 Featuring a user-friendly, step-by-step format, the book guides you through customizing the IDE, building a Planet Wrox website example, working with files and web forms, designing web pages, displaying and updating data, creating tables, and much more With this resource in hand, you will be completely at ease learning ASP.NET 4.5 Beginning Visual C# 2012 ISBN 978-1-118-31441-8 Using this book, you will first cover the fundamentals such as variables, flow control, and object-oriented programming and gradually build your skills for web and Windows programming, Windows forms, and data access Step-by-step directions walk you through processes and invite you to “Try it Out,” at every stage By the end, you’ll be able to write useful programming code following the steps you’ve learned in this thorough, practical book If you’ve always wanted to master Visual C# programming, this book is the perfect one-stop resource Professional C++, 2nd Edition ISBN: 978-0-470-93244-5 With this no-nonsense book, you will learn to conquer the latest version of the C++ language: C++11 The authors share real-world examples, decipher little-known features of C++, and reveal the significant changes to C++ that accompany the latest release Ultimately, you’ll discover programming methodologies, reusable design patterns, and good programming style that will increase the quality of your code and improve your programming efficiency Professional C# 2012 and NET 4.5 ISBN 978-1-118-31442-5 After a quick refresher on C# basics, the author dream team moves on to provide you with details of language and framework features including LINQ, LINQ to SQL, LINQ to XML, WCF, WPF, Workflow, and Generics Coverage also spans ASP.NET programming with C#, working in Visual Studio 2012 with C#, and more Professional Visual Basic 2012 and NET 4.5 ISBN: 978-1-118-31445-6 Written by an author team of veteran programmers and developers, this book gets you quickly up to speed on what you can expect from Visual Studio 2012 Packed with helpful examples, this comprehensive guide examines the features of Visual Studio 2012, and walks you through every facet of the Integrated Development Environment (IDE), from common tasks and functions to its powerful tools Professional Visual Studio 2012 ISBN: 978-1-118-33770-7 This book is what you need to get up and running quickly on Visual Studio 2012 Written by a Microsoft Visual C# MVP, it guides you through the integrated development environment (IDE), showing you how to maximize each of the tools and features Visual Basic 2012 Programmer’s Reference ISBN: 978-1-118-31407-4 Visual Basic 2012 is packed with powerful features and this book will help you master them all You’ll gain a solid understanding of essential Visual Basic topics and begin applying the information to perform a host of important development tasks The tutorials inside are filled with code examples and the best methods for using them to write your own programs www.it-ebooks.info Related Wrox Books Beginning ASP.NET 4.5 ISBN: 978-1-118-31180-6 Featuring a user-friendly, step-by-step format, the book guides you through customizing the IDE, building a Planet Wrox website example, working with files and web forms, designing web pages, displaying and updating data, creating tables, and much more With this resource in hand, you will be completely at ease learning ASP.NET 4.5 Beginning Visual C# 2012 ISBN 978-1-118-31441-8 Using this book, you will first cover the fundamentals such as variables, flow control, and object-oriented programming and gradually build your skills for web and Windows programming, Windows forms, and data access Step-by-step directions walk you through processes and invite you to “Try it Out,” at every stage By the end, you’ll be able to write useful programming code following the steps you’ve learned in this thorough, practical book If you’ve always wanted to master Visual C# programming, this book is the perfect one-stop resource Professional C++, 2nd Edition ISBN: 978-0-470-93244-5 With this no-nonsense book, you will learn to conquer the latest version of the C++ language: C++11 The authors share real-world examples, decipher little-known features of C++, and reveal the significant changes to C++ that accompany the latest release Ultimately, you’ll discover programming methodologies, reusable design patterns, and good programming style that will increase the quality of your code and improve your programming efficiency Professional C# 2012 and NET 4.5 ISBN 978-1-118-31442-5 After a quick refresher on C# basics, the author dream team moves on to provide you with details of language and framework features including LINQ, LINQ to SQL, LINQ to XML, WCF, WPF, Workflow, and Generics Coverage also spans ASP.NET programming with C#, working in Visual Studio 2012 with C#, and more Professional Visual Basic 2012 and NET 4.5 ISBN: 978-1-118-31445-6 Written by an author team of veteran programmers and developers, this book gets you quickly up to speed on what you can expect from Visual Studio 2012 Packed with helpful examples, this comprehensive guide examines the features of Visual Studio 2012, and walks you through every facet of the Integrated Development Environment (IDE), from common tasks and functions to its powerful tools Professional Visual Studio 2012 ISBN: 978-1-118-33770-7 This book is what you need to get up and running quickly on Visual Studio 2012 Written by a Microsoft Visual C# MVP, it guides you through the integrated development environment (IDE), showing you how to maximize each of the tools and features Visual Basic 2012 Programmer’s Reference ISBN: 978-1-118-31407-4 Visual Basic 2012 is packed with powerful features and this book will help you master them all You’ll gain a solid understanding of essential Visual Basic topics and begin applying the information to perform a host of important development tasks The tutorials inside are filled with code examples and the best methods for using them to write your own programs www.it-ebooks.info ... PM IVOR HORTON’S BEGINNING ® Visual C ++ 2012 www.it-ebooks.info ffirs.indd iii 17/09/12 6:32 PM www.it-ebooks.info ffirs.indd iv 17/09/12 6:32 PM IVOR HORTON’S BEGINNING ® Visual C++ 2012 Ivor. .. 17/09/12 6:32 PM Ivor Horton’s Beginning Visual C++ 2012 Published by John Wiley & Sons, Inc 10475 Crosspoint Boulevard Indianapolis, IN 46256 www.wiley.com Copyright © 2012 by Ivor Horton Published... ii 17/09/12 6:32 PM IVOR HORTON’S BEGINNING VISUAL C ++® 2012 INTRODUCTION xxxv CHAPTER Programming with Visual C++