Академический Документы
Профессиональный Документы
Культура Документы
PHStudios.com Tutorials
Contents
Section I About Windows Applications 3
Part I Introduction 3
II Advantages and Disadvantages 3
III Visual C++ Windows Apps Overview (WinForms) 4
Section II Getting Started 9
Part I Modifying Window Size 9
II Change the Window's Title 11
Section I
Section Overview
This section will introduce you to the greatest type of programs currently
available, GUI (graphical user interface) applications. Advantages and disadvantages
of creating a GUI application will be listed to help you determine if you want to go
through the trouble coding them. We will also take a look at the easiest way to
create GUI applications using Windows Forms, which is only available in Microsoft®
Visual C++. At the end of the advanced sub-series, I will briefly go over the Win32
type of GUI which is compiler independent.
Part I Introduction
A GUI application, like your browser or music player, is one of the most difficult
things to program. The more advanced your application progresses, the more
graphical you need to make it. Microsoft® Visual C++ makes developing GUI
applications easier, but limits distribution to Microsoft® Windows platforms only.
GUI applications may look nice, but they require a large amount of development
time. Most of the code and actions of a program will be processed behind the
application itself, but the development and style of the main window needs to be
carefully implemented to look nice and professional. Here is a list of advantages and
disadvantages for GUI applications:
Advantages
More programmer control
Application does not quit when finished, unless programmed to
Better looking than console
Can do more than console applications
Disadvantages
Requires more work than usual
Graphical side needs to be designed carefully to appear professional
Longer development time
Longer testing time
I will briefly go over the basic code for the windows applications. Open Visual C++ 2008
Express and create a new Windows Form Application with any name you want:
Once your project is created, you will have a basic window for you finished already. We should
examine the current source and files before we continue. The following picture shows all the
files found in the generated program.
Note: If you do not see the Solution Explorer, go to View - Solution Explorer
File Description
Form1.h Header file that contains the code to create
the window
Form1.resX XML resource file for Form1.h. Contains
BuildAction
resource.h General resource file for app.rc
stdafx.h Includes standard system files or program
specific include files
app.ico Icon for the file
app.rc Resource script
AssemblyInfo.cpp Project's metadata (copyright, company,
title, ...)
Introduction.cpp Entry point of the application (main function)
stdafx.cpp Includes stdafx.h file
namespace Introduction {
/// <summary>
/// Summary for Form1
///
/// WARNING: If you change the name of this class, you will
need to change the
/// 'Resource File Name' property for the managed
resource compiler tool
/// associated with all .resx files this class
depends on. Otherwise,
/// the designers will not be able to interact
properly with localized
/// resources associated with this form.
/// </summary>
public ref class Form1 : public System::Windows::Forms::Form
{
public:
Form1(void)
{
InitializeComponent();
//
//TODO: Add the constructor code here
//
}
protected:
/// <summary>
/// Clean up any resources being used.
/// </summary>
~Form1()
{
if (components)
{
delete components;
}
}
private:
/// <summary>
/// Required designer variable.
/// </summary>
System::ComponentModel::Container ^components;
Form1.h Analysis
As you see, the file is well commented. The only function they do not
recommend modifying manually is the InitializeComponent function. Every button,
label, text box, and other component you add will be automatically put in the
InitializeComponent function, so there is no need to modify it yourself. Use the
Properties Window if you want to modify something manually. We will be using the
Properties Window later in this tutorial.
#include "stdafx.h"
#include "Form1.h"
[STAThreadAttribute]
int main(array<System::String ^> ^args)
{
// Enabling Windows XP visual effects before any controls are
created
Application::EnableVisualStyles();
Application::SetCompatibleTextRenderingDefault(false);
Introduction.cpp Analysis
You should rarely have to edit this file, but sometimes you might need to. This
file is commented really well too and does not need much analysis. At the top of the
file we include the two header files stdafx and Form1. Next, we have a main function
which accepts program arguments. The function will first set the application to
windows cp visual effects, then will create the form.
Section II
Section Overview
Enough with the introductions, this section we will be modifying the window's
size and title. These changes will be small, but it seems like a nice way to start
learning how to program with .NET. We will also take a look at the Properties
Window to change the values of anything we add to a Windows application.
Press F5 on the keyboard and select Yes on the build confirmation window if you
receive it.
We have a nice size for our application finally. If you would like a different
size, just change the Size property of the form. Width is first in the property, then
height.
Press F5 on the keyboard and select Yes on the build confirmation window if you receive it.
Conclusion
The goal of this tutorial was to introduce you to GUI programming, in this case using
Windows Forms. All we modified in this tutorial was the window dimensions and title. Next
tutorial we will add buttons to our window and add an effect when we click it.