Win+


An Overview of this Book

This book provides additional information to programmers who are familiar with .Net programming. Programmers who are familiar with Win32 will also find this discussion straightforward. The basic interface (Win+) is in C++ and the first three programs are in C++. After that, a switch is made to C# and the discussion continues in C#. Due to the fact that Windows is written in C++, some of the many C++ APIs that are available are discussed.

What is unusual about the C# programs of this book is that they make use of the native graphics interface GDI (rather than GDI+). This allows the programmer to gain a feel for the native operating system graphics functions. A set of managed classes are provided by I++ to facilitate this discussion. These classes are based upon the Win+ API which is discussed in what follows.

Win+ Overview

Win+ redefines the unmanaged windows interface to be managed. The many hundreds of individual macro constants defined in the original interface have been renamed, grouped into units then expressed as enum classes. The pointers are gone; often replaced by the Handle class. The __stdcall functions have been replaced by static, managed methods inside classes. Effectively, these steps upgrade the native interface to a managed interface.

Win+ enables access to GDI from C#. This means that you can write native windows graphics in C# (instead of only GDI+). You can learn about the native graphics subsystem without venturing outside C#.

Win+ enables GDI+ classes as well. A new rendition of the class Graphics (as well as all the other GDI+ classes) is present in I++. Additionally, retained graphics in the form of the class R2 is present. Retained graphics is new to Windows. The Analog clock demonstrates how to use retained graphics to draw a clock.

The projects for this book may be found in

These directories contain subdirectories containing the actual projects. Depending upon which chapter is being studied, the reader should navigate the projects directories to load the project corresponding to the discussion. The chapter that is being discussed needs to be known in advance.

Win+ in Detail

The Win+ interface is a managed C++ interface for programming windows. It is an Operating System Abstraction Layer. It abstracts the operating system to a C++ Code Layer. This code layer provides an improved interface for programming Windows, and it may eventually lead to new, improved operating systems.

Win+ is packaged using name spaces, and the names chosen for programming identifiers within the names spaces has been carefully thought through. Win+ applies corrections to the original Win32 name space. Functions names like GetDC have been expanded to GetDeviceContext. Another example is DefDlgProc, which has been renamed to DefaultDialogProcedure. Thousands of constants that previously were defined as macros have been redefined as enumerators. For example, in the existing Win32 interface, window styles are defined as follows:

#define WS_OVERLAPPED 0x00000000L
#define WS_POPUP      0x80000000L
#define WS_CHILD      0x40000000L
...

whereas, in Win+, the window styles are part of the enum class Style - a portion of which is shown below.

public enum class Style
{
  Window            = 0x00000000,
  Popup             = 0x80000000,
  Child             = 0x40000000,
 ...
};

Note that macros are part of the preprocessor and have no place in common programming. Macros are of global scope, whereas the enumeration for styles is part of the IPlusPlus namespace contained in the .Net Assemblies IPlusPlus.Constants.dll and IPlusPlus.WinPlus.dll. Win+ repositions all of the constants of Win32 in this way. In doing so, all the acronyms (like WS_) are banished. Note that Intellisense is available on all constants using the scope operator. For example, to refer to the Child style the following is used Style::Child. When the scope operator is used, Intellisense prompts the user with a list of options. The entire operating system has been restructured to ensure optimum use of Intellisense.

Additionally, no use is made of terms that:

Notice in the above declaration of window styles, Win32 contains the acronym WS_. This pattern is repeated throughout the Win32 interface, making the entire interface acronymic. Win+ undoes by packaging constants in enum classes. When the constants are defined in enum classes, the burden of uniqueness is lifted, thereby enabling the prefixes to be dropped. This provides an optimal definition of the Windows operating system.

The main unsigned integer data type of Win32 is DWORD (short for double word). In 64 bit windows, a DWORD is 32 bits - a half word. DWORD has its origins in 16 bit windows, where a word was 16 bits and thus a double word was 32 bits. Clearly DWORD is a hardware dependent term and the hardware it refers to is twenty years in the past. A DWORD becomes simply an unsigned in Win+. So Win32 is hardware dependent and Win+ is hardward independent.

The API naming conventions of Win32 are the best portion of the namespace. The API uses a mixed case naming convention with uppercase used to separate words. In Win+, the mixed case naming convention has been extended to classes and constants. In Win32, constants are in solid uppercase with words run together. Win+ remedies this unsightly code with the mixed case naming convention. The end result is that constants, functions and classes all use the same, consistent naming convention.

Name Spaces

The primary interface of i++ is contained in the name space IPlusPlus. Additionally, there are descendent namespaces:

This leads to Win+ code containing the statements:

using namespace IPlusPlus;
using namespace IPlusPlus::Control;
using namespace IPlusPlus::Windows;
using namespace IPlusPlus::Graphics;

The use of name spaces and the careful selection of elements of the name space lead to the Win+ C interface being a modern, clean method of accessing the services of the windows operating system.