C++ Windows Programming - Stefan Bjornander - E-Book

C++ Windows Programming E-Book

Stefan Björnander

0,0
41,99 €

-100%
Sammeln Sie Punkte in unserem Gutscheinprogramm und kaufen Sie E-Books und Hörbücher mit bis zu 100% Rabatt.

Mehr erfahren.
Beschreibung

Develop real-world applications in Windows

About This Book

  • Create diverse applications featuring the versatility of Small Windows C++ library
  • Learn about object-oriented programming in Windows and how to develop a large object-oriented class library in C++
  • Understand how to tackle application-specific problems along with acquiring a deep understanding of the workings of Windows architecture

Who This Book Is For

This book is for application developers who want a head-first approach into Windows programming. It will teach you how to develop an object-oriented class library in C++ and enhanced applications in Windows. Basic knowledge of C++ and the object-oriented framework is assumed to get the most out of this book.

What You Will Learn

  • Develop advanced real-world applications in Windows
  • Design and implement a graphical object-oriented class library in C++
  • Get to grips with the workings of the integral aspects of the Win32 API, such as mouse input, drawing, cut-and-paste, file handling, and drop files
  • Identify general problems when developing graphical applications as well as specific problems regarding drawing, spreadsheet, and word processing applications
  • Implement classes, functions, and macros of the object-oriented class library developed in the book and how we implement its functionality by calling functions and macros in the Win32 API

In Detail

It is critical that modern developers have the right tools to build practical, user-friendly, and efficient applications in order to compete in today's market. Through hands-on guidance, this book illustrates and demonstrates C++ best practices and the Small Windows object-oriented class library to ease your development of interactive Windows applications.

Begin with a focus on high level application development using Small Windows. Learn how to build four real-world applications which focus on the general problems faced when developing graphical applications. Get essential troubleshooting guidance on drawing, spreadsheet, and word processing applications. Finally finish up with a deep dive into the workings of the Small Windows class library, which will give you all the insights you need to build your own object-oriented class library in C++.

Style and approach

This book takes a tutorial-style approach that will demonstrate the features of a C++ object-oriented library by developing interactive Windows applications.

Sie lesen das E-Book in den Legimi-Apps auf:

Android
iOS
von Legimi
zertifizierten E-Readern

Seitenzahl: 611

Veröffentlichungsjahr: 2016

Bewertungen
0,0
0
0
0
0
0
Mehr Informationen
Mehr Informationen
Legimi prüft nicht, ob Rezensionen von Nutzern stammen, die den betreffenden Titel tatsächlich gekauft oder gelesen/gehört haben. Wir entfernen aber gefälschte Rezensionen.



Table of Contents

C++ Windows Programming
Credits
About the Author
About the Reviewer
www.PacktPub.com
eBooks, discount offers, and more
Why subscribe?
Free access for Packt account holders
Dedication
Preface
What this book covers
What you need for this book
Who this book is for
Conventions
Reader feedback
Customer support
Downloading the example code
Downloading the color images of this book
Errata
Piracy
Questions
1. Introduction
The library
Summary
2. Hello, Small World!
Hello, Small Windows!
The circle application
The main window
The CircleDocument class
The Circle class
Summary
3. Building a Tetris Application
The MainWindow function
The Tetris window
Keyboard input
Drawing
Input focus
The timer
New figures
Game over
New game
Deleting and flashing rows
Closing the window
The TetrisFigure class
The red figure
The brown figure
The turquoise figure
The green figure
The yellow figure
The blue figure
The purple figure
The GameGrid class
Invalidating and drawing squares
Summary
4. Working with Shapes and Figures
The MainWindow function
The DrawDocument class
The application modes
The DynamicList class
Initialization
Mouse input
Painting
The File menu
Cut, copy, and paste
The Modify menu
The Add menu
The cursor
Summary
5. The Figure Hierarchy
The DrawFigure class
The LineFigure class
The ArrowFigure class
The RectangleFigure class
The EllipseFigure class
Summary
6. Building a Word Processor
Auxiliary classes
Character information
Line information
The Paragraph class
The MainWindow class
The WordDocument class
The caret
Mouse input
Touchscreen
Page setup and calculation
Painting and drawing
File management
Cut, copy, and paste
Delete
Page break
Font
Alignment
Summary
7. Keyboard Input and Character Calculation
Keyboard handling
Arrow keys
Home and End
Shift arrow keys
Shift Page Up and Page Down
Shift Home and End
Control Home and End
Shift Control Home and End
Neutral keys
Visible characters
Character calculation
Character size and ascent line
Line generation
Regular and justified rectangle list generation
Invalidate rectangle set generation
Summary
8. Building a Spreadsheet Application
The MainWindow class
The CalcDocument class
Mouse input
Scrolling and marking
Painting
Visibility
Marking and updating
Keyboard input
File management
Cut, copy, and paste
Font and color
Alignment
Source and target sets
Graph searching
Error handling
Summary
9. Formula Interpretation
Formula interpretation
The tokens
The tree node
The Scanner – Generating the list of tokens
The parser – Generating the syntax tree
Matrix and reference
The reference class
The Matrix class
The cell
Character input
Drawing
Caret rectangle list generation
Formula interpretation
File management
Further reading
Summary
10. The Framework
An overview of Small Windows
"Hello" window for the Win32 API
The MainWindow function
The WinMain function
The Application class
The Win32 API Windows classes
The message loop
The Window class
Initialization
Header and visibility
The touch screen
Invalidation and window updates
Preparing the device context
Unit transformation
Window size and position
Text metrics
Closing the window
The MessageBox method
The Graphics class
Summary
11. The Document
The Document class
Initialization
The Document header
The caret
The mouse wheel
The menu bar
The scroll bar
The DocumentProc method
The Menu class
The Accelerator class
The StandardDocument class
Initialization
Standard menus
File management
Cut, copy, and paste
Drop files
Page size
Page setup
Printing
Summary
12. The Auxiliary Classes
The Size class
The Point class
The Rect class
The Color class
The Font class
The Cursor class
The DynamicList class
The Tree class
The InfoList class
Strings
Summary
13. The Registry, Clipboard, Standard Dialogs, and Print Preview
The registry
The Clipboard class
ASCII and Unicode lines
Generic information
Standard dialogs
The Save dialog
The Open dialog
The Color dialog
The Font dialog
The Print dialog
Print preview
Keyboard input
Scroll bar
Summary
14. Dialogs, Controls, and Page Setup
Custom dialogs
Controls
The button controls
List controls
Combo box
Label
The TextField class
Converters
Signed integers
Unsigned integers
Double values
Strings
Rational numbers
Complex numbers
Page setup
Page setup information
The Page Setup dialog
The Template function
Summary
A. Rational and Complex Numbers
Rational numbers
Complex numbers
Summary

C++ Windows Programming

C++ Windows Programming

Copyright © 2016 Packt Publishing

All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.

Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author, nor Packt Publishing, and its dealers and distributors will be held liable for any damages caused or alleged to be caused directly or indirectly by this book.

Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.

First published: September 2016

Production reference: 1020916

Published by Packt Publishing Ltd.

Livery Place

35 Livery Street

Birmingham 

B3 2PB, UK.

ISBN 978-1-78646-422-4

www.packtpub.com

Credits

Author

Stefan Björnander

Copy Editor

Pranjali Chury

Reviewer

Lou Mauget

Project Coordinator

Suzanne Coutinho

Commissioning Editor

Kunal Parikh

Proofreader

Safis Editing

Acquisition Editor

Chaitanya Nair

Indexer

Rekha Nair

Content Development Editor

Zeeyan Pinheiro

Graphics

Jason Monteiro

Disha Haria

Technical Editor

Pratish Shetty

Production Coordinator

Melwyn Dsa

About the Author

Stefan Björnander holds a master's degree in computer science, and has worked with software development for many years. He has lectured on programming for the industry and universities. He has also authored Microsoft Visual C++ Windows Applications by Example for Packt Publishing, which gained great acclaim. 

About the Reviewer

Lou Mauget learned to program long ago at Michigan State University as a physics major, learning to use software to design a cyclotron. He worked at IBM for 34 years, and after that, he went on to work for several consulting firms, including a long-term engagement with the railroad industry. He is currently consulting for Keyhole Software of Leawood, Kansas. Recently, he designed and coded MockOla, a drag-drop wire-frame prototyping tool for Keyhole Software. Lou has coded in C++, Java, JavaScript, Python, and newer languages, as each was conceived. His current interests include reactive functional programming, containers, Node JS, NoSQL, geospatial systems, mobile, and any new language or framework. Occasionally, Lou blogs about software technology for Keyhole Software. He has coauthored three computer books and authored two IBM DeveloperWorks XML tutorials and a WebSphere Journal LDAP tutorial. Lou coauthored several J2EE certification tests for IBM. He has reviewed books for Packt Publishing, as well as other publications.

www.PacktPub.com

eBooks, discount offers, and more

Did you know that Packt offers eBook versions of every book published, with PDF and ePub files available? You can upgrade to the eBook version at www.PacktPub.com and as a print book customer, you are entitled to a discount on the eBook copy. Get in touch with us at [email protected] for more details.

At www.PacktPub.com, you can also read a collection of free technical articles, sign up for a range of free newsletters and receive exclusive discounts and offers on Packt books and eBooks.

https://www2.packtpub.com/books/subscription/packtlib

Do you need instant solutions to your IT questions? PacktLib is Packt's online digital book library. Here, you can search, access, and read Packt's entire library of books.

Why subscribe?

Fully searchable across every book published by PacktCopy and paste, print, and bookmark contentOn demand and accessible via a web browser

Free access for Packt account holders

Get notified! Find out when new books are published by following @PacktEnterprise on Twitter or the Packt Enterprise Facebook page.

Dedication

I dedicate this book to my parents Ralf and Gunilla, my sister Catharina, her husband Magnus, and their sons Emil and Rasmus.

Preface

Application development has gained massive popularity because of the immense impact it has on various sectors. In this booming market, it has become critical to have the right set of tools to enable developers to build practical, user-friendly, and efficient applications. This book is focused on the use and implementation of Small Windows, which is a C++ object-oriented class library that eases the development of interactive Windows applications.

What this book covers

Chapter 1, Introduction, gives an introduction to Small Windows, which is a class library that encapsulates a part of the Win32 API.

Chapter 2, Hello, Small World!, starts by building a (very) small application—the Small Windows version of the famous Hello World program. Then, we will continue with a (still rather small) application that handles circles in a window. The user can add and move circles, change their colors, and save and load circles.

Chapter 3, Building a Tetris Application, explores a version of the classic Tetris game. Seven different kinds of figure are falling down the screen and the user’s task is to move or rotate them so that as many rows as possible can be completely filled and removed.

Chapter 4, Working with Shapes and Figures, teaches you how to build a drawing program, which can be regarded as a more advanced version of the circle application. It is possible to create and remove figures as well as mark and drag figures.

Chapter 5, The Figure Hierarchy, continues to build the drawing program. We can define a class hierarchy with lines, arrows, rectangles, and ellipses.

Chapter 6, Building a Word Processor, describes a word processor capable of formatting individual characters.

Chapter 7, Keyboard Input and Character Calculation, discusses how the word processor handles many keyboard input combinations and calculates the size and position of each individual character.

Chapter 8, Building a Spreadsheet Application, talks about the final application, which is a spreadsheet program capable of calculating formulas with the four rules of arithmetic. It is also possible to cut and paste blocks of cells.

Chapter 9, Formula Interpretation, explains that when the user inputs a formula, we need to interpret it. The process is divided into scanning and parsing, which we will look into in this chapter.

Chapter 10, The Framework, describes the most central part of Small Windows. This chapter begins the description of Small Windows. The Application class handles the message loop of the application and the registration of Windows classes. The Window class handles basic window functionality.

Chapter 11, The Document, talks about the document-based Window subclasses, that is, the Document class that provides basic document functionality, such as menus and accelerators, and the Standard Document framework, which provides a document-based framework.

Chapter 12, The Auxiliary Classes, explores a set of small auxiliary classes handling points and sizes, rectangles, colors and fonts, dynamic lists, and tree structures.

Chapter 13, The Registry, Clipboard, Standard Dialogs, and Print Preview, explains the implementation of the registry and clipboard, the standard dialogs to save and load files, choosing color or font, or printing a document. The chapter also explains the implementation a class for print previewing.

Chapter 14, Dialogs, Controls, and Print Setup, describes the possibility to design custom dialogs with controls such as push buttons, check boxes, radio buttons, list boxes, combo boxes, and text field. The input of a text field can be converted to any type. Finally, the Print Setup dialog is a custom dialog annotated with suitable controls.

What you need for this book

First of all, you need to download Visual Studio on your computer. I suggest you download and install Express for Desktop, which is free, and is available at https://www.visualstudio.com/en-us/products/visual-studio-express-vs.aspx.

Then, there are two ways to install Small Windows:

If you want to follow the chapter structure of this book you can download it from https://github.com/PacktPublishing/Cpp-Windows-Programming. It is made up by a set of Visual Studio projects holding the applications of this book.If you want all the code in one Visual Studio solution you can download the C++ Windows Programming solution in the Cpp Windows Programming file.If you want to write code with Small Windows on your own, you can download the Empty project in the Empty Project file. It is an application holding only the Small Windows source code with a very simple application. You can change the name of the project and add your own application-specific code.

Who this book is for

This book is for application developers who want a head-first approach into Windows programming. It will teach you how to develop an object-oriented class library in C++ and enhanced applications in Windows. Basic knowledge of C++ and the object-oriented framework is assumed to get the most out of this book.

Conventions

In this book, you will find a number of text styles that distinguish between different kinds of information. Here are some examples of these styles and an explanation of their meaning.

Code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles are shown as follows: "The first part of a Small Windows application is the MainWindow function."

A block of code is set as follows:

void MainWindow(vector<String>argumentList,                 SmallWindows::WindowShow windowShow);

New terms and important words are shown in bold. Words that you see on the screen, for example, in menus or dialog boxes, appear in the text like this: "For instance, often, the Open item in the File menu is annotated with the text Ctrl+O."

Note

Warnings or important notes appear in a box like this.

Tip

Tips and tricks appear like this.

Reader feedback

Feedback from our readers is always welcome. Let us know what you think about this book-what you liked or disliked. Reader feedback is important for us as it helps us develop titles that you will really get the most out of. To send us general feedback, simply e-mail [email protected], and mention the book's title in the subject of your message. If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide at www.packtpub.com/authors.

Customer support

Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.

Downloading the example code

You can download the example code files for this book from your account at http://www.packtpub.com. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.

You can download the code files by following these steps:

Log in or register to our website using your e-mail address and password.Hover the mouse pointer on the SUPPORT tab at the top.Click on Code Downloads & Errata.Enter the name of the book in the Search box.Select the book for which you're looking to download the code files.Choose from the drop-down menu where you purchased this book from.Click on Code Download.

Once the file is downloaded, please make sure that you unzip or extract the folder using the latest version of:

WinRAR / 7-Zip for WindowsZipeg / iZip / UnRarX for Mac7-Zip / PeaZip for Linux

The code bundle for the book is also hosted on GitHub at https://github.com/PacktPublishing/Cpp-Windows-Programming. We also have other code bundles from our rich catalog of books and videos available at https://github.com/PacktPublishing/. Check them out!

Downloading the color images of this book

We also provide you with a PDF file that has color images of the screenshots/diagrams used in this book. The color images will help you better understand the changes in the output. You can download this file from https://www.packtpub.com/sites/default/files/downloads/CppWindowsProgramming_ColorImages.pdf.

Errata

Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books-maybe a mistake in the text or the code-we would be grateful if you could report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub.com/submit-errata, selecting your book, clicking on the Errata Submission Form link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded to our website or added to any list of existing errata under the Errata section of that title.

To view the previously submitted errata, go to https://www.packtpub.com/books/content/support and enter the name of the book in the search field. The required information will appear under the Errata section.

Piracy

Piracy of copyrighted material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works in any form on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy.

Please contact us at [email protected] with a link to the suspected pirated material.

We appreciate your help in protecting our authors and our ability to bring you valuable content.

Questions

If you have a problem with any aspect of this book, you can contact us at [email protected], and we will do our best to address the problem.

Summary

This chapter has given an introduction to Small Windows. In Chapter 2, Hello, Small World, we will start to develop applications with Small Windows.