Part I

Introduction to Windows 8 Application Development

Chapter 1: A Brief History of Windows Application Development

Chapter 2: Using Windows 8

Chapter 3: Windows 8 Architecture from a Developer’s Point of View

Chapter 4: Getting to Know Your Development Environment

Chapter 1

A Brief History of Windows Application Development

WHAT YOU WILL LEARN IN THIS CHAPTER:

Understanding how the Windows operating system began, and how it evolved over the past 27 years

Grasping the different historical tools and technologies that have characterized Windows development

Perceiving the paradigm shift of Windows 8 and using it for application development

Getting to know Windows 8 style applications

Windows 8 represents the biggest leap in the entire lifetime of this operating system. It is not simply a new version that updates old capabilities and adds a number of requested and trendy features. But, as Microsoft emphasizes, the operating system has been “re-imagined.” Without knowing where Windows 8 comes from, it is difficult to understand the paradigm shift it brings.

In this chapter, you first learn how the operating system has evolved over the last 27 years, and then you learn about the development technologies and tools as they evolved in tandem with Windows.

The Life of Windows

When the very first version of Microsoft Windows was released on November 20, 1985, it was designed to be geared toward graphical user interfaces (GUIs). Microsoft created Windows as an extra component for its MS-DOS operating system, and Windows totally changed the landscape for personal computers. The first version of Windows used very simple graphics, and it was more of a front end to MS-DOS than a real operating system.

From Windows 3.1 to 32-bit

Almost seven years passed after the first version was introduced before Windows 3.1 was released in March 1992. This 16-bit operating system allowed multitasking — in an environment where users were not used to seeing it. The new version of Windows contained virtual device drivers that could be shared between DOS applications. Because of its protected mode, Windows 3.1 was capable of addressing several megabytes of memory — the default address mode used by the 8086 family of central processing units (CPUs) allowed only 640 KB at that time — without the need for any virtual memory manager software. Computer users living in that era might remember the startup splash screen of this operating system, as shown in Figure 1-1.

Figure 1-1: The splash screen of Windows 3.1

NOTE Multitasking is a capability of operating systems that allow the running of multiple tasks (also known as processes) during the same period of time. These tasks share the computer’s resources, such as the CPU and memory. The operating system switches among the tasks while executing them. Each task runs for a small amount of time, and because of fast switching, they seem to run simultaneously.

Protected mode is an operational mode of x86-compatible CPUs that enables special features such as virtual memory handling and multitasking.

Released in August 1995, Windows 95 was a 32-bit operating system that supported preemptive multitasking — in other words, the operating system was capable of interrupting a task without any active contribution by the task. Windows 95 no longer was an add-on for MS-DOS, but now represented a full-fledged operating system (a fact that was debated for a long time). A few other Windows versions followed (specifically, Windows 98 and Windows Me), before Windows XP was released in October 2001.

Windows XP and Windows Vista

With its famous logo shown in Figure 1-2, Windows XP became the most popular version of Windows. Weird as it may seem, this success (in terms of its huge installed base) was only partly because of the new user experience (XP stands for “eXPerience”) it offered when it was released. Similarly, innovations such as the GDI+ graphical subsystem, the fast user switching, ClearType font rendering, 64-bit support, and much more, also only partially contributed to the success of this version of Windows. Actually, the primary boost to XP’s success was the unpopularity of Windows Vista — its successor.

Figure 1-2: The Windows XP logo

Released in November 2006, Windows Vista appeared with a brand-new design, and it offered a very improved security — in contrast to XP, which required three service packs to remove its security issues and pains. Although this could have been enough to achieve a greater popularity than its predecessor, Vista required improved hardware as a price for its new features. Most enterprises that had spent a significant part of their IT budget stabilizing XP — after Windows XP Service Pack 3 (SP3)—simply did not deem it reasonable to migrate to Vista. Vista soon became the shortest-living operating system in the Windows family.

Windows 7 Blots Out Vista Fiasco

As Steven Sinofsky (the president of Microsoft’s Windows division) confessed several times, Microsoft had learned its lesson even before it started to design Windows 7, which was released in July 2009, two years and eight months after Vista. Windows 7 contains significant performance improvements over Windows XP and Vista, including boot time, shutdown time, better task scheduling on multicore CPUs (that is, CPUs with more than one processor), search, and much more. The user experience improved a lot, and Windows 7 introduced new features such as jump lists, Aero Peek, Aero Snap, and many other small things that made it easier to navigate among application windows, as well as organize them on the screen.

Windows 7 definitely provided a successful way to blot out the Vista fiasco. For the Windows team, it would have been easy to follow the direction designated by Windows 7, but the team instead undertook a most compelling challenge.

The Paradigm Shift of Windows 8

Although Windows was born in an era where personal computers became part of everyday life, it still remained an operating system created with enterprises and information workers in mind. Most functions offered by the operating system actually wanted — or sometimes forced — the users to work in the way wired into the system. Users could not perform any actions before getting acquainted with concepts such as files, directories, security groups, permissions, shares, the registry, and so on. This approach mirrored how the designers assumed that users should interact with the system.

NOTE Because of the applications that swarmed out to available system resources, the Windows operating system needed periodic maintenance by way of cleanups, disk defragmentation, virus checks, service pack installations, and so on. Although each new version made some great improvement toward lightening or automating this burden, the onus never faded away completely.

Microsoft Takes the First Steps Toward Consumers

Apple’s consumer-centric products such as iPhone and iPad showed the world that there was another approach making it possible to interact with computer software in an intuitive way — without having any idea what a file, a directory, the system registry, or an application installation procedure was. Microsoft seemed to not understand this approach for a long time, but the sales figures of the market forced the company to shift its focus to consumer-centric devices and operating systems.

The first serious change in Microsoft’s behavior could be seen in the middle of February 2010 at the Mobile World Congress (in Barcelona, Spain), where the company first introduced Windows Phone 7 to the public. Windows Phone 7 was totally about the consumer experience. The visual design, its simplicity, and its gentle, well-hit animations highlighted the user interface (UI), and so the usage of this device became very intuitive. The market appraised this change, and now — almost a year after the Windows Phone 7.5 “Mango” release — Microsoft is the third competitor in the mobile operating system (OS) market, and is getting closer and closer to Apple’s iOS and Google’s Android.

NOTE The Windows operating system family did have editions for embedded devices (Windows Embedded) and mobile phones (Windows CE and Windows Mobile), which were available before Windows Phone 7.

Windows 8 Appears on the Scene

The consumer-centric approach of Windows Phone 7 became a part of the operating system experience with the release of Windows 8. When you start the operating system (the boot time has significantly decreased in comparison to Windows 7), the new Windows 8 Start screen does not remind you of the former desktop with the taskbar at the bottom. Instead, you are faced with a set of tiles, each representing an application, as shown in Figure 1-3.

Figure 1-3: The Windows 8 Start screen

This new Start screen is a clear message to consumers. Windows is not only an operating system for information workers and seasoned computer users, but it is also a consumer device designed with multi-touch sensitivity, tablets, and slates in mind. The surface of the Start screen is very intuitive, and most people can immediately start playing with it without any guidance. Users having experience with touch-screen smartphones and tablets find it natural to use the Start screen, launch applications, scroll, zoom, and apply the gestures they have already learned with other devices.

Those people who use Windows to run business applications (such as Word, Excel, or PowerPoint), or any other enterprise-specific system’s UI, may find this change to the Windows UI discipline unusual. Well, Windows was designed with total compatibility for existing applications, so it has a desktop mode as well. When launching an application that was created for any of the previous Windows versions (or one that simply does not use the Windows 8 style UI), the application will run in the well-known desktop environment. For example, when a user starts Excel, it opens in desktop mode, as shown in Figure 1-4.

Figure 1-4: Excel running in the desktop mode of Windows 8

This is the second face of Windows 8 — familiar to everyone who used Windows before. If you did not see the Start menu and the status indicator displaying the current date and time, you might think you were using Windows 7.

The new Windows 8 Start screen is not just a simple addition to Windows 7. Behind this simple screen, there is a brand-new world of consumer-centric applications, called Windows 8 style applications. Instead of using a desktop full of icons and rectangular windows of applications, users see only one application at a time, which possesses the full screen. No window caption, close button, sizable border, or any other element (called “chrome” in the user experience terminology) detracts the user’s sight from the application. The Weather application shown in Figure 1-5 is a great example of this new style.

Figure 1-5: The Weather application in Windows 8

In this book, you learn all about this new UI paradigm, and most importantly, you will acquire a command of developing such a new style of applications. Before diving deeply into the development aspects of Windows 8 style applications, you should understand a bit about the history of Windows development.

History of APIs and Tools

The Windows story would be pretty lame without applications running on the platform, and developers creating these programs. Microsoft has always been a company building a strong developer community around its products, including its flagship, Windows.

NOTE The importance of this community is often voiced by Microsoft leaders. When you surf the Internet searching for “Steve Ballmer,” you can’t miss the videos where he passionately starts shouting “developers, developers, developers, …” and repeats this word a dozen times.

In 2012, the Windows platform turned 27 years old. During its long life, not only the operating system, but also its application programming interfaces (APIs) and the related development tools improved vastly. From this point of view, Windows 8 represents the biggest leap that has ever happened in Windows’s history. To understand why this can be said, it is worth a look back in time, right to the very first moments of Windows application development.

The Power of C

Although, in today’s world, programming Windows applications is very common, it was not at the very beginning of the life of Windows. At that time, programmers who grew up with MS-DOS applications perceived the Windows approach as being weird — as if it had been turned inside out. Though a clean-cut MS-DOS application controlled everything, and it called operating system functions when they were needed, Windows followed a crazy path! The operating system controlled the application, and called it whenever it wanted to goad the program into doing something, such as refreshing the UI or executing a menu command.

And this was not the only outrage against poor developers. Using the C programming language — that was “the” language of the time — writing the simplest “Hello, world” application in MS-DOS was a piece of cake, as shown here:

#include <stdio.h>

main()
{
    printf("Hello, world");
}

Well, to achieve the same result, Windows required some more work. It demanded writing “scaffolding” code around the single printf function, and you could call it anything but intuitive, as shown in Listing 1-1.

Listing 1-1: The “Hello, world” program à la Windows 3.1 (extract)

#include <windows.h>

/* Export the entry point to be called by Windows */
long FAR PASCAL _export WndProc(HWND, UINT, UINT, LONG)

/* The entry point of the application */
int PASCAL WinMain(HANDLE hInstance, HANDLE hPrevInstance,
    LPSTR lpszCmdParam, int nCmdShow)
{
    static char szApplication[] = "HelloW";
    HWND hwnd;
    MSG msg;
    WNDCLASS wndClass;

    /* Create a Window class */
    if (!hPrevInstance)
    {
        wndClass.Style = CS_HREDRAW | CS_VREDRAW;
        wndClass.lpfnWndProc = WndProc;
        /* A few code lines omitted for the sake of brevity */
        wndClass.hbrBackground = GetStockObject(WHITE_BRUSH);
        wndClass.lpszMenuName = NULL;
        wndClass.lpszClassName = szApplication;
        RegisterClass(&wndClass);
    }

    /* Create a window instance for the class */
    hwnd = CreateWindow(szApplication,
        "My Hello World Program",
        WS_OVERLAPPEDWINDOW,
        /* A few parameters omitted for the sake of brevity */
        hInstance,
        NULL);
    /* Initiate displaying the window */
    ShowWindow(hwnd, nCmdShow);
    UpdateWindow(hwnd);

    /* Manage the message loop */
    while (GetMessage(&msg, NULL, 0, 0))
    {
        TranslateMessage(&msg);
        DispatchMessage(&msg)
    }
}

/* Processing messages */
long FAR PASCAL _export WndProc(HWND hwnd, UINT message,
    UINT wParam, LONG lParam)
{
    HDC hdc;
    PAINTSTRUCT ps;
    RECT rect;

    switch (message)
    {
        case WM_PAINT:
            hdc = BeginPaint(hwnd, &ps);
            GetClientRect(hwnd, &rect);
            DrawText(hdc, "Hello, world", -1, &rect,
                DT_SINGLELINE | DT_CENTER | DT_VCENTER);
            EndPaint(hwnd, &pd);
            return 0;

        case WM_DESTROY:
            PostQuitMessage(0);
            return 0
    }
    return DefWindowProc(hwnd, message, wParam, lParam);
}

This program contains many lines of code, because it was written over an API that offered only low-level operating system functions. Although this source code is long, it uncovers important internal details of Windows. All of them are still in the heart of Windows 8, of course, in an improved form:

At the very beginning, the program creates a window class by setting up the fields of the wndClass structure and using the RegisterClass method. The window class is a concept that identifies a procedure (called window procedure) that processes messages sent to the window.

The program creates a window (with the CreateWindow method) using the registered window class, and then displays it with the ShowWindow method. The UpdateWindow method sends a message to the window in order to repaint its UI.

The soul of the application is the message loop, as shown here:

while (GetMessage(&msg, NULL, 0, 0))
{
    TranslateMessage(&msg);
    DispatchMessage(&msg)
}

This loop obtains messages from a queue, translates key presses to equivalent messages (for example, as if a mouse were used), and then dispatches them to the appropriate window procedure.

If the message loop is the soul, the window procedure is the heart. In Listing 1-1, WndProc is called by the message loop. Its message parameter contains the code of the message (the event to handle), and a switch statement wraps the pieces of code snippets processing individual messages.

The WM_PAINT message tells the window that it should repaint itself. With the BeginPaint method, it obtains a device-context resource to use for drawing in the client area of the window. This device context is then used to write the “Hello, World” message in the middle of the window. ReleasePaint releases this device context — which happens to be a very limited resource in the system.

You can imagine how time-consuming and painful Windows development was at that time — because programmers were forced to use low-level operating system constructs through the Windows API.

C++ Takes Over C

In 1983, only a few years after Brian Kernighan and Dennis Ritchie published the first edition of C (1978), Bjarne Stroustrup created a new language that added object-oriented aspects to C. This language was C++, and it soon became popular in the Windows platform, too.

C++ allows encapsulating data and functionality in classes, as well as supporting object inheritance and polymorphism. With these features, the flat API of Windows could be presented as a smaller set of entities that grouped data structures and API operations into a logical context. For example, all the operations related to create, display, and manage windows on the UI could be put into a class named Window.

The C++ approach helped developers have a better overview of the API, and lowered the entry barrier to Windows programming. For example, the essential parts of the “Hello, World” program described in Listing 1-1 could be organized around objects, as shown in Listing 1-2.

Listing 1-2: The blueprint of the “Hello, World” program in C++ (extract)

// --- Class representing the main program
class Main
{
  public:
    static HINSTANCE hInstance;
    static HINSTANCE hPrevInstance;
    static int nCmdShow;
    static int MessageLoop( void );
};

// --- Class representing a window
class Window
{
  protected:
    HWND hWnd;
  public:
    HWND GetHandle( void ) { return hWnd; }
    BOOL Show( int nCmdShow ) { return ShowWindow( hWnd, nCmdShow ); }
    void Update( void ) { UpdateWindow( hWnd ); }
    virtual LRESULT WndProc( UINT iMessage, WPARAM wParam, LPARAM lParam ) = 0;
};

// --- The class representing this program’s main window
class MainWindow : public Window
{
    // --- Implementation omitted for brevity
};

// --- Extract from the implementation of the Main class
int Main::MessageLoop( void )
{
    MSG msg;

    while( GetMessage( (LPMSG) &msg, NULL, 0, 0 ) )
    {
        TranslateMessage( &msg );
        DispatchMessage( &msg );
    }
    return msg.wParam;
}

LRESULT MainWindow::WndProc( UINT iMessage, WPARAM wParam, LPARAM lParam )
{
    switch (iMessage)
    {
        case WM_CREATE:
            break;
        case WM_PAINT:
            Paint();
            break;
        case WM_DESTROY:
            PostQuitMessage( 0 );
            break;
        default:
            return DefWindowProc( hWnd, iMessage, wParam, lParam );
    }
    return 0;
}

With the object-oriented approach offered by C++, object behaviors could be packaged into reusable code libraries. Programmers could create their programs based on these libraries so that they needed to define only the behaviors that differed from the built-in ones. For example, they had to override the Paint() method in Listing 1-2 to repaint the UI of their window objects.

Windows programming changed a lot with C++ and object libraries. Microsoft created two libraries, Microsoft Foundation Classes (MFC) and Active Template Library (ATL), which are still maintained and available in their flagship development environment, Visual Studio.

NOTE You will soon learn more about the Visual Studio development environment.

Visual Basic

Applications written in the C or C++ programming languages expose a lot of details about how Windows works. In a few instances, it is important to know these things, but in most cases, it could be frustrating and detract developers from focusing on the real application functionality.

Released in May 1991, Visual Basic dramatically changed this programming style. Instead of exposing internal Windows details, Visual Basic concealed them from programmers, and offered high-level constructs such as forms, controls, modules, classes, and code-behind files. Instead of writing dozens of lines to achieve very simple functionality, the Visual Basic language enabled developers to focus on the real business of their applications. The “Hello, World” program could be written in one line:

MsgBox("Hello, World!")

No window class setup, no window registration, no message loop programming! The high-level concepts of the language made it totally unnecessary to deal with scaffolding details. All of this was implemented by the Visual Basic run time.

Using a graphical Integrated Development Environment (IDE), this way of application development is still the most preferred and most productive approach. Programmers graphically design the dialog box windows (or forms, in Visual Basic terminology) of the application by dragging UI elements (controls) from the toolbox of the IDE, and dropping them to the form’s surface. Each control has several event handlers that respond to the events arriving from the environment — such as when the user clicks a button or changes the selection in a combo box. Programming is actually writing the code that handles these events.

In 1993, Microsoft developed a binary standard, the component object model (COM), which allowed the creation of reusable objects that can be consumed by other applications. A number of technologies are built upon COM, such as Object Linking and Embedding (OLE), which made it possible to automate applications. The versions of Visual Basic released after 1993 were created with COM and OLE in mind. This approach was so successful that a dialect of the language, Visual Basic for Applications (VBA), became the programming language of Microsoft Office macros.

Delphi

Visual Basic was not the only programming environment that had gone off the beaten track of C and C++. Originally developed by Borland, Delphi used the Object Pascal programming language. Whereas Visual Basic was an object-based language (it supported classes with encapsulated data and functions, but did not allow object inheritance), Object Pascal was a real object-oriented language. The IDE of Delphi (its first version was released in 1995) was very similar to the Visual Basic IDE. Delphi was designed to be a Rapid Application Development (RAD) tool that supported developing database applications, including simple ones and even enterprise systems.

The product evolved very fast, with five versions released in the first five years of its life. Delphi was the first tool capable of compiling 32-bit applications for Windows. Similar to Visual Basic controls, it provided more than 100 visual components (organized into Delphi’s Visual Component Library) that developers could immediately put into practice. In addition, developers could easily create their own visual components, and add them to the existing library.

The Emergence of .NET

In 2002, the .NET Framework provided fresh momentum to Windows development. .NET programs are compiled into an intermediate language called Microsoft Intermediate Language (MSIL). This intermediate code is transformed to executable CPU-specific operations during run time by a just-in-time (JIT) compiler. This new approach brought several important paradigms into Windows development, including the following:

Prior to the release of .NET, each language (and development environment) used its own runtime library. Learning a new language used to mean learning a new runtime library as well. With .NET, all languages use the same run time. In 2002, only two programming languages were supported by Microsoft (C# and Visual Basic.NET). Today, more than 100 .NET languages are in use. Microsoft itself added F# to this list, and the company also supports IronPython and IronRuby (which are driven by their own communities).

Using a garbage-collection mechanism, the runtime environment manages memory allocation and object destruction automatically. This behavior helps increase productivity, and allows developers to create less error-prone code.

Garbage collection also reduces the chance of writing programs with memory leaks.

Instead of low-level API methods, programmers can work with objects that cover the complexity of the APIs behind the scenes. Instead of dealing with nitty-gritty, internal Windows details, developers can use high-level abstraction, thus boosting productivity.

.NET provides a great level of cooperation between COM and .NET objects. The .NET code can not only access COM objects, but it also provides objects that can be consumed by the COM world.

.NET is called managed environment, and its languages are called managed languages — as a distinction from native languages such as C, Object Pascal (Delphi), and C++, which compile CPU-specific code.

NOTE The .NET Framework was not the first managed runtime environment. This distinction belonged to Java, which was released by Sun Microsystems in 1995. .NET was Microsoft’s answer to the Java phenomenon, and a number of its features were inspired by Sun’s Java implementation.

Released in tandem with the .NET Framework, Visual Studio played an important role in the success of .NET. Visual Studio shipped with about two dozen project templates to boost the start of Windows application development. Today, the Ultimate edition of Visual Studio contains more than a hundred project templates.

NOTE You learn more about Visual Studio in Chapter 4.

Visual Studio templates are very powerful. For example, you can create the application shown in Figure 1-6 with a few clicks by using the Windows Forms Application template.

Figure 1-6: A simple Windows Forms application created with Visual Studio

With the tools of Visual Studio, you can easily establish the visual properties of the window shown in Figure 1-6. Listing 1-3 shows the only code that you should add manually in this example.

Listing 1-3: The code behind the form in Figure 1-6

using System;
using System.Windows.Forms;

namespace HelloWorldWinForms
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            label1.Text = "Hello from Windows Forms!";
        }

    }
}

Although .NET was harnessed with rich object libraries and great tools, it still used the API that was based on the design of the first Windows versions.

New UI Technologies

For a long time, the Windows UI was managed by the Graphics Device Interface (GDI) API that evolved to GDI+ with the release of Windows XP. GDI and GDI+ are raster-based APIs, and all standard Windows UI controls used them for rendering themselves. The only way a developer could change the default visual appearance of any standard control was to override the Windows event that rendered the UI of the controls.

When the Windows Presentation Foundation (WPF) graphical subsystem was introduced in the .NET Framework 3.0 (and later as a built-in component of Windows Vista), the GDI paradigm was totally changed. Instead of creating the UI in an imperative way (that is, using instructions written in a programming language), WPF employs eXtensible Application Markup Language (XAML), a derivative of eXtensible Markup Language (XML), to describe UI elements. WPF also leverages the great hardware-accelerated capabilities of graphics processing units (GPUs) built into the computers.

Silverlight (Microsoft’s rich Internet application framework) uses XAML to define the user interface, too. Listing 1-4 shows a very simple XAML sample implementing the “Hello, World” application in Silverlight.

Listing 1-4: The “Hello, World” applications’ MainPage.xaml file

<UserControl x:Class="HelloFromSL.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"
    d:DesignHeight="300" d:DesignWidth="400">

    <Grid x:Name="LayoutRoot" Background="White">
        <TextBlock FontSize="48">Hello from Silverlight</TextBlock>
    </Grid>
</UserControl>

This code produces the page shown in Figure 1-7. The text in this figure is displayed as a result of the boldface code line in Listing 1-4.

Figure 1-7: The output of Listing 1-4

WPF and Silverlight are great technologies. Using them is like replacing a 1930s Lamborghini engine (the GDI/GDI+ type one) with a state-of-the-art one produced in 2012 (WPF/Silverlight). These technologies not only define the UI, but also can declare its dynamic behavior using no (or a minimal amount of) code. These technologies connect the UI with the logic (model) layer of an application. Following are some important features of these technologies:

These technologies are designed and tailored so that you can create rich, powerful desktop or Internet applications to produce a superior user experience. In addition to providing simple UI elements (such as text boxes, buttons, lists, combo boxes, images, and so on), they also provide the freedom to create content with animation and media elements, such as video and audio. In contrast to the traditional (some may even say boring) UI approach with rectangular UI elements, WPF and Silverlight enable you to change the entire face of an application.

They provide a very flexible layout system that makes it easy to create layouts you can automatically adapt to a number of factors (such as available screen size, number of items displayed, size of the displayed elements, and magnification).

Styles and templates are features that contribute to a smooth cooperation between developers and designers. Developers implement the logic of the application, so they never set the visual properties of the UI directly. Instead, they signal programmatically that the state of the UI is changed. Designers create the visuals of the UI, taking into account the possible states of the UI.

Silverlight and WPF declaratively (in other words, no code required) apply data binding — that is, a technology used to connect elements of the UI to data, or other UI elements. Data binding works in cooperation with styles, templates, layouts, and even animations. This mechanism is especially useful in line-of-business (LOB) applications. With the help of data-binding information coming from the database and processed by the application’s logic, elements can be declaratively bound to the UI elements.

NOTE A layout system is used to arrange the elements on the UI. With a flexible layout system (such as the one behind WPF, Silverlight, and Windows 8), you can define relationships among UI elements, and those are automatically placed on the UI at run time. For example, you can define a layout system so that it should arrange UI controls in two columns, and distribute them evenly.

Styles and templates in WPF and Silverlight are used similarly as styles and templates in document publishing systems. A style collects common attributes of UI elements; a template is a skeleton with placeholders for the content of a UI element.

The primary virtue of WPF and Silverlight is probably the fact they can help in the clear separation of UI-related tasks belonging to developers from tasks carried out by designers. With today’s consumer-centric applications, this is an obvious advantage over approaches where the tasks of developers and designers are mingled.

NOTE XAML plays a very important role in the Windows 8 style applications, as you learn in Chapter 3.

Catch-22 of Windows Application Development

During the evolution of Windows application development, technologies and related techniques branched out. One branch consisted of the native development, which started with the C programming language in the very early days of Windows. The other branch consisted of the managed development, which uses the .NET Framework, along with its managed technologies and languages.

Because of CPU-specific code compilation and the low-level access to Windows API and system resources, native applications can provide great performance that cannot be beaten by managed technologies. However, when writing business applications, using native code is less productive and more cumbersome than employing managed code with the .NET Framework. Because business applications generally work with databases, the performance overhead of managed languages cannot be perceived at all — the application spends most of its time communicating with underlying services and databases.

When Windows application developers are looking for the right technology and tool for a certain application, they may find themselves in the same predicament as Yossarian, the bombardier in Joseph Heller’s novel, Catch-22 (New York: Alfred A. Knopf, 1995).

In many situations, especially when writing desktop applications, there is no optimal choice between native and managed development. Although WPF and Silverlight would be great technologies for spectacular applications, they are not available from native code. WPF and Silverlight are not embedded into the operating system deeply enough. For example, launching a WPF application takes time while the WPF subsystem loads into the memory. In many cases where computing capacity is required, .NET produces much poorer results than native code.

Visual Studio is a great example of this schizophrenic situation. It uses a mixed codebase. Most of the components are implemented in C++, and certain parts in C# (using WPF). The splash screen should be immediately popped up on the screen after the user launches the application. It is implemented in C++ with GDI+, so WPF would not have been fast enough. The code editor of Visual Studio is implemented in WPF, because it has a rich and easy-to-use toolset for hosting such a complex component with a great UI.

In LOB application development, productivity is the most important factor. The performance advantage of native code development does not add much value to an application, because, in most cases, the database tier is the performance bottleneck. Using managed code, the programming phase of a business application is generally much faster and less error-prone.

So, when writing a desktop application, native code provides the optimal performance, but, in this case, you cannot use the rich toolset of WPF and Silverlight. When you move to managed code, you may gain productivity, but lose final application performance. In your final despair, you can go on with some “mule” solution — just as Visual Studio does, but, in this case, you undertake a lot of overhead. It’s not an easy decision, is it?

This situation totally changes with Windows 8. Web developers with HTML5/cascading style sheets 3 (CSS3)/JavaScript experience, seasoned C++ programmers, and developers growing up on .NET, can all feel that their knowledge is enough and appropriate for starting Windows 8 style application development. There is no privileged camp of geeks like C programmers happened to be at the very beginning of the Windows era. Everyone can use the same technologies and the same tools — all without compromise. How is this possible? Chapter 3 explains how.

Summary

The Windows platform has evolved amazingly in the past 27 years. It has transformed from a simple MS-DOS extension to a complex and full-fledged operating system used in the majority of personal computers all around the world. Windows was designed with information workers and seasoned computer users in mind. Although, in every version, it moved closer and closer to less-advanced users, it never could become the operating system of such a simple consumer device as Apple’s iPhone or iPad.

Windows 8 changes this. In addition to the traditional desktop mode familiar to all its users, the operating system has a new face with Windows 8 style applications that provide an intuitive user experience — the application possesses the full screen and the full attention of the user.

Not only has the operating system changed, but the development tools and APIs have changed and been significantly improved. Unlike in the past when only C and C++ programmers were privileged to create Windows applications, today C++, Visual Basic, C#, and Delphi programmers can also develop applications with their favorite IDEs. Depending on the chosen language and tool, programmers must use different APIs and technologies. Whereas native programming languages (such as C, C++, and Delphi) offer CPU-specific code and better performance, managed code is more productive for developing LOB applications, and they can easily access the modern UI technologies such as WPF and Silverlight.

Windows 8 style applications provide the same API that is available both in native code and managed code — without compromises. Moreover, this API is available for HTML5/CSS3/JavaScript developers, too.

Windows 8 changes not only the UI of the operating system, but also the way in which you can interact with it. In addition to supporting the traditional input devices such as the keyboard and the mouse, it provides first-class support for interacting with the operating system and Windows 8 style applications — with support for multi-touch gestures, a stylus, and through sensors such as the gyroscope and accelerometer.

In Chapter 2, you learn about all these new things when using Windows.

Exercises

1. What was Microsoft’s first operating system in the Windows family that was designed and developed totally with consumers in mind?

2. Do Windows 8 style applications have window captions and borders?

3. List the programming languages that are frequently used for Windows application development.

4. What stack of languages can web developers use to create Windows 8 style applications with Windows 8?

NOTE You can find answers to the exercises in Appendix A.

What You Learned In This Chapter

Topic | Key Concepts

Windows operating system
Windows is the family of operating systems that started with Windows 1.0, released on November 20, 1985, as an extra component of the MS-DOS operating system. The family has also included members for embedded devices (Windows Embedded) and mobile phones (Windows CE, Windows Mobile, and Windows Phone). The current versions are Windows 8 and Windows Phone 7.5.

Windows APIs | The applications working on Windows can access the underlying services of the operating system through the Windows application programming interfaces (APIs).

The C and C++ programming languages
As two programming languages that can be used for developing Windows applications, C and C++ exploit all the features of the operating system, including hardware-specific and very low-level ones. These languages have been used for application development since the early days of Windows. C++ extends C with object-oriented features, and has become a very mature programming language over the past 25 years.

The Visual Basic programming language
Released in 1991, Visual Basic is a revolutionary programming language that significantly reduces the programming efforts required by providing high-level UI concepts such as forms, controls, and events. The language also provides a seamless integration with component object model (COM)/Object Linking and Embedding (OLE) components.

.NET Framework
The Microsoft .NET Framework is a runtime environment that sits between the operating system and the applications. Its primary role is to provide access to all services of the underlying operating system in a managed way that enables developers to be productive. C# and Visual Basic .NET are the two most frequently used languages to create applications for the .NET Framework.

WPF and Silverlight
Windows Presentation Foundation (WPF) and Silverlight are modern and sophisticated UI platforms running on the .NET Framework. They enable you to create applications with a rich UI, including flexible layout, multimedia elements, and animation. They use advanced techniques such as styles, templates, and data binding to provide a very efficient way to tie the UI layer of applications with the underlying logic.

Windows 8 style applications
Windows 8 style applications are a new form of applications introduced in Windows 8. These are totally different from the traditional desktop applications because of their visual appearance and ways of managing user interactions. Windows 8 style applications possess the full screen (that is, they do not have an application chrome), and no longer require users to display and manage multiple windows within the application.

Chapter 2

Using Windows 8

WHAT YOU WILL LEARN IN THIS CHAPTER:

Using Windows 8 with the mouse and keyboard

Using Windows 8 with multi-touch devices

Leveraging the features of the Start screen, Live Tiles, and the charm bar

Switching to the desktop and using traditional Windows applications

Windows 8 changes a lot in terms of the user interface (UI). It was built with a more touch-centric approach in mind. The desktop has a few slightly changed features, but most of the traditional, mouse-based workflows remain untouched. On the new Windows 8 style interface, virtually everything is new. Live Tiles aren’t just shortcuts; Windows 8 style applications aren’t handled like traditional Windows apps. Even the Start screen contains features the old Start menu didn’t.

Although the user may learn these things intuitively, for a developer, it is imperative to know all the nooks and crannies of using the Windows 8 UI. Only with extensive knowledge of these capabilities can you build really engaging and intuitive apps that users use not just to complete a task, but enjoy doing so.

Two Worlds, One Operating System

Windows 8 has two distinct UIs: the ordinary desktop UI (which probably you are used to) and the completely different and new Windows 8 UI. Why is the Windows 8 UI so important?

In the past few decades, users have experienced the triumph of the mouse over nearly every other controlling device on PCs. For an ordinary Windows user, using a mouse is considered to be the easiest way to use a desktop computer’s graphical user interface (GUI). In addition to the mouse, power users rely on the keyboard, too. Keyboard shortcuts such as Ctrl+Alt+Del and special keys, like the Windows key, speed up their work.

Microsoft built its Windows operating systems on the assumption that you will use a mouse and a keyboard to control the operating system and the programs. This premise led Microsoft to create a GUI, which coordinates user interactions performed with these devices. It is always assumed that you have a pixel-precise pointer, and you can click on a small icon without any trouble.

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!