diff --git a/2554.pdf b/2554.pdf new file mode 100644 index 0000000..66020dd Binary files /dev/null and b/2554.pdf differ diff --git a/2555.pdf b/2555.pdf new file mode 100644 index 0000000..774201e Binary files /dev/null and b/2555.pdf differ diff --git a/2744.html b/2744.html new file mode 100644 index 0000000..301eff9 --- /dev/null +++ b/2744.html @@ -0,0 +1 @@ + Reprint -- Pro Visual C++/CLI and the

Reprint -- Pro Visual C++/CLI and the .NET 2.0 Platform – Fixes

 

Page xxvii, So What Did You Say About C++/CLI?, Paragraph 2 read:

 

  • Mixed mode: source-level mix of native and CTS types plus binary mix of native and CIL object files. (Compiler switch: \clr.)
  • Pure mode: source-level mix of native and CTS types. All compiled to CIL object files. (Compiler switch: \clr:pure.)
  • Native class can hold CTS types through a special wrapper class only.
  • CTS classes can hold native types only as pointers.

Of course, the C++/CLI programmer can also choose to program with the .NET managed types only, and in this way provide verifiable code, using the \clr:safe Visual C++ compiler switch.

 

It should read (changes highlighted):

 

  • Mixed mode: source-level mix of native and CTS types plus binary mix of native and CIL object files. (Compiler switch: /clr.)
  • Pure mode: source-level mix of native and CTS types. All compiled to CIL object files. (Compiler switch: /clr:pure.)
  • Native class can hold CTS types through a special wrapper class only.
  • CTS classes can hold native types only as pointers.

Of course, the C++/CLI programmer can also choose to program with the .NET managed types only, and in this way provide verifiable code, using the /clr:safe Visual C++ compiler switch.

 

 

Page xxviii

 

C++\CLI  should read:  C++/CLI   (occurs 5 times on the page)

 

Page 5, Figure 1-1

 

 [2nd label] Application Development Technologies should read:  .NET Framework Base Classes

 [3rd label] Application Development Technologies should read: Common Language Runtime

 

 

 

 

Page 6, 3rd bullet, 1st  line reads:

 

Managed code is used to create objects that can be garbage collection.

 

It should read (change highlighted):

 

Managed code is used to create objects that can be garbage collected.

 

Page 8, 6th bullet, 1st  line reads:

 

A list of all reference assemblies

 

It should read (change highlighted):

 

A list of all referenced assemblies

 

 

Page 17, Just-In-Time Compilation, Paragraph 2 reads:

 

The JIT compiling process is, in concept, very easy. When an application is started, the JIT compiler is called to convert the MSIL code and metadata into machine code. To avoid the potentially slow start-up time caused by compiling the entire application, the JIT compiler only compiles the portions of code that it calls, when they are called (hence the name, just-in-time compiler).

 

It should read (changes highlighted):

 

The JIT compiling process is, in concept, very easy. When an application is started, the JIT compiler is called to convert the MSIL code and metadata into machine code. To avoid the potentially slow start-up time caused by compiling the entire application, the JIT compiler only compiles the portions of code that the application calls, when they are called (hence the name, just-in-time compiler).

 

 

 

Page 19, 6th bullet, 1st line reads:

 

Handler types: A reference to a type

 

It should read (changes highlighted):

 

Handle types: A reference to a type

 

 

Page 19, Paragraph 1 reads:

 

A point worth mentioning is that the CLS defines all .NET-compatible language data types, but a .NET-compatible language does not need to support all CLS-defined data types.

 

It should read (changes highlighted):

 

A point worth mentioning is that the CTS defines all .NET-compatible language data types, but a .NET-compatible language does not need to support all CTS-defined data types.

 

 

Page 21, .NET Application Development Realms, Paragraph 1 reads:

 

.NET application development falls primarily into one of five realms: Web applications, Web services, Windows applications, Windows services, and console applications. Using languages such as C#, Visual Basic .NET, and Visual Studio .NET provides a simple, powerful, and consistent environment to develop all five. Unfortunately, for C++/CLI, only four are supported: console applications, Windows applications, Windows services, and Web services.

 

It should read (changes highlighted):

 

.NET application development falls primarily into one of five realms: Web applications, Web services, Windows applications, Windows services, and console applications. Using languages such as C#, Visual Basic .NET and C++/CLI, in conjunction with Visual Studio .NET provides a simple, powerful, and consistent environment to develop all five. Unfortunately, for C++/CLI, only four are supported: console applications, Windows applications, Windows services, and Web services.

 

 

Page 30, Paragraph 4 reads:

 

The preceding line actually declares one handle and one pointer to an int and two variables of type int.

 

It should read (changes highlighted):

 

The preceding lines actually declare one handle and one pointer to an int and two variables of type int.

 

 

Page 31, top of page reads:

 

int x = y = z = 200;

 

It should read (changes highlighted):

 

int y, z;

int x = y = z = 200;

 

 

 

 

 

Page 32, Table 2-3 reads:

 

Abstract     delegate       event          finally

Generic      in                 initonly       literal

Override     property      sealed         where

 

It should read (changes highlighted):

 

abstract     delegate       event          finally

generic      in                 initonly       literal

override     property      sealed         where

 

 

Page 34, in Caution reads:

 

A char is an 8-bit unsigned integer

 

It should read (changes highlighted):

 

A char is an 8-bit signed integer

 

 

Page 32, in Listing 2-1 reads:

 

// Initialize using charater literal

 

It should read (changes highlighted):

 

// Initialize using character literal

 

 

Page 43, paragraph 2 reads:

 

Like the fundamental types already discussed, enums default to being placed on the stack but can beused automatically as objects when required.

 

It should read (changes highlighted):

 

Like the fundamental types already discussed, enums default to being placed on the stack but can be used automatically as objects when required.

 

 

Page 43, paragraph 5 reads:

 

CLI enums are different from native enums in that the names of the CLI enums values, better known as enumerators, can only be found through the scope of the enums name, and the declaring of the enumÕs data type has no meaning with a CLI enum.

 

It should read (changes highlighted):

 

CLI enums are different from native enums in that the names of the CLI enums values, better known as enumerators, can only be found through the scope of the enums name, and the declaring of the enumÕs base data type has no meaning with a CLI enum.

 

 

 

Page 45, paragraph 2 reads:

 

Listing 2-8 is a simple example of a value class called Coord3D. It is made up of three doubles, a constructor, and a Write() method. I cover constructors and overriding in Chapter 3.

 

It should read (text to be removed highlighted):

 

Listing 2-8 is a simple example of a value class called Coord3D. It is made up of three doubles, a constructor, and a Write() method. I cover constructors and overriding in Chapter 3.

 

 

Page 46, last paragraph reads:

 

There are no stack base declarations of C++/CLI arrays using subscripts, as in traditional C++. All C++/CLI arrays are references and created on the managed heap.

 

It should read (changes highlighted):

 

There are no stack based declarations of C++/CLI arrays using subscripts, as in traditional C++. All C++/CLI arrays are references and created on the managed heap.

 

 

Page 47 reads:

 

Unlike what you have seen so far when declaring data types, arrays are declared with syntax very similar to a C++/CLI templates or .NET 2.0 generic classes. Also, to declare an array requires the namespace stdcli::language:

 

using namespace stdcli::language;

 

For those coders who had to struggle with the declaration syntax of an array in the previous version of .NET (1.0 and prior), the new syntax should seem like a breath of fresh air, as I believe is a little easier to work with do to three aspects of the declaration:

 

É

 

To create an instance of the array, use the constructor initialization format. Also, because you are allocating the array to the managed heap, the gcnew operator is required. Therefore, to create an array of five ints and an array of seven Strings would require the following statements:

 

using namespace stdcli::language;

 

array<int>^ fiveInts = gcnew array<int>(5);

array<String^>^ sevenStrings = gcnew array<String^>(7);

 

It should read (changes highlighted):

 

Unlike what you have seen so far when declaring data types, arrays are declared with syntax very similar to a C++/CLI templates or .NET 2.0 generic classes. Also, to declare an array requires the namespace stdcli::language:

 

using namespace stdcli::language;

 

For those coders who had to struggle with the declaration syntax of an array in the previous version of .NET (1.1 and prior), the new syntax should seem like a breath of fresh air, and I believe is a little easier to work with do to three aspects of the declaration:

 

É

 

To create an instance of the array, use the constructor initialization format. Also, because you are allocating the array to the managed heap, the gcnew operator is required. Therefore, to create an array of five ints and an array of seven Strings would require the following statements:

 

using namespace stdcli::language;

 

array<int>^ fiveInts = gcnew array<int>(5);

array<String^>^ sevenStrings = gcnew array<String^>(7);

 

 

Page 47, Code snippet after the second Unsafe code block read:

 

class CLASS {};

array<CLASS*>^ pClass = gcnew array<CLASS*>(5);

for (int i = 0; i < pClass->Length; i++)

    pClass[i] = new CLASS();

...

for (int i = 0; i < pClass->Length; i++)

    delete pClass[i];

 

It should read (changes highlighted):

 

class CLASS {};

array<CLASS*>^ hClass = gcnew array<CLASS*>(5);

for (int i = 0; i < hClass->Length; i++)

    hClass[i] = new CLASS();

...

for (int i = 0; i < hClass->Length; i++)

    delete hClass[i];

 

 

 

Page 48, first code snippet reads:

 

using namespace stdcli::language;

 

array<int, 1>^ Ints_5 = gcnew array<int>(5);

array<int, 2>^ Ints_5x3 = gcnew array<int>(5, 3);

array<int, 3>^ Ints_5x3x2 = gcnew array<int>(5, 3, 2);

 

It should read (text to be removed highlighted):

 

using namespace stdcli::language;

 

array<int, 1>^ Ints_5 = gcnew array<int>(5);

array<int, 2>^ Ints_5x3 = gcnew array<int>(5, 3);

array<int, 3>^ Ints_5x3x2 = gcnew array<int>(5, 3, 2);

 

 

Page 48, middle code snippet reads:

 

array< array<int>^ >^ jagged = gcnew array< array<int>^ >(4);

for (int i = 0; i < jagged->Length; i++)

{

    e[i] = gcnew array<int>((i+1) * 5); // each row 5 bigger

}

 

It should read (changes highlighted):

 

array< array<int>^ >^ jagged = gcnew array< array<int>^ >(4);

for (int i = 0; i < jagged->Length; i++)

{

    jagged[i] = gcnew array<int>((i+1) * 5); // each row 5 bigger

}

 

 

Pages 52, 61, 75, 80,  Assorted instances

 

Change all references of ÔInt32Õ on these pages to int

 

Page 59 second last line on listing 2-12 reads:

 

Console::WriteLine ( e ); // displays the letter 'e'

 

It should read (changes highlighted):

 

Console::WriteLine ( e ); // displays the letter 'E'

 

 

 

 

 

 

Pages 63 and continues on 64 reads: (Careful with this one. This error is from the first book)

 

The bitwise AND operator compares the bit pattern of its two operands. If both the bits at the same offset in the bit pattern are 1s, then the resulting bit pattern will become a 1; otherwise, it will become a 0. For example:

 

0101 & 0011 becomes 0001

 

The bitwise OR operator compares the bit pattern of its two operands. If either or both the bits at the same offset in the bit pattern are 1s, then the resulting bit pattern will become a 1; otherwise, it will become a 0. For example:

 

0101 & 0011 becomes 0111

 

The bitwise XOR operator compares the bit pattern of its two operands. If either, but not both, of the bits at the same offset in the bit pattern is a 1, then the resulting bit pattern will become a 1; otherwise, it will become a 0. For example:

 

0101 & 0011 becomes 0110

 

The ones complement operator simply flips the bits. If it was a 1, then it becomes a 0, and vice versa:

0101 becomes 1010

 

It should read (changes highlighted):

 

The bitwise AND operator compares the bit pattern of its two operands. If both the bits at the same offset in the bit pattern are 1s, then the resulting bit pattern will become a 1; otherwise, it will become a 0. For example:

 

0101 & 0011 becomes 0001

 

The bitwise OR operator compares the bit pattern of its two operands. If either or both the bits at the same offset in the bit pattern are 1s, then the resulting bit pattern will become a 1; otherwise, it will become a 0. For example:

 

0101 | 0011 becomes 0111

 

The bitwise XOR operator compares the bit pattern of its two operands. If either, but not both, of the bits at the same offset in the bit pattern is a 1, then the resulting bit pattern will become a 1; otherwise, it will become a 0. For example:

 

0101 ^ 0011 becomes 0110

 

The ones complement operator simply flips the bits. If it was a 1, then it becomes a 0, and vice versa:

~0101 becomes 1010

 

 

Page 75, paragraph one reads:

 

It means you canÕt add or remove elements to or from the collection. This is not an issue for arrays, given that this is not allowed anyway, but for many other collection types it may be a problem. The worst thing is if the compiler doesn't catch it. It is the CLR that lets you know about it by throwing an exception.

 

It should read (changes highlighted):

 

It means you canÕt add or remove elements to or from the collection. This is not an issue for arrays, given that this is not allowed anyway, but for many other collection types it may be a problem. The worst thing is that the compiler doesn't catch it. It is the CLR that lets you know about it by throwing an exception.

 

 

Page 76, paragraph 4 reads:

 

The parameter-list is a comma-separated list of variable declarations that define the variable, which will be passed to the function when it starts executing. Parameter variables can be any value types, references, handles, or pointers, even ones that are user defined.

 

It should read (changes highlighted):

 

The parameter-list is a comma-separated list of variable declarations that define the variables, which will be passed to the function when it starts executing. Parameter variables can be any value types, references, handles, or pointers, even ones that are user defined.

 

 

Page 77, middle of page reads:

 

int a = 5;

int b = example(a);

the value of a will be 10.

There is a pro and a con to using references. The pro is that it is faster to pass arguments by reference, as there is no copy step involved. The con is that, unlike using handlers, other than %, there is no difference between passing by value or reference. There is a very real possibility that changes can happen to argument variables within a function without the programmer knowing.

 

It should read (text to be removed highlighted):

 

int a = 5;

int b = example(a);

the value of a will be 10.

There is a pro and a con to using references. The pro is that it is faster to pass arguments by reference, as there is no copy step involved. The con is that, unlike using handlers, other than %, there is no difference between passing by value or reference. There is a very real possibility that changes can happen to argument variables within a function without the programmer knowing.

 

 

Page 90, Private Public and Protected..., end of paragraph 1 reads:

 

Most people who code C++ use the keywords ref class when they create objects, and ref struct is very seldom if ever used.

 

It should read (changes highlighted):

 

Most people who code C++/CLI use the keywords ref class when they create objects, and ref struct is very seldom if ever used.

 

 

Page 92, last paragraph reads:

 

If you have come from the traditional C++ world, you may have noticed the new keyword ref in front of the classÕs definition. This is one of the biggest and most important changes between traditional C++ and C++/CLI. (It is also a big change from C++/CLI and Managed Extensions for C++, as the keyword was __gc.)

 

It should read (text to be removed highlighted):

 

If you have come from the traditional C++ world, you may have noticed the new keyword ref in front of the classÕs definition. This is one of the biggest and most important changes between traditional C++ and C++/CLI. (It is also a big change for C++/CLI and Managed Extensions for C++, as the keyword was __gc.)

 

 

Page 97, last paragraph reads:

 

This fancy name is simply C++/CLIÕs way of reminding programmers that ref classes are objects. Member variables are simply variables defined within the definition of a ref class.

 

It should read (changes highlighted):

 

This fancy name is simply C++/CLIÕs way of reminding programmers that ref classes are object definitions. Member variables are simply variables defined within the definition of a ref class.

 

 

Page 98, 1st paragraph after Unsafe Code block reads:

 

Member variables can be public, protected, or private. With C++/CLI and ref classes, public member variables should be handled with care, especially if invalid values in these variables will cause problems in the programÕs execution.

 

It should read (changes highlighted):

 

Member variables can be public, protected, or private. With C++/CLI, a ref classÕs public member variables should be handled with care, especially if invalid values in these variables will cause problems in the programÕs execution.

 

 

 

Page 119, Scalar Properties, Paragraph 3 reads:

 

You can make a property write-only by excluding the set method in the propertyÕs declaration:

property type PropertyName

{

    type get() {};

}

Conversely, you can make the property read-only by excluding the get method:

property type PropertyName

{

    void set (type value) {};

}

The get() method gives you full access to the property to do as you please. The most common thing you will do is validate the parameter and then assign it to a private member variable.

The only real catch you might encounter is that the property name cannot be the same as a member variable. A conversion I use, which is by no means a standard, is to use a lowercase letter as the first letter of the member variable and an uppercase as the first letter of the property name.

With the addition of a set method, you are now free to put any calculation you want within the method, but it must return the type specified. For this type of property, the most common body of the method is a simple return of the member variable storage of the property.

 

It should read (changes highlighted):

 

You can make a property write-only by excluding the get() method in the propertyÕs declaration:

property type PropertyName

{

    void set(type value) {};

}

Conversely, you can make the property read-only by excluding the set() method:

property type PropertyName

{

    type get() {};

}

The set() method gives you full access to the property to do as you please. The most common thing you will do is validate the parameter and then assign it to a private member variable.

The only real catch you might encounter is that the property name cannot be the same as a member variable. A convention I use, which is by no means a standard, is to use a lowercase letter as the first letter of the member variable and an uppercase as the first letter of the property name.

With the addition of a get() method, you are now free to put any calculation you want within the method, but it must return the type specified. For this type of property, the most common body of the method is a simple return of the member variable storage of the property.

 

 

Page 127, listing 3-13 reads:

 

    property String^ default [int]

    {

        String^ get(int index)

        {

            if (index < 0)

                index = 0;

            else if (index > defaultArray->Length)

                index = defaultArray->Length - 1;

 

            return defaultArray[index];

        }

    }

private:

     array<String^>^ defaultArray;

};

 

void main()

{

    Numbers numbers;

 

    Console::WriteLine(numbers[-1]);

    Console::WriteLine(numbers[3]);

    Console::WriteLine(numbers[10]);

}

 

It should read (changes highlighted):

 

    property String^ default [int]

    {

        String^ get(int index)

        {

            if (index < 0)

                index = 0;

            else if (index > defaultArray->Length - 1)

                index = defaultArray->Length - 1;

 

            return defaultArray[index];

        }

    }

private:

     array<String^>^ defaultArray;

};

 

void main()

{

    Numbers numbers;

 

    Console::WriteLine(numbers[-1]);

    Console::WriteLine(numbers[3]);

    Console::WriteLine(numbers[6]);

}

 

 

 

Page 128, listing 3-14 reads:

 

public:

    ref class NestedClass // Declaration of the nested class

    {

    public:

        int publicMember;

    protected:

        int protectedMember;

    private:

        int privateMember;

    };

    NestedClass^ protectedNC; // protected variable reference to NestedClass

private:

    NestedClass^ privateNC; // private variable reference to NestedClass

 

It should read (changes highlighted):

 

public:

    ref class NestedClass // Declaration of the nested class

    {

    public:

        int publicMember;

    protected:

        int protectedMember;

    private:

        int privateMember;

    };

 

protected:

    NestedClass^ protectedNC; // protected variable reference to NestedClass

 

private:

    NestedClass^ privateNC; // private variable reference to NestedClass

 

 

 

Page 167, paragraph before Listing 4-10 reads:

 

Listing 4-10 shows a simple example of an exception. I noted in Chapter 3 that the safe_cast operator throws a System::InvalidCastException when it is unable to convert from one try to another.

 

It should read (changes highlighted):

 

Listing 4-10 shows a simple example of an exception. I noted in Chapter 3 that the safe_cast operator throws a System::InvalidCastException when it is unable to convert from one type to another.

 

 

Page 170, 1st code snippet reads:

 

try

{

    // Methods that throw OutOfMemoryException

}

catch (OutOfMemoryException *oome) // If a method throws an exception

{                                  // Execution will continue here

    // Process exception

}

 

It should read (changes highlighted):

 

try

{

    // Methods that throw OutOfMemoryException

}

catch (OutOfMemoryException ^oome) // If a method throws an exception

{                                  // Execution will continue here

    // Process exception

}

 

 

\ No newline at end of file diff --git a/9781590596401.jpg b/9781590596401.jpg new file mode 100644 index 0000000..b8b44a1 Binary files /dev/null and b/9781590596401.jpg differ diff --git a/Chapter02/Arrays.cpp b/Chapter02/Arrays.cpp new file mode 100644 index 0000000..eccc639 --- /dev/null +++ b/Chapter02/Arrays.cpp @@ -0,0 +1,76 @@ +using namespace System; + +// Arrays in Action +void main() +{ + // Single dimension + array^ a = gcnew array(4); + array^ b = gcnew array(4); + + for (int i = 0; i < a->Length; i++) + { + a[i] = i; + } + + for (int i = 0; i < b->Length; i++) + { + b[i] = a[i].ToString(); + } + + for (int i = 0; i < b->Length; i++) + { + Console::WriteLine(b[i]); + } + + Console::WriteLine(); + Array::Reverse(b); + for (int i = 0; i < b->Length; i++) + { + Console::WriteLine(b[i]); + } + + // Multi dimension uniform + array^ c = gcnew array(4,3); + array^ d = gcnew array(4,3); + + for (int x = 0; x < c->GetLength(0); x++) + { + for (int y = 0; y < c->GetLength(1); y++) + { + c[x,y] = (x*10)+y; + } + } + + Console::WriteLine(); + for (int x = 0; x < d->GetLength(0); x++) + { + for (int y = 0; y < d->GetLength(1); y++) + { + Console::Write("{0,-5:00}", c[x,y]); + } + Console::WriteLine(); + } + + // Multi dimension jagged + array< array^ >^ e = gcnew array^>(4); + + for (int x = 0; x < e->Length; x++) + { + e[x] = gcnew array(4+(x*2)); // each row 2 bigger + for(int y = 0; y < e[x]->Length; y++) + { + e[x][y] = (x*10)+y; + } + } + + Console::WriteLine(); + + for (int x = 0; x < e->Length; x++) + { + for (int y = 0; y < e[x]->Length; y++) + { + Console::Write("{0,-5:00}", e[x][y]); + } + Console::WriteLine(); + } +} diff --git a/Chapter02/Boolean.cpp b/Chapter02/Boolean.cpp new file mode 100644 index 0000000..9e59c3a --- /dev/null +++ b/Chapter02/Boolean.cpp @@ -0,0 +1,15 @@ +using namespace System; + +// Boolean Fundamental Type in Action +void main() +{ + bool a = 18757; // will give a warning but set to true + bool b = 0; // false + bool c = true; // obviously true + bool d = false; // obviously false + + Console::WriteLine( a ); + Console::WriteLine( b ); + Console::WriteLine( c ); + Console::WriteLine( d ); +} diff --git a/Chapter02/BooleanLiteral.cpp b/Chapter02/BooleanLiteral.cpp new file mode 100644 index 0000000..e9d8cea --- /dev/null +++ b/Chapter02/BooleanLiteral.cpp @@ -0,0 +1,15 @@ +using namespace System; + +// Boolean Literals in Action +void main() +{ + bool isTrue = true; + bool isFalse = false; + + Console::WriteLine ( isTrue ); + Console::WriteLine ( isFalse ); + + // This is kind of neat. Boolean literals are objects too! + Console::WriteLine ( true.ToString () ); + Console::WriteLine ( false.ToString () ); +} diff --git a/Chapter02/Boxing.cpp b/Chapter02/Boxing.cpp new file mode 100644 index 0000000..1eab786 --- /dev/null +++ b/Chapter02/Boxing.cpp @@ -0,0 +1,32 @@ +using namespace System; + +// Boxing in Action +value class POINT +{ +public: + int x, y; + POINT(int x, int y) : x(x) , y(y) {} +}; + +void main() +{ + POINT p1(1,2); + Object ^o = p1; + POINT ^p2 = (POINT)o; + POINT ^p3 = (POINT^)o; + + Console::WriteLine("p1 x={0} y={1}\n", p1.x, p1.y); + Console::WriteLine("o x={0} y={1}\n", ((POINT)o).x, ((POINT)o).y); + Console::WriteLine("p2 x={0} y={1}\n", p2->x, p2->y); + Console::WriteLine("p3 x={0} y={1}\n", p3->x, p3->y); + + Console::WriteLine("-------"); + + p3->x = 3; + p3->y = 4; + + Console::WriteLine("p1 x={0} y={1}\n", p1.x, p1.y); + Console::WriteLine("o x={0} y={1}\n", ((POINT)o).x, ((POINT)o).y); + Console::WriteLine("p2 x={0} y={1}\n", p2->x, p2->y); + Console::WriteLine("p3 x={0} y={1}\n", p3->x, p3->y); +} \ No newline at end of file diff --git a/Chapter02/BuildAll.bat b/Chapter02/BuildAll.bat new file mode 100644 index 0000000..3bb4314 --- /dev/null +++ b/Chapter02/BuildAll.bat @@ -0,0 +1,18 @@ +cl Arrays.cpp /clr:safe +cl Boolean.cpp /clr:safe +cl BooleanLiteral.cpp /clr:safe +cl Boxing.cpp /clr:safe +cl CharLiteral.cpp /clr:safe +cl Chars.cpp /clr:safe +cl Decimal.cpp /clr:safe +cl Enums.cpp /clr:safe +cl FloatingPoint.cpp /clr:safe +cl Hello.cpp /clr:safe +cl IntegerLiteral.cpp /clr:safe +cl IntegerTypes.cpp /clr:safe +cl MainArgsNew.cpp /clr:safe +cl MainArgsTrad.cpp /clr:pure +cl ReferenceIndirect.cpp /clr:pure +cl StringFun.cpp /clr:safe +cl StringLiteral.cpp /clr:safe +cl ValueClass.cpp /clr:safe diff --git a/Chapter02/CharLiteral.cpp b/Chapter02/CharLiteral.cpp new file mode 100644 index 0000000..31a2ef4 --- /dev/null +++ b/Chapter02/CharLiteral.cpp @@ -0,0 +1,21 @@ +using namespace System; + +// Character Literals in Action +void main() +{ + char a = 'a'; // character 'a' + Char b = L'b'; // Unicode 'b' + + char t = '\t'; // tab escape + Char s = L'\\'; // Unicode backslash escape + + char d = '\45'; // octal escape + Char e = L'\x0045'; // Unicode hexadecimal escape + + Console::WriteLine ( a ); // displays numeric equiv of 'A' + Console::WriteLine ( b ); // displays the letter 'b' + Console::WriteLine ( t ); // displays numeric equiv of tab + Console::WriteLine ( s ); // displays backslash + Console::WriteLine ( d ); // displays decimal equiv of octal 45 + Console::WriteLine ( e ); // displays the letter 'e' +} diff --git a/Chapter02/Chars.cpp b/Chapter02/Chars.cpp new file mode 100644 index 0000000..7beba5e --- /dev/null +++ b/Chapter02/Chars.cpp @@ -0,0 +1,12 @@ +using namespace System; + +// Character Fundamental Type in Action +void main() +{ + Char a = L'A'; // character literal 'A' + Char b = L'\x0041'; // hex notation for hex 41 which happens to be 'A' + + Console::WriteLine ( a ); + Console::WriteLine ( b ); //Even though I put hex 41 in b, the ASCII 'A' + //is printed due to b being a Char +} diff --git a/Chapter02/Decimal.cpp b/Chapter02/Decimal.cpp new file mode 100644 index 0000000..38212e0 --- /dev/null +++ b/Chapter02/Decimal.cpp @@ -0,0 +1,39 @@ +using namespace System; + +// Decimal Fundamental Type in Action +void main() +{ + Decimal w = System::Convert::ToDecimal("123456789012345678901.2345678"); + Console::WriteLine( w ); + + Decimal x = (Decimal)0.1234567890123456789012345678; // will get truncated + Decimal y = (Decimal)0.0000000000000000789012345678; // works fine + + Console::WriteLine( x ); + Console::WriteLine( y ); + + // Decimal constructor + Decimal z(0xeb1f0ad2, 0xab54a98c, 0, false, 0); // = 12345678901234567890 + Console::WriteLine( z ); + + // Create a 28 significate digit number + Decimal a = (Decimal)123456789012345000000.00000000; + Decimal b = (Decimal)678901.23456780; + Decimal c = -(a + b); + + Console::WriteLine( c ); // display pre broken Decimal + + // Break it up into 4 parts + array^ d = Decimal::GetBits(c); + + // Reassemble using Decimal constructor + Decimal e(d[0], d[1], d[2], // digits + ((d[3] & 0x80000000) == 0x80000000), // sign + ((d[3] >> 16) & 0xff) ); // decimal location + + Console::WriteLine( d[0] ); // display part 1 + Console::WriteLine( d[1] ); // display part 2 + Console::WriteLine( d[2] ); // display part 3 + Console::WriteLine( d[3].ToString("X") ); // display part 4 + Console::WriteLine( e ); // display reassembled Decimal +} diff --git a/Chapter02/Enums.cpp b/Chapter02/Enums.cpp new file mode 100644 index 0000000..5746626 --- /dev/null +++ b/Chapter02/Enums.cpp @@ -0,0 +1,26 @@ +using namespace System; + +enum class PrimeColors { Red, Blue, Yellow }; + +// Enum Type in Action +void main() +{ + PrimeColors color; + + color = PrimeColors::Blue; + + switch (color) + { + case PrimeColors::Red : + Console::WriteLine("Red"); + break; + case PrimeColors::Blue : + Console::WriteLine("Blue"); + break; + case PrimeColors::Yellow : + Console::WriteLine("Yellow"); + break; + } + + Console::WriteLine(color.ToString()); +} diff --git a/Chapter02/FloatingPoint.cpp b/Chapter02/FloatingPoint.cpp new file mode 100644 index 0000000..543c672 --- /dev/null +++ b/Chapter02/FloatingPoint.cpp @@ -0,0 +1,15 @@ +using namespace System; + +// Floating-point Fundamental Types in Action +void main() +{ + float w = 123.456f; // standard decimal notation + float x = 7890e3f; // exponent notation + double y = 34525425432525764765.76476476547654; // too big will truncate + double z = 123456789012345e-300; // exponent will be reset + + Console::WriteLine( w ); // Write out Single + Console::WriteLine( x ); // Write out Single with more zeros + Console::WriteLine( y ); // Write out Double truncated + Console::WriteLine( z ); // Write out Double shift back decimal +} diff --git a/Chapter02/Hello.cpp b/Chapter02/Hello.cpp new file mode 100644 index 0000000..1251f0e --- /dev/null +++ b/Chapter02/Hello.cpp @@ -0,0 +1,7 @@ +using namespace System; + +// The Obligatory Hello World! +void main(void) +{ + Console::WriteLine("Hello C++/CLI World"); +} \ No newline at end of file diff --git a/Chapter02/IntegerLiteral.cpp b/Chapter02/IntegerLiteral.cpp new file mode 100644 index 0000000..69daeba --- /dev/null +++ b/Chapter02/IntegerLiteral.cpp @@ -0,0 +1,15 @@ +using namespace System; + +// Integer Literals in Action +void main() +{ + Console::WriteLine ( 010 ); // An Octal 10 is a base-10 8 + Console::WriteLine ( -010 ); // Negative Octal 10 is a base-10 -8 + + Console::WriteLine ( 0x10 ); // A Hex 10 is a base-10 16 + Console::WriteLine ( -0x10 ); // Negative Hex 10 is a base-10 -16 + + // This is kind of neat. Number literals are objects too! + Console::WriteLine ( (1234567890).ToString() ); + Console::WriteLine ( (0xABCDEF).ToString("X") ); +} diff --git a/Chapter02/IntegerTypes.cpp b/Chapter02/IntegerTypes.cpp new file mode 100644 index 0000000..524b090 --- /dev/null +++ b/Chapter02/IntegerTypes.cpp @@ -0,0 +1,18 @@ +using namespace System; + +// Integer Fundamental Types in Action +void main() +{ + char v = 'F'; // Intialize using charater literal + short w(123); // Intializing using Functional Notation + int x = 456789; // Decimal literal assigned + long y = 987654321l; // long integer literal assigned + Int64 z = 0xFEDCBA9876543210; // Hex literal assigned + + Console::WriteLine( v ); // Write out a char + Console::WriteLine( w ); // Write out a short + Console::WriteLine( x ); // Write out a int + Console::WriteLine( y ); // Write out a long + Console::WriteLine( z ); // Write out a Int64 + Console::WriteLine( z.ToString("x") ); // Write out a Int64 in Hex +} diff --git a/Chapter02/MainArgsNew.cpp b/Chapter02/MainArgsNew.cpp new file mode 100644 index 0000000..806569d --- /dev/null +++ b/Chapter02/MainArgsNew.cpp @@ -0,0 +1,14 @@ +using namespace System; + +// Passing parameters to main() new method +int main(array ^args) +{ + Console::WriteLine(args->Length); + + for each (String^ s in args) + { + Console::WriteLine(s); + } + return 0; +} + diff --git a/Chapter02/MainArgsTrad.cpp b/Chapter02/MainArgsTrad.cpp new file mode 100644 index 0000000..7e1a476 --- /dev/null +++ b/Chapter02/MainArgsTrad.cpp @@ -0,0 +1,12 @@ +using namespace System; + +// Passing parameters to main() +int main ( int argc, char *argv[] ) +{ + Console::WriteLine ( argc.ToString() ); + for (int i = 0; i < argc; i++) + { + Console::WriteLine ( gcnew String(argv[i]) ); + } + return 0; +} diff --git a/Chapter02/ReferenceIndirect.cpp b/Chapter02/ReferenceIndirect.cpp new file mode 100644 index 0000000..f5395f1 --- /dev/null +++ b/Chapter02/ReferenceIndirect.cpp @@ -0,0 +1,38 @@ +using namespace System; + +ref class RefClass +{ +public: + int X; + + RefClass(int x) + { + X = x; + } +}; + +// Reference and Indirection in Action +void main() +{ + RefClass rc(10); + RefClass ^o; + + o = %rc; // place a reference of rc in the handle o + Console::WriteLine(o->X); // print out object. This should contain 10. + + rc.X = 20; // place 50 at the address y points to + Console::WriteLine(o->X); // print out object. This should contain 20. + + int %i = rc.X; // assign rc.X to a reference + + i = 30; // change value of reference + Console::WriteLine(o->X); // print out object. This should contain 30. + + Console::WriteLine(); + + int ^y = gcnew int(100); // create a handle to an int + Console::WriteLine(y); // print out int. + + *y = 110; // Assign new value to dereferenced int + Console::WriteLine(*y); // print out dereferenced int. +} diff --git a/Chapter02/StringFun.cpp b/Chapter02/StringFun.cpp new file mode 100644 index 0000000..e84755f --- /dev/null +++ b/Chapter02/StringFun.cpp @@ -0,0 +1,29 @@ +using namespace System; + +// String Type in Action +void main() +{ + // Create some strings + String^ s1 = "This will "; + String^ s2 = "be a "; + String^ s3 = "String"; + Console::WriteLine(String::Concat(s1, s2, s3)); + + // Create a copy, then concatenate new text + String^ s4 = s2; + s4 = String::Concat(s4, "new "); + Console::WriteLine(String::Concat(s1, s4, s3)); + + // Replace stuff in a concatenated string + String^ s5 = String::Concat(s1, s2, s3)->Replace("i", "*"); + Console::WriteLine(s5); + + // Insert into a string + String^ s6 = s3->Insert(3, "ange Str"); + Console::WriteLine(String::Concat(s1, s2, s6)); + + // Remove text from strings + s1 = s1->Remove(4, 5); // remove ' will' from middle + s2 = s2->Remove(0, 3); // remove 'be ' from start + Console::WriteLine(String::Concat(s1, "is ", s2, s3)); +} diff --git a/Chapter02/StringLiteral.cpp b/Chapter02/StringLiteral.cpp new file mode 100644 index 0000000..8f54540 --- /dev/null +++ b/Chapter02/StringLiteral.cpp @@ -0,0 +1,11 @@ +using namespace System; + +// String Literals in Action +void main() +{ + String^ a = "Managed String"; + String^ b = L"Unicode String"; + + Console::WriteLine(a); + Console::WriteLine(b); +} diff --git a/Chapter02/ValueClass.cpp b/Chapter02/ValueClass.cpp new file mode 100644 index 0000000..240d9f2 --- /dev/null +++ b/Chapter02/ValueClass.cpp @@ -0,0 +1,39 @@ +using namespace System; + +// Value class in Action +value class Coord3D +{ +public: + double x; + double y; + double z; + + Coord3D (double x, double y, double z) + { + this->x = x; + this->y = y; + this->z = z; + } + + String^ Write() + { + return String::Format("{0},{1},{2}", x, y, z); + } +}; + +void main() +{ + Coord3D coordA; + Coord3D coordB(1,2,3); + + coordA = coordB; // Assign is simply an = + + coordA.x += 5.5; // Operations work just like usual + coordA.y *= 2.7; + coordA.z /= 1.3; + + Console::WriteLine(coordB.Write()); + Console::WriteLine(coordA.x); + Console::WriteLine(coordA.y); + Console::WriteLine(coordA.z); +} diff --git a/Chapter03/AbstractEx.cpp b/Chapter03/AbstractEx.cpp new file mode 100644 index 0000000..9dd2511 --- /dev/null +++ b/Chapter03/AbstractEx.cpp @@ -0,0 +1,57 @@ +using namespace System; + + ref class AbstractExClass abstract +{ +protected: + int AbstractVar; + AbstractExClass(int val): AbstractVar(val) {} +public: + virtual void Method1() = 0; // unimplemented method + virtual void Method2() = 0; // unimplemented method + void Method3() + { + Console::WriteLine(AbstractVar.ToString()); + } +}; + +ref class MidAbstractExClass abstract : public AbstractExClass +{ +public: + virtual void Method1() override sealed + { + Console::WriteLine((AbstractVar * 3).ToString()); + } +protected: + MidAbstractExClass(int val) : AbstractExClass(val) {} +}; + +ref class DerivedExClass : public MidAbstractExClass +{ +public: + DerivedExClass(int val) : MidAbstractExClass(val) {} + virtual void Method2() override + { + Console::WriteLine((AbstractVar * 2).ToString()); + } +}; + +void testMethod(AbstractExClass ^aec) +{ + aec->Method1(); + aec->Method2(); + aec->Method3(); +} + +void main() +{ + AbstractExClass ^Ab1 = gcnew DerivedExClass(5); + Ab1->Method1(); + Ab1->Method2(); + Ab1->Method3(); + + AbstractExClass ^Ab2 = gcnew DerivedExClass(6); + testMethod(Ab2); + + DerivedExClass ^dc = gcnew DerivedExClass(7); + testMethod(dc); +} diff --git a/Chapter03/ArrayProp.cpp b/Chapter03/ArrayProp.cpp new file mode 100644 index 0000000..934cd22 --- /dev/null +++ b/Chapter03/ArrayProp.cpp @@ -0,0 +1,36 @@ +using namespace System; + +ref class ArrayProp +{ +public: + ArrayProp(int size) + { + numArray = gcnew array(size); + } + + property array^ NumArray + { + array^ get() + { + return numArray; + } + + void set ( array^ value ) + { + numArray = value; + } + } +private: + array^ numArray; +}; + +void main() +{ + ArrayProp aprop(5); + + for ( int i = 0 ; i < aprop.NumArray->Length ; ++i ) + aprop.NumArray[i] = i; + + for each (int i in aprop.NumArray) + Console::WriteLine(i); +} diff --git a/Chapter03/BuildAll.bat b/Chapter03/BuildAll.bat new file mode 100644 index 0000000..62cb412 --- /dev/null +++ b/Chapter03/BuildAll.bat @@ -0,0 +1,17 @@ +cl AbstractEx.cpp /clr:safe +cl ArrayProp.cpp /clr:safe +cl Casting.cpp /clr +cl Constructors.cpp /clr:safe +cl DefIndexProps.cpp /clr:safe +cl IndexProps.cpp /clr:safe +cl Inherit.cpp /clr:safe +cl InterfaceEx.cpp /clr:safe +cl MethodEx.cpp /clr:safe +cl NestedClass.cpp /clr:safe +cl OperatorOverload.cpp /clr:safe +cl OperatorOverloadMixed.cpp /clr:safe +cl ScalarProp.cpp /clr:safe +cl StackReferences.cpp /clr:safe +cl StaticMethodEx.cpp /clr:safe +cl StaticProp.cpp /clr:safe +cl VirtualAnimals.cpp /clr:safe diff --git a/Chapter03/Casting.cpp b/Chapter03/Casting.cpp new file mode 100644 index 0000000..22212a9 --- /dev/null +++ b/Chapter03/Casting.cpp @@ -0,0 +1,33 @@ +using namespace System; + +ref class A {}; +ref class B : public A {}; +ref class C {}; + +void main() +{ + Object ^v1 = gcnew A(); + Object ^v2 = gcnew B(); + Object ^v3 = gcnew C(); + + A ^a1 = gcnew A(); + A ^a2 = gcnew B(); + A ^a3 = dynamic_cast(v1); // downcast + A ^a4 = dynamic_cast(v2); // downcast + A ^a5 = static_cast(v3); // a5 has invalid value of type C class + + B ^b1 = gcnew B(); + B ^b2 = dynamic_cast(v2); // downcast + B ^b3 = dynamic_cast(v3); // Fails b3 = null. Miss match classes + B ^b4 = dynamic_cast(a2); // downcast + + C ^c1 = gcnew C(); + C ^c2 = dynamic_cast(v1); // Fails c2 = null. Miss match classes + C ^c3 = static_cast(v2); // c3 has invalid value of type B class + C ^c4 = safe_cast(v3); // downcast + + C ^c5 = (C^)(v3); // downcast + +// B ^e1 = safe_cast(c1); // does not compile as compiler knows these + // are unrelated handles. +} \ No newline at end of file diff --git a/Chapter03/Constructors.cpp b/Chapter03/Constructors.cpp new file mode 100644 index 0000000..6d23ee0 --- /dev/null +++ b/Chapter03/Constructors.cpp @@ -0,0 +1,53 @@ +using namespace System; + +// Parent Class +ref class ParentClass +{ +public: + // Default constructor that initializes ParentVal to a default value + ParentClass() : PVal(10) {} + + // A constructor that initializes ParentVal to a passed value + ParentClass(int inVal) : PVal(inVal) {} + + // Copy Constructor + ParentClass(const ParentClass %p) : PVal(p.PVal) {} + + int PVal; +}; + +// --------------------------------------------------------------- + +// Child class that inherits form ParentClass +ref class ChildClass : public ParentClass +{ +public: + // Default constructor that initializes ChildVal to a default value + ChildClass () : CVal(20) {}; // default constructor + + // A constructor that initialized the parent class with a passed value + // and initializes ChildVal to a another passed value + ChildClass (int inVal1, int inVal2) : ParentClass(inVal1), CVal(inVal2) {} + + ChildClass(const ChildClass %vals) : ParentClass(vals.PVal), CVal(vals.CVal) {} + + int CVal; +}; + +void main() +{ + ParentClass p1(4); // Constructor + ParentClass p2 = p1; // Copy Constructor + + p1.PVal = 2; // Change original, new unchanged + + Console::WriteLine("p1.PVal=[{0}] p2.PVal=[{1}]", p1.PVal, p2.PVal); + + ChildClass ^c1 = gcnew ChildClass(5,6); // Constructor + ChildClass c2 = *c1; // Copy Constructor + + c1->CVal = 12; // Change original, new unchanged + + Console::WriteLine("c1=[{0}/{1}] c2=[{2}/{3}]", + c1->PVal, c1->CVal, c2.PVal, c2.CVal); +} diff --git a/Chapter03/DefIndexProps.cpp b/Chapter03/DefIndexProps.cpp new file mode 100644 index 0000000..3e61bb3 --- /dev/null +++ b/Chapter03/DefIndexProps.cpp @@ -0,0 +1,37 @@ +using namespace System; + +ref class Numbers +{ +public: + Numbers() + { + defaultArray = gcnew array + { + "zero", "one", "two", "three", "four", "five" + }; + } + + property String^ default [int] + { + String^ get(int index) + { + if (index < 0) + index = 0; + else if (index > defaultArray->Length) + index = defaultArray->Length - 1; + + return defaultArray[index]; + } + } +private: + array^ defaultArray; +}; + +void main() +{ + Numbers numbers; + + Console::WriteLine(numbers[-1]); + Console::WriteLine(numbers[3]); + Console::WriteLine(numbers[10]); +} \ No newline at end of file diff --git a/Chapter03/IndexProps.cpp b/Chapter03/IndexProps.cpp new file mode 100644 index 0000000..1a0a6a1 --- /dev/null +++ b/Chapter03/IndexProps.cpp @@ -0,0 +1,65 @@ +using namespace System; + +ref class Student +{ +public: + Student(String^ s, int g) + { + Name = s; + Grade = g; + } + + property String^ Name; + property int Grade; +}; + +ref class Course +{ + ref struct StuList + { + Student ^stu; + StuList ^next; + }; + StuList ^Stu; + static StuList ^ReportCards = nullptr; + +public: + property Student^ ReportCard [String^] + { + Student^ get(String^ n) + { + for(Stu = ReportCards; Stu && (Stu->stu->Name != n); Stu = Stu->next) + ; + if (Stu != nullptr) + return Stu->stu; + else + return gcnew Student("",0); // empty student + } + + void set(String^ n, Student^ s) + { + for(Stu = ReportCards; Stu && (Stu->stu->Name != n); Stu = Stu->next) + ; + if (Stu == nullptr) + { + StuList ^stuList = gcnew StuList; + stuList->stu = s; + stuList->next = ReportCards; + ReportCards = stuList; + } + } + } +}; + +void main() +{ + Course EnglishLit; + Student Stephen("Stephen", 95); // student as stack variable + Student ^Sarah = gcnew Student("Sarah", 98); // student as heap variable + + EnglishLit.ReportCard[ "Stephen" ] = %Stephen; // index as String literal + EnglishLit.ReportCard[ Sarah->Name ] = Sarah; // index as String^ + + Console::WriteLine(EnglishLit.ReportCard[ Stephen.Name ]->Grade); + Console::WriteLine(EnglishLit.ReportCard[ "Sarah" ]->Grade); +} \ No newline at end of file diff --git a/Chapter03/Inherit.cpp b/Chapter03/Inherit.cpp new file mode 100644 index 0000000..d1bb26b --- /dev/null +++ b/Chapter03/Inherit.cpp @@ -0,0 +1,34 @@ +using namespace System; + +/// Base class +ref class Square +{ +public: + int Area() + { + return Dims * Dims; + } + + int Dims; +}; + +/// Child class +ref class Cube : public Square +{ +public: + int Volume() + { + return Area() * Dims; + } +}; + +/// Inheritance in action +void main() +{ + Cube ^cube = gcnew Cube(); + cube->Dims = 3; + + Console::WriteLine(cube->Dims); + Console::WriteLine(cube->Area()); + Console::WriteLine(cube->Volume()); +} diff --git a/Chapter03/InterfaceEx.cpp b/Chapter03/InterfaceEx.cpp new file mode 100644 index 0000000..182ace9 --- /dev/null +++ b/Chapter03/InterfaceEx.cpp @@ -0,0 +1,75 @@ +using namespace System; + +interface class Interface1 +{ + void Method1(); + void Method2(); +}; + +interface class Interface2 +{ + void Method3(); + property String^ X; +}; + +ref class Base +{ +public: + void MethodBase() + { + Console::WriteLine("MethodBase()"); + } +}; + +ref class DerivedClass : public Base, public Interface1, public Interface2 +{ +public: + virtual property String^ X + { + String^ get() + { + return x; + } + + void set(String^ value) + { + x = value; + } + } + + virtual void Method1() + { + Console::WriteLine("Method1()"); + } + + virtual void Method2() + { + Console::WriteLine("Method2()"); + } + + virtual void Method3() + { + Console::WriteLine("Method3()"); + } + + virtual void Print() + { + MethodBase(); + Method1(); + Method2(); + Method3(); + } + +private: + String^ x; +}; + +void main() +{ + DerivedClass dc; + + dc.X = "Start'n Up"; + Console::WriteLine(dc.X); + + dc.Print(); +} diff --git a/Chapter03/MethodEx.cpp b/Chapter03/MethodEx.cpp new file mode 100644 index 0000000..678ee31 --- /dev/null +++ b/Chapter03/MethodEx.cpp @@ -0,0 +1,40 @@ +using namespace System; + +ref class MethodEx +{ +public: + void printPublic(int num) + { + for (int i = 0; i < num; i++) + { + Console::WriteLine( "Public" ); + } + printProtected(num/2); + } +protected: + void printProtected(int num) + { + for (int i = 0; i < num; i++) + { + Console::WriteLine( "Protected" ); + } + printPrivate(num/2); + } +private: + void printPrivate(int num) + { + for (int i = 0; i < num; i++) + { + Console::WriteLine( "Private" ); + } + } +}; + +int main() +{ + MethodEx ex; + + ex.printPublic(4); + // ex.printProtected(4); // Error can not access + // ex.printPrivate(4); // Error can not access +} diff --git a/Chapter03/NestedClass.cpp b/Chapter03/NestedClass.cpp new file mode 100644 index 0000000..2833084 --- /dev/null +++ b/Chapter03/NestedClass.cpp @@ -0,0 +1,74 @@ +using namespace System; + +ref class SurroundClass +{ +public: + ref class NestedClass // Declaration of the nested class + { + public: + int publicMember; + protected: + int protectedMember; + private: + int privateMember; + }; + + NestedClass^ protectedNC; // protected variable reference to NestedClass + +private: + NestedClass^ privateNC; // private variable reference to NestedClass + +public: + NestedClass^ publicNC; // public variable reference to NestedClass + + // Constructor for SurroundClass + // Notice the initializer list declaration of the reference member variable + SurroundClass() : publicNC(gcnew NestedClass), + protectedNC(gcnew NestedClass), + privateNC(gcnew NestedClass) + {} + + // A member showing how to access NestedClass within SurroundClass + // Notice only public member varibles of the nested class are accessed + // The private and protected are hidden + void method() + { + int x; + + NestedClass nc1; // Declared another reference NestedClass + + x = nc1.publicMember; // Accessing new NestedClass variable + + x = publicNC->publicMember; // Accessing public NestedClass variable + x = protectedNC->publicMember;// Accessing protected NestedClass variable + x = privateNC->publicMember; // Accessing private NestedClass variable + } +}; + +// A inhertied class showing how to access NestedClass within a member method +// Notice only public and protected NestedClass are accessed +// The private is hidden +ref class inheritSurroundClass : public SurroundClass +{ +public: + void method() + { + int x; + + NestedClass nc1; // can access because NestedClass + // declaration protected + x = nc1.publicMember; + + x = publicNC->publicMember; + x = protectedNC->publicMember; + } +}; + +// The main function shows how to access NestedClass from outside SurroundClass +// inhertance tree +// Notice only the public NestedClass reference is accessible +void main() +{ + SurroundClass sc; + int x = sc.publicNC->publicMember; +} diff --git a/Chapter03/OperatorOverload.cpp b/Chapter03/OperatorOverload.cpp new file mode 100644 index 0000000..8c5d9e3 --- /dev/null +++ b/Chapter03/OperatorOverload.cpp @@ -0,0 +1,76 @@ +using namespace System; + +ref class OpClass +{ +public: + OpClass() : i(0) {} + OpClass(int x) : i(x) {} + + // x != y + static bool operator !=(const OpClass ^lhs, const OpClass ^rhs) + { + return lhs->i != rhs->i; + } + + // x * y + static OpClass^ operator *(const OpClass ^lhs, const OpClass ^rhs) + { + OpClass^ ret = gcnew OpClass(); + ret->i = lhs->i * rhs->i; + + return ret; + } + + // x *= y + static void operator *=(OpClass ^lhs, const OpClass ^rhs) + { + lhs->i *= rhs->i; + } + + // -x + static OpClass^ operator -(const OpClass ^lhs) + { + OpClass^ ret = gcnew OpClass(); + ret->i = -(lhs->i); + + return ret; + } + + // ++x and x++ + static OpClass^ operator ++(const OpClass ^lhs) + { + OpClass^ ret = gcnew OpClass(); + ret->i = (lhs->i) + 1; + + return ret; + } + + virtual String ^ ToString() override + { + return i.ToString(); + } + +private: + int i; +}; + +void main() +{ + OpClass ^op1 = gcnew OpClass(3); + OpClass ^op2 = gcnew OpClass(5); + OpClass ^op3 = gcnew OpClass(15); + + if ( op1 * op2 != op3) + Console::WriteLine("Don't Equal"); + else + Console::WriteLine("Equal"); + + op1 *= op2; + Console::WriteLine(op1); + + Console::WriteLine(++op1); // prints 15 then increments to 16 + Console::WriteLine(op1++); // increOpClassents to 17 then prints + + Console::WriteLine(-op1); // Negation of OpClass1 + Console::WriteLine(op1); // prior Negation op left OpClass1 unchanged +} diff --git a/Chapter03/OperatorOverloadMixed.cpp b/Chapter03/OperatorOverloadMixed.cpp new file mode 100644 index 0000000..d3918f3 --- /dev/null +++ b/Chapter03/OperatorOverloadMixed.cpp @@ -0,0 +1,38 @@ +using namespace System; + +ref class Number +{ +public: + Number(int x) : i(x) {} + + static bool operator >(Number^ n, int v) // maps to operator > + { + return n->i > v; + } + static bool operator >(int v, Number^ n) // maps to operator > + { + return v > n->i; + } + + virtual String ^ ToString() override + { + return i.ToString(); + } +private: + int i; +}; + +int main() +{ + Number^ n = gcnew Number(5); + + if ( n > 6 ) + Console::WriteLine("{0} Greater than 6", n); + else + Console::WriteLine("{0} Less than or Equal 6", n); + + if ( 6 > n ) + Console::WriteLine("6 Greater than {0}", n); + else + Console::WriteLine("6 Less than or Equal {0}", n); +} diff --git a/Chapter03/ScalarProp.cpp b/Chapter03/ScalarProp.cpp new file mode 100644 index 0000000..f0b9e84 --- /dev/null +++ b/Chapter03/ScalarProp.cpp @@ -0,0 +1,81 @@ +using namespace System; + +ref class ScalarProp +{ +public: + // Constructor + ScalarProp() + { + Cost = 0.0; + number = 0; + name = "Blank Name"; + description = "Scalar Property"; + } + + // trivial property + property double Cost; + + // Read & write with validated parameter + property int Number + { + void set(int value) + { + if (value < 1) + value = 1; + else if (value > 10) + value = 10; + + number = value; + } + + int get() + { + return number; + } + } + + // Write only property + property String^ Name + { + void set(String^ value) + { + name = value; + } + } + + // Ready only property + property String ^Description + { + String^ get() + { + return String::Concat(name, " ", description); + } + } + +private: + String ^name; + String ^description; + int number; +}; + + +void main() +{ + ScalarProp sp; + + sp.Name = "The Ref Class"; + + Console::WriteLine(sp.Description); + + sp.Cost = 123.45; + Console::WriteLine(sp.Cost); + + sp.Number = 20; // Will be changed to 10 + Console::WriteLine(sp.Number); + + sp.Number = -5; // Will be changed to 1 + Console::WriteLine(sp.Number); + + sp.Number = 6; // Will not change + Console::WriteLine(sp.Number); +} \ No newline at end of file diff --git a/Chapter03/StackReferences.cpp b/Chapter03/StackReferences.cpp new file mode 100644 index 0000000..cfd2164 --- /dev/null +++ b/Chapter03/StackReferences.cpp @@ -0,0 +1,23 @@ +using namespace System; + +ref class Square +{ +public: + int Area() + { + return Dims * Dims; + } + + int Dims; +}; + +void main() +{ + Square ^sqr1 = gcnew Square(); // Handle + sqr1->Dims = 2; + Console::WriteLine( sqr1->Area() ); + + Square sqr2; // local stack instance + sqr2.Dims = 3; + Console::WriteLine( sqr2.Area() ); +} diff --git a/Chapter03/StaticMethodEx.cpp b/Chapter03/StaticMethodEx.cpp new file mode 100644 index 0000000..165dbfe --- /dev/null +++ b/Chapter03/StaticMethodEx.cpp @@ -0,0 +1,17 @@ +using namespace System; + +ref class StaticTest +{ +private: + static int x = 42; +public: + static int get_x() + { + return x; + } +}; + +void main() +{ + Console::WriteLine ( StaticTest::get_x() ); +} \ No newline at end of file diff --git a/Chapter03/StaticProp.cpp b/Chapter03/StaticProp.cpp new file mode 100644 index 0000000..6751d11 --- /dev/null +++ b/Chapter03/StaticProp.cpp @@ -0,0 +1,26 @@ +using namespace System; + +ref class StaticProp +{ + static String^ name; + +public: + property static String^ Name + { + void set(String^ value) + { + name = value; + } + String^ get() + { + return name; + } + } +}; + +int main() +{ + StaticProp::Name = "Static Property"; + + Console::WriteLine(StaticProp::Name); +} \ No newline at end of file diff --git a/Chapter03/VirtualAnimals.cpp b/Chapter03/VirtualAnimals.cpp new file mode 100644 index 0000000..4c99d9f --- /dev/null +++ b/Chapter03/VirtualAnimals.cpp @@ -0,0 +1,83 @@ +using namespace System; + +ref class Animal +{ +public: + virtual void Speak () + { + Console::WriteLine("Animal is Mysteriously Silent"); + } +}; + +ref class Dog : public Animal +{ +public: + // Standard explicit virtual override + virtual void Speak() override + { + Console::WriteLine("Dog says Woof"); + } +}; + +ref class Puppy : public Dog +{ +public: + // Yip name overrides dog's virtual speak + virtual void Yip() = Dog::Speak // should be just: = Speak + { + Console::WriteLine("Puppy says Yip Yip"); + } +}; + +ref class Cat : public Animal +{ +public: + // Start a new speak virtual sequence so animal's virtual speak fails + virtual void Speak() new + { + Console::WriteLine("Cat says Meow"); + } +}; + +ref class Tiger : public Cat +{ +public: + // Though inherited from cat, Tiger name overrides Animal's speak + // thus, can speak though animal virtual sequence + // also this method overrides Cat’s virtual Speak method as well + virtual void Growl() = Animal::Speak, Cat::Speak + { + Console::WriteLine("Tiger says Grrrr"); + } +}; + +void main() +{ + // Array of Animal handles + array^ animals = gcnew array + { + gcnew Animal(), + gcnew Dog(), + gcnew Puppy(), + gcnew Cat(), + gcnew Tiger() + }; + + for each ( Animal ^a in animals) + { + a->Speak(); + } + + Console::WriteLine(); + + Animal^ cat1 = gcnew Cat(); + Cat^ cat2 = gcnew Cat(); + Cat^ tiger = gcnew Tiger(); + + // new cancels virtual sequence of Animal + cat1->Speak(); + + // new speak sequence established for cat + cat2->Speak(); + tiger->Speak(); +} diff --git a/Chapter04/BuildAll.bat b/Chapter04/BuildAll.bat new file mode 100644 index 0000000..70715f4 --- /dev/null +++ b/Chapter04/BuildAll.bat @@ -0,0 +1,18 @@ +cd Cards +call BuildAll.bat + +cd ../PlayCards +call BuildAll.bat + +cd .. +cl CatchAll.cpp /clr +cl CatchException.cpp /clr:safe +cl Defined.cpp /clr:safe +cl Delegates.cpp /clr:safe +cl Events.cpp /clr:safe +cl Finally.cpp /clr:safe +cl Generics.cpp /clr:safe +cl MultiException.cpp /clr:safe +cl RethrowException.cpp /clr:safe +cl Templates.cpp /clr:safe +cl ThrowDerived.cpp /clr:safe diff --git a/Chapter04/Cards/BuildAll.bat b/Chapter04/Cards/BuildAll.bat new file mode 100644 index 0000000..0703ce3 --- /dev/null +++ b/Chapter04/Cards/BuildAll.bat @@ -0,0 +1 @@ +cl card.cpp deck.cpp /clr:safe /LD /FeCards.dll diff --git a/Chapter04/Cards/Card.cpp b/Chapter04/Cards/Card.cpp new file mode 100644 index 0000000..c106965 --- /dev/null +++ b/Chapter04/Cards/Card.cpp @@ -0,0 +1,58 @@ +using namespace System; + +#include "card.h" +using namespace Cards; + +Card::Card(int type, Suits suit) +{ + Type = type; + Suit = suit; +} + +int Card::Type::get() +{ + return type; +} + +void Card::Type::set(int value) +{ + type = value; +} + +Suits Card::Suit::get() +{ + return suit; +} + +void Card::Suit::set(Suits value) +{ + suit = value; +} + +String^ Card::ToString() +{ + String ^t; + + if (Type > 1 && Type < 11) + t = Type.ToString(); + else if (Type == 1) + t = "A"; + else if (Type == 11) + t = "J"; + else if (Type == 12) + t = "Q"; + else + t = "K"; + + switch (Suit) + { + case Suits::Heart: + return String::Concat(t, "H"); + case Suits::Diamond: + return String::Concat(t, "D"); + case Suits::Spade: + return String::Concat(t, "S"); + default: + return String::Concat(t, "C"); + } +} diff --git a/Chapter04/Cards/Card.h b/Chapter04/Cards/Card.h new file mode 100644 index 0000000..da35e6a --- /dev/null +++ b/Chapter04/Cards/Card.h @@ -0,0 +1,26 @@ +namespace Cards +{ + public enum class Suits { Heart, Diamond, Spade, Club }; + + public ref class Card + { + int type; + Suits suit; + + public: + Card(int type, Suits suit); + + property int Type + { + int get(); + void set(int value); + } + property Suits Suit + { + Suits get(); + void set(Suits value); + } + + virtual String^ ToString() override; + }; +} diff --git a/Chapter04/Cards/Deck.h b/Chapter04/Cards/Deck.h new file mode 100644 index 0000000..b091265 --- /dev/null +++ b/Chapter04/Cards/Deck.h @@ -0,0 +1,14 @@ +namespace Cards +{ + public ref class Deck + { + array^ deck; + int curCard; + + public: + Deck(void); + + Card ^Deal(); + void Shuffle(); + }; +} diff --git a/Chapter04/CatchAll.cpp b/Chapter04/CatchAll.cpp new file mode 100644 index 0000000..610d308 --- /dev/null +++ b/Chapter04/CatchAll.cpp @@ -0,0 +1,45 @@ +using namespace System; + +ref class MyDerivedException : public ApplicationException +{ +public: + MyDerivedException( String ^err ); +}; + +MyDerivedException::MyDerivedException(String ^err) : ApplicationException(err) +{ +} + + +ref class MyException // Not derived from Exception class +{ +}; + + +void main() +{ + for (int i = 0; i < 4; i++) + { + Console::WriteLine("Start Loop"); + try + { + if (i == 1) + throw gcnew ApplicationException("\tBase Exception"); + else if (i == 2) + throw gcnew MyDerivedException("\tMy Derived Exception"); + else if (i == 3) + throw gcnew MyException(); + + Console::WriteLine("\tNo Exception"); + } + catch (ApplicationException ^e) + { + Console::WriteLine(e->Message); + } + catch (...) + { + Console::WriteLine("\tMy Exception"); + } + Console::WriteLine("End Loop"); + } +} \ No newline at end of file diff --git a/Chapter04/CatchException.cpp b/Chapter04/CatchException.cpp new file mode 100644 index 0000000..63c00ca --- /dev/null +++ b/Chapter04/CatchException.cpp @@ -0,0 +1,20 @@ +using namespace System; + +ref class X {}; +ref class Y {}; + +void main() +{ + X ^x = gcnew X; + + try + { + Y ^y = (Y^)x; + Console::WriteLine("No Exception"); // Should not execute + } + catch (InvalidCastException ^e) + { + Console::WriteLine("Invalid Cast Exception"); + Console::WriteLine(e->StackTrace); + } +} \ No newline at end of file diff --git a/Chapter04/Defined.cpp b/Chapter04/Defined.cpp new file mode 100644 index 0000000..576af64 --- /dev/null +++ b/Chapter04/Defined.cpp @@ -0,0 +1,17 @@ +using namespace System; + +#define DISAPPEARS +#define ONE 1 +#define TWO 2 +#define POW2(x) (x)*(x) + +void main() +{ + Console::Write("The follow symbol disappears->" DISAPPEARS); + Console::WriteLine("<-"); + + Int32 x = TWO; + Int32 y = POW2(x + ONE); + + Console::WriteLine(y); +} \ No newline at end of file diff --git a/Chapter04/Delegates.cpp b/Chapter04/Delegates.cpp new file mode 100644 index 0000000..7bdc7b6 --- /dev/null +++ b/Chapter04/Delegates.cpp @@ -0,0 +1,69 @@ +using namespace System; + +/// A Delegate that talks a lot +delegate void SayDelegate(String ^name); + +/// A friendly function +void SayHello(String ^name) +{ + Console::Write("Hello there "); + Console::WriteLine(name); +} + +/// A talkative class +ref class Talkative +{ +public: + static void SayHi(String ^name); + void SayStuff(String ^name); + void SayBye(String ^name); +}; + +void Talkative::SayHi(System::String ^name) +{ + Console::Write("Hi there "); + Console::WriteLine(name); +} + +void Talkative::SayStuff(System::String ^name) +{ + Console::Write("Nice weather we are having. Right, "); + Console::Write(name); + Console::WriteLine("?"); +} + +void Talkative::SayBye(System::String ^name) +{ + Console::Write("Good-bye "); + Console::WriteLine(name); +} + +/// Delegates in action +void main() +{ + SayDelegate^ say; + + // Global Function + say = gcnew SayDelegate(&SayHello); + + // add Static member function + say += gcnew SayDelegate(&Talkative::SayHi); + + Talkative ^computer = gcnew Talkative(); + + // add instance member functions + say = say + gcnew SayDelegate(computer, &Talkative::SayStuff); + say += gcnew SayDelegate(computer, &Talkative::SayBye); + + // invoke delegate + say->Invoke("Stephen"); + + Console::WriteLine("-------------------------------"); + + // remove a couple of methods + say = say - gcnew SayDelegate(&Talkative::SayHi); + say -= gcnew SayDelegate(computer, &Talkative::SayBye); + + // invoke delegate again with two fewer methods + say("Stephen"); +} \ No newline at end of file diff --git a/Chapter04/Events.cpp b/Chapter04/Events.cpp new file mode 100644 index 0000000..a46deaa --- /dev/null +++ b/Chapter04/Events.cpp @@ -0,0 +1,87 @@ +using namespace System; + +delegate void SayHandler(String ^name); + +ref class EventSource +{ +public: + event SayHandler^ OnSay; + + void Say(String ^name) + { + OnSay(name); + } +}; + +ref class EventReceiver1 +{ + EventSource ^source; +public: + + EventReceiver1(EventSource ^src) + { + if (src == nullptr) + throw gcnew ArgumentNullException("Must pass an Event Source"); + + source = src; + + source->OnSay += gcnew SayHandler(this, &EventReceiver1::SayHello); + source->OnSay += gcnew SayHandler(this, &EventReceiver1::SayStuff); + } + + void RemoveStuff() + { + source->OnSay -= gcnew SayHandler(this, &EventReceiver1::SayStuff); + } + + void SayHello(String ^name) + { + Console::Write("Hello there "); + Console::WriteLine(name); + } + + void SayStuff(String ^name) + { + Console::Write("Nice weather we are having. Right, "); + Console::Write(name); + Console::WriteLine("?"); + } +}; + +ref class EventReceiver2 +{ + EventSource ^source; +public: + + EventReceiver2(EventSource ^src) + { + if (src == nullptr) + throw gcnew ArgumentNullException("Must pass an Event Source"); + + source = src; + + source->OnSay += gcnew SayHandler(this, &EventReceiver2::SayBye); + } + + void SayBye(String ^name) + { + Console::Write("Good-bye "); + Console::WriteLine(name); + } +}; + +void main() +{ + EventSource ^source = gcnew EventSource(); + + EventReceiver1 ^receiver1 = gcnew EventReceiver1(source); + EventReceiver2 ^receiver2 = gcnew EventReceiver2(source); + + source->Say("Mr Fraser"); + + Console::WriteLine("-------------------------------"); + + receiver1->RemoveStuff(); + + source->Say("Stephen"); +} \ No newline at end of file diff --git a/Chapter04/Finally.cpp b/Chapter04/Finally.cpp new file mode 100644 index 0000000..dc5c4c8 --- /dev/null +++ b/Chapter04/Finally.cpp @@ -0,0 +1,33 @@ +using namespace System; + +void main() +{ + for (int i = 0; i < 3; i++) + { + Console::WriteLine("Start Loop"); + try + { + if (i == 0) + { + Console::WriteLine("\tCounter = 0"); + } + else if (i == 1) + { + throw gcnew ApplicationException("\t*Exception* Counter = 1"); + } + else + { + Console::WriteLine("\tCounter > 1"); + } + } + catch (ApplicationException ^e) + { + Console::WriteLine(e->Message); + } + finally + { + Console::WriteLine("\tDone every time"); + } + Console::WriteLine("End Loop"); + } +} \ No newline at end of file diff --git a/Chapter04/Generics.cpp b/Chapter04/Generics.cpp new file mode 100644 index 0000000..f0153a4 --- /dev/null +++ b/Chapter04/Generics.cpp @@ -0,0 +1,49 @@ +using namespace System; + +// Generic Class ---------------------------------------- + +generic + where K : IComparable +ref class KVClass +{ +public: + property K Key; + property V Value; + KVClass(K key, V value); + + V isGreater(KVClass ^in); +}; + +generic +KVClass::KVClass(K key, V value) +{ + Key = key; + Value = value; +} + + +generic + where K : IComparable +V KVClass::isGreater(KVClass ^in) +{ + if (Key->CompareTo(in->Key) > 0) + return Value; + else + return in->Value; +} + + +// main function ---------------------------------------- + +void main() +{ + KVClass ^a = gcnew KVClass(5, "Five"); + KVClass ^b = gcnew KVClass(6, "Six"); + + Console::WriteLine(a->isGreater(b)); + + KVClass ^t = gcnew KVClass("Tomato", 1); + KVClass ^c = gcnew KVClass("Carrot", 2); + + Console::WriteLine(t->isGreater(c)); +} \ No newline at end of file diff --git a/Chapter04/MultiException.cpp b/Chapter04/MultiException.cpp new file mode 100644 index 0000000..2807e2b --- /dev/null +++ b/Chapter04/MultiException.cpp @@ -0,0 +1,59 @@ +using namespace System; + +/// Base Class +ref class LevelOneException : public ApplicationException +{ +public: + LevelOneException( String ^err ); +}; + +LevelOneException::LevelOneException(String ^err) : ApplicationException(err) +{ +} + +/// Inherited Class +ref class LevelTwoException : public LevelOneException +{ +public: + LevelTwoException( String ^err ); +}; + +LevelTwoException::LevelTwoException(String ^err) : LevelOneException(err) +{ +} + +/// Catching multiple exceptions +void main() +{ + for (int i = 0; i < 4; i++) + { + Console::WriteLine("Start Loop"); + try + { + if (i == 1) + throw gcnew ApplicationException("\tBase Exception Thrown"); + else if (i == 2) + throw gcnew LevelOneException("\tLevel 1 Exception Thrown"); + else if (i == 3) + throw gcnew LevelTwoException("\tLevel 2 Exception Thrown"); + + Console::WriteLine("\tNo Exception"); + } + catch (LevelTwoException ^e2) + { + Console::WriteLine(e2->Message); + Console::WriteLine("\tLevel 2 Exception Caught"); + } + catch (LevelOneException ^e1) + { + Console::WriteLine(e1->Message); + Console::WriteLine("\tLevel 1 Exception Caught"); + } + catch (ApplicationException ^e) + { + Console::WriteLine(e->Message); + Console::WriteLine("\tBase Exception Caught"); + } + Console::WriteLine("End Loop"); + } +} \ No newline at end of file diff --git a/Chapter04/PlayCards/BuildAll.bat b/Chapter04/PlayCards/BuildAll.bat new file mode 100644 index 0000000..9e14baa --- /dev/null +++ b/Chapter04/PlayCards/BuildAll.bat @@ -0,0 +1,2 @@ +cl card.cpp deck.cpp /clr:safe /LD /FeCards.dll +cl playcards.cpp /CLR:safe diff --git a/Chapter04/PlayCards/Card.cpp b/Chapter04/PlayCards/Card.cpp new file mode 100644 index 0000000..c106965 --- /dev/null +++ b/Chapter04/PlayCards/Card.cpp @@ -0,0 +1,58 @@ +using namespace System; + +#include "card.h" +using namespace Cards; + +Card::Card(int type, Suits suit) +{ + Type = type; + Suit = suit; +} + +int Card::Type::get() +{ + return type; +} + +void Card::Type::set(int value) +{ + type = value; +} + +Suits Card::Suit::get() +{ + return suit; +} + +void Card::Suit::set(Suits value) +{ + suit = value; +} + +String^ Card::ToString() +{ + String ^t; + + if (Type > 1 && Type < 11) + t = Type.ToString(); + else if (Type == 1) + t = "A"; + else if (Type == 11) + t = "J"; + else if (Type == 12) + t = "Q"; + else + t = "K"; + + switch (Suit) + { + case Suits::Heart: + return String::Concat(t, "H"); + case Suits::Diamond: + return String::Concat(t, "D"); + case Suits::Spade: + return String::Concat(t, "S"); + default: + return String::Concat(t, "C"); + } +} diff --git a/Chapter04/PlayCards/Card.h b/Chapter04/PlayCards/Card.h new file mode 100644 index 0000000..da35e6a --- /dev/null +++ b/Chapter04/PlayCards/Card.h @@ -0,0 +1,26 @@ +namespace Cards +{ + public enum class Suits { Heart, Diamond, Spade, Club }; + + public ref class Card + { + int type; + Suits suit; + + public: + Card(int type, Suits suit); + + property int Type + { + int get(); + void set(int value); + } + property Suits Suit + { + Suits get(); + void set(Suits value); + } + + virtual String^ ToString() override; + }; +} diff --git a/Chapter04/PlayCards/Deck.cpp b/Chapter04/PlayCards/Deck.cpp new file mode 100644 index 0000000..03a208a --- /dev/null +++ b/Chapter04/PlayCards/Deck.cpp @@ -0,0 +1,44 @@ +using namespace System; + +#include "card.h" +#include "deck.h" +using namespace Cards; + +Deck::Deck(void) +{ + deck = gcnew array(52); + + for (int i = 0; i < 13; i++) + { + deck[i] = gcnew Card(i+1, Suits::Heart); + deck[i+13] = gcnew Card(i+1, Suits::Club); + deck[i+26] = gcnew Card(i+1, Suits::Diamond); + deck[i+39] = gcnew Card(i+1, Suits::Spade); + } + curCard = 0; +} + +Card^ Deck::Deal() +{ + if (curCard < deck->Length) + return deck[curCard++]; + else + return nullptr; +} + +void Deck::Shuffle() +{ + Random ^r = gcnew Random(); + Card ^tmp; + int j; + + for( int i = 0; i < deck->Length; i++ ) + { + j = r->Next(deck->Length); + tmp = deck[j]; + deck[j] = deck[i]; + deck[i] = tmp; + } + + curCard = 0; +} diff --git a/Chapter04/PlayCards/Deck.h b/Chapter04/PlayCards/Deck.h new file mode 100644 index 0000000..b091265 --- /dev/null +++ b/Chapter04/PlayCards/Deck.h @@ -0,0 +1,14 @@ +namespace Cards +{ + public ref class Deck + { + array^ deck; + int curCard; + + public: + Deck(void); + + Card ^Deal(); + void Shuffle(); + }; +} diff --git a/Chapter04/PlayCards/PlayCards.cpp b/Chapter04/PlayCards/PlayCards.cpp new file mode 100644 index 0000000..a9e1f05 --- /dev/null +++ b/Chapter04/PlayCards/PlayCards.cpp @@ -0,0 +1,27 @@ +#using + +using namespace System; +using namespace Cards; + +void main() +{ + Deck deck; + + deck.Shuffle(); + + Card ^card; + int cnt = 0; + while ((card = deck.Deal()) != nullptr) + { + Console::Write(card->ToString()); + Console::Write("\t"); + cnt++; + + if (cnt > 4) + { + Console::WriteLine(""); + cnt = 0; + } + } + Console::WriteLine(""); +} \ No newline at end of file diff --git a/Chapter04/RethrowException.cpp b/Chapter04/RethrowException.cpp new file mode 100644 index 0000000..ebd79af --- /dev/null +++ b/Chapter04/RethrowException.cpp @@ -0,0 +1,25 @@ +using namespace System; + +void main() +{ + try + { + try + { + throw gcnew ApplicationException("\t***Boom***"); + Console::WriteLine("Imbedded Try End"); + } + catch (ApplicationException ^ie) + { + Console::WriteLine("Caught Exception "); + Console::WriteLine(ie->Message); + throw; + } + Console::WriteLine("Outer Try End"); + } + catch (ApplicationException ^oe) + { + Console::WriteLine("Recaught Exception "); + Console::WriteLine(oe->Message); + } +} \ No newline at end of file diff --git a/Chapter04/Templates.cpp b/Chapter04/Templates.cpp new file mode 100644 index 0000000..c8d5b36 --- /dev/null +++ b/Chapter04/Templates.cpp @@ -0,0 +1,116 @@ +using namespace System; + +// Function Template -------------------------------------- + +template +T min ( T a, T b) +{ + return (a < b) ? a : b; +} + +// Class Template ----------------------------------------- + +template +ref class Point2D +{ +public: + Point2D(); + Point2D(T x, T y); + + T X; + T Y; + + static Point2D^ operator-(const Point2D^ lhs, const Point2D^ rhs); + static Point2D^ operator*(const Point2D^ lhs, const T rhs); + + virtual String^ ToString() override; +}; + +template +Point2D::Point2D() : X((T)0), Y((T)0) {} + +template +Point2D::Point2D(T x, T y) : X(x), Y(y) {} + +template +Point2D^ Point2D::operator-(const Point2D^ lhs, const Point2D^ rhs) +{ + Point2D^ ret = gcnew Point2D(); + + ret->X = lhs->X - rhs->X; + ret->Y = lhs->Y - rhs->Y; + + return ret; +} + +template +Point2D^ Point2D::operator*(const Point2D^ lhs, const T rhs) +{ + Point2D^ ret = gcnew Point2D(); + + ret->X = lhs->X * rhs; + ret->Y = lhs->Y * rhs; + + return ret; +} + +template +String^ Point2D::ToString() +{ + return String::Format("X={0} Y={1}", X, Y); +} + +// Class Template Specialization ---------------------------- + +template <> +ref class Point2D +{ +public: + Point2D() { throw gcnew Exception("Data Type is too small"); } + Point2D(char x, char y) { throw gcnew Exception("Data Type is too small"); } +}; + +// main function -------------------------------------------- + +void main() +{ + int a = 5; + int b = 6; + double c = 5.1; + + Console::WriteLine("The min of {0} and {1} is {2}", a, b, min(a,b)); + Console::WriteLine("The min of {0} and {1} is {2}", a, c, min(a,c)); + + Console::WriteLine("----------------------------"); + + Point2D^ TopLeftI = gcnew Point2D(10, 10); + Point2D^ BottomRightI = gcnew Point2D(15, 20); + + Point2D^ SizeI = BottomRightI - TopLeftI; + Console::WriteLine(SizeI); + + SizeI = SizeI * 2; + Console::WriteLine(SizeI); + + Console::WriteLine("----------------------------"); + + Point2D^ TopLeft = gcnew Point2D(10.5, 10.9); + Point2D^ BottomRight = gcnew Point2D(15.2, 20.3); + + Point2D^ SizeD = BottomRight - TopLeft; + Console::WriteLine(SizeD); + + SizeD = SizeD * 0.5; + Console::WriteLine(SizeD); + + Console::WriteLine("----------------------------"); + + try + { + Point2D^ TopLeft = gcnew Point2D(10, 10); + } + catch (Exception^ ex) + { + Console::WriteLine(ex->Message); + } +} \ No newline at end of file diff --git a/Chapter04/ThrowDerived.cpp b/Chapter04/ThrowDerived.cpp new file mode 100644 index 0000000..0bf72f3 --- /dev/null +++ b/Chapter04/ThrowDerived.cpp @@ -0,0 +1,39 @@ +using namespace System; + +ref class MyException : public ApplicationException +{ +public: + MyException( String ^err ); +}; + +MyException::MyException(System::String ^err) : ApplicationException(err) +{ +} + +void main() +{ + for (int i = 0; i < 3; i++) + { + Console::WriteLine("Start Loop"); + try + { + if (i == 0) + { + Console::WriteLine("\tCounter equal to 0"); + } + else if (i == 1) + { + throw gcnew MyException("\t**Exception** Counter equal to 1"); + } + else + { + Console::WriteLine("\tCounter greater than 1"); + } + } + catch (MyException ^e) + { + Console::WriteLine(e->Message); + } + Console::WriteLine("End Loop"); + } +} \ No newline at end of file diff --git a/Chapter06/AllTags/AllTags.cpp b/Chapter06/AllTags/AllTags.cpp new file mode 100644 index 0000000..8c61385 --- /dev/null +++ b/Chapter06/AllTags/AllTags.cpp @@ -0,0 +1,2 @@ +#include "AllTags.h" + diff --git a/Chapter06/AllTags/AllTags.h b/Chapter06/AllTags/AllTags.h new file mode 100644 index 0000000..f29e98a --- /dev/null +++ b/Chapter06/AllTags/AllTags.h @@ -0,0 +1,155 @@ +#pragma once + +using namespace System; +using namespace System::IO; + +namespace AllTags +{ + public ref class AClass + { + public: + + /// + /// This is a summary tag for the summaryTag() method + /// + void summaryTag() {} + + /// The first int parameter + /// The second String^ parameter + void paramTag(int param1, String ^param2) {} + + /// returnsTag returns an int + int returnsTag() {return 0;} + + /// valueTag property has a value of double + property double valueTag + { + double get() {return 0.0;} + void set(double val) {} + } + + /// + /// This is a remarks tag for the remarksTag() method + /// + void remarksTag() {} + + /// + /// Example summary + /// [Visual Basic] + /// + /// Visual Basic .NET code example + /// + /// [C#] + /// + /// C# code example + /// + /// [C++] + /// + /// C++ code example + /// + /// + void exampleTag() {} + + /// + /// This method might throw this exception (NOT) + /// + void exceptionTag() {} + + /// + /// Go ahead anyone can access me. + /// + void permissionTag() {} + + /// + /// Some Program code in a summary + /// + void cTag() {} + + /// + /// Some code in an example tag + /// + /// A code statement; + /// Another code statement; + /// + /// + void codeTag() {} + + /// + /// This is the first paragraph which spans nore than one line + /// When the document window is small enough.This is the + /// next paragraph which started in a new line. + /// + void paraTag() {} + + /// + /// A bullet list + /// + /// bullet + /// bullet + /// + /// A numbered list + /// + /// entry 1 + /// entry 2 + /// entry n + /// + /// A table + /// + /// + /// row 1 -- column a + /// row 1 -- column b + /// row 1 -- column c + /// + /// + /// row 2 -- column a + /// row 2 -- column b + /// row 2 -- column c + /// + /// + /// A definition of terms + /// + /// + /// Properties + /// Initial Value + /// + /// + /// term1 name + /// term1 description + /// + /// + /// term2 name + /// term2 description + /// + /// + /// termN name + /// termN description + /// + /// + /// + void listTag() {} + + /// This is a summary with an <include> tag containing + /// a <list type="bullet"> + /// + /// + /// + void includeTag() {} + + /// This summary reference the + /// parameter of the method + /// + void paramrefTag(int param1) {} + + /// + /// The basic see tag + /// The enhanced see tag System::IO:FileInfo + /// + void seeTag() {} + + /// + /// The basic see tag [] Nothing here + /// The enhanced see tag FileInfo + /// + void seealsoTag() {} + }; +} diff --git a/Chapter06/AllTags/AllTags.vcproj b/Chapter06/AllTags/AllTags.vcproj new file mode 100644 index 0000000..2d5cfe5 --- /dev/null +++ b/Chapter06/AllTags/AllTags.vcproj @@ -0,0 +1,218 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Chapter06/AllTags/document.xml b/Chapter06/AllTags/document.xml new file mode 100644 index 0000000..83c4db8 --- /dev/null +++ b/Chapter06/AllTags/document.xml @@ -0,0 +1,20 @@ + + + + + These are repeating bullets: + + bullet + bullet + bullet + + + + + + This is a complete <remark> entry from an include + file called documentation.xml. + + + + diff --git a/Chapter06/Chapter06.sln b/Chapter06/Chapter06.sln new file mode 100644 index 0000000..49ffff3 --- /dev/null +++ b/Chapter06/Chapter06.sln @@ -0,0 +1,54 @@ + +Microsoft Visual Studio Solution File, Format Version 9.00 +# Visual Studio 2005 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "SimpleTripleSlash", "SimpleTripleSlash\SimpleTripleSlash.vcproj", "{7D891CBC-A936-4BD5-9697-C9B3DB8D9B98}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ViewSimple", "ViewSimple\ViewSimple.vcproj", "{C64C6183-FD33-42CF-8A27-2774E22CFC82}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "AllTags", "AllTags\AllTags.vcproj", "{E42DA001-0DAA-4ED9-AEF6-6220777D40BC}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Debug|Mixed Platforms = Debug|Mixed Platforms + Debug|Win32 = Debug|Win32 + Release|Any CPU = Release|Any CPU + Release|Mixed Platforms = Release|Mixed Platforms + Release|Win32 = Release|Win32 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {7D891CBC-A936-4BD5-9697-C9B3DB8D9B98}.Debug|Any CPU.ActiveCfg = Debug|Win32 + {7D891CBC-A936-4BD5-9697-C9B3DB8D9B98}.Debug|Mixed Platforms.ActiveCfg = Debug|Win32 + {7D891CBC-A936-4BD5-9697-C9B3DB8D9B98}.Debug|Mixed Platforms.Build.0 = Debug|Win32 + {7D891CBC-A936-4BD5-9697-C9B3DB8D9B98}.Debug|Win32.ActiveCfg = Debug|Win32 + {7D891CBC-A936-4BD5-9697-C9B3DB8D9B98}.Debug|Win32.Build.0 = Debug|Win32 + {7D891CBC-A936-4BD5-9697-C9B3DB8D9B98}.Release|Any CPU.ActiveCfg = Release|Win32 + {7D891CBC-A936-4BD5-9697-C9B3DB8D9B98}.Release|Mixed Platforms.ActiveCfg = Release|Win32 + {7D891CBC-A936-4BD5-9697-C9B3DB8D9B98}.Release|Mixed Platforms.Build.0 = Release|Win32 + {7D891CBC-A936-4BD5-9697-C9B3DB8D9B98}.Release|Win32.ActiveCfg = Release|Win32 + {7D891CBC-A936-4BD5-9697-C9B3DB8D9B98}.Release|Win32.Build.0 = Release|Win32 + {C64C6183-FD33-42CF-8A27-2774E22CFC82}.Debug|Any CPU.ActiveCfg = Debug|Win32 + {C64C6183-FD33-42CF-8A27-2774E22CFC82}.Debug|Mixed Platforms.ActiveCfg = Debug|Win32 + {C64C6183-FD33-42CF-8A27-2774E22CFC82}.Debug|Mixed Platforms.Build.0 = Debug|Win32 + {C64C6183-FD33-42CF-8A27-2774E22CFC82}.Debug|Win32.ActiveCfg = Debug|Win32 + {C64C6183-FD33-42CF-8A27-2774E22CFC82}.Debug|Win32.Build.0 = Debug|Win32 + {C64C6183-FD33-42CF-8A27-2774E22CFC82}.Release|Any CPU.ActiveCfg = Release|Win32 + {C64C6183-FD33-42CF-8A27-2774E22CFC82}.Release|Mixed Platforms.ActiveCfg = Release|Win32 + {C64C6183-FD33-42CF-8A27-2774E22CFC82}.Release|Mixed Platforms.Build.0 = Release|Win32 + {C64C6183-FD33-42CF-8A27-2774E22CFC82}.Release|Win32.ActiveCfg = Release|Win32 + {C64C6183-FD33-42CF-8A27-2774E22CFC82}.Release|Win32.Build.0 = Release|Win32 + {E42DA001-0DAA-4ED9-AEF6-6220777D40BC}.Debug|Any CPU.ActiveCfg = Debug|Win32 + {E42DA001-0DAA-4ED9-AEF6-6220777D40BC}.Debug|Mixed Platforms.ActiveCfg = Debug|Win32 + {E42DA001-0DAA-4ED9-AEF6-6220777D40BC}.Debug|Mixed Platforms.Build.0 = Debug|Win32 + {E42DA001-0DAA-4ED9-AEF6-6220777D40BC}.Debug|Win32.ActiveCfg = Debug|Win32 + {E42DA001-0DAA-4ED9-AEF6-6220777D40BC}.Debug|Win32.Build.0 = Debug|Win32 + {E42DA001-0DAA-4ED9-AEF6-6220777D40BC}.Release|Any CPU.ActiveCfg = Release|Win32 + {E42DA001-0DAA-4ED9-AEF6-6220777D40BC}.Release|Mixed Platforms.ActiveCfg = Release|Win32 + {E42DA001-0DAA-4ED9-AEF6-6220777D40BC}.Release|Mixed Platforms.Build.0 = Release|Win32 + {E42DA001-0DAA-4ED9-AEF6-6220777D40BC}.Release|Win32.ActiveCfg = Release|Win32 + {E42DA001-0DAA-4ED9-AEF6-6220777D40BC}.Release|Win32.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/Chapter06/Chapter06.suo b/Chapter06/Chapter06.suo new file mode 100644 index 0000000..b7a360c Binary files /dev/null and b/Chapter06/Chapter06.suo differ diff --git a/Chapter06/Documentation.chm b/Chapter06/Documentation.chm new file mode 100644 index 0000000..8710152 Binary files /dev/null and b/Chapter06/Documentation.chm differ diff --git a/Chapter06/SimpleTripleSlash/SimpleTripleSlash.cpp b/Chapter06/SimpleTripleSlash/SimpleTripleSlash.cpp new file mode 100644 index 0000000..0b2acd1 --- /dev/null +++ b/Chapter06/SimpleTripleSlash/SimpleTripleSlash.cpp @@ -0,0 +1,4 @@ +// This is the main DLL file. + +#include "SimpleTripleSlash.h" + diff --git a/Chapter06/SimpleTripleSlash/SimpleTripleSlash.h b/Chapter06/SimpleTripleSlash/SimpleTripleSlash.h new file mode 100644 index 0000000..fd0eab6 --- /dev/null +++ b/Chapter06/SimpleTripleSlash/SimpleTripleSlash.h @@ -0,0 +1,25 @@ +// SimpleTripleSlash.h + +#pragma once + +using namespace System; +using namespace System::IO; + + +namespace SimpleTripleSlash +{ + /// + /// This is a summary comment for Class1 + /// + public ref class Class1 + { + public: + /// This is a summary comment for Method1 Boo Boo + /// + /// + void Method1() {} + + /// This is a summary comment for Variable1 + int Variable1; + }; +} diff --git a/Chapter06/SimpleTripleSlash/SimpleTripleSlash.vcproj b/Chapter06/SimpleTripleSlash/SimpleTripleSlash.vcproj new file mode 100644 index 0000000..1820dc1 --- /dev/null +++ b/Chapter06/SimpleTripleSlash/SimpleTripleSlash.vcproj @@ -0,0 +1,211 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Chapter06/ViewSimple/AssemblyInfo.cpp b/Chapter06/ViewSimple/AssemblyInfo.cpp new file mode 100644 index 0000000..4bb4f93 --- /dev/null +++ b/Chapter06/ViewSimple/AssemblyInfo.cpp @@ -0,0 +1,61 @@ +#include "stdafx.h" + +using namespace System::Reflection; +using namespace System::Runtime::CompilerServices; +using namespace System::Runtime::InteropServices; + +// +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +// +[assembly:AssemblyTitleAttribute("ViewSimple")]; +[assembly:AssemblyDescriptionAttribute("")]; +[assembly:AssemblyConfigurationAttribute("")]; +[assembly:AssemblyCompanyAttribute("")]; +[assembly:AssemblyProductAttribute("ViewSimple")]; +[assembly:AssemblyCopyrightAttribute("Copyright @ 2005")]; +[assembly:AssemblyTrademarkAttribute("")]; +[assembly:AssemblyCultureAttribute("")]; + +// +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the value or you can default the Revision and Build Numbers +// by using the '*' as shown below: + +[assembly:AssemblyVersionAttribute("1.0.*")]; + +// +// In order to sign your assembly you must specify a key to use. Refer to the +// Microsoft .NET Framework documentation for more information on assembly signing. +// +// Use the attributes below to control which key is used for signing. +// +// Notes: +// (*) If no key is specified, the assembly is not signed. +// (*) KeyName refers to a key that has been installed in the Crypto Service +// Provider (CSP) on your machine. KeyFile refers to a file which contains +// a key. +// (*) If the KeyFile and the KeyName values are both specified, the +// following processing occurs: +// (1) If the KeyName can be found in the CSP, that key is used. +// (2) If the KeyName does not exist and the KeyFile does exist, the key +// in the KeyFile is installed into the CSP and used. +// (*) In order to create a KeyFile, you can use the sn.exe (Strong Name) utility. +// When specifying the KeyFile, the location of the KeyFile should be +// relative to the project directory. +// (*) Delay Signing is an advanced option - see the Microsoft .NET Framework +// documentation for more information on this. +// +[assembly:AssemblyDelaySignAttribute(false)]; +[assembly:AssemblyKeyFileAttribute("")]; +[assembly:AssemblyKeyNameAttribute("")]; + +[assembly:ComVisible(false)]; + diff --git a/Chapter06/ViewSimple/ViewSimple.cpp b/Chapter06/ViewSimple/ViewSimple.cpp new file mode 100644 index 0000000..2c40667 --- /dev/null +++ b/Chapter06/ViewSimple/ViewSimple.cpp @@ -0,0 +1,14 @@ +// This is the main project file for VC++ application project +// generated using an Application Wizard. + +using namespace System; +using namespace SimpleTripleSlash; + +void main() +{ + Class1 ^class1 = gcnew Class1(); + + class1->Method1(); + + int x = class1->Variable1; +} diff --git a/Chapter06/ViewSimple/ViewSimple.vcproj b/Chapter06/ViewSimple/ViewSimple.vcproj new file mode 100644 index 0000000..34dedae --- /dev/null +++ b/Chapter06/ViewSimple/ViewSimple.vcproj @@ -0,0 +1,201 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Chapter06/ViewSimple/resource.h b/Chapter06/ViewSimple/resource.h new file mode 100644 index 0000000..d5ac7c4 --- /dev/null +++ b/Chapter06/ViewSimple/resource.h @@ -0,0 +1,3 @@ +//{{NO_DEPENDENCIES}} +// Microsoft Visual C++ generated include file. +// Used by app.rc diff --git a/Chapter06/ViewSimple/stdafx.cpp b/Chapter06/ViewSimple/stdafx.cpp new file mode 100644 index 0000000..38c5ac0 --- /dev/null +++ b/Chapter06/ViewSimple/stdafx.cpp @@ -0,0 +1,7 @@ +// stdafx.cpp : source file that includes just the standard includes +// ViewSimple.pch will be the pre-compiled header +// stdafx.obj will contain the pre-compiled type information + +#include "stdafx.h" + + diff --git a/Chapter06/ViewSimple/stdafx.h b/Chapter06/ViewSimple/stdafx.h new file mode 100644 index 0000000..5acdcf6 --- /dev/null +++ b/Chapter06/ViewSimple/stdafx.h @@ -0,0 +1,10 @@ +// stdafx.h : include file for standard system include files, +// or project specific include files that are used frequently, but +// are changed infrequently +// + +#pragma once + +#include + +// TODO: reference additional headers your program requires here diff --git a/Chapter07/DictionaryGeneric.cpp b/Chapter07/DictionaryGeneric.cpp new file mode 100644 index 0000000..df04f7a --- /dev/null +++ b/Chapter07/DictionaryGeneric.cpp @@ -0,0 +1,113 @@ +#using + +using namespace System; +using namespace System::Collections::Generic; + +// Make the dictionary sort in reverse +ref class Reverse : public IComparer +{ +public: + virtual int Compare(int x, int y) { return y - x; } + virtual bool Equals(int x, int y) { return x == y; } + virtual int GetHashCode(int obj) { return obj.GetHashCode(); } +}; + +Dictionary^ DictionaryExample() +{ + Dictionary^ dict = gcnew Dictionary(); + + dict->Add(1, "One"); + dict->Add(6, "Six"); + dict->Add(5, "Five"); + + dict->Add(3, "3"); +// dict->Add(3, "3"); // throws an exception + dict[3] = "Three"; + + dict[7] = "Seven"; + + String^ t = dict[3]; + Console::WriteLine("dict[3] = {0}\n", t); + + for each (KeyValuePair^ pair in dict) + { + Console::WriteLine("Key = [{0}]\tValue = [{1}]", + pair->Key, pair->Value); + } + + Console::WriteLine("\nDictionary contains 6? [{0}]", + dict->ContainsKey(6)); + + dict->Remove(6); + + Console::WriteLine("\nDictionary had 6 removed? [{0}]\n", + !dict->ContainsKey(6)); + + Dictionary::KeyCollection::Enumerator ^key = + dict->Keys->GetEnumerator(); + Dictionary::ValueCollection::Enumerator ^value = + dict->Values->GetEnumerator(); + + while ( key->MoveNext() && value->MoveNext()) + { + Console::WriteLine("Key = [{0}]\tValue = [{1}]", + key->Current, value->Current); + } + + return dict; +} + +void SortedDictionaryExample(Dictionary^ inDict) +{ + SortedDictionary^ dict = + gcnew SortedDictionary(inDict, gcnew Reverse()); + + dict->Add(6, "Six"); + + String^ t = dict[3]; + Console::WriteLine("dict[3] = {0}\n", t); + + Console::WriteLine("Sorted Values:"); + for each (String ^s in dict->Values) + Console::WriteLine("\t{0}",s); + + Console::WriteLine(); + + for each (KeyValuePair^ pair in dict) + { + Console::WriteLine("Key = [{0}]\tValue = [{1}]", + pair->Key, pair->Value); + } + + Console::WriteLine("\nSortedDictionary contains 'Six'? [{0}]", + dict->ContainsValue("Six")); + + dict->Remove(6); + + Console::WriteLine("\nSortedDictionary had 'Six' removed? [{0}]\n", + !dict->ContainsValue("Six")); + + SortedDictionary::KeyCollection::Enumerator ^key = + dict->Keys->GetEnumerator(); + SortedDictionary::ValueCollection::Enumerator ^value = + dict->Values->GetEnumerator(); + + while ( key->MoveNext() && value->MoveNext()) + { + Console::WriteLine("Key = [{0}]\tValue = [{1}]", + key->Current, value->Current); + } +} + +void main() +{ + Console::WriteLine("Dictionary\n----------"); + Dictionary^ dict = DictionaryExample(); + + Console::WriteLine(); + + Console::WriteLine("\nReverse SortedDictionary\n----------------"); + SortedDictionaryExample(dict); + + Console::WriteLine(); +} diff --git a/Chapter07/HashSortList.cpp b/Chapter07/HashSortList.cpp new file mode 100644 index 0000000..8245e79 --- /dev/null +++ b/Chapter07/HashSortList.cpp @@ -0,0 +1,80 @@ +using namespace System; +using namespace System::Collections; + +void main() +{ + Hashtable ^hash = gcnew Hashtable(); + SortedList ^sort = gcnew SortedList(); + + array^ keys = gcnew array { "B", "A", "C", "D" }; + array^ skeys = gcnew array { "A", "B", "C", "D" }; + array^ values = gcnew array { "moose", "zebra", "horse", "frog" }; + + for (int i = 0; i < keys->Length; i++) + { + hash->Add(keys[i], values[i]); + sort->Add(keys[i], values[i]); + } + + Console::WriteLine("Hashtable\tSortedList"); + + Console::WriteLine("By indexed property"); + for (int i = 0; i < hash->Count; i++) + { + Console::WriteLine("{0} {1}\t\t{2} {3}", skeys[i], + hash[skeys[i]], skeys[i], sort[skeys[i]]); + } + + Console::WriteLine("\nBy index"); + for (int i = 0; i < sort->Count; i++) + { + Console::WriteLine("N/A\t\t{0} {1}", i, sort->GetByIndex(i)); + } + + Console::WriteLine("\nBy enumerator"); + IDictionaryEnumerator ^enum1 = hash->GetEnumerator(); + IDictionaryEnumerator ^enum2 = sort->GetEnumerator(); + while ( enum1->MoveNext() && enum2->MoveNext()) + { + Console::Write("{0} {1}\t\t", enum1->Key, enum1->Value); + Console::WriteLine("{0} {1}", enum2->Key, enum2->Value); + } + + Console::WriteLine("\nEnumerate Key"); + IEnumerator ^keys1 = hash->Keys->GetEnumerator(); + IEnumerator ^keys2 = sort->Keys->GetEnumerator(); + while ( keys1->MoveNext() && keys2->MoveNext()) + { + Console::Write("{0}\t\t", keys1->Current); + Console::WriteLine("{0}", keys2->Current); + } + + Console::WriteLine("\nEnumerate Value"); + IEnumerator ^vals1 = hash->Values->GetEnumerator(); + IEnumerator ^vals2 = sort->Values->GetEnumerator(); + while ( vals1->MoveNext() && vals2->MoveNext()) + { + Console::Write("{0}\t\t", vals1->Current); + Console::WriteLine("{0}", vals2->Current); + } + + Console::WriteLine("\nContains a Key 'A' and 'Z'"); + Console::WriteLine("{0}\t\t{1}", hash->Contains("A"), + sort->Contains("A")); + Console::WriteLine("{0}\t\t{1}", hash->ContainsKey("Z"), + sort->ContainsKey("Z")); + + Console::WriteLine("\nContains a Value 'frog' and 'cow'"); + Console::WriteLine("{0}\t\t{1}", hash->ContainsValue("frog"), + sort->ContainsValue("frog")); + Console::WriteLine("{0}\t\t{1}", hash->ContainsValue("cow"), + sort->ContainsValue("cow")); + + Console::WriteLine("\n\t\t'B' key index: {0}", + sort->IndexOfKey("B")); + + Console::WriteLine("\t\t'frog' value index: {0}", + sort->IndexOfValue("frog")); + + Console::WriteLine(); +} diff --git a/Chapter07/IEnum_foreach.cpp b/Chapter07/IEnum_foreach.cpp new file mode 100644 index 0000000..4008d5d --- /dev/null +++ b/Chapter07/IEnum_foreach.cpp @@ -0,0 +1,26 @@ +using namespace System; +using namespace System::Collections; + +void main() +{ + array^ IntList = gcnew array { 1, 2, 3, 4, 5 }; + + + IEnumerable ^collection = (IEnumerable^)IntList; //Not really needed + IEnumerator ^enumerator = collection->GetEnumerator(); + + Console::WriteLine("IEnumerator\n-----------"); + + while (enumerator->MoveNext()) + { + int i = (int)enumerator->Current; + Console::WriteLine(i); + } + + Console::WriteLine("\nfor each\n--------"); + + for each (int i in IntList) + Console::WriteLine(i); + + Console::WriteLine(); +} diff --git a/Chapter07/LinkedListGeneric.cpp b/Chapter07/LinkedListGeneric.cpp new file mode 100644 index 0000000..045f670 --- /dev/null +++ b/Chapter07/LinkedListGeneric.cpp @@ -0,0 +1,44 @@ +#using + +using namespace System; +using namespace System::Collections::Generic; + +int main() +{ + array^ arrList = gcnew array {"Two", "Three", "Four"}; + + LinkedList^ list = gcnew LinkedList((IEnumerable^)arrList); + + list->AddTail("Six"); + list->AddHead("Zero"); + list->AddAfter(list->Head, "One"); + list->AddBefore(list->Tail, "5"); + + Console::WriteLine("Write with error"); + + LinkedListNode^ current = list->Tail; + while (current != nullptr) + { + Console::WriteLine(current->Value); + current = current->Previous; + } + + Console::WriteLine("\nNumber of elements = {0}", list->Count); + + LinkedListNode^ node = list->Find("5"); + + list->AddBefore(node, "Five"); + list->Remove(node); + + list->RemoveHead(); + + Console::WriteLine("\nWrite with corrections"); + for each (String^ str in list) + Console::WriteLine(str); + + Console::WriteLine("\nNumber of elements = {0}", list->Count); + + Console::WriteLine(); + +// list->Add(4); // Compile time error +} \ No newline at end of file diff --git a/Chapter07/ListDict.cpp b/Chapter07/ListDict.cpp new file mode 100644 index 0000000..551a1bb --- /dev/null +++ b/Chapter07/ListDict.cpp @@ -0,0 +1,35 @@ +#using + +using namespace System; +using namespace System::Collections; +using namespace System::Collections::Specialized; + +void main() +{ + ListDictionary ^ldict = gcnew ListDictionary(); + + ldict->Add("A", "First"); + ldict->Add("B", "Second"); + ldict->Add("C", "Third"); + ldict["D"] = "Fourth"; + + try { + ldict->Add("C", "Third Replaced"); + } + catch (ArgumentException ^e) + { + Console::WriteLine("ldict->Add(\"C\", \"Third Replaced\");"); + Console::WriteLine("Throws exception: {0}", e->Message); + } + ldict["B"] = "Second Replaced"; + + Console::WriteLine("\nEnumerate"); + IEnumerator ^keys = ldict->Keys->GetEnumerator(); + IEnumerator ^vals = ldict->Values->GetEnumerator(); + while ( keys->MoveNext() && vals->MoveNext()) + { + Console::WriteLine("{0}\t\t{1}", keys->Current, vals->Current); + } + + Console::WriteLine(); +} \ No newline at end of file diff --git a/Chapter07/ListGeneric.cpp b/Chapter07/ListGeneric.cpp new file mode 100644 index 0000000..9c7aa95 --- /dev/null +++ b/Chapter07/ListGeneric.cpp @@ -0,0 +1,75 @@ +using namespace System; +using namespace System::Collections::Generic; + +// -------- StringEx class --------------------------------------- + +ref class StringEx +{ +public: + String^ Value; + + StringEx(String^ in); + virtual String^ ToString() override; + + static bool With_e_Predicate(StringEx^ val); + static void SurroundInStars(StringEx^ val); +}; + +StringEx::StringEx(String^ in) : Value(in) {} + +String^ StringEx::ToString() { return Value; } + +bool StringEx::With_e_Predicate(StringEx^ val) +{ + return val->Value->ToUpper()->IndexOf("E") > 0; +} + +void StringEx::SurroundInStars(StringEx^ val) +{ + val->Value = String::Format("** {0} **", val->Value); +} + +// ---------- Main function --------------------------------------- + +void main() +{ + List^ alist = gcnew List(); + + alist->Add(gcnew StringEx("One")); + alist->Add(gcnew StringEx("-")); + alist[1] = gcnew StringEx("Three"); + + alist->Insert(1, gcnew StringEx("Two")); + + List^ morenums = gcnew List(); + morenums->Add(gcnew StringEx("Four")); + morenums->Add(gcnew StringEx("Five")); + + alist->AddRange(morenums); + +// alist[0] = "Six"; // Compile time error not a StringEx +// alist->Add("Six"); // Compile time error not a StringEx + + Console::WriteLine("*** The List ***"); + for (int i = 0; i < alist->Count; i++) + Console::WriteLine("{0} ", alist[i]); + + // Find all words in list that contain an 'e' + List^ With_e = + alist->FindAll(gcnew Predicate(StringEx::With_e_Predicate)); + + Console::WriteLine("\n\n*** The List containing an 'e' ***"); + + for each(StringEx^ str in With_e) + Console::WriteLine("{0} ", str); + + // Surround all elements with stars + alist->ForEach(gcnew Action(StringEx::SurroundInStars)); + + Console::WriteLine("\n\n*** The List surrounded by stars ***"); + + for each(StringEx^ str in alist) + Console::WriteLine("{0} ", str); + + Console::WriteLine("\n"); +} \ No newline at end of file diff --git a/Chapter07/NameValue.cpp b/Chapter07/NameValue.cpp new file mode 100644 index 0000000..7225a9c --- /dev/null +++ b/Chapter07/NameValue.cpp @@ -0,0 +1,58 @@ +#using + +using namespace System; +using namespace System::Collections::Specialized; + +void main() +{ + NameValueCollection^ nvCol = gcnew NameValueCollection(); + + nvCol->Add(nullptr, "void"); + + nvCol->Set("Flower", "Rose"); + + nvCol->Add("Animal", "Dog"); + nvCol->Add("Animal", "Cat"); + nvCol->Add("Animal", "Cow"); + + nvCol->Add("Fruit", "Apple"); + nvCol->Add("Fruit", "Pear"); + nvCol->Add("Fruit", "Peach"); + + + array^ keys = nvCol->AllKeys; + + Console::WriteLine("Key\t\tValue"); + for (int i = 0; i < keys->Length; i++) + { + array^ vals = nvCol->GetValues(keys[i]); + + Console::WriteLine("{0}:\t\t{1}", keys[i], vals[0]); + for (int j = 1; j < vals->Length; j++) + { + Console::WriteLine("\t\t{0}", vals[j]); + } + } + + Console::WriteLine("------ Index Lookups ------"); + Console::WriteLine("Key @[1]:\t{0}", nvCol->GetKey(1)); + Console::WriteLine("Values @[3]:\t{0}", nvCol[3]); + + + nvCol->Remove(nullptr); + + nvCol["Fruit"] = "Plum"; + + nvCol->Set("Animal", "Deer"); + nvCol->Add("Animal", "Ape"); + + keys = nvCol->AllKeys; + + Console::WriteLine("--------- Updated ---------"); + for (int i = 0; i < keys->Length; i++) + { + Console::WriteLine("{0}:\t\t{1}", keys[i], nvCol->Get(keys[i])); + } + + Console::WriteLine(); +} \ No newline at end of file diff --git a/Chapter07/QueueStack.cpp b/Chapter07/QueueStack.cpp new file mode 100644 index 0000000..59d76bf --- /dev/null +++ b/Chapter07/QueueStack.cpp @@ -0,0 +1,32 @@ +using namespace System; +using namespace System::Collections; + +void main() +{ + Queue ^que = gcnew Queue(); + Stack ^stk = gcnew Stack(); + + array^ entry = gcnew array { "First", "Second", "Third", "Fourth" }; + + Console::WriteLine("Queue\t\tStack"); + + Console::WriteLine("** ON **"); + for (int i = 0; i < entry->Length; i++) + { + que->Enqueue(entry[i]); + stk->Push(entry[i]); + + Console::WriteLine("{0}\t\t{1}", entry[i], entry[i]); + } + + Console::WriteLine("\n** OFF **"); + while ((que->Count > 0) && (stk->Count > 0)) + { + Console::WriteLine("{0}\t\t{1}", que->Dequeue(), stk->Pop()); + } + + que->Clear(); + stk->Clear(); + + Console::WriteLine(""); +} \ No newline at end of file diff --git a/Chapter07/QueueStackGeneric.cpp b/Chapter07/QueueStackGeneric.cpp new file mode 100644 index 0000000..ec0b4ba --- /dev/null +++ b/Chapter07/QueueStackGeneric.cpp @@ -0,0 +1,36 @@ +#using + +using namespace System; +using namespace System::Collections::Generic; + +void main() +{ + Queue^ que = gcnew Queue(); + Stack^ stk = gcnew Stack(); + + array^ entry = gcnew array { + "First", "Second", "Third", "Fourth" + }; + + Console::WriteLine("Queue\t\tStack"); + + Console::WriteLine("** ON **"); + for (int i = 0; i < entry->Length; i++) + { + que->Enqueue(entry[i]); + stk->Push(entry[i]); + + Console::WriteLine("{0}\t\t{1}", entry[i], entry[i]); + } + + Console::WriteLine("\n** OFF **"); + while ((que->Count > 0) && (stk->Count > 0)) + { + Console::WriteLine("{0}\t\t{1}", que->Dequeue(), stk->Pop()); + } + + que->Clear(); + stk->Clear(); + + Console::WriteLine("\n"); +} diff --git a/Chapter07/StringColl.cpp b/Chapter07/StringColl.cpp new file mode 100644 index 0000000..c63978b --- /dev/null +++ b/Chapter07/StringColl.cpp @@ -0,0 +1,32 @@ +#using + +using namespace System; +using namespace System::Collections; +using namespace System::Collections::Specialized; + +void main() +{ + StringCollection ^strcol = gcnew StringCollection(); + + strcol->Add("The first String"); + + array^ tmpstr = gcnew array {"Third", "Fourth" }; + strcol->AddRange(tmpstr); + + strcol->Insert(1, "Second"); + + strcol[0] = "First"; + + StringEnumerator ^strenum = strcol->GetEnumerator(); + while ( strenum->MoveNext()) + { + Console::WriteLine(strenum->Current); + } + + Console::WriteLine("\n'for each' works as well"); + + for each (String^ s in strcol) + Console::WriteLine(s); + + Console::WriteLine(); +} \ No newline at end of file diff --git a/Chapter07/StringDict.cpp b/Chapter07/StringDict.cpp new file mode 100644 index 0000000..cc08002 --- /dev/null +++ b/Chapter07/StringDict.cpp @@ -0,0 +1,27 @@ +#using + +using namespace System; +using namespace System::Collections; +using namespace System::Collections::Specialized; + +void main() +{ + StringDictionary ^strdict = gcnew StringDictionary(); + + strdict->Add("Dog", "Four leg, hydrant loving, barking, mammal"); + strdict->Add("Frog", "Green, jumping, croaking, amphibian"); + + strdict["Crocodile"] = "Ugly, boot origin, snapping, reptile"; + + ArrayList ^alist = gcnew ArrayList(); + alist->AddRange(strdict->Keys); + alist->Sort(); + + for (int i = 0; i < alist->Count; i++) + { + Console::WriteLine("{0,10}:\t{1}", alist[i], + strdict[(String^)alist[i]]); + } + + Console::WriteLine(); +} \ No newline at end of file diff --git a/Chapter07/arraylist.cpp b/Chapter07/arraylist.cpp new file mode 100644 index 0000000..c3a45fc --- /dev/null +++ b/Chapter07/arraylist.cpp @@ -0,0 +1,41 @@ +using namespace System; +using namespace System::Collections; + +void main() +{ + ArrayList ^alist = gcnew ArrayList(4); // will double to 8 + alist->Add("One"); + alist->Add("-"); + alist[1] = "Three"; + + alist->Insert(1, "Two"); + + array^ morenums = gcnew array {"Four", "Five"}; + + alist->AddRange(morenums); + + alist->Reverse(); + + Console::WriteLine("*** The ArrayList ***"); + for (int i = 0; i < alist->Count; i++) + { + Console::Write("{0} ", alist[i]); + } + + Console::WriteLine("\n\nCapacity is: {0}", alist->Capacity.ToString()); + + alist->Capacity = 10; + Console::WriteLine("New capacity is: {0}", alist->Capacity.ToString()); + + Console::WriteLine("Count is: {0}", alist->Count.ToString()); + + alist->Sort(); + + int indx = alist->BinarySearch("Four"); + Console::WriteLine("Four found at index: {0}", indx.ToString()); + + bool fnd = alist->Contains("One"); + Console::WriteLine("ArrayList contains a 'One': {0}", fnd.ToString()); + + Console::WriteLine(); +} \ No newline at end of file diff --git a/Chapter07/bitarray.cpp b/Chapter07/bitarray.cpp new file mode 100644 index 0000000..80c5c39 --- /dev/null +++ b/Chapter07/bitarray.cpp @@ -0,0 +1,52 @@ +using namespace System; +using namespace System::Collections; + +void Print( BitArray ^barray, String ^desc) +{ + Console::WriteLine(desc); + + int i = 0; + for each( bool^ val in barray ) + { + Console::Write("{0} ", val); + + if (++i > 7) + { + Console::WriteLine(); + i = 0; + } + } + Console::WriteLine(); +} + +void main() +{ + BitArray ^barray1 = gcnew BitArray( 8, true ); + Print(barray1, "BitArray( 8, true );"); + + barray1[1] = false; + barray1[4] = false; + barray1->Not(); + Print(barray1, "Modified bit 1&4 then Not"); + + BitArray ^barray2 = gcnew BitArray( 8, true ); + barray2->And(barray1); + Print(barray2, "And with BitArray( 8, true )"); + + barray2->SetAll(true); + barray2->Or(barray1); + Print(barray2, "Or with BitArray( 8, true )"); + + barray2->SetAll(true); + barray2->Xor(barray1); + Print(barray2, "Xor with BitArray( 8, true )"); + + array^ chars = gcnew array { 0x55, 0xAA }; + BitArray ^barray3 = gcnew BitArray( chars ); + Print(barray3, "BitArray(0x55, 0xAA);"); + + Console::WriteLine("Item[0]={0}", barray3[0]); + Console::WriteLine("Item[8]={0}", barray3[8]); + + Console::WriteLine(); +} \ No newline at end of file diff --git a/Chapter07/buildall.bat b/Chapter07/buildall.bat new file mode 100644 index 0000000..7ecbb3c --- /dev/null +++ b/Chapter07/buildall.bat @@ -0,0 +1,13 @@ +cl arraylist.cpp /clr:safe +cl bitarray.cpp /clr:safe +cl DictionaryGeneric.cpp /clr:safe +cl HashSortList.cpp /clr:safe +cl IEnum_foreach.cpp /clr:safe +cl LinkedListGeneric.cpp /clr:safe +cl ListDict.cpp /clr:safe +cl ListGeneric.cpp /clr:safe +cl NameValue.cpp /clr:safe +cl QueueStack.cpp /clr:safe +cl QueueStackGeneric.cpp /clr:safe +cl StringColl.cpp /clr:safe +cl StringDict.cpp /clr:safe diff --git a/Chapter08/BinFormSerial.cpp b/Chapter08/BinFormSerial.cpp new file mode 100644 index 0000000..baa1b8c --- /dev/null +++ b/Chapter08/BinFormSerial.cpp @@ -0,0 +1,96 @@ +using namespace System; +using namespace System::IO; +using namespace System::Runtime::Serialization::Formatters::Binary; + +// --------- Player Attribute class ------------------------------------ + +[Serializable] +ref class PlayerAttr +{ +public: + property int Strength; + property int Dexterity; + property int Constitution; + property int Intelligence; + property int Wisdom; + property int Charisma; + + PlayerAttr(int Str, int Dex, int Con, int Int, int Wis, int Cha); + void Print(); +}; + +PlayerAttr::PlayerAttr(int Str, int Dex, int Con, int Int, int Wis, int Cha) +{ + this->Strength = Str; + this->Dexterity = Dex; + this->Constitution = Con; + this->Intelligence = Int; + this->Wisdom = Wis; + this->Charisma = Cha; +} + +void PlayerAttr::Print() +{ + Console::WriteLine("Str: {0}, Dex: {1}, Con {2}", + Strength, Dexterity, Constitution); + Console::WriteLine("Int: {0}, Wis: {1}, Cha {2}", + Intelligence, Wisdom, Charisma); +} + +// -------- Player class --------------------------------------- + +[Serializable] +ref class Player +{ +public: + property String ^Name; + property String ^Race; + property String ^Class; + property PlayerAttr ^pattr; + + Player (String ^Name, String ^Race, String ^Class, + int Str, int Dex, int Con, int Int, int Wis, int Cha); + void Print(); +}; + +Player::Player (String ^Name, String ^Race, String ^Class, + int Str, int Dex, int Con, int Int, int Wis, int Cha) +{ + this->Name = Name; + this->Race = Race; + this->Class = Class; + this->pattr = gcnew PlayerAttr(Str, Dex, Con, Int, Wis, Cha); +} + +void Player::Print() +{ + Console::WriteLine("Name: {0}", Name); + Console::WriteLine("Race: {0}", Race); + Console::WriteLine("Class: {0}", Class); + pattr->Print(); +} + +// -------- Main Function ---------------------------------------------- + + +Int32 main(void) +{ + Player ^Joe = gcnew Player("Joe", "Human", "Thief", 10, 18, 9, 13,10, 11); + + Console::WriteLine("Original Joe"); + Joe->Print(); + + FileStream ^plStream = File::Create("Player.dat"); + + BinaryFormatter ^bf = gcnew BinaryFormatter(); + bf->Serialize(plStream, Joe); + plStream->Close(); + + plStream = File::OpenRead("Player.dat"); + + Player ^JoeClone = (Player^)bf->Deserialize(plStream); + plStream->Close(); + + Console::WriteLine("\nCloned Joe"); + JoeClone->Print(); +} \ No newline at end of file diff --git a/Chapter08/BinaryRW.cpp b/Chapter08/BinaryRW.cpp new file mode 100644 index 0000000..e9d7bb0 --- /dev/null +++ b/Chapter08/BinaryRW.cpp @@ -0,0 +1,89 @@ +using namespace System; +using namespace System::IO; +using namespace System::Runtime::Serialization::Formatters::Binary; + +// ------ Player class --------------------------------------------- + +ref class Player +{ + String ^Name; + Int32 Strength; + Boolean IsMale; + DateTime CreateDate; + +public: + Player(); + Player (String ^Name, int Str, bool IsMale); + + void Print(); + void Save(String ^fname); + void Load(String ^fname); +}; + +Player::Player() +{ +} + +Player::Player (String ^Name, int Str, bool IsMale) +{ + this->Name = Name; + this->Strength = Str; + this->IsMale = IsMale; + this->CreateDate = DateTime::Now; +} + +void Player::Print() +{ + Console::WriteLine("Name: {0} ({1})", Name, (IsMale ? "M" : "F")); + Console::WriteLine("Str: {0}", Strength); + Console::WriteLine("Date: {0}", CreateDate.ToString()); +} + +void Player::Save(String ^fname) +{ + FileStream ^fs = File::OpenWrite(fname); + BinaryWriter ^bw = gcnew BinaryWriter(fs); + + bw->Write(Name); + bw->Write(Strength); + bw->Write(IsMale); + + // Due to multicultures this is a safe way of storing DateTimes + bw->Write(CreateDate.Ticks); + + bw->Close(); + fs->Close(); +} + +void Player::Load(String ^fname) +{ + FileStream ^fs = File::OpenRead(fname); + BinaryReader ^br = gcnew BinaryReader(fs); + + Name = br->ReadString(); + Strength = br->ReadInt32(); + IsMale = br->ReadBoolean(); + + // Due to multicultures this is a safe way of retrieving DateTimes + CreateDate = DateTime( br->ReadInt64() ); + + br->Close(); + fs->Close(); +} + +// ------- Main Function --------------------------------------------- + +void main() +{ + Player ^Joe = gcnew Player("Joe", 10, true); + Joe->Save("Player.dat"); + + Console::WriteLine("Original Joe"); + Joe->Print(); + + Player ^JoeClone = gcnew Player(); + JoeClone->Load("Player.dat"); + + Console::WriteLine("\nCloned Joe"); + JoeClone->Print(); +} \ No newline at end of file diff --git a/Chapter08/DirInfo.cpp b/Chapter08/DirInfo.cpp new file mode 100644 index 0000000..9574125 --- /dev/null +++ b/Chapter08/DirInfo.cpp @@ -0,0 +1,75 @@ +using namespace System; +using namespace System::IO; +using namespace System::Text; + +int main(array ^args) +{ + if (args->Length == 0) + { + Console::WriteLine("Usage: DirInfo "); + return -1; + } + + StringBuilder ^tmppath = gcnew StringBuilder(); + + for each (String^ s in args) + { + tmppath->Append(s); + tmppath->Append(" "); + } + + String ^path = tmppath->ToString()->Trim(); + + DirectoryInfo ^dir = gcnew DirectoryInfo(path); + + if (!dir->Exists) + { + Console::WriteLine("Directory Not Found"); + return -1; + } + + Console::WriteLine("Name: {0}", dir->FullName); + + Console::WriteLine("Created: {0} {1}", + dir->CreationTime.ToShortDateString(), + dir->CreationTime.ToLongTimeString()); + + Console::WriteLine("Accessed: {0} {1}", + dir->LastAccessTime.ToShortDateString(), + dir->LastAccessTime.ToLongTimeString()); + + Console::WriteLine("Updated: {0} {1}", + dir->LastWriteTime.ToShortDateString(), + dir->LastWriteTime.ToLongTimeString()); + + Console::WriteLine("Attributes: {0}", + dir->Attributes); + + Console::WriteLine("Sub-Directories:"); + + array^ subDirs = dir->GetDirectories(); + if (subDirs->Length == 0) + Console::WriteLine("\tNone."); + else + { + for each (DirectoryInfo^ dinfo in subDirs) + { + Console::WriteLine("\t{0}", dinfo->Name); + } + } + + Console::WriteLine("Files:"); + + array^ files = dir->GetFiles(); + if (files->Length == 0) + Console::WriteLine("\tNone."); + else + { + for each (FileInfo^ finfo in files) + { + Console::WriteLine("\t{0}", finfo->Name); + } + } + + return 0; +} diff --git a/Chapter08/FileInfo.cpp b/Chapter08/FileInfo.cpp new file mode 100644 index 0000000..6d635b1 --- /dev/null +++ b/Chapter08/FileInfo.cpp @@ -0,0 +1,50 @@ +using namespace System; +using namespace System::IO; +using namespace System::Text; + +int main(array ^args) +{ + if (args->Length == 0) + { + Console::WriteLine("Usage: FileInfo "); + return -1; + } + + StringBuilder ^tmpfile = gcnew StringBuilder(); + + for each (String^ s in args) + { + tmpfile->Append(s); + tmpfile->Append(" "); + } + + String ^strfile = tmpfile->ToString()->Trim(); + + FileInfo ^fileinfo = gcnew FileInfo(strfile); + + if (!fileinfo->Exists) + { + Console::WriteLine("File Not Found"); + return -1; + } + + Console::WriteLine("Name: {0}", fileinfo->FullName); + + Console::WriteLine("Created: {0} {1}", + fileinfo->CreationTime.ToShortDateString(), + fileinfo->CreationTime.ToLongTimeString()); + + Console::WriteLine("Accessed: {0} {1}", + fileinfo->LastAccessTime.ToShortDateString(), + fileinfo->LastAccessTime.ToLongTimeString()); + + Console::WriteLine("Updated: {0} {1}", + fileinfo->LastWriteTime.ToShortDateString(), + fileinfo->LastWriteTime.ToLongTimeString()); + + Console::WriteLine("Length: {0}", fileinfo->Length); + + Console::WriteLine("Attributes: {0}", fileinfo->Attributes); + + return 0; +} \ No newline at end of file diff --git a/Chapter08/FileStream.cpp b/Chapter08/FileStream.cpp new file mode 100644 index 0000000..9f52894 --- /dev/null +++ b/Chapter08/FileStream.cpp @@ -0,0 +1,50 @@ +using namespace System; +using namespace System::IO; + +void main() +{ + FileStream ^fso = gcnew FileStream("file.dat", FileMode::Create, + FileAccess::Write, FileShare::None); + + array^ data = gcnew array { 'T', 'h', 'i', + 's', ' ', 'i', 's', ' ', 'a', ' ', 't', 'e', + 's', 't', '!', '\r', '\n', 'T', 'h', 'i', 's', + ' ', 'i', 's', ' ', 'o', 'n', 'l', 'y', ' ', + 'a', ' ', 't', 'e', 's', 't', '.','\r', '\n' }; + + for (int i = 0; i < data->Length-5; i += 5) + { + fso->Write(data, i, 5); + } + + for (int i = data->Length-4; i < data->Length; i++) + { + fso->WriteByte(data[i]); + } + + fso->Close(); + + FileInfo ^fi = gcnew FileInfo("file.dat"); + FileStream ^fsi = fi->OpenRead(); + + int b; + while ((b = fsi->ReadByte()) != -1) + { + Console::Write((Char)b); + } + + fsi->Position = 0; + + array^ ca = gcnew array(17); + fsi->Read(ca, 0, 17); + for (int i = 0; i < ca->Length; i++) + { + Console::Write((Char)ca[i]); + } + + Console::WriteLine(); + + fsi->Close(); + + fi->Delete(); // If you want to get rid of it +} \ No newline at end of file diff --git a/Chapter08/MemoryStream.cpp b/Chapter08/MemoryStream.cpp new file mode 100644 index 0000000..6e77304 --- /dev/null +++ b/Chapter08/MemoryStream.cpp @@ -0,0 +1,38 @@ +using namespace System; +using namespace System::IO; + +void main() +{ + array^ data = gcnew array { 'T', 'h', 'i', + 's', ' ', 'i', 's', ' ', 'a', ' ', 't', 'e', 's', 't', + '!', '\r', '\n', 'T', 'h', 'i', 's', ' ', 'i', 's', ' ', + 'o', 'n', 'l', 'y', ' ', 'a', ' ', 't', 'e', 's', 't', + '.','\r', '\n' }; + + MemoryStream ^ms = gcnew MemoryStream(); + ms->Capacity = 40; + + for (int i = 0; i < data->Length-5; i += 5) + { + ms->Write(data, i, 5); + } + + for (int i = data->Length-4; i < data->Length; i++) + { + ms->WriteByte(data[i]); + } + + array^ ca = ms->GetBuffer(); + for each (unsigned char c in ca) + { + Console::Write((Char)c); + } + Console::WriteLine(); + + FileStream ^fs = File::OpenWrite("file.dat"); + + ms->WriteTo(fs); + + fs->Close(); + ms->Close(); +} \ No newline at end of file diff --git a/Chapter08/SoapFormSerial.cpp b/Chapter08/SoapFormSerial.cpp new file mode 100644 index 0000000..f939321 --- /dev/null +++ b/Chapter08/SoapFormSerial.cpp @@ -0,0 +1,98 @@ +#using + +using namespace System; +using namespace System::IO; +using namespace System::Runtime::Serialization::Formatters::Soap; + +// --------- Player Attribute class ------------------------------------ + +[Serializable] +ref class PlayerAttr +{ +public: + property int Strength; + property int Dexterity; + property int Constitution; + property int Intelligence; + property int Wisdom; + property int Charisma; + + PlayerAttr(int Str, int Dex, int Con, int Int, int Wis, int Cha); + void Print(); +}; + +PlayerAttr::PlayerAttr(int Str, int Dex, int Con, int Int, int Wis, int Cha) +{ + this->Strength = Str; + this->Dexterity = Dex; + this->Constitution = Con; + this->Intelligence = Int; + this->Wisdom = Wis; + this->Charisma = Cha; +} + +void PlayerAttr::Print() +{ + Console::WriteLine("Str: {0}, Dex: {1}, Con {2}", + Strength, Dexterity, Constitution); + Console::WriteLine("Int: {0}, Wis: {1}, Cha {2}", + Intelligence, Wisdom, Charisma); +} + +// -------- Player class --------------------------------------- + +[Serializable] +ref class Player +{ +public: + property String ^Name; + property String ^Race; + property String ^Class; + property PlayerAttr ^pattr; + + Player (String ^Name, String ^Race, String ^Class, + int Str, int Dex, int Con, int Int, int Wis, int Cha); + void Print(); +}; + +Player::Player (String ^Name, String ^Race, String ^Class, + int Str, int Dex, int Con, int Int, int Wis, int Cha) +{ + this->Name = Name; + this->Race = Race; + this->Class = Class; + this->pattr = gcnew PlayerAttr(Str, Dex, Con, Int, Wis, Cha); +} + +void Player::Print() +{ + Console::WriteLine("Name: {0}", Name); + Console::WriteLine("Race: {0}", Race); + Console::WriteLine("Class: {0}", Class); + pattr->Print(); +} + +// -------- Main Function ---------------------------------------------- + + +int main(void) +{ + Player ^Joe = gcnew Player("Joe", "Human", "Thief", 10, 18, 9, 13,10, 11); + + Console::WriteLine("Original Joe"); + Joe->Print(); + + FileStream ^plStream = File::Create("Player.xml"); + + SoapFormatter ^sf = gcnew SoapFormatter(); + sf->Serialize(plStream, Joe); + plStream->Close(); + + plStream = File::OpenRead("Player.xml"); + + Player ^JoeClone = (Player^)sf->Deserialize(plStream); + plStream->Close(); + + Console::WriteLine("\nCloned Joe"); + JoeClone->Print(); +} \ No newline at end of file diff --git a/Chapter08/StreamRW.cpp b/Chapter08/StreamRW.cpp new file mode 100644 index 0000000..9b9f02a --- /dev/null +++ b/Chapter08/StreamRW.cpp @@ -0,0 +1,30 @@ +using namespace System; +using namespace System::IO; + +void main() +{ + array^ data = gcnew array { + "This is ", "a test!", "This is only a test." }; + + StreamWriter ^sw = gcnew StreamWriter(gcnew FileStream("file.dat", + FileMode::Create, FileAccess::Write, FileShare::None)); + + for (int i = 0; i < data->Length-1; i++) + { + sw->Write(data[i]); + } + sw->WriteLine(); + + sw->WriteLine(data[2]); + + sw->Close(); + + StreamReader ^sr = File::OpenText("file.dat"); + + String^ in = sr->ReadLine(); + Console::WriteLine(in); + + Console::WriteLine(sr->ReadToEnd()); + + sw->Close(); +} \ No newline at end of file diff --git a/Chapter08/buildall.bat b/Chapter08/buildall.bat new file mode 100644 index 0000000..5ced349 --- /dev/null +++ b/Chapter08/buildall.bat @@ -0,0 +1,8 @@ +cl BinaryRW.cpp /clr:safe +cl BinFormSerial.cpp /clr:safe +cl DirInfo.cpp /clr +cl FileInfo.cpp /clr +cl filestream.cpp /clr:safe +cl memorystream.cpp /clr:safe +cl SoapFormSerial.cpp /clr:safe +cl StreamRW.cpp /clr:safe diff --git a/Chapter09/ArrayOfRadios/ArrayOfRadios.cpp b/Chapter09/ArrayOfRadios/ArrayOfRadios.cpp new file mode 100644 index 0000000..f02d3dc --- /dev/null +++ b/Chapter09/ArrayOfRadios/ArrayOfRadios.cpp @@ -0,0 +1,18 @@ +// ArrayOfRadios.cpp : main project file. + +#include "stdafx.h" +#include "Form1.h" + +using namespace ArrayOfRadios; + +[STAThreadAttribute] +int main(array ^args) +{ + // Enabling Windows XP visual effects before any controls are created + Application::EnableVisualStyles(); + Application::SetCompatibleTextRenderingDefault(false); + + // Create the main window and run it + Application::Run(gcnew Form1()); + return 0; +} diff --git a/Chapter09/ArrayOfRadios/ArrayOfRadios.vcproj b/Chapter09/ArrayOfRadios/ArrayOfRadios.vcproj new file mode 100644 index 0000000..e3a8644 --- /dev/null +++ b/Chapter09/ArrayOfRadios/ArrayOfRadios.vcproj @@ -0,0 +1,250 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Chapter09/ArrayOfRadios/AssemblyInfo.cpp b/Chapter09/ArrayOfRadios/AssemblyInfo.cpp new file mode 100644 index 0000000..cf0c58d --- /dev/null +++ b/Chapter09/ArrayOfRadios/AssemblyInfo.cpp @@ -0,0 +1,40 @@ +#include "stdafx.h" + +using namespace System; +using namespace System::Reflection; +using namespace System::Runtime::CompilerServices; +using namespace System::Runtime::InteropServices; +using namespace System::Security::Permissions; + +// +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +// +[assembly:AssemblyTitleAttribute("ArrayOfRadios")]; +[assembly:AssemblyDescriptionAttribute("")]; +[assembly:AssemblyConfigurationAttribute("")]; +[assembly:AssemblyCompanyAttribute("")]; +[assembly:AssemblyProductAttribute("ArrayOfRadios")]; +[assembly:AssemblyCopyrightAttribute("Copyright (c) 2005")]; +[assembly:AssemblyTrademarkAttribute("")]; +[assembly:AssemblyCultureAttribute("")]; + +// +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the value or you can default the Revision and Build Numbers +// by using the '*' as shown below: + +[assembly:AssemblyVersionAttribute("1.0.*")]; + +[assembly:ComVisible(false)]; + +[assembly:CLSCompliantAttribute(true)]; + +[assembly:SecurityPermission(SecurityAction::RequestMinimum, UnmanagedCode = true)]; diff --git a/Chapter09/ArrayOfRadios/Form1.h b/Chapter09/ArrayOfRadios/Form1.h new file mode 100644 index 0000000..526fb11 --- /dev/null +++ b/Chapter09/ArrayOfRadios/Form1.h @@ -0,0 +1,86 @@ +#pragma once + +namespace ArrayOfRadios +{ + using namespace System; + using namespace System::ComponentModel; + using namespace System::Collections; + using namespace System::Windows::Forms; + using namespace System::Data; + using namespace System::Drawing; + + public ref class Form1 : public System::Windows::Forms::Form + { + public: + Form1(void) + { + InitializeComponent(); + + array^ rbText = gcnew array { + L"Can", L"You", L"Click", L"More", L"Than", L"One" + }; + radios = gcnew array(6); + label = gcnew Label(); + + for (int i = 0; i < radios->Length; i++) + { + int j = 50*i; + radios[i] = gcnew RadioButton(); + radios[i]->BackColor = Color::FromArgb(255,j+5,j+5,j+5); + radios[i]->ForeColor = Color::FromArgb(255,250-j,250-j,250-j); + radios[i]->Location = Drawing::Point(90, 10+(40*i)); + radios[i]->TabIndex = i; + radios[i]->TabStop = true; + radios[i]->Text = rbText[i]; + radios[i]->CheckedChanged += + gcnew EventHandler(this, &Form1::radioCheckedChanged); + } + Controls->AddRange(radios); + + label->Location = Drawing::Point(90, 10+(40*radios->Length)); + Controls->Add(label); + } + + protected: + ~Form1() + { + if (components) + { + delete components; + } + } + + private: + array^ radios; + Label ^label; + System::ComponentModel::Container ^components; + +#pragma region Windows Form Designer generated code + + void InitializeComponent(void) + { + this->SuspendLayout(); + // + // Form1 + // + this->AutoScaleDimensions = System::Drawing::SizeF(6, 13); + this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font; + this->ClientSize = System::Drawing::Size(292, 273); + this->Name = L"Form1"; + this->Text = L"An Array Of Radios"; + this->ResumeLayout(false); + + } +#pragma endregion + + private: + void radioCheckedChanged(Object ^sender, EventArgs ^e) + { + RadioButton ^rb = (RadioButton^)sender; + + if (rb->Checked == true) + label->Text = rb->Text; + } + }; +} + diff --git a/Chapter09/ArrayOfRadios/Form1.resx b/Chapter09/ArrayOfRadios/Form1.resx new file mode 100644 index 0000000..7080a7d --- /dev/null +++ b/Chapter09/ArrayOfRadios/Form1.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Chapter09/ArrayOfRadios/stdafx.cpp b/Chapter09/ArrayOfRadios/stdafx.cpp new file mode 100644 index 0000000..b8dd4c0 --- /dev/null +++ b/Chapter09/ArrayOfRadios/stdafx.cpp @@ -0,0 +1,7 @@ +// stdafx.cpp : source file that includes just the standard includes +// ArrayOfRadios.pch will be the pre-compiled header +// stdafx.obj will contain the pre-compiled type information + +#include "stdafx.h" + + diff --git a/Chapter09/ArrayOfRadios/stdafx.h b/Chapter09/ArrayOfRadios/stdafx.h new file mode 100644 index 0000000..46bef73 --- /dev/null +++ b/Chapter09/ArrayOfRadios/stdafx.h @@ -0,0 +1,6 @@ +// stdafx.h : include file for standard system include files, +// or project specific include files that are used frequently, but +// are changed infrequently +#pragma once + +// TODO: reference additional headers your program requires here diff --git a/Chapter09/Chapter09.sln b/Chapter09/Chapter09.sln new file mode 100644 index 0000000..187ea1e --- /dev/null +++ b/Chapter09/Chapter09.sln @@ -0,0 +1,104 @@ + +Microsoft Visual Studio Solution File, Format Version 9.00 +# Visual Studio 2005 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ArrayOfRadios", "ArrayOfRadios\ArrayOfRadios.vcproj", "{5DA11E94-FBA3-4247-BBB2-767AA84A96C0}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "CheckMe", "CheckMe\CheckMe.vcproj", "{071A6F09-3A5E-49CB-8249-B7BB7B270DB3}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "CustomHello", "CustomHello\CustomHello.vcproj", "{344F8A49-4411-4A95-80A0-B1C625EBC6B0}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "GroupingRadios", "GroupingRadios\GroupingRadios.vcproj", "{579022FD-9B93-4339-AB14-9406D0A16389}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Hello", "Hello\Hello.vcproj", "{1E55F865-7E76-4C7E-856A-679810CC5E45}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ListTransfers", "ListTransfers\ListTransfers.vcproj", "{B7E70C29-D7BE-47DF-A5ED-EA7EE70E7259}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "MightyLabel", "MightyLabel\MightyLabel.vcproj", "{DEB8DB95-E0D5-47D5-BD85-5CB81BCB0087}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "MinuteTimer", "MinuteTimer\MinuteTimer.vcproj", "{9AEDD737-A8E6-4461-A13B-DC727345CD60}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "MouseJump", "MouseJump\MouseJump.vcproj", "{9E295046-5F85-4DC3-9B4B-FBFC6958F792}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Panels", "Panels\Panels.vcproj", "{A61DE735-8D7E-4FB2-BC6C-673E415E298E}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "RichText", "RichText\RichText.vcproj", "{7E94547E-291F-45C0-BA26-DC8B144B4C8B}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "SplitCLB", "SplitCLB\SplitCLB.vcproj", "{F69D9B1C-70F1-48EC-A1C5-E7B3956CDABC}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "SyncCombos", "SyncCombos\SyncCombos.vcproj", "{4297C3DE-E28C-4ADD-A690-ACCC79F225CC}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "TextEntry", "TextEntry\TextEntry.vcproj", "{8FA40ED0-3404-43E9-AAFF-0F68CA4A3E2D}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "TooManyButtons", "TooManyButtons\TooManyButtons.vcproj", "{B4795061-9118-4355-BAD0-215DFAFF3FCD}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Win32 = Debug|Win32 + Release|Win32 = Release|Win32 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {5DA11E94-FBA3-4247-BBB2-767AA84A96C0}.Debug|Win32.ActiveCfg = Debug|Win32 + {5DA11E94-FBA3-4247-BBB2-767AA84A96C0}.Debug|Win32.Build.0 = Debug|Win32 + {5DA11E94-FBA3-4247-BBB2-767AA84A96C0}.Release|Win32.ActiveCfg = Release|Win32 + {5DA11E94-FBA3-4247-BBB2-767AA84A96C0}.Release|Win32.Build.0 = Release|Win32 + {071A6F09-3A5E-49CB-8249-B7BB7B270DB3}.Debug|Win32.ActiveCfg = Debug|Win32 + {071A6F09-3A5E-49CB-8249-B7BB7B270DB3}.Debug|Win32.Build.0 = Debug|Win32 + {071A6F09-3A5E-49CB-8249-B7BB7B270DB3}.Release|Win32.ActiveCfg = Release|Win32 + {071A6F09-3A5E-49CB-8249-B7BB7B270DB3}.Release|Win32.Build.0 = Release|Win32 + {344F8A49-4411-4A95-80A0-B1C625EBC6B0}.Debug|Win32.ActiveCfg = Debug|Win32 + {344F8A49-4411-4A95-80A0-B1C625EBC6B0}.Debug|Win32.Build.0 = Debug|Win32 + {344F8A49-4411-4A95-80A0-B1C625EBC6B0}.Release|Win32.ActiveCfg = Release|Win32 + {344F8A49-4411-4A95-80A0-B1C625EBC6B0}.Release|Win32.Build.0 = Release|Win32 + {579022FD-9B93-4339-AB14-9406D0A16389}.Debug|Win32.ActiveCfg = Debug|Win32 + {579022FD-9B93-4339-AB14-9406D0A16389}.Debug|Win32.Build.0 = Debug|Win32 + {579022FD-9B93-4339-AB14-9406D0A16389}.Release|Win32.ActiveCfg = Release|Win32 + {579022FD-9B93-4339-AB14-9406D0A16389}.Release|Win32.Build.0 = Release|Win32 + {1E55F865-7E76-4C7E-856A-679810CC5E45}.Debug|Win32.ActiveCfg = Debug|Win32 + {1E55F865-7E76-4C7E-856A-679810CC5E45}.Debug|Win32.Build.0 = Debug|Win32 + {1E55F865-7E76-4C7E-856A-679810CC5E45}.Release|Win32.ActiveCfg = Release|Win32 + {1E55F865-7E76-4C7E-856A-679810CC5E45}.Release|Win32.Build.0 = Release|Win32 + {B7E70C29-D7BE-47DF-A5ED-EA7EE70E7259}.Debug|Win32.ActiveCfg = Debug|Win32 + {B7E70C29-D7BE-47DF-A5ED-EA7EE70E7259}.Debug|Win32.Build.0 = Debug|Win32 + {B7E70C29-D7BE-47DF-A5ED-EA7EE70E7259}.Release|Win32.ActiveCfg = Release|Win32 + {B7E70C29-D7BE-47DF-A5ED-EA7EE70E7259}.Release|Win32.Build.0 = Release|Win32 + {DEB8DB95-E0D5-47D5-BD85-5CB81BCB0087}.Debug|Win32.ActiveCfg = Debug|Win32 + {DEB8DB95-E0D5-47D5-BD85-5CB81BCB0087}.Debug|Win32.Build.0 = Debug|Win32 + {DEB8DB95-E0D5-47D5-BD85-5CB81BCB0087}.Release|Win32.ActiveCfg = Release|Win32 + {DEB8DB95-E0D5-47D5-BD85-5CB81BCB0087}.Release|Win32.Build.0 = Release|Win32 + {9AEDD737-A8E6-4461-A13B-DC727345CD60}.Debug|Win32.ActiveCfg = Debug|Win32 + {9AEDD737-A8E6-4461-A13B-DC727345CD60}.Debug|Win32.Build.0 = Debug|Win32 + {9AEDD737-A8E6-4461-A13B-DC727345CD60}.Release|Win32.ActiveCfg = Release|Win32 + {9AEDD737-A8E6-4461-A13B-DC727345CD60}.Release|Win32.Build.0 = Release|Win32 + {9E295046-5F85-4DC3-9B4B-FBFC6958F792}.Debug|Win32.ActiveCfg = Debug|Win32 + {9E295046-5F85-4DC3-9B4B-FBFC6958F792}.Debug|Win32.Build.0 = Debug|Win32 + {9E295046-5F85-4DC3-9B4B-FBFC6958F792}.Release|Win32.ActiveCfg = Release|Win32 + {9E295046-5F85-4DC3-9B4B-FBFC6958F792}.Release|Win32.Build.0 = Release|Win32 + {A61DE735-8D7E-4FB2-BC6C-673E415E298E}.Debug|Win32.ActiveCfg = Debug|Win32 + {A61DE735-8D7E-4FB2-BC6C-673E415E298E}.Debug|Win32.Build.0 = Debug|Win32 + {A61DE735-8D7E-4FB2-BC6C-673E415E298E}.Release|Win32.ActiveCfg = Release|Win32 + {A61DE735-8D7E-4FB2-BC6C-673E415E298E}.Release|Win32.Build.0 = Release|Win32 + {7E94547E-291F-45C0-BA26-DC8B144B4C8B}.Debug|Win32.ActiveCfg = Debug|Win32 + {7E94547E-291F-45C0-BA26-DC8B144B4C8B}.Debug|Win32.Build.0 = Debug|Win32 + {7E94547E-291F-45C0-BA26-DC8B144B4C8B}.Release|Win32.ActiveCfg = Release|Win32 + {7E94547E-291F-45C0-BA26-DC8B144B4C8B}.Release|Win32.Build.0 = Release|Win32 + {F69D9B1C-70F1-48EC-A1C5-E7B3956CDABC}.Debug|Win32.ActiveCfg = Debug|Win32 + {F69D9B1C-70F1-48EC-A1C5-E7B3956CDABC}.Debug|Win32.Build.0 = Debug|Win32 + {F69D9B1C-70F1-48EC-A1C5-E7B3956CDABC}.Release|Win32.ActiveCfg = Release|Win32 + {F69D9B1C-70F1-48EC-A1C5-E7B3956CDABC}.Release|Win32.Build.0 = Release|Win32 + {4297C3DE-E28C-4ADD-A690-ACCC79F225CC}.Debug|Win32.ActiveCfg = Debug|Win32 + {4297C3DE-E28C-4ADD-A690-ACCC79F225CC}.Debug|Win32.Build.0 = Debug|Win32 + {4297C3DE-E28C-4ADD-A690-ACCC79F225CC}.Release|Win32.ActiveCfg = Release|Win32 + {4297C3DE-E28C-4ADD-A690-ACCC79F225CC}.Release|Win32.Build.0 = Release|Win32 + {8FA40ED0-3404-43E9-AAFF-0F68CA4A3E2D}.Debug|Win32.ActiveCfg = Debug|Win32 + {8FA40ED0-3404-43E9-AAFF-0F68CA4A3E2D}.Debug|Win32.Build.0 = Debug|Win32 + {8FA40ED0-3404-43E9-AAFF-0F68CA4A3E2D}.Release|Win32.ActiveCfg = Release|Win32 + {8FA40ED0-3404-43E9-AAFF-0F68CA4A3E2D}.Release|Win32.Build.0 = Release|Win32 + {B4795061-9118-4355-BAD0-215DFAFF3FCD}.Debug|Win32.ActiveCfg = Debug|Win32 + {B4795061-9118-4355-BAD0-215DFAFF3FCD}.Debug|Win32.Build.0 = Debug|Win32 + {B4795061-9118-4355-BAD0-215DFAFF3FCD}.Release|Win32.ActiveCfg = Release|Win32 + {B4795061-9118-4355-BAD0-215DFAFF3FCD}.Release|Win32.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/Chapter09/Chapter09.suo b/Chapter09/Chapter09.suo new file mode 100644 index 0000000..17bc1a5 Binary files /dev/null and b/Chapter09/Chapter09.suo differ diff --git a/Chapter09/CheckMe/AssemblyInfo.cpp b/Chapter09/CheckMe/AssemblyInfo.cpp new file mode 100644 index 0000000..7e2decb --- /dev/null +++ b/Chapter09/CheckMe/AssemblyInfo.cpp @@ -0,0 +1,40 @@ +#include "stdafx.h" + +using namespace System; +using namespace System::Reflection; +using namespace System::Runtime::CompilerServices; +using namespace System::Runtime::InteropServices; +using namespace System::Security::Permissions; + +// +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +// +[assembly:AssemblyTitleAttribute("CheckMe")]; +[assembly:AssemblyDescriptionAttribute("")]; +[assembly:AssemblyConfigurationAttribute("")]; +[assembly:AssemblyCompanyAttribute("")]; +[assembly:AssemblyProductAttribute("CheckMe")]; +[assembly:AssemblyCopyrightAttribute("Copyright (c) 2005")]; +[assembly:AssemblyTrademarkAttribute("")]; +[assembly:AssemblyCultureAttribute("")]; + +// +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the value or you can default the Revision and Build Numbers +// by using the '*' as shown below: + +[assembly:AssemblyVersionAttribute("1.0.*")]; + +[assembly:ComVisible(false)]; + +[assembly:CLSCompliantAttribute(true)]; + +[assembly:SecurityPermission(SecurityAction::RequestMinimum, UnmanagedCode = true)]; diff --git a/Chapter09/CheckMe/CheckMe.cpp b/Chapter09/CheckMe/CheckMe.cpp new file mode 100644 index 0000000..3807498 --- /dev/null +++ b/Chapter09/CheckMe/CheckMe.cpp @@ -0,0 +1,18 @@ +// CheckMe.cpp : main project file. + +#include "stdafx.h" +#include "Form1.h" + +using namespace CheckMe; + +[STAThreadAttribute] +int main(array ^args) +{ + // Enabling Windows XP visual effects before any controls are created + Application::EnableVisualStyles(); + Application::SetCompatibleTextRenderingDefault(false); + + // Create the main window and run it + Application::Run(gcnew Form1()); + return 0; +} diff --git a/Chapter09/CheckMe/CheckMe.vcproj b/Chapter09/CheckMe/CheckMe.vcproj new file mode 100644 index 0000000..e4efc2f --- /dev/null +++ b/Chapter09/CheckMe/CheckMe.vcproj @@ -0,0 +1,250 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Chapter09/CheckMe/Form1.h b/Chapter09/CheckMe/Form1.h new file mode 100644 index 0000000..e4185c9 --- /dev/null +++ b/Chapter09/CheckMe/Form1.h @@ -0,0 +1,138 @@ +#pragma once + +namespace CheckMe +{ + using namespace System; + using namespace System::ComponentModel; + using namespace System::Collections; + using namespace System::Windows::Forms; + using namespace System::Data; + using namespace System::Drawing; + + public ref class Form1 : public System::Windows::Forms::Form + { + public: + Form1(void) + { + InitializeComponent(); + } + + protected: + ~Form1() + { + if (components) + { + delete components; + } + } + + private: + System::Windows::Forms::CheckBox^ BottomCheck; + System::Windows::Forms::CheckBox^ checkBox2; + System::Windows::Forms::CheckBox^ checkBox1; + System::Windows::Forms::CheckBox^ TopCheck; + + System::ComponentModel::Container ^components; + +#pragma region Windows Form Designer generated code + + void InitializeComponent(void) + { + this->BottomCheck = (gcnew System::Windows::Forms::CheckBox()); + this->checkBox2 = (gcnew System::Windows::Forms::CheckBox()); + this->checkBox1 = (gcnew System::Windows::Forms::CheckBox()); + this->TopCheck = (gcnew System::Windows::Forms::CheckBox()); + this->SuspendLayout(); + // + // BottomCheck + // + this->BottomCheck->AutoSize = true; + this->BottomCheck->Enabled = false; + this->BottomCheck->Location = System::Drawing::Point(52, 167); + this->BottomCheck->Name = L"BottomCheck"; + this->BottomCheck->Size = System::Drawing::Size(127, 17); + this->BottomCheck->TabIndex = 4; + this->BottomCheck->TabStop = false; + this->BottomCheck->Text = L"You Can\'t Check Me!"; + this->BottomCheck->Visible = false; + this->BottomCheck->Enter += + gcnew System::EventHandler(this, &Form1::BottomCheck_Enter); + this->BottomCheck->MouseEnter += + gcnew System::EventHandler(this, &Form1::BottomCheck_Enter); + // + // checkBox2 + // + this->checkBox2->AutoSize = true; + this->checkBox2->Location = System::Drawing::Point(52, 130); + this->checkBox2->Name = L"checkBox2"; + this->checkBox2->Size = System::Drawing::Size(106, 17); + this->checkBox2->TabIndex = 5; + this->checkBox2->Text = L"Don\'t Forget ME!"; + // + // checkBox1 + // + this->checkBox1->AutoSize = true; + this->checkBox1->Checked = true; + this->checkBox1->CheckState = + System::Windows::Forms::CheckState::Indeterminate; + this->checkBox1->Location = System::Drawing::Point(52, 90); + this->checkBox1->Name = L"checkBox1"; + this->checkBox1->Size = System::Drawing::Size(133, 17); + this->checkBox1->TabIndex = 2; + this->checkBox1->Text = L"Check Me! Check Me!"; + this->checkBox1->ThreeState = true; + // + // TopCheck + // + this->TopCheck->AutoSize = true; + this->TopCheck->Location = System::Drawing::Point(52, 49); + this->TopCheck->Name = L"TopCheck"; + this->TopCheck->Size = System::Drawing::Size(127, 17); + this->TopCheck->TabIndex = 3; + this->TopCheck->TabStop = false; + this->TopCheck->Text = L"You Can\'t Check Me!"; + this->TopCheck->Enter += + gcnew System::EventHandler(this, &Form1::TopCheck_Enter); + this->TopCheck->MouseEnter += + gcnew System::EventHandler(this, &Form1::TopCheck_Enter); + // + // Form1 + // + this->AutoScaleDimensions = System::Drawing::SizeF(6, 13); + this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font; + this->ClientSize = System::Drawing::Size(242, 273); + this->Controls->Add(this->BottomCheck); + this->Controls->Add(this->checkBox2); + this->Controls->Add(this->checkBox1); + this->Controls->Add(this->TopCheck); + this->Name = L"Form1"; + this->Text = L"Can\'t Check Me"; + this->ResumeLayout(false); + this->PerformLayout(); + } +#pragma endregion + + private: + System::Void TopCheck_Enter(System::Object^ sender, + System::EventArgs^ e) + { + // Hide Top checkbox and display bottom + TopCheck->Enabled = false; + TopCheck->Visible = false; + BottomCheck->Enabled = true; + BottomCheck->Visible = true; + } + + private: + System::Void BottomCheck_Enter(System::Object^ sender, + System::EventArgs^ e) + { + // Hide Bottom checkbox and display top + BottomCheck->Enabled = false; + BottomCheck->Visible = false; + TopCheck->Enabled = true; + TopCheck->Visible = true; + } + }; +} + diff --git a/Chapter09/CheckMe/Form1.resx b/Chapter09/CheckMe/Form1.resx new file mode 100644 index 0000000..7080a7d --- /dev/null +++ b/Chapter09/CheckMe/Form1.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Chapter09/CheckMe/stdafx.cpp b/Chapter09/CheckMe/stdafx.cpp new file mode 100644 index 0000000..cf33cba --- /dev/null +++ b/Chapter09/CheckMe/stdafx.cpp @@ -0,0 +1,7 @@ +// stdafx.cpp : source file that includes just the standard includes +// CheckMe.pch will be the pre-compiled header +// stdafx.obj will contain the pre-compiled type information + +#include "stdafx.h" + + diff --git a/Chapter09/CheckMe/stdafx.h b/Chapter09/CheckMe/stdafx.h new file mode 100644 index 0000000..46bef73 --- /dev/null +++ b/Chapter09/CheckMe/stdafx.h @@ -0,0 +1,6 @@ +// stdafx.h : include file for standard system include files, +// or project specific include files that are used frequently, but +// are changed infrequently +#pragma once + +// TODO: reference additional headers your program requires here diff --git a/Chapter09/CustomHello/AssemblyInfo.cpp b/Chapter09/CustomHello/AssemblyInfo.cpp new file mode 100644 index 0000000..54c4e3a --- /dev/null +++ b/Chapter09/CustomHello/AssemblyInfo.cpp @@ -0,0 +1,40 @@ +#include "stdafx.h" + +using namespace System; +using namespace System::Reflection; +using namespace System::Runtime::CompilerServices; +using namespace System::Runtime::InteropServices; +using namespace System::Security::Permissions; + +// +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +// +[assembly:AssemblyTitleAttribute("CustomHello")]; +[assembly:AssemblyDescriptionAttribute("")]; +[assembly:AssemblyConfigurationAttribute("")]; +[assembly:AssemblyCompanyAttribute("")]; +[assembly:AssemblyProductAttribute("CustomHello")]; +[assembly:AssemblyCopyrightAttribute("Copyright (c) 2005")]; +[assembly:AssemblyTrademarkAttribute("")]; +[assembly:AssemblyCultureAttribute("")]; + +// +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the value or you can default the Revision and Build Numbers +// by using the '*' as shown below: + +[assembly:AssemblyVersionAttribute("1.0.*")]; + +[assembly:ComVisible(false)]; + +[assembly:CLSCompliantAttribute(true)]; + +[assembly:SecurityPermission(SecurityAction::RequestMinimum, UnmanagedCode = true)]; diff --git a/Chapter09/CustomHello/CustomHello.cpp b/Chapter09/CustomHello/CustomHello.cpp new file mode 100644 index 0000000..295cacb --- /dev/null +++ b/Chapter09/CustomHello/CustomHello.cpp @@ -0,0 +1,18 @@ +// CustomHello.cpp : main project file. + +#include "stdafx.h" +#include "Form1.h" + +using namespace CustomHello; + +[STAThreadAttribute] +int main(array ^args) +{ + // Enabling Windows XP visual effects before any controls are created + Application::EnableVisualStyles(); + Application::SetCompatibleTextRenderingDefault(false); + + // Create the main window and run it + Application::Run(gcnew Form1()); + return 0; +} diff --git a/Chapter09/CustomHello/CustomHello.vcproj b/Chapter09/CustomHello/CustomHello.vcproj new file mode 100644 index 0000000..f5e8ca3 --- /dev/null +++ b/Chapter09/CustomHello/CustomHello.vcproj @@ -0,0 +1,250 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Chapter09/CustomHello/Form1.h b/Chapter09/CustomHello/Form1.h new file mode 100644 index 0000000..220a6a1 --- /dev/null +++ b/Chapter09/CustomHello/Form1.h @@ -0,0 +1,56 @@ +#pragma once + +namespace CustomHello +{ + using namespace System; + using namespace System::ComponentModel; + using namespace System::Collections; + using namespace System::Windows::Forms; + using namespace System::Data; + using namespace System::Drawing; + + public ref class Form1 : public System::Windows::Forms::Form + { + public: + Form1(void) + { + InitializeComponent(); + } + + protected: + ~Form1() + { + if (components) + { + delete components; + } + } + + private: + System::ComponentModel::Container ^components; + +#pragma region Windows Form Designer generated code + + void InitializeComponent(void) + { + this->SuspendLayout(); + // + // Form1 + // + this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font; + this->BackColor = System::Drawing::Color::Black; + this->ClientSize = System::Drawing::Size(692, 274); + this->Cursor = System::Windows::Forms::Cursors::UpArrow; + this->FormBorderStyle = + System::Windows::Forms::FormBorderStyle::SizableToolWindow; + this->Name = L"Form1"; + this->SizeGripStyle = System::Windows::Forms::SizeGripStyle::Show; + this->Text = L"Custom Form"; + this->TopMost = true; + this->ResumeLayout(false); + } + +#pragma endregion + }; +} + diff --git a/Chapter09/CustomHello/Form1.resx b/Chapter09/CustomHello/Form1.resx new file mode 100644 index 0000000..7080a7d --- /dev/null +++ b/Chapter09/CustomHello/Form1.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Chapter09/CustomHello/stdafx.cpp b/Chapter09/CustomHello/stdafx.cpp new file mode 100644 index 0000000..8ba14ba --- /dev/null +++ b/Chapter09/CustomHello/stdafx.cpp @@ -0,0 +1,7 @@ +// stdafx.cpp : source file that includes just the standard includes +// CustomHello.pch will be the pre-compiled header +// stdafx.obj will contain the pre-compiled type information + +#include "stdafx.h" + + diff --git a/Chapter09/CustomHello/stdafx.h b/Chapter09/CustomHello/stdafx.h new file mode 100644 index 0000000..46bef73 --- /dev/null +++ b/Chapter09/CustomHello/stdafx.h @@ -0,0 +1,6 @@ +// stdafx.h : include file for standard system include files, +// or project specific include files that are used frequently, but +// are changed infrequently +#pragma once + +// TODO: reference additional headers your program requires here diff --git a/Chapter09/GroupingRadios/AssemblyInfo.cpp b/Chapter09/GroupingRadios/AssemblyInfo.cpp new file mode 100644 index 0000000..c71b4fb --- /dev/null +++ b/Chapter09/GroupingRadios/AssemblyInfo.cpp @@ -0,0 +1,40 @@ +#include "stdafx.h" + +using namespace System; +using namespace System::Reflection; +using namespace System::Runtime::CompilerServices; +using namespace System::Runtime::InteropServices; +using namespace System::Security::Permissions; + +// +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +// +[assembly:AssemblyTitleAttribute("GroupingRadios")]; +[assembly:AssemblyDescriptionAttribute("")]; +[assembly:AssemblyConfigurationAttribute("")]; +[assembly:AssemblyCompanyAttribute("")]; +[assembly:AssemblyProductAttribute("GroupingRadios")]; +[assembly:AssemblyCopyrightAttribute("Copyright (c) 2005")]; +[assembly:AssemblyTrademarkAttribute("")]; +[assembly:AssemblyCultureAttribute("")]; + +// +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the value or you can default the Revision and Build Numbers +// by using the '*' as shown below: + +[assembly:AssemblyVersionAttribute("1.0.*")]; + +[assembly:ComVisible(false)]; + +[assembly:CLSCompliantAttribute(true)]; + +[assembly:SecurityPermission(SecurityAction::RequestMinimum, UnmanagedCode = true)]; diff --git a/Chapter09/GroupingRadios/Form1.h b/Chapter09/GroupingRadios/Form1.h new file mode 100644 index 0000000..8192fce --- /dev/null +++ b/Chapter09/GroupingRadios/Form1.h @@ -0,0 +1,135 @@ +#pragma once + +namespace GroupingRadios +{ + using namespace System; + using namespace System::ComponentModel; + using namespace System::Collections; + using namespace System::Windows::Forms; + using namespace System::Data; + using namespace System::Drawing; + + public ref class Form1 : public System::Windows::Forms::Form + { + public: + Form1(void) + { + InitializeComponent(); + BuildRadios(); + } + + protected: + ~Form1() + { + if (components) + { + delete components; + } + } + + private: + System::Windows::Forms::GroupBox^ groupBox2; + System::Windows::Forms::GroupBox^ groupBox1; + + array^ radio1; + array^ radio2; + array^ radio3; + + System::ComponentModel::Container ^components; + +#pragma region Windows Form Designer generated code + + void InitializeComponent(void) + { + this->groupBox2 = (gcnew System::Windows::Forms::GroupBox()); + this->groupBox1 = (gcnew System::Windows::Forms::GroupBox()); + this->SuspendLayout(); + // + // groupBox2 + // + this->groupBox2->Location = System::Drawing::Point(125, 153); + this->groupBox2->Name = L"groupBox2"; + this->groupBox2->Size = System::Drawing::Size(152, 134); + this->groupBox2->TabIndex = 3; + this->groupBox2->TabStop = false; + this->groupBox2->Text = L"Use"; + // + // groupBox1 + // + this->groupBox1->Location = System::Drawing::Point(125, 12); + this->groupBox1->Name = L"groupBox1"; + this->groupBox1->Size = System::Drawing::Size(152, 135); + this->groupBox1->TabIndex = 2; + this->groupBox1->TabStop = false; + this->groupBox1->Text = L"You"; + // + // Form1 + // + this->AutoScaleDimensions = System::Drawing::SizeF(6, 13); + this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font; + this->ClientSize = System::Drawing::Size(352, 330); + this->Controls->Add(this->groupBox2); + this->Controls->Add(this->groupBox1); + this->Name = L"Form1"; + this->Text = L"Using Group Boxes"; + this->ResumeLayout(false); + } + +#pragma endregion + + void BuildRadios() + { + this->SuspendLayout(); + + // Text for RadioButton places on Form directly + array^ rbText1 = gcnew array { + L"Can", L"You", L"Click", L"More", L"Than", L"One" + }; + + // Build a RadioButton for each rbText1 + radio1 = gcnew array(6); + for (int i = 0; i < radio1->Length; i++) + { + radio1[i] = gcnew RadioButton(); + radio1[i]->Location = Drawing::Point(20, 20+(40*i)); + radio1[i]->Text = rbText1[i]; + } + // Add RadioButtons to Form + Controls->AddRange(radio1); + + // Text for RadioButton places in first GroupBox + array^ rbText2 = gcnew array { + L"Can", L"If", L"You" + }; + + // Build a RadioButton for each rbText2 + radio2 = gcnew array(3); + for (int i = 0; i < radio2->Length; i++) + { + radio2[i] = gcnew RadioButton(); + radio2[i]->Location = Drawing::Point(40, 30+(35*i)); + radio2[i]->Text = rbText2[i]; + } + // Add RadioButtons to GroupBox + groupBox1->Controls->AddRange(radio2); + + // Text for RadioButton places in second GroupBox + array^ rbText3 = gcnew array { + L"Different", L"Group", L"Boxes" + }; + + // Build a RadioButton for each rbText3 + radio3 = gcnew array(3); + for (int i = 0; i < radio3->Length; i++) + { + radio3[i] = gcnew RadioButton(); + radio3[i]->Location = Drawing::Point(40, 30+(35*i)); + radio3[i]->Text = rbText3[i]; + } + // Add RadioButtons to GroupBox2 + groupBox2->Controls->AddRange(radio3); + + this->ResumeLayout(false); + } + }; +} \ No newline at end of file diff --git a/Chapter09/GroupingRadios/Form1.resx b/Chapter09/GroupingRadios/Form1.resx new file mode 100644 index 0000000..7080a7d --- /dev/null +++ b/Chapter09/GroupingRadios/Form1.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Chapter09/GroupingRadios/GroupingRadios.cpp b/Chapter09/GroupingRadios/GroupingRadios.cpp new file mode 100644 index 0000000..38c3f61 --- /dev/null +++ b/Chapter09/GroupingRadios/GroupingRadios.cpp @@ -0,0 +1,18 @@ +// GroupingRadios.cpp : main project file. + +#include "stdafx.h" +#include "Form1.h" + +using namespace GroupingRadios; + +[STAThreadAttribute] +int main(array ^args) +{ + // Enabling Windows XP visual effects before any controls are created + Application::EnableVisualStyles(); + Application::SetCompatibleTextRenderingDefault(false); + + // Create the main window and run it + Application::Run(gcnew Form1()); + return 0; +} diff --git a/Chapter09/GroupingRadios/GroupingRadios.vcproj b/Chapter09/GroupingRadios/GroupingRadios.vcproj new file mode 100644 index 0000000..34a8285 --- /dev/null +++ b/Chapter09/GroupingRadios/GroupingRadios.vcproj @@ -0,0 +1,250 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Chapter09/GroupingRadios/stdafx.cpp b/Chapter09/GroupingRadios/stdafx.cpp new file mode 100644 index 0000000..22a4e7a --- /dev/null +++ b/Chapter09/GroupingRadios/stdafx.cpp @@ -0,0 +1,7 @@ +// stdafx.cpp : source file that includes just the standard includes +// GroupingRadios.pch will be the pre-compiled header +// stdafx.obj will contain the pre-compiled type information + +#include "stdafx.h" + + diff --git a/Chapter09/GroupingRadios/stdafx.h b/Chapter09/GroupingRadios/stdafx.h new file mode 100644 index 0000000..46bef73 --- /dev/null +++ b/Chapter09/GroupingRadios/stdafx.h @@ -0,0 +1,6 @@ +// stdafx.h : include file for standard system include files, +// or project specific include files that are used frequently, but +// are changed infrequently +#pragma once + +// TODO: reference additional headers your program requires here diff --git a/Chapter09/Hello/AssemblyInfo.cpp b/Chapter09/Hello/AssemblyInfo.cpp new file mode 100644 index 0000000..80a9272 --- /dev/null +++ b/Chapter09/Hello/AssemblyInfo.cpp @@ -0,0 +1,40 @@ +#include "stdafx.h" + +using namespace System; +using namespace System::Reflection; +using namespace System::Runtime::CompilerServices; +using namespace System::Runtime::InteropServices; +using namespace System::Security::Permissions; + +// +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +// +[assembly:AssemblyTitleAttribute("Hello")]; +[assembly:AssemblyDescriptionAttribute("")]; +[assembly:AssemblyConfigurationAttribute("")]; +[assembly:AssemblyCompanyAttribute("")]; +[assembly:AssemblyProductAttribute("Hello")]; +[assembly:AssemblyCopyrightAttribute("Copyright (c) 2005")]; +[assembly:AssemblyTrademarkAttribute("")]; +[assembly:AssemblyCultureAttribute("")]; + +// +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the value or you can default the Revision and Build Numbers +// by using the '*' as shown below: + +[assembly:AssemblyVersionAttribute("1.0.*")]; + +[assembly:ComVisible(false)]; + +[assembly:CLSCompliantAttribute(true)]; + +[assembly:SecurityPermission(SecurityAction::RequestMinimum, UnmanagedCode = true)]; diff --git a/Chapter09/Hello/Form1.h b/Chapter09/Hello/Form1.h new file mode 100644 index 0000000..66602f4 --- /dev/null +++ b/Chapter09/Hello/Form1.h @@ -0,0 +1,71 @@ +#pragma once + +namespace Hello +{ + using namespace System; + using namespace System::ComponentModel; + using namespace System::Collections; + using namespace System::Windows::Forms; + using namespace System::Data; + using namespace System::Drawing; + + /// + /// 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. + /// + public ref class Form1 : public System::Windows::Forms::Form + { + public: + Form1(void) + { + InitializeComponent(); + // + //TODO: Add the constructor code here + // + } + + protected: + /// + /// Clean up any resources being used. + /// + ~Form1() + { + if (components) + { + delete components; + } + } + + private: + /// + /// Required designer variable. + /// + System::ComponentModel::Container ^components; + +#pragma region Windows Form Designer generated code + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + void InitializeComponent(void) + { + this->SuspendLayout(); + // + // Form1 + // + this->AutoScaleDimensions = System::Drawing::SizeF(6, 13); + this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font; + this->ClientSize = System::Drawing::Size(292, 273); + this->Name = L"Form1"; + this->Text = L"Hello World!"; + this->ResumeLayout(false); + } +#pragma endregion + }; +} diff --git a/Chapter09/Hello/Form1.resx b/Chapter09/Hello/Form1.resx new file mode 100644 index 0000000..7080a7d --- /dev/null +++ b/Chapter09/Hello/Form1.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Chapter09/Hello/Hello.cpp b/Chapter09/Hello/Hello.cpp new file mode 100644 index 0000000..9773c2d --- /dev/null +++ b/Chapter09/Hello/Hello.cpp @@ -0,0 +1,18 @@ +// Hello.cpp : main project file. + +#include "stdafx.h" +#include "Form1.h" + +using namespace Hello; + +[STAThreadAttribute] +int main(array ^args) +{ + // Enabling Windows XP visual effects before any controls are created + Application::EnableVisualStyles(); + Application::SetCompatibleTextRenderingDefault(false); + + // Create the main window and run it + Application::Run(gcnew Form1()); + return 0; +} diff --git a/Chapter09/Hello/Hello.vcproj b/Chapter09/Hello/Hello.vcproj new file mode 100644 index 0000000..414920b --- /dev/null +++ b/Chapter09/Hello/Hello.vcproj @@ -0,0 +1,250 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Chapter09/Hello/stdafx.cpp b/Chapter09/Hello/stdafx.cpp new file mode 100644 index 0000000..f89dfd1 --- /dev/null +++ b/Chapter09/Hello/stdafx.cpp @@ -0,0 +1,7 @@ +// stdafx.cpp : source file that includes just the standard includes +// Hello.pch will be the pre-compiled header +// stdafx.obj will contain the pre-compiled type information + +#include "stdafx.h" + + diff --git a/Chapter09/Hello/stdafx.h b/Chapter09/Hello/stdafx.h new file mode 100644 index 0000000..46bef73 --- /dev/null +++ b/Chapter09/Hello/stdafx.h @@ -0,0 +1,6 @@ +// stdafx.h : include file for standard system include files, +// or project specific include files that are used frequently, but +// are changed infrequently +#pragma once + +// TODO: reference additional headers your program requires here diff --git a/Chapter09/ListTransfers/AssemblyInfo.cpp b/Chapter09/ListTransfers/AssemblyInfo.cpp new file mode 100644 index 0000000..e18fc34 --- /dev/null +++ b/Chapter09/ListTransfers/AssemblyInfo.cpp @@ -0,0 +1,40 @@ +#include "stdafx.h" + +using namespace System; +using namespace System::Reflection; +using namespace System::Runtime::CompilerServices; +using namespace System::Runtime::InteropServices; +using namespace System::Security::Permissions; + +// +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +// +[assembly:AssemblyTitleAttribute("ListTransfers")]; +[assembly:AssemblyDescriptionAttribute("")]; +[assembly:AssemblyConfigurationAttribute("")]; +[assembly:AssemblyCompanyAttribute("")]; +[assembly:AssemblyProductAttribute("ListTransfers")]; +[assembly:AssemblyCopyrightAttribute("Copyright (c) 2005")]; +[assembly:AssemblyTrademarkAttribute("")]; +[assembly:AssemblyCultureAttribute("")]; + +// +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the value or you can default the Revision and Build Numbers +// by using the '*' as shown below: + +[assembly:AssemblyVersionAttribute("1.0.*")]; + +[assembly:ComVisible(false)]; + +[assembly:CLSCompliantAttribute(true)]; + +[assembly:SecurityPermission(SecurityAction::RequestMinimum, UnmanagedCode = true)]; diff --git a/Chapter09/ListTransfers/Form1.h b/Chapter09/ListTransfers/Form1.h new file mode 100644 index 0000000..0cf80e2 --- /dev/null +++ b/Chapter09/ListTransfers/Form1.h @@ -0,0 +1,187 @@ +#pragma once + +namespace ListTransfers +{ + using namespace System; + using namespace System::ComponentModel; + using namespace System::Collections; + using namespace System::Windows::Forms; + using namespace System::Data; + using namespace System::Drawing; + + public ref class Form1 : public System::Windows::Forms::Form + { + public: + Form1(void) + { + InitializeComponent(); + } + + protected: + ~Form1() + { + if (components) + { + delete components; + } + } + + private: + System::Windows::Forms::ListBox^ LBDest; + System::Windows::Forms::Button^ bnR2L; + System::Windows::Forms::Button^ bnL2R; + System::Windows::Forms::ListBox^ LBOrg; + System::Windows::Forms::Label^ label2; + System::Windows::Forms::Label^ label1; + + System::ComponentModel::Container ^components; + +#pragma region Windows Form Designer generated code + + void InitializeComponent(void) + { + this->LBDest = (gcnew System::Windows::Forms::ListBox()); + this->bnR2L = (gcnew System::Windows::Forms::Button()); + this->bnL2R = (gcnew System::Windows::Forms::Button()); + this->LBOrg = (gcnew System::Windows::Forms::ListBox()); + this->label2 = (gcnew System::Windows::Forms::Label()); + this->label1 = (gcnew System::Windows::Forms::Label()); + this->SuspendLayout(); + // + // LBDest + // + this->LBDest->FormattingEnabled = true; + this->LBDest->Location = System::Drawing::Point(213, 46); + this->LBDest->Name = L"LBDest"; + this->LBDest->SelectionMode = + System::Windows::Forms::SelectionMode::MultiSimple; + this->LBDest->Size = System::Drawing::Size(134, 134); + this->LBDest->TabIndex = 10; + this->LBDest->DoubleClick += + gcnew System::EventHandler(this, &Form1::LBDest_DoubleClick); + // + // bnR2L + // + this->bnR2L->Location = System::Drawing::Point(167, 108); + this->bnR2L->Name = L"bnR2L"; + this->bnR2L->Size = System::Drawing::Size(33, 20); + this->bnR2L->TabIndex = 9; + this->bnR2L->Text = L"<=="; + this->bnR2L->Click += + gcnew System::EventHandler(this, &Form1::bnR2L_Click); + // + // bnL2R + // + this->bnL2R->Location = System::Drawing::Point(167, 80); + this->bnL2R->Name = L"bnL2R"; + this->bnL2R->Size = System::Drawing::Size(33, 20); + this->bnL2R->TabIndex = 8; + this->bnL2R->Text = L"==>"; + this->bnL2R->Click += + gcnew System::EventHandler(this, &Form1::bnL2R_Click); + // + // LBOrg + // + this->LBOrg->FormattingEnabled = true; + this->LBOrg->Items->AddRange(gcnew cli::array< System::Object^>(10) + {L"System", L"System::Collections", L"System::Data", + L"System::Drawing", L"System::IO", L"System::Net", + L"System::Threading", L"System::Web", + L"System::Windows::Forms", L"System::Xml"}); + this->LBOrg->Location = System::Drawing::Point(20, 46); + this->LBOrg->Name = L"LBOrg"; + this->LBOrg->SelectionMode = + System::Windows::Forms::SelectionMode::MultiExtended; + this->LBOrg->Size = System::Drawing::Size(133, 134); + this->LBOrg->Sorted = true; + this->LBOrg->TabIndex = 6; + this->LBOrg->DoubleClick += + gcnew System::EventHandler(this, &Form1::LBOrg_DoubleClick); + // + // label2 + // + this->label2->AutoSize = true; + this->label2->Location = System::Drawing::Point(213, 17); + this->label2->Name = L"label2"; + this->label2->Size = System::Drawing::Size(104, 13); + this->label2->TabIndex = 7; + this->label2->Text = L"Unsorted Multisimple"; + // + // label1 + // + this->label1->AutoSize = true; + this->label1->Location = System::Drawing::Point(20, 17); + this->label1->Name = L"label1"; + this->label1->Size = System::Drawing::Size(107, 13); + this->label1->TabIndex = 5; + this->label1->Text = L"Sorted Multiextended"; + // + // Form1 + // + this->AutoScaleDimensions = System::Drawing::SizeF(6, 13); + this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font; + this->ClientSize = System::Drawing::Size(367, 196); + this->Controls->Add(this->LBDest); + this->Controls->Add(this->bnR2L); + this->Controls->Add(this->bnL2R); + this->Controls->Add(this->LBOrg); + this->Controls->Add(this->label2); + this->Controls->Add(this->label1); + this->Name = L"Form1"; + this->Text = L"List Box Transfers"; + this->ResumeLayout(false); + this->PerformLayout(); + } + +#pragma endregion + + private: + System::Void LBOrg_DoubleClick(System::Object^ sender, + System::EventArgs^ e) + { + // Add Selected item to other ListBox + // Then remove item from original + if (LBOrg->SelectedItem != nullptr) + { + LBDest->Items->Add(LBOrg->SelectedItem); + LBOrg->Items->Remove(LBOrg->SelectedItem); + } + } + + System::Void LBDest_DoubleClick(System::Object^ sender, + System::EventArgs^ e) + { + // Add Selected item to other ListBox + // Then remove item from original + if (LBDest->SelectedItem != nullptr) + { + LBOrg->Items->Add(LBDest->SelectedItem); + LBDest->Items->Remove(LBDest->SelectedItem); + } + } + + System::Void bnL2R_Click(System::Object^ sender, System::EventArgs^ e) + { + // Add all Selected items to other ListBox + // Then remove the all items from original + array^ tmp = + gcnew array(LBOrg->SelectedItems->Count); + LBOrg->SelectedItems->CopyTo(tmp, 0); + LBDest->Items->AddRange(tmp); + for (int i = 0; i < tmp->Length; i++) + LBOrg->Items->Remove(tmp[i]); + } + + System::Void bnR2L_Click(System::Object^ sender, System::EventArgs^ e) + { + // Add all Selected items to other ListBox + // Then remove all the items from original + array^ tmp = + gcnew array(LBDest->SelectedItems->Count); + LBDest->SelectedItems->CopyTo(tmp, 0); + LBOrg->Items->AddRange(tmp); + for (int i = 0; i < tmp->Length; i++) + LBDest->Items->Remove(tmp[i]); + } + }; +} \ No newline at end of file diff --git a/Chapter09/ListTransfers/Form1.resx b/Chapter09/ListTransfers/Form1.resx new file mode 100644 index 0000000..7080a7d --- /dev/null +++ b/Chapter09/ListTransfers/Form1.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Chapter09/ListTransfers/ListTransfers.cpp b/Chapter09/ListTransfers/ListTransfers.cpp new file mode 100644 index 0000000..d2167a1 --- /dev/null +++ b/Chapter09/ListTransfers/ListTransfers.cpp @@ -0,0 +1,18 @@ +// ListTransfers.cpp : main project file. + +#include "stdafx.h" +#include "Form1.h" + +using namespace ListTransfers; + +[STAThreadAttribute] +int main(array ^args) +{ + // Enabling Windows XP visual effects before any controls are created + Application::EnableVisualStyles(); + Application::SetCompatibleTextRenderingDefault(false); + + // Create the main window and run it + Application::Run(gcnew Form1()); + return 0; +} diff --git a/Chapter09/ListTransfers/ListTransfers.vcproj b/Chapter09/ListTransfers/ListTransfers.vcproj new file mode 100644 index 0000000..ea4bd7b --- /dev/null +++ b/Chapter09/ListTransfers/ListTransfers.vcproj @@ -0,0 +1,250 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Chapter09/ListTransfers/stdafx.cpp b/Chapter09/ListTransfers/stdafx.cpp new file mode 100644 index 0000000..8930556 --- /dev/null +++ b/Chapter09/ListTransfers/stdafx.cpp @@ -0,0 +1,7 @@ +// stdafx.cpp : source file that includes just the standard includes +// ListTransfers.pch will be the pre-compiled header +// stdafx.obj will contain the pre-compiled type information + +#include "stdafx.h" + + diff --git a/Chapter09/ListTransfers/stdafx.h b/Chapter09/ListTransfers/stdafx.h new file mode 100644 index 0000000..46bef73 --- /dev/null +++ b/Chapter09/ListTransfers/stdafx.h @@ -0,0 +1,6 @@ +// stdafx.h : include file for standard system include files, +// or project specific include files that are used frequently, but +// are changed infrequently +#pragma once + +// TODO: reference additional headers your program requires here diff --git a/Chapter09/MightyLabel/AssemblyInfo.cpp b/Chapter09/MightyLabel/AssemblyInfo.cpp new file mode 100644 index 0000000..c4f0b11 --- /dev/null +++ b/Chapter09/MightyLabel/AssemblyInfo.cpp @@ -0,0 +1,40 @@ +#include "stdafx.h" + +using namespace System; +using namespace System::Reflection; +using namespace System::Runtime::CompilerServices; +using namespace System::Runtime::InteropServices; +using namespace System::Security::Permissions; + +// +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +// +[assembly:AssemblyTitleAttribute("MightyLabel")]; +[assembly:AssemblyDescriptionAttribute("")]; +[assembly:AssemblyConfigurationAttribute("")]; +[assembly:AssemblyCompanyAttribute("")]; +[assembly:AssemblyProductAttribute("MightyLabel")]; +[assembly:AssemblyCopyrightAttribute("Copyright (c) 2005")]; +[assembly:AssemblyTrademarkAttribute("")]; +[assembly:AssemblyCultureAttribute("")]; + +// +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the value or you can default the Revision and Build Numbers +// by using the '*' as shown below: + +[assembly:AssemblyVersionAttribute("1.0.*")]; + +[assembly:ComVisible(false)]; + +[assembly:CLSCompliantAttribute(true)]; + +[assembly:SecurityPermission(SecurityAction::RequestMinimum, UnmanagedCode = true)]; diff --git a/Chapter09/MightyLabel/Form1.h b/Chapter09/MightyLabel/Form1.h new file mode 100644 index 0000000..6d02678 --- /dev/null +++ b/Chapter09/MightyLabel/Form1.h @@ -0,0 +1,83 @@ +#pragma once + +namespace MightyLabel +{ + using namespace System; + using namespace System::ComponentModel; + using namespace System::Collections; + using namespace System::Windows::Forms; + using namespace System::Data; + using namespace System::Drawing; + + public ref class Form1 : public System::Windows::Forms::Form + { + public: + Form1(void) + { + labelSwitch = true; + InitializeComponent(); + } + + protected: + ~Form1() + { + if (components) + { + delete components; + } + } + + private: + System::Windows::Forms::Label^ MightyLabel; + bool labelSwitch; + + System::ComponentModel::Container ^components; + +#pragma region Windows Form Designer generated code + + void InitializeComponent(void) + { + this->MightyLabel = (gcnew System::Windows::Forms::Label()); + this->SuspendLayout(); + // + // MightyLabel + // + this->MightyLabel->BorderStyle = + System::Windows::Forms::BorderStyle::FixedSingle; + this->MightyLabel->Cursor = System::Windows::Forms::Cursors::Hand; + this->MightyLabel->Location = System::Drawing::Point(63, 91); + this->MightyLabel->Name = L"MightyLabel"; + this->MightyLabel->Size = System::Drawing::Size(150, 35); + this->MightyLabel->TabIndex = 1; + this->MightyLabel->Text = + L"This is the mighty label! It will change when you click it"; + this->MightyLabel->TextAlign = + System::Drawing::ContentAlignment::MiddleCenter; + this->MightyLabel->Click += + gcnew System::EventHandler(this, &Form1::MightyLabel_Click); + // + // Form1 + // + this->AutoScaleDimensions = System::Drawing::SizeF(6, 13); + this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font; + this->ClientSize = System::Drawing::Size(292, 273); + this->Controls->Add(this->MightyLabel); + this->Name = L"Form1"; + this->Text = L"The Mighty Label"; + this->ResumeLayout(false); + } + +#pragma endregion + + private: + System::Void MightyLabel_Click(System::Object^ sender, + System::EventArgs^ e) + { + if (labelSwitch) + MightyLabel->Text = L"Ouchie!!! That hurt."; + else + MightyLabel->Text = L"Ooo!!! That tickled."; + labelSwitch = !labelSwitch; + } + }; +} \ No newline at end of file diff --git a/Chapter09/MightyLabel/Form1.resx b/Chapter09/MightyLabel/Form1.resx new file mode 100644 index 0000000..7080a7d --- /dev/null +++ b/Chapter09/MightyLabel/Form1.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Chapter09/MightyLabel/MightyLabel.cpp b/Chapter09/MightyLabel/MightyLabel.cpp new file mode 100644 index 0000000..3e7a30d --- /dev/null +++ b/Chapter09/MightyLabel/MightyLabel.cpp @@ -0,0 +1,18 @@ +// MightyLabel.cpp : main project file. + +#include "stdafx.h" +#include "Form1.h" + +using namespace MightyLabel; + +[STAThreadAttribute] +int main(array ^args) +{ + // Enabling Windows XP visual effects before any controls are created + Application::EnableVisualStyles(); + Application::SetCompatibleTextRenderingDefault(false); + + // Create the main window and run it + Application::Run(gcnew Form1()); + return 0; +} diff --git a/Chapter09/MightyLabel/MightyLabel.vcproj b/Chapter09/MightyLabel/MightyLabel.vcproj new file mode 100644 index 0000000..2f5d33f --- /dev/null +++ b/Chapter09/MightyLabel/MightyLabel.vcproj @@ -0,0 +1,250 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Chapter09/MightyLabel/stdafx.cpp b/Chapter09/MightyLabel/stdafx.cpp new file mode 100644 index 0000000..66e705a --- /dev/null +++ b/Chapter09/MightyLabel/stdafx.cpp @@ -0,0 +1,7 @@ +// stdafx.cpp : source file that includes just the standard includes +// MightyLabel.pch will be the pre-compiled header +// stdafx.obj will contain the pre-compiled type information + +#include "stdafx.h" + + diff --git a/Chapter09/MightyLabel/stdafx.h b/Chapter09/MightyLabel/stdafx.h new file mode 100644 index 0000000..46bef73 --- /dev/null +++ b/Chapter09/MightyLabel/stdafx.h @@ -0,0 +1,6 @@ +// stdafx.h : include file for standard system include files, +// or project specific include files that are used frequently, but +// are changed infrequently +#pragma once + +// TODO: reference additional headers your program requires here diff --git a/Chapter09/MinuteTimer/AssemblyInfo.cpp b/Chapter09/MinuteTimer/AssemblyInfo.cpp new file mode 100644 index 0000000..e90c63b --- /dev/null +++ b/Chapter09/MinuteTimer/AssemblyInfo.cpp @@ -0,0 +1,40 @@ +#include "stdafx.h" + +using namespace System; +using namespace System::Reflection; +using namespace System::Runtime::CompilerServices; +using namespace System::Runtime::InteropServices; +using namespace System::Security::Permissions; + +// +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +// +[assembly:AssemblyTitleAttribute("MinuteTimer")]; +[assembly:AssemblyDescriptionAttribute("")]; +[assembly:AssemblyConfigurationAttribute("")]; +[assembly:AssemblyCompanyAttribute("")]; +[assembly:AssemblyProductAttribute("MinuteTimer")]; +[assembly:AssemblyCopyrightAttribute("Copyright (c) 2005")]; +[assembly:AssemblyTrademarkAttribute("")]; +[assembly:AssemblyCultureAttribute("")]; + +// +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the value or you can default the Revision and Build Numbers +// by using the '*' as shown below: + +[assembly:AssemblyVersionAttribute("1.0.*")]; + +[assembly:ComVisible(false)]; + +[assembly:CLSCompliantAttribute(true)]; + +[assembly:SecurityPermission(SecurityAction::RequestMinimum, UnmanagedCode = true)]; diff --git a/Chapter09/MinuteTimer/Form1.h b/Chapter09/MinuteTimer/Form1.h new file mode 100644 index 0000000..e8030d2 --- /dev/null +++ b/Chapter09/MinuteTimer/Form1.h @@ -0,0 +1,103 @@ +#pragma once + +namespace MinuteTimer +{ + using namespace System; + using namespace System::ComponentModel; + using namespace System::Collections; + using namespace System::Windows::Forms; + using namespace System::Data; + using namespace System::Drawing; + + public ref class Form1 : public System::Windows::Forms::Form + { + public: + Form1(void) + { + InitializeComponent(); + seconds = 0; + } + + protected: + ~Form1() + { + if (components) + { + delete components; + } + } + + private: + System::Windows::Forms::ProgressBar^ progressBar; + System::Windows::Forms::Label^ lbsecs; + System::Windows::Forms::Timer^ timer; + + int seconds; + + System::ComponentModel::IContainer^ components; + +#pragma region Windows Form Designer generated code + + void InitializeComponent(void) + { + this->components = (gcnew System::ComponentModel::Container()); + this->progressBar = (gcnew System::Windows::Forms::ProgressBar()); + this->lbsecs = (gcnew System::Windows::Forms::Label()); + this->timer = + (gcnew System::Windows::Forms::Timer(this->components)); + this->SuspendLayout(); + // + // progressBar + // + this->progressBar->Location = System::Drawing::Point(61, 16); + this->progressBar->Maximum = 60; + this->progressBar->Name = L"progressBar"; + this->progressBar->Size = System::Drawing::Size(326, 23); + this->progressBar->TabIndex = 3; + // + // lbsecs + // + this->lbsecs->AutoSize = true; + this->lbsecs->Location = System::Drawing::Point(19, 25); + this->lbsecs->Name = L"lbsecs"; + this->lbsecs->Size = System::Drawing::Size(13, 13); + this->lbsecs->TabIndex = 2; + this->lbsecs->Text = L"0"; + this->lbsecs->TextAlign = + System::Drawing::ContentAlignment::MiddleRight; + // + // timer + // + this->timer->Enabled = true; + this->timer->Tick += + gcnew System::EventHandler(this, &Form1::timer_Tick); + // + // Form1 + // + this->AutoScaleDimensions = System::Drawing::SizeF(6, 13); + this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font; + this->ClientSize = System::Drawing::Size(407, 55); + this->Controls->Add(this->progressBar); + this->Controls->Add(this->lbsecs); + this->Name = L"Form1"; + this->Text = L"One minute timer"; + this->ResumeLayout(false); + this->PerformLayout(); + } + +#pragma endregion + + private: + System::Void timer_Tick(System::Object^ sender, System::EventArgs^ e) + { + // Write current tick count (int 10th of second) to label + seconds++; + seconds %= 600; + lbsecs->Text = String::Format("{0}.{1}", (seconds/10).ToString(), + (seconds%10).ToString()); + // Update ProgressBar + progressBar->Value = seconds/10; + } + }; +} + diff --git a/Chapter09/MinuteTimer/Form1.resx b/Chapter09/MinuteTimer/Form1.resx new file mode 100644 index 0000000..afe614d --- /dev/null +++ b/Chapter09/MinuteTimer/Form1.resx @@ -0,0 +1,123 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 17, 17 + + \ No newline at end of file diff --git a/Chapter09/MinuteTimer/MinuteTimer.cpp b/Chapter09/MinuteTimer/MinuteTimer.cpp new file mode 100644 index 0000000..6988982 --- /dev/null +++ b/Chapter09/MinuteTimer/MinuteTimer.cpp @@ -0,0 +1,18 @@ +// MinuteTimer.cpp : main project file. + +#include "stdafx.h" +#include "Form1.h" + +using namespace MinuteTimer; + +[STAThreadAttribute] +int main(array ^args) +{ + // Enabling Windows XP visual effects before any controls are created + Application::EnableVisualStyles(); + Application::SetCompatibleTextRenderingDefault(false); + + // Create the main window and run it + Application::Run(gcnew Form1()); + return 0; +} diff --git a/Chapter09/MinuteTimer/MinuteTimer.vcproj b/Chapter09/MinuteTimer/MinuteTimer.vcproj new file mode 100644 index 0000000..64ebb36 --- /dev/null +++ b/Chapter09/MinuteTimer/MinuteTimer.vcproj @@ -0,0 +1,250 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Chapter09/MinuteTimer/stdafx.cpp b/Chapter09/MinuteTimer/stdafx.cpp new file mode 100644 index 0000000..5ff6b30 --- /dev/null +++ b/Chapter09/MinuteTimer/stdafx.cpp @@ -0,0 +1,7 @@ +// stdafx.cpp : source file that includes just the standard includes +// MinuteTimer.pch will be the pre-compiled header +// stdafx.obj will contain the pre-compiled type information + +#include "stdafx.h" + + diff --git a/Chapter09/MinuteTimer/stdafx.h b/Chapter09/MinuteTimer/stdafx.h new file mode 100644 index 0000000..46bef73 --- /dev/null +++ b/Chapter09/MinuteTimer/stdafx.h @@ -0,0 +1,6 @@ +// stdafx.h : include file for standard system include files, +// or project specific include files that are used frequently, but +// are changed infrequently +#pragma once + +// TODO: reference additional headers your program requires here diff --git a/Chapter09/MouseJump/AssemblyInfo.cpp b/Chapter09/MouseJump/AssemblyInfo.cpp new file mode 100644 index 0000000..fee978c --- /dev/null +++ b/Chapter09/MouseJump/AssemblyInfo.cpp @@ -0,0 +1,40 @@ +#include "stdafx.h" + +using namespace System; +using namespace System::Reflection; +using namespace System::Runtime::CompilerServices; +using namespace System::Runtime::InteropServices; +using namespace System::Security::Permissions; + +// +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +// +[assembly:AssemblyTitleAttribute("MouseJump")]; +[assembly:AssemblyDescriptionAttribute("")]; +[assembly:AssemblyConfigurationAttribute("")]; +[assembly:AssemblyCompanyAttribute("")]; +[assembly:AssemblyProductAttribute("MouseJump")]; +[assembly:AssemblyCopyrightAttribute("Copyright (c) 2005")]; +[assembly:AssemblyTrademarkAttribute("")]; +[assembly:AssemblyCultureAttribute("")]; + +// +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the value or you can default the Revision and Build Numbers +// by using the '*' as shown below: + +[assembly:AssemblyVersionAttribute("1.0.*")]; + +[assembly:ComVisible(false)]; + +[assembly:CLSCompliantAttribute(true)]; + +[assembly:SecurityPermission(SecurityAction::RequestMinimum, UnmanagedCode = true)]; diff --git a/Chapter09/MouseJump/Form1.h b/Chapter09/MouseJump/Form1.h new file mode 100644 index 0000000..41d902f --- /dev/null +++ b/Chapter09/MouseJump/Form1.h @@ -0,0 +1,92 @@ +#pragma once + +namespace MouseJump +{ + using namespace System; + using namespace System::ComponentModel; + using namespace System::Collections; + using namespace System::Windows::Forms; + using namespace System::Data; + using namespace System::Drawing; + + public ref class Form1 : public System::Windows::Forms::Form + { + public: + Form1(void) + { + InitializeComponent(); + } + + protected: + ~Form1() + { + if (components) + { + delete components; + } + } + + private: + System::ComponentModel::Container ^components; + +#pragma region Windows Form Designer generated code + + void InitializeComponent(void) + { + this->SuspendLayout(); + // + // Form1 + // + this->AutoScaleDimensions = System::Drawing::SizeF(6, 13); + this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font; + this->ClientSize = System::Drawing::Size(450, 300); + this->Name = L"Form1"; + this->Text = L"Mouse Jump"; + this->MouseDown += + gcnew System::Windows::Forms::MouseEventHandler(this, + &Form1::Form1_MouseDown); + this->ResumeLayout(false); + } + +#pragma endregion + + private: + System::Void Form1_MouseDown(System::Object^ sender, + System::Windows::Forms::MouseEventArgs^ e) + { + // Get mouse x and y coordinates + int x = e->X; + int y = e->Y; + + // Get Forms upper left location + Point loc = DesktopLocation; + + // Handle left button mouse click + if (e->Button == Windows::Forms::MouseButtons::Left) + { + Text = String::Format("Mouse Jump - Left Button at {0},{1}", + x, y); + + DesktopLocation = Drawing::Point(loc.X + x, loc.Y +y); + } + // Handle right button mouse click + else if (e->Button == Windows::Forms::MouseButtons::Right) + { + Text = String::Format("Mouse Jump - Right Button at {0},{1}", + x, y); + + DesktopLocation = Point((loc.X+1) - (ClientSize.Width - x), + (loc.Y+1) - (ClientSize.Height - y)); + } + // Handle middle button mouse click + else + { + Text = String::Format("Mouse Jump - Middle Button at {0},{1}", + x, y); + DesktopLocation = Point((loc.X+1) - ((ClientSize.Width/2) - x), + (loc.Y+1) - ((ClientSize.Height/2) - y)); + } + } + }; +} + diff --git a/Chapter09/MouseJump/Form1.resx b/Chapter09/MouseJump/Form1.resx new file mode 100644 index 0000000..7080a7d --- /dev/null +++ b/Chapter09/MouseJump/Form1.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Chapter09/MouseJump/MouseJump.cpp b/Chapter09/MouseJump/MouseJump.cpp new file mode 100644 index 0000000..ec1cb0c --- /dev/null +++ b/Chapter09/MouseJump/MouseJump.cpp @@ -0,0 +1,18 @@ +// MouseJump.cpp : main project file. + +#include "stdafx.h" +#include "Form1.h" + +using namespace MouseJump; + +[STAThreadAttribute] +int main(array ^args) +{ + // Enabling Windows XP visual effects before any controls are created + Application::EnableVisualStyles(); + Application::SetCompatibleTextRenderingDefault(false); + + // Create the main window and run it + Application::Run(gcnew Form1()); + return 0; +} diff --git a/Chapter09/MouseJump/MouseJump.vcproj b/Chapter09/MouseJump/MouseJump.vcproj new file mode 100644 index 0000000..ef59a01 --- /dev/null +++ b/Chapter09/MouseJump/MouseJump.vcproj @@ -0,0 +1,250 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Chapter09/MouseJump/stdafx.cpp b/Chapter09/MouseJump/stdafx.cpp new file mode 100644 index 0000000..2d61dd7 --- /dev/null +++ b/Chapter09/MouseJump/stdafx.cpp @@ -0,0 +1,7 @@ +// stdafx.cpp : source file that includes just the standard includes +// MouseJump.pch will be the pre-compiled header +// stdafx.obj will contain the pre-compiled type information + +#include "stdafx.h" + + diff --git a/Chapter09/MouseJump/stdafx.h b/Chapter09/MouseJump/stdafx.h new file mode 100644 index 0000000..46bef73 --- /dev/null +++ b/Chapter09/MouseJump/stdafx.h @@ -0,0 +1,6 @@ +// stdafx.h : include file for standard system include files, +// or project specific include files that are used frequently, but +// are changed infrequently +#pragma once + +// TODO: reference additional headers your program requires here diff --git a/Chapter09/Panels/AssemblyInfo.cpp b/Chapter09/Panels/AssemblyInfo.cpp new file mode 100644 index 0000000..e85e529 --- /dev/null +++ b/Chapter09/Panels/AssemblyInfo.cpp @@ -0,0 +1,40 @@ +#include "stdafx.h" + +using namespace System; +using namespace System::Reflection; +using namespace System::Runtime::CompilerServices; +using namespace System::Runtime::InteropServices; +using namespace System::Security::Permissions; + +// +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +// +[assembly:AssemblyTitleAttribute("Panels")]; +[assembly:AssemblyDescriptionAttribute("")]; +[assembly:AssemblyConfigurationAttribute("")]; +[assembly:AssemblyCompanyAttribute("")]; +[assembly:AssemblyProductAttribute("Panels")]; +[assembly:AssemblyCopyrightAttribute("Copyright (c) 2005")]; +[assembly:AssemblyTrademarkAttribute("")]; +[assembly:AssemblyCultureAttribute("")]; + +// +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the value or you can default the Revision and Build Numbers +// by using the '*' as shown below: + +[assembly:AssemblyVersionAttribute("1.0.*")]; + +[assembly:ComVisible(false)]; + +[assembly:CLSCompliantAttribute(true)]; + +[assembly:SecurityPermission(SecurityAction::RequestMinimum, UnmanagedCode = true)]; diff --git a/Chapter09/Panels/Form1.h b/Chapter09/Panels/Form1.h new file mode 100644 index 0000000..1e441a0 --- /dev/null +++ b/Chapter09/Panels/Form1.h @@ -0,0 +1,142 @@ +#pragma once + +namespace Panels +{ + using namespace System; + using namespace System::ComponentModel; + using namespace System::Collections; + using namespace System::Windows::Forms; + using namespace System::Data; + using namespace System::Drawing; + + public ref class Form1 : public System::Windows::Forms::Form + { + public: + Form1(void) + { + InitializeComponent(); + } + + protected: + ~Form1() + { + if (components) + { + delete components; + } + } + + private: + System::Windows::Forms::Panel^ Rightpanel; + System::Windows::Forms::Button^ button2; + System::Windows::Forms::Button^ button1; + System::Windows::Forms::Panel^ Leftpanel; + System::Windows::Forms::Button^ bnHide; + System::Windows::Forms::Button^ bnDisable; + + System::ComponentModel::Container ^components; + +#pragma region Windows Form Designer generated code + + void InitializeComponent(void) + { + this->Rightpanel = (gcnew System::Windows::Forms::Panel()); + this->button2 = (gcnew System::Windows::Forms::Button()); + this->button1 = (gcnew System::Windows::Forms::Button()); + this->Leftpanel = (gcnew System::Windows::Forms::Panel()); + this->bnHide = (gcnew System::Windows::Forms::Button()); + this->bnDisable = (gcnew System::Windows::Forms::Button()); + this->Rightpanel->SuspendLayout(); + this->Leftpanel->SuspendLayout(); + this->SuspendLayout(); + // + // Rightpanel + // + this->Rightpanel->AutoScroll = true; + this->Rightpanel->BorderStyle = + System::Windows::Forms::BorderStyle::Fixed3D; + this->Rightpanel->Controls->Add(this->button2); + this->Rightpanel->Controls->Add(this->button1); + this->Rightpanel->Location = System::Drawing::Point(161, 22); + this->Rightpanel->Name = L"Rightpanel"; + this->Rightpanel->Size = System::Drawing::Size(121, 60); + this->Rightpanel->TabIndex = 3; + // + // button2 + // + this->button2->Location = System::Drawing::Point(20, 62); + this->button2->Name = L"button2"; + this->button2->Size = System::Drawing::Size(75, 23); + this->button2->TabIndex = 1; + this->button2->Text = L"button 2"; + // + // button1 + // + this->button1->Location = System::Drawing::Point(20, 7); + this->button1->Name = L"button1"; + this->button1->Size = System::Drawing::Size(75, 23); + this->button1->TabIndex = 0; + this->button1->Text = L"button 1"; + // + // Leftpanel + // + this->Leftpanel->BorderStyle = + System::Windows::Forms::BorderStyle::FixedSingle; + this->Leftpanel->Controls->Add(this->bnHide); + this->Leftpanel->Controls->Add(this->bnDisable); + this->Leftpanel->Location = System::Drawing::Point(28, 22); + this->Leftpanel->Name = L"Leftpanel"; + this->Leftpanel->Size = System::Drawing::Size(120, 95); + this->Leftpanel->TabIndex = 2; + // + // bnHide + // + this->bnHide->Location = System::Drawing::Point(17, 62); + this->bnHide->Name = L"bnHide"; + this->bnHide->Size = System::Drawing::Size(75, 23); + this->bnHide->TabIndex = 1; + this->bnHide->Text = L"Hide"; + this->bnHide->Click += + gcnew System::EventHandler(this, &Form1::bnHide_Click); + // + // bnDisable + // + this->bnDisable->Location = System::Drawing::Point(17, 7); + this->bnDisable->Name = L"bnDisable"; + this->bnDisable->Size = System::Drawing::Size(75, 23); + this->bnDisable->TabIndex = 0; + this->bnDisable->Text = L"Disable"; + this->bnDisable->Click += + gcnew System::EventHandler(this, &Form1::bnDisable_Click); + // + // Form1 + // + this->AutoScaleDimensions = System::Drawing::SizeF(6, 13); + this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font; + this->ClientSize = System::Drawing::Size(310, 139); + this->Controls->Add(this->Rightpanel); + this->Controls->Add(this->Leftpanel); + this->Name = L"Form1"; + this->Text = L"A hidden fourth button"; + this->Rightpanel->ResumeLayout(false); + this->Leftpanel->ResumeLayout(false); + this->ResumeLayout(false); + } + +#pragma endregion + + private: + System::Void bnDisable_Click(System::Object^ sender, + System::EventArgs^ e) + { + Rightpanel->Enabled = !Rightpanel->Enabled; + } + + private: + System::Void bnHide_Click(System::Object^ sender, System::EventArgs^ e) + { + Rightpanel->Visible = !Rightpanel->Visible; + } + }; +} + diff --git a/Chapter09/Panels/Form1.resx b/Chapter09/Panels/Form1.resx new file mode 100644 index 0000000..7080a7d --- /dev/null +++ b/Chapter09/Panels/Form1.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Chapter09/Panels/Panels.cpp b/Chapter09/Panels/Panels.cpp new file mode 100644 index 0000000..918832f --- /dev/null +++ b/Chapter09/Panels/Panels.cpp @@ -0,0 +1,18 @@ +// Panels.cpp : main project file. + +#include "stdafx.h" +#include "Form1.h" + +using namespace Panels; + +[STAThreadAttribute] +int main(array ^args) +{ + // Enabling Windows XP visual effects before any controls are created + Application::EnableVisualStyles(); + Application::SetCompatibleTextRenderingDefault(false); + + // Create the main window and run it + Application::Run(gcnew Form1()); + return 0; +} diff --git a/Chapter09/Panels/Panels.vcproj b/Chapter09/Panels/Panels.vcproj new file mode 100644 index 0000000..aa5deae --- /dev/null +++ b/Chapter09/Panels/Panels.vcproj @@ -0,0 +1,250 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Chapter09/Panels/stdafx.cpp b/Chapter09/Panels/stdafx.cpp new file mode 100644 index 0000000..6702ffa --- /dev/null +++ b/Chapter09/Panels/stdafx.cpp @@ -0,0 +1,7 @@ +// stdafx.cpp : source file that includes just the standard includes +// Panels.pch will be the pre-compiled header +// stdafx.obj will contain the pre-compiled type information + +#include "stdafx.h" + + diff --git a/Chapter09/Panels/stdafx.h b/Chapter09/Panels/stdafx.h new file mode 100644 index 0000000..46bef73 --- /dev/null +++ b/Chapter09/Panels/stdafx.h @@ -0,0 +1,6 @@ +// stdafx.h : include file for standard system include files, +// or project specific include files that are used frequently, but +// are changed infrequently +#pragma once + +// TODO: reference additional headers your program requires here diff --git a/Chapter09/RichText/AssemblyInfo.cpp b/Chapter09/RichText/AssemblyInfo.cpp new file mode 100644 index 0000000..d17b6e9 --- /dev/null +++ b/Chapter09/RichText/AssemblyInfo.cpp @@ -0,0 +1,40 @@ +#include "stdafx.h" + +using namespace System; +using namespace System::Reflection; +using namespace System::Runtime::CompilerServices; +using namespace System::Runtime::InteropServices; +using namespace System::Security::Permissions; + +// +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +// +[assembly:AssemblyTitleAttribute("RichText")]; +[assembly:AssemblyDescriptionAttribute("")]; +[assembly:AssemblyConfigurationAttribute("")]; +[assembly:AssemblyCompanyAttribute("")]; +[assembly:AssemblyProductAttribute("RichText")]; +[assembly:AssemblyCopyrightAttribute("Copyright (c) 2005")]; +[assembly:AssemblyTrademarkAttribute("")]; +[assembly:AssemblyCultureAttribute("")]; + +// +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the value or you can default the Revision and Build Numbers +// by using the '*' as shown below: + +[assembly:AssemblyVersionAttribute("1.0.*")]; + +[assembly:ComVisible(false)]; + +[assembly:CLSCompliantAttribute(true)]; + +[assembly:SecurityPermission(SecurityAction::RequestMinimum, UnmanagedCode = true)]; diff --git a/Chapter09/RichText/Chapter01.rtf b/Chapter09/RichText/Chapter01.rtf new file mode 100644 index 0000000..b973e9b Binary files /dev/null and b/Chapter09/RichText/Chapter01.rtf differ diff --git a/Chapter09/RichText/Form1.h b/Chapter09/RichText/Form1.h new file mode 100644 index 0000000..24a8ee8 --- /dev/null +++ b/Chapter09/RichText/Form1.h @@ -0,0 +1,169 @@ +#pragma once + +namespace RichText +{ + using namespace System; + using namespace System::ComponentModel; + using namespace System::Collections; + using namespace System::Windows::Forms; + using namespace System::Data; + using namespace System::Drawing; + + public ref class Form1 : public System::Windows::Forms::Form + { + public: + Form1(void) + { + InitializeComponent(); + BuildLabels(); + } + + protected: + ~Form1() + { + if (components) + { + delete components; + } + } + private: + System::Windows::Forms::RichTextBox^ rtBox; + + array^ labels; + + System::ComponentModel::Container ^components; + +#pragma region Windows Form Designer generated code + + void InitializeComponent(void) + { + this->rtBox = (gcnew System::Windows::Forms::RichTextBox()); + this->SuspendLayout(); + // + // rtBox + // + this->rtBox->Anchor = + static_cast + ((((System::Windows::Forms::AnchorStyles::Top + | System::Windows::Forms::AnchorStyles::Bottom) + | System::Windows::Forms::AnchorStyles::Left) + | System::Windows::Forms::AnchorStyles::Right)); + this->rtBox->Location = System::Drawing::Point(0, 32); + this->rtBox->Name = L"rtBox"; + this->rtBox->RightMargin = 900; + this->rtBox->ScrollBars = + System::Windows::Forms::RichTextBoxScrollBars::ForcedVertical; + this->rtBox->ShowSelectionMargin = true; + this->rtBox->Size = System::Drawing::Size(950, 488); + this->rtBox->TabIndex = 1; + this->rtBox->Text = L""; + this->rtBox->KeyDown += + gcnew System::Windows::Forms::KeyEventHandler(this, + &Form1::rtBox_KeyDown); + // + // Form1 + // + this->AutoScaleDimensions = System::Drawing::SizeF(6, 13); + this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font; + this->ClientSize = System::Drawing::Size(950, 520); + this->Controls->Add(this->rtBox); + this->Name = L"Form1"; + this->Text = L"(Very Simple Rich Text Editor)"; + this->ResumeLayout(false); + } + +#pragma endregion + + void BuildLabels() + { + array^ rtLabel = gcnew array { + L"F1-Bold", L"F2-Italics", L"F3-Underline", + L"F4-Normal", L"F5-Red", L"F6-Blue", + L"F7-Green", L"F8-Black", L"F9-Load", + L"F10-Save" + }; + labels = gcnew array(10); + + // Build the labels + for (int i = 0; i < labels->Length; i++) + { + labels[i] = gcnew Label(); + labels[i]->BackColor = SystemColors::ControlDark; + labels[i]->BorderStyle = BorderStyle::FixedSingle; + labels[i]->Location = Drawing::Point(5+(95*i), 8); + labels[i]->Size = Drawing::Size(85, 16); + labels[i]->Text = rtLabel[i]; + labels[i]->TextAlign = ContentAlignment::MiddleCenter; + } + // Place labels on the Form + Controls->AddRange(labels); + } + + System::Void rtBox_KeyDown(System::Object^ sender, + System::Windows::Forms::KeyEventArgs^ e) + { + try + { + if (rtBox->SelectionLength > 0) + { + // Change selected text style + FontStyle fs; + switch (e->KeyCode) + { + case Keys::F1: + fs = FontStyle::Bold; + break; + case Keys::F2: + fs = FontStyle::Italic; + break; + case Keys::F3: + fs = FontStyle::Underline; + break; + case Keys::F4: + fs = FontStyle::Regular; + break; + // Change selected text color + case Keys::F5: + rtBox->SelectionColor = Color::Red; + break; + case Keys::F6: + rtBox->SelectionColor = Color::Blue; + break; + case Keys::F7: + rtBox->SelectionColor = Color::Green; + break; + case Keys::F8: + rtBox->SelectionColor = Color::Black; + break; + } + // Do the actual change of the selected text style + if (e->KeyCode >= Keys::F1 && e->KeyCode <= Keys::F4) + { + rtBox->SelectionFont = gcnew Drawing::Font( + rtBox->SelectionFont->FontFamily, + rtBox->SelectionFont->Size, + fs + ); + } + } + // Load hard coded Chapter01.rtf file + else if (e->KeyCode == Keys::F9) + { + rtBox->LoadFile("Chapter01.rtf"); + } + // Save hard coded Chapter01.rtf file + else if (e->KeyCode == Keys::F10) + { + rtBox->SaveFile("Chapter01.rtf", + RichTextBoxStreamType::RichText); + } + } + // Capture any blowups + catch (Exception ^e) + { + MessageBox::Show(String::Format("Error: {0}", e->Message)); + } + } + }; +} + diff --git a/Chapter09/RichText/Form1.resx b/Chapter09/RichText/Form1.resx new file mode 100644 index 0000000..7080a7d --- /dev/null +++ b/Chapter09/RichText/Form1.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Chapter09/RichText/RichText.cpp b/Chapter09/RichText/RichText.cpp new file mode 100644 index 0000000..0bee821 --- /dev/null +++ b/Chapter09/RichText/RichText.cpp @@ -0,0 +1,18 @@ +// RichText.cpp : main project file. + +#include "stdafx.h" +#include "Form1.h" + +using namespace RichText; + +[STAThreadAttribute] +int main(array ^args) +{ + // Enabling Windows XP visual effects before any controls are created + Application::EnableVisualStyles(); + Application::SetCompatibleTextRenderingDefault(false); + + // Create the main window and run it + Application::Run(gcnew Form1()); + return 0; +} diff --git a/Chapter09/RichText/RichText.vcproj b/Chapter09/RichText/RichText.vcproj new file mode 100644 index 0000000..38330bf --- /dev/null +++ b/Chapter09/RichText/RichText.vcproj @@ -0,0 +1,254 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Chapter09/RichText/stdafx.cpp b/Chapter09/RichText/stdafx.cpp new file mode 100644 index 0000000..b4d6081 --- /dev/null +++ b/Chapter09/RichText/stdafx.cpp @@ -0,0 +1,7 @@ +// stdafx.cpp : source file that includes just the standard includes +// RichText.pch will be the pre-compiled header +// stdafx.obj will contain the pre-compiled type information + +#include "stdafx.h" + + diff --git a/Chapter09/RichText/stdafx.h b/Chapter09/RichText/stdafx.h new file mode 100644 index 0000000..46bef73 --- /dev/null +++ b/Chapter09/RichText/stdafx.h @@ -0,0 +1,6 @@ +// stdafx.h : include file for standard system include files, +// or project specific include files that are used frequently, but +// are changed infrequently +#pragma once + +// TODO: reference additional headers your program requires here diff --git a/Chapter09/SplitCLB/AssemblyInfo.cpp b/Chapter09/SplitCLB/AssemblyInfo.cpp new file mode 100644 index 0000000..71054f4 --- /dev/null +++ b/Chapter09/SplitCLB/AssemblyInfo.cpp @@ -0,0 +1,40 @@ +#include "stdafx.h" + +using namespace System; +using namespace System::Reflection; +using namespace System::Runtime::CompilerServices; +using namespace System::Runtime::InteropServices; +using namespace System::Security::Permissions; + +// +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +// +[assembly:AssemblyTitleAttribute("SplitCLB")]; +[assembly:AssemblyDescriptionAttribute("")]; +[assembly:AssemblyConfigurationAttribute("")]; +[assembly:AssemblyCompanyAttribute("")]; +[assembly:AssemblyProductAttribute("SplitCLB")]; +[assembly:AssemblyCopyrightAttribute("Copyright (c) 2005")]; +[assembly:AssemblyTrademarkAttribute("")]; +[assembly:AssemblyCultureAttribute("")]; + +// +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the value or you can default the Revision and Build Numbers +// by using the '*' as shown below: + +[assembly:AssemblyVersionAttribute("1.0.*")]; + +[assembly:ComVisible(false)]; + +[assembly:CLSCompliantAttribute(true)]; + +[assembly:SecurityPermission(SecurityAction::RequestMinimum, UnmanagedCode = true)]; diff --git a/Chapter09/SplitCLB/Form1.h b/Chapter09/SplitCLB/Form1.h new file mode 100644 index 0000000..ff03da3 --- /dev/null +++ b/Chapter09/SplitCLB/Form1.h @@ -0,0 +1,149 @@ +#pragma once + +namespace SplitCLB +{ + using namespace System; + using namespace System::ComponentModel; + using namespace System::Collections; + using namespace System::Windows::Forms; + using namespace System::Data; + using namespace System::Drawing; + + public ref class Form1 : public System::Windows::Forms::Form + { + public: + Form1(void) + { + InitializeComponent(); + + array^ Items = gcnew array { + "Appleman", "Challa", "Chand", "Cornell", + "Fraser", "Gunnerson", "Harris", "Rammer", + "Symmonds", "Thomsen", "Troelsen", "Vaughn" + }; + clBox->Items->AddRange(Items); + lBox->Items->AddRange(Items); + + // Create a Check box for each entry in Items array. + cBox = gcnew array(Items->Length); + + int j = cBox->Length/2; + for (int i = 0; i < j; i++) + { + // Build Left Column + cBox[i] = gcnew CheckBox(); + cBox[i]->Location = Drawing::Point(50, 160+(30*i)); + cBox[i]->TabIndex = i+2; + cBox[i]->Text = Items[i]->ToString(); + cBox[i]->CheckStateChanged += + gcnew EventHandler(this, &Form1::cBox_CheckStateChanged); + + // Build Right Column + cBox[i+j] = gcnew CheckBox(); + cBox[i+j]->Location = Drawing::Point(180, 160+(30*i)); + cBox[i+j]->TabIndex = i+j+2; + cBox[i+j]->Text = Items[i+j]->ToString(); + cBox[i+j]->CheckStateChanged += + gcnew EventHandler(this, &Form1::cBox_CheckStateChanged); + } + // Add all CheckBoxes to Form + Controls->AddRange(cBox); + } + + protected: + ~Form1() + { + if (components) + { + delete components; + } + } + + private: + System::Windows::Forms::ListBox^ lBox; + System::Windows::Forms::CheckedListBox^ clBox; + + array^ cBox; + + System::ComponentModel::Container ^components; + +#pragma region Windows Form Designer generated code + + void InitializeComponent(void) + { + this->lBox = (gcnew System::Windows::Forms::ListBox()); + this->clBox = (gcnew System::Windows::Forms::CheckedListBox()); + this->SuspendLayout(); + // + // lBox + // + this->lBox->FormattingEnabled = true; + this->lBox->Location = System::Drawing::Point(356, 32); + this->lBox->Name = L"lBox"; + this->lBox->Size = System::Drawing::Size(120, 264); + this->lBox->TabIndex = 3; + this->lBox->SelectedIndexChanged += + gcnew System::EventHandler(this, + &Form1::lBox_SelectedIndexChanged); + // + // clBox + // + this->clBox->FormattingEnabled = true; + this->clBox->Location = System::Drawing::Point(12, 32); + this->clBox->MultiColumn = true; + this->clBox->Name = L"clBox"; + this->clBox->Size = System::Drawing::Size(323, 79); + this->clBox->TabIndex = 2; + this->clBox->ThreeDCheckBoxes = true; + this->clBox->SelectedIndexChanged += + gcnew System::EventHandler(this, + &Form1::clBox_SelectedIndexChanged); + this->clBox->ItemCheck += + gcnew System::Windows::Forms::ItemCheckEventHandler(this, + &Form1::clBox_ItemCheck); + // + // Form1 + // + this->AutoScaleDimensions = System::Drawing::SizeF(6, 13); + this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font; + this->ClientSize = System::Drawing::Size(494, 392); + this->Controls->Add(this->lBox); + this->Controls->Add(this->clBox); + this->Name = L"Form1"; + this->Text = L"Splitting The Check List Box"; + this->ResumeLayout(false); + } + +#pragma endregion + + private: + System::Void clBox_ItemCheck(System::Object^ sender, + System::Windows::Forms::ItemCheckEventArgs^ e) + { + // update state of CheckBox with same index as checked CheckedListBox + cBox[e->Index]->CheckState = e->NewValue; + } + + System::Void clBox_SelectedIndexChanged(System::Object^ sender, + System::EventArgs^ e) + { + // update ListBox with same selected item in the CheckedListBox + lBox->SelectedItem = clBox->SelectedItem->ToString(); + } + + System::Void lBox_SelectedIndexChanged(System::Object^ sender, + System::EventArgs^ e) + { + // update CheckedListBox with same selected item in the ListBox + clBox->SelectedItem = lBox->SelectedItem; + } + + void cBox_CheckStateChanged(Object^ sender, EventArgs^ e) + { + // update state of CheckedListBox with same index as checked CheckBox + CheckBox^ cb = (CheckBox^)sender; + clBox->SetItemCheckState(Array::IndexOf(cBox, cb), cb->CheckState); + } + }; +} + diff --git a/Chapter09/SplitCLB/Form1.resx b/Chapter09/SplitCLB/Form1.resx new file mode 100644 index 0000000..7080a7d --- /dev/null +++ b/Chapter09/SplitCLB/Form1.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Chapter09/SplitCLB/SplitCLB.cpp b/Chapter09/SplitCLB/SplitCLB.cpp new file mode 100644 index 0000000..83345c1 --- /dev/null +++ b/Chapter09/SplitCLB/SplitCLB.cpp @@ -0,0 +1,18 @@ +// SplitCLB.cpp : main project file. + +#include "stdafx.h" +#include "Form1.h" + +using namespace SplitCLB; + +[STAThreadAttribute] +int main(array ^args) +{ + // Enabling Windows XP visual effects before any controls are created + Application::EnableVisualStyles(); + Application::SetCompatibleTextRenderingDefault(false); + + // Create the main window and run it + Application::Run(gcnew Form1()); + return 0; +} diff --git a/Chapter09/SplitCLB/SplitCLB.vcproj b/Chapter09/SplitCLB/SplitCLB.vcproj new file mode 100644 index 0000000..6393e2b --- /dev/null +++ b/Chapter09/SplitCLB/SplitCLB.vcproj @@ -0,0 +1,250 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Chapter09/SplitCLB/stdafx.cpp b/Chapter09/SplitCLB/stdafx.cpp new file mode 100644 index 0000000..284f34d --- /dev/null +++ b/Chapter09/SplitCLB/stdafx.cpp @@ -0,0 +1,7 @@ +// stdafx.cpp : source file that includes just the standard includes +// SplitCLB.pch will be the pre-compiled header +// stdafx.obj will contain the pre-compiled type information + +#include "stdafx.h" + + diff --git a/Chapter09/SplitCLB/stdafx.h b/Chapter09/SplitCLB/stdafx.h new file mode 100644 index 0000000..46bef73 --- /dev/null +++ b/Chapter09/SplitCLB/stdafx.h @@ -0,0 +1,6 @@ +// stdafx.h : include file for standard system include files, +// or project specific include files that are used frequently, but +// are changed infrequently +#pragma once + +// TODO: reference additional headers your program requires here diff --git a/Chapter09/SyncCombos/AssemblyInfo.cpp b/Chapter09/SyncCombos/AssemblyInfo.cpp new file mode 100644 index 0000000..d615057 --- /dev/null +++ b/Chapter09/SyncCombos/AssemblyInfo.cpp @@ -0,0 +1,40 @@ +#include "stdafx.h" + +using namespace System; +using namespace System::Reflection; +using namespace System::Runtime::CompilerServices; +using namespace System::Runtime::InteropServices; +using namespace System::Security::Permissions; + +// +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +// +[assembly:AssemblyTitleAttribute("SyncCombos")]; +[assembly:AssemblyDescriptionAttribute("")]; +[assembly:AssemblyConfigurationAttribute("")]; +[assembly:AssemblyCompanyAttribute("")]; +[assembly:AssemblyProductAttribute("SyncCombos")]; +[assembly:AssemblyCopyrightAttribute("Copyright (c) 2005")]; +[assembly:AssemblyTrademarkAttribute("")]; +[assembly:AssemblyCultureAttribute("")]; + +// +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the value or you can default the Revision and Build Numbers +// by using the '*' as shown below: + +[assembly:AssemblyVersionAttribute("1.0.*")]; + +[assembly:ComVisible(false)]; + +[assembly:CLSCompliantAttribute(true)]; + +[assembly:SecurityPermission(SecurityAction::RequestMinimum, UnmanagedCode = true)]; diff --git a/Chapter09/SyncCombos/Form1.h b/Chapter09/SyncCombos/Form1.h new file mode 100644 index 0000000..897104b --- /dev/null +++ b/Chapter09/SyncCombos/Form1.h @@ -0,0 +1,136 @@ +#pragma once + +namespace SyncCombos +{ + using namespace System; + using namespace System::ComponentModel; + using namespace System::Collections; + using namespace System::Windows::Forms; + using namespace System::Data; + using namespace System::Drawing; + + public ref class Form1 : public System::Windows::Forms::Form + { + public: + Form1(void) + { + InitializeComponent(); + PopulateLists(); + } + + protected: + ~Form1() + { + if (components) + { + delete components; + } + } + + private: + System::Windows::Forms::ComboBox^ ddlist; + System::Windows::Forms::ComboBox^ simple; + System::Windows::Forms::ComboBox^ ddown; + + System::ComponentModel::Container ^components; + +#pragma region Windows Form Designer generated code + + void InitializeComponent(void) + { + this->ddlist = (gcnew System::Windows::Forms::ComboBox()); + this->simple = (gcnew System::Windows::Forms::ComboBox()); + this->ddown = (gcnew System::Windows::Forms::ComboBox()); + this->SuspendLayout(); + // + // ddlist + // + this->ddlist->DropDownStyle = + System::Windows::Forms::ComboBoxStyle::DropDownList; + this->ddlist->FormattingEnabled = true; + this->ddlist->Location = System::Drawing::Point(300, 14); + this->ddlist->Name = L"ddlist"; + this->ddlist->Size = System::Drawing::Size(121, 21); + this->ddlist->TabIndex = 5; + this->ddlist->SelectedIndexChanged += + gcnew System::EventHandler(this, &Form1::ddlist_Change); + // + // simple + // + this->simple->DropDownStyle = + System::Windows::Forms::ComboBoxStyle::Simple; + this->simple->FormattingEnabled = true; + this->simple->Location = System::Drawing::Point(154, 11); + this->simple->Name = L"simple"; + this->simple->Size = System::Drawing::Size(122, 117); + this->simple->TabIndex = 4; + this->simple->SelectedIndexChanged += + gcnew System::EventHandler(this, &Form1::simple_Change); + this->simple->TextChanged += + gcnew System::EventHandler(this, &Form1::simple_Change); + // + // ddown + // + this->ddown->FormattingEnabled = true; + this->ddown->Location = System::Drawing::Point(12, 14); + this->ddown->MaxDropDownItems = 3; + this->ddown->MaxLength = 10; + this->ddown->Name = L"ddown"; + this->ddown->Size = System::Drawing::Size(121, 21); + this->ddown->TabIndex = 3; + this->ddown->SelectedIndexChanged += + gcnew System::EventHandler(this, &Form1::ddown_Change); + this->ddown->TextChanged += + gcnew System::EventHandler(this, &Form1::ddown_Change); + // + // Form1 + // + this->AutoScaleDimensions = System::Drawing::SizeF(6, 13); + this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font; + this->ClientSize = System::Drawing::Size(433, 138); + this->Controls->Add(this->ddlist); + this->Controls->Add(this->simple); + this->Controls->Add(this->ddown); + this->Name = L"Form1"; + this->Text = L"Synchronized Combo boxing"; + this->ResumeLayout(false); + } + +#pragma endregion + + private: + void PopulateLists() + { + // Item to be placed in all ComboBoxes + array^ ddItems = gcnew array { + L"oranges", L"cherries", L"apples", + L"lemons", L"bananas", L"grapes" + }; + ddown->Items->AddRange(ddItems); + simple->Items->AddRange(ddItems); + ddlist->Items->AddRange(ddItems); + } + + System::Void ddown_Change(System::Object^ sender, System::EventArgs^ e) + { + // Update simple and dropdownlist with dropdown text + simple->Text = ddown->Text; + ddlist->SelectedItem = ddown->Text; + } + + System::Void simple_Change(System::Object^ sender,System::EventArgs^ e) + { + // Update dropdown and dropdownlist with simple text + ddown->Text = simple->Text; + ddlist->SelectedItem = simple->Text; + } + + System::Void ddlist_Change(System::Object^ sender,System::EventArgs^ e) + { + // Update simple and dropdown with dropdownlist SelectedText + ddown->SelectedItem = ddlist->SelectedItem; + simple->SelectedItem = ddlist->SelectedItem; + } + }; +} + diff --git a/Chapter09/SyncCombos/Form1.resx b/Chapter09/SyncCombos/Form1.resx new file mode 100644 index 0000000..7080a7d --- /dev/null +++ b/Chapter09/SyncCombos/Form1.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Chapter09/SyncCombos/SyncCombos.cpp b/Chapter09/SyncCombos/SyncCombos.cpp new file mode 100644 index 0000000..8d7538d --- /dev/null +++ b/Chapter09/SyncCombos/SyncCombos.cpp @@ -0,0 +1,18 @@ +// SyncCombos.cpp : main project file. + +#include "stdafx.h" +#include "Form1.h" + +using namespace SyncCombos; + +[STAThreadAttribute] +int main(array ^args) +{ + // Enabling Windows XP visual effects before any controls are created + Application::EnableVisualStyles(); + Application::SetCompatibleTextRenderingDefault(false); + + // Create the main window and run it + Application::Run(gcnew Form1()); + return 0; +} diff --git a/Chapter09/SyncCombos/SyncCombos.vcproj b/Chapter09/SyncCombos/SyncCombos.vcproj new file mode 100644 index 0000000..d65823c --- /dev/null +++ b/Chapter09/SyncCombos/SyncCombos.vcproj @@ -0,0 +1,250 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Chapter09/SyncCombos/stdafx.cpp b/Chapter09/SyncCombos/stdafx.cpp new file mode 100644 index 0000000..7d22a35 --- /dev/null +++ b/Chapter09/SyncCombos/stdafx.cpp @@ -0,0 +1,7 @@ +// stdafx.cpp : source file that includes just the standard includes +// SyncCombos.pch will be the pre-compiled header +// stdafx.obj will contain the pre-compiled type information + +#include "stdafx.h" + + diff --git a/Chapter09/SyncCombos/stdafx.h b/Chapter09/SyncCombos/stdafx.h new file mode 100644 index 0000000..46bef73 --- /dev/null +++ b/Chapter09/SyncCombos/stdafx.h @@ -0,0 +1,6 @@ +// stdafx.h : include file for standard system include files, +// or project specific include files that are used frequently, but +// are changed infrequently +#pragma once + +// TODO: reference additional headers your program requires here diff --git a/Chapter09/TextEntry/AssemblyInfo.cpp b/Chapter09/TextEntry/AssemblyInfo.cpp new file mode 100644 index 0000000..eca62e2 --- /dev/null +++ b/Chapter09/TextEntry/AssemblyInfo.cpp @@ -0,0 +1,40 @@ +#include "stdafx.h" + +using namespace System; +using namespace System::Reflection; +using namespace System::Runtime::CompilerServices; +using namespace System::Runtime::InteropServices; +using namespace System::Security::Permissions; + +// +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +// +[assembly:AssemblyTitleAttribute("TextEntry")]; +[assembly:AssemblyDescriptionAttribute("")]; +[assembly:AssemblyConfigurationAttribute("")]; +[assembly:AssemblyCompanyAttribute("")]; +[assembly:AssemblyProductAttribute("TextEntry")]; +[assembly:AssemblyCopyrightAttribute("Copyright (c) 2005")]; +[assembly:AssemblyTrademarkAttribute("")]; +[assembly:AssemblyCultureAttribute("")]; + +// +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the value or you can default the Revision and Build Numbers +// by using the '*' as shown below: + +[assembly:AssemblyVersionAttribute("1.0.*")]; + +[assembly:ComVisible(false)]; + +[assembly:CLSCompliantAttribute(true)]; + +[assembly:SecurityPermission(SecurityAction::RequestMinimum, UnmanagedCode = true)]; diff --git a/Chapter09/TextEntry/Form1.h b/Chapter09/TextEntry/Form1.h new file mode 100644 index 0000000..bb11cf7 --- /dev/null +++ b/Chapter09/TextEntry/Form1.h @@ -0,0 +1,238 @@ +#pragma once + +namespace TextEntry +{ + using namespace System; + using namespace System::ComponentModel; + using namespace System::Collections; + using namespace System::Windows::Forms; + using namespace System::Data; + using namespace System::Drawing; + + public ref class Form1 : public System::Windows::Forms::Form + { + public: + Form1(void) + { + InitializeComponent(); + + DoB = DateTime::MinValue; + + // setting validating type to DateTime + mtbDoB->ValidatingType = DateTime::typeid; + } + + protected: + ~Form1() + { + if (components) + { + delete components; + } + } + + private: + System::Windows::Forms::Button^ bnSubmit; + System::Windows::Forms::Label^ label3; + System::Windows::Forms::TextBox^ tbPassword; + System::Windows::Forms::TextBox^ tbOutput; + System::Windows::Forms::Label^ label2; + System::Windows::Forms::MaskedTextBox^ mtbDoB; + System::Windows::Forms::Label^ label1; + System::Windows::Forms::TextBox^ tbName; + + DateTime^ DoB; + + System::ComponentModel::Container ^components; + +#pragma region Windows Form Designer generated code + + void InitializeComponent(void) + { + this->bnSubmit = (gcnew System::Windows::Forms::Button()); + this->label3 = (gcnew System::Windows::Forms::Label()); + this->tbPassword = (gcnew System::Windows::Forms::TextBox()); + this->tbOutput = (gcnew System::Windows::Forms::TextBox()); + this->label2 = (gcnew System::Windows::Forms::Label()); + this->mtbDoB = (gcnew System::Windows::Forms::MaskedTextBox()); + this->label1 = (gcnew System::Windows::Forms::Label()); + this->tbName = (gcnew System::Windows::Forms::TextBox()); + this->SuspendLayout(); + // + // bnSubmit + // + this->bnSubmit->Location = System::Drawing::Point(260, 36); + this->bnSubmit->Margin = System::Windows::Forms::Padding(1,3,3,3); + this->bnSubmit->Name = L"bnSubmit"; + this->bnSubmit->Size = System::Drawing::Size(56, 20); + this->bnSubmit->TabIndex = 10; + this->bnSubmit->Text = L" Submit"; + this->bnSubmit->Click += + gcnew System::EventHandler(this, &Form1::bnSubmit_Click); + // + // label3 + // + this->label3->AutoSize = true; + this->label3->Location = System::Drawing::Point(14, 232); + this->label3->Name = L"label3"; + this->label3->Size = System::Drawing::Size(56, 13); + this->label3->TabIndex = 14; + this->label3->Text = L"Password:"; + // + // tbPassword + // + this->tbPassword->CausesValidation = false; + this->tbPassword->Location = System::Drawing::Point(78, 226); + this->tbPassword->MaxLength = 16; + this->tbPassword->Name = L"tbPassword"; + this->tbPassword->PasswordChar = '?'; + this->tbPassword->Size = System::Drawing::Size(238, 20); + this->tbPassword->TabIndex = 13; + this->tbPassword->UseSystemPasswordChar = true; + this->tbPassword->WordWrap = false; + this->tbPassword->TextChanged += + gcnew System::EventHandler(this,&Form1::tbPassword_TextChanged); + // + // tbOutput + // + this->tbOutput->Location = System::Drawing::Point(14, 63); + this->tbOutput->Multiline = true; + this->tbOutput->Name = L"tbOutput"; + this->tbOutput->ReadOnly = true; + this->tbOutput->ScrollBars = + System::Windows::Forms::ScrollBars::Vertical; + this->tbOutput->Size = System::Drawing::Size(302, 156); + this->tbOutput->TabIndex = 12; + this->tbOutput->TabStop = false; + // + // label2 + // + this->label2->AutoSize = true; + this->label2->Location = System::Drawing::Point(168, 15); + this->label2->Name = L"label2"; + this->label2->Size = System::Drawing::Size(69, 13); + this->label2->TabIndex = 11; + this->label2->Text = L"Date of Birth:"; + // + // mtbDoB + // + this->mtbDoB->AllowPromptAsInput = false; + this->mtbDoB->BeepOnError = true; + this->mtbDoB->Location = System::Drawing::Point(168, 36); + this->mtbDoB->Margin = System::Windows::Forms::Padding(3,3,1,3); + this->mtbDoB->Mask = L"00/00/0000"; + this->mtbDoB->Name = L"mtbDoB"; + this->mtbDoB->Size = System::Drawing::Size(89, 20); + this->mtbDoB->TabIndex = 8; + this->mtbDoB->TypeValidationCompleted += + gcnew System::Windows::Forms::TypeValidationEventHandler(this, + &Form1::mtbDoB_TypeValidationCompleted); + // + // label1 + // + this->label1->AutoSize = true; + this->label1->Location = System::Drawing::Point(14, 15); + this->label1->Name = L"label1"; + this->label1->Size = System::Drawing::Size(38, 13); + this->label1->TabIndex = 9; + this->label1->Text = L"Name:"; + // + // tbName + // + this->tbName->Location = System::Drawing::Point(14, 36); + this->tbName->Name = L"tbName"; + this->tbName->Size = System::Drawing::Size(147, 20); + this->tbName->TabIndex = 7; + this->tbName->Validating += + gcnew System::ComponentModel::CancelEventHandler(this, + &Form1::tbName_Validating); + // + // Form1 + // + this->AutoScaleDimensions = System::Drawing::SizeF(6, 13); + this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font; + this->ClientSize = System::Drawing::Size(331, 261); + this->Controls->Add(this->bnSubmit); + this->Controls->Add(this->label3); + this->Controls->Add(this->tbPassword); + this->Controls->Add(this->tbOutput); + this->Controls->Add(this->label2); + this->Controls->Add(this->mtbDoB); + this->Controls->Add(this->label1); + this->Controls->Add(this->tbName); + this->Name = L"Form1"; + this->Text = L"Simple entry data entry"; + this->ResumeLayout(false); + this->PerformLayout(); + } + +#pragma endregion + + private: + System::Void bnSubmit_Click(System::Object^ sender, + System::EventArgs^ e) + { + if (tbName->Text->Length <= 0) // Blank name bad! + tbName->Focus(); + else if (*DoB == DateTime::MinValue) // Bad date bad! + mtbDoB->Focus(); + else // Good! + { + // Concatinate name and date of birth and add to output + tbOutput->Text = String::Format("{0} - {1}\r\n{2}", + tbName->Text, mtbDoB->Text, tbOutput->Text); + tbName->Clear(); + mtbDoB->Clear(); + DoB = DateTime::MinValue; + } + } + + System::Void tbPassword_TextChanged(System::Object^ sender, + System::EventArgs^ e) + { + // if the Password TextBox Text equals "Editable" then make + // the multiline TextBox editable and have a tab stop + if (tbPassword->Text->Equals("Editable")) + { + tbOutput->TabStop = true; + tbOutput->ReadOnly = false; + } + else + { + tbOutput->TabStop = false; + tbOutput->ReadOnly = true; + } + } + + System::Void mtbDoB_TypeValidationCompleted(System::Object^ sender, + System::Windows::Forms::TypeValidationEventArgs^ e) + { + // Check to see if the date was valid and less then or equals + // todays date. When false make the MaskedTextBox yellow + // and make DoB MinValue. otherwise set it to normal and make + // DoB the value within MaskedTextBox + if (e->IsValidInput && + (*(DateTime^)e->ReturnValue) <= DateTime::Now) + { + DoB = (DateTime^)e->ReturnValue; + mtbDoB->BackColor = SystemColors::Window; + } + else + { + mtbDoB->BackColor = Color::Yellow; + DoB = DateTime::MinValue; + } + } + + System::Void tbName_Validating(System::Object^ sender, + System::ComponentModel::CancelEventArgs^ e) + { + // Check to make sure there is a name. When false make the + // TextBox yellow. Otherwise set it to normal as all is okay + if (tbName->Text->Length <= 0) + tbName->BackColor = Color::Yellow; + else + tbName->BackColor = SystemColors::Window; + } + }; +} diff --git a/Chapter09/TextEntry/Form1.resx b/Chapter09/TextEntry/Form1.resx new file mode 100644 index 0000000..7080a7d --- /dev/null +++ b/Chapter09/TextEntry/Form1.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Chapter09/TextEntry/TextEntry.cpp b/Chapter09/TextEntry/TextEntry.cpp new file mode 100644 index 0000000..f008bc8 --- /dev/null +++ b/Chapter09/TextEntry/TextEntry.cpp @@ -0,0 +1,18 @@ +// TextEntry.cpp : main project file. + +#include "stdafx.h" +#include "Form1.h" + +using namespace TextEntry; + +[STAThreadAttribute] +int main(array ^args) +{ + // Enabling Windows XP visual effects before any controls are created + Application::EnableVisualStyles(); + Application::SetCompatibleTextRenderingDefault(false); + + // Create the main window and run it + Application::Run(gcnew Form1()); + return 0; +} diff --git a/Chapter09/TextEntry/TextEntry.vcproj b/Chapter09/TextEntry/TextEntry.vcproj new file mode 100644 index 0000000..8dc36a1 --- /dev/null +++ b/Chapter09/TextEntry/TextEntry.vcproj @@ -0,0 +1,250 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Chapter09/TextEntry/stdafx.cpp b/Chapter09/TextEntry/stdafx.cpp new file mode 100644 index 0000000..ecc8ae1 --- /dev/null +++ b/Chapter09/TextEntry/stdafx.cpp @@ -0,0 +1,7 @@ +// stdafx.cpp : source file that includes just the standard includes +// TextEntry.pch will be the pre-compiled header +// stdafx.obj will contain the pre-compiled type information + +#include "stdafx.h" + + diff --git a/Chapter09/TextEntry/stdafx.h b/Chapter09/TextEntry/stdafx.h new file mode 100644 index 0000000..46bef73 --- /dev/null +++ b/Chapter09/TextEntry/stdafx.h @@ -0,0 +1,6 @@ +// stdafx.h : include file for standard system include files, +// or project specific include files that are used frequently, but +// are changed infrequently +#pragma once + +// TODO: reference additional headers your program requires here diff --git a/Chapter09/TooManyButtons/AssemblyInfo.cpp b/Chapter09/TooManyButtons/AssemblyInfo.cpp new file mode 100644 index 0000000..9765912 --- /dev/null +++ b/Chapter09/TooManyButtons/AssemblyInfo.cpp @@ -0,0 +1,40 @@ +#include "stdafx.h" + +using namespace System; +using namespace System::Reflection; +using namespace System::Runtime::CompilerServices; +using namespace System::Runtime::InteropServices; +using namespace System::Security::Permissions; + +// +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +// +[assembly:AssemblyTitleAttribute("TooManyButtons")]; +[assembly:AssemblyDescriptionAttribute("")]; +[assembly:AssemblyConfigurationAttribute("")]; +[assembly:AssemblyCompanyAttribute("")]; +[assembly:AssemblyProductAttribute("TooManyButtons")]; +[assembly:AssemblyCopyrightAttribute("Copyright (c) 2005")]; +[assembly:AssemblyTrademarkAttribute("")]; +[assembly:AssemblyCultureAttribute("")]; + +// +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the value or you can default the Revision and Build Numbers +// by using the '*' as shown below: + +[assembly:AssemblyVersionAttribute("1.0.*")]; + +[assembly:ComVisible(false)]; + +[assembly:CLSCompliantAttribute(true)]; + +[assembly:SecurityPermission(SecurityAction::RequestMinimum, UnmanagedCode = true)]; diff --git a/Chapter09/TooManyButtons/Form1.h b/Chapter09/TooManyButtons/Form1.h new file mode 100644 index 0000000..6862a37 --- /dev/null +++ b/Chapter09/TooManyButtons/Form1.h @@ -0,0 +1,81 @@ +#pragma once + +namespace TooManyButtons +{ + using namespace System; + using namespace System::ComponentModel; + using namespace System::Collections; + using namespace System::Windows::Forms; + using namespace System::Data; + using namespace System::Drawing; + + public ref class Form1 : public System::Windows::Forms::Form + { + public: + Form1(void) + { + InitializeComponent(); + } + + protected: + ~Form1() + { + if (components) + { + delete components; + } + } + private: + System::Windows::Forms::Button^ TooMany; + + System::ComponentModel::Container ^components; + +#pragma region Windows Form Designer generated code + + void InitializeComponent(void) + { + this->TooMany = (gcnew System::Windows::Forms::Button()); + this->SuspendLayout(); + // + // TooMany + // + this->TooMany->Location = System::Drawing::Point(12, 12); + this->TooMany->Name = L"TooMany"; + this->TooMany->Size = System::Drawing::Size(75, 23); + this->TooMany->TabIndex = 1; + this->TooMany->Text = L"Click Me!"; + this->TooMany->Click += + gcnew System::EventHandler(this, &Form1::TooMany_Click); + // + // Form1 + // + this->AutoScaleDimensions = System::Drawing::SizeF(6, 13); + this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font; + this->AutoScroll = true; + this->ClientSize = System::Drawing::Size(292, 273); + this->Controls->Add(this->TooMany); + this->Name = L"Form1"; + this->Text = L"Too Many Buttons"; + this->ResumeLayout(false); + } + +#pragma endregion + + private: + System::Void TooMany_Click(System::Object^ sender, + System::EventArgs^ e) + { + // Grab the location of the button that was clicked + Point p = ((Button^)sender)->Location; + + // Create a dynamic button + Button ^Many = gcnew Button(); + Many->Location = Drawing::Point(p.X + 36, p.Y + 26); + Many->Text = L"Click Me!"; + Many->Click += gcnew System::EventHandler(this, + &Form1::TooMany_Click); + // Add dynamic button to Form + Controls->Add(Many); + } + }; +} diff --git a/Chapter09/TooManyButtons/Form1.resx b/Chapter09/TooManyButtons/Form1.resx new file mode 100644 index 0000000..7080a7d --- /dev/null +++ b/Chapter09/TooManyButtons/Form1.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Chapter09/TooManyButtons/TooManyButtons.cpp b/Chapter09/TooManyButtons/TooManyButtons.cpp new file mode 100644 index 0000000..89f8565 --- /dev/null +++ b/Chapter09/TooManyButtons/TooManyButtons.cpp @@ -0,0 +1,18 @@ +// TooManyButtons.cpp : main project file. + +#include "stdafx.h" +#include "Form1.h" + +using namespace TooManyButtons; + +[STAThreadAttribute] +int main(array ^args) +{ + // Enabling Windows XP visual effects before any controls are created + Application::EnableVisualStyles(); + Application::SetCompatibleTextRenderingDefault(false); + + // Create the main window and run it + Application::Run(gcnew Form1()); + return 0; +} diff --git a/Chapter09/TooManyButtons/TooManyButtons.vcproj b/Chapter09/TooManyButtons/TooManyButtons.vcproj new file mode 100644 index 0000000..659bc84 --- /dev/null +++ b/Chapter09/TooManyButtons/TooManyButtons.vcproj @@ -0,0 +1,250 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Chapter09/TooManyButtons/stdafx.cpp b/Chapter09/TooManyButtons/stdafx.cpp new file mode 100644 index 0000000..d3ad02a --- /dev/null +++ b/Chapter09/TooManyButtons/stdafx.cpp @@ -0,0 +1,7 @@ +// stdafx.cpp : source file that includes just the standard includes +// TooManyButtons.pch will be the pre-compiled header +// stdafx.obj will contain the pre-compiled type information + +#include "stdafx.h" + + diff --git a/Chapter09/TooManyButtons/stdafx.h b/Chapter09/TooManyButtons/stdafx.h new file mode 100644 index 0000000..46bef73 --- /dev/null +++ b/Chapter09/TooManyButtons/stdafx.h @@ -0,0 +1,6 @@ +// stdafx.h : include file for standard system include files, +// or project specific include files that are used frequently, but +// are changed infrequently +#pragma once + +// TODO: reference additional headers your program requires here diff --git a/Chapter10/Chapter10.sln b/Chapter10/Chapter10.sln new file mode 100644 index 0000000..997a479 --- /dev/null +++ b/Chapter10/Chapter10.sln @@ -0,0 +1,92 @@ + +Microsoft Visual Studio Solution File, Format Version 9.00 +# Visual Studio 2005 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ListViewEx", "ListViewEx\ListViewEx.vcproj", "{A223F2E8-EA2C-4B07-8DD3-9CF46828F84D}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "TreeViewEx", "TreeViewEx\TreeViewEx.vcproj", "{81576C83-0520-44AF-AC69-E380284D6C52}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "TabControlEx", "TabControlEx\TabControlEx.vcproj", "{9FF43562-ECBE-4897-9472-BD3CB5F78996}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "SplitContainerEx", "SplitContainerEx\SplitContainerEx.vcproj", "{59A03817-D772-4772-8052-708D94E74508}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ToolStripEx", "ToolStripEx\ToolStripEx.vcproj", "{B68AE121-DC3E-4795-8071-87DD4D29D9A6}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "StatusStripEx", "StatusStripEx\StatusStripEx.vcproj", "{BC9ACAB2-FD43-4CD1-B3D9-513CC202B073}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "SimpleMenu", "SimpleMenu\SimpleMenu.vcproj", "{6F7B2B34-C41A-4CA6-B701-3AE0B94A62B3}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "PictureBoxEx", "PictureBoxEx\PictureBoxEx.vcproj", "{EF6B0287-13FD-45A8-88C2-EB961D9317EB}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "MonthCalendarEx", "MonthCalendarEx\MonthCalendarEx.vcproj", "{E6DA953C-4580-48FA-B9F6-1B3A65F5F4E8}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "NotifyIconEx", "NotifyIconEx\NotifyIconEx.vcproj", "{03B06887-B2C1-440C-A852-94545F540B07}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ErrorProviderEx", "ErrorProviderEx\ErrorProviderEx.vcproj", "{D547D9A8-3732-44F6-AF9D-9962F7FA8883}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "CustomDialog", "CustomDialog\CustomDialog.vcproj", "{D5E65699-D8A6-4432-AB41-BA3B59D58CF6}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ColorDialogEx", "ColorDialogEx\ColorDialogEx.vcproj", "{4B8FC566-68F0-47FD-A13F-550D7CF07EF0}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Win32 = Debug|Win32 + Release|Win32 = Release|Win32 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {A223F2E8-EA2C-4B07-8DD3-9CF46828F84D}.Debug|Win32.ActiveCfg = Debug|Win32 + {A223F2E8-EA2C-4B07-8DD3-9CF46828F84D}.Debug|Win32.Build.0 = Debug|Win32 + {A223F2E8-EA2C-4B07-8DD3-9CF46828F84D}.Release|Win32.ActiveCfg = Release|Win32 + {A223F2E8-EA2C-4B07-8DD3-9CF46828F84D}.Release|Win32.Build.0 = Release|Win32 + {81576C83-0520-44AF-AC69-E380284D6C52}.Debug|Win32.ActiveCfg = Debug|Win32 + {81576C83-0520-44AF-AC69-E380284D6C52}.Debug|Win32.Build.0 = Debug|Win32 + {81576C83-0520-44AF-AC69-E380284D6C52}.Release|Win32.ActiveCfg = Release|Win32 + {81576C83-0520-44AF-AC69-E380284D6C52}.Release|Win32.Build.0 = Release|Win32 + {9FF43562-ECBE-4897-9472-BD3CB5F78996}.Debug|Win32.ActiveCfg = Debug|Win32 + {9FF43562-ECBE-4897-9472-BD3CB5F78996}.Debug|Win32.Build.0 = Debug|Win32 + {9FF43562-ECBE-4897-9472-BD3CB5F78996}.Release|Win32.ActiveCfg = Release|Win32 + {9FF43562-ECBE-4897-9472-BD3CB5F78996}.Release|Win32.Build.0 = Release|Win32 + {59A03817-D772-4772-8052-708D94E74508}.Debug|Win32.ActiveCfg = Debug|Win32 + {59A03817-D772-4772-8052-708D94E74508}.Debug|Win32.Build.0 = Debug|Win32 + {59A03817-D772-4772-8052-708D94E74508}.Release|Win32.ActiveCfg = Release|Win32 + {59A03817-D772-4772-8052-708D94E74508}.Release|Win32.Build.0 = Release|Win32 + {B68AE121-DC3E-4795-8071-87DD4D29D9A6}.Debug|Win32.ActiveCfg = Debug|Win32 + {B68AE121-DC3E-4795-8071-87DD4D29D9A6}.Debug|Win32.Build.0 = Debug|Win32 + {B68AE121-DC3E-4795-8071-87DD4D29D9A6}.Release|Win32.ActiveCfg = Release|Win32 + {B68AE121-DC3E-4795-8071-87DD4D29D9A6}.Release|Win32.Build.0 = Release|Win32 + {BC9ACAB2-FD43-4CD1-B3D9-513CC202B073}.Debug|Win32.ActiveCfg = Debug|Win32 + {BC9ACAB2-FD43-4CD1-B3D9-513CC202B073}.Debug|Win32.Build.0 = Debug|Win32 + {BC9ACAB2-FD43-4CD1-B3D9-513CC202B073}.Release|Win32.ActiveCfg = Release|Win32 + {BC9ACAB2-FD43-4CD1-B3D9-513CC202B073}.Release|Win32.Build.0 = Release|Win32 + {6F7B2B34-C41A-4CA6-B701-3AE0B94A62B3}.Debug|Win32.ActiveCfg = Debug|Win32 + {6F7B2B34-C41A-4CA6-B701-3AE0B94A62B3}.Debug|Win32.Build.0 = Debug|Win32 + {6F7B2B34-C41A-4CA6-B701-3AE0B94A62B3}.Release|Win32.ActiveCfg = Release|Win32 + {6F7B2B34-C41A-4CA6-B701-3AE0B94A62B3}.Release|Win32.Build.0 = Release|Win32 + {EF6B0287-13FD-45A8-88C2-EB961D9317EB}.Debug|Win32.ActiveCfg = Debug|Win32 + {EF6B0287-13FD-45A8-88C2-EB961D9317EB}.Debug|Win32.Build.0 = Debug|Win32 + {EF6B0287-13FD-45A8-88C2-EB961D9317EB}.Release|Win32.ActiveCfg = Release|Win32 + {EF6B0287-13FD-45A8-88C2-EB961D9317EB}.Release|Win32.Build.0 = Release|Win32 + {E6DA953C-4580-48FA-B9F6-1B3A65F5F4E8}.Debug|Win32.ActiveCfg = Debug|Win32 + {E6DA953C-4580-48FA-B9F6-1B3A65F5F4E8}.Debug|Win32.Build.0 = Debug|Win32 + {E6DA953C-4580-48FA-B9F6-1B3A65F5F4E8}.Release|Win32.ActiveCfg = Release|Win32 + {E6DA953C-4580-48FA-B9F6-1B3A65F5F4E8}.Release|Win32.Build.0 = Release|Win32 + {03B06887-B2C1-440C-A852-94545F540B07}.Debug|Win32.ActiveCfg = Debug|Win32 + {03B06887-B2C1-440C-A852-94545F540B07}.Debug|Win32.Build.0 = Debug|Win32 + {03B06887-B2C1-440C-A852-94545F540B07}.Release|Win32.ActiveCfg = Release|Win32 + {03B06887-B2C1-440C-A852-94545F540B07}.Release|Win32.Build.0 = Release|Win32 + {D547D9A8-3732-44F6-AF9D-9962F7FA8883}.Debug|Win32.ActiveCfg = Debug|Win32 + {D547D9A8-3732-44F6-AF9D-9962F7FA8883}.Debug|Win32.Build.0 = Debug|Win32 + {D547D9A8-3732-44F6-AF9D-9962F7FA8883}.Release|Win32.ActiveCfg = Release|Win32 + {D547D9A8-3732-44F6-AF9D-9962F7FA8883}.Release|Win32.Build.0 = Release|Win32 + {D5E65699-D8A6-4432-AB41-BA3B59D58CF6}.Debug|Win32.ActiveCfg = Debug|Win32 + {D5E65699-D8A6-4432-AB41-BA3B59D58CF6}.Debug|Win32.Build.0 = Debug|Win32 + {D5E65699-D8A6-4432-AB41-BA3B59D58CF6}.Release|Win32.ActiveCfg = Release|Win32 + {D5E65699-D8A6-4432-AB41-BA3B59D58CF6}.Release|Win32.Build.0 = Release|Win32 + {4B8FC566-68F0-47FD-A13F-550D7CF07EF0}.Debug|Win32.ActiveCfg = Debug|Win32 + {4B8FC566-68F0-47FD-A13F-550D7CF07EF0}.Debug|Win32.Build.0 = Debug|Win32 + {4B8FC566-68F0-47FD-A13F-550D7CF07EF0}.Release|Win32.ActiveCfg = Release|Win32 + {4B8FC566-68F0-47FD-A13F-550D7CF07EF0}.Release|Win32.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/Chapter10/Chapter10.suo b/Chapter10/Chapter10.suo new file mode 100644 index 0000000..0fdbc65 Binary files /dev/null and b/Chapter10/Chapter10.suo differ diff --git a/Chapter10/ColorDialogEx/AssemblyInfo.cpp b/Chapter10/ColorDialogEx/AssemblyInfo.cpp new file mode 100644 index 0000000..a5817e9 --- /dev/null +++ b/Chapter10/ColorDialogEx/AssemblyInfo.cpp @@ -0,0 +1,35 @@ +#include "stdafx.h" + +using namespace System::Reflection; +using namespace System::Runtime::CompilerServices; +using namespace System::Runtime::InteropServices; + +// +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +// +[assembly:AssemblyTitleAttribute("ColorDialogEx")]; +[assembly:AssemblyDescriptionAttribute("")]; +[assembly:AssemblyConfigurationAttribute("")]; +[assembly:AssemblyCompanyAttribute("")]; +[assembly:AssemblyProductAttribute("ColorDialogEx")]; +[assembly:AssemblyCopyrightAttribute("Copyright (c) 2005")]; +[assembly:AssemblyTrademarkAttribute("")]; +[assembly:AssemblyCultureAttribute("")]; + +// +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the value or you can default the Revision and Build Numbers +// by using the '*' as shown below: + +[assembly:AssemblyVersionAttribute("1.0.*")]; + +[assembly:ComVisible(false)]; + diff --git a/Chapter10/ColorDialogEx/ColorDialogEx.cpp b/Chapter10/ColorDialogEx/ColorDialogEx.cpp new file mode 100644 index 0000000..3c122ae --- /dev/null +++ b/Chapter10/ColorDialogEx/ColorDialogEx.cpp @@ -0,0 +1,16 @@ +// ColorDialogEx.cpp : main project file. + +#include "stdafx.h" +#include "Form1.h" + +using namespace ColorDialogEx; + +[STAThreadAttribute] +int main(array ^args) +{ + // Enabling Windows XP visual effects before any controls are created + Application::EnableVisualStyles(); + // Create the main window and run it + Application::Run(gcnew Form1()); + return 0; +} diff --git a/Chapter10/ColorDialogEx/ColorDialogEx.vcproj b/Chapter10/ColorDialogEx/ColorDialogEx.vcproj new file mode 100644 index 0000000..66eef9c --- /dev/null +++ b/Chapter10/ColorDialogEx/ColorDialogEx.vcproj @@ -0,0 +1,254 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Chapter10/ColorDialogEx/Form1.h b/Chapter10/ColorDialogEx/Form1.h new file mode 100644 index 0000000..e7bc208 --- /dev/null +++ b/Chapter10/ColorDialogEx/Form1.h @@ -0,0 +1,66 @@ +#pragma once + + +namespace ColorDialogEx { + + using namespace System; + using namespace System::ComponentModel; + using namespace System::Collections; + using namespace System::Windows::Forms; + using namespace System::Data; + using namespace System::Drawing; + + public ref class Form1 : public System::Windows::Forms::Form + { + public: + Form1(void) + { + InitializeComponent(); + } + + protected: + ~Form1() + { + if (components) + { + delete components; + } + } + + private: + System::ComponentModel::Container ^components; + +#pragma region Windows Form Designer generated code + + void InitializeComponent(void) + { + this->SuspendLayout(); + // + // Form1 + // + this->AutoScaleDimensions = System::Drawing::SizeF(6, 13); + this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font; + this->ClientSize = System::Drawing::Size(292, 273); + this->Name = L"Form1"; + this->Text = L"Common Color Dialog - Click Form"; + this->Click += + gcnew System::EventHandler(this, &Form1::Form1_Click); + this->ResumeLayout(false); + + } +#pragma endregion + + private: + System::Void Form1_Click(System::Object^ sender, System::EventArgs^ e) + { + ColorDialog^ colordialog = gcnew ColorDialog(); + + if (colordialog->ShowDialog() == + System::Windows::Forms::DialogResult::OK) + { + BackColor = colordialog->Color; + } + } + }; +} + diff --git a/Chapter10/ColorDialogEx/Form1.resx b/Chapter10/ColorDialogEx/Form1.resx new file mode 100644 index 0000000..de824e1 --- /dev/null +++ b/Chapter10/ColorDialogEx/Form1.resx @@ -0,0 +1,110 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Chapter10/ColorDialogEx/resource.h b/Chapter10/ColorDialogEx/resource.h new file mode 100644 index 0000000..d5ac7c4 --- /dev/null +++ b/Chapter10/ColorDialogEx/resource.h @@ -0,0 +1,3 @@ +//{{NO_DEPENDENCIES}} +// Microsoft Visual C++ generated include file. +// Used by app.rc diff --git a/Chapter10/ColorDialogEx/stdafx.cpp b/Chapter10/ColorDialogEx/stdafx.cpp new file mode 100644 index 0000000..98db4b9 --- /dev/null +++ b/Chapter10/ColorDialogEx/stdafx.cpp @@ -0,0 +1,7 @@ +// stdafx.cpp : source file that includes just the standard includes +// ColorDialogEx.pch will be the pre-compiled header +// stdafx.obj will contain the pre-compiled type information + +#include "stdafx.h" + + diff --git a/Chapter10/ColorDialogEx/stdafx.h b/Chapter10/ColorDialogEx/stdafx.h new file mode 100644 index 0000000..46bef73 --- /dev/null +++ b/Chapter10/ColorDialogEx/stdafx.h @@ -0,0 +1,6 @@ +// stdafx.h : include file for standard system include files, +// or project specific include files that are used frequently, but +// are changed infrequently +#pragma once + +// TODO: reference additional headers your program requires here diff --git a/Chapter10/CustomDialog/AssemblyInfo.cpp b/Chapter10/CustomDialog/AssemblyInfo.cpp new file mode 100644 index 0000000..15ffeeb --- /dev/null +++ b/Chapter10/CustomDialog/AssemblyInfo.cpp @@ -0,0 +1,35 @@ +#include "stdafx.h" + +using namespace System::Reflection; +using namespace System::Runtime::CompilerServices; +using namespace System::Runtime::InteropServices; + +// +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +// +[assembly:AssemblyTitleAttribute("CustomDialog")]; +[assembly:AssemblyDescriptionAttribute("")]; +[assembly:AssemblyConfigurationAttribute("")]; +[assembly:AssemblyCompanyAttribute("")]; +[assembly:AssemblyProductAttribute("CustomDialog")]; +[assembly:AssemblyCopyrightAttribute("Copyright (c) 2005")]; +[assembly:AssemblyTrademarkAttribute("")]; +[assembly:AssemblyCultureAttribute("")]; + +// +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the value or you can default the Revision and Build Numbers +// by using the '*' as shown below: + +[assembly:AssemblyVersionAttribute("1.0.*")]; + +[assembly:ComVisible(false)]; + diff --git a/Chapter10/CustomDialog/CustomDialog.cpp b/Chapter10/CustomDialog/CustomDialog.cpp new file mode 100644 index 0000000..f53550d --- /dev/null +++ b/Chapter10/CustomDialog/CustomDialog.cpp @@ -0,0 +1,16 @@ +// CustomDialog.cpp : main project file. + +#include "stdafx.h" +#include "Form1.h" + +using namespace CustomDialog; + +[STAThreadAttribute] +int main(array ^args) +{ + // Enabling Windows XP visual effects before any controls are created + Application::EnableVisualStyles(); + // Create the main window and run it + Application::Run(gcnew Form1()); + return 0; +} diff --git a/Chapter10/CustomDialog/CustomDialog.vcproj b/Chapter10/CustomDialog/CustomDialog.vcproj new file mode 100644 index 0000000..1bae514 --- /dev/null +++ b/Chapter10/CustomDialog/CustomDialog.vcproj @@ -0,0 +1,263 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Chapter10/CustomDialog/Form1.h b/Chapter10/CustomDialog/Form1.h new file mode 100644 index 0000000..e2b6463 --- /dev/null +++ b/Chapter10/CustomDialog/Form1.h @@ -0,0 +1,93 @@ +#pragma once + +#include "MyDialog.h" + +namespace CustomDialog { + + using namespace System; + using namespace System::ComponentModel; + using namespace System::Collections; + using namespace System::Windows::Forms; + using namespace System::Data; + using namespace System::Drawing; + + public ref class Form1 : public System::Windows::Forms::Form + { + public: + Form1(void) + { + InitializeComponent(); + } + + protected: + ~Form1() + { + if (components) + { + delete components; + } + } + + private: + System::Windows::Forms::Label^ lbRetString; + System::Windows::Forms::Label^ lbRetVal; + System::ComponentModel::Container ^components; + +#pragma region Windows Form Designer generated code + + void InitializeComponent(void) + { + this->lbRetString = (gcnew System::Windows::Forms::Label()); + this->lbRetVal = (gcnew System::Windows::Forms::Label()); + this->SuspendLayout(); + // + // lbRetString + // + this->lbRetString->Location = System::Drawing::Point(34, 119); + this->lbRetString->Name = L"lbRetString"; + this->lbRetString->Size = System::Drawing::Size(225, 19); + this->lbRetString->TabIndex = 3; + // + // lbRetVal + // + this->lbRetVal->Location = System::Drawing::Point(34, 77); + this->lbRetVal->Name = L"lbRetVal"; + this->lbRetVal->Size = System::Drawing::Size(225, 19); + this->lbRetVal->TabIndex = 2; + // + // Form1 + // + this->AutoScaleDimensions = System::Drawing::SizeF(6, 13); + this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font; + this->ClientSize = System::Drawing::Size(292, 273); + this->Controls->Add(this->lbRetString); + this->Controls->Add(this->lbRetVal); + this->Name = L"Form1"; + this->Text = L"Click Form to get dialog"; + this->Click += + gcnew System::EventHandler(this, &Form1::Form1_Click); + this->ResumeLayout(false); + } + +#pragma endregion + + private: + System::Void Form1_Click(System::Object^ sender, System::EventArgs^ e) + { + MyDialog ^mydialog = gcnew MyDialog(); + mydialog->PassedValue = "This has been passed from Form1"; + + if (mydialog->ShowDialog() == + System::Windows::Forms::DialogResult::OK) + lbRetVal->Text = "OK"; + else if (mydialog->DialogResult == + System::Windows::Forms::DialogResult::Abort) + lbRetVal->Text = "Abort"; + else + lbRetVal->Text = "Cancel"; + + lbRetString->Text = mydialog->PassedValue; + } + }; +} + diff --git a/Chapter10/CustomDialog/Form1.resx b/Chapter10/CustomDialog/Form1.resx new file mode 100644 index 0000000..de824e1 --- /dev/null +++ b/Chapter10/CustomDialog/Form1.resx @@ -0,0 +1,110 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Chapter10/CustomDialog/MyDialog.h b/Chapter10/CustomDialog/MyDialog.h new file mode 100644 index 0000000..1019356 --- /dev/null +++ b/Chapter10/CustomDialog/MyDialog.h @@ -0,0 +1,110 @@ +#pragma once + +using namespace System; +using namespace System::ComponentModel; +using namespace System::Collections; +using namespace System::Windows::Forms; +using namespace System::Data; +using namespace System::Drawing; + + +namespace CustomDialog { + + public ref class MyDialog : public System::Windows::Forms::Form + { + public: + MyDialog(void) + { + InitializeComponent(); + } + + protected: + ~MyDialog() + { + if (components) + { + delete components; + } + } + + public: + property String^ PassedValue // PassedValue property + { + void set(String ^value) + { + tbPassedValue->Text = value; + } + String ^get() + { + return tbPassedValue->Text; + } + } + + private: + System::Windows::Forms::Button^ bnCancel; + System::Windows::Forms::Button^ bnAbort; + System::Windows::Forms::Button^ bnOK; + System::Windows::Forms::TextBox^ tbPassedValue; + System::ComponentModel::Container ^components; + +#pragma region Windows Form Designer generated code + + void InitializeComponent(void) + { + this->bnCancel = (gcnew System::Windows::Forms::Button()); + this->bnAbort = (gcnew System::Windows::Forms::Button()); + this->bnOK = (gcnew System::Windows::Forms::Button()); + this->tbPassedValue = (gcnew System::Windows::Forms::TextBox()); + this->SuspendLayout(); + // + // bnCancel + // + this->bnCancel->DialogResult = System::Windows::Forms::DialogResult::Cancel; + this->bnCancel->Location = System::Drawing::Point(205, 60); + this->bnCancel->Name = L"bnCancel"; + this->bnCancel->Size = System::Drawing::Size(75, 23); + this->bnCancel->TabIndex = 7; + this->bnCancel->Text = L"Cancel"; + // + // bnAbort + // + this->bnAbort->DialogResult = System::Windows::Forms::DialogResult::Abort; + this->bnAbort->Location = System::Drawing::Point(110, 60); + this->bnAbort->Name = L"bnAbort"; + this->bnAbort->Size = System::Drawing::Size(75, 23); + this->bnAbort->TabIndex = 6; + this->bnAbort->Text = L"Abort"; + // + // bnOK + // + this->bnOK->DialogResult = System::Windows::Forms::DialogResult::OK; + this->bnOK->Location = System::Drawing::Point(13, 60); + this->bnOK->Name = L"bnOK"; + this->bnOK->Size = System::Drawing::Size(75, 23); + this->bnOK->TabIndex = 5; + this->bnOK->Text = L"OK"; + // + // tbPassedValue + // + this->tbPassedValue->Location = System::Drawing::Point(13, 20); + this->tbPassedValue->Name = L"tbPassedValue"; + this->tbPassedValue->Size = System::Drawing::Size(267, 20); + this->tbPassedValue->TabIndex = 4; + // + // myDialog + // + this->AutoScaleDimensions = System::Drawing::SizeF(6, 13); + this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font; + this->ClientSize = System::Drawing::Size(292, 102); + this->Controls->Add(this->bnCancel); + this->Controls->Add(this->bnAbort); + this->Controls->Add(this->bnOK); + this->Controls->Add(this->tbPassedValue); + this->Name = L"myDialog"; + this->Text = L"My Custom Dialog"; + this->ResumeLayout(false); + this->PerformLayout(); + } +#pragma endregion + }; +} diff --git a/Chapter10/CustomDialog/myDialog.cpp b/Chapter10/CustomDialog/myDialog.cpp new file mode 100644 index 0000000..5898a78 --- /dev/null +++ b/Chapter10/CustomDialog/myDialog.cpp @@ -0,0 +1,3 @@ +#include "StdAfx.h" +#include "myDialog.h" + diff --git a/Chapter10/CustomDialog/resource.h b/Chapter10/CustomDialog/resource.h new file mode 100644 index 0000000..d5ac7c4 --- /dev/null +++ b/Chapter10/CustomDialog/resource.h @@ -0,0 +1,3 @@ +//{{NO_DEPENDENCIES}} +// Microsoft Visual C++ generated include file. +// Used by app.rc diff --git a/Chapter10/CustomDialog/stdafx.cpp b/Chapter10/CustomDialog/stdafx.cpp new file mode 100644 index 0000000..cb51d3d --- /dev/null +++ b/Chapter10/CustomDialog/stdafx.cpp @@ -0,0 +1,7 @@ +// stdafx.cpp : source file that includes just the standard includes +// CustomDialog.pch will be the pre-compiled header +// stdafx.obj will contain the pre-compiled type information + +#include "stdafx.h" + + diff --git a/Chapter10/CustomDialog/stdafx.h b/Chapter10/CustomDialog/stdafx.h new file mode 100644 index 0000000..46bef73 --- /dev/null +++ b/Chapter10/CustomDialog/stdafx.h @@ -0,0 +1,6 @@ +// stdafx.h : include file for standard system include files, +// or project specific include files that are used frequently, but +// are changed infrequently +#pragma once + +// TODO: reference additional headers your program requires here diff --git a/Chapter10/ErrorProviderEx/AssemblyInfo.cpp b/Chapter10/ErrorProviderEx/AssemblyInfo.cpp new file mode 100644 index 0000000..aa1a7a2 --- /dev/null +++ b/Chapter10/ErrorProviderEx/AssemblyInfo.cpp @@ -0,0 +1,35 @@ +#include "stdafx.h" + +using namespace System::Reflection; +using namespace System::Runtime::CompilerServices; +using namespace System::Runtime::InteropServices; + +// +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +// +[assembly:AssemblyTitleAttribute("ErrorProviderEx")]; +[assembly:AssemblyDescriptionAttribute("")]; +[assembly:AssemblyConfigurationAttribute("")]; +[assembly:AssemblyCompanyAttribute("")]; +[assembly:AssemblyProductAttribute("ErrorProviderEx")]; +[assembly:AssemblyCopyrightAttribute("Copyright (c) 2005")]; +[assembly:AssemblyTrademarkAttribute("")]; +[assembly:AssemblyCultureAttribute("")]; + +// +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the value or you can default the Revision and Build Numbers +// by using the '*' as shown below: + +[assembly:AssemblyVersionAttribute("1.0.*")]; + +[assembly:ComVisible(false)]; + diff --git a/Chapter10/ErrorProviderEx/ErrorProviderEx.cpp b/Chapter10/ErrorProviderEx/ErrorProviderEx.cpp new file mode 100644 index 0000000..3962350 --- /dev/null +++ b/Chapter10/ErrorProviderEx/ErrorProviderEx.cpp @@ -0,0 +1,16 @@ +// ErrorProviderEx.cpp : main project file. + +#include "stdafx.h" +#include "Form1.h" + +using namespace ErrorProviderEx; + +[STAThreadAttribute] +int main(array ^args) +{ + // Enabling Windows XP visual effects before any controls are created + Application::EnableVisualStyles(); + // Create the main window and run it + Application::Run(gcnew Form1()); + return 0; +} diff --git a/Chapter10/ErrorProviderEx/ErrorProviderEx.vcproj b/Chapter10/ErrorProviderEx/ErrorProviderEx.vcproj new file mode 100644 index 0000000..e351df6 --- /dev/null +++ b/Chapter10/ErrorProviderEx/ErrorProviderEx.vcproj @@ -0,0 +1,254 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Chapter10/ErrorProviderEx/Form1.h b/Chapter10/ErrorProviderEx/Form1.h new file mode 100644 index 0000000..b41e613 --- /dev/null +++ b/Chapter10/ErrorProviderEx/Form1.h @@ -0,0 +1,165 @@ +#pragma once + + +namespace ErrorProviderEx +{ + using namespace System; + using namespace System::ComponentModel; + using namespace System::Collections; + using namespace System::Windows::Forms; + using namespace System::Data; + using namespace System::Drawing; + + public ref class Form1 : public System::Windows::Forms::Form + { + public: + Form1(void) + { + InitializeComponent(); + } + + protected: + ~Form1() + { + if (components) + { + delete components; + } + } + + private: + System::Windows::Forms::TextBox^ tbPword; + System::Windows::Forms::Label^ lbPword; + System::Windows::Forms::Button^ bnLogin; + System::Windows::Forms::TextBox^ tbName; + System::Windows::Forms::Label^ lbName; + System::Windows::Forms::ErrorProvider^ eProvider; + System::ComponentModel::IContainer^ components; + +#pragma region Windows Form Designer generated code + void InitializeComponent(void) + { + this->components = (gcnew System::ComponentModel::Container()); + this->tbPword = (gcnew System::Windows::Forms::TextBox()); + this->lbPword = (gcnew System::Windows::Forms::Label()); + this->bnLogin = (gcnew System::Windows::Forms::Button()); + this->tbName = (gcnew System::Windows::Forms::TextBox()); + this->lbName = (gcnew System::Windows::Forms::Label()); + this->eProvider = + (gcnew System::Windows::Forms::ErrorProvider(this->components)); + (cli::safe_cast + (this->eProvider))->BeginInit(); + this->SuspendLayout(); + // + // tbPword + // + this->tbPword->Location = System::Drawing::Point(103, 83); + this->tbPword->Name = L"tbPword"; + this->tbPword->PasswordChar = '*'; + this->tbPword->Size = System::Drawing::Size(100, 20); + this->tbPword->TabIndex = 9; + this->tbPword->Validating += + gcnew System::ComponentModel::CancelEventHandler(this, + &Form1::textbox_Validating); + // + // lbPword + // + this->lbPword->AutoSize = true; + this->lbPword->Location = System::Drawing::Point(34, 83); + this->lbPword->Name = L"lbPword"; + this->lbPword->Size = System::Drawing::Size(53, 13); + this->lbPword->TabIndex = 8; + this->lbPword->Text = L"&Password"; + // + // bnLogin + // + this->bnLogin->Location = System::Drawing::Point(75, 131); + this->bnLogin->Name = L"bnLogin"; + this->bnLogin->Size = System::Drawing::Size(75, 23); + this->bnLogin->TabIndex = 7; + this->bnLogin->Text = L"&Login"; + this->bnLogin->Click += + gcnew System::EventHandler(this, &Form1::login_Click); + // + // tbName + // + this->tbName->Location = System::Drawing::Point(103, 31); + this->tbName->Name = L"tbName"; + this->tbName->Size = System::Drawing::Size(100, 20); + this->tbName->TabIndex = 6; + this->tbName->Validating += + gcnew System::ComponentModel::CancelEventHandler(this, + &Form1::textbox_Validating); + // + // lbName + // + this->lbName->AutoSize = true; + this->lbName->Location = System::Drawing::Point(34, 31); + this->lbName->Name = L"lbName"; + this->lbName->Size = System::Drawing::Size(35, 13); + this->lbName->TabIndex = 5; + this->lbName->Text = L"&Name"; + // + // eProvider + // + this->eProvider->ContainerControl = this; + // + // Form1 + // + this->AutoScaleDimensions = System::Drawing::SizeF(6, 13); + this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font; + this->ClientSize = System::Drawing::Size(237, 185); + this->Controls->Add(this->tbPword); + this->Controls->Add(this->lbPword); + this->Controls->Add(this->bnLogin); + this->Controls->Add(this->tbName); + this->Controls->Add(this->lbName); + this->Name = L"Form1"; + this->Text = L"System Login"; + (cli::safe_cast + (this->eProvider))->EndInit(); + this->ResumeLayout(false); + this->PerformLayout(); + + } +#pragma endregion + + private: + System::Void textbox_Validating(System::Object^ sender, + System::ComponentModel::CancelEventArgs^ e) + { + try + { + TextBox ^tb = (TextBox^)(sender); + + if (tb->Text->Equals("")) + eProvider->SetError(tb, "**Error** Missing Entry!"); + else + eProvider->SetError(tb, ""); + } + catch (Exception^) + { + // Not TextBox + } + } + + System::Void login_Click(System::Object^ sender, System::EventArgs^ e) + { + if (tbName->Text->Equals("")) + eProvider->SetError(tbName, "**Error** Missing Entry!"); + else + eProvider->SetError(tbName, ""); + + if (tbPword->Text->Equals("")) + { + // Place the icon left side of control + eProvider->SetIconAlignment(tbPword, + ErrorIconAlignment::MiddleLeft); + eProvider->SetError(tbPword, "**Error** Missing Entry!"); + } + else + eProvider->SetError(tbPword, ""); + } + }; +} + diff --git a/Chapter10/ErrorProviderEx/Form1.resx b/Chapter10/ErrorProviderEx/Form1.resx new file mode 100644 index 0000000..119b9f3 --- /dev/null +++ b/Chapter10/ErrorProviderEx/Form1.resx @@ -0,0 +1,123 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 17, 17 + + \ No newline at end of file diff --git a/Chapter10/ErrorProviderEx/resource.h b/Chapter10/ErrorProviderEx/resource.h new file mode 100644 index 0000000..d5ac7c4 --- /dev/null +++ b/Chapter10/ErrorProviderEx/resource.h @@ -0,0 +1,3 @@ +//{{NO_DEPENDENCIES}} +// Microsoft Visual C++ generated include file. +// Used by app.rc diff --git a/Chapter10/ErrorProviderEx/stdafx.cpp b/Chapter10/ErrorProviderEx/stdafx.cpp new file mode 100644 index 0000000..27d7bb8 --- /dev/null +++ b/Chapter10/ErrorProviderEx/stdafx.cpp @@ -0,0 +1,7 @@ +// stdafx.cpp : source file that includes just the standard includes +// ErrorProviderEx.pch will be the pre-compiled header +// stdafx.obj will contain the pre-compiled type information + +#include "stdafx.h" + + diff --git a/Chapter10/ErrorProviderEx/stdafx.h b/Chapter10/ErrorProviderEx/stdafx.h new file mode 100644 index 0000000..46bef73 --- /dev/null +++ b/Chapter10/ErrorProviderEx/stdafx.h @@ -0,0 +1,6 @@ +// stdafx.h : include file for standard system include files, +// or project specific include files that are used frequently, but +// are changed infrequently +#pragma once + +// TODO: reference additional headers your program requires here diff --git a/Chapter10/ListViewEx/AssemblyInfo.cpp b/Chapter10/ListViewEx/AssemblyInfo.cpp new file mode 100644 index 0000000..ef78c7d --- /dev/null +++ b/Chapter10/ListViewEx/AssemblyInfo.cpp @@ -0,0 +1,63 @@ +#include "stdafx.h" + +using namespace System::Reflection; +using namespace System::Runtime::CompilerServices; +using namespace System::Runtime::InteropServices; + +// +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +// +[assembly:AssemblyTitleAttribute("ListViewEx")]; +[assembly:AssemblyDescriptionAttribute("")]; +[assembly:AssemblyConfigurationAttribute("")]; +[assembly:AssemblyCompanyAttribute("")]; +[assembly:AssemblyProductAttribute("ListViewEx")]; +[assembly:AssemblyCopyrightAttribute("Copyright © 2005")]; +[assembly:AssemblyTrademarkAttribute("")]; +[assembly:AssemblyCultureAttribute("")]; + +// +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the value or you can default the Revision and Build Numbers +// by using the '*' as shown below: + +[assembly:AssemblyVersionAttribute("1.0.*")]; + +// +// In order to sign your assembly you must specify a key to use. Refer to the +// Microsoft CLR Framework documentation for more information on assembly signing. +// +// You can use the attributes below to control which key is used for signing. +// You can also use the project property page for signing under Common Properties +// to set the same information. +// +// Notes: +// (*) If no key is specified, the assembly is not signed. +// (*) KeyName refers to a key that has been installed in the Crypto Service +// Provider (CSP) on your machine. KeyFile refers to a file which contains +// a key. +// (*) If the KeyFile and the KeyName values are both specified, the +// following processing occurs: +// (1) If the KeyName can be found in the CSP, that key is used. +// (2) If the KeyName does not exist and the KeyFile does exist, the key +// in the KeyFile is installed into the CSP and used. +// (*) In order to create a KeyFile, you can use the sn.exe (Strong Name) utility. +// When specifying the KeyFile, the location of the KeyFile should be +// relative to the project directory. +// (*) Delay Signing is an advanced option - see the Microsoft CLR Framework +// documentation for more information on this. +// +//[assembly:AssemblyDelaySignAttribute(false)]; +//[assembly:AssemblyKeyFileAttribute("")]; +//[assembly:AssemblyKeyNameAttribute("")]; + +[assembly:ComVisible(false)]; + diff --git a/Chapter10/ListViewEx/Form1.h b/Chapter10/ListViewEx/Form1.h new file mode 100644 index 0000000..77d2069 --- /dev/null +++ b/Chapter10/ListViewEx/Form1.h @@ -0,0 +1,265 @@ +#pragma once + +namespace ListViewEx +{ + using namespace System; + using namespace System::ComponentModel; + using namespace System::Collections; + using namespace System::Windows::Forms; + using namespace System::Data; + using namespace System::Drawing; + + public ref class Form1 : public System::Windows::Forms::Form + { + public: + Form1(void) + { + InitializeComponent(); + FillListView(); + } + + protected: + ~Form1() + { + if (components) + { + delete components; + } + } + + private: + System::Windows::Forms::ImageList^ imFruitSmall; + System::Windows::Forms::ImageList^ ilFruitLarge; + System::Windows::Forms::RadioButton^ rbDetails; + System::Windows::Forms::RadioButton^ rbList; + System::Windows::Forms::RadioButton^ rbSmallIcon; + System::Windows::Forms::RadioButton^ rbLargeIcon; + System::Windows::Forms::Label^ label; + System::Windows::Forms::ListView^ lView; + System::Windows::Forms::ColumnHeader^ Fruit; + System::Windows::Forms::ColumnHeader^ Price; + System::Windows::Forms::ColumnHeader^ Available; + System::ComponentModel::IContainer^ components; + +#pragma region Windows Form Designer generated code + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + void InitializeComponent(void) + { + this->components = (gcnew System::ComponentModel::Container()); + System::ComponentModel::ComponentResourceManager^ resources = + (gcnew System::ComponentModel::ComponentResourceManager(Form1::typeid)); + this->imFruitSmall = + (gcnew System::Windows::Forms::ImageList(this->components)); + this->ilFruitLarge = + (gcnew System::Windows::Forms::ImageList(this->components)); + this->rbDetails = (gcnew System::Windows::Forms::RadioButton()); + this->rbList = (gcnew System::Windows::Forms::RadioButton()); + this->rbSmallIcon = (gcnew System::Windows::Forms::RadioButton()); + this->rbLargeIcon = (gcnew System::Windows::Forms::RadioButton()); + this->label = (gcnew System::Windows::Forms::Label()); + this->lView = (gcnew System::Windows::Forms::ListView()); + this->Fruit = (gcnew System::Windows::Forms::ColumnHeader()); + this->Price = (gcnew System::Windows::Forms::ColumnHeader()); + this->Available = (gcnew System::Windows::Forms::ColumnHeader()); + this->SuspendLayout(); + // + // imFruitSmall + // + this->imFruitSmall->ImageStream = + (cli::safe_cast + (resources->GetObject(L"imFruitSmall.ImageStream"))); + this->imFruitSmall->Images->SetKeyName(0, L"apple.ico"); + this->imFruitSmall->Images->SetKeyName(1, L"banana.ico"); + this->imFruitSmall->Images->SetKeyName(2, L"orange.ico"); + // + // ilFruitLarge + // + this->ilFruitLarge->ImageStream = + (cli::safe_cast + (resources->GetObject(L"ilFruitLarge.ImageStream"))); + this->ilFruitLarge->Images->SetKeyName(0, L"apple.ico"); + this->ilFruitLarge->Images->SetKeyName(1, L"banana.ico"); + this->ilFruitLarge->Images->SetKeyName(2, L"orange.ico"); + // + // rbDetails + // + this->rbDetails->Anchor = + static_cast + ((System::Windows::Forms::AnchorStyles::Bottom | + System::Windows::Forms::AnchorStyles::Right)); + this->rbDetails->AutoSize = true; + this->rbDetails->Checked = true; + this->rbDetails->Location = System::Drawing::Point(154, 201); + this->rbDetails->Name = L"rbDetails"; + this->rbDetails->Size = System::Drawing::Size(53, 17); + this->rbDetails->TabIndex = 17; + this->rbDetails->Text = L"Details"; + this->rbDetails->CheckedChanged += + gcnew System::EventHandler(this, &Form1::rbType_CheckedChanged); + // + // rbList + // + this->rbList->Anchor = + static_cast + ((System::Windows::Forms::AnchorStyles::Bottom | + System::Windows::Forms::AnchorStyles::Right)); + this->rbList->AutoSize = true; + this->rbList->Location = System::Drawing::Point(154, 177); + this->rbList->Name = L"rbList"; + this->rbList->Size = System::Drawing::Size(37, 17); + this->rbList->TabIndex = 16; + this->rbList->Text = L"List"; + this->rbList->CheckedChanged += + gcnew System::EventHandler(this, &Form1::rbType_CheckedChanged); + // + // rbSmallIcon + // + this->rbSmallIcon->Anchor = + static_cast + ((System::Windows::Forms::AnchorStyles::Bottom | + System::Windows::Forms::AnchorStyles::Right)); + this->rbSmallIcon->AutoSize = true; + this->rbSmallIcon->Location = System::Drawing::Point(154, 153); + this->rbSmallIcon->Name = L"rbSmallIcon"; + this->rbSmallIcon->Size = System::Drawing::Size(70, 17); + this->rbSmallIcon->TabIndex = 15; + this->rbSmallIcon->Text = L"Small Icon"; + this->rbSmallIcon->CheckedChanged += + gcnew System::EventHandler(this, &Form1::rbType_CheckedChanged); + // + // rbLargeIcon + // + this->rbLargeIcon->Anchor = + static_cast + ((System::Windows::Forms::AnchorStyles::Bottom | + System::Windows::Forms::AnchorStyles::Right)); + this->rbLargeIcon->AutoSize = true; + this->rbLargeIcon->Location = System::Drawing::Point(154, 129); + this->rbLargeIcon->Name = L"rbLargeIcon"; + this->rbLargeIcon->Size = System::Drawing::Size(72, 17); + this->rbLargeIcon->TabIndex = 14; + this->rbLargeIcon->Text = L"Large Icon"; + this->rbLargeIcon->CheckedChanged += + gcnew System::EventHandler(this, &Form1::rbType_CheckedChanged); + // + // label + // + this->label->Anchor = + static_cast + ((System::Windows::Forms::AnchorStyles::Bottom | + System::Windows::Forms::AnchorStyles::Left)); + this->label->BorderStyle = + System::Windows::Forms::BorderStyle::FixedSingle; + this->label->Location = System::Drawing::Point(19, 162); + this->label->Name = L"label"; + this->label->Size = System::Drawing::Size(64, 21); + this->label->TabIndex = 13; + this->label->TextAlign = + System::Drawing::ContentAlignment::MiddleCenter; + // + // lView + // + this->lView->Anchor = + static_cast + ((((System::Windows::Forms::AnchorStyles::Top | + System::Windows::Forms::AnchorStyles::Bottom) | + System::Windows::Forms::AnchorStyles::Left) | + System::Windows::Forms::AnchorStyles::Right)); + this->lView->Columns->AddRange( + gcnew cli::array< System::Windows::Forms::ColumnHeader^>(3) + { + this->Fruit, this->Price, this->Available + }); + this->lView->FullRowSelect = true; + this->lView->GridLines = true; + this->lView->LabelEdit = true; + this->lView->LargeImageList = this->ilFruitLarge; + this->lView->Location = System::Drawing::Point(0, 0); + this->lView->MultiSelect = false; + this->lView->Name = L"lView"; + this->lView->Size = System::Drawing::Size(270, 109); + this->lView->SmallImageList = this->imFruitSmall; + this->lView->TabIndex = 12; + this->lView->View = System::Windows::Forms::View::Details; + this->lView->SelectedIndexChanged += + gcnew System::EventHandler(this, + &Form1::lView_SelectedIndexChanged); + // + // Fruit + // + this->Fruit->Text = L"Fruit"; + this->Fruit->Width = 115; + // + // Price + // + this->Price->Text = L"Price"; + this->Price->Width = 50; + // + // Available + // + this->Available->Text = L"Available"; + this->Available->Width = 100; + // + // Form1 + // + this->AutoScaleDimensions = System::Drawing::SizeF(6, 13); + this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font; + this->ClientSize = System::Drawing::Size(269, 229); + this->Controls->Add(this->rbDetails); + this->Controls->Add(this->rbList); + this->Controls->Add(this->rbSmallIcon); + this->Controls->Add(this->rbLargeIcon); + this->Controls->Add(this->label); + this->Controls->Add(this->lView); + this->Name = L"Form1"; + this->Text = L"List View Example"; + this->ResumeLayout(false); + this->PerformLayout(); + } +#pragma endregion + + private: + void FillListView() + { + array^ itemRec1 = gcnew array { + "Apple", "1.50", "September" + }; + lView->Items->Add(gcnew ListViewItem(itemRec1, 0)); + + array^ itemRec2 = gcnew array { + "Banana", "3.95", "November" + }; + lView->Items->Add(gcnew ListViewItem(itemRec2, 1)); + + array^ itemRec3 = gcnew array { + "Orange", "2.50", "March" + }; + lView->Items->Add(gcnew ListViewItem(itemRec3, 2)); + } + + System::Void lView_SelectedIndexChanged(System::Object^ sender, + System::EventArgs^ e) + { + if (lView->FocusedItem != nullptr) + label->Text = lView->FocusedItem->SubItems[1]->Text; + } + + System::Void rbType_CheckedChanged(System::Object^ sender, + System::EventArgs^ e) + { + if (rbLargeIcon->Checked) + lView->View = View::LargeIcon; + else if (rbSmallIcon->Checked) + lView->View = View::SmallIcon; + else if (rbList->Checked) + lView->View = View::List; + else if (rbDetails->Checked) + lView->View = View::Details; + } + }; +} + + diff --git a/Chapter10/ListViewEx/Form1.resx b/Chapter10/ListViewEx/Form1.resx new file mode 100644 index 0000000..6ab62a7 --- /dev/null +++ b/Chapter10/ListViewEx/Form1.resx @@ -0,0 +1,245 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 17, 17 + + + + AAEAAAD/////AQAAAAAAAAAMAgAAAFdTeXN0ZW0uV2luZG93cy5Gb3JtcywgVmVyc2lvbj0yLjAuMC4w + LCBDdWx0dXJlPW5ldXRyYWwsIFB1YmxpY0tleVRva2VuPWI3N2E1YzU2MTkzNGUwODkFAQAAACZTeXN0 + ZW0uV2luZG93cy5Gb3Jtcy5JbWFnZUxpc3RTdHJlYW1lcgEAAAAERGF0YQcCAgAAAAkDAAAADwMAAAC8 + CQAAAk1TRnQBSQFMAgEBAwEAAQQBAAEEAQABEAEAARABAAT/AQkBAAj/AUIBTQE2AQQGAAE2AQQCAAEo + AwABQAMAARADAAEBAQABCAYAAQQYAAGAAgABgAMAAoABAAGAAwABgAEAAYABAAKAAgADwAEAAcAB3AHA + AQAB8AHKAaYBAAEzBQABMwEAATMBAAEzAQACMwIAAxYBAAMcAQADIgEAAykBAANVAQADTQEAA0IBAAM5 + AQABgAF8Af8BAAJQAf8BAAGTAQAB1gEAAf8B7AHMAQABxgHWAe8BAAHWAucBAAGQAakBrQIAAf8BMwMA + AWYDAAGZAwABzAIAATMDAAIzAgABMwFmAgABMwGZAgABMwHMAgABMwH/AgABZgMAAWYBMwIAAmYCAAFm + AZkCAAFmAcwCAAFmAf8CAAGZAwABmQEzAgABmQFmAgACmQIAAZkBzAIAAZkB/wIAAcwDAAHMATMCAAHM + AWYCAAHMAZkCAALMAgABzAH/AgAB/wFmAgAB/wGZAgAB/wHMAQABMwH/AgAB/wEAATMBAAEzAQABZgEA + ATMBAAGZAQABMwEAAcwBAAEzAQAB/wEAAf8BMwIAAzMBAAIzAWYBAAIzAZkBAAIzAcwBAAIzAf8BAAEz + AWYCAAEzAWYBMwEAATMCZgEAATMBZgGZAQABMwFmAcwBAAEzAWYB/wEAATMBmQIAATMBmQEzAQABMwGZ + AWYBAAEzApkBAAEzAZkBzAEAATMBmQH/AQABMwHMAgABMwHMATMBAAEzAcwBZgEAATMBzAGZAQABMwLM + AQABMwHMAf8BAAEzAf8BMwEAATMB/wFmAQABMwH/AZkBAAEzAf8BzAEAATMC/wEAAWYDAAFmAQABMwEA + AWYBAAFmAQABZgEAAZkBAAFmAQABzAEAAWYBAAH/AQABZgEzAgABZgIzAQABZgEzAWYBAAFmATMBmQEA + AWYBMwHMAQABZgEzAf8BAAJmAgACZgEzAQADZgEAAmYBmQEAAmYBzAEAAWYBmQIAAWYBmQEzAQABZgGZ + AWYBAAFmApkBAAFmAZkBzAEAAWYBmQH/AQABZgHMAgABZgHMATMBAAFmAcwBmQEAAWYCzAEAAWYBzAH/ + AQABZgH/AgABZgH/ATMBAAFmAf8BmQEAAWYB/wHMAQABzAEAAf8BAAH/AQABzAEAApkCAAGZATMBmQEA + AZkBAAGZAQABmQEAAcwBAAGZAwABmQIzAQABmQEAAWYBAAGZATMBzAEAAZkBAAH/AQABmQFmAgABmQFm + ATMBAAGZATMBZgEAAZkBZgGZAQABmQFmAcwBAAGZATMB/wEAApkBMwEAApkBZgEAA5kBAAKZAcwBAAKZ + Af8BAAGZAcwCAAGZAcwBMwEAAWYBzAFmAQABmQHMAZkBAAGZAswBAAGZAcwB/wEAAZkB/wIAAZkB/wEz + AQABmQHMAWYBAAGZAf8BmQEAAZkB/wHMAQABmQL/AQABzAMAAZkBAAEzAQABzAEAAWYBAAHMAQABmQEA + AcwBAAHMAQABmQEzAgABzAIzAQABzAEzAWYBAAHMATMBmQEAAcwBMwHMAQABzAEzAf8BAAHMAWYCAAHM + AWYBMwEAAZkCZgEAAcwBZgGZAQABzAFmAcwBAAGZAWYB/wEAAcwBmQIAAcwBmQEzAQABzAGZAWYBAAHM + ApkBAAHMAZkBzAEAAcwBmQH/AQACzAIAAswBMwEAAswBZgEAAswBmQEAA8wBAALMAf8BAAHMAf8CAAHM + Af8BMwEAAZkB/wFmAQABzAH/AZkBAAHMAf8BzAEAAcwC/wEAAcwBAAEzAQAB/wEAAWYBAAH/AQABmQEA + AcwBMwIAAf8CMwEAAf8BMwFmAQAB/wEzAZkBAAH/ATMBzAEAAf8BMwH/AQAB/wFmAgAB/wFmATMBAAHM + AmYBAAH/AWYBmQEAAf8BZgHMAQABzAFmAf8BAAH/AZkCAAH/AZkBMwEAAf8BmQFmAQAB/wKZAQAB/wGZ + AcwBAAH/AZkB/wEAAf8BzAIAAf8BzAEzAQAB/wHMAWYBAAH/AcwBmQEAAf8CzAEAAf8BzAH/AQAC/wEz + AQABzAH/AWYBAAL/AZkBAAL/AcwBAAJmAf8BAAFmAf8BZgEAAWYC/wEAAf8CZgEAAf8BZgH/AQAC/wFm + AQABIQEAAaUBAANfAQADdwEAA4YBAAOWAQADywEAA7IBAAPXAQAD3QEAA+MBAAPqAQAD8QEAA/gBAAHw + AfsB/wEAAaQCoAEAA4ADAAH/AgAB/wMAAv8BAAH/AwAB/wEAAf8BAAL/AgAD/wEAAUEPAAH7DwABUx8A + AUEFAAEOBAsFAAH7ASIB+w0AAVMfAAFBAwABDgELAQEEHwEBAQsDAAH7ATAB+wE4DAABUwQAAQsBAQIk + ASMBCxUAAUECAAEOAR4BHwEgAR8EIAEfAR4CAAP7ATgBIgsAAVMDAAEkASwFJQEkAQsTAAFBAgABHgEf + AiAF+QEgAR8BCwEAAfsBNwH7AjgLAAFTAgABJQUsASUDJAELEgABQQEAAQsBAQEfASAB+QFBAUcC+QFB + AfkBIAEBAQAB+wEOAvsBOAEqCgABUwEAAQsBLAEyBCwBKwQkEgABQQEAAQsBHwEgA0cB4wJHA/kBIAEA + AfsBAAH7AVgCOAoAAVMBAAErATICUwEsAU0CLAElAyQSAAFBAQABHgEgAfkBQQFHARYBtwHjAWoBRwFB + AfkBIAELAfsBAAEpAV4B+wE4ATIJAAFTAQABKwEyAVMBegFNAVMBMgEsASUDJAELEQABQQEAAQEBIAL5 + AUcBFwEWARcCRwJBASABCwH7AgAB+wFeAfsBMgEiCAABUwEAASsBMgJ6A1MBLAQlAQsRAAFBAQABHgIg + AvkBIAFHAfkDQQH5ASABAAH7AgABIgFeAeUBOAErAQ4GAAELAVMBAAEjATIBUwGaA1MBTQQlEgABQQEA + AR4BAQEfAQEBHgEBASQBHgEBAyABAQEAAfsDAAH7AaAB5QE4ASUBIwQAAfsBAAFTAgABUwEyAZoCUwIs + AyUBJBIAAUECAAELAh4BAQEgASMBHwMeAQsCAAH7BAAB+wHDAaAC+wI3AvsCAAFTAgABIwNTAiwBJgIl + ASQTAAFBBgABCwEjAgsFAAH7BAABDgH7AcMB9gGgAl4B+wExAgABUwMAAQsBJQFNAkYBJQEkAR4UAAFB + BgABJAFLBwAB+wYAAvsBoALDAV4BKQIAAVMfAAFBDwAB+wgAASkCNwEOAwABUx8AEEEQ+xBTEAABQgFN + AT4HAAE+AwABKAMAAUADAAEQAwABAQEAAQEFAAGAFwAD/4EACw== + + + + 237, 17 + + + + AAEAAAD/////AQAAAAAAAAAMAgAAAFdTeXN0ZW0uV2luZG93cy5Gb3JtcywgVmVyc2lvbj0yLjAuMC4w + LCBDdWx0dXJlPW5ldXRyYWwsIFB1YmxpY0tleVRva2VuPWI3N2E1YzU2MTkzNGUwODkFAQAAACZTeXN0 + ZW0uV2luZG93cy5Gb3Jtcy5JbWFnZUxpc3RTdHJlYW1lcgEAAAAERGF0YQcCAgAAAAkDAAAADwMAAABm + DwAAAk1TRnQBSQFMAgEBAwEAAQQBAAEEAQABIAEAASABAAT/AQkBAAj/AUIBTQE2AQQGAAE2AQQCAAEo + AwABgAMAASADAAEBAQABCAYAARAYAAGAAgABgAMAAoABAAGAAwABgAEAAYABAAKAAgADwAEAAcAB3AHA + AQAB8AHKAaYBAAEzBQABMwEAATMBAAEzAQACMwIAAxYBAAMcAQADIgEAAykBAANVAQADTQEAA0IBAAM5 + AQABgAF8Af8BAAJQAf8BAAGTAQAB1gEAAf8B7AHMAQABxgHWAe8BAAHWAucBAAGQAakBrQIAAf8BMwMA + AWYDAAGZAwABzAIAATMDAAIzAgABMwFmAgABMwGZAgABMwHMAgABMwH/AgABZgMAAWYBMwIAAmYCAAFm + AZkCAAFmAcwCAAFmAf8CAAGZAwABmQEzAgABmQFmAgACmQIAAZkBzAIAAZkB/wIAAcwDAAHMATMCAAHM + AWYCAAHMAZkCAALMAgABzAH/AgAB/wFmAgAB/wGZAgAB/wHMAQABMwH/AgAB/wEAATMBAAEzAQABZgEA + ATMBAAGZAQABMwEAAcwBAAEzAQAB/wEAAf8BMwIAAzMBAAIzAWYBAAIzAZkBAAIzAcwBAAIzAf8BAAEz + AWYCAAEzAWYBMwEAATMCZgEAATMBZgGZAQABMwFmAcwBAAEzAWYB/wEAATMBmQIAATMBmQEzAQABMwGZ + AWYBAAEzApkBAAEzAZkBzAEAATMBmQH/AQABMwHMAgABMwHMATMBAAEzAcwBZgEAATMBzAGZAQABMwLM + AQABMwHMAf8BAAEzAf8BMwEAATMB/wFmAQABMwH/AZkBAAEzAf8BzAEAATMC/wEAAWYDAAFmAQABMwEA + AWYBAAFmAQABZgEAAZkBAAFmAQABzAEAAWYBAAH/AQABZgEzAgABZgIzAQABZgEzAWYBAAFmATMBmQEA + AWYBMwHMAQABZgEzAf8BAAJmAgACZgEzAQADZgEAAmYBmQEAAmYBzAEAAWYBmQIAAWYBmQEzAQABZgGZ + AWYBAAFmApkBAAFmAZkBzAEAAWYBmQH/AQABZgHMAgABZgHMATMBAAFmAcwBmQEAAWYCzAEAAWYBzAH/ + AQABZgH/AgABZgH/ATMBAAFmAf8BmQEAAWYB/wHMAQABzAEAAf8BAAH/AQABzAEAApkCAAGZATMBmQEA + AZkBAAGZAQABmQEAAcwBAAGZAwABmQIzAQABmQEAAWYBAAGZATMBzAEAAZkBAAH/AQABmQFmAgABmQFm + ATMBAAGZATMBZgEAAZkBZgGZAQABmQFmAcwBAAGZATMB/wEAApkBMwEAApkBZgEAA5kBAAKZAcwBAAKZ + Af8BAAGZAcwCAAGZAcwBMwEAAWYBzAFmAQABmQHMAZkBAAGZAswBAAGZAcwB/wEAAZkB/wIAAZkB/wEz + AQABmQHMAWYBAAGZAf8BmQEAAZkB/wHMAQABmQL/AQABzAMAAZkBAAEzAQABzAEAAWYBAAHMAQABmQEA + AcwBAAHMAQABmQEzAgABzAIzAQABzAEzAWYBAAHMATMBmQEAAcwBMwHMAQABzAEzAf8BAAHMAWYCAAHM + AWYBMwEAAZkCZgEAAcwBZgGZAQABzAFmAcwBAAGZAWYB/wEAAcwBmQIAAcwBmQEzAQABzAGZAWYBAAHM + ApkBAAHMAZkBzAEAAcwBmQH/AQACzAIAAswBMwEAAswBZgEAAswBmQEAA8wBAALMAf8BAAHMAf8CAAHM + Af8BMwEAAZkB/wFmAQABzAH/AZkBAAHMAf8BzAEAAcwC/wEAAcwBAAEzAQAB/wEAAWYBAAH/AQABmQEA + AcwBMwIAAf8CMwEAAf8BMwFmAQAB/wEzAZkBAAH/ATMBzAEAAf8BMwH/AQAB/wFmAgAB/wFmATMBAAHM + AmYBAAH/AWYBmQEAAf8BZgHMAQABzAFmAf8BAAH/AZkCAAH/AZkBMwEAAf8BmQFmAQAB/wKZAQAB/wGZ + AcwBAAH/AZkB/wEAAf8BzAIAAf8BzAEzAQAB/wHMAWYBAAH/AcwBmQEAAf8CzAEAAf8BzAH/AQAC/wEz + AQABzAH/AWYBAAL/AZkBAAL/AcwBAAJmAf8BAAFmAf8BZgEAAWYC/wEAAf8CZgEAAf8BZgH/AQAC/wFm + AQABIQEAAaUBAANfAQADdwEAA4YBAAOWAQADywEAA7IBAAPXAQAD3QEAA+MBAAPqAQAD8QEAA/gBAAHw + AfsB/wEAAaQCoAEAA4ADAAH/AgAB/wMAAv8BAAH/AwAB/wEAAf8BAAL/AgAD/wEAIEEg+yBTIAABQR4A + AUEB+x4AAfsBUx4AAVMgAAFBDgAEDgwAAUEB+wIAASIBAxoAAfsBUx4AAVMgAAFBCwABDgkLCQABQQH7 + AQABIgL7AQMZAAH7AVMeAAFTIAABQQkAAQ4CCwIeBQECHgILBwABQQH7AQABKQH7AjgBIhgAAfsBUx4A + AVMgAAFBBwABDgILAR4CAQgfAQEBHgELBgABQQH7AQABMAL7AjgBDhcAAfsBUwgAAgsBHgIBBCQBIwIL + CgABUyAAAUEGAAEOAQsBHgIBAx8IIAEfAQEBHgEOBAABQQH7AQABNwL7AjgBKhcAAfsBUwcAAQsBAQEk + CCUCJAEBAQsIAAFTIAABQQUAAQ4BCwEeAQECHwIgAR8JIAIfAR4EAAFBAfsBAAP7AzgBIhYAAfsBUwYA + AR4BJAElASwBKwklAiQBHgELBgABUyAAAUEFAAELAR4BAQIfBCAH+QQgAR8BCwMAAUEB+wEAATcD+wI4 + ATEWAAH7AVMFAAEeASUELAErAiUBKwMlBSQBAQELBQABUyAAAUEEAAELAR4BAQIfAyAK+QMgAR8BAQEL + AgABQQH7AQABNwP7AzgBKhUAAfsBUwQAAQsBJQosAiUGJAEBAQsEAAFTIAABQQQAAQsBHgIfAyAD+QFB + BfkBIAP5AiABHwEeAgABQQH7AQABKQL7ATcB+wM4AQ4UAAH7AVMEAAEkCywBKwIlBiQBAQQAAVMgAAFB + AwABCwEeAQECHwIgA/kBQQNHBPkBQQP5AiABAQELAQABQQH7AQABDgT7AzgBKhQAAfsBUwMAAQsDLAEy + CSwBKwElByQBCwMAAVMgAAFBAwABCwEeAQEBHwIgA/kBQQRHBUED+QIgAR8BCwEAAUEB+wIAATcB+wFe + ATcEOAEiEwAB+wFTAwABJAUyAVMILAIlBiQBCwMAAVMgAAFBAwABCwEeAR8DIAFHAUEDRwEXAeMBFwNH + AUEF+QIgAR4BAAFBAfsCAAEiAvsBWAE3AzgBMRMAAfsBUwMAASsDMgRTAiwBTQFTAywCJQYkAQEDAAFT + IAABQQIAAQ4BCwEBAR8CIAH5AUEBRwMXARYBlAEWARcBagRHA/kCIAEBAQ4BQQH7AwABOAH7AV4BOAH7 + AzgBIhIAAfsBUwIAAQsBKwMyAlMBdQFTAiwBTQFTATICLAErASUGJAEBAwABUyAAAUECAAELAR4BAQIg + AvkBQQJHAeMBFgGUAbcBlAHjAmoCRwJBA/kBIAEBAQsBQQH7AwABKQH7Al4B+wM4ATISAAH7AVMDAAEr + AzIBUwJ6AVMBTQEsAlMBMgMsAiUGJAELAgABUyAAAUECAAELAR4BHwIgA/kCRwEXAeMBlAG9AZQBFgJq + AkcDQQL5ASABAQELAUEB+wQAATcB+wJeAfsCOAEyASoRAAH7AVMDAAErAzIBdQJ6AlMBTQNTAywDJQUk + AQsCAAFTIAABQQIAAQsBAQEfAiAD+QFBAkcBFwHjARYB4wEXBEcEQQH5ASABHwELAUEB+wQAASkB+wNe + AfsBOAIyASIQAAH7AVMDAAErAzIBegGaAXoBdQVTAywHJQEkAQsCAAFTIAABQQIAAQsBAQEfAiAE+QFB + AkcBFwdHAUECRwFBAfkBIAEfAQsBQQH7BQABNwH7AuUBXgH7AjIBKwELDwAB+wFTAwABJAMyAXUCmgF6 + BVMDLAclASQDAAFTIAABQQIAAQsBHgEfAyAE+QIgAkcBIAL5BUED+QEgAQEBAAFBAfsFAAEiAfsBXgLl + AV4BOAEyAisBDgwAASMBCwH7AVMDAAEjAzIBUwOaBVMCTQEsByUBAQMAAVMgAAFBAgABCwEeAQEBHwUg + Bh8DIAP5AUcBQQH5AiABCwEAAUEB+wYAATcB+wHlAaAB5QFeATgBMQIrAQsKAAEpATEBHgH7AVMEAAEr + AjIBUwF6ApoFUwJNASwHJQELAwABUyAAAUEDAAEeAgEDHwIBAR4DAQEkAQEBHgIBAR8GIAEBAQ4BAAFB + AfsGAAEOAvsCoAHlAV4BOAExAiUBIwEOBwABMAH7ASIBAAH7AVMEAAEjAVMCMgFTApoEUwQsBiUBJAQA + AVMgAAFBAwABDggeAQEBHwEkASMBAQEeAgsCHgIBAh8BAQELAgABQQH7BwABKQH7AV4BoAHDAeUBXgE4 + ATcCKwEkASMDCwIiATAB+wEiAgAB+wFTBAABCwFMAVMCMgFTAXoDUwEyAywGJQEkBQABUyAAAUEFAAIL + BB4BAQEfASABRQEjAh8HHgILAwABQQH7CAABMAH7AeUCwwGgAV4D+wE4AzcBOAP7ASMDAAH7AVMFAAEj + AUwBUwEyAVMBdQFTAU0ELAEmBSUBJAYAAVMgAAFBBwADCwEeAwEBJAEjAR4CAQIeAwsGAAFBAfsJAAE3 + AfsB5QPDAaACXgf7ATEEAAH7AVMGAAEeASUBTQEsAlMBTQFGAUUBKwEsBSUBJAcAAVMgAAFBDAACCwEk + ASMECwoAAUEB+wkAAQ4BNwH7AeUBwwL2AcMBoAHlBF4B+wIxAQ4DAAH7AVMHAAELASMBJQJNASUBRgFE + AUYBTQIlAiQBHggAAVMgAAFBDQABIwEkAUsBIg0AAUEB+woAAQ4BNwL7AeUEwwGgAsMBoAFeAjcBDgMA + AfsBUwoAAR4GJAEeAQsLAAFTIAABQQwAAUQBJAFFAUsBRA0AAUEB+wwAASkD+wFeAaAEwwHlAV4B+wEp + BAAB+wFTHgABUyAAAUEMAAFLAUUBAAEMDgABQQH7DQABDgEDATcCXgHlBF4B+wEDBQAB+wFTHgABUyAA + AUEeAAFBAfsQAAEiASkBMAM3ASkBDgYAAfsBUx4AAVMgAAFBHgABQQH7HgAB+wFTHgABUyAAIEEg+yBT + IAABQgFNAT4HAAE+AwABKAMAAYADAAEgAwABAQEAAQEGAAECFgAD//8A/wADAAs= + + + \ No newline at end of file diff --git a/Chapter10/ListViewEx/Images/apple.ico b/Chapter10/ListViewEx/Images/apple.ico new file mode 100644 index 0000000..a7cf2f9 Binary files /dev/null and b/Chapter10/ListViewEx/Images/apple.ico differ diff --git a/Chapter10/ListViewEx/Images/banana.ico b/Chapter10/ListViewEx/Images/banana.ico new file mode 100644 index 0000000..b6a5a40 Binary files /dev/null and b/Chapter10/ListViewEx/Images/banana.ico differ diff --git a/Chapter10/ListViewEx/Images/orange.ico b/Chapter10/ListViewEx/Images/orange.ico new file mode 100644 index 0000000..39e0e71 Binary files /dev/null and b/Chapter10/ListViewEx/Images/orange.ico differ diff --git a/Chapter10/ListViewEx/ListViewEx.cpp b/Chapter10/ListViewEx/ListViewEx.cpp new file mode 100644 index 0000000..f92b6ba --- /dev/null +++ b/Chapter10/ListViewEx/ListViewEx.cpp @@ -0,0 +1,16 @@ +// ListViewEx.cpp : main project file. + +#include "stdafx.h" +#include "Form1.h" + +using namespace ListViewEx; + +[STAThreadAttribute] +int main(array ^args) +{ + // Enabling Windows XP visual effects before any controls are created + Application::EnableVisualStyles(); + // Create the main window and run it + Application::Run(gcnew Form1()); + return 0; +} diff --git a/Chapter10/ListViewEx/ListViewEx.vcproj b/Chapter10/ListViewEx/ListViewEx.vcproj new file mode 100644 index 0000000..3cdf33b --- /dev/null +++ b/Chapter10/ListViewEx/ListViewEx.vcproj @@ -0,0 +1,256 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Chapter10/ListViewEx/resource.h b/Chapter10/ListViewEx/resource.h new file mode 100644 index 0000000..d5ac7c4 --- /dev/null +++ b/Chapter10/ListViewEx/resource.h @@ -0,0 +1,3 @@ +//{{NO_DEPENDENCIES}} +// Microsoft Visual C++ generated include file. +// Used by app.rc diff --git a/Chapter10/ListViewEx/stdafx.cpp b/Chapter10/ListViewEx/stdafx.cpp new file mode 100644 index 0000000..2641476 --- /dev/null +++ b/Chapter10/ListViewEx/stdafx.cpp @@ -0,0 +1,7 @@ +// stdafx.cpp : source file that includes just the standard includes +// ListViewEx.pch will be the pre-compiled header +// stdafx.obj will contain the pre-compiled type information + +#include "stdafx.h" + + diff --git a/Chapter10/ListViewEx/stdafx.h b/Chapter10/ListViewEx/stdafx.h new file mode 100644 index 0000000..46bef73 --- /dev/null +++ b/Chapter10/ListViewEx/stdafx.h @@ -0,0 +1,6 @@ +// stdafx.h : include file for standard system include files, +// or project specific include files that are used frequently, but +// are changed infrequently +#pragma once + +// TODO: reference additional headers your program requires here diff --git a/Chapter10/MonthCalendarEx/AssemblyInfo.cpp b/Chapter10/MonthCalendarEx/AssemblyInfo.cpp new file mode 100644 index 0000000..1c03c6f --- /dev/null +++ b/Chapter10/MonthCalendarEx/AssemblyInfo.cpp @@ -0,0 +1,35 @@ +#include "stdafx.h" + +using namespace System::Reflection; +using namespace System::Runtime::CompilerServices; +using namespace System::Runtime::InteropServices; + +// +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +// +[assembly:AssemblyTitleAttribute("MonthCalendarEx")]; +[assembly:AssemblyDescriptionAttribute("")]; +[assembly:AssemblyConfigurationAttribute("")]; +[assembly:AssemblyCompanyAttribute("")]; +[assembly:AssemblyProductAttribute("MonthCalendarEx")]; +[assembly:AssemblyCopyrightAttribute("Copyright (c) 2005")]; +[assembly:AssemblyTrademarkAttribute("")]; +[assembly:AssemblyCultureAttribute("")]; + +// +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the value or you can default the Revision and Build Numbers +// by using the '*' as shown below: + +[assembly:AssemblyVersionAttribute("1.0.*")]; + +[assembly:ComVisible(false)]; + diff --git a/Chapter10/MonthCalendarEx/Form1.h b/Chapter10/MonthCalendarEx/Form1.h new file mode 100644 index 0000000..7a2edbe --- /dev/null +++ b/Chapter10/MonthCalendarEx/Form1.h @@ -0,0 +1,105 @@ +#pragma once + + +namespace MonthCalendarEx +{ + using namespace System; + using namespace System::ComponentModel; + using namespace System::Collections; + using namespace System::Windows::Forms; + using namespace System::Data; + using namespace System::Drawing; + + public ref class Form1 : public System::Windows::Forms::Form + { + public: + Form1(void) + { + InitializeComponent(); + } + + protected: + ~Form1() + { + if (components) + { + delete components; + } + } + private: + System::Windows::Forms::Label^ End; + System::Windows::Forms::Label^ Start; + System::Windows::Forms::MonthCalendar^ monthCal; + System::ComponentModel::Container ^components; + +#pragma region Windows Form Designer generated code + void InitializeComponent(void) + { + this->End = (gcnew System::Windows::Forms::Label()); + this->Start = (gcnew System::Windows::Forms::Label()); + this->monthCal = (gcnew System::Windows::Forms::MonthCalendar()); + this->SuspendLayout(); + // + // End + // + this->End->BorderStyle = + System::Windows::Forms::BorderStyle::FixedSingle; + this->End->Location = System::Drawing::Point(230, 323); + this->End->Name = L"End"; + this->End->Size = System::Drawing::Size(83, 20); + this->End->TabIndex = 5; + // + // Start + // + this->Start->BorderStyle = + System::Windows::Forms::BorderStyle::FixedSingle; + this->Start->Location = System::Drawing::Point(122, 323); + this->Start->Name = L"Start"; + this->Start->Size = System::Drawing::Size(83, 20); + this->Start->TabIndex = 4; + // + // monthCal + // + this->monthCal->AnnuallyBoldedDates = + gcnew cli::array< System::DateTime >(1) + {System::DateTime(2004, 12, 31, 0, 0, 0, 0)}; + this->monthCal->CalendarDimensions = System::Drawing::Size(2, 2); + this->monthCal->Location = System::Drawing::Point(13, 11); + this->monthCal->MaxSelectionCount = 365; + this->monthCal->MonthlyBoldedDates = + gcnew cli::array< System::DateTime >(2) + {System::DateTime(2004, 10, 1, 0, 0, 0, 0), + System::DateTime(2004, 10, 15, 0, 0, 0, 0)}; + this->monthCal->Name = L"monthCal"; + this->monthCal->ShowWeekNumbers = true; + this->monthCal->Size = System::Drawing::Size(410, 297); + this->monthCal->TabIndex = 3; + this->monthCal->DateChanged += + gcnew System::Windows::Forms::DateRangeEventHandler(this, + &Form1::monthCal_DateChanged); + // + // Form1 + // + this->AutoScaleDimensions = System::Drawing::SizeF(6, 13); + this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font; + this->ClientSize = System::Drawing::Size(436, 355); + this->Controls->Add(this->End); + this->Controls->Add(this->Start); + this->Controls->Add(this->monthCal); + this->Name = L"Form1"; + this->Text = L"Month Calendar"; + this->ResumeLayout(false); + + } +#pragma endregion + private: + System::Void monthCal_DateChanged(System::Object^ sender, + System::Windows::Forms::DateRangeEventArgs^ e) + { + // Update start and end range labels when date changes + Start->Text = e->Start.Date.ToShortDateString(); + End->Text = e->End.Date.ToShortDateString(); + } + }; +} + diff --git a/Chapter10/MonthCalendarEx/Form1.resx b/Chapter10/MonthCalendarEx/Form1.resx new file mode 100644 index 0000000..de824e1 --- /dev/null +++ b/Chapter10/MonthCalendarEx/Form1.resx @@ -0,0 +1,110 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Chapter10/MonthCalendarEx/MonthCalendarEx.cpp b/Chapter10/MonthCalendarEx/MonthCalendarEx.cpp new file mode 100644 index 0000000..b54102b --- /dev/null +++ b/Chapter10/MonthCalendarEx/MonthCalendarEx.cpp @@ -0,0 +1,16 @@ +// MonthCalendarEx.cpp : main project file. + +#include "stdafx.h" +#include "Form1.h" + +using namespace MonthCalendarEx; + +[STAThreadAttribute] +int main(array ^args) +{ + // Enabling Windows XP visual effects before any controls are created + Application::EnableVisualStyles(); + // Create the main window and run it + Application::Run(gcnew Form1()); + return 0; +} diff --git a/Chapter10/MonthCalendarEx/MonthCalendarEx.vcproj b/Chapter10/MonthCalendarEx/MonthCalendarEx.vcproj new file mode 100644 index 0000000..794b390 --- /dev/null +++ b/Chapter10/MonthCalendarEx/MonthCalendarEx.vcproj @@ -0,0 +1,254 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Chapter10/MonthCalendarEx/resource.h b/Chapter10/MonthCalendarEx/resource.h new file mode 100644 index 0000000..d5ac7c4 --- /dev/null +++ b/Chapter10/MonthCalendarEx/resource.h @@ -0,0 +1,3 @@ +//{{NO_DEPENDENCIES}} +// Microsoft Visual C++ generated include file. +// Used by app.rc diff --git a/Chapter10/MonthCalendarEx/stdafx.cpp b/Chapter10/MonthCalendarEx/stdafx.cpp new file mode 100644 index 0000000..79ad161 --- /dev/null +++ b/Chapter10/MonthCalendarEx/stdafx.cpp @@ -0,0 +1,7 @@ +// stdafx.cpp : source file that includes just the standard includes +// MonthCalendarEx.pch will be the pre-compiled header +// stdafx.obj will contain the pre-compiled type information + +#include "stdafx.h" + + diff --git a/Chapter10/MonthCalendarEx/stdafx.h b/Chapter10/MonthCalendarEx/stdafx.h new file mode 100644 index 0000000..46bef73 --- /dev/null +++ b/Chapter10/MonthCalendarEx/stdafx.h @@ -0,0 +1,6 @@ +// stdafx.h : include file for standard system include files, +// or project specific include files that are used frequently, but +// are changed infrequently +#pragma once + +// TODO: reference additional headers your program requires here diff --git a/Chapter10/NotifyIconEx/AssemblyInfo.cpp b/Chapter10/NotifyIconEx/AssemblyInfo.cpp new file mode 100644 index 0000000..f1e17da --- /dev/null +++ b/Chapter10/NotifyIconEx/AssemblyInfo.cpp @@ -0,0 +1,35 @@ +#include "stdafx.h" + +using namespace System::Reflection; +using namespace System::Runtime::CompilerServices; +using namespace System::Runtime::InteropServices; + +// +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +// +[assembly:AssemblyTitleAttribute("NotifyIconEx")]; +[assembly:AssemblyDescriptionAttribute("")]; +[assembly:AssemblyConfigurationAttribute("")]; +[assembly:AssemblyCompanyAttribute("")]; +[assembly:AssemblyProductAttribute("NotifyIconEx")]; +[assembly:AssemblyCopyrightAttribute("Copyright (c) 2005")]; +[assembly:AssemblyTrademarkAttribute("")]; +[assembly:AssemblyCultureAttribute("")]; + +// +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the value or you can default the Revision and Build Numbers +// by using the '*' as shown below: + +[assembly:AssemblyVersionAttribute("1.0.*")]; + +[assembly:ComVisible(false)]; + diff --git a/Chapter10/NotifyIconEx/Form1.h b/Chapter10/NotifyIconEx/Form1.h new file mode 100644 index 0000000..877391d --- /dev/null +++ b/Chapter10/NotifyIconEx/Form1.h @@ -0,0 +1,138 @@ +#pragma once + + +namespace NotifyIconEx { + + using namespace System; + using namespace System::ComponentModel; + using namespace System::Collections; + using namespace System::Windows::Forms; + using namespace System::Data; + using namespace System::Drawing; + + public ref class Form1 : public System::Windows::Forms::Form + { + public: + Form1(void) + { + InitializeComponent(); + } + + protected: + ~Form1() + { + if (components) + { + delete components; + } + } + + private: + System::Windows::Forms::Button^ bnTaskBar; + System::Windows::Forms::Button^ bnNotify; + System::Windows::Forms::NotifyIcon^ notifyIcon; + System::Windows::Forms::ContextMenuStrip^ menuExit; + System::Windows::Forms::ToolStripMenuItem^ miExit; + System::ComponentModel::IContainer^ components; + +#pragma region Windows Form Designer generated code + + void InitializeComponent(void) + { + this->components = (gcnew System::ComponentModel::Container()); + System::ComponentModel::ComponentResourceManager^ resources = + (gcnew System::ComponentModel::ComponentResourceManager(Form1::typeid)); + this->bnTaskBar = (gcnew System::Windows::Forms::Button()); + this->bnNotify = (gcnew System::Windows::Forms::Button()); + this->notifyIcon = + (gcnew System::Windows::Forms::NotifyIcon(this->components)); + this->menuExit = + (gcnew System::Windows::Forms::ContextMenuStrip(this->components)); + this->miExit = (gcnew System::Windows::Forms::ToolStripMenuItem()); + this->menuExit->SuspendLayout(); + this->SuspendLayout(); + // + // bnTaskBar + // + this->bnTaskBar->Location = System::Drawing::Point(28, 59); + this->bnTaskBar->Name = L"bnTaskBar"; + this->bnTaskBar->Size = System::Drawing::Size(131, 23); + this->bnTaskBar->TabIndex = 3; + this->bnTaskBar->Text = L"Toggle TaskBar Icon"; + this->bnTaskBar->Click += + gcnew System::EventHandler(this, &Form1::bnTaskBar_Click); + // + // bnNotify + // + this->bnNotify->Location = System::Drawing::Point(28, 12); + this->bnNotify->Name = L"bnNotify"; + this->bnNotify->Size = System::Drawing::Size(131, 23); + this->bnNotify->TabIndex = 2; + this->bnNotify->Text = L"Toggle Notify Icon"; + this->bnNotify->Click += + gcnew System::EventHandler(this, &Form1::bnNotify_Click); + // + // notifyIcon + // + this->notifyIcon->ContextMenuStrip = this->menuExit; + this->notifyIcon->Icon = (cli::safe_cast + (resources->GetObject(L"notifyIcon.Icon"))); + this->notifyIcon->Text = L"Notify Icon Example"; + this->notifyIcon->Visible = true; + // + // menuExit + // + this->menuExit->Items->AddRange( + gcnew cli::array< System::Windows::Forms::ToolStripItem^>(1) + {this->miExit}); + this->menuExit->Name = L"miExit"; + this->menuExit->RightToLeft = + System::Windows::Forms::RightToLeft::No; + this->menuExit->Size = System::Drawing::Size(153, 48); + // + // miExit + // + this->miExit->Name = L"miExit"; + this->miExit->Size = System::Drawing::Size(152, 22); + this->miExit->Text = L"E&xit"; + this->miExit->Click += + gcnew System::EventHandler(this, &Form1::miExit_Click); + // + // Form1 + // + this->AutoScaleDimensions = System::Drawing::SizeF(6, 13); + this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font; + this->ClientSize = System::Drawing::Size(192, 106); + this->Controls->Add(this->bnTaskBar); + this->Controls->Add(this->bnNotify); + this->Icon = (cli::safe_cast + (resources->GetObject(L"$this.Icon"))); + this->Name = L"Form1"; + this->Text = L"Notify Icon"; + this->menuExit->ResumeLayout(false); + this->ResumeLayout(false); + + } +#pragma endregion + + private: + System::Void bnNotify_Click(System::Object^ sender, + System::EventArgs^ e) + { + notifyIcon->Visible = !notifyIcon->Visible; + } + + System::Void bnTaskBar_Click(System::Object^ sender, + System::EventArgs^ e) + { + this->ShowInTaskbar = ! this->ShowInTaskbar; + } + + System::Void miExit_Click(System::Object^ sender, + System::EventArgs^ e) + { + Application::Exit(); + } + }; +} + diff --git a/Chapter10/NotifyIconEx/Form1.resx b/Chapter10/NotifyIconEx/Form1.resx new file mode 100644 index 0000000..2e5ccf1 --- /dev/null +++ b/Chapter10/NotifyIconEx/Form1.resx @@ -0,0 +1,171 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 17, 17 + + + 118, 17 + + + + + AAABAAIAICAQAAAAAADoAgAAJgAAABAQEAAAAAAAKAEAAA4DAAAoAAAAIAAAAEAAAAABAAQAAAAAAAAC + AAAAAAAAAAAAABAAAAAQAAAAAAAAAAAAgAAAgAAAAICAAIAAAACAAIAAgIAAAICAgADAwMAAAAD/AAD/ + AAAA//8A/wAAAP8A/wD//wAA////AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAkAAAkAAJAAmZkAAAAAAAC5AAC5AAuQC7uwmQAAAAAAsJAAuZALALAA + C7AAAAAAAAuQC7uQuQuQAAAAAACQAAALCQsLkLALkAALkAALkAAAALm5C5uQC5AAm5mQm5mQAAC5uQub + AAsJC7u7C7u7AAAAsLALuQAAuQALkAALkAAAAAuQALkAALCQCwAACwAAAAALkAC5AAALCQAJAAAAAAAA + C5AAuQAAALCZuQAAAAAAAAsAALAAAAALu7AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA//w////A + A///AAD//gAAf/gAAB/wAAAP8AAAD+AAAAfAAAADwAAAA4AAAAGAAAABgAAAAQAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAIAAAAGAAAABgAAAAcAAAAPAAAAD4AAAB/AAAA/wAAAP+AAAH/4AAH//AAD//8AD///8 + P/8oAAAAEAAAACAAAAABAAQAAAAAAIAAAAAAAAAAAAAAABAAAAAQAAAAAAAAAAAAgAAAgAAAAICAAIAA + AACAAIAAgIAAAICAgADAwMAAAAD/AAD/AAAA//8A/wAAAP8A/wD//wAA////AAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACQmQkJmQAAALC7C5u7CQCQububsAALkLkLu7C5ALu7uwuw + sAuZCwCwCwCwALsAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA+B8AAPAP + AADAAwAAwAMAAIABAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACAAQAAwAMAAMADAADwDwAA+B8AAA== + + + + + AAABAAIAICAQAAAAAADoAgAAJgAAABAQEAAAAAAAKAEAAA4DAAAoAAAAIAAAAEAAAAABAAQAAAAAAAAC + AAAAAAAAAAAAABAAAAAQAAAAAAAAAAAAgAAAgAAAAICAAIAAAACAAIAAgIAAAICAgADAwMAAAAD/AAD/ + AAAA//8A/wAAAP8A/wD//wAA////AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAkAAAkAAJAAmZkAAAAAAAC5AAC5AAuQC7uwmQAAAAAAsJAAuZALALAA + C7AAAAAAAAuQC7uQuQuQAAAAAACQAAALCQsLkLALkAALkAALkAAAALm5C5uQC5AAm5mQm5mQAAC5uQub + AAsJC7u7C7u7AAAAsLALuQAAuQALkAALkAAAAAuQALkAALCQCwAACwAAAAALkAC5AAALCQAJAAAAAAAA + C5AAuQAAALCZuQAAAAAAAAsAALAAAAALu7AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA//w////A + A///AAD//gAAf/gAAB/wAAAP8AAAD+AAAAfAAAADwAAAA4AAAAGAAAABgAAAAQAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAIAAAAGAAAABgAAAAcAAAAPAAAAD4AAAB/AAAA/wAAAP+AAAH/4AAH//AAD//8AD///8 + P/8oAAAAEAAAACAAAAABAAQAAAAAAIAAAAAAAAAAAAAAABAAAAAQAAAAAAAAAAAAgAAAgAAAAICAAIAA + AACAAIAAgIAAAICAgADAwMAAAAD/AAD/AAAA//8A/wAAAP8A/wD//wAA////AAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACQmQkJmQAAALC7C5u7CQCQububsAALkLkLu7C5ALu7uwuw + sAuZCwCwCwCwALsAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA+B8AAPAP + AADAAwAAwAMAAIABAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACAAQAAwAMAAMADAADwDwAA+B8AAA== + + + \ No newline at end of file diff --git a/Chapter10/NotifyIconEx/Images/app.ico b/Chapter10/NotifyIconEx/Images/app.ico new file mode 100644 index 0000000..14f4ee8 Binary files /dev/null and b/Chapter10/NotifyIconEx/Images/app.ico differ diff --git a/Chapter10/NotifyIconEx/NotifyIconEx.cpp b/Chapter10/NotifyIconEx/NotifyIconEx.cpp new file mode 100644 index 0000000..5be094e --- /dev/null +++ b/Chapter10/NotifyIconEx/NotifyIconEx.cpp @@ -0,0 +1,16 @@ +// NotifyIconEx.cpp : main project file. + +#include "stdafx.h" +#include "Form1.h" + +using namespace NotifyIconEx; + +[STAThreadAttribute] +int main(array ^args) +{ + // Enabling Windows XP visual effects before any controls are created + Application::EnableVisualStyles(); + // Create the main window and run it + Application::Run(gcnew Form1()); + return 0; +} diff --git a/Chapter10/NotifyIconEx/NotifyIconEx.vcproj b/Chapter10/NotifyIconEx/NotifyIconEx.vcproj new file mode 100644 index 0000000..010a94a --- /dev/null +++ b/Chapter10/NotifyIconEx/NotifyIconEx.vcproj @@ -0,0 +1,254 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Chapter10/NotifyIconEx/resource.h b/Chapter10/NotifyIconEx/resource.h new file mode 100644 index 0000000..d5ac7c4 --- /dev/null +++ b/Chapter10/NotifyIconEx/resource.h @@ -0,0 +1,3 @@ +//{{NO_DEPENDENCIES}} +// Microsoft Visual C++ generated include file. +// Used by app.rc diff --git a/Chapter10/NotifyIconEx/stdafx.cpp b/Chapter10/NotifyIconEx/stdafx.cpp new file mode 100644 index 0000000..64eab1e --- /dev/null +++ b/Chapter10/NotifyIconEx/stdafx.cpp @@ -0,0 +1,7 @@ +// stdafx.cpp : source file that includes just the standard includes +// NotifyIconEx.pch will be the pre-compiled header +// stdafx.obj will contain the pre-compiled type information + +#include "stdafx.h" + + diff --git a/Chapter10/NotifyIconEx/stdafx.h b/Chapter10/NotifyIconEx/stdafx.h new file mode 100644 index 0000000..46bef73 --- /dev/null +++ b/Chapter10/NotifyIconEx/stdafx.h @@ -0,0 +1,6 @@ +// stdafx.h : include file for standard system include files, +// or project specific include files that are used frequently, but +// are changed infrequently +#pragma once + +// TODO: reference additional headers your program requires here diff --git a/Chapter10/PictureBoxEx/AssemblyInfo.cpp b/Chapter10/PictureBoxEx/AssemblyInfo.cpp new file mode 100644 index 0000000..21a73ad --- /dev/null +++ b/Chapter10/PictureBoxEx/AssemblyInfo.cpp @@ -0,0 +1,35 @@ +#include "stdafx.h" + +using namespace System::Reflection; +using namespace System::Runtime::CompilerServices; +using namespace System::Runtime::InteropServices; + +// +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +// +[assembly:AssemblyTitleAttribute("PictureBoxEx")]; +[assembly:AssemblyDescriptionAttribute("")]; +[assembly:AssemblyConfigurationAttribute("")]; +[assembly:AssemblyCompanyAttribute("")]; +[assembly:AssemblyProductAttribute("PictureBoxEx")]; +[assembly:AssemblyCopyrightAttribute("Copyright (c) 2005")]; +[assembly:AssemblyTrademarkAttribute("")]; +[assembly:AssemblyCultureAttribute("")]; + +// +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the value or you can default the Revision and Build Numbers +// by using the '*' as shown below: + +[assembly:AssemblyVersionAttribute("1.0.*")]; + +[assembly:ComVisible(false)]; + diff --git a/Chapter10/PictureBoxEx/Form1.h b/Chapter10/PictureBoxEx/Form1.h new file mode 100644 index 0000000..3924e45 --- /dev/null +++ b/Chapter10/PictureBoxEx/Form1.h @@ -0,0 +1,76 @@ +#pragma once + + +namespace PictureBoxEx +{ + using namespace System; + using namespace System::ComponentModel; + using namespace System::Collections; + using namespace System::Windows::Forms; + using namespace System::Data; + using namespace System::Drawing; + + public ref class Form1 : public System::Windows::Forms::Form + { + public: + Form1(void) + { + InitializeComponent(); + } + + protected: + ~Form1() + { + if (components) + { + delete components; + } + } + private: + System::Windows::Forms::PictureBox^ pictureBox1; + System::ComponentModel::Container ^components; + +#pragma region Windows Form Designer generated code + + void InitializeComponent(void) + { + System::ComponentModel::ComponentResourceManager^ resources = + (gcnew System::ComponentModel::ComponentResourceManager(Form1::typeid)); + this->pictureBox1 = (gcnew System::Windows::Forms::PictureBox()); + (cli::safe_cast + (this->pictureBox1))->BeginInit(); + this->SuspendLayout(); + // + // pictureBox1 + // + this->pictureBox1->Anchor = + static_cast + ((((System::Windows::Forms::AnchorStyles::Top + | System::Windows::Forms::AnchorStyles::Bottom) + | System::Windows::Forms::AnchorStyles::Left) + | System::Windows::Forms::AnchorStyles::Right)); + this->pictureBox1->Image = (cli::safe_cast + (resources->GetObject(L"pictureBox1.Image"))); + this->pictureBox1->Location = System::Drawing::Point(12, 12); + this->pictureBox1->Name = L"pictureBox1"; + this->pictureBox1->Size = System::Drawing::Size(369, 287); + this->pictureBox1->SizeMode = + System::Windows::Forms::PictureBoxSizeMode::StretchImage; + this->pictureBox1->TabIndex = 0; + this->pictureBox1->TabStop = false; + // + // Form1 + // + this->AutoScaleDimensions = System::Drawing::SizeF(6, 13); + this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font; + this->ClientSize = System::Drawing::Size(393, 311); + this->Controls->Add(this->pictureBox1); + this->Name = L"Form1"; + this->Text = L"Shaina Shoshana"; + (cli::safe_cast + (this->pictureBox1))->EndInit(); + this->ResumeLayout(false); + } +#pragma endregion + }; +} diff --git a/Chapter10/PictureBoxEx/Form1.resx b/Chapter10/PictureBoxEx/Form1.resx new file mode 100644 index 0000000..e4a6364 --- /dev/null +++ b/Chapter10/PictureBoxEx/Form1.resx @@ -0,0 +1,361 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + + + /9j/4AAQSkZJRgABAQEAYABgAAD/2wBDAAgGBgcGBQgHBwcJCQgKDBQNDAsLDBkSEw8UHRofHh0aHBwg + JC4nICIsIxwcKDcpLDAxNDQ0Hyc5PTgyPC4zNDL/2wBDAQkJCQwLDBgNDRgyIRwhMjIyMjIyMjIyMjIy + MjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjL/wAARCAEgAYEDASIAAhEBAxEB/8QA + HwAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL/8QAtRAAAgEDAwIEAwUFBAQAAAF9AQIDAAQRBRIh + MUEGE1FhByJxFDKBkaEII0KxwRVS0fAkM2JyggkKFhcYGRolJicoKSo0NTY3ODk6Q0RFRkdISUpTVFVW + V1hZWmNkZWZnaGlqc3R1dnd4eXqDhIWGh4iJipKTlJWWl5iZmqKjpKWmp6ipqrKztLW2t7i5usLDxMXG + x8jJytLT1NXW19jZ2uHi4+Tl5ufo6erx8vP09fb3+Pn6/8QAHwEAAwEBAQEBAQEBAQAAAAAAAAECAwQF + BgcICQoL/8QAtREAAgECBAQDBAcFBAQAAQJ3AAECAxEEBSExBhJBUQdhcRMiMoEIFEKRobHBCSMzUvAV + YnLRChYkNOEl8RcYGRomJygpKjU2Nzg5OkNERUZHSElKU1RVVldYWVpjZGVmZ2hpanN0dXZ3eHl6goOE + hYaHiImKkpOUlZaXmJmaoqOkpaanqKmqsrO0tba3uLm6wsPExcbHyMnK0tPU1dbX2Nna4uPk5ebn6Onq + 8vP09fb3+Pn6/9oADAMBAAIRAxEAPwCwaTHpTz1pD+dIQwim7akIOf8A61JigCPFLjjin7c4pwWnYQzH + FKBT9tKAMUDGYpO9S7aQJzQK4ymtjjnipivrWXqWq2unxNJO/A4AHepk7IpK5ZL8fKPqaPMCHB5IHY1y + E3jS0CnEcoJIPHQ1XXxYZWd47fYAcjJ6Cs+dmns2dm04/g5pFvIc4MihvrXFXfidJcBcgnnJHNVZfEXP + 3wwPJGKXOw5D0USrg5PSoZbkgFY9pb1PauCh8UW6gb3mZsdu1Sw+KoUUgrJknrRzsPZncRzYTPGfapVc + MCa4qPxVBGq4D7jwQw4X3q/beJLNgAZh65IIo9pYPZs6XhjxStgHI6VmQ6tZzIDC4ZvrVqKZ2b2PrVqa + exDi1uWD8wpGByKccYGD+VKRz71QhgB6UucdaeF79qCo54poTGZpDzS8ZoOM0ARMDjNMI56VNgk03H4f + SkBDgZx3FBGOf61JjvTSOKBkZ4PTimnOPpUhHr1ppHuaBDOtGMinFRjNJg0ANxmkK8U/GecUmKAIjk9e + RTCCPapiKYR7UARfz96djPbFLgj/AOtS4xSAb1FL9BQaTFUIRhgU1ulOI70hHH4dqQyPGKMccCnH86MU + wG7D7/lRTtvsKKNAOnOKbTu+aMH1+lNCGEc0DrTtuaXb6UANpwHFKBxyAPel6d6YDcYFHQenpRkdAc0i + ruPHJHFK4DtwXkkVXnvooVOX6Akkc1Ff3sVhEWcBmx0WuN1HVZbskHhf7o6ConO2iNIU+bUvar4n3ArE + WGAcEcZPauAvbqaeQGSdnA7E5xWtcgMCzEn1waxLkDceKyTvubctthyhdoPXmpMMvy52jqaqx8dDjmrC + p13Nx602wSELxpuySSe/c1W3BmBPA9BUrRbjkEgep70wW0m7haAsSjyghVB+J60meOB+VPiXacPGPfir + 0FiLjlXI+nNK41EyjwCMnn1pyyMvAOQPbiteTSmB7sPUihNOG3nHqecUXQ+Vmek7cYZgR6Vs6d4lvrQq + rN5qd1Y81nPYMuSgzxx6VUdHB6YPrSaTFsen6XrlvqBMiPhsYKHqPetfzVPpXjdrdTWsqurFSDwa6qx8 + WuiKs3PYmmm47kSgnqjvgw7GlxkGsbTdYgvMbXFbCOCoIPBrSMkzJxsJjNGz0p2PanleOlWiSErSMvWp + CM0nHFAERHboKaV4qXGR/Sm896QELL6e9MINTkCmsOaAISPakx+tSN160Ef5NAEWQBnvQRjJpxAPpnvR + jimBGRzzSY5zUhGT6e1NxjgUgI9tIVxUm0+lJj2oAiI/xppqbGeKaRx0oAiIzSYqTbSBeRQAzbRj3qTH + ejuaYiPy/wDZFFP3H3oosFzoaXH/AOqn7eaXZ7YpgMHH4UuAacFIFIxIH9aAI2IXPPFRbS3Jz/Snn95I + ABnHWh1wQO1IZGVC9d2B6VC8wSNn3lUHOc9qmfEcZdyMDp9a5XXtTZ0NtERg/exWc5WNIR5mY+qarNd3 + jkNtQE4rOR8t3b27VK9skajexYn06Cmo6qCEwTnrWR02GGBpTyny9ary2EYXPJ9hWjArSS75OIxztz1r + QtoRcz58tSqnjPQmlzWK5bnNf2a5ALIVHYml/s85xn6CuynsWKnd87t1x0FWLTQ9zD5MnHfsKh1C40rn + HrpDsgZgdppyaa6ZA4x3NejR6WoQLsGO4qO90uJUAVQC3Xip9rctU0eaS2kgQkKcE9fWnpA8DKUJBxk1 + 3VxpSy2ZiRAPQ96yn04GJPl9jgU/aXH7LUx0v57dxv8AmQ+orWt/sl9B8vDnggnmoZtN3EDHFZ9xYy2c + 6vDIVYHINCa6Eygy19ne2kbYyuo654NJeWMV5EXACyqOOMVbW4jvbREuFxMP4l7f41W3SWrbZOV7NVKT + vdEOPQ5q6tWiG0jHPBqkrFDyfxrqruCO7jMqsA38SHvWBc2oAwDhgfu1pGSZjKLQ2C7ktpA8THH16V2W + h+JTJhJ27jk1wIJRirDA96mjkeJgyGm0Rfue3W0qSorA5Bqbbx1rz7w34iZWEUrGu+gnSeNXVgc+9XCd + 9GZTjbVClaaVqbb0puK0IIcU0ipCKbigBhWmlelS4FNx60AQOvOabgVKwxTSOKQDMU0rmpMZ69aaRQAw + qT3pCOnNSEU3qcUAM98UhHFSfr7CkIxQIi200ipMUhHNAyIr+VGO9Sbe9JimA0DikIpxHNJjP40CI9h9 + TRUuz2/SikM6Xb6dqB1z29afjPagKc1Qhu2mPGAOe9TDI6ZFROMg46DigCEAYwvBpjZV/m4A5qwqhdxx + z71FN8sLMRgnn3NSxoyNVvGWFt5AUDPBrjZmxlyTk9K6DUZDJP5YGQvzMa5q/mKE7ePlz+JrklK7O2Eb + IrTyZGS2fUDtTYUYsDt+Xr0qfTbdJ8eZnA5+pq/LCuQqZC0nKxrGNyrDCTl5D/n0rYs7WWfbsG1Panaf + pL3Miu67YwflU9TXaafp6wqDgE9vasZO5uopFOz0lY41aQZPXB/rV9bZS2AoArQWHLemBThAdwxznpmk + kNspCAKfl4HqaY9sZWAA+Ve+O9aiwcc9aPJ29BihRFcxhamMlSOD7Vm3GntDcYVflbkcV1TQh0OR+JqG + S0MsWxiMjlWxVcoXORlsSrFWXvnpVW+09XiTKYI9q614Qy7XG2QVQu4G8vbxg80tR3OMNl5TlGX8qrXi + FVKsBkD866e5tkK71PzdCM1iagBgEZOOKuLM5I58SGKQlemeVNNkt2uEJTG4fMMelPu48uZEz7ioo7gK + VdevcVqtNTGWqMSXBkII56GmlcZQ9uhq3qBRbxmVcZOSarsm8DnBHStTnCF2ikVhxXdeG9eyBG7exrh+ + nFSwStbTB1NJoF2Pa4pFljBU5BpzVzPh7VxNCqM+TjiumVgVzitITujGUbMaR60wipMZPWmkVZJFQRxT + 6bQBE4qMnFSvwKjIpABHrSEZNOAxikIzjFAhpHr603GKf9KQ8dKAGEY//VSEcU/OOlJ26/lQAztz1pmD + /WpCO2Kbg4zigBncelBBp5GP5Uh/zigZGaAppTk/WlAxQA3B/wAmin49h+VFMDpyOtKOtOx7UoHFMRGR + TDgLxU20d+/rUTgZCjFDAj2hjtzxnkj+VUtQmEcTtnhRx/SrkrCFfvcH1/nXN6pdCVSitgDqfU1jVlaJ + tSjzSMO5uSFeU4G8msW7YzWgdsH5gv1ArSvHRojnAVc4xWbMh/s5G7BzmuZHaaelMi2uCvtWrZwLPLvY + cDpWLpPMe0nrxXT2aBYwKibNaaNayQb+BgAVuQAEA8+1ZVuAFGAOlalucgfyqEaMuRgZIqUJ8xHemxjj + PH41OoyemMVokZMREyckYoeMY4FTxjPFKy+31qkhXKu0nGKkMYK9MetOI242nrScngUwKc1tG46fNWdd + WCupG4g4xzWyy7fSq0vBNQ0NM468tZbSTcfmX+VYt5tLA45PUV211EHUhuQR9a5i/szG3A68KazNNzk7 + yAxDePutn86xCrK5UfWuouEaZGhxnZ82awHjJvCg7CuiL0OeSMqdg8h7nNKowKHA8xj70BwDg1qc4EAn + Oaj5J2mgHORUwjO0MRgGmSbfh7f5g56GvQrOcmMBjzXBeH5Yl+9gYNdxAwYArj3NKO5MjVUCg1HA+eOK + mI5rZGLIm4puOakPNMOKYEbKKYRUpFMNArjO9Jn8aceBTSO/40hjfrSH8qXvSEHGf1osAn+c0h6UvfFN + PFABjvikPFB6D+dB+lAhCMn+lNNPPXFJ0oAbjtQBx04peppePxoATHvRS4PqKKAOqxnrS4pwHFNkOxc4 + z2xVCIZXwfbtVaSWUHcseQOp6VYKqPnc85/Kqsk6EEcj096lspLsZ+pTkLn5uR3/AFrmLq4yG28ZNbeq + TAJuHTGORXMvxE3GWrkqas7KOiKNzIqgg9AMY9TSxhX0x0YgnquPWq9wMlM+vWo4LjyLrBwVBIOaSWhq + 9zXsojCUJGFIyDXUWS5C9fWuUhuzJsjB+RelddYFRAjO2NvABNYzN4OyNiBNoHpWjAQD15rEbULeAAtI + BU1rrNq54cke1JaFM6WIZq6iZ561i22qWzkAPiti3uI3Hy9OtbRkmZSTLMcOR0p5tsZHOKkikUgYNTPI + Npxzj0rVJGbbM1ownOOPWmsBjOaWeQHJyOO9c9e6u6s4iIAXjceaiTSLSua0shBPpVZ3DZBrm5dXvmJK + YKju1Ni12YvtmjAPqKzu2XaxuSoGB45rD1GMGFlf8CBVg6oiYz0Peqeo3Ec1uzK61AzkZJDHJIANzdKx + 4VJmnncgBQc5rZneE28m3m4kOEH90Vzd++x/syn3Y+tbQRlNmXO21Xb1PFVtzEZHYVYnQlDxyDUKRkLk + 9+AK2OZomtY98nPpVyVFRPmPPQCoYT5S5P3j2HWo5GZ5csaEJ7FqylMcwIbHPSvRNGkMluDnsK8ygcrM + prudFvgIlXPA6Ck9HcT1R1UZw1Xc7lzWZBIZBkZrRhPHNaxMGLj1qMipmHpUZH4ZqhEZ6c00inkUwjmm + AzvTSMninkUnU98UgIyKQ9aeR60hX/61AiM9cetN46CnnuB1ppGKQxD/AEpvapMdfWmnjP8AKgBPak4z + 70feyM0Y56UAORGc7VXJPFTvYXKgtgdOner+k23BkZa1HRPKJYjpxWTm27Hp0MNDlvJHJ+Vc/wB2itn5 + f+eg/wC+aKd33NPq1LsbGOo9aif5pAMdKnP+c1Xi+Zmc+tbnjGT4glktrJ5UOCcDd6V5Xc61fm6bbcy4 + U8HNeta5btdaXPHGAW25A9a8yXSA0zZ7nnIxg+9c9Xc6aGwkOrXcyBZ3LjvmrKyhiyHOSOP61YTSfLhZ + 8ZC85HWookVmkdvSue99jpSRl3S5iZjxtb0rMnb96WPfk1pXhLKyZyWOBWbLGd3rgc1cdgZoWL7IxO5+ + Wt231G4vBsgjfOMDFYdjC15DbW65AL4OK9Q0XSoLSKMqnOOT61LSZonoYNj4Zv7hhLcZHfa1bg8OTRoN + u0Z/Oty41G3s1y5XI64qi/iW1MhQTwqfd6dkO7M1tMubdwSMqD1FbOmzOjbSTVf+0/NG4FHUcEq2abBd + KLkEcis3ZFXbOttXcqOeven3DOi9eMdqqWMnyZLcVNesGjJU9q1UtCGtTHvbpmTYp69aopp3nKN5zzmk + uZhG3Xmn/wBo+Wu2NctjrngVmmm9S2uxLHoUQJJJ2kcDNLJ4btJTkAgd+ax7jxZZ2cm261JI2I6ADNMg + 8dadNceVDextgcluPyrVKy2M29bXJNR8MeWuLeWTn1PFctqmm3unqXMmRjoK72PWI7l426Bh3qv4gt1l + 0yeTHKjNRo9irtbnkc9y8UigH5m/SsqVvMumY5IJ5Nat1AQXmbvnFZUSggjHOTVx2M5rUbKo5Pr3qqcj + A6Yq/NhIsHB5qtjzAQo+arMWRxlQQRkseDk1NKVCbm5b2qGKLyzk8ntSs2cg0+pLGKecg11vhy0aZkOc + 57VyKDBxXZ+FpCGUY6HvRInod5a26xxBanC7DimwP8oOKkbJHpWqMWOIH51Gw/SpR92mEVRJERxTCKlI + 9aYR2oGREUEGn4ppBoAZikPNKQc0EZoAj/D8aaefxqQjpSY5NICPFB5GacR6UmOKAGYJOcU6GEyyhQOc + +lBAFa+i6e9xLvIOKicuVG9Cnzy12NK3g8q3VQOCKq30gSBiT0rda3CJsPp9a5HxPqMNhGEbJZ2AAA5N + ZJWR63PZWRlfbD/s/nRVP+0If+eMn/fJopcyOb2lX+U9DYcGs4StFAHzwASfzrUIrmdZRzfrb7mERj37 + QepziumbsrnlxVySTUmlk2xqAV5IJzmsyW1jvp/OPyM/UKOtWJLDyAJYgVI6jPUVHFIYG2n8DWD7SNlp + rEzNRjNgGQ52MODXNiYxlvpiuv1G5huVMUidvyrkL1DCzDqCcispRs9DopyvoyGOAyyIQR15LVW1WBYp + RbxsGJ5Yip0lJxnjvj2ptlEl/eu5+WMDA96EWzS8L2++6i4zgkivQry9i02zLueccBRya5DQFEN9wOAC + BXYLFHLgzAN6ZqG9S4o4ySa71u4b7UklpZKpwR95vr7Vxlpby6drsdxdaa2pWyMy+S7EBuCASfbOfwr2 + l7SzkG1vunsKrNpmmowkxkj7vHStY1FFWJnR52cb4FtEjnuDeieKMpmNdxPzE/p/9auoiyLkLknnvUr+ + Wvy2sWD64qIg2uCwy7c1lVqKRpTpcnU6qznAjwT+VSz3I2Nj/IrlUvJyvyIcU5p7nOWyKx52aez1uP1F + iXz71VjLNdKZwWth95U6mp1b7QCrDmiK3aJ8YyKcZ2dxuN1Y5HxhEZ/Edvf6Vao/lMjpHIgK5XsQeorn + jo+oavr0t/qNtHH58xeRYuAPoK9fihtSwaaFTx1AqxFaaUjFwq9Ociuv29zkeGVzgbfT9Rhuj9gmb7Px + iN+a6/zZLjSpYJ12uUIzmthRa8+XGB+FQXUKSI+FwcVk9XdG3SzPMLu1Qx3CHrGMr71yD5SU7fWvR760 + 8uSUhOeetef3sflXLDGATxTg+hNRdRrxmSPC9RzioooJTKBGMuOwqeDJcDOCfWut0q1tra3M0yjcR97N + W52M1C5yd0SQAU8uT+JccVmynGeMEV1OttDKTMV+6PzrlZRuJYdauLvqZTjbQW3jMkwHqa9C0O0WCMNX + DadEzygr2rutOLgIvA6Chmb2OwtpFKDipyue1V7NP3Y4Aq7tHHFbR2MGR7RTGHXipyPaojjJq0SQNTSP + apT1ph5P+FA7kWOab+NSEZNNOPoKQDCKbTzTQKAG4z601qkxxTG/WgY0jrSEYp3ek5/EUASQRGeVUHOS + K7rS7IW1qoxg4rnfD9qJJjIei9K6522RADjFYP3peh30Y8sPUr3ChEJzzXnupQDVPEkcbY2QjccGuy1a + 7W0tXkZuAM1xGmFjFcX7H55WJGfSlU2t3Oulu5djT/syH/Z/Kisz7fJ/ef8AOiqtEXOu52uD0xWdq1k0 + 6rLGB50Z4GOGHcVqEU1krZpNWPFTs7mErBrfvjB4bqPY1j3DDLHHvW5q9/YWJ/flhMRkLGOT9a5WXWIJ + XI2tEn99hnH1rmm+h0Qi2rooXJIZn6D86xrnNww28jPWt5kt58kzCSPPVTxVJ40L7UwBU8rNFKzKCWWb + eTcxztIFZcNy1p8qnoK3JxLGjYGOOK5xoiwYHO7rzRYuD1O48Pt5qwyY5INdfDGXGc1xfhU7rVVHVeBX + oml2vmBS2fwrFrU6YaakKWLMfunBPWra6UHT7mc1u21nuAGOKvLbxxjPBoUOrCVQ5eXTYbK1a4mHyrz9 + axrWwfULo3MqbY8/KuO1dTriie08sYIDZIHf2rN2XM9vi0njiZeAjCk0ugRbtdmpY6PauhDfLx1qG70u + BlKKBnPBxS2s1xEipPgPj5ivQmq99Nqjxs9gkYx03jrVcqtsLW+5zl7aXGn3O9UyvtW5YwRalarNGMHo + fY06Y3B0/wD4mHlGUj+CpvDlu9vExcYDkkKe1Z8tmW3pcU6XtHQUwWIU5Kiuk8tHByMmkNqCMEA1qoIj + 2jOe+zKoHy8VWnXaCMCugntwqn0rBv4ymdpH0p8tgvc5jUwME4zXnOs26NOzD7rH8jXo96cROWHBrz7U + p0W7MOciiIpW2My2idHGRuUd66i0RJbRhuIwvC571hRAqwA7V1+k+W8arIijcMFitJzs0Jr3ThdSZgWT + J6/nWPkgkV0+v2axXT4k4Lccdq5uRFyea2RhLXUmsbnyJgwNdtpVwbmNWCn1rgVjwwI9a7PQLqNFRWOA + OtBnJaHc2l1gAe1aaPuxXMR3Me/Cv37mteCb5FIP61rGXQwkjSJ44qJ8UkcmRTjzWtzMiNMK96kIxTWp + hciK55puDTzwKQikAwim8089qQigYym44p+OKckbSuFXOTxSbS3HGLk7IgkYIPm61Te+SNsMp59q6UaU + iqA/zP1x6VIPD0U0efLA/CuaVVt6HdDDRS94t+HZ4HtR5bgseo71uyOuPmwAK5A6Dd2TCW0JXocZqxZ6 + 800xtLsbJ19eM1MZuPxHQ4p/CZ3jCeS5nt7CI4ErYJ9qhurdba3jtU44ApJ5Gv8AxTGBykQznFS37iW/ + bp8nFXbmqPysRUnyUku5T+zx+i/kKKn5orf2aPN9o+51pqK5njtrWW4lbCRqWJrkvGOuX9rqCWNpI0Ch + A7OhwWz7+lc5cavqN3Zi0ubp5Yg275up+p71nOsldGtPDykkxbq6kvbiS5mbLyHPPYdhWfM23PcelTAk + gU2RARgiuW7bO9RSRlSbc/usoevBptpczyXyQSShS5wrHgZrRezlK/JBIfoprIv7d0TDxsjDsQQa1Skt + 0YT5ZaJnV/2FeSqVd8e5rLvtHNrK0ZwSOhFa3gvVpdQgezlfdLCBtLHkrWzqumE7ZTzjqAO1W43WhhGT + jKzMbwlbmPzAw/i4Jr1HTBhVGOCMV5zoh8ud1HTdxXo2mMBCg74rDqdyfum9FhE/wqGaducUqOCnWq10 + QID2/rTexJl3txliSelQWkimUNnHNUNQuVjk5PJ6CqX2x1OQQPrWfKzojC6O9iW2eMF2UntmnTyQCEqp + X8O9cfY6qDI63LLtA4+tSvqRlJAZQvp7Vau0J0GmaMuzdkgE5p9tNzjNZguBgA/iat2pDEcjmp5WTJWO + gglJA557mrqsCOaoQYCA9KleYrwMZq46GL1C4IwQR1rCv04OK2JG3AZrKvSSOKtocTkNTX905HSvKNQV + n1KY5JAbFevaqoEBPXivKLyRFvZQ2Pv0krIJMks3kBG4AntmugjuoraNfMV8jrsNYEN1ACCTgdqm/teJ + X/1W/wCtZuN2DkLq0tlcRGWNpw/oelcxJGS2cN+VddLMZ7UuLOPd154rDupJABujRB7DANaxZlJdzPVM + dc1PHcND90kGmxuzOcnIpjkMD61aRk2W49WnR87ya6PSPEkjusTnNcRzuxWtots73SsO1DRO56zZ3Alj + DZq5u4HpWXpQVIFBYZ9jWnvQDAOfpWsNUYSWoE+tNp2AeaNtaEEZGT05puMnmpCOKaaLAMpp9aeQR1NI + OaBjCCO3StfRrU+Ysrcg1nQQmaUIB1rqbOFbeNVPbviuaq7tRPRwkEo87Ev4NmydO3UUltqVqVXzJAAO + 1JdStdy+TAcr0JFEegu2CV49qznvodOnUlvfE1moWKGJmIGMgYFYjaIdV1FL0oUz0A9K2xo6qvzIM9uK + 0bO6FpD5bRBsHg043btLYXKo6w3Odv8AQxYWzXEXEmOprmkYsN7nLE8mus8Ta2iWjK7KCwwPrXnFxqYj + IReWPQV0e7FnNXjKSUerN3zF/vfrRWNsvv7p/Kil9Yp9zD6lW7HX+JNDXVrUTRj/AEuEfIf7w/u/4V54 + EIcowKspwVI5Br10da5PxNolt9sivkba8jfvIx0bHf8Az1onR55e6TSxHs172xz1nphuDukYonbHU1rR + W9vb5EaKPfqTREvy8HipdnHpXp0MNCmtFqedXxNSq9XoMZdwwRWLqturIFdFde9bTAjtmqtzGZYSOnFb + TipKxjCTi7nCWk3/AAj/AIkguYyfKLYYf7J6ivZpI1lgVlwRjcD7YrxzxFbbYg+Ojc16V4Mvv7Q8L2rO + d0ka+Weck4ryZR5JtHpX5oKRnGH7JqbbV+UscGu3005iQg5rndTsj5LSDcSp31raNcgxKcZyK5akbM7q + E7xOrgi3R1na2Ta6e0o6LWjZT5QqKj1WJJ7R45BwwxUM0T97U8wRLzUbxgvEefnbPIrprHw7bObZp2BU + 5V+T+dctf2lzpt2+ySREbgEHqKs2+varHsCSqwTplaScVujtdOpPWD0O6svDmgvazyT8hWZQ+8jBFc5J + pZj1HyLazkdD8y7s5YDvS2uuagtm1q8cRWR9x4wQasy+J9TWaO5itoi0cezoTkVV10RMadaLd3f5l278 + OlLCCWGQpO+A0ZOcc96ytRtb/Q3jYyLKrjcQp6VUbxTq7PKxSMCQ9+1UZ7rVdWmQPJuIXaAPSjmi+4vZ + Vl8TR1Og+IF1GXyCpWRRnJ9K6PZvkHpXO+G9HGnL5jjMjDkmuq/hB70ROadlLQrSrhevas+4UOpNaM7A + 496oy4Ckg1aJucvrCBY2+nWvE9Vz/a1xnOA9ey+IbsRW0jnsPWvHWQ6m8zocyBiSPWntqJ6kQv4I02xx + /Nj7zc0lvPl9+e/U1B9hbcd3UdquQwHpt9sUnYnXdlg6jKRtXnPY1UujNO++Qk9sDpV6O0iiy8mWPZRW + rZ20E7qzKUQfwkUo2WxM2+py4hlVCAh5qJgVU7uDmus1OW2hGyFQW9qx7fS5b64G1cLnrWj0Mk76lG0s + 2nlwFzXZaXpckSg+WvX0rU0nw8lvGryKCcdK6CKFEGAgwBjpTUWyJTtsUrSIqoDYBrSSHIBzUUihTxU8 + ByMevStUrGTdx+zbxSEZIFPIPSmkZ4qyCMjgY5ppyT0/CpCAPpTT0oGMIpvFSUmAWH1FJjjq7Gzolhvf + zWHFa15IqJ9niUM7dT7VXsrn7LZA7B0yM1Y0y3e5mM8gwWORmuJy69Weukoq3RFzS9NEKcj5j1NbY2Qx + 4PSmxIIoqwtb1PyLdyGxtB71pThZEazZZvLuIZG5a4zxD4qttLiYtIN3ZQa5c+JNX13UpLKwVQAcF6en + gK7ubgT6nOXPXHaodXVpLU6lBRWrOK1HxJfa1qwZwywg5UetdR4c0KW5uFvbpDtByAa1b3wtbQoghgAZ + OQcda09Pv1EAt5EEbrx9amacnaWzFTsnzdTS2wf88qKrecPX9KKv2cew+dG3iua8QSFr9I88JHnH1NdP + 0rG1vTnuNtzCMuowyjutd9KSUrs+dmm00jnwdu0GrcfI561TnHyBgMYOatI22IH2r0EzjkgdARx61E8a + 4681Oo3gE/lTGXk4HSrSM7nN6vYRzxvEw+Vh+VRfD3VVsdTuNIuTgyHKZ4GR2/KtfVYW8jzAPu8nArgt + Xkay1iC+gO1xhhj1Fefi4W9478NPmXKe5eUpQhhwRzWNATp981ueFzuQ+orU0u8XUNNt7pTnzUDVBqlk + 1zGJIuJk5HuPSuOpDmjoddGpyS1Nmwuxx+dWru4DKBnrXKaZfgttbKsOCDxzWnJcq7KSR7c1xts77Jsl + ubaKcYkQMvvVNPDNu7FkJU1qWxEig55q9GQgBx07U1ruXCcofCzMh8O7AMyhh9Knk0mUwmMFRu6t3rXg + kDk4Wp8AH5l4rReQOtPqcmPC0A++zN7VetNNhtjiONRnvW6+0ZwOTVR8buDzSaSJlVlLdkGNjYHOKvB8 + xDms+SUB/elFwdmB2pLchi3B5Jz0rOvbsJFwevpTrm5xnJx9a5TX9YjtIWZ3AwKtITZynjvWBHatErAs + 3Arz3Trh4LlXQ455qXWtSfUrxpWztz8oqKxi3ucdQKqS0sZX947dobDU7NJY2EdyRyOxqpb6U7ylFYbv + Q1gRXL26MUbkDrmrltq8rMrZO9TnNZcrsacxrXukyQwncNrKe3esdrqSMFd5PoM1eudXmu0Ikc56dazL + gBx6HtVRIlqauj6eb+QPM3H1ruLOztrSIbFAPrXndjqT2sqqORXU2t5LOoIdlB7Zq1o9TGSZ1Im3EKvS + rSsFTJFY9lIcAnk1o5LgACtou5i0Kx3vyOamjUAYH6UxI/y9amHGTVoljsnOMUxiM044xUbHJpkiHB9/ + SkpM+/1pGPagYHjp2oyVo7UyV9uGx3qZfCzSl8aOi06N77buzsUdK6yzhWMDA49q57w3lrccYzzXUqAi + 5xXFT11PTn2C6bbCSBXkvj3WWjjFnAT5spxxXpeo3H7lgR+FeY6zp7zXTXzp/qzlc1tJtR03HSWuppeD + /Dv9maalxIv7+Tkk12EUQljGfvVU0K9TU9IhkxhgoUitRUwPl4b61jRiuVNDqzbk7mPc6eS+OCDWFqGl + OSxC4I712rKR95earziMjDAZrWxKmea/2ddf89/0NFd59mtvX9aKu4tBuOaUdKQ89MUvbitjyTl9ctFg + nJVcRyDI9Ae9Ut+YlGa6nU7X7TZsAMsvIHr7VycILTKmDx29K7qE7qxy1Y2dy/Gg29Kd5eDUqrimyyBB + 05rpscjZDNbiRSCOtef+KNGO0vEMY+YLXfNcMR2FZ99Ck6/MeairTU42ZrRqOEtBPhxqaXegCzLjzrdi + Nvfb2rtCOea8Z82bwl4ihvof+PeQ/Oo9O4r2CxvIdRsormBt0ci5BrybOL5Wek7S95GdqWmbi13b8SAZ + Zf71ZSahuABbB4GK6xlDKR6jFc0ljHNA6EDerEA1hWgr3OrD1JWaNrSLzftBORW/EA/JNeewPNZTfKxO + OxrqNN1iOQBHwD9ax5Gjp5r6nX28SryMYxU5jV1xmsm31BcZBBz6U/7aq5IPJ/nWq2Id7j5kZWxnj1qp + LJxgmmXWpoFyzKBXP3uuIMhTnNCgxuRoT3Cq3tVaS+RQOa5+S+urliIY2Yk9e1Kui397/wAfE5RO4Sk3 + GItWV9Y8SwwsUiJlmxwicmuN1K0vtSJudQJjiHKxA8/jXf8A9k2OmIfIiXfjlzyTXMa4/m7kXPXFR7Rv + QrlVjzPUCsl7tQAKnAAqWA+Uu4HnpzWlLoYn1uG380RCb+JuRmte48Baoq7YJoJV7c7a6o05TV4q5ySq + xhK0nY5hMMVU9zVsQJFnAwRWh/wiOswcvApAPVXBp8mhao7bhYSnA7c1EqU10ZcasH1MpCHynrTJiVAT + OSO9Wm06+t7nElpOg9TGahvInUZMbL65GKlJp6jck9UVY97EkAnHNalpq726hc4o0JYp5DFJjnpXTJ4X + t51LbRmmkZyl3JNE1QTkfNXXQMGQdK4KfS5NKfdGcAHkV0Wj6oZUVXJzjvVJ8r1M5K60Oi3cU7PHpTVO + 8Ain9BWyMRrVGwJ+lPPPOTSHA4J7UwISPWmk9KkI/OmY5zQMXI461DKnmPGvq1SnIp1uN19EPes6rtBs + 2w6vUR3Gh2yxwr04HIrdAGMD8qz9OTbGoB6jOK0UHJrmpKyO2buzNu4d5OR+GKwNXtFmtHBA6HiuuljX + ac1haooMbIAOetb2GpaHOeCp0FlPasfmjbI+ldXAx9e9cN4YIh1u8hJxmu0gOGPNc1PS67M0qb3NEEMO + ap3MSMpA6mnPIyDIOKQSq6cjmtkzNK2pnfZPc/nRV7I9P1op6Fcxl4z1paBzxS1ueSA6cVzNxbrHrNyQ + MAkEV02awroZ1KUn2H6V0Yb4zCu/cGt8sZOKou4PJOWPapb2cIuwHmq8KFzkmvQRw20HLDk5fj8ar3ax + shCZyO4q6YiRyaidIlG0uB9aATOL8QxtPp8kUy/MvzIw9a0fhfrTMk2kytnb88eT27irGowJKpBXcp7Y + rkNLn/4RnxZBOxIhLYPsprzsXBpqR6OGkpRcT3Hg54rJtYgby5jIGN5PFT3OqQQ2izIwk3jKAHrVbSmm + +2O1wMGTDDjFclaL5FI68M/faM7Vbdre6B5KsetJDFvA2j8jXQ6xYrNbmQc7RmsSzyrBCDkcVzczR3ct + yVEuI87JGH0pxN85wJBn3rShj3gDFXILZSckVXtGLlRhrpd3ccyzkD0UdavW2gRKc+Xk+prdiiRccdKu + Ro2PkQ/lUtykJtIy4NMigGSoBA6VHcnauF4ArTl3kEAfNUBtFY5ck1rDC1J9LGE8VTp7s5a7jlmysaF8 + elZ9v4VuL2433DeTEPxNd35caLhVAHtUJU8nOB9a7KeAgtZO5x1Mwm9IqxiDwnpMe0m3V3Xozc0r6akf + yrHnHpWq8oHGd38qqySO/GSB7V3QhGKtFHBKpKTu2ZklpER+8C/hWXc2rRMWtXkT6HiugEY3fP0qTNqq + 4IFWSpHL2+o3O8xT4DdiV4NWDAt2pimiiII5ylWNWjjljOxB04xWDY6lLa6gLW5zh8+W5/lQ0luNNvVH + LeJLK30jUInt0VGLYbbwDXT6LdJcWqneC2K5fx46tLE27LFj+Vcpb6peWh/dSkD0rzMVFRq+6ejQblSV + z2O4s1ukIP8AKqtpoggfcvAzXL+F/FF3czGGZt2K9GiIZA3rzWSaloU04kcalFA9qkPSnECmnv8ArWlj + MZkH6009etISdxwKX+dAbDT1poX1FO/WjufegBjDkYqawXOoJxUR6mpbMlb9D0rKsvcZ0Yb+Ij0GyOEG + D2q+p9zWVZSZjB6ir6yfNmsaex1yRJMxIrGvwDbseM471pzS/LWRetuXrgVrcUUzz57h7DxB544Vzg12 + mnXhk6nNcnrNqWkV/etzQ8tFycHvXFNtT9Tt5U4HRtIGXGKjwADio1B296TflSPSt0zC1h3mD/JoqHd7 + UVoSQClB9etN/rSg1seUKeDWJeHbfzEdeD+lbfP9awtYPkXBfpuTPPqK6MO7TMayvAyHPm3DZPGatiQR + qFRc9qq2qFyD2q60iQDkZbsK9BM4ZaMiaOaU/OxUegppghQ84J96GeSQFnOxfrUDzRJwu5z2xVE6kdzD + lfkIrkda0K71FS0EDOIiC8ijKoCQMk9ucCuqkdypJTaPeooS+113sEYgsueCRnGR7ZP5msa0VNcp0UZO + PvCabaGC2hgLM/lrtBJr03SUinsY98asQMcjNcJYD/SVyMgV1ek/6KTsdtjHO0npWVSmuXlXQ6aNVKTc + up0MmmW00ZUoRn0NVF8LaaHD4fP+9VmO+RgPmNTpdxY+/iuZ0V2O1Vl0ZGmg2ceMK34saspplqgGIxj3 + 5qGTUUU7VJYiq0l5I2fmIzTjh12Iniox6mg7Wttwqrn0AqjNds4wuFH0qqWJPU0mSa3hSjE4qmKlLbYe + Xxx1NRM/djj0FMeQjhBn3piIScnkn1rWxzXuDS46DHuRULtI54BP1qyYlByaazAdBVIVym0Jxl259BUJ + TPQ9KuN8xOaZtyelMCg6tjrVWWJiMnIrY8ntjmlW1Bxnke9O4HOmGXoCT+FU57BpTmSNjjkMBXarbRgf + dGaa0CjtSvcfM0eQ+KtCur+FPKwWj5G4YJrzu6tprWUxzRsjD1r6ZuLSGQNvTIPrXJeIvCFrfQO0aAtj + gY5rnrYdVNVudFHEcmj2PLvCHOon0yK9hhOIVGe1eT2VufD+tGOb/Vk8E9vY16ZZalBdQKUcE4rzlFwm + 1I7Zvmimi/uB/wAKCfl5FMzkZFG7jrWpiIev6UhOKDx3phJx70DDPc0mcfjRk/5NJ2ouAufer0VjKsEd + 0QQpPH0rP612lxbg6HDsHIUU1BTumXCfJNPzHWMpCAAGtRHGOhrK04fu171twgbea4YaHpTI2QuvQ9Kz + rqAjI7fWtZ5CBgDiqso3D+VaN6Ci2crdWhZsFentVrTrQwrnbjNaJtdzZbBq3HGNuAorncbyudHNZWKz + RMErLuJmiJ5OK3ZRtQ/pXMa3MI4ZHyOhrVRIuV/tx/u0VyH9oSf89D/n8aK00M+Y9EApwpgNOzitjzBS + PasjxBAXshKOqHnHoa188VDPEs8EkR+6wIqovldyWrqxylvJ5SepNWI7cu25+tVYUIuzGw+ZBgitFpFh + Tc3Xt716kHdHn1FZkM8SKvz9egFUp5I7cYC5c9hUlxKUBmlOX/hXsKpWyedchnOT1J9aq9tCVFbssNC/ + 2NpJPvN29Kit4jIwVat37/ukjXin2UfljJ6mpluXG1izbWvlyLtBPrW5bcJis6xY73YDcCcEVrqiHG1s + H3PNRcbJUGB1qVTgVEqY704detBJIvLVIck1EDTgCRyaAHgYHrShGKk4wKFAHSnZzQAxYtiEDoTzS/d4 + pQw3c/jTZSCD2I6H2oERu3GO/WojzzVczliQKepJH9au1hXQ8CnKnNIoPFTAUBcRU3HJqZY/ahF71LnA + qRjDH9ajdDjFSlvzphOfegCpLGcYHWs6dJI84BrZKH1qKaHIqkxHm3i7Ql1W1Z0UR3C8qQOteYW+r3+k + 3RjZmDRtgqTXvuoWW5DivI/HOhGGQ3kaYP8Ay0Fc+KoqceZbnVhqtnyPY2ND8ZJdbUmIDHiuwguFnQMh + zkcV8+pI0UgdDgivRPCWvtKgjkfkdjXmqTW53OCex6CfWmkcU1JBJGHB60pPrxWpkIfSjNJn3ppJxQMs + 2kTSzoo5Ga7jT8S2bW7ZyBxmuS0iItNv6445rpYXMUqsDxXTRj7tznqztKxJaRmGQxkYweK2YhxntVCV + d+2dB9at28iletcNSlyS8j06dZVI36kjKG4qJ4htqwSMZHSmkAjpUGqZSZcHFAOwcVNKMDg1Umm2DtzU + 8pakQXc3YVxnie6CWzIDlmOB71uX92qqTk/hXHxwPrniKOBmPlR/Mw61cVdiqTUY3KX2E/8APN/yor0X + +zk9F/Kiun6pPueZ9cRXBFPBNQg09W71IEoNBHpTVPalB470AYOpW4g1HzhwJFzj3FVUbzFaZsFVPH+N + amtxsbVZVGWQ4/Pisl3EdqCx4A4UdzXo4Z3gcOIVpGXeTGSUk+vFTWLbMnNQS5kCuepJzTrclGK961+0 + Q/gsi453yZPUVNv2xnHXFVw3zmpFG9wD061LepcVoa2mghQT361tInyis2xXFaaY44pEPceOnFPUAHr+ + tM79KcPrQIlAHpT+g9KjBx707P4UhjieKTPGBTCTjPSgmgALADJ4qGRmfO3sOtPYFj7U9UoCxQSFg2Km + Ax3qy8QX0qEgZq73IaHDpTlfmo+oxUirjk/rQBOrkClL4+tMzg0BcmkMcOe1OVe9OUYHSnDilcQ0jsKY + wqXHpTSuaBmfcRblbHXvXK69pSXkEiOAdwwT612rpkYrOurQSKRj61aYtnc+Z9b0uTStRkgdCq5yp9qq + WN5JZXKyIcYNeteNfD4vbVyIyJkyVOOtePOjI5Vhgg4IrzMTR5JeTPUoVeePmeu+HNcW7gUMwrpA2VyK + 8V8P6o1ndqpPynpXrOm3q3MCkHmsIO2jNJx6o0c5FJnmkpM1oZ2Ok0RMw571shRjmszQ0H2ZT3NajDBr + vp/CjiqfEyeCUx49D1zU7J83mRN+FVkwcAVZXKjIyKU4KSswp1ZU3dFqGcMMHg+hqRmwPaqKzRyfeOCO + 9T43j5XBHsa43hmnod8cZFrUJBxx1rKvfuk5rSdX6bhiqc1uXH3wPpWfsZ9jZYmnvc5i7UFW3d6qeE0V + tbunA+6v5V0M2kxOpWSZsH0qCy0/T9HZ5IWbe/Uk5zWlLDzvqjHEYqnKDSZvbh/dorL/ALUg9Gor0eVn + lcyM0HvTh9aiJp6HnivMPTJlPNPz/kVGp6Yp4PNAFTUxnT5Rjrj+dcxfMTMEzgKuTXXXEfnW0kfcjiuL + mZ2kmMow+SCPSu3CtWaOXEJ3TGYBXaaZGSsoB609xhQR2pjYJzjNdJguxZQ7pCT61oWaZbccflWdb5Iz + xWzaR8jjpWZo9EalqKuDAPWqsQA4HSrC5ximZsl609cCmA8ZpwPPWgCUHjNJntTSeOtHOPakApPNKFPW + kAzipB04oAQD25qReOKjyBxxSF/SgQ2eT5evzDiq4LHvU7R7kJ755qEAA1SExyDp1qZeOtRpjpUmfU9a + Yh/vUoKqtVw3pTXlI70guWjKB3FOWQZ61mmQ9aTzZV5BNPlBM1uCtN7deay1vJY+q5FWo7+JjhsqfcUr + WAskVGwBA4p/mI4wHH500jnA6GkBmajp0V3CysATivD/AB74Tm065a+ijzEx+faOnvXvr5ArP1LT4NQt + nhlTcGGMUTiqkeVl05um7o+VQ2xgQea7fwtrpUrE7c1n+NfC8nh3U22Kfs0hyhx09q522na3nV1PQ15N + Wm4OzPWhNTjdbHukE4mjDA1N+tcj4d1lZ4VUtya6tX3DdRGV0RJWZ2mh/wDHpGcHOK13jyKxdBbNonsK + 3gcrXpU/hR59T4mV4wRzVtfQioRH8341NsIFUzMY9uoJYcZqtiWFsoTV7ORzSOoYcGgLlFbibIyetRSy + ynILH86tyEADOOKhcpzx+lUkQ2Zp812wSSBUbQF2yR+lXmYDoKjY/LVokz/szeg/KirG8epoqyT/2Q== + + + \ No newline at end of file diff --git a/Chapter10/PictureBoxEx/Images/shainaOK.JPG b/Chapter10/PictureBoxEx/Images/shainaOK.JPG new file mode 100644 index 0000000..4d238f8 Binary files /dev/null and b/Chapter10/PictureBoxEx/Images/shainaOK.JPG differ diff --git a/Chapter10/PictureBoxEx/PictureBoxEx.cpp b/Chapter10/PictureBoxEx/PictureBoxEx.cpp new file mode 100644 index 0000000..a277419 --- /dev/null +++ b/Chapter10/PictureBoxEx/PictureBoxEx.cpp @@ -0,0 +1,16 @@ +// PictureBoxEx.cpp : main project file. + +#include "stdafx.h" +#include "Form1.h" + +using namespace PictureBoxEx; + +[STAThreadAttribute] +int main(array ^args) +{ + // Enabling Windows XP visual effects before any controls are created + Application::EnableVisualStyles(); + // Create the main window and run it + Application::Run(gcnew Form1()); + return 0; +} diff --git a/Chapter10/PictureBoxEx/PictureBoxEx.vcproj b/Chapter10/PictureBoxEx/PictureBoxEx.vcproj new file mode 100644 index 0000000..407ee1e --- /dev/null +++ b/Chapter10/PictureBoxEx/PictureBoxEx.vcproj @@ -0,0 +1,254 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Chapter10/PictureBoxEx/resource.h b/Chapter10/PictureBoxEx/resource.h new file mode 100644 index 0000000..d5ac7c4 --- /dev/null +++ b/Chapter10/PictureBoxEx/resource.h @@ -0,0 +1,3 @@ +//{{NO_DEPENDENCIES}} +// Microsoft Visual C++ generated include file. +// Used by app.rc diff --git a/Chapter10/PictureBoxEx/stdafx.cpp b/Chapter10/PictureBoxEx/stdafx.cpp new file mode 100644 index 0000000..e621c7a --- /dev/null +++ b/Chapter10/PictureBoxEx/stdafx.cpp @@ -0,0 +1,7 @@ +// stdafx.cpp : source file that includes just the standard includes +// PictureBoxEx.pch will be the pre-compiled header +// stdafx.obj will contain the pre-compiled type information + +#include "stdafx.h" + + diff --git a/Chapter10/PictureBoxEx/stdafx.h b/Chapter10/PictureBoxEx/stdafx.h new file mode 100644 index 0000000..46bef73 --- /dev/null +++ b/Chapter10/PictureBoxEx/stdafx.h @@ -0,0 +1,6 @@ +// stdafx.h : include file for standard system include files, +// or project specific include files that are used frequently, but +// are changed infrequently +#pragma once + +// TODO: reference additional headers your program requires here diff --git a/Chapter10/SimpleMenu/AssemblyInfo.cpp b/Chapter10/SimpleMenu/AssemblyInfo.cpp new file mode 100644 index 0000000..73d49e2 --- /dev/null +++ b/Chapter10/SimpleMenu/AssemblyInfo.cpp @@ -0,0 +1,35 @@ +#include "stdafx.h" + +using namespace System::Reflection; +using namespace System::Runtime::CompilerServices; +using namespace System::Runtime::InteropServices; + +// +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +// +[assembly:AssemblyTitleAttribute("SimpleMenu")]; +[assembly:AssemblyDescriptionAttribute("")]; +[assembly:AssemblyConfigurationAttribute("")]; +[assembly:AssemblyCompanyAttribute("")]; +[assembly:AssemblyProductAttribute("SimpleMenu")]; +[assembly:AssemblyCopyrightAttribute("Copyright (c) 2005")]; +[assembly:AssemblyTrademarkAttribute("")]; +[assembly:AssemblyCultureAttribute("")]; + +// +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the value or you can default the Revision and Build Numbers +// by using the '*' as shown below: + +[assembly:AssemblyVersionAttribute("1.0.*")]; + +[assembly:ComVisible(false)]; + diff --git a/Chapter10/SimpleMenu/Form1.h b/Chapter10/SimpleMenu/Form1.h new file mode 100644 index 0000000..0c28bfa --- /dev/null +++ b/Chapter10/SimpleMenu/Form1.h @@ -0,0 +1,240 @@ +#pragma once + + +namespace SimpleMenu { + + using namespace System; + using namespace System::ComponentModel; + using namespace System::Collections; + using namespace System::Windows::Forms; + using namespace System::Data; + using namespace System::Drawing; + + public ref class Form1 : public System::Windows::Forms::Form + { + public: + Form1(void) + { + InitializeComponent(); + } + + protected: + ~Form1() + { + if (components) + { + delete components; + } + } + + private: + System::Windows::Forms::ToolStripContainer^ toolStripContainer1; + System::Windows::Forms::MenuStrip^ mainMenuStrip; + System::Windows::Forms::ToolStripMenuItem^ miFile; + System::Windows::Forms::ToolStripMenuItem^ miFileSub; + System::Windows::Forms::ToolStripComboBox^ miFileSubThis; + System::Windows::Forms::ToolStripMenuItem^ miFileExit; + System::Windows::Forms::ToolStripMenuItem^ miFileSubCheck; + System::Windows::Forms::ToolStripMenuItem^ miFileSubImage; + System::Windows::Forms::ToolStripMenuItem^ miFileSubSayBoo; + System::Windows::Forms::ToolStripMenuItem^ miHelp; + System::Windows::Forms::ToolStripMenuItem^ miHelpAbout; + System::Windows::Forms::ToolStripSeparator^ miFileSep1; + + System::ComponentModel::IContainer^ components; + + private: + +#pragma region Windows Form Designer generated code + + void InitializeComponent(void) + { + System::ComponentModel::ComponentResourceManager^ resources = + (gcnew System::ComponentModel::ComponentResourceManager(Form1::typeid)); + this->toolStripContainer1 = + (gcnew System::Windows::Forms::ToolStripContainer()); + this->mainMenuStrip = (gcnew System::Windows::Forms::MenuStrip()); + this->miFile = (gcnew System::Windows::Forms::ToolStripMenuItem()); + this->miFileSub = + (gcnew System::Windows::Forms::ToolStripMenuItem()); + this->miFileSubThis = + (gcnew System::Windows::Forms::ToolStripComboBox()); + this->miFileSubCheck = + (gcnew System::Windows::Forms::ToolStripMenuItem()); + this->miFileSubImage = + (gcnew System::Windows::Forms::ToolStripMenuItem()); + this->miFileSubSayBoo = + (gcnew System::Windows::Forms::ToolStripMenuItem()); + this->miFileSep1 = + (gcnew System::Windows::Forms::ToolStripSeparator()); + this->miFileExit = + (gcnew System::Windows::Forms::ToolStripMenuItem()); + this->miHelp = + (gcnew System::Windows::Forms::ToolStripMenuItem()); + this->miHelpAbout = + (gcnew System::Windows::Forms::ToolStripMenuItem()); + this->toolStripContainer1->TopToolStripPanel->SuspendLayout(); + this->toolStripContainer1->SuspendLayout(); + this->mainMenuStrip->SuspendLayout(); + this->SuspendLayout(); + // + // toolStripContainer1 + // + // + // toolStripContainer1.ContentPanel + // + this->toolStripContainer1->ContentPanel->Size = + System::Drawing::Size(292, 249); + this->toolStripContainer1->Dock = + System::Windows::Forms::DockStyle::Fill; + this->toolStripContainer1->Location = System::Drawing::Point(0, 0); + this->toolStripContainer1->Name = L"toolStripContainer1"; + this->toolStripContainer1->Size = System::Drawing::Size(292, 273); + this->toolStripContainer1->TabIndex = 0; + this->toolStripContainer1->Text = L"toolStripContainer1"; + // + // toolStripContainer1.TopToolStripPanel + // + this->toolStripContainer1->TopToolStripPanel->Controls->Add( + this->mainMenuStrip); + // + // mainMenuStrip + // + this->mainMenuStrip->Dock =System::Windows::Forms::DockStyle::None; + this->mainMenuStrip->Items->AddRange( + gcnew cli::array< System::Windows::Forms::ToolStripItem^>(2) + {this->miFile, this->miHelp}); + this->mainMenuStrip->Location = System::Drawing::Point(0, 0); + this->mainMenuStrip->Name = L"mainMenuStrip"; + this->mainMenuStrip->Size = System::Drawing::Size(292, 24); + this->mainMenuStrip->TabIndex = 0; + this->mainMenuStrip->Text = L"menuStrip1"; + // + // miFile + // + this->miFile->DropDownItems->AddRange( + gcnew cli::array< System::Windows::Forms::ToolStripItem^>(3) + {this->miFileSub, this->miFileSep1, this->miFileExit}); + this->miFile->Name = L"miFile"; + this->miFile->Size = System::Drawing::Size(35, 20); + this->miFile->Text = L"&File"; + // + // miFileSub + // + this->miFileSub->DropDownItems->AddRange( + gcnew cli::array< System::Windows::Forms::ToolStripItem^>(4) + {this->miFileSubThis, this->miFileSubCheck, + this->miFileSubImage, this->miFileSubSayBoo}); + this->miFileSub->Name = L"miFileSub"; + this->miFileSub->Size = System::Drawing::Size(152, 22); + this->miFileSub->Text = L"&Sub"; + // + // miFileSubThis + // + this->miFileSubThis->Items->AddRange( + gcnew cli::array< System::Object^>(3) + {L"This", L"That", L"Other Thing"}); + this->miFileSubThis->Name = L"miFileSubThis"; + this->miFileSubThis->Size = System::Drawing::Size(121, 21); + // + // miFileSubCheck + // + this->miFileSubCheck->Checked = true; + this->miFileSubCheck->CheckOnClick = true; + this->miFileSubCheck->CheckState = + System::Windows::Forms::CheckState::Checked; + this->miFileSubCheck->Name = L"miFileSubCheck"; + this->miFileSubCheck->Size = System::Drawing::Size(181, 22); + this->miFileSubCheck->Text = L"Check Me"; + // + // miFileSubImage + // + this->miFileSubImage->Image = + (cli::safe_cast + (resources->GetObject(L"miFileSubImage.Image"))); + this->miFileSubImage->Name = L"miFileSubImage"; + this->miFileSubImage->Size = System::Drawing::Size(181, 22); + this->miFileSubImage->Text = L"I have an image"; + // + // miFileSubSayBoo + // + this->miFileSubSayBoo->Name = L"miFileSubSayBoo"; + this->miFileSubSayBoo->ShortcutKeys = + static_cast + ((System::Windows::Forms::Keys::Control | + System::Windows::Forms::Keys::S)); + this->miFileSubSayBoo->Size = System::Drawing::Size(181, 22); + this->miFileSubSayBoo->Text = L"Say Boo"; + this->miFileSubSayBoo->Click += + gcnew System::EventHandler(this,&Form1::miFileSubSayBoo_Click); + // + // miFileSep1 + // + this->miFileSep1->Name = L"miFileSep1"; + this->miFileSep1->Size = System::Drawing::Size(149, 6); + // + // miFileExit + // + this->miFileExit->Name = L"miFileExit"; + this->miFileExit->Size = System::Drawing::Size(152, 22); + this->miFileExit->Text = L"E&xit"; + this->miFileExit->Click += + gcnew System::EventHandler(this, &Form1::miFileExit_Click); + // + // miHelp + // + this->miHelp->DropDownItems->AddRange( + gcnew cli::array< System::Windows::Forms::ToolStripItem^>(1) + {this->miHelpAbout}); + this->miHelp->Name = L"miHelp"; + this->miHelp->Size = System::Drawing::Size(40, 20); + this->miHelp->Text = L"&Help"; + // + // miHelpAbout + // + this->miHelpAbout->Name = L"miHelpAbout"; + this->miHelpAbout->Size = System::Drawing::Size(152, 22); + this->miHelpAbout->Text = L"About"; + this->miHelpAbout->Click += + gcnew System::EventHandler(this, &Form1::miHelpAbout_Click); + // + // Form1 + // + this->AutoScaleDimensions = System::Drawing::SizeF(6, 13); + this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font; + this->ClientSize = System::Drawing::Size(292, 273); + this->Controls->Add(this->toolStripContainer1); + this->MainMenuStrip = this->mainMenuStrip; + this->Name = L"Form1"; + this->Text = L"Simple Menu"; + this->toolStripContainer1->TopToolStripPanel->ResumeLayout(false); + this->toolStripContainer1->TopToolStripPanel->PerformLayout(); + this->toolStripContainer1->ResumeLayout(false); + this->toolStripContainer1->PerformLayout(); + this->mainMenuStrip->ResumeLayout(false); + this->mainMenuStrip->PerformLayout(); + this->ResumeLayout(false); + } +#pragma endregion + + private: + System::Void miFileExit_Click(System::Object^ sender, + System::EventArgs^ e) + { + Application::Exit(); + } + + System::Void miHelpAbout_Click(System::Object^ sender, + System::EventArgs^ e) + { + MessageBox::Show("Simple Menu v.1.0.0.0"); + } + + System::Void miFileSubSayBoo_Click(System::Object^ sender, + System::EventArgs^ e) + { + MessageBox::Show("BOO"); + } + }; +} + diff --git a/Chapter10/SimpleMenu/Form1.resx b/Chapter10/SimpleMenu/Form1.resx new file mode 100644 index 0000000..714b908 --- /dev/null +++ b/Chapter10/SimpleMenu/Form1.resx @@ -0,0 +1,133 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 17, 17 + + + + + iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8 + YQUAAAAgY0hSTQAAeiYAAICEAAD6AAAAgOgAAHUwAADqYAAAOpgAABdwnLpRPAAAAH1JREFUOE/Nk0sO + wCAIROvNvTkNRizg8FnWhA06T4RxPHhRkB9B/qRZSEQ4eG8H5IRCD0SQtlhgHmIAUqo7jM6sp1y3dwAM + lyp+CIjGGE3jak7mA70He1AZCQHMJLbFYGPn/CZW+WBBdWixHqH2dNuN6X+oepCJTTX+CZHwBRkr1T3o + ssMyAAAAAElFTkSuQmCC + + + \ No newline at end of file diff --git a/Chapter10/SimpleMenu/Images/happy.ico b/Chapter10/SimpleMenu/Images/happy.ico new file mode 100644 index 0000000..6d10f69 Binary files /dev/null and b/Chapter10/SimpleMenu/Images/happy.ico differ diff --git a/Chapter10/SimpleMenu/SimpleMenu.cpp b/Chapter10/SimpleMenu/SimpleMenu.cpp new file mode 100644 index 0000000..27e4ce5 --- /dev/null +++ b/Chapter10/SimpleMenu/SimpleMenu.cpp @@ -0,0 +1,16 @@ +// SimpleMenu.cpp : main project file. + +#include "stdafx.h" +#include "Form1.h" + +using namespace SimpleMenu; + +[STAThreadAttribute] +int main(array ^args) +{ + // Enabling Windows XP visual effects before any controls are created + Application::EnableVisualStyles(); + // Create the main window and run it + Application::Run(gcnew Form1()); + return 0; +} diff --git a/Chapter10/SimpleMenu/SimpleMenu.vcproj b/Chapter10/SimpleMenu/SimpleMenu.vcproj new file mode 100644 index 0000000..8e4bf7f --- /dev/null +++ b/Chapter10/SimpleMenu/SimpleMenu.vcproj @@ -0,0 +1,254 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Chapter10/SimpleMenu/resource.h b/Chapter10/SimpleMenu/resource.h new file mode 100644 index 0000000..d5ac7c4 --- /dev/null +++ b/Chapter10/SimpleMenu/resource.h @@ -0,0 +1,3 @@ +//{{NO_DEPENDENCIES}} +// Microsoft Visual C++ generated include file. +// Used by app.rc diff --git a/Chapter10/SimpleMenu/stdafx.cpp b/Chapter10/SimpleMenu/stdafx.cpp new file mode 100644 index 0000000..9c9e11a --- /dev/null +++ b/Chapter10/SimpleMenu/stdafx.cpp @@ -0,0 +1,7 @@ +// stdafx.cpp : source file that includes just the standard includes +// SimpleMenu.pch will be the pre-compiled header +// stdafx.obj will contain the pre-compiled type information + +#include "stdafx.h" + + diff --git a/Chapter10/SimpleMenu/stdafx.h b/Chapter10/SimpleMenu/stdafx.h new file mode 100644 index 0000000..46bef73 --- /dev/null +++ b/Chapter10/SimpleMenu/stdafx.h @@ -0,0 +1,6 @@ +// stdafx.h : include file for standard system include files, +// or project specific include files that are used frequently, but +// are changed infrequently +#pragma once + +// TODO: reference additional headers your program requires here diff --git a/Chapter10/SplitContainerEx/AssemblyInfo.cpp b/Chapter10/SplitContainerEx/AssemblyInfo.cpp new file mode 100644 index 0000000..f6a27e8 --- /dev/null +++ b/Chapter10/SplitContainerEx/AssemblyInfo.cpp @@ -0,0 +1,63 @@ +#include "stdafx.h" + +using namespace System::Reflection; +using namespace System::Runtime::CompilerServices; +using namespace System::Runtime::InteropServices; + +// +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +// +[assembly:AssemblyTitleAttribute("SplitContainerEx")]; +[assembly:AssemblyDescriptionAttribute("")]; +[assembly:AssemblyConfigurationAttribute("")]; +[assembly:AssemblyCompanyAttribute("")]; +[assembly:AssemblyProductAttribute("SplitContainerEx")]; +[assembly:AssemblyCopyrightAttribute("Copyright © 2005")]; +[assembly:AssemblyTrademarkAttribute("")]; +[assembly:AssemblyCultureAttribute("")]; + +// +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the value or you can default the Revision and Build Numbers +// by using the '*' as shown below: + +[assembly:AssemblyVersionAttribute("1.0.*")]; + +// +// In order to sign your assembly you must specify a key to use. Refer to the +// Microsoft CLR Framework documentation for more information on assembly signing. +// +// You can use the attributes below to control which key is used for signing. +// You can also use the project property page for signing under Common Properties +// to set the same information. +// +// Notes: +// (*) If no key is specified, the assembly is not signed. +// (*) KeyName refers to a key that has been installed in the Crypto Service +// Provider (CSP) on your machine. KeyFile refers to a file which contains +// a key. +// (*) If the KeyFile and the KeyName values are both specified, the +// following processing occurs: +// (1) If the KeyName can be found in the CSP, that key is used. +// (2) If the KeyName does not exist and the KeyFile does exist, the key +// in the KeyFile is installed into the CSP and used. +// (*) In order to create a KeyFile, you can use the sn.exe (Strong Name) utility. +// When specifying the KeyFile, the location of the KeyFile should be +// relative to the project directory. +// (*) Delay Signing is an advanced option - see the Microsoft CLR Framework +// documentation for more information on this. +// +//[assembly:AssemblyDelaySignAttribute(false)]; +//[assembly:AssemblyKeyFileAttribute("")]; +//[assembly:AssemblyKeyNameAttribute("")]; + +[assembly:ComVisible(false)]; + diff --git a/Chapter10/SplitContainerEx/Form1.h b/Chapter10/SplitContainerEx/Form1.h new file mode 100644 index 0000000..6cf5f71 --- /dev/null +++ b/Chapter10/SplitContainerEx/Form1.h @@ -0,0 +1,158 @@ +#pragma once + +namespace SplitContainerEx +{ + using namespace System; + using namespace System::ComponentModel; + using namespace System::Collections; + using namespace System::Windows::Forms; + using namespace System::Data; + using namespace System::Drawing; + + public ref class Form1 : public System::Windows::Forms::Form + { + public: + Form1(void) + { + InitializeComponent(); + } + + protected: + ~Form1() + { + if (components) + { + delete components; + } + } + private: + System::Windows::Forms::SplitContainer^ splitContainer1; + System::Windows::Forms::TextBox^ textBox1; + System::Windows::Forms::SplitContainer^ splitContainer2; + System::Windows::Forms::TextBox^ textBox2; + System::Windows::Forms::TextBox^ textBox3; + + System::ComponentModel::Container ^components; + +#pragma region Windows Form Designer generated code + + void InitializeComponent(void) + { + this->splitContainer1 = + (gcnew System::Windows::Forms::SplitContainer()); + this->textBox1 = (gcnew System::Windows::Forms::TextBox()); + this->splitContainer2 = + (gcnew System::Windows::Forms::SplitContainer()); + this->textBox2 = (gcnew System::Windows::Forms::TextBox()); + this->textBox3 = (gcnew System::Windows::Forms::TextBox()); + this->splitContainer1->Panel1->SuspendLayout(); + this->splitContainer1->Panel2->SuspendLayout(); + this->splitContainer1->SuspendLayout(); + this->splitContainer2->Panel1->SuspendLayout(); + this->splitContainer2->Panel2->SuspendLayout(); + this->splitContainer2->SuspendLayout(); + this->SuspendLayout(); + // + // splitContainer1 + // + this->splitContainer1->BackColor = System::Drawing::Color::Green; + this->splitContainer1->Dock = + System::Windows::Forms::DockStyle::Fill; + this->splitContainer1->Location = System::Drawing::Point(0, 0); + this->splitContainer1->Name = L"splitContainer1"; + // + // splitContainer1.Panel1 + // + this->splitContainer1->Panel1->Controls->Add(this->textBox1); + // + // splitContainer1.Panel2 + // + this->splitContainer1->Panel2->Controls->Add(this->splitContainer2); + this->splitContainer1->Size = System::Drawing::Size(292, 273); + this->splitContainer1->SplitterDistance = 116; + this->splitContainer1->TabIndex = 1; + this->splitContainer1->Text = L"splitContainer1"; + // + // textBox1 + // + this->textBox1->AutoSize = false; + this->textBox1->BorderStyle = + System::Windows::Forms::BorderStyle::None; + this->textBox1->Dock = System::Windows::Forms::DockStyle::Fill; + this->textBox1->Location = System::Drawing::Point(0, 0); + this->textBox1->Name = L"textBox1"; + this->textBox1->Size = System::Drawing::Size(116, 273); + this->textBox1->TabIndex = 0; + this->textBox1->Text = L"Left Textbox"; + this->textBox1->TextAlign = + System::Windows::Forms::HorizontalAlignment::Center; + // + // splitContainer2 + // + this->splitContainer2->BackColor = System::Drawing::Color::Red; + this->splitContainer2->Location = System::Drawing::Point(18, 82); + this->splitContainer2->Name = L"splitContainer2"; + this->splitContainer2->Orientation = + System::Windows::Forms::Orientation::Horizontal; + // + // splitContainer2.Panel1 + // + this->splitContainer2->Panel1->Controls->Add(this->textBox2); + // + // splitContainer2.Panel2 + // + this->splitContainer2->Panel2->Controls->Add(this->textBox3); + this->splitContainer2->Size = System::Drawing::Size(132, 102); + this->splitContainer2->SplitterDistance = 42; + this->splitContainer2->TabIndex = 0; + this->splitContainer2->Text = L"splitContainer2"; + // + // textBox2 + // + this->textBox2->AutoSize = false; + this->textBox2->BorderStyle = + System::Windows::Forms::BorderStyle::None; + this->textBox2->Dock = System::Windows::Forms::DockStyle::Fill; + this->textBox2->Location = System::Drawing::Point(0, 0); + this->textBox2->Name = L"textBox2"; + this->textBox2->Size = System::Drawing::Size(132, 42); + this->textBox2->TabIndex = 0; + this->textBox2->Text = L"Top Right Textbox"; + this->textBox2->TextAlign = + System::Windows::Forms::HorizontalAlignment::Center; + // + // textBox3 + // + this->textBox3->AutoSize = false; + this->textBox3->BorderStyle = + System::Windows::Forms::BorderStyle::None; + this->textBox3->Dock = System::Windows::Forms::DockStyle::Fill; + this->textBox3->Location = System::Drawing::Point(0, 0); + this->textBox3->Name = L"textBox3"; + this->textBox3->Size = System::Drawing::Size(132, 56); + this->textBox3->TabIndex = 0; + this->textBox3->Text = L"Bottom Right Textbox"; + this->textBox3->TextAlign = + System::Windows::Forms::HorizontalAlignment::Center; + // + // Form1 + // + this->AutoScaleDimensions = System::Drawing::SizeF(6, 13); + this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font; + this->ClientSize = System::Drawing::Size(292, 273); + this->Controls->Add(this->splitContainer1); + this->Name = L"Form1"; + this->Text = L"Form1"; + this->splitContainer1->Panel1->ResumeLayout(false); + this->splitContainer1->Panel2->ResumeLayout(false); + this->splitContainer1->ResumeLayout(false); + this->splitContainer2->Panel1->ResumeLayout(false); + this->splitContainer2->Panel2->ResumeLayout(false); + this->splitContainer2->ResumeLayout(false); + this->ResumeLayout(false); + } +#pragma endregion + }; +} + + diff --git a/Chapter10/SplitContainerEx/Form1.resx b/Chapter10/SplitContainerEx/Form1.resx new file mode 100644 index 0000000..02bbfa2 --- /dev/null +++ b/Chapter10/SplitContainerEx/Form1.resx @@ -0,0 +1,117 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Chapter10/SplitContainerEx/SplitContainerEx.cpp b/Chapter10/SplitContainerEx/SplitContainerEx.cpp new file mode 100644 index 0000000..cf69a27 --- /dev/null +++ b/Chapter10/SplitContainerEx/SplitContainerEx.cpp @@ -0,0 +1,16 @@ +// SplitContainerEx.cpp : main project file. + +#include "stdafx.h" +#include "Form1.h" + +using namespace SplitContainerEx; + +[STAThreadAttribute] +int main(array ^args) +{ + // Enabling Windows XP visual effects before any controls are created + Application::EnableVisualStyles(); + // Create the main window and run it + Application::Run(gcnew Form1()); + return 0; +} diff --git a/Chapter10/SplitContainerEx/SplitContainerEx.vcproj b/Chapter10/SplitContainerEx/SplitContainerEx.vcproj new file mode 100644 index 0000000..465c5b7 --- /dev/null +++ b/Chapter10/SplitContainerEx/SplitContainerEx.vcproj @@ -0,0 +1,256 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Chapter10/SplitContainerEx/resource.h b/Chapter10/SplitContainerEx/resource.h new file mode 100644 index 0000000..d5ac7c4 --- /dev/null +++ b/Chapter10/SplitContainerEx/resource.h @@ -0,0 +1,3 @@ +//{{NO_DEPENDENCIES}} +// Microsoft Visual C++ generated include file. +// Used by app.rc diff --git a/Chapter10/SplitContainerEx/stdafx.cpp b/Chapter10/SplitContainerEx/stdafx.cpp new file mode 100644 index 0000000..f46cce8 --- /dev/null +++ b/Chapter10/SplitContainerEx/stdafx.cpp @@ -0,0 +1,7 @@ +// stdafx.cpp : source file that includes just the standard includes +// SplitContainerEx.pch will be the pre-compiled header +// stdafx.obj will contain the pre-compiled type information + +#include "stdafx.h" + + diff --git a/Chapter10/SplitContainerEx/stdafx.h b/Chapter10/SplitContainerEx/stdafx.h new file mode 100644 index 0000000..46bef73 --- /dev/null +++ b/Chapter10/SplitContainerEx/stdafx.h @@ -0,0 +1,6 @@ +// stdafx.h : include file for standard system include files, +// or project specific include files that are used frequently, but +// are changed infrequently +#pragma once + +// TODO: reference additional headers your program requires here diff --git a/Chapter10/StatusStripEx/AssemblyInfo.cpp b/Chapter10/StatusStripEx/AssemblyInfo.cpp new file mode 100644 index 0000000..982bf8a --- /dev/null +++ b/Chapter10/StatusStripEx/AssemblyInfo.cpp @@ -0,0 +1,35 @@ +#include "stdafx.h" + +using namespace System::Reflection; +using namespace System::Runtime::CompilerServices; +using namespace System::Runtime::InteropServices; + +// +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +// +[assembly:AssemblyTitleAttribute("StatusStripEx")]; +[assembly:AssemblyDescriptionAttribute("")]; +[assembly:AssemblyConfigurationAttribute("")]; +[assembly:AssemblyCompanyAttribute("")]; +[assembly:AssemblyProductAttribute("StatusStripEx")]; +[assembly:AssemblyCopyrightAttribute("Copyright (c) 2005")]; +[assembly:AssemblyTrademarkAttribute("")]; +[assembly:AssemblyCultureAttribute("")]; + +// +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the value or you can default the Revision and Build Numbers +// by using the '*' as shown below: + +[assembly:AssemblyVersionAttribute("1.0.*")]; + +[assembly:ComVisible(false)]; + diff --git a/Chapter10/StatusStripEx/Form1.h b/Chapter10/StatusStripEx/Form1.h new file mode 100644 index 0000000..f7b4079 --- /dev/null +++ b/Chapter10/StatusStripEx/Form1.h @@ -0,0 +1,171 @@ +#pragma once + + +namespace StatusStripEx { + + using namespace System; + using namespace System::ComponentModel; + using namespace System::Collections; + using namespace System::Windows::Forms; + using namespace System::Data; + using namespace System::Drawing; + + public ref class Form1 : public System::Windows::Forms::Form + { + public: + Form1(void) + { + InitializeComponent(); + } + + protected: + ~Form1() + { + if (components) + { + delete components; + } + } + + private: + System::Windows::Forms::ToolStripContainer^ tsContainer; + System::Windows::Forms::StatusStrip^ statusStrip1; + System::Windows::Forms::ToolStripStatusLabel^ statusButtons; + System::Windows::Forms::ToolStripStatusLabel^ statusXCoord; + System::Windows::Forms::ToolStripStatusLabel^ statusYCoord; + + System::ComponentModel::Container ^components; + +#pragma region Windows Form Designer generated code + + void InitializeComponent(void) + { + this->tsContainer = + (gcnew System::Windows::Forms::ToolStripContainer()); + this->statusStrip1 = + (gcnew System::Windows::Forms::StatusStrip()); + this->statusButtons = + (gcnew System::Windows::Forms::ToolStripStatusLabel()); + this->statusXCoord = + (gcnew System::Windows::Forms::ToolStripStatusLabel()); + this->statusYCoord = + (gcnew System::Windows::Forms::ToolStripStatusLabel()); + this->tsContainer->BottomToolStripPanel->SuspendLayout(); + this->tsContainer->SuspendLayout(); + this->statusStrip1->SuspendLayout(); + this->SuspendLayout(); + // + // tsContainer + // + // + // tsContainer.BottomToolStripPanel + // + this->tsContainer->BottomToolStripPanel->Controls->Add( + this->statusStrip1); + // + // tsContainer.ContentPanel + // + this->tsContainer->ContentPanel->Size = + System::Drawing::Size(292, 251); + this->tsContainer->ContentPanel->MouseDown += + gcnew System::Windows::Forms::MouseEventHandler(this, + &Form1::tsContainer_ContentPanel_MouseDown); + this->tsContainer->ContentPanel->MouseMove += + gcnew System::Windows::Forms::MouseEventHandler(this, + &Form1::tsContainer1_ContentPanel_MouseMove); + this->tsContainer->Dock = System::Windows::Forms::DockStyle::Fill; + this->tsContainer->Location = System::Drawing::Point(0, 0); + this->tsContainer->Name = L"tsContainer"; + this->tsContainer->Size = System::Drawing::Size(292, 273); + this->tsContainer->TabIndex = 0; + this->tsContainer->Text = L"toolStripContainer1"; + // + // statusStrip1 + // + this->statusStrip1->Dock = System::Windows::Forms::DockStyle::None; + this->statusStrip1->Items->AddRange( + gcnew cli::array< System::Windows::Forms::ToolStripItem^>(3) + {this->statusButtons, this->statusXCoord, this->statusYCoord}); + this->statusStrip1->Location = System::Drawing::Point(0, 0); + this->statusStrip1->Name = L"statusStrip1"; + this->statusStrip1->Size = System::Drawing::Size(292, 22); + this->statusStrip1->TabIndex = 0; + // + // statusButtons + // + this->statusButtons->Name = L"statusButtons"; + this->statusButtons->Size = System::Drawing::Size(177, 17); + this->statusButtons->Spring = true; + this->statusButtons->TextAlign = + System::Drawing::ContentAlignment::MiddleLeft; + // + // statusXCoord + // + this->statusXCoord->AutoSize = false; + this->statusXCoord->BorderSides = + static_cast + ((((System::Windows::Forms::ToolStripStatusLabelBorderSides::Left + | System::Windows::Forms::ToolStripStatusLabelBorderSides::Top) + | System::Windows::Forms::ToolStripStatusLabelBorderSides::Right) + | System::Windows::Forms::ToolStripStatusLabelBorderSides::Bottom)); + this->statusXCoord->BorderStyle = + System::Windows::Forms::Border3DStyle::Sunken; + this->statusXCoord->Name = L"statusXCoord"; + this->statusXCoord->Size = System::Drawing::Size(50, 17); + // + // statusYCoord + // + this->statusYCoord->AutoSize = false; + this->statusYCoord->BorderSides = + static_cast + ((((System::Windows::Forms::ToolStripStatusLabelBorderSides::Left + | System::Windows::Forms::ToolStripStatusLabelBorderSides::Top) + | System::Windows::Forms::ToolStripStatusLabelBorderSides::Right) + | System::Windows::Forms::ToolStripStatusLabelBorderSides::Bottom)); + this->statusYCoord->BorderStyle = + System::Windows::Forms::Border3DStyle::Sunken; + this->statusYCoord->Name = L"statusYCoord"; + this->statusYCoord->Size = System::Drawing::Size(50, 17); + // + // Form1 + // + this->AutoScaleDimensions = System::Drawing::SizeF(6, 13); + this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font; + this->ClientSize = System::Drawing::Size(292, 273); + this->Controls->Add(this->tsContainer); + this->Name = L"Form1"; + this->Text = L"Status Strip Mouse Tracking"; + this->tsContainer->BottomToolStripPanel->ResumeLayout(false); + this->tsContainer->BottomToolStripPanel->PerformLayout(); + this->tsContainer->ResumeLayout(false); + this->tsContainer->PerformLayout(); + this->statusStrip1->ResumeLayout(false); + this->statusStrip1->PerformLayout(); + this->ResumeLayout(false); + + } +#pragma endregion + +private: + System::Void tsContainer_ContentPanel_MouseDown(System::Object^ sender, + System::Windows::Forms::MouseEventArgs^ e) + { + // clicked mouse button in first status bar panel + if (e->Button == System::Windows::Forms::MouseButtons::Right) + statusButtons->Text = "Right"; + else if (e->Button == System::Windows::Forms::MouseButtons::Left) + statusButtons->Text = "Left"; + else + statusButtons->Text = "Middle"; + } + + System::Void tsContainer1_ContentPanel_MouseMove(System::Object^ sender, + System::Windows::Forms::MouseEventArgs^ e) + { + // x,y coords in second and third status bar panels + statusXCoord->Text = String::Format("X={0}", e->X); + statusYCoord->Text = String::Format("Y={0}", e->Y); + } + }; +} + diff --git a/Chapter10/StatusStripEx/Form1.resx b/Chapter10/StatusStripEx/Form1.resx new file mode 100644 index 0000000..d26a846 --- /dev/null +++ b/Chapter10/StatusStripEx/Form1.resx @@ -0,0 +1,123 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 17, 17 + + \ No newline at end of file diff --git a/Chapter10/StatusStripEx/StatusStripEx.cpp b/Chapter10/StatusStripEx/StatusStripEx.cpp new file mode 100644 index 0000000..cba4a7f --- /dev/null +++ b/Chapter10/StatusStripEx/StatusStripEx.cpp @@ -0,0 +1,16 @@ +// StatusStripEx.cpp : main project file. + +#include "stdafx.h" +#include "Form1.h" + +using namespace StatusStripEx; + +[STAThreadAttribute] +int main(array ^args) +{ + // Enabling Windows XP visual effects before any controls are created + Application::EnableVisualStyles(); + // Create the main window and run it + Application::Run(gcnew Form1()); + return 0; +} diff --git a/Chapter10/StatusStripEx/StatusStripEx.vcproj b/Chapter10/StatusStripEx/StatusStripEx.vcproj new file mode 100644 index 0000000..70a071c --- /dev/null +++ b/Chapter10/StatusStripEx/StatusStripEx.vcproj @@ -0,0 +1,254 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Chapter10/StatusStripEx/resource.h b/Chapter10/StatusStripEx/resource.h new file mode 100644 index 0000000..d5ac7c4 --- /dev/null +++ b/Chapter10/StatusStripEx/resource.h @@ -0,0 +1,3 @@ +//{{NO_DEPENDENCIES}} +// Microsoft Visual C++ generated include file. +// Used by app.rc diff --git a/Chapter10/StatusStripEx/stdafx.cpp b/Chapter10/StatusStripEx/stdafx.cpp new file mode 100644 index 0000000..7e36619 --- /dev/null +++ b/Chapter10/StatusStripEx/stdafx.cpp @@ -0,0 +1,7 @@ +// stdafx.cpp : source file that includes just the standard includes +// StatusStripEx.pch will be the pre-compiled header +// stdafx.obj will contain the pre-compiled type information + +#include "stdafx.h" + + diff --git a/Chapter10/StatusStripEx/stdafx.h b/Chapter10/StatusStripEx/stdafx.h new file mode 100644 index 0000000..46bef73 --- /dev/null +++ b/Chapter10/StatusStripEx/stdafx.h @@ -0,0 +1,6 @@ +// stdafx.h : include file for standard system include files, +// or project specific include files that are used frequently, but +// are changed infrequently +#pragma once + +// TODO: reference additional headers your program requires here diff --git a/Chapter10/TabControlEx/AssemblyInfo.cpp b/Chapter10/TabControlEx/AssemblyInfo.cpp new file mode 100644 index 0000000..648f2ed --- /dev/null +++ b/Chapter10/TabControlEx/AssemblyInfo.cpp @@ -0,0 +1,63 @@ +#include "stdafx.h" + +using namespace System::Reflection; +using namespace System::Runtime::CompilerServices; +using namespace System::Runtime::InteropServices; + +// +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +// +[assembly:AssemblyTitleAttribute("TabControlEx")]; +[assembly:AssemblyDescriptionAttribute("")]; +[assembly:AssemblyConfigurationAttribute("")]; +[assembly:AssemblyCompanyAttribute("")]; +[assembly:AssemblyProductAttribute("TabControlEx")]; +[assembly:AssemblyCopyrightAttribute("Copyright © 2005")]; +[assembly:AssemblyTrademarkAttribute("")]; +[assembly:AssemblyCultureAttribute("")]; + +// +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the value or you can default the Revision and Build Numbers +// by using the '*' as shown below: + +[assembly:AssemblyVersionAttribute("1.0.*")]; + +// +// In order to sign your assembly you must specify a key to use. Refer to the +// Microsoft CLR Framework documentation for more information on assembly signing. +// +// You can use the attributes below to control which key is used for signing. +// You can also use the project property page for signing under Common Properties +// to set the same information. +// +// Notes: +// (*) If no key is specified, the assembly is not signed. +// (*) KeyName refers to a key that has been installed in the Crypto Service +// Provider (CSP) on your machine. KeyFile refers to a file which contains +// a key. +// (*) If the KeyFile and the KeyName values are both specified, the +// following processing occurs: +// (1) If the KeyName can be found in the CSP, that key is used. +// (2) If the KeyName does not exist and the KeyFile does exist, the key +// in the KeyFile is installed into the CSP and used. +// (*) In order to create a KeyFile, you can use the sn.exe (Strong Name) utility. +// When specifying the KeyFile, the location of the KeyFile should be +// relative to the project directory. +// (*) Delay Signing is an advanced option - see the Microsoft CLR Framework +// documentation for more information on this. +// +//[assembly:AssemblyDelaySignAttribute(false)]; +//[assembly:AssemblyKeyFileAttribute("")]; +//[assembly:AssemblyKeyNameAttribute("")]; + +[assembly:ComVisible(false)]; + diff --git a/Chapter10/TabControlEx/Form1.h b/Chapter10/TabControlEx/Form1.h new file mode 100644 index 0000000..d990bf6 --- /dev/null +++ b/Chapter10/TabControlEx/Form1.h @@ -0,0 +1,132 @@ +#pragma once + +namespace TabControlEx +{ + using namespace System; + using namespace System::ComponentModel; + using namespace System::Collections; + using namespace System::Windows::Forms; + using namespace System::Data; + using namespace System::Drawing; + + public ref class Form1 : public System::Windows::Forms::Form + { + public: + Form1(void) + { + InitializeComponent(); + } + + protected: + ~Form1() + { + if (components) + { + delete components; + } + } + + private: + System::Windows::Forms::TabControl^ tabControl1; + System::Windows::Forms::TabPage^ tabPage1; + System::Windows::Forms::Label^ label2; + System::Windows::Forms::TabPage^ tabPage2; + System::Windows::Forms::Label^ label1; + + System::ComponentModel::Container ^components; + +#pragma region Windows Form Designer generated code + + void InitializeComponent(void) + { + this->tabControl1 = (gcnew System::Windows::Forms::TabControl()); + this->tabPage1 = (gcnew System::Windows::Forms::TabPage()); + this->label2 = (gcnew System::Windows::Forms::Label()); + this->tabPage2 = (gcnew System::Windows::Forms::TabPage()); + this->label1 = (gcnew System::Windows::Forms::Label()); + this->tabControl1->SuspendLayout(); + this->tabPage1->SuspendLayout(); + this->tabPage2->SuspendLayout(); + this->SuspendLayout(); + // + // tabControl1 + // + this->tabControl1->Alignment = + System::Windows::Forms::TabAlignment::Bottom; + this->tabControl1->Controls->Add(this->tabPage1); + this->tabControl1->Controls->Add(this->tabPage2); + this->tabControl1->Dock = System::Windows::Forms::DockStyle::Fill; + this->tabControl1->HotTrack = true; + this->tabControl1->Location = System::Drawing::Point(0, 0); + this->tabControl1->Multiline = true; + this->tabControl1->Name = L"tabControl1"; + this->tabControl1->SelectedIndex = 0; + this->tabControl1->ShowToolTips = true; + this->tabControl1->Size = System::Drawing::Size(215, 129); + this->tabControl1->TabIndex = 1; + // + // tabPage1 + // + this->tabPage1->BackColor = System::Drawing::Color::PaleGreen; + this->tabPage1->Controls->Add(this->label2); + this->tabPage1->Location = System::Drawing::Point(4, 4); + this->tabPage1->Name = L"tabPage1"; + this->tabPage1->Padding = System::Windows::Forms::Padding(3); + this->tabPage1->Size = System::Drawing::Size(207, 103); + this->tabPage1->TabIndex = 0; + this->tabPage1->Text = L"Tab One"; + this->tabPage1->ToolTipText = L"This is tab one"; + this->tabPage1->UseVisualStyleBackColor = false; + // + // label2 + // + this->label2->AutoSize = true; + this->label2->Location = System::Drawing::Point(61, 44); + this->label2->Name = L"label2"; + this->label2->Size = System::Drawing::Size(78, 13); + this->label2->TabIndex = 1; + this->label2->Text = L"This is Tab One"; + // + // tabPage2 + // + this->tabPage2->BackColor = System::Drawing::Color::Plum; + this->tabPage2->Controls->Add(this->label1); + this->tabPage2->Location = System::Drawing::Point(4, 4); + this->tabPage2->Name = L"tabPage2"; + this->tabPage2->Padding = System::Windows::Forms::Padding(3); + this->tabPage2->Size = System::Drawing::Size(207, 103); + this->tabPage2->TabIndex = 1; + this->tabPage2->Text = L"Tab Two"; + this->tabPage2->ToolTipText = L"This is tab two"; + this->tabPage2->UseVisualStyleBackColor = false; + // + // label1 + // + this->label1->AutoSize = true; + this->label1->Location = System::Drawing::Point(61, 44); + this->label1->Name = L"label1"; + this->label1->Size = System::Drawing::Size(79, 13); + this->label1->TabIndex = 0; + this->label1->Text = L"This is Tab Two"; + // + // Form1 + // + this->AutoScaleDimensions = System::Drawing::SizeF(6, 13); + this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font; + this->ClientSize = System::Drawing::Size(215, 129); + this->Controls->Add(this->tabControl1); + this->Name = L"Form1"; + this->Text = L"Tab Control Example"; + this->tabControl1->ResumeLayout(false); + this->tabPage1->ResumeLayout(false); + this->tabPage1->PerformLayout(); + this->tabPage2->ResumeLayout(false); + this->tabPage2->PerformLayout(); + this->ResumeLayout(false); + + } +#pragma endregion + }; +} + + diff --git a/Chapter10/TabControlEx/Form1.resx b/Chapter10/TabControlEx/Form1.resx new file mode 100644 index 0000000..02bbfa2 --- /dev/null +++ b/Chapter10/TabControlEx/Form1.resx @@ -0,0 +1,117 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Chapter10/TabControlEx/TabControlEx.cpp b/Chapter10/TabControlEx/TabControlEx.cpp new file mode 100644 index 0000000..e7cc5d9 --- /dev/null +++ b/Chapter10/TabControlEx/TabControlEx.cpp @@ -0,0 +1,16 @@ +// TabControlEx.cpp : main project file. + +#include "stdafx.h" +#include "Form1.h" + +using namespace TabControlEx; + +[STAThreadAttribute] +int main(array ^args) +{ + // Enabling Windows XP visual effects before any controls are created + Application::EnableVisualStyles(); + // Create the main window and run it + Application::Run(gcnew Form1()); + return 0; +} diff --git a/Chapter10/TabControlEx/TabControlEx.vcproj b/Chapter10/TabControlEx/TabControlEx.vcproj new file mode 100644 index 0000000..5abd7cb --- /dev/null +++ b/Chapter10/TabControlEx/TabControlEx.vcproj @@ -0,0 +1,256 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Chapter10/TabControlEx/resource.h b/Chapter10/TabControlEx/resource.h new file mode 100644 index 0000000..d5ac7c4 --- /dev/null +++ b/Chapter10/TabControlEx/resource.h @@ -0,0 +1,3 @@ +//{{NO_DEPENDENCIES}} +// Microsoft Visual C++ generated include file. +// Used by app.rc diff --git a/Chapter10/TabControlEx/stdafx.cpp b/Chapter10/TabControlEx/stdafx.cpp new file mode 100644 index 0000000..a391b4b --- /dev/null +++ b/Chapter10/TabControlEx/stdafx.cpp @@ -0,0 +1,7 @@ +// stdafx.cpp : source file that includes just the standard includes +// TabControlEx.pch will be the pre-compiled header +// stdafx.obj will contain the pre-compiled type information + +#include "stdafx.h" + + diff --git a/Chapter10/TabControlEx/stdafx.h b/Chapter10/TabControlEx/stdafx.h new file mode 100644 index 0000000..46bef73 --- /dev/null +++ b/Chapter10/TabControlEx/stdafx.h @@ -0,0 +1,6 @@ +// stdafx.h : include file for standard system include files, +// or project specific include files that are used frequently, but +// are changed infrequently +#pragma once + +// TODO: reference additional headers your program requires here diff --git a/Chapter10/ToolStripEx/AssemblyInfo.cpp b/Chapter10/ToolStripEx/AssemblyInfo.cpp new file mode 100644 index 0000000..833df9f --- /dev/null +++ b/Chapter10/ToolStripEx/AssemblyInfo.cpp @@ -0,0 +1,63 @@ +#include "stdafx.h" + +using namespace System::Reflection; +using namespace System::Runtime::CompilerServices; +using namespace System::Runtime::InteropServices; + +// +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +// +[assembly:AssemblyTitleAttribute("ToolStripEx")]; +[assembly:AssemblyDescriptionAttribute("")]; +[assembly:AssemblyConfigurationAttribute("")]; +[assembly:AssemblyCompanyAttribute("")]; +[assembly:AssemblyProductAttribute("ToolStripEx")]; +[assembly:AssemblyCopyrightAttribute("Copyright © 2005")]; +[assembly:AssemblyTrademarkAttribute("")]; +[assembly:AssemblyCultureAttribute("")]; + +// +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the value or you can default the Revision and Build Numbers +// by using the '*' as shown below: + +[assembly:AssemblyVersionAttribute("1.0.*")]; + +// +// In order to sign your assembly you must specify a key to use. Refer to the +// Microsoft CLR Framework documentation for more information on assembly signing. +// +// You can use the attributes below to control which key is used for signing. +// You can also use the project property page for signing under Common Properties +// to set the same information. +// +// Notes: +// (*) If no key is specified, the assembly is not signed. +// (*) KeyName refers to a key that has been installed in the Crypto Service +// Provider (CSP) on your machine. KeyFile refers to a file which contains +// a key. +// (*) If the KeyFile and the KeyName values are both specified, the +// following processing occurs: +// (1) If the KeyName can be found in the CSP, that key is used. +// (2) If the KeyName does not exist and the KeyFile does exist, the key +// in the KeyFile is installed into the CSP and used. +// (*) In order to create a KeyFile, you can use the sn.exe (Strong Name) utility. +// When specifying the KeyFile, the location of the KeyFile should be +// relative to the project directory. +// (*) Delay Signing is an advanced option - see the Microsoft CLR Framework +// documentation for more information on this. +// +//[assembly:AssemblyDelaySignAttribute(false)]; +//[assembly:AssemblyKeyFileAttribute("")]; +//[assembly:AssemblyKeyNameAttribute("")]; + +[assembly:ComVisible(false)]; + diff --git a/Chapter10/ToolStripEx/Form1.h b/Chapter10/ToolStripEx/Form1.h new file mode 100644 index 0000000..80d912d --- /dev/null +++ b/Chapter10/ToolStripEx/Form1.h @@ -0,0 +1,167 @@ +#pragma once + + +namespace ToolStripEx +{ + using namespace System; + using namespace System::ComponentModel; + using namespace System::Collections; + using namespace System::Windows::Forms; + using namespace System::Data; + using namespace System::Drawing; + + public ref class Form1 : public System::Windows::Forms::Form + { + public: + Form1(void) + { + InitializeComponent(); + } + + protected: + ~Form1() + { + if (components) + { + delete components; + } + } + + private: + System::Windows::Forms::Label^ lbOutput; + System::Windows::Forms::ToolStrip^ toolStrip; + System::Windows::Forms::ToolStripButton^ tsbnHappy; + System::Windows::Forms::ToolStripButton^ tsbnSad; + System::Windows::Forms::ToolStripSeparator^ Sep1; + System::Windows::Forms::ToolStripLabel^ Label; + System::Windows::Forms::ToolStripTextBox^ tstbName; + System::Windows::Forms::ToolStripContainer^ toolStripContainer1; + + + + + System::ComponentModel::Container ^components; + +#pragma region Windows Form Designer generated code + + void InitializeComponent(void) + { + System::ComponentModel::ComponentResourceManager^ resources = (gcnew System::ComponentModel::ComponentResourceManager(Form1::typeid)); + this->lbOutput = (gcnew System::Windows::Forms::Label()); + this->toolStrip = (gcnew System::Windows::Forms::ToolStrip()); + this->tsbnHappy = (gcnew System::Windows::Forms::ToolStripButton()); + this->tsbnSad = (gcnew System::Windows::Forms::ToolStripButton()); + this->Sep1 = (gcnew System::Windows::Forms::ToolStripSeparator()); + this->Label = (gcnew System::Windows::Forms::ToolStripLabel()); + this->tstbName = (gcnew System::Windows::Forms::ToolStripTextBox()); + this->toolStripContainer1 = (gcnew System::Windows::Forms::ToolStripContainer()); + this->toolStrip->SuspendLayout(); + this->toolStripContainer1->ContentPanel->SuspendLayout(); + this->toolStripContainer1->TopToolStripPanel->SuspendLayout(); + this->toolStripContainer1->SuspendLayout(); + this->SuspendLayout(); + // + // lbOutput + // + this->lbOutput->AutoSize = true; + this->lbOutput->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 8.25F, System::Drawing::FontStyle::Bold, System::Drawing::GraphicsUnit::Point, + static_cast(0))); + this->lbOutput->Location = System::Drawing::Point(47, 42); + this->lbOutput->Name = L"lbOutput"; + this->lbOutput->Size = System::Drawing::Size(208, 13); + this->lbOutput->TabIndex = 7; + this->lbOutput->Text = L"Enter a name then click an emotion"; + // + // toolStrip + // + this->toolStrip->Dock = System::Windows::Forms::DockStyle::None; + this->toolStrip->Items->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^ >(5) {this->tsbnHappy, this->tsbnSad, + this->Sep1, this->Label, this->tstbName}); + this->toolStrip->Location = System::Drawing::Point(0, 0); + this->toolStrip->Name = L"toolStrip"; + this->toolStrip->Size = System::Drawing::Size(300, 25); + this->toolStrip->Stretch = true; + this->toolStrip->TabIndex = 6; + this->toolStrip->Text = L"toolStrip1"; + // + // tsbnHappy + // + this->tsbnHappy->Image = (cli::safe_cast(resources->GetObject(L"tsbnHappy.Image"))); + this->tsbnHappy->Name = L"tsbnHappy"; + this->tsbnHappy->Size = System::Drawing::Size(58, 22); + this->tsbnHappy->Text = L"Happy"; + this->tsbnHappy->ToolTipText = L"a happy camper"; + this->tsbnHappy->Click += gcnew System::EventHandler(this, &Form1::tsbn_Click); + // + // tsbnSad + // + this->tsbnSad->Image = (cli::safe_cast(resources->GetObject(L"tsbnSad.Image"))); + this->tsbnSad->Name = L"tsbnSad"; + this->tsbnSad->Size = System::Drawing::Size(45, 22); + this->tsbnSad->Text = L"Sad"; + this->tsbnSad->ToolTipText = L"major gloomy"; + this->tsbnSad->Click += gcnew System::EventHandler(this, &Form1::tsbn_Click); + // + // Sep1 + // + this->Sep1->Name = L"Sep1"; + this->Sep1->Size = System::Drawing::Size(6, 25); + // + // Label + // + this->Label->Name = L"Label"; + this->Label->Size = System::Drawing::Size(34, 22); + this->Label->Text = L"Name"; + // + // tstbName + // + this->tstbName->Name = L"tstbName"; + this->tstbName->Size = System::Drawing::Size(92, 25); + this->tstbName->Text = L"Computer"; + // + // toolStripContainer1 + // + // + // toolStripContainer1.ContentPanel + // + this->toolStripContainer1->ContentPanel->Controls->Add(this->lbOutput); + this->toolStripContainer1->ContentPanel->Size = System::Drawing::Size(300, 105); + this->toolStripContainer1->Location = System::Drawing::Point(0, 0); + this->toolStripContainer1->Name = L"toolStripContainer1"; + this->toolStripContainer1->Size = System::Drawing::Size(300, 130); + this->toolStripContainer1->TabIndex = 8; + this->toolStripContainer1->Text = L"toolStripContainer1"; + // + // toolStripContainer1.TopToolStripPanel + // + this->toolStripContainer1->TopToolStripPanel->Controls->Add(this->toolStrip); + // + // Form1 + // + this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Inherit; + this->ClientSize = System::Drawing::Size(300, 129); + this->Controls->Add(this->toolStripContainer1); + this->Name = L"Form1"; + this->Text = L"Emotional Tool Strip"; + this->toolStrip->ResumeLayout(false); + this->toolStrip->PerformLayout(); + this->toolStripContainer1->ContentPanel->ResumeLayout(false); + this->toolStripContainer1->ContentPanel->PerformLayout(); + this->toolStripContainer1->TopToolStripPanel->ResumeLayout(false); + this->toolStripContainer1->TopToolStripPanel->PerformLayout(); + this->toolStripContainer1->ResumeLayout(false); + this->toolStripContainer1->PerformLayout(); + this->ResumeLayout(false); + + } +#pragma endregion + + private: + System::Void tsbn_Click(System::Object^ sender, System::EventArgs^ e) + { + this->lbOutput->Text = String::Format("{0} is {1}!", tstbName->Text, ((ToolStripButton^)sender)->ToolTipText); + } + }; +} + + diff --git a/Chapter10/ToolStripEx/Form1.resx b/Chapter10/ToolStripEx/Form1.resx new file mode 100644 index 0000000..fa0a78a --- /dev/null +++ b/Chapter10/ToolStripEx/Form1.resx @@ -0,0 +1,142 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 17, 17 + + + + + iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8 + YQUAAAAgY0hSTQAAeiYAAICEAAD6AAAAgOgAAHUwAADqYAAAOpgAABdwnLpRPAAAAH1JREFUOE/Nk0sO + wCAIROvNvTkNRizg8FnWhA06T4RxPHhRkB9B/qRZSEQ4eG8H5IRCD0SQtlhgHmIAUqo7jM6sp1y3dwAM + lyp+CIjGGE3jak7mA70He1AZCQHMJLbFYGPn/CZW+WBBdWixHqH2dNuN6X+oepCJTTX+CZHwBRkr1T3o + ssMyAAAAAElFTkSuQmCC + + + + + iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8 + YQUAAAAgY0hSTQAAeiYAAICEAAD6AAAAgOgAAHUwAADqYAAAOpgAABdwnLpRPAAAAHxJREFUOE/Nk0sO + wCAIROvNvTmNRijiTCFd1YQNwuPfLvyE6BvRm3o4igiW8bcEcqhjBCJI2VlhEbIBNNVgjGxmKUf0CmDA + NYsfAtgY2TSOEnq3+rTOuVglgDpz46fpfpSWRbaJ6R58BcB9SG4C30OWwdsxeaLv/jaJGPYGZLLVPX6l + YeIAAAAASUVORK5CYII= + + + \ No newline at end of file diff --git a/Chapter10/ToolStripEx/ToolStripEx.cpp b/Chapter10/ToolStripEx/ToolStripEx.cpp new file mode 100644 index 0000000..06a3ccd --- /dev/null +++ b/Chapter10/ToolStripEx/ToolStripEx.cpp @@ -0,0 +1,16 @@ +// ToolStripEx.cpp : main project file. + +#include "stdafx.h" +#include "Form1.h" + +using namespace ToolStripEx; + +[STAThreadAttribute] +int main(array ^args) +{ + // Enabling Windows XP visual effects before any controls are created + Application::EnableVisualStyles(); + // Create the main window and run it + Application::Run(gcnew Form1()); + return 0; +} diff --git a/Chapter10/ToolStripEx/ToolStripEx.vcproj b/Chapter10/ToolStripEx/ToolStripEx.vcproj new file mode 100644 index 0000000..1d9a2d4 --- /dev/null +++ b/Chapter10/ToolStripEx/ToolStripEx.vcproj @@ -0,0 +1,256 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Chapter10/ToolStripEx/resource.h b/Chapter10/ToolStripEx/resource.h new file mode 100644 index 0000000..d5ac7c4 --- /dev/null +++ b/Chapter10/ToolStripEx/resource.h @@ -0,0 +1,3 @@ +//{{NO_DEPENDENCIES}} +// Microsoft Visual C++ generated include file. +// Used by app.rc diff --git a/Chapter10/ToolStripEx/stdafx.cpp b/Chapter10/ToolStripEx/stdafx.cpp new file mode 100644 index 0000000..77a792b --- /dev/null +++ b/Chapter10/ToolStripEx/stdafx.cpp @@ -0,0 +1,7 @@ +// stdafx.cpp : source file that includes just the standard includes +// ToolStripEx.pch will be the pre-compiled header +// stdafx.obj will contain the pre-compiled type information + +#include "stdafx.h" + + diff --git a/Chapter10/ToolStripEx/stdafx.h b/Chapter10/ToolStripEx/stdafx.h new file mode 100644 index 0000000..46bef73 --- /dev/null +++ b/Chapter10/ToolStripEx/stdafx.h @@ -0,0 +1,6 @@ +// stdafx.h : include file for standard system include files, +// or project specific include files that are used frequently, but +// are changed infrequently +#pragma once + +// TODO: reference additional headers your program requires here diff --git a/Chapter10/TreeViewEx/AssemblyInfo.cpp b/Chapter10/TreeViewEx/AssemblyInfo.cpp new file mode 100644 index 0000000..1ddae91 --- /dev/null +++ b/Chapter10/TreeViewEx/AssemblyInfo.cpp @@ -0,0 +1,63 @@ +#include "stdafx.h" + +using namespace System::Reflection; +using namespace System::Runtime::CompilerServices; +using namespace System::Runtime::InteropServices; + +// +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +// +[assembly:AssemblyTitleAttribute("TreeViewEx")]; +[assembly:AssemblyDescriptionAttribute("")]; +[assembly:AssemblyConfigurationAttribute("")]; +[assembly:AssemblyCompanyAttribute("")]; +[assembly:AssemblyProductAttribute("TreeViewEx")]; +[assembly:AssemblyCopyrightAttribute("Copyright © 2005")]; +[assembly:AssemblyTrademarkAttribute("")]; +[assembly:AssemblyCultureAttribute("")]; + +// +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the value or you can default the Revision and Build Numbers +// by using the '*' as shown below: + +[assembly:AssemblyVersionAttribute("1.0.*")]; + +// +// In order to sign your assembly you must specify a key to use. Refer to the +// Microsoft CLR Framework documentation for more information on assembly signing. +// +// You can use the attributes below to control which key is used for signing. +// You can also use the project property page for signing under Common Properties +// to set the same information. +// +// Notes: +// (*) If no key is specified, the assembly is not signed. +// (*) KeyName refers to a key that has been installed in the Crypto Service +// Provider (CSP) on your machine. KeyFile refers to a file which contains +// a key. +// (*) If the KeyFile and the KeyName values are both specified, the +// following processing occurs: +// (1) If the KeyName can be found in the CSP, that key is used. +// (2) If the KeyName does not exist and the KeyFile does exist, the key +// in the KeyFile is installed into the CSP and used. +// (*) In order to create a KeyFile, you can use the sn.exe (Strong Name) utility. +// When specifying the KeyFile, the location of the KeyFile should be +// relative to the project directory. +// (*) Delay Signing is an advanced option - see the Microsoft CLR Framework +// documentation for more information on this. +// +//[assembly:AssemblyDelaySignAttribute(false)]; +//[assembly:AssemblyKeyFileAttribute("")]; +//[assembly:AssemblyKeyNameAttribute("")]; + +[assembly:ComVisible(false)]; + diff --git a/Chapter10/TreeViewEx/Form1.h b/Chapter10/TreeViewEx/Form1.h new file mode 100644 index 0000000..04dd289 --- /dev/null +++ b/Chapter10/TreeViewEx/Form1.h @@ -0,0 +1,141 @@ +#pragma once + +namespace TreeViewEx +{ + using namespace System; + using namespace System::ComponentModel; + using namespace System::Collections; + using namespace System::Windows::Forms; + using namespace System::Data; + using namespace System::Drawing; + + public ref class Form1 : public System::Windows::Forms::Form + { + public: + Form1(void) + { + InitializeComponent(); + } + + protected: + ~Form1() + { + if (components) + { + delete components; + } + } + + private: + System::Windows::Forms::TreeView^ tView; + System::Windows::Forms::ImageList^ imFolders; + System::ComponentModel::IContainer^ components; + +#pragma region Windows Form Designer generated code + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + void InitializeComponent(void) + { + this->components = (gcnew System::ComponentModel::Container()); + System::Windows::Forms::TreeNode^ treeNode1 = + (gcnew System::Windows::Forms::TreeNode(L"")); + System::Windows::Forms::TreeNode^ treeNode2 = + (gcnew System::Windows::Forms::TreeNode( + L"Root Node A", 0, 1, + gcnew cli::array< System::Windows::Forms::TreeNode^ >(1) + {treeNode1})); + System::Windows::Forms::TreeNode^ treeNode3 = + (gcnew System::Windows::Forms::TreeNode(L"")); + System::Windows::Forms::TreeNode^ treeNode4 = + (gcnew System::Windows::Forms::TreeNode( + L"Root Node B", 0, 1, + gcnew cli::array< System::Windows::Forms::TreeNode^ >(1) + {treeNode3})); + System::ComponentModel::ComponentResourceManager^ resources = + (gcnew System::ComponentModel::ComponentResourceManager(Form1::typeid)); + this->tView = (gcnew System::Windows::Forms::TreeView()); + this->imFolders = + (gcnew System::Windows::Forms::ImageList(this->components)); + this->SuspendLayout(); + // + // tView + // + this->tView->Dock = System::Windows::Forms::DockStyle::Fill; + this->tView->ImageIndex = 0; + this->tView->ImageList = this->imFolders; + this->tView->LabelEdit = true; + this->tView->Location = System::Drawing::Point(0, 0); + this->tView->Name = L"tView"; + treeNode1->Name = L"Node1"; + treeNode1->Text = L""; + treeNode2->ImageIndex = 0; + treeNode2->Name = L"Node0"; + treeNode2->SelectedImageIndex = 1; + treeNode2->Text = L"Root Node A"; + treeNode3->Name = L"Node3"; + treeNode3->Text = L""; + treeNode4->ImageIndex = 0; + treeNode4->Name = L"Node2"; + treeNode4->SelectedImageIndex = 1; + treeNode4->Text = L"Root Node B"; + this->tView->Nodes->AddRange( + gcnew cli::array< System::Windows::Forms::TreeNode^ >(2) + {treeNode2, treeNode4}); + this->tView->SelectedImageIndex = 1; + this->tView->Size = System::Drawing::Size(194, 481); + this->tView->TabIndex = 0; + this->tView->BeforeExpand += + gcnew System::Windows::Forms::TreeViewCancelEventHandler(this, + &Form1::tView_BeforeExpand); + // + // imFolders + // + this->imFolders->ImageStream = + (cli::safe_cast + (resources->GetObject(L"imFolders.ImageStream"))); + this->imFolders->Images->SetKeyName(0, L"CLSDFOLD.ICO"); + this->imFolders->Images->SetKeyName(1, L"OPENFOLD.ICO"); + // + // Form1 + // + this->AutoScaleDimensions = System::Drawing::SizeF(6, 13); + this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font; + this->ClientSize = System::Drawing::Size(194, 481); + this->Controls->Add(this->tView); + this->Name = L"Form1"; + this->Text = L"Tree View Example"; + this->ResumeLayout(false); + + } +#pragma endregion + private: + System::Void tView_BeforeExpand(System::Object^ sender, + System::Windows::Forms::TreeViewCancelEventArgs^ e) + { + // Already expanded before? + if (e->Node->Nodes->Count > 1) + return; // Already expanded + else if (e->Node->Nodes->Count == 1) + { + if (e->Node->Nodes[0]->Text->Equals("")) + e->Node->Nodes->RemoveAt(0); // Node ready for expanding + else + return; // Already expanded but only one sub node + } + // Randomly expand the Node + Random ^rand = gcnew Random(); + int rnd = rand->Next(1,5); + for (int i = 0; i < rnd; i++) // Randon number of sub nodes + { + TreeNode ^stn = + gcnew TreeNode(String::Format("Sub Node {0}", i+1), 0, 1); + e->Node->Nodes->Add(stn); + + if (rand->Next(2) == 1) // Has sub sub-nodes + stn->Nodes->Add(gcnew TreeNode("", 0, 1)); + } + } + }; +} \ No newline at end of file diff --git a/Chapter10/TreeViewEx/Form1.resx b/Chapter10/TreeViewEx/Form1.resx new file mode 100644 index 0000000..3febece --- /dev/null +++ b/Chapter10/TreeViewEx/Form1.resx @@ -0,0 +1,167 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 17, 17 + + + + AAEAAAD/////AQAAAAAAAAAMAgAAAFdTeXN0ZW0uV2luZG93cy5Gb3JtcywgVmVyc2lvbj0yLjAuMC4w + LCBDdWx0dXJlPW5ldXRyYWwsIFB1YmxpY0tleVRva2VuPWI3N2E1YzU2MTkzNGUwODkFAQAAACZTeXN0 + ZW0uV2luZG93cy5Gb3Jtcy5JbWFnZUxpc3RTdHJlYW1lcgEAAAAERGF0YQcCAgAAAAkDAAAADwMAAAAs + CQAAAk1TRnQBSQFMAgEBAgEAAQQBAAEEAQABEAEAARABAAT/AQkBAAj/AUIBTQE2AQQGAAE2AQQCAAEo + AwABQAMAARADAAEBAQABCAYAAQQYAAGAAgABgAMAAoABAAGAAwABgAEAAYABAAKAAgADwAEAAcAB3AHA + AQAB8AHKAaYBAAEzBQABMwEAATMBAAEzAQACMwIAAxYBAAMcAQADIgEAAykBAANVAQADTQEAA0IBAAM5 + AQABgAF8Af8BAAJQAf8BAAGTAQAB1gEAAf8B7AHMAQABxgHWAe8BAAHWAucBAAGQAakBrQIAAf8BMwMA + AWYDAAGZAwABzAIAATMDAAIzAgABMwFmAgABMwGZAgABMwHMAgABMwH/AgABZgMAAWYBMwIAAmYCAAFm + AZkCAAFmAcwCAAFmAf8CAAGZAwABmQEzAgABmQFmAgACmQIAAZkBzAIAAZkB/wIAAcwDAAHMATMCAAHM + AWYCAAHMAZkCAALMAgABzAH/AgAB/wFmAgAB/wGZAgAB/wHMAQABMwH/AgAB/wEAATMBAAEzAQABZgEA + ATMBAAGZAQABMwEAAcwBAAEzAQAB/wEAAf8BMwIAAzMBAAIzAWYBAAIzAZkBAAIzAcwBAAIzAf8BAAEz + AWYCAAEzAWYBMwEAATMCZgEAATMBZgGZAQABMwFmAcwBAAEzAWYB/wEAATMBmQIAATMBmQEzAQABMwGZ + AWYBAAEzApkBAAEzAZkBzAEAATMBmQH/AQABMwHMAgABMwHMATMBAAEzAcwBZgEAATMBzAGZAQABMwLM + AQABMwHMAf8BAAEzAf8BMwEAATMB/wFmAQABMwH/AZkBAAEzAf8BzAEAATMC/wEAAWYDAAFmAQABMwEA + AWYBAAFmAQABZgEAAZkBAAFmAQABzAEAAWYBAAH/AQABZgEzAgABZgIzAQABZgEzAWYBAAFmATMBmQEA + AWYBMwHMAQABZgEzAf8BAAJmAgACZgEzAQADZgEAAmYBmQEAAmYBzAEAAWYBmQIAAWYBmQEzAQABZgGZ + AWYBAAFmApkBAAFmAZkBzAEAAWYBmQH/AQABZgHMAgABZgHMATMBAAFmAcwBmQEAAWYCzAEAAWYBzAH/ + AQABZgH/AgABZgH/ATMBAAFmAf8BmQEAAWYB/wHMAQABzAEAAf8BAAH/AQABzAEAApkCAAGZATMBmQEA + AZkBAAGZAQABmQEAAcwBAAGZAwABmQIzAQABmQEAAWYBAAGZATMBzAEAAZkBAAH/AQABmQFmAgABmQFm + ATMBAAGZATMBZgEAAZkBZgGZAQABmQFmAcwBAAGZATMB/wEAApkBMwEAApkBZgEAA5kBAAKZAcwBAAKZ + Af8BAAGZAcwCAAGZAcwBMwEAAWYBzAFmAQABmQHMAZkBAAGZAswBAAGZAcwB/wEAAZkB/wIAAZkB/wEz + AQABmQHMAWYBAAGZAf8BmQEAAZkB/wHMAQABmQL/AQABzAMAAZkBAAEzAQABzAEAAWYBAAHMAQABmQEA + AcwBAAHMAQABmQEzAgABzAIzAQABzAEzAWYBAAHMATMBmQEAAcwBMwHMAQABzAEzAf8BAAHMAWYCAAHM + AWYBMwEAAZkCZgEAAcwBZgGZAQABzAFmAcwBAAGZAWYB/wEAAcwBmQIAAcwBmQEzAQABzAGZAWYBAAHM + ApkBAAHMAZkBzAEAAcwBmQH/AQACzAIAAswBMwEAAswBZgEAAswBmQEAA8wBAALMAf8BAAHMAf8CAAHM + Af8BMwEAAZkB/wFmAQABzAH/AZkBAAHMAf8BzAEAAcwC/wEAAcwBAAEzAQAB/wEAAWYBAAH/AQABmQEA + AcwBMwIAAf8CMwEAAf8BMwFmAQAB/wEzAZkBAAH/ATMBzAEAAf8BMwH/AQAB/wFmAgAB/wFmATMBAAHM + AmYBAAH/AWYBmQEAAf8BZgHMAQABzAFmAf8BAAH/AZkCAAH/AZkBMwEAAf8BmQFmAQAB/wKZAQAB/wGZ + AcwBAAH/AZkB/wEAAf8BzAIAAf8BzAEzAQAB/wHMAWYBAAH/AcwBmQEAAf8CzAEAAf8BzAH/AQAC/wEz + AQABzAH/AWYBAAL/AZkBAAL/AcwBAAJmAf8BAAFmAf8BZgEAAWYC/wEAAf8CZgEAAf8BZgH/AQAC/wFm + AQABIQEAAaUBAANfAQADdwEAA4YBAAOWAQADywEAA7IBAAPXAQAD3QEAA+MBAAPqAQAD8QEAA/gBAAHw + AfsB/wEAAaQCoAEAA4ADAAH/AgAB/wMAAv8BAAH/AwAB/wEAAf8BAAL/AgAD/8EADuwEAAzsIgAB7AH/ + AfsBBwH7AQcB+wEHAfsBBwH7AQcB+wHsBAAB7AH/AfsBBwH7AQcB+wEHAfsBBwH7AewiAAHsAf8BBwH7 + AQcB+wEHAfsBBwH7AQcB+wEHAewDAAHsAf8B+wEHAfsBBwH7AQcB+wEHAfsBBwEAAewhAAHsAf8B+wEH + AfsBBwH7AQcB+wEHAfsBBwH7AewDAAHsAf8BBwH7AQcB+wEHAfsBBwH7AQcB7AEAAewhAAHsAf8BBwH7 + AQcB+wEHAfsBBwH7AQcB+wEHAewCAAHsAf8BBwH7AQcB+wEHAfsBBwH7AQcB+wEAAuwhAAHsAf8B+wEH + AfsBBwH7AQcB+wEHAfsBBwH7AewCAAHsCv8B7AEAAQcB7CEAAewB/wEHAfsBBwH7AQcB+wEHAfsBBwH7 + AQcB7AIADewB+wHsIQAB7AH/AfsBBwH7AQcB+wEHAfsBBwH7AQcB+wHsAwAB7AH/AQcB+wEHAfsBBwH7 + AQcB+wEHAfsBBwHsIQAB7Az/AewDAAHsAf8B+wEHAfsBBwH7AQcF/wHsIQAB7AEHAfsBBwH7AQcB+wEH + BuwDAAHsAf8BBwH7AQcB+wEHAf8G7CIAAewBBwH7AQcB+wEHAewKAAHsBf8B7CkABewMAAXsaAABQgFN + AT4HAAE+AwABKAMAAUADAAEQAwABAQEAAQEFAAGAFwAD/wEABP8EAAT/BAABgAEBAeAGAAEBAcAGAAEB + AcAGAAEBAYAGAAEBAYAGAAEBBwABAQcAAQEHAAEBAYAGAAEBAYAGAAEDAYABAQQAAYAB/wHAAX8EAAHB + Af8B4AH/BAAE/wQACw== + + + \ No newline at end of file diff --git a/Chapter10/TreeViewEx/Images/CLSDFOLD.ICO b/Chapter10/TreeViewEx/Images/CLSDFOLD.ICO new file mode 100644 index 0000000..adfd173 Binary files /dev/null and b/Chapter10/TreeViewEx/Images/CLSDFOLD.ICO differ diff --git a/Chapter10/TreeViewEx/Images/OPENFOLD.ICO b/Chapter10/TreeViewEx/Images/OPENFOLD.ICO new file mode 100644 index 0000000..d36827b Binary files /dev/null and b/Chapter10/TreeViewEx/Images/OPENFOLD.ICO differ diff --git a/Chapter10/TreeViewEx/TreeViewEx.cpp b/Chapter10/TreeViewEx/TreeViewEx.cpp new file mode 100644 index 0000000..403f141 --- /dev/null +++ b/Chapter10/TreeViewEx/TreeViewEx.cpp @@ -0,0 +1,16 @@ +// TreeViewEx.cpp : main project file. + +#include "stdafx.h" +#include "Form1.h" + +using namespace TreeViewEx; + +[STAThreadAttribute] +int main(array ^args) +{ + // Enabling Windows XP visual effects before any controls are created + Application::EnableVisualStyles(); + // Create the main window and run it + Application::Run(gcnew Form1()); + return 0; +} diff --git a/Chapter10/TreeViewEx/TreeViewEx.vcproj b/Chapter10/TreeViewEx/TreeViewEx.vcproj new file mode 100644 index 0000000..f68c7ad --- /dev/null +++ b/Chapter10/TreeViewEx/TreeViewEx.vcproj @@ -0,0 +1,256 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Chapter10/TreeViewEx/resource.h b/Chapter10/TreeViewEx/resource.h new file mode 100644 index 0000000..d5ac7c4 --- /dev/null +++ b/Chapter10/TreeViewEx/resource.h @@ -0,0 +1,3 @@ +//{{NO_DEPENDENCIES}} +// Microsoft Visual C++ generated include file. +// Used by app.rc diff --git a/Chapter10/TreeViewEx/stdafx.cpp b/Chapter10/TreeViewEx/stdafx.cpp new file mode 100644 index 0000000..8dcebf1 --- /dev/null +++ b/Chapter10/TreeViewEx/stdafx.cpp @@ -0,0 +1,7 @@ +// stdafx.cpp : source file that includes just the standard includes +// TreeViewEx.pch will be the pre-compiled header +// stdafx.obj will contain the pre-compiled type information + +#include "stdafx.h" + + diff --git a/Chapter10/TreeViewEx/stdafx.h b/Chapter10/TreeViewEx/stdafx.h new file mode 100644 index 0000000..46bef73 --- /dev/null +++ b/Chapter10/TreeViewEx/stdafx.h @@ -0,0 +1,6 @@ +// stdafx.h : include file for standard system include files, +// or project specific include files that are used frequently, but +// are changed infrequently +#pragma once + +// TODO: reference additional headers your program requires here diff --git a/Chapter11/Chapter11.sln b/Chapter11/Chapter11.sln new file mode 100644 index 0000000..cf2e6de --- /dev/null +++ b/Chapter11/Chapter11.sln @@ -0,0 +1,134 @@ + +Microsoft Visual Studio Solution File, Format Version 9.00 +# Visual Studio 2005 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "HelloGDI", "HelloGDI\HelloGDI.vcproj", "{BD9DA4A5-D189-4FB4-AAA7-1DD2A740DCB6}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "OnPaintWhere", "OnPaintWhere\OnPaintWhere.vcproj", "{9E90B430-A308-40C4-B6D6-0C5C9EAB0535}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "HelloGDI_OnPaint", "HelloGDI_OnPaint\HelloGDI_OnPaint.vcproj", "{283072E8-6ED6-4A75-AEE2-744763E0ACFB}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "DisappearingCoords", "DisappearingCoords\DisappearingCoords.vcproj", "{4157C521-881D-44CA-902A-7AF609BC4A82}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "CorrectingCoords", "CorrectingCoords\CorrectingCoords.vcproj", "{F33F5E58-7F29-4FD1-8FC5-570E6E3BDBE1}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "NewUnitsOrigin", "NewUnitsOrigin\NewUnitsOrigin.vcproj", "{C82F3F5E-3F84-4E68-9142-B3B1352D0F23}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "InterOrUnion", "InterOrUnion\InterOrUnion.vcproj", "{1640CD24-A9DF-4E28-864E-8524EF68CB73}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "RegionEx", "RegionEx\RegionEx.vcproj", "{9E1C26F4-CE4C-4893-B955-2BAA6971CC76}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "StringRect", "StringRect\StringRect.vcproj", "{03092038-12FC-4CA4-B517-037F643F29AD}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "DownwardStringRect", "DownwardStringRect\DownwardStringRect.vcproj", "{07FA1D77-2BB4-42E0-9D62-6355EB697E25}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "FontsGalore", "FontsGalore\FontsGalore.vcproj", "{A4777E86-7DFF-417A-8470-2273056C3BFF}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "DrawingLines", "DrawingLines\DrawingLines.vcproj", "{D50CF418-4C67-4F4E-AFB8-B26C15CFD0FB}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "TextureBrushEx", "TextureBrushEx\TextureBrushEx.vcproj", "{6DDE2259-9932-4BA9-98CF-33A2BEB6B2EE}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "DrawImageEx", "DrawImageEx\DrawImageEx.vcproj", "{DC9D2C88-4F1E-43F7-9454-33959F51842E}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "HappyFace", "HappyFace\HappyFace.vcproj", "{F9840F0D-62E3-441A-ABD0-E0A5F4A0F56A}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ScrollingHappyFace", "ScrollingHappyFace\ScrollingHappyFace.vcproj", "{6D9E6F62-DA3F-470F-847E-D089BBBE47C0}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "OptimizedHappyFace", "OptimizedHappyFace\OptimizedHappyFace.vcproj", "{C26C7F38-200C-4535-8304-EA87B4EF16CC}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "SingleBuffering", "SingleBuffering\SingleBuffering.vcproj", "{D32071A7-6AC0-4ED7-BE57-CE11132823D7}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "DoubleBuffering", "DoubleBuffering\DoubleBuffering.vcproj", "{0AC75397-CD4F-4579-B3F0-E1D121B354FD}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "PrintHappyFace", "PrintHappyFace\PrintHappyFace.vcproj", "{7CEC43F0-0025-4B89-8470-5400D102532D}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Win32 = Debug|Win32 + Release|Win32 = Release|Win32 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {BD9DA4A5-D189-4FB4-AAA7-1DD2A740DCB6}.Debug|Win32.ActiveCfg = Debug|Win32 + {BD9DA4A5-D189-4FB4-AAA7-1DD2A740DCB6}.Debug|Win32.Build.0 = Debug|Win32 + {BD9DA4A5-D189-4FB4-AAA7-1DD2A740DCB6}.Release|Win32.ActiveCfg = Release|Win32 + {BD9DA4A5-D189-4FB4-AAA7-1DD2A740DCB6}.Release|Win32.Build.0 = Release|Win32 + {9E90B430-A308-40C4-B6D6-0C5C9EAB0535}.Debug|Win32.ActiveCfg = Debug|Win32 + {9E90B430-A308-40C4-B6D6-0C5C9EAB0535}.Debug|Win32.Build.0 = Debug|Win32 + {9E90B430-A308-40C4-B6D6-0C5C9EAB0535}.Release|Win32.ActiveCfg = Release|Win32 + {9E90B430-A308-40C4-B6D6-0C5C9EAB0535}.Release|Win32.Build.0 = Release|Win32 + {283072E8-6ED6-4A75-AEE2-744763E0ACFB}.Debug|Win32.ActiveCfg = Debug|Win32 + {283072E8-6ED6-4A75-AEE2-744763E0ACFB}.Debug|Win32.Build.0 = Debug|Win32 + {283072E8-6ED6-4A75-AEE2-744763E0ACFB}.Release|Win32.ActiveCfg = Release|Win32 + {283072E8-6ED6-4A75-AEE2-744763E0ACFB}.Release|Win32.Build.0 = Release|Win32 + {4157C521-881D-44CA-902A-7AF609BC4A82}.Debug|Win32.ActiveCfg = Debug|Win32 + {4157C521-881D-44CA-902A-7AF609BC4A82}.Debug|Win32.Build.0 = Debug|Win32 + {4157C521-881D-44CA-902A-7AF609BC4A82}.Release|Win32.ActiveCfg = Release|Win32 + {4157C521-881D-44CA-902A-7AF609BC4A82}.Release|Win32.Build.0 = Release|Win32 + {F33F5E58-7F29-4FD1-8FC5-570E6E3BDBE1}.Debug|Win32.ActiveCfg = Debug|Win32 + {F33F5E58-7F29-4FD1-8FC5-570E6E3BDBE1}.Debug|Win32.Build.0 = Debug|Win32 + {F33F5E58-7F29-4FD1-8FC5-570E6E3BDBE1}.Release|Win32.ActiveCfg = Release|Win32 + {F33F5E58-7F29-4FD1-8FC5-570E6E3BDBE1}.Release|Win32.Build.0 = Release|Win32 + {C82F3F5E-3F84-4E68-9142-B3B1352D0F23}.Debug|Win32.ActiveCfg = Debug|Win32 + {C82F3F5E-3F84-4E68-9142-B3B1352D0F23}.Debug|Win32.Build.0 = Debug|Win32 + {C82F3F5E-3F84-4E68-9142-B3B1352D0F23}.Release|Win32.ActiveCfg = Release|Win32 + {C82F3F5E-3F84-4E68-9142-B3B1352D0F23}.Release|Win32.Build.0 = Release|Win32 + {1640CD24-A9DF-4E28-864E-8524EF68CB73}.Debug|Win32.ActiveCfg = Debug|Win32 + {1640CD24-A9DF-4E28-864E-8524EF68CB73}.Debug|Win32.Build.0 = Debug|Win32 + {1640CD24-A9DF-4E28-864E-8524EF68CB73}.Release|Win32.ActiveCfg = Release|Win32 + {1640CD24-A9DF-4E28-864E-8524EF68CB73}.Release|Win32.Build.0 = Release|Win32 + {9E1C26F4-CE4C-4893-B955-2BAA6971CC76}.Debug|Win32.ActiveCfg = Debug|Win32 + {9E1C26F4-CE4C-4893-B955-2BAA6971CC76}.Debug|Win32.Build.0 = Debug|Win32 + {9E1C26F4-CE4C-4893-B955-2BAA6971CC76}.Release|Win32.ActiveCfg = Release|Win32 + {9E1C26F4-CE4C-4893-B955-2BAA6971CC76}.Release|Win32.Build.0 = Release|Win32 + {03092038-12FC-4CA4-B517-037F643F29AD}.Debug|Win32.ActiveCfg = Debug|Win32 + {03092038-12FC-4CA4-B517-037F643F29AD}.Debug|Win32.Build.0 = Debug|Win32 + {03092038-12FC-4CA4-B517-037F643F29AD}.Release|Win32.ActiveCfg = Release|Win32 + {03092038-12FC-4CA4-B517-037F643F29AD}.Release|Win32.Build.0 = Release|Win32 + {07FA1D77-2BB4-42E0-9D62-6355EB697E25}.Debug|Win32.ActiveCfg = Debug|Win32 + {07FA1D77-2BB4-42E0-9D62-6355EB697E25}.Debug|Win32.Build.0 = Debug|Win32 + {07FA1D77-2BB4-42E0-9D62-6355EB697E25}.Release|Win32.ActiveCfg = Release|Win32 + {07FA1D77-2BB4-42E0-9D62-6355EB697E25}.Release|Win32.Build.0 = Release|Win32 + {A4777E86-7DFF-417A-8470-2273056C3BFF}.Debug|Win32.ActiveCfg = Debug|Win32 + {A4777E86-7DFF-417A-8470-2273056C3BFF}.Debug|Win32.Build.0 = Debug|Win32 + {A4777E86-7DFF-417A-8470-2273056C3BFF}.Release|Win32.ActiveCfg = Release|Win32 + {A4777E86-7DFF-417A-8470-2273056C3BFF}.Release|Win32.Build.0 = Release|Win32 + {D50CF418-4C67-4F4E-AFB8-B26C15CFD0FB}.Debug|Win32.ActiveCfg = Debug|Win32 + {D50CF418-4C67-4F4E-AFB8-B26C15CFD0FB}.Debug|Win32.Build.0 = Debug|Win32 + {D50CF418-4C67-4F4E-AFB8-B26C15CFD0FB}.Release|Win32.ActiveCfg = Release|Win32 + {D50CF418-4C67-4F4E-AFB8-B26C15CFD0FB}.Release|Win32.Build.0 = Release|Win32 + {6DDE2259-9932-4BA9-98CF-33A2BEB6B2EE}.Debug|Win32.ActiveCfg = Debug|Win32 + {6DDE2259-9932-4BA9-98CF-33A2BEB6B2EE}.Debug|Win32.Build.0 = Debug|Win32 + {6DDE2259-9932-4BA9-98CF-33A2BEB6B2EE}.Release|Win32.ActiveCfg = Release|Win32 + {6DDE2259-9932-4BA9-98CF-33A2BEB6B2EE}.Release|Win32.Build.0 = Release|Win32 + {DC9D2C88-4F1E-43F7-9454-33959F51842E}.Debug|Win32.ActiveCfg = Debug|Win32 + {DC9D2C88-4F1E-43F7-9454-33959F51842E}.Debug|Win32.Build.0 = Debug|Win32 + {DC9D2C88-4F1E-43F7-9454-33959F51842E}.Release|Win32.ActiveCfg = Release|Win32 + {DC9D2C88-4F1E-43F7-9454-33959F51842E}.Release|Win32.Build.0 = Release|Win32 + {F9840F0D-62E3-441A-ABD0-E0A5F4A0F56A}.Debug|Win32.ActiveCfg = Debug|Win32 + {F9840F0D-62E3-441A-ABD0-E0A5F4A0F56A}.Debug|Win32.Build.0 = Debug|Win32 + {F9840F0D-62E3-441A-ABD0-E0A5F4A0F56A}.Release|Win32.ActiveCfg = Release|Win32 + {F9840F0D-62E3-441A-ABD0-E0A5F4A0F56A}.Release|Win32.Build.0 = Release|Win32 + {6D9E6F62-DA3F-470F-847E-D089BBBE47C0}.Debug|Win32.ActiveCfg = Debug|Win32 + {6D9E6F62-DA3F-470F-847E-D089BBBE47C0}.Debug|Win32.Build.0 = Debug|Win32 + {6D9E6F62-DA3F-470F-847E-D089BBBE47C0}.Release|Win32.ActiveCfg = Release|Win32 + {6D9E6F62-DA3F-470F-847E-D089BBBE47C0}.Release|Win32.Build.0 = Release|Win32 + {C26C7F38-200C-4535-8304-EA87B4EF16CC}.Debug|Win32.ActiveCfg = Debug|Win32 + {C26C7F38-200C-4535-8304-EA87B4EF16CC}.Debug|Win32.Build.0 = Debug|Win32 + {C26C7F38-200C-4535-8304-EA87B4EF16CC}.Release|Win32.ActiveCfg = Release|Win32 + {C26C7F38-200C-4535-8304-EA87B4EF16CC}.Release|Win32.Build.0 = Release|Win32 + {D32071A7-6AC0-4ED7-BE57-CE11132823D7}.Debug|Win32.ActiveCfg = Debug|Win32 + {D32071A7-6AC0-4ED7-BE57-CE11132823D7}.Debug|Win32.Build.0 = Debug|Win32 + {D32071A7-6AC0-4ED7-BE57-CE11132823D7}.Release|Win32.ActiveCfg = Release|Win32 + {D32071A7-6AC0-4ED7-BE57-CE11132823D7}.Release|Win32.Build.0 = Release|Win32 + {0AC75397-CD4F-4579-B3F0-E1D121B354FD}.Debug|Win32.ActiveCfg = Debug|Win32 + {0AC75397-CD4F-4579-B3F0-E1D121B354FD}.Debug|Win32.Build.0 = Debug|Win32 + {0AC75397-CD4F-4579-B3F0-E1D121B354FD}.Release|Win32.ActiveCfg = Release|Win32 + {0AC75397-CD4F-4579-B3F0-E1D121B354FD}.Release|Win32.Build.0 = Release|Win32 + {7CEC43F0-0025-4B89-8470-5400D102532D}.Debug|Win32.ActiveCfg = Debug|Win32 + {7CEC43F0-0025-4B89-8470-5400D102532D}.Debug|Win32.Build.0 = Debug|Win32 + {7CEC43F0-0025-4B89-8470-5400D102532D}.Release|Win32.ActiveCfg = Release|Win32 + {7CEC43F0-0025-4B89-8470-5400D102532D}.Release|Win32.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/Chapter11/Chapter11.suo b/Chapter11/Chapter11.suo new file mode 100644 index 0000000..166354c Binary files /dev/null and b/Chapter11/Chapter11.suo differ diff --git a/Chapter11/CorrectingCoords/AssemblyInfo.cpp b/Chapter11/CorrectingCoords/AssemblyInfo.cpp new file mode 100644 index 0000000..32012b9 --- /dev/null +++ b/Chapter11/CorrectingCoords/AssemblyInfo.cpp @@ -0,0 +1,35 @@ +#include "stdafx.h" + +using namespace System::Reflection; +using namespace System::Runtime::CompilerServices; +using namespace System::Runtime::InteropServices; + +// +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +// +[assembly:AssemblyTitleAttribute("CorrectingCoords")]; +[assembly:AssemblyDescriptionAttribute("")]; +[assembly:AssemblyConfigurationAttribute("")]; +[assembly:AssemblyCompanyAttribute("")]; +[assembly:AssemblyProductAttribute("CorrectingCoords")]; +[assembly:AssemblyCopyrightAttribute("Copyright (c) 2005")]; +[assembly:AssemblyTrademarkAttribute("")]; +[assembly:AssemblyCultureAttribute("")]; + +// +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the value or you can default the Revision and Build Numbers +// by using the '*' as shown below: + +[assembly:AssemblyVersionAttribute("1.0.*")]; + +[assembly:ComVisible(false)]; + diff --git a/Chapter11/CorrectingCoords/CorrectingCoords.cpp b/Chapter11/CorrectingCoords/CorrectingCoords.cpp new file mode 100644 index 0000000..9b17eaa --- /dev/null +++ b/Chapter11/CorrectingCoords/CorrectingCoords.cpp @@ -0,0 +1,16 @@ +// CorrectingCoords.cpp : main project file. + +#include "stdafx.h" +#include "Form1.h" + +using namespace CorrectingCoords; + +[STAThreadAttribute] +int main(array ^args) +{ + // Enabling Windows XP visual effects before any controls are created + Application::EnableVisualStyles(); + // Create the main window and run it + Application::Run(gcnew Form1()); + return 0; +} diff --git a/Chapter11/CorrectingCoords/CorrectingCoords.vcproj b/Chapter11/CorrectingCoords/CorrectingCoords.vcproj new file mode 100644 index 0000000..7d326b8 --- /dev/null +++ b/Chapter11/CorrectingCoords/CorrectingCoords.vcproj @@ -0,0 +1,250 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Chapter11/CorrectingCoords/Form1.h b/Chapter11/CorrectingCoords/Form1.h new file mode 100644 index 0000000..f800897 --- /dev/null +++ b/Chapter11/CorrectingCoords/Form1.h @@ -0,0 +1,75 @@ +#pragma once + + +namespace CorrectingCoords +{ + using namespace System; + using namespace System::ComponentModel; + using namespace System::Collections; + using namespace System::Windows::Forms; + using namespace System::Data; + using namespace System::Drawing; + + public ref class Form1 : public System::Windows::Forms::Form + { + public: + Form1(void) + { + InitializeComponent(); + coords = gcnew ArrayList(); // Instantiate coords array + } + + protected: + ~Form1() + { + if (components) + { + delete components; + } + } + + private: + System::ComponentModel::Container ^components; + ArrayList ^coords; + +#pragma region Windows Form Designer generated code + void InitializeComponent(void) + { + this->SuspendLayout(); + this->AutoScaleDimensions = System::Drawing::SizeF(6, 13); + this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font; + this->ClientSize = System::Drawing::Size(292, 273); + this->Name = L"Form1"; + this->Text = L"Click and see coords"; + this->Paint += + gcnew System::Windows::Forms::PaintEventHandler(this, + &Form1::Form1_Paint); + this->MouseDown += + gcnew System::Windows::Forms::MouseEventHandler(this, + &Form1::Form1_MouseDown); + this->ResumeLayout(false); + } +#pragma endregion + + private: + System::Void Form1_MouseDown(System::Object^ sender, + System::Windows::Forms::MouseEventArgs^ e) + { + coords->Add(Point(e->X, e->Y)); + Invalidate(); + } + + private: + System::Void Form1_Paint(System::Object^ sender, + System::Windows::Forms::PaintEventArgs^ e) + { + for each (Point^ p in coords) + { + e->Graphics->DrawString(String::Format("({0},{1})",p->X,p->Y), + gcnew Drawing::Font("Courier New", 8), + Brushes::Black, (Single)p->X, (Single)p->Y); + } + } + }; +} + diff --git a/Chapter11/CorrectingCoords/Form1.resx b/Chapter11/CorrectingCoords/Form1.resx new file mode 100644 index 0000000..de824e1 --- /dev/null +++ b/Chapter11/CorrectingCoords/Form1.resx @@ -0,0 +1,110 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Chapter11/CorrectingCoords/stdafx.cpp b/Chapter11/CorrectingCoords/stdafx.cpp new file mode 100644 index 0000000..9f3ffe3 --- /dev/null +++ b/Chapter11/CorrectingCoords/stdafx.cpp @@ -0,0 +1,7 @@ +// stdafx.cpp : source file that includes just the standard includes +// CorrectingCoords.pch will be the pre-compiled header +// stdafx.obj will contain the pre-compiled type information + +#include "stdafx.h" + + diff --git a/Chapter11/CorrectingCoords/stdafx.h b/Chapter11/CorrectingCoords/stdafx.h new file mode 100644 index 0000000..46bef73 --- /dev/null +++ b/Chapter11/CorrectingCoords/stdafx.h @@ -0,0 +1,6 @@ +// stdafx.h : include file for standard system include files, +// or project specific include files that are used frequently, but +// are changed infrequently +#pragma once + +// TODO: reference additional headers your program requires here diff --git a/Chapter11/DisappearingCoords/AssemblyInfo.cpp b/Chapter11/DisappearingCoords/AssemblyInfo.cpp new file mode 100644 index 0000000..72600bc --- /dev/null +++ b/Chapter11/DisappearingCoords/AssemblyInfo.cpp @@ -0,0 +1,35 @@ +#include "stdafx.h" + +using namespace System::Reflection; +using namespace System::Runtime::CompilerServices; +using namespace System::Runtime::InteropServices; + +// +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +// +[assembly:AssemblyTitleAttribute("DisappearingCoords")]; +[assembly:AssemblyDescriptionAttribute("")]; +[assembly:AssemblyConfigurationAttribute("")]; +[assembly:AssemblyCompanyAttribute("")]; +[assembly:AssemblyProductAttribute("DisappearingCoords")]; +[assembly:AssemblyCopyrightAttribute("Copyright (c) 2005")]; +[assembly:AssemblyTrademarkAttribute("")]; +[assembly:AssemblyCultureAttribute("")]; + +// +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the value or you can default the Revision and Build Numbers +// by using the '*' as shown below: + +[assembly:AssemblyVersionAttribute("1.0.*")]; + +[assembly:ComVisible(false)]; + diff --git a/Chapter11/DisappearingCoords/DisappearingCoords.cpp b/Chapter11/DisappearingCoords/DisappearingCoords.cpp new file mode 100644 index 0000000..a5cc5a8 --- /dev/null +++ b/Chapter11/DisappearingCoords/DisappearingCoords.cpp @@ -0,0 +1,16 @@ +// DisappearingCoords.cpp : main project file. + +#include "stdafx.h" +#include "Form1.h" + +using namespace DisappearingCoords; + +[STAThreadAttribute] +int main(array ^args) +{ + // Enabling Windows XP visual effects before any controls are created + Application::EnableVisualStyles(); + // Create the main window and run it + Application::Run(gcnew Form1()); + return 0; +} diff --git a/Chapter11/DisappearingCoords/DisappearingCoords.vcproj b/Chapter11/DisappearingCoords/DisappearingCoords.vcproj new file mode 100644 index 0000000..c31f139 --- /dev/null +++ b/Chapter11/DisappearingCoords/DisappearingCoords.vcproj @@ -0,0 +1,250 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Chapter11/DisappearingCoords/Form1.h b/Chapter11/DisappearingCoords/Form1.h new file mode 100644 index 0000000..89c32f6 --- /dev/null +++ b/Chapter11/DisappearingCoords/Form1.h @@ -0,0 +1,63 @@ +#pragma once + +namespace DisappearingCoords +{ + using namespace System; + using namespace System::ComponentModel; + using namespace System::Collections; + using namespace System::Windows::Forms; + using namespace System::Data; + using namespace System::Drawing; + + public ref class Form1 : public System::Windows::Forms::Form + { + public: + Form1(void) + { + InitializeComponent(); + } + + protected: + ~Form1() + { + if (components) + { + delete components; + } + } + + private: + System::ComponentModel::Container ^components; + +#pragma region Windows Form Designer generated code + void InitializeComponent(void) + { + this->SuspendLayout(); + this->AutoScaleDimensions = System::Drawing::SizeF(6, 13); + this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font; + this->ClientSize = System::Drawing::Size(292, 273); + this->Name = L"Form1"; + this->Text = L"Click and see coords"; + this->MouseDown += + gcnew System::Windows::Forms::MouseEventHandler(this, + &Form1::Form1_MouseDown); + this->ResumeLayout(false); + + } +#pragma endregion + + private: + System::Void Form1_MouseDown(System::Object^ sender, + System::Windows::Forms::MouseEventArgs^ e) + { + Graphics ^g = this->CreateGraphics(); + g->DrawString(String::Format("({0},{1})", e->X, e->Y), + gcnew Drawing::Font("Courier New", 8), + Brushes::Black, (Single)e->X, (Single)e->Y); + + delete g; // we delete of the Graphics object because we + // created it with the CreateGraphics() method. + } + }; +} + diff --git a/Chapter11/DisappearingCoords/Form1.resx b/Chapter11/DisappearingCoords/Form1.resx new file mode 100644 index 0000000..de824e1 --- /dev/null +++ b/Chapter11/DisappearingCoords/Form1.resx @@ -0,0 +1,110 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Chapter11/DisappearingCoords/stdafx.cpp b/Chapter11/DisappearingCoords/stdafx.cpp new file mode 100644 index 0000000..b5c6217 --- /dev/null +++ b/Chapter11/DisappearingCoords/stdafx.cpp @@ -0,0 +1,7 @@ +// stdafx.cpp : source file that includes just the standard includes +// DisappearingCoords.pch will be the pre-compiled header +// stdafx.obj will contain the pre-compiled type information + +#include "stdafx.h" + + diff --git a/Chapter11/DisappearingCoords/stdafx.h b/Chapter11/DisappearingCoords/stdafx.h new file mode 100644 index 0000000..46bef73 --- /dev/null +++ b/Chapter11/DisappearingCoords/stdafx.h @@ -0,0 +1,6 @@ +// stdafx.h : include file for standard system include files, +// or project specific include files that are used frequently, but +// are changed infrequently +#pragma once + +// TODO: reference additional headers your program requires here diff --git a/Chapter11/DoubleBuffering/AssemblyInfo.cpp b/Chapter11/DoubleBuffering/AssemblyInfo.cpp new file mode 100644 index 0000000..0b0ad72 --- /dev/null +++ b/Chapter11/DoubleBuffering/AssemblyInfo.cpp @@ -0,0 +1,35 @@ +#include "stdafx.h" + +using namespace System::Reflection; +using namespace System::Runtime::CompilerServices; +using namespace System::Runtime::InteropServices; + +// +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +// +[assembly:AssemblyTitleAttribute("DoubleBuffering")]; +[assembly:AssemblyDescriptionAttribute("")]; +[assembly:AssemblyConfigurationAttribute("")]; +[assembly:AssemblyCompanyAttribute("")]; +[assembly:AssemblyProductAttribute("DoubleBuffering")]; +[assembly:AssemblyCopyrightAttribute("Copyright (c) 2005")]; +[assembly:AssemblyTrademarkAttribute("")]; +[assembly:AssemblyCultureAttribute("")]; + +// +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the value or you can default the Revision and Build Numbers +// by using the '*' as shown below: + +[assembly:AssemblyVersionAttribute("1.0.*")]; + +[assembly:ComVisible(false)]; + diff --git a/Chapter11/DoubleBuffering/DoubleBuffering.cpp b/Chapter11/DoubleBuffering/DoubleBuffering.cpp new file mode 100644 index 0000000..d6cc8f4 --- /dev/null +++ b/Chapter11/DoubleBuffering/DoubleBuffering.cpp @@ -0,0 +1,16 @@ +// DoubleBuffering.cpp : main project file. + +#include "stdafx.h" +#include "Form1.h" + +using namespace DoubleBuffering; + +[STAThreadAttribute] +int main(array ^args) +{ + // Enabling Windows XP visual effects before any controls are created + Application::EnableVisualStyles(); + // Create the main window and run it + Application::Run(gcnew Form1()); + return 0; +} diff --git a/Chapter11/DoubleBuffering/DoubleBuffering.vcproj b/Chapter11/DoubleBuffering/DoubleBuffering.vcproj new file mode 100644 index 0000000..6e759f4 --- /dev/null +++ b/Chapter11/DoubleBuffering/DoubleBuffering.vcproj @@ -0,0 +1,250 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Chapter11/DoubleBuffering/Form1.h b/Chapter11/DoubleBuffering/Form1.h new file mode 100644 index 0000000..3eb4ee2 --- /dev/null +++ b/Chapter11/DoubleBuffering/Form1.h @@ -0,0 +1,155 @@ +#pragma once + +namespace DoubleBuffering +{ + using namespace System; + using namespace System::ComponentModel; + using namespace System::Collections; + using namespace System::Windows::Forms; + using namespace System::Data; + using namespace System::Drawing; + + public ref class Form1 : public System::Windows::Forms::Form + { + public: + Form1(void) + { + InitializeComponent(); + this->SetStyle(ControlStyles::Opaque, true); + + dbBitmap = nullptr; + dbGraphics = nullptr; + X = -250; // Preset to be just left of window + + Form1_Resize(nullptr, EventArgs::Empty); + } + + protected: + ~Form1() + { + if (components) + { + delete components; + } + } + private: + System::Windows::Forms::Timer^ timer1; + System::ComponentModel::IContainer^ components; + + Bitmap^ dbBitmap; + Graphics^ dbGraphics; + int X; // Actual x coordinate of Happy face + +#pragma region Windows Form Designer generated code + + void InitializeComponent(void) + { + this->components = (gcnew System::ComponentModel::Container()); + this->timer1 = + (gcnew System::Windows::Forms::Timer(this->components)); + this->SuspendLayout(); + // + // timer1 + // + this->timer1->Enabled = true; + this->timer1->Interval = 10; + this->timer1->Tick += + gcnew System::EventHandler(this, &Form1::timer1_Tick); + // + // Form1 + // + this->AutoScaleDimensions = System::Drawing::SizeF(6, 13); + this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font; + this->ClientSize = System::Drawing::Size(500, 300); + this->Name = L"Form1"; + this->Text = L"Sliding Happy Face"; + this->Paint += + gcnew System::Windows::Forms::PaintEventHandler(this, + &Form1::Form1_Paint); + this->Resize += + gcnew System::EventHandler(this, &Form1::Form1_Resize); + this->ResumeLayout(false); + + } +#pragma endregion + + private: + System::Void Form1_Paint(System::Object^ sender, + System::Windows::Forms::PaintEventArgs^ e) + { + // Move image at end of line start from beginning + if (X < ClientRectangle.Width) + { + X ++; + dbGraphics->TranslateTransform(1.0, 0.0); + } + else + { + X = -250; + dbGraphics->TranslateTransform( + (float)-(ClientRectangle.Width+250), 0.0); + } + + // Clear background + dbGraphics->Clear(Color::White); + + // redraw image from scratch + Pen^ b4pen = gcnew Pen(Color::Black, 4); + + Drawing::Rectangle Head = Drawing::Rectangle(0, 0, 250, 250); + dbGraphics->FillEllipse(Brushes::Yellow, Head); + dbGraphics->DrawEllipse(b4pen, Head); + + Drawing::Rectangle Mouth = Drawing::Rectangle(75, 150, 100, 50); + dbGraphics->FillPie(Brushes::White, Mouth,0,180); + dbGraphics->DrawPie(b4pen, Mouth, 0, 180); + + Drawing::Rectangle LEye = Drawing::Rectangle(75, 75, 25, 25); + dbGraphics->FillEllipse(Brushes::White, LEye); + dbGraphics->DrawEllipse(b4pen, LEye); + + Drawing::Rectangle REye = Drawing::Rectangle(150, 75, 25, 25); + dbGraphics->FillEllipse(Brushes::White, REye); + dbGraphics->DrawEllipse(b4pen, REye); + + // Make the buffer visible + e->Graphics->DrawImageUnscaled(dbBitmap, 0, 0); + + delete b4pen; + } + + System::Void Form1_Resize(System::Object^ sender, System::EventArgs^ e) + { + // Get rid of old stuff + if (dbGraphics != nullptr) + { + delete dbGraphics; + } + + if (dbBitmap != nullptr) + { + delete dbBitmap; + } + + if (ClientRectangle.Width > 0 && ClientRectangle.Height > 0) + { + // Create a bitmap + dbBitmap = gcnew Bitmap(ClientRectangle.Width, + ClientRectangle.Height); + + // Grab its Graphics + dbGraphics = Graphics::FromImage(dbBitmap); + + // Set up initial translation after resize (also at start) + dbGraphics->TranslateTransform((float)X, 25.0); + } + } + + System::Void timer1_Tick(System::Object^ sender, System::EventArgs^ e) + { + // Move the image + Invalidate(); + } + }; +} + diff --git a/Chapter11/DoubleBuffering/Form1.resx b/Chapter11/DoubleBuffering/Form1.resx new file mode 100644 index 0000000..886d0de --- /dev/null +++ b/Chapter11/DoubleBuffering/Form1.resx @@ -0,0 +1,123 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 17, 17 + + \ No newline at end of file diff --git a/Chapter11/DoubleBuffering/stdafx.cpp b/Chapter11/DoubleBuffering/stdafx.cpp new file mode 100644 index 0000000..247730e --- /dev/null +++ b/Chapter11/DoubleBuffering/stdafx.cpp @@ -0,0 +1,7 @@ +// stdafx.cpp : source file that includes just the standard includes +// DoubleBuffering.pch will be the pre-compiled header +// stdafx.obj will contain the pre-compiled type information + +#include "stdafx.h" + + diff --git a/Chapter11/DoubleBuffering/stdafx.h b/Chapter11/DoubleBuffering/stdafx.h new file mode 100644 index 0000000..46bef73 --- /dev/null +++ b/Chapter11/DoubleBuffering/stdafx.h @@ -0,0 +1,6 @@ +// stdafx.h : include file for standard system include files, +// or project specific include files that are used frequently, but +// are changed infrequently +#pragma once + +// TODO: reference additional headers your program requires here diff --git a/Chapter11/DownwardStringRect/AssemblyInfo.cpp b/Chapter11/DownwardStringRect/AssemblyInfo.cpp new file mode 100644 index 0000000..a645cd2 --- /dev/null +++ b/Chapter11/DownwardStringRect/AssemblyInfo.cpp @@ -0,0 +1,35 @@ +#include "stdafx.h" + +using namespace System::Reflection; +using namespace System::Runtime::CompilerServices; +using namespace System::Runtime::InteropServices; + +// +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +// +[assembly:AssemblyTitleAttribute("DownwardStringRect")]; +[assembly:AssemblyDescriptionAttribute("")]; +[assembly:AssemblyConfigurationAttribute("")]; +[assembly:AssemblyCompanyAttribute("")]; +[assembly:AssemblyProductAttribute("DownwardStringRect")]; +[assembly:AssemblyCopyrightAttribute("Copyright (c) 2005")]; +[assembly:AssemblyTrademarkAttribute("")]; +[assembly:AssemblyCultureAttribute("")]; + +// +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the value or you can default the Revision and Build Numbers +// by using the '*' as shown below: + +[assembly:AssemblyVersionAttribute("1.0.*")]; + +[assembly:ComVisible(false)]; + diff --git a/Chapter11/DownwardStringRect/DownwardStringRect.cpp b/Chapter11/DownwardStringRect/DownwardStringRect.cpp new file mode 100644 index 0000000..005683f --- /dev/null +++ b/Chapter11/DownwardStringRect/DownwardStringRect.cpp @@ -0,0 +1,16 @@ +// DownwardStringRect.cpp : main project file. + +#include "stdafx.h" +#include "Form1.h" + +using namespace DownwardStringRect; + +[STAThreadAttribute] +int main(array ^args) +{ + // Enabling Windows XP visual effects before any controls are created + Application::EnableVisualStyles(); + // Create the main window and run it + Application::Run(gcnew Form1()); + return 0; +} diff --git a/Chapter11/DownwardStringRect/DownwardStringRect.vcproj b/Chapter11/DownwardStringRect/DownwardStringRect.vcproj new file mode 100644 index 0000000..30434df --- /dev/null +++ b/Chapter11/DownwardStringRect/DownwardStringRect.vcproj @@ -0,0 +1,250 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Chapter11/DownwardStringRect/Form1.h b/Chapter11/DownwardStringRect/Form1.h new file mode 100644 index 0000000..40ee79a --- /dev/null +++ b/Chapter11/DownwardStringRect/Form1.h @@ -0,0 +1,68 @@ +#pragma once + +namespace DownwardStringRect +{ + using namespace System; + using namespace System::ComponentModel; + using namespace System::Collections; + using namespace System::Windows::Forms; + using namespace System::Data; + using namespace System::Drawing; + + public ref class Form1 : public System::Windows::Forms::Form + { + public: + Form1(void) + { + InitializeComponent(); + } + + protected: + ~Form1() + { + if (components) + { + delete components; + } + } + + private: + System::ComponentModel::Container ^components; + +#pragma region Windows Form Designer generated code + void InitializeComponent(void) + { + this->SuspendLayout(); + this->AutoScaleDimensions = System::Drawing::SizeF(6, 13); + this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font; + this->ClientSize = System::Drawing::Size(300, 145); + this->Name = L"Form1"; + this->Text = L"Downward String in a Rectangle"; + this->Paint += + gcnew System::Windows::Forms::PaintEventHandler(this, + &Form1::Form1_Paint); + this->ResumeLayout(false); + } +#pragma endregion + + private: + System::Void Form1_Paint(System::Object^ sender, + System::Windows::Forms::PaintEventArgs^ e) + { + // create and configure the StringFormat object + StringFormat ^stringformat = gcnew StringFormat(); + stringformat->FormatFlags = StringFormatFlags::DirectionVertical; + stringformat->Alignment = StringAlignment::Center; + + // Draw the string + e->Graphics->DrawString( + "Let's draw a string to a rectangle and go a little " + "overboard on the size of the string that we place " + "inside of it", + gcnew Drawing::Font(gcnew FontFamily("Arial"), 13), + Brushes::Black, Drawing::RectangleF(20.0, 40.0, 250.0, 80.0), + stringformat); + } + }; +} + diff --git a/Chapter11/DownwardStringRect/Form1.resx b/Chapter11/DownwardStringRect/Form1.resx new file mode 100644 index 0000000..de824e1 --- /dev/null +++ b/Chapter11/DownwardStringRect/Form1.resx @@ -0,0 +1,110 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Chapter11/DownwardStringRect/stdafx.cpp b/Chapter11/DownwardStringRect/stdafx.cpp new file mode 100644 index 0000000..2580201 --- /dev/null +++ b/Chapter11/DownwardStringRect/stdafx.cpp @@ -0,0 +1,7 @@ +// stdafx.cpp : source file that includes just the standard includes +// DownwardStringRect.pch will be the pre-compiled header +// stdafx.obj will contain the pre-compiled type information + +#include "stdafx.h" + + diff --git a/Chapter11/DownwardStringRect/stdafx.h b/Chapter11/DownwardStringRect/stdafx.h new file mode 100644 index 0000000..46bef73 --- /dev/null +++ b/Chapter11/DownwardStringRect/stdafx.h @@ -0,0 +1,6 @@ +// stdafx.h : include file for standard system include files, +// or project specific include files that are used frequently, but +// are changed infrequently +#pragma once + +// TODO: reference additional headers your program requires here diff --git a/Chapter11/DrawImageEx/AssemblyInfo.cpp b/Chapter11/DrawImageEx/AssemblyInfo.cpp new file mode 100644 index 0000000..2f00614 --- /dev/null +++ b/Chapter11/DrawImageEx/AssemblyInfo.cpp @@ -0,0 +1,35 @@ +#include "stdafx.h" + +using namespace System::Reflection; +using namespace System::Runtime::CompilerServices; +using namespace System::Runtime::InteropServices; + +// +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +// +[assembly:AssemblyTitleAttribute("DrawImageEx")]; +[assembly:AssemblyDescriptionAttribute("")]; +[assembly:AssemblyConfigurationAttribute("")]; +[assembly:AssemblyCompanyAttribute("")]; +[assembly:AssemblyProductAttribute("DrawImageEx")]; +[assembly:AssemblyCopyrightAttribute("Copyright (c) 2005")]; +[assembly:AssemblyTrademarkAttribute("")]; +[assembly:AssemblyCultureAttribute("")]; + +// +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the value or you can default the Revision and Build Numbers +// by using the '*' as shown below: + +[assembly:AssemblyVersionAttribute("1.0.*")]; + +[assembly:ComVisible(false)]; + diff --git a/Chapter11/DrawImageEx/DrawImageEx.cpp b/Chapter11/DrawImageEx/DrawImageEx.cpp new file mode 100644 index 0000000..c0374e0 --- /dev/null +++ b/Chapter11/DrawImageEx/DrawImageEx.cpp @@ -0,0 +1,16 @@ +// DrawImageEx.cpp : main project file. + +#include "stdafx.h" +#include "Form1.h" + +using namespace DrawImageEx; + +[STAThreadAttribute] +int main(array ^args) +{ + // Enabling Windows XP visual effects before any controls are created + Application::EnableVisualStyles(); + // Create the main window and run it + Application::Run(gcnew Form1()); + return 0; +} diff --git a/Chapter11/DrawImageEx/DrawImageEx.vcproj b/Chapter11/DrawImageEx/DrawImageEx.vcproj new file mode 100644 index 0000000..4b76350 --- /dev/null +++ b/Chapter11/DrawImageEx/DrawImageEx.vcproj @@ -0,0 +1,250 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Chapter11/DrawImageEx/Form1.h b/Chapter11/DrawImageEx/Form1.h new file mode 100644 index 0000000..cf386f9 --- /dev/null +++ b/Chapter11/DrawImageEx/Form1.h @@ -0,0 +1,57 @@ +#pragma once + +namespace DrawImageEx +{ + using namespace System; + using namespace System::ComponentModel; + using namespace System::Collections; + using namespace System::Windows::Forms; + using namespace System::Data; + using namespace System::Drawing; + + public ref class Form1 : public System::Windows::Forms::Form + { + public: + Form1(void) + { + InitializeComponent(); + } + + protected: + ~Form1() + { + if (components) + { + delete components; + } + } + + private: + System::ComponentModel::Container ^components; + +#pragma region Windows Form Designer generated code + + void InitializeComponent(void) + { + this->SuspendLayout(); + this->AutoScaleDimensions = System::Drawing::SizeF(6, 13); + this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font; + this->ClientSize = System::Drawing::Size(292, 273); + this->Name = L"Form1"; + this->Text = L"Draw Image"; + this->Paint += + gcnew System::Windows::Forms::PaintEventHandler(this, + &Form1::Form1_Paint); + this->ResumeLayout(false); + } +#pragma endregion + + private: + System::Void Form1_Paint(System::Object^ sender, + System::Windows::Forms::PaintEventArgs^ e) + { + Image^ img = Image::FromFile("Images\\CLICppCover.gif"); + e->Graphics->DrawImage(img, 0, 0, img->Width*2, img->Height*2); + } + }; +} \ No newline at end of file diff --git a/Chapter11/DrawImageEx/Form1.resx b/Chapter11/DrawImageEx/Form1.resx new file mode 100644 index 0000000..de824e1 --- /dev/null +++ b/Chapter11/DrawImageEx/Form1.resx @@ -0,0 +1,110 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Chapter11/DrawImageEx/Images/CLICppCover.gif b/Chapter11/DrawImageEx/Images/CLICppCover.gif new file mode 100644 index 0000000..b9c6832 Binary files /dev/null and b/Chapter11/DrawImageEx/Images/CLICppCover.gif differ diff --git a/Chapter11/DrawImageEx/stdafx.cpp b/Chapter11/DrawImageEx/stdafx.cpp new file mode 100644 index 0000000..85cbb3c --- /dev/null +++ b/Chapter11/DrawImageEx/stdafx.cpp @@ -0,0 +1,7 @@ +// stdafx.cpp : source file that includes just the standard includes +// DrawImageEx.pch will be the pre-compiled header +// stdafx.obj will contain the pre-compiled type information + +#include "stdafx.h" + + diff --git a/Chapter11/DrawImageEx/stdafx.h b/Chapter11/DrawImageEx/stdafx.h new file mode 100644 index 0000000..46bef73 --- /dev/null +++ b/Chapter11/DrawImageEx/stdafx.h @@ -0,0 +1,6 @@ +// stdafx.h : include file for standard system include files, +// or project specific include files that are used frequently, but +// are changed infrequently +#pragma once + +// TODO: reference additional headers your program requires here diff --git a/Chapter11/DrawingLines/AssemblyInfo.cpp b/Chapter11/DrawingLines/AssemblyInfo.cpp new file mode 100644 index 0000000..3e7d657 --- /dev/null +++ b/Chapter11/DrawingLines/AssemblyInfo.cpp @@ -0,0 +1,35 @@ +#include "stdafx.h" + +using namespace System::Reflection; +using namespace System::Runtime::CompilerServices; +using namespace System::Runtime::InteropServices; + +// +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +// +[assembly:AssemblyTitleAttribute("DrawingLines")]; +[assembly:AssemblyDescriptionAttribute("")]; +[assembly:AssemblyConfigurationAttribute("")]; +[assembly:AssemblyCompanyAttribute("")]; +[assembly:AssemblyProductAttribute("DrawingLines")]; +[assembly:AssemblyCopyrightAttribute("Copyright (c) 2005")]; +[assembly:AssemblyTrademarkAttribute("")]; +[assembly:AssemblyCultureAttribute("")]; + +// +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the value or you can default the Revision and Build Numbers +// by using the '*' as shown below: + +[assembly:AssemblyVersionAttribute("1.0.*")]; + +[assembly:ComVisible(false)]; + diff --git a/Chapter11/DrawingLines/DrawingLines.cpp b/Chapter11/DrawingLines/DrawingLines.cpp new file mode 100644 index 0000000..d306bf3 --- /dev/null +++ b/Chapter11/DrawingLines/DrawingLines.cpp @@ -0,0 +1,16 @@ +// DrawingLines.cpp : main project file. + +#include "stdafx.h" +#include "Form1.h" + +using namespace DrawingLines; + +[STAThreadAttribute] +int main(array ^args) +{ + // Enabling Windows XP visual effects before any controls are created + Application::EnableVisualStyles(); + // Create the main window and run it + Application::Run(gcnew Form1()); + return 0; +} diff --git a/Chapter11/DrawingLines/DrawingLines.vcproj b/Chapter11/DrawingLines/DrawingLines.vcproj new file mode 100644 index 0000000..e17f1c9 --- /dev/null +++ b/Chapter11/DrawingLines/DrawingLines.vcproj @@ -0,0 +1,250 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Chapter11/DrawingLines/Form1.h b/Chapter11/DrawingLines/Form1.h new file mode 100644 index 0000000..0321cd6 --- /dev/null +++ b/Chapter11/DrawingLines/Form1.h @@ -0,0 +1,90 @@ +#pragma once + +namespace DrawingLines +{ + using namespace System; + using namespace System::ComponentModel; + using namespace System::Collections; + using namespace System::Windows::Forms; + using namespace System::Data; + using namespace System::Drawing; + using namespace System::Drawing::Drawing2D; + + public ref class Form1 : public System::Windows::Forms::Form + { + public: + Form1(void) + { + InitializeComponent(); + + pen = gcnew array(5); + + // a one unit width black pen + pen[0] = Pens::Black; + + // a one unit with purple pen broken with dashes + pen[1] = gcnew Pen(Color::Purple); + pen[1]->DashStyle = DashStyle::Dash; + + // a 4 unit width chocolate pen + pen[2] = gcnew Pen(Color::Chocolate, 4); + + // A 8 width royalblue pen made of three lines narrow wide narrow + pen[3] = gcnew Pen(Color::RoyalBlue, 10); + array^ cArray = gcnew array { + 0.0f, 0.1f, 0.3f, 0.7f, 0.9f, 1.0f + }; + pen[3]->CompoundArray = cArray; + + // a 5 width tomato pen with dimond start and round end anchors + pen[4] = gcnew Pen(Color::Tomato, 5); + pen[4]->StartCap = LineCap::DiamondAnchor; + pen[4]->EndCap = LineCap::RoundAnchor; + } + + protected: + ~Form1() + { + if (components) + { + delete components; + } + } + + private: + System::ComponentModel::Container ^components; + array^ pen; + +#pragma region Windows Form Designer generated code + + void InitializeComponent(void) + { + this->SuspendLayout(); + this->AutoScaleDimensions = System::Drawing::SizeF(6, 13); + this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font; + this->ClientSize = System::Drawing::Size(292, 273); + this->Name = L"Form1"; + this->Text = L"Drawing Some lines"; + this->Paint += + gcnew System::Windows::Forms::PaintEventHandler(this, + &Form1::Form1_Paint); + this->ResumeLayout(false); + + } +#pragma endregion + + private: + System::Void Form1_Paint(System::Object^ sender, + System::Windows::Forms::PaintEventArgs^ e) + { + Random ^rand = gcnew Random(); + + for (int i = 0; i < 10; i++) + { + e->Graphics->DrawLine(pen[i%5], rand->Next(0,299), + rand->Next(0,299), rand->Next(0,299), rand->Next(0,299)); + } + } + }; +} + diff --git a/Chapter11/DrawingLines/Form1.resx b/Chapter11/DrawingLines/Form1.resx new file mode 100644 index 0000000..de824e1 --- /dev/null +++ b/Chapter11/DrawingLines/Form1.resx @@ -0,0 +1,110 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Chapter11/DrawingLines/stdafx.cpp b/Chapter11/DrawingLines/stdafx.cpp new file mode 100644 index 0000000..43d931c --- /dev/null +++ b/Chapter11/DrawingLines/stdafx.cpp @@ -0,0 +1,7 @@ +// stdafx.cpp : source file that includes just the standard includes +// DrawingLines.pch will be the pre-compiled header +// stdafx.obj will contain the pre-compiled type information + +#include "stdafx.h" + + diff --git a/Chapter11/DrawingLines/stdafx.h b/Chapter11/DrawingLines/stdafx.h new file mode 100644 index 0000000..46bef73 --- /dev/null +++ b/Chapter11/DrawingLines/stdafx.h @@ -0,0 +1,6 @@ +// stdafx.h : include file for standard system include files, +// or project specific include files that are used frequently, but +// are changed infrequently +#pragma once + +// TODO: reference additional headers your program requires here diff --git a/Chapter11/FontsGalore/AssemblyInfo.cpp b/Chapter11/FontsGalore/AssemblyInfo.cpp new file mode 100644 index 0000000..9bb6fc9 --- /dev/null +++ b/Chapter11/FontsGalore/AssemblyInfo.cpp @@ -0,0 +1,35 @@ +#include "stdafx.h" + +using namespace System::Reflection; +using namespace System::Runtime::CompilerServices; +using namespace System::Runtime::InteropServices; + +// +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +// +[assembly:AssemblyTitleAttribute("FontsGalore")]; +[assembly:AssemblyDescriptionAttribute("")]; +[assembly:AssemblyConfigurationAttribute("")]; +[assembly:AssemblyCompanyAttribute("")]; +[assembly:AssemblyProductAttribute("FontsGalore")]; +[assembly:AssemblyCopyrightAttribute("Copyright (c) 2005")]; +[assembly:AssemblyTrademarkAttribute("")]; +[assembly:AssemblyCultureAttribute("")]; + +// +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the value or you can default the Revision and Build Numbers +// by using the '*' as shown below: + +[assembly:AssemblyVersionAttribute("1.0.*")]; + +[assembly:ComVisible(false)]; + diff --git a/Chapter11/FontsGalore/FontsGalore.cpp b/Chapter11/FontsGalore/FontsGalore.cpp new file mode 100644 index 0000000..4f21424 --- /dev/null +++ b/Chapter11/FontsGalore/FontsGalore.cpp @@ -0,0 +1,16 @@ +// FontsGalore.cpp : main project file. + +#include "stdafx.h" +#include "Form1.h" + +using namespace FontsGalore; + +[STAThreadAttribute] +int main(array ^args) +{ + // Enabling Windows XP visual effects before any controls are created + Application::EnableVisualStyles(); + // Create the main window and run it + Application::Run(gcnew Form1()); + return 0; +} diff --git a/Chapter11/FontsGalore/FontsGalore.vcproj b/Chapter11/FontsGalore/FontsGalore.vcproj new file mode 100644 index 0000000..178b5a1 --- /dev/null +++ b/Chapter11/FontsGalore/FontsGalore.vcproj @@ -0,0 +1,250 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Chapter11/FontsGalore/Form1.h b/Chapter11/FontsGalore/Form1.h new file mode 100644 index 0000000..0143df2 --- /dev/null +++ b/Chapter11/FontsGalore/Form1.h @@ -0,0 +1,121 @@ +#pragma once + +namespace FontsGalore +{ + using namespace System; + using namespace System::ComponentModel; + using namespace System::Collections; + using namespace System::Windows::Forms; + using namespace System::Data; + using namespace System::Drawing; + using namespace System::Drawing::Text; + + public ref class Form1 : public System::Windows::Forms::Form + { + public: + Form1(void) + { + InitializeComponent(); + + fonts = gcnew array(10); + fontstr = gcnew array(10); + + // Used to generate random fonts + array^ sizes = gcnew array { + 10.0, 12.5, 16.0 + }; + + array^ fontstyles = gcnew array { + FontStyle::Regular, FontStyle::Bold, + FontStyle::Italic, + (FontStyle)(FontStyle::Underline|FontStyle::Bold|FontStyle::Italic) + }; + + array^ units = gcnew array { + GraphicsUnit::Point, GraphicsUnit::Pixel + }; + + // Get all fonts on computer + InstalledFontCollection ^availFonts = + gcnew InstalledFontCollection(); + + array^ fontfamilies = availFonts->Families; + + Random ^rand = gcnew Random(); + int ff, s, fs, u; + + for (int i = 0; i < fonts->Length; i++) + { + s = rand->Next(0,3); + fs = rand->Next(0,3); + u = rand->Next(0,2); + + // Not all fonts support every style + do { + ff = rand->Next(0,fontfamilies->Length); + } + while (!fontfamilies[ff]->IsStyleAvailable( + (FontStyle)fontstyles[fs])); + + // Display string of font + fontstr[i] = String::Format("{0} {1} {2}", + fontfamilies[ff]->Name, + sizes[s], + String::Concat(fontstyles[fs], " ", + units[u])); + + // Create the font + fonts[i] = gcnew Drawing::Font(fontfamilies[ff], sizes[s], + (FontStyle)fontstyles[fs], + (GraphicsUnit)units[u]); + } + } + + protected: + ~Form1() + { + if (components) + { + delete components; + } + } + + private: + System::ComponentModel::Container ^components; + array^ fonts; + array^ fontstr; + +#pragma region Windows Form Designer generated code + + void InitializeComponent(void) + { + this->SuspendLayout(); + this->AutoScaleDimensions = System::Drawing::SizeF(6, 13); + this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font; + this->ClientSize = System::Drawing::Size(292, 273); + this->Name = L"Form1"; + this->Text = L"Many Fonts"; + this->Paint += + gcnew System::Windows::Forms::PaintEventHandler(this, + &Form1::Form1_Paint); + this->ResumeLayout(false); + } +#pragma endregion + + private: + System::Void Form1_Paint(System::Object^ sender, + System::Windows::Forms::PaintEventArgs^ e) + { + float lineloc = 0; + for (int i = 0; i < fonts->Length; i++) + { + // Display font + e->Graphics->DrawString(fontstr[i], fonts[i], Brushes::Black, + 10, lineloc); + + // Calculate the top of the next line + lineloc += fonts[i]->Height; + } + } + }; +} \ No newline at end of file diff --git a/Chapter11/FontsGalore/Form1.resx b/Chapter11/FontsGalore/Form1.resx new file mode 100644 index 0000000..de824e1 --- /dev/null +++ b/Chapter11/FontsGalore/Form1.resx @@ -0,0 +1,110 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Chapter11/FontsGalore/stdafx.cpp b/Chapter11/FontsGalore/stdafx.cpp new file mode 100644 index 0000000..335960a --- /dev/null +++ b/Chapter11/FontsGalore/stdafx.cpp @@ -0,0 +1,7 @@ +// stdafx.cpp : source file that includes just the standard includes +// FontsGalore.pch will be the pre-compiled header +// stdafx.obj will contain the pre-compiled type information + +#include "stdafx.h" + + diff --git a/Chapter11/FontsGalore/stdafx.h b/Chapter11/FontsGalore/stdafx.h new file mode 100644 index 0000000..46bef73 --- /dev/null +++ b/Chapter11/FontsGalore/stdafx.h @@ -0,0 +1,6 @@ +// stdafx.h : include file for standard system include files, +// or project specific include files that are used frequently, but +// are changed infrequently +#pragma once + +// TODO: reference additional headers your program requires here diff --git a/Chapter11/HappyFace/AssemblyInfo.cpp b/Chapter11/HappyFace/AssemblyInfo.cpp new file mode 100644 index 0000000..9a42379 --- /dev/null +++ b/Chapter11/HappyFace/AssemblyInfo.cpp @@ -0,0 +1,35 @@ +#include "stdafx.h" + +using namespace System::Reflection; +using namespace System::Runtime::CompilerServices; +using namespace System::Runtime::InteropServices; + +// +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +// +[assembly:AssemblyTitleAttribute("HappyFace")]; +[assembly:AssemblyDescriptionAttribute("")]; +[assembly:AssemblyConfigurationAttribute("")]; +[assembly:AssemblyCompanyAttribute("")]; +[assembly:AssemblyProductAttribute("HappyFace")]; +[assembly:AssemblyCopyrightAttribute("Copyright (c) 2005")]; +[assembly:AssemblyTrademarkAttribute("")]; +[assembly:AssemblyCultureAttribute("")]; + +// +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the value or you can default the Revision and Build Numbers +// by using the '*' as shown below: + +[assembly:AssemblyVersionAttribute("1.0.*")]; + +[assembly:ComVisible(false)]; + diff --git a/Chapter11/HappyFace/Form1.h b/Chapter11/HappyFace/Form1.h new file mode 100644 index 0000000..7f5e8de --- /dev/null +++ b/Chapter11/HappyFace/Form1.h @@ -0,0 +1,80 @@ +#pragma once + +namespace HappyFace +{ + using namespace System; + using namespace System::ComponentModel; + using namespace System::Collections; + using namespace System::Windows::Forms; + using namespace System::Data; + using namespace System::Drawing; + + public ref class Form1 : public System::Windows::Forms::Form + { + public: + Form1(void) + { + InitializeComponent(); + } + + protected: + ~Form1() + { + if (components) + { + delete components; + } + } + + private: + System::ComponentModel::Container ^components; + +#pragma region Windows Form Designer generated code + + void InitializeComponent(void) + { + this->SuspendLayout(); + this->AutoScaleDimensions = System::Drawing::SizeF(6, 13); + this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font; + this->ClientSize = System::Drawing::Size(300, 300); + this->Name = L"Form1"; + this->Text = L"Happy Face"; + this->Paint += + gcnew System::Windows::Forms::PaintEventHandler(this, + &Form1::Form1_Paint); + this->ResumeLayout(false); + + } +#pragma endregion + + private: + System::Void Form1_Paint(System::Object^ sender, + System::Windows::Forms::PaintEventArgs^ e) + { + Graphics^ g = e->Graphics; + Pen^ b4pen = gcnew Pen(Color::Black, 4); + + // Head + Rectangle rect = Drawing::Rectangle(25, 25, 250, 250); + g->FillEllipse(Brushes::Yellow, rect); + g->DrawEllipse(b4pen, rect); + + // Mouth + g->FillPie(Brushes::White, 100, 175, 100, 50, 0, 180); + g->DrawPie(b4pen, 100, 175, 100, 50, 0, 180); + + // Left Eye + rect = Drawing::Rectangle(100, 100, 25, 25); + g->FillEllipse(Brushes::White, rect); + g->DrawEllipse(b4pen, rect); + + // Right Eye + rect = Drawing::Rectangle(175, 100, 25, 25); + g->FillEllipse(Brushes::White, rect); + g->DrawEllipse(b4pen, rect); + + // Get rid of pen Created + delete b4pen; + } + }; +} \ No newline at end of file diff --git a/Chapter11/HappyFace/Form1.resx b/Chapter11/HappyFace/Form1.resx new file mode 100644 index 0000000..de824e1 --- /dev/null +++ b/Chapter11/HappyFace/Form1.resx @@ -0,0 +1,110 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Chapter11/HappyFace/HappyFace.cpp b/Chapter11/HappyFace/HappyFace.cpp new file mode 100644 index 0000000..d9c0b5c --- /dev/null +++ b/Chapter11/HappyFace/HappyFace.cpp @@ -0,0 +1,16 @@ +// HappyFace.cpp : main project file. + +#include "stdafx.h" +#include "Form1.h" + +using namespace HappyFace; + +[STAThreadAttribute] +int main(array ^args) +{ + // Enabling Windows XP visual effects before any controls are created + Application::EnableVisualStyles(); + // Create the main window and run it + Application::Run(gcnew Form1()); + return 0; +} diff --git a/Chapter11/HappyFace/HappyFace.vcproj b/Chapter11/HappyFace/HappyFace.vcproj new file mode 100644 index 0000000..ec3aa07 --- /dev/null +++ b/Chapter11/HappyFace/HappyFace.vcproj @@ -0,0 +1,250 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Chapter11/HappyFace/stdafx.cpp b/Chapter11/HappyFace/stdafx.cpp new file mode 100644 index 0000000..ea6f730 --- /dev/null +++ b/Chapter11/HappyFace/stdafx.cpp @@ -0,0 +1,7 @@ +// stdafx.cpp : source file that includes just the standard includes +// HappyFace.pch will be the pre-compiled header +// stdafx.obj will contain the pre-compiled type information + +#include "stdafx.h" + + diff --git a/Chapter11/HappyFace/stdafx.h b/Chapter11/HappyFace/stdafx.h new file mode 100644 index 0000000..46bef73 --- /dev/null +++ b/Chapter11/HappyFace/stdafx.h @@ -0,0 +1,6 @@ +// stdafx.h : include file for standard system include files, +// or project specific include files that are used frequently, but +// are changed infrequently +#pragma once + +// TODO: reference additional headers your program requires here diff --git a/Chapter11/HelloGDI/AssemblyInfo.cpp b/Chapter11/HelloGDI/AssemblyInfo.cpp new file mode 100644 index 0000000..4c3ccc3 --- /dev/null +++ b/Chapter11/HelloGDI/AssemblyInfo.cpp @@ -0,0 +1,35 @@ +#include "stdafx.h" + +using namespace System::Reflection; +using namespace System::Runtime::CompilerServices; +using namespace System::Runtime::InteropServices; + +// +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +// +[assembly:AssemblyTitleAttribute("HelloGDI")]; +[assembly:AssemblyDescriptionAttribute("")]; +[assembly:AssemblyConfigurationAttribute("")]; +[assembly:AssemblyCompanyAttribute("")]; +[assembly:AssemblyProductAttribute("HelloGDI")]; +[assembly:AssemblyCopyrightAttribute("Copyright (c) 2005")]; +[assembly:AssemblyTrademarkAttribute("")]; +[assembly:AssemblyCultureAttribute("")]; + +// +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the value or you can default the Revision and Build Numbers +// by using the '*' as shown below: + +[assembly:AssemblyVersionAttribute("1.0.*")]; + +[assembly:ComVisible(false)]; + diff --git a/Chapter11/HelloGDI/Form1.h b/Chapter11/HelloGDI/Form1.h new file mode 100644 index 0000000..4b58dbc --- /dev/null +++ b/Chapter11/HelloGDI/Form1.h @@ -0,0 +1,58 @@ +#pragma once + +namespace HelloGDI +{ + using namespace System; + using namespace System::ComponentModel; + using namespace System::Collections; + using namespace System::Windows::Forms; + using namespace System::Data; + using namespace System::Drawing; + + public ref class Form1 : public System::Windows::Forms::Form + { + public: + Form1(void) + { + InitializeComponent(); + } + + protected: + ~Form1() + { + if (components) + { + delete components; + } + } + + private: + System::ComponentModel::Container ^components; + +#pragma region Windows Form Designer generated code + void InitializeComponent(void) + { + this->SuspendLayout(); + this->AutoScaleDimensions = System::Drawing::SizeF(6, 13); + this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font; + this->ClientSize = System::Drawing::Size(292, 273); + this->Name = L"Form1"; + this->Text = L"Hello GDI+"; + this->Paint += + gcnew System::Windows::Forms::PaintEventHandler(this, + &Form1::Form1_Paint); + this->ResumeLayout(false); + + } +#pragma endregion + private: + System::Void Form1_Paint(System::Object^ sender, + System::Windows::Forms::PaintEventArgs^ e) + { + Graphics ^g = e->Graphics; + g->DrawString("Hello World!", + gcnew Drawing::Font("Arial", 16), Brushes::Black, 75.0, 110.0); + } + }; +} + diff --git a/Chapter11/HelloGDI/Form1.resx b/Chapter11/HelloGDI/Form1.resx new file mode 100644 index 0000000..de824e1 --- /dev/null +++ b/Chapter11/HelloGDI/Form1.resx @@ -0,0 +1,110 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Chapter11/HelloGDI/HelloGDI.cpp b/Chapter11/HelloGDI/HelloGDI.cpp new file mode 100644 index 0000000..2ca9456 --- /dev/null +++ b/Chapter11/HelloGDI/HelloGDI.cpp @@ -0,0 +1,16 @@ +// HelloGDI.cpp : main project file. + +#include "stdafx.h" +#include "Form1.h" + +using namespace HelloGDI; + +[STAThreadAttribute] +int main(array ^args) +{ + // Enabling Windows XP visual effects before any controls are created + Application::EnableVisualStyles(); + // Create the main window and run it + Application::Run(gcnew Form1()); + return 0; +} diff --git a/Chapter11/HelloGDI/HelloGDI.vcproj b/Chapter11/HelloGDI/HelloGDI.vcproj new file mode 100644 index 0000000..0802308 --- /dev/null +++ b/Chapter11/HelloGDI/HelloGDI.vcproj @@ -0,0 +1,250 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Chapter11/HelloGDI/resource.h b/Chapter11/HelloGDI/resource.h new file mode 100644 index 0000000..d5ac7c4 --- /dev/null +++ b/Chapter11/HelloGDI/resource.h @@ -0,0 +1,3 @@ +//{{NO_DEPENDENCIES}} +// Microsoft Visual C++ generated include file. +// Used by app.rc diff --git a/Chapter11/HelloGDI/stdafx.cpp b/Chapter11/HelloGDI/stdafx.cpp new file mode 100644 index 0000000..a1d330d --- /dev/null +++ b/Chapter11/HelloGDI/stdafx.cpp @@ -0,0 +1,7 @@ +// stdafx.cpp : source file that includes just the standard includes +// HelloGDI.pch will be the pre-compiled header +// stdafx.obj will contain the pre-compiled type information + +#include "stdafx.h" + + diff --git a/Chapter11/HelloGDI/stdafx.h b/Chapter11/HelloGDI/stdafx.h new file mode 100644 index 0000000..46bef73 --- /dev/null +++ b/Chapter11/HelloGDI/stdafx.h @@ -0,0 +1,6 @@ +// stdafx.h : include file for standard system include files, +// or project specific include files that are used frequently, but +// are changed infrequently +#pragma once + +// TODO: reference additional headers your program requires here diff --git a/Chapter11/HelloGDI_OnPaint/AssemblyInfo.cpp b/Chapter11/HelloGDI_OnPaint/AssemblyInfo.cpp new file mode 100644 index 0000000..3382a8b --- /dev/null +++ b/Chapter11/HelloGDI_OnPaint/AssemblyInfo.cpp @@ -0,0 +1,35 @@ +#include "stdafx.h" + +using namespace System::Reflection; +using namespace System::Runtime::CompilerServices; +using namespace System::Runtime::InteropServices; + +// +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +// +[assembly:AssemblyTitleAttribute("HelloGDI_OnPaint")]; +[assembly:AssemblyDescriptionAttribute("")]; +[assembly:AssemblyConfigurationAttribute("")]; +[assembly:AssemblyCompanyAttribute("")]; +[assembly:AssemblyProductAttribute("HelloGDI_OnPaint")]; +[assembly:AssemblyCopyrightAttribute("Copyright (c) 2005")]; +[assembly:AssemblyTrademarkAttribute("")]; +[assembly:AssemblyCultureAttribute("")]; + +// +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the value or you can default the Revision and Build Numbers +// by using the '*' as shown below: + +[assembly:AssemblyVersionAttribute("1.0.*")]; + +[assembly:ComVisible(false)]; + diff --git a/Chapter11/HelloGDI_OnPaint/Form1.h b/Chapter11/HelloGDI_OnPaint/Form1.h new file mode 100644 index 0000000..dda9a1e --- /dev/null +++ b/Chapter11/HelloGDI_OnPaint/Form1.h @@ -0,0 +1,55 @@ +#pragma once + + +namespace HelloGDI_OnPaint +{ + using namespace System; + using namespace System::ComponentModel; + using namespace System::Collections; + using namespace System::Windows::Forms; + using namespace System::Data; + using namespace System::Drawing; + + public ref class Form1 : public System::Windows::Forms::Form + { + public: + Form1(void) + { + InitializeComponent(); + } + + protected: + ~Form1() + { + if (components) + { + delete components; + } + } + + private: + System::ComponentModel::Container ^components; + +#pragma region Windows Form Designer generated code + void InitializeComponent(void) + { + this->components = gcnew System::ComponentModel::Container(); + this->Size = System::Drawing::Size(300,300); + this->Text = L"Hello GDI+"; + this->Padding = System::Windows::Forms::Padding(0); + this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font; + } +#pragma endregion + + protected: + virtual void OnPaint(System::Windows::Forms::PaintEventArgs ^e) override + { + Form::OnPaint(e); + + Graphics ^g = e->Graphics; + g->DrawString("Hello World!", + gcnew Drawing::Font("Arial", 16), Brushes::Black, 75.0, 110.0); + } + }; +} + diff --git a/Chapter11/HelloGDI_OnPaint/Form1.resX b/Chapter11/HelloGDI_OnPaint/Form1.resX new file mode 100644 index 0000000..de824e1 --- /dev/null +++ b/Chapter11/HelloGDI_OnPaint/Form1.resX @@ -0,0 +1,110 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Chapter11/HelloGDI_OnPaint/HelloGDI_OnPaint.cpp b/Chapter11/HelloGDI_OnPaint/HelloGDI_OnPaint.cpp new file mode 100644 index 0000000..dbb0eb0 --- /dev/null +++ b/Chapter11/HelloGDI_OnPaint/HelloGDI_OnPaint.cpp @@ -0,0 +1,16 @@ +// HelloGDI_OnPaint.cpp : main project file. + +#include "stdafx.h" +#include "Form1.h" + +using namespace HelloGDI_OnPaint; + +[STAThreadAttribute] +int main(array ^args) +{ + // Enabling Windows XP visual effects before any controls are created + Application::EnableVisualStyles(); + // Create the main window and run it + Application::Run(gcnew Form1()); + return 0; +} diff --git a/Chapter11/HelloGDI_OnPaint/HelloGDI_OnPaint.vcproj b/Chapter11/HelloGDI_OnPaint/HelloGDI_OnPaint.vcproj new file mode 100644 index 0000000..d98210e --- /dev/null +++ b/Chapter11/HelloGDI_OnPaint/HelloGDI_OnPaint.vcproj @@ -0,0 +1,250 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Chapter11/HelloGDI_OnPaint/stdafx.cpp b/Chapter11/HelloGDI_OnPaint/stdafx.cpp new file mode 100644 index 0000000..67c8a92 --- /dev/null +++ b/Chapter11/HelloGDI_OnPaint/stdafx.cpp @@ -0,0 +1,7 @@ +// stdafx.cpp : source file that includes just the standard includes +// HelloGDI_OnPaint.pch will be the pre-compiled header +// stdafx.obj will contain the pre-compiled type information + +#include "stdafx.h" + + diff --git a/Chapter11/HelloGDI_OnPaint/stdafx.h b/Chapter11/HelloGDI_OnPaint/stdafx.h new file mode 100644 index 0000000..46bef73 --- /dev/null +++ b/Chapter11/HelloGDI_OnPaint/stdafx.h @@ -0,0 +1,6 @@ +// stdafx.h : include file for standard system include files, +// or project specific include files that are used frequently, but +// are changed infrequently +#pragma once + +// TODO: reference additional headers your program requires here diff --git a/Chapter11/InterOrUnion/AssemblyInfo.cpp b/Chapter11/InterOrUnion/AssemblyInfo.cpp new file mode 100644 index 0000000..e7f3ad2 --- /dev/null +++ b/Chapter11/InterOrUnion/AssemblyInfo.cpp @@ -0,0 +1,35 @@ +#include "stdafx.h" + +using namespace System::Reflection; +using namespace System::Runtime::CompilerServices; +using namespace System::Runtime::InteropServices; + +// +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +// +[assembly:AssemblyTitleAttribute("InterOrUnion")]; +[assembly:AssemblyDescriptionAttribute("")]; +[assembly:AssemblyConfigurationAttribute("")]; +[assembly:AssemblyCompanyAttribute("")]; +[assembly:AssemblyProductAttribute("InterOrUnion")]; +[assembly:AssemblyCopyrightAttribute("Copyright (c) 2005")]; +[assembly:AssemblyTrademarkAttribute("")]; +[assembly:AssemblyCultureAttribute("")]; + +// +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the value or you can default the Revision and Build Numbers +// by using the '*' as shown below: + +[assembly:AssemblyVersionAttribute("1.0.*")]; + +[assembly:ComVisible(false)]; + diff --git a/Chapter11/InterOrUnion/Form1.h b/Chapter11/InterOrUnion/Form1.h new file mode 100644 index 0000000..6ea4121 --- /dev/null +++ b/Chapter11/InterOrUnion/Form1.h @@ -0,0 +1,89 @@ +#pragma once + +namespace InterOrUnion +{ + using namespace System; + using namespace System::ComponentModel; + using namespace System::Collections; + using namespace System::Windows::Forms; + using namespace System::Data; + using namespace System::Drawing; + + public ref class Form1 : public System::Windows::Forms::Form + { + public: + Form1(void) + { + InitializeComponent(); + + // Build the rectangles from points and size + Drawing::Point point1 = Drawing::Point(25,25); + Drawing::Point point2 = Drawing::Point(100,100); + Drawing::Size size = Drawing::Size(200, 150); + rect1 = Drawing::Rectangle(point1, size); + rect2 = Drawing::Rectangle(point2, size); + } + + protected: + ~Form1() + { + if (components) + { + delete components; + } + } + + private: + System::ComponentModel::Container ^components; + + // intersecting and unions rectangles + Drawing::Rectangle rect1; + Drawing::Rectangle rect2; + +#pragma region Windows Form Designer generated code + void InitializeComponent(void) + { + this->SuspendLayout(); + this->AutoScaleDimensions = System::Drawing::SizeF(6, 13); + this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font; + this->ClientSize = System::Drawing::Size(330, 300); + this->Name = L"Form1"; + this->Text = L"Click in Window"; + this->Paint += + gcnew System::Windows::Forms::PaintEventHandler(this, + &Form1::Form1_Paint); + this->MouseDown += + gcnew System::Windows::Forms::MouseEventHandler(this, + &Form1::Form1_MouseDown); + this->ResumeLayout(false); + } +#pragma endregion + + private: + System::Void Form1_Paint(System::Object^ sender, + System::Windows::Forms::PaintEventArgs^ e) + { + // Draw a couple of rectangles + e->Graphics->DrawRectangle(Pens::Black, rect1); + e->Graphics->DrawRectangle(Pens::Black, rect2); + } + + private: + System::Void Form1_MouseDown(System::Object^ sender, + System::Windows::Forms::MouseEventArgs^ e) + { + // build a point from x,y coords of mouse click + Point p = Point(e->X, e->Y); + + // did we click in the intersection? + if (Rectangle::Intersect(rect1, rect2).Contains(p)) + Text = "Intersection and Union"; + // did we click in the union? + else if (Rectangle::Union(rect1, rect2).Contains(p)) + Text = "Union"; + // did we miss altogether + else + Text = "Outside of Both"; + } + }; +} \ No newline at end of file diff --git a/Chapter11/InterOrUnion/Form1.resx b/Chapter11/InterOrUnion/Form1.resx new file mode 100644 index 0000000..de824e1 --- /dev/null +++ b/Chapter11/InterOrUnion/Form1.resx @@ -0,0 +1,110 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Chapter11/InterOrUnion/InterOrUnion.cpp b/Chapter11/InterOrUnion/InterOrUnion.cpp new file mode 100644 index 0000000..87d20c2 --- /dev/null +++ b/Chapter11/InterOrUnion/InterOrUnion.cpp @@ -0,0 +1,16 @@ +// InterOrUnion.cpp : main project file. + +#include "stdafx.h" +#include "Form1.h" + +using namespace InterOrUnion; + +[STAThreadAttribute] +int main(array ^args) +{ + // Enabling Windows XP visual effects before any controls are created + Application::EnableVisualStyles(); + // Create the main window and run it + Application::Run(gcnew Form1()); + return 0; +} diff --git a/Chapter11/InterOrUnion/InterOrUnion.vcproj b/Chapter11/InterOrUnion/InterOrUnion.vcproj new file mode 100644 index 0000000..49288ee --- /dev/null +++ b/Chapter11/InterOrUnion/InterOrUnion.vcproj @@ -0,0 +1,250 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Chapter11/InterOrUnion/stdafx.cpp b/Chapter11/InterOrUnion/stdafx.cpp new file mode 100644 index 0000000..dd8556c --- /dev/null +++ b/Chapter11/InterOrUnion/stdafx.cpp @@ -0,0 +1,7 @@ +// stdafx.cpp : source file that includes just the standard includes +// InterOrUnion.pch will be the pre-compiled header +// stdafx.obj will contain the pre-compiled type information + +#include "stdafx.h" + + diff --git a/Chapter11/InterOrUnion/stdafx.h b/Chapter11/InterOrUnion/stdafx.h new file mode 100644 index 0000000..46bef73 --- /dev/null +++ b/Chapter11/InterOrUnion/stdafx.h @@ -0,0 +1,6 @@ +// stdafx.h : include file for standard system include files, +// or project specific include files that are used frequently, but +// are changed infrequently +#pragma once + +// TODO: reference additional headers your program requires here diff --git a/Chapter11/NewUnitsOrigin/AssemblyInfo.cpp b/Chapter11/NewUnitsOrigin/AssemblyInfo.cpp new file mode 100644 index 0000000..98064fa --- /dev/null +++ b/Chapter11/NewUnitsOrigin/AssemblyInfo.cpp @@ -0,0 +1,35 @@ +#include "stdafx.h" + +using namespace System::Reflection; +using namespace System::Runtime::CompilerServices; +using namespace System::Runtime::InteropServices; + +// +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +// +[assembly:AssemblyTitleAttribute("NewUnitsOrigin")]; +[assembly:AssemblyDescriptionAttribute("")]; +[assembly:AssemblyConfigurationAttribute("")]; +[assembly:AssemblyCompanyAttribute("")]; +[assembly:AssemblyProductAttribute("NewUnitsOrigin")]; +[assembly:AssemblyCopyrightAttribute("Copyright (c) 2005")]; +[assembly:AssemblyTrademarkAttribute("")]; +[assembly:AssemblyCultureAttribute("")]; + +// +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the value or you can default the Revision and Build Numbers +// by using the '*' as shown below: + +[assembly:AssemblyVersionAttribute("1.0.*")]; + +[assembly:ComVisible(false)]; + diff --git a/Chapter11/NewUnitsOrigin/Form1.h b/Chapter11/NewUnitsOrigin/Form1.h new file mode 100644 index 0000000..eb00041 --- /dev/null +++ b/Chapter11/NewUnitsOrigin/Form1.h @@ -0,0 +1,65 @@ +#pragma once + + +namespace NewUnitsOrigin { + + using namespace System; + using namespace System::ComponentModel; + using namespace System::Collections; + using namespace System::Windows::Forms; + using namespace System::Data; + using namespace System::Drawing; + + public ref class Form1 : public System::Windows::Forms::Form + { + public: + Form1(void) + { + InitializeComponent(); + } + + protected: + ~Form1() + { + if (components) + { + delete components; + } + } + + private: + System::ComponentModel::Container ^components; + +#pragma region Windows Form Designer generated code + void InitializeComponent(void) + { + this->SuspendLayout(); + this->AutoScaleDimensions = System::Drawing::SizeF(6, 13); + this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font; + this->ClientSize = System::Drawing::Size(341, 273); + this->Name = L"Form1"; + this->Text = L"Millimeter Unit of measure Origin (20,20)"; + this->Paint += + gcnew System::Windows::Forms::PaintEventHandler(this, + &Form1::Form1_Paint); + this->ResumeLayout(false); + } +#pragma endregion + + private: + System::Void Form1_Paint(System::Object^ sender, + System::Windows::Forms::PaintEventArgs^ e) + { + Graphics ^g = e->Graphics; + + // Draw a rectangle before unit of measure and origin change + g->DrawRectangle(Pens::Black, 5, 5, 50, 20); + + // Draw same rectangle after change + g->PageUnit = GraphicsUnit::Millimeter; + g->TranslateTransform(20,20); + g->DrawRectangle(Pens::Black, 5, 5, 50, 20); + } + }; +} + diff --git a/Chapter11/NewUnitsOrigin/Form1.resx b/Chapter11/NewUnitsOrigin/Form1.resx new file mode 100644 index 0000000..de824e1 --- /dev/null +++ b/Chapter11/NewUnitsOrigin/Form1.resx @@ -0,0 +1,110 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Chapter11/NewUnitsOrigin/NewUnitsOrigin.cpp b/Chapter11/NewUnitsOrigin/NewUnitsOrigin.cpp new file mode 100644 index 0000000..96f0c2c --- /dev/null +++ b/Chapter11/NewUnitsOrigin/NewUnitsOrigin.cpp @@ -0,0 +1,16 @@ +// NewUnitsOrigin.cpp : main project file. + +#include "stdafx.h" +#include "Form1.h" + +using namespace NewUnitsOrigin; + +[STAThreadAttribute] +int main(array ^args) +{ + // Enabling Windows XP visual effects before any controls are created + Application::EnableVisualStyles(); + // Create the main window and run it + Application::Run(gcnew Form1()); + return 0; +} diff --git a/Chapter11/NewUnitsOrigin/NewUnitsOrigin.vcproj b/Chapter11/NewUnitsOrigin/NewUnitsOrigin.vcproj new file mode 100644 index 0000000..cce472a --- /dev/null +++ b/Chapter11/NewUnitsOrigin/NewUnitsOrigin.vcproj @@ -0,0 +1,250 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Chapter11/NewUnitsOrigin/stdafx.cpp b/Chapter11/NewUnitsOrigin/stdafx.cpp new file mode 100644 index 0000000..2431710 --- /dev/null +++ b/Chapter11/NewUnitsOrigin/stdafx.cpp @@ -0,0 +1,7 @@ +// stdafx.cpp : source file that includes just the standard includes +// NewUnitsOrigin.pch will be the pre-compiled header +// stdafx.obj will contain the pre-compiled type information + +#include "stdafx.h" + + diff --git a/Chapter11/NewUnitsOrigin/stdafx.h b/Chapter11/NewUnitsOrigin/stdafx.h new file mode 100644 index 0000000..46bef73 --- /dev/null +++ b/Chapter11/NewUnitsOrigin/stdafx.h @@ -0,0 +1,6 @@ +// stdafx.h : include file for standard system include files, +// or project specific include files that are used frequently, but +// are changed infrequently +#pragma once + +// TODO: reference additional headers your program requires here diff --git a/Chapter11/OnPaintWhere/AssemblyInfo.cpp b/Chapter11/OnPaintWhere/AssemblyInfo.cpp new file mode 100644 index 0000000..9f3dd0b --- /dev/null +++ b/Chapter11/OnPaintWhere/AssemblyInfo.cpp @@ -0,0 +1,35 @@ +#include "stdafx.h" + +using namespace System::Reflection; +using namespace System::Runtime::CompilerServices; +using namespace System::Runtime::InteropServices; + +// +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +// +[assembly:AssemblyTitleAttribute("OnPaintWhere")]; +[assembly:AssemblyDescriptionAttribute("")]; +[assembly:AssemblyConfigurationAttribute("")]; +[assembly:AssemblyCompanyAttribute("")]; +[assembly:AssemblyProductAttribute("OnPaintWhere")]; +[assembly:AssemblyCopyrightAttribute("Copyright (c) 2005")]; +[assembly:AssemblyTrademarkAttribute("")]; +[assembly:AssemblyCultureAttribute("")]; + +// +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the value or you can default the Revision and Build Numbers +// by using the '*' as shown below: + +[assembly:AssemblyVersionAttribute("1.0.*")]; + +[assembly:ComVisible(false)]; + diff --git a/Chapter11/OnPaintWhere/Form1.h b/Chapter11/OnPaintWhere/Form1.h new file mode 100644 index 0000000..6e0f7ae --- /dev/null +++ b/Chapter11/OnPaintWhere/Form1.h @@ -0,0 +1,68 @@ +#pragma once + +namespace OnPaintWhere +{ + using namespace System; + using namespace System::ComponentModel; + using namespace System::Collections; + using namespace System::Windows::Forms; + using namespace System::Data; + using namespace System::Drawing; + + public ref class Form1 : public System::Windows::Forms::Form + { + public: + Form1(void) + { + InitializeComponent(); + } + + protected: + ~Form1() + { + if (components) + { + delete components; + } + } + + private: + System::ComponentModel::Container ^components; + +#pragma region Windows Form Designer generated code + void InitializeComponent(void) + { + this->SuspendLayout(); + this->AutoScaleDimensions = System::Drawing::SizeF(6, 13); + this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font; + this->ClientSize = System::Drawing::Size(292, 273); + this->Name = L"Form1"; + this->Text = L"Hello GDI+"; + this->Paint += + gcnew System::Windows::Forms::PaintEventHandler(this, + &Form1::Form1_Paint); + this->ResumeLayout(false); + } +#pragma endregion + + protected: + virtual void OnPaint(System::Windows::Forms::PaintEventArgs ^e) override + { +// Form::OnPaint(e); + + e->Graphics->DrawString("Hello GDI+", + gcnew Drawing::Font("Arial", 16), Brushes::Black, 75.0, 110.0); + + Form::OnPaint(e); + } + + private: + System::Void Form1_Paint(System::Object^ sender, + System::Windows::Forms::PaintEventArgs^ e) + { + e->Graphics->DrawString("Hello GDI+", + gcnew Drawing::Font("Arial", 16), Brushes::Purple, 75.0, 110.0); + } + }; +} + diff --git a/Chapter11/OnPaintWhere/Form1.resx b/Chapter11/OnPaintWhere/Form1.resx new file mode 100644 index 0000000..de824e1 --- /dev/null +++ b/Chapter11/OnPaintWhere/Form1.resx @@ -0,0 +1,110 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Chapter11/OnPaintWhere/OnPaintWhere.cpp b/Chapter11/OnPaintWhere/OnPaintWhere.cpp new file mode 100644 index 0000000..a413b82 --- /dev/null +++ b/Chapter11/OnPaintWhere/OnPaintWhere.cpp @@ -0,0 +1,16 @@ +// OnPaintWhere.cpp : main project file. + +#include "stdafx.h" +#include "Form1.h" + +using namespace OnPaintWhere; + +[STAThreadAttribute] +int main(array ^args) +{ + // Enabling Windows XP visual effects before any controls are created + Application::EnableVisualStyles(); + // Create the main window and run it + Application::Run(gcnew Form1()); + return 0; +} diff --git a/Chapter11/OnPaintWhere/OnPaintWhere.vcproj b/Chapter11/OnPaintWhere/OnPaintWhere.vcproj new file mode 100644 index 0000000..3f61551 --- /dev/null +++ b/Chapter11/OnPaintWhere/OnPaintWhere.vcproj @@ -0,0 +1,250 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Chapter11/OnPaintWhere/stdafx.cpp b/Chapter11/OnPaintWhere/stdafx.cpp new file mode 100644 index 0000000..0d99dc3 --- /dev/null +++ b/Chapter11/OnPaintWhere/stdafx.cpp @@ -0,0 +1,7 @@ +// stdafx.cpp : source file that includes just the standard includes +// OnPaintWhere.pch will be the pre-compiled header +// stdafx.obj will contain the pre-compiled type information + +#include "stdafx.h" + + diff --git a/Chapter11/OnPaintWhere/stdafx.h b/Chapter11/OnPaintWhere/stdafx.h new file mode 100644 index 0000000..46bef73 --- /dev/null +++ b/Chapter11/OnPaintWhere/stdafx.h @@ -0,0 +1,6 @@ +// stdafx.h : include file for standard system include files, +// or project specific include files that are used frequently, but +// are changed infrequently +#pragma once + +// TODO: reference additional headers your program requires here diff --git a/Chapter11/OptimizedHappyFace/AssemblyInfo.cpp b/Chapter11/OptimizedHappyFace/AssemblyInfo.cpp new file mode 100644 index 0000000..556b8ba --- /dev/null +++ b/Chapter11/OptimizedHappyFace/AssemblyInfo.cpp @@ -0,0 +1,35 @@ +#include "stdafx.h" + +using namespace System::Reflection; +using namespace System::Runtime::CompilerServices; +using namespace System::Runtime::InteropServices; + +// +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +// +[assembly:AssemblyTitleAttribute("OptimizedHappyFace")]; +[assembly:AssemblyDescriptionAttribute("")]; +[assembly:AssemblyConfigurationAttribute("")]; +[assembly:AssemblyCompanyAttribute("")]; +[assembly:AssemblyProductAttribute("OptimizedHappyFace")]; +[assembly:AssemblyCopyrightAttribute("Copyright (c) 2005")]; +[assembly:AssemblyTrademarkAttribute("")]; +[assembly:AssemblyCultureAttribute("")]; + +// +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the value or you can default the Revision and Build Numbers +// by using the '*' as shown below: + +[assembly:AssemblyVersionAttribute("1.0.*")]; + +[assembly:ComVisible(false)]; + diff --git a/Chapter11/OptimizedHappyFace/Form1.h b/Chapter11/OptimizedHappyFace/Form1.h new file mode 100644 index 0000000..12c10de --- /dev/null +++ b/Chapter11/OptimizedHappyFace/Form1.h @@ -0,0 +1,100 @@ +#pragma once + +namespace OptimizedHappyFace +{ + using namespace System; + using namespace System::ComponentModel; + using namespace System::Collections; + using namespace System::Windows::Forms; + using namespace System::Data; + using namespace System::Drawing; + + public ref class Form1 : public System::Windows::Forms::Form + { + public: + Form1(void) + { + InitializeComponent(); + + Head = Drawing::Rectangle(125, 25, 250, 250); + Mouth = Drawing::Rectangle(200, 175, 100, 50); + LEye = Drawing::Rectangle(200, 100, 25, 25); + REye = Drawing::Rectangle(275, 100, 25, 25); + + b4pen = gcnew Pen(Color::Black, 4); + } + + protected: + ~Form1() + { + if (components) + { + delete components; + } + } + + private: + System::ComponentModel::Container ^components; + + System::Drawing::Rectangle Head; + System::Drawing::Rectangle Mouth; + System::Drawing::Rectangle LEye; + System::Drawing::Rectangle REye; + Pen^ b4pen; + +#pragma region Windows Form Designer generated code + void InitializeComponent(void) + { + this->SuspendLayout(); + + this->AutoScrollMinSize = System::Drawing::Size(400,400); + + this->AutoScaleDimensions = System::Drawing::SizeF(6, 13); + this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font; + this->ClientSize = System::Drawing::Size(292, 273); + this->Name = L"Form1"; + this->Text = L"Optimized Happy Face"; + this->Paint += + gcnew System::Windows::Forms::PaintEventHandler(this, + &Form1::Form1_Paint); + this->ResumeLayout(false); + } +#pragma endregion + + private: + System::Void Form1_Paint(System::Object^ sender, + System::Windows::Forms::PaintEventArgs^ e) + { + Graphics^ g = e->Graphics; + + Drawing::Rectangle ClipRect = e->ClipRectangle; + ClipRect.Offset(-AutoScrollPosition.X, -AutoScrollPosition.Y); + + g->TranslateTransform((float)AutoScrollPosition.X, + (float)AutoScrollPosition.Y); + + if (!(Rectangle::Intersect(ClipRect, Head)).IsEmpty) + { + g->FillEllipse(Brushes::Yellow, Head); + g->DrawEllipse(b4pen, Head); + + if (!(Rectangle::Intersect(ClipRect, Mouth)).IsEmpty) + { + g->FillPie(Brushes::White, Mouth, 0, 180); + g->DrawPie(b4pen, Mouth, 0, 180); + } + if (!(Rectangle::Intersect(ClipRect, LEye)).IsEmpty) + { + g->FillEllipse(Brushes::White, LEye); + g->DrawEllipse(b4pen, LEye); + } + if (!(Rectangle::Intersect(ClipRect, REye)).IsEmpty) + { + g->FillEllipse(Brushes::White, REye); + g->DrawEllipse(b4pen, REye); + } + } + } + }; +} + diff --git a/Chapter11/OptimizedHappyFace/Form1.resx b/Chapter11/OptimizedHappyFace/Form1.resx new file mode 100644 index 0000000..de824e1 --- /dev/null +++ b/Chapter11/OptimizedHappyFace/Form1.resx @@ -0,0 +1,110 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Chapter11/OptimizedHappyFace/OptimizedHappyFace.cpp b/Chapter11/OptimizedHappyFace/OptimizedHappyFace.cpp new file mode 100644 index 0000000..8494607 --- /dev/null +++ b/Chapter11/OptimizedHappyFace/OptimizedHappyFace.cpp @@ -0,0 +1,16 @@ +// OptimizedHappyFace.cpp : main project file. + +#include "stdafx.h" +#include "Form1.h" + +using namespace OptimizedHappyFace; + +[STAThreadAttribute] +int main(array ^args) +{ + // Enabling Windows XP visual effects before any controls are created + Application::EnableVisualStyles(); + // Create the main window and run it + Application::Run(gcnew Form1()); + return 0; +} diff --git a/Chapter11/OptimizedHappyFace/OptimizedHappyFace.vcproj b/Chapter11/OptimizedHappyFace/OptimizedHappyFace.vcproj new file mode 100644 index 0000000..489a9d2 --- /dev/null +++ b/Chapter11/OptimizedHappyFace/OptimizedHappyFace.vcproj @@ -0,0 +1,250 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Chapter11/OptimizedHappyFace/stdafx.cpp b/Chapter11/OptimizedHappyFace/stdafx.cpp new file mode 100644 index 0000000..aa4d3ea --- /dev/null +++ b/Chapter11/OptimizedHappyFace/stdafx.cpp @@ -0,0 +1,7 @@ +// stdafx.cpp : source file that includes just the standard includes +// OptimizedHappyFace.pch will be the pre-compiled header +// stdafx.obj will contain the pre-compiled type information + +#include "stdafx.h" + + diff --git a/Chapter11/OptimizedHappyFace/stdafx.h b/Chapter11/OptimizedHappyFace/stdafx.h new file mode 100644 index 0000000..46bef73 --- /dev/null +++ b/Chapter11/OptimizedHappyFace/stdafx.h @@ -0,0 +1,6 @@ +// stdafx.h : include file for standard system include files, +// or project specific include files that are used frequently, but +// are changed infrequently +#pragma once + +// TODO: reference additional headers your program requires here diff --git a/Chapter11/PrintHappyFace/AssemblyInfo.cpp b/Chapter11/PrintHappyFace/AssemblyInfo.cpp new file mode 100644 index 0000000..7cbb247 --- /dev/null +++ b/Chapter11/PrintHappyFace/AssemblyInfo.cpp @@ -0,0 +1,35 @@ +#include "stdafx.h" + +using namespace System::Reflection; +using namespace System::Runtime::CompilerServices; +using namespace System::Runtime::InteropServices; + +// +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +// +[assembly:AssemblyTitleAttribute("PrintHappyFace")]; +[assembly:AssemblyDescriptionAttribute("")]; +[assembly:AssemblyConfigurationAttribute("")]; +[assembly:AssemblyCompanyAttribute("")]; +[assembly:AssemblyProductAttribute("PrintHappyFace")]; +[assembly:AssemblyCopyrightAttribute("Copyright (c) 2005")]; +[assembly:AssemblyTrademarkAttribute("")]; +[assembly:AssemblyCultureAttribute("")]; + +// +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the value or you can default the Revision and Build Numbers +// by using the '*' as shown below: + +[assembly:AssemblyVersionAttribute("1.0.*")]; + +[assembly:ComVisible(false)]; + diff --git a/Chapter11/PrintHappyFace/Form1.h b/Chapter11/PrintHappyFace/Form1.h new file mode 100644 index 0000000..4cca86a --- /dev/null +++ b/Chapter11/PrintHappyFace/Form1.h @@ -0,0 +1,115 @@ +#pragma once + +namespace PrintHappyFace +{ + using namespace System; + using namespace System::ComponentModel; + using namespace System::Collections; + using namespace System::Windows::Forms; + using namespace System::Data; + using namespace System::Drawing; + + public ref class Form1 : public System::Windows::Forms::Form + { + public: + Form1(void) + { + InitializeComponent(); + } + + protected: + ~Form1() + { + if (components) + { + delete components; + } + } + private: + System::Drawing::Printing::PrintDocument^ printDocument; + System::Windows::Forms::PrintDialog^ printDialog; + System::ComponentModel::Container ^components; + +#pragma region Windows Form Designer generated code + + void InitializeComponent(void) + { + this->printDocument = + (gcnew System::Drawing::Printing::PrintDocument()); + this->printDialog = (gcnew System::Windows::Forms::PrintDialog()); + this->SuspendLayout(); + // + // printDocument + // + this->printDocument->PrintPage += + gcnew System::Drawing::Printing::PrintPageEventHandler(this, + &Form1::printDocument_PrintPage); + // + // printDialog + // + this->printDialog->Document = this->printDocument; + // + // Form1 + // + this->AutoScaleDimensions = System::Drawing::SizeF(6, 13); + this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font; + this->ClientSize = System::Drawing::Size(300, 300); + this->Name = L"Form1"; + this->Text = L"Click to Print"; + this->Paint += + gcnew System::Windows::Forms::PaintEventHandler(this, + &Form1::Form1_Paint); + this->Click += + gcnew System::EventHandler(this, &Form1::Form1_Click); + this->ResumeLayout(false); + } +#pragma endregion + + private: + System::Void Form1_Click(System::Object^ sender, System::EventArgs^ e) + { + // Display Print dialog when mouse pressed + if (printDialog->ShowDialog() == Windows::Forms::DialogResult::OK) + { + printDocument->Print(); + } + } + + System::Void printDocument_PrintPage(System::Object^ sender, + System::Drawing::Printing::PrintPageEventArgs^ e) + { + CreateHappyFace(e->Graphics); //Same call as Form1_Paint + e->HasMorePages = false; + } + + System::Void Form1_Paint(System::Object^ sender, + System::Windows::Forms::PaintEventArgs^ e) + { + CreateHappyFace(e->Graphics);//Same call as printDocument_PrintPage + } + + // Generic Happy Face Creator + void CreateHappyFace(Graphics ^g) + { + Pen^ b4pen = gcnew Pen(Color::Black, 4); + + Rectangle rect = Drawing::Rectangle(25, 25, 250, 250); + g->FillEllipse(Brushes::Yellow, rect); + g->DrawEllipse(b4pen, rect); + + g->FillPie(Brushes::White, 100, 175, 100, 50, 0, 180); + g->DrawPie(b4pen, 100, 175, 100, 50, 0, 180); + + rect = Drawing::Rectangle(100, 100, 25, 25); + g->FillEllipse(Brushes::White, rect); + g->DrawEllipse(b4pen, rect); + + rect = Drawing::Rectangle(175, 100, 25, 25); + g->FillEllipse(Brushes::White, rect); + g->DrawEllipse(b4pen, rect); + + delete b4pen; + } + }; +} + diff --git a/Chapter11/PrintHappyFace/Form1.resx b/Chapter11/PrintHappyFace/Form1.resx new file mode 100644 index 0000000..5995a90 --- /dev/null +++ b/Chapter11/PrintHappyFace/Form1.resx @@ -0,0 +1,126 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 17, 17 + + + 148, 17 + + \ No newline at end of file diff --git a/Chapter11/PrintHappyFace/PrintHappyFace.cpp b/Chapter11/PrintHappyFace/PrintHappyFace.cpp new file mode 100644 index 0000000..04b5e99 --- /dev/null +++ b/Chapter11/PrintHappyFace/PrintHappyFace.cpp @@ -0,0 +1,16 @@ +// PrintHappyFace.cpp : main project file. + +#include "stdafx.h" +#include "Form1.h" + +using namespace PrintHappyFace; + +[STAThreadAttribute] +int main(array ^args) +{ + // Enabling Windows XP visual effects before any controls are created + Application::EnableVisualStyles(); + // Create the main window and run it + Application::Run(gcnew Form1()); + return 0; +} diff --git a/Chapter11/PrintHappyFace/PrintHappyFace.vcproj b/Chapter11/PrintHappyFace/PrintHappyFace.vcproj new file mode 100644 index 0000000..60f3138 --- /dev/null +++ b/Chapter11/PrintHappyFace/PrintHappyFace.vcproj @@ -0,0 +1,250 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Chapter11/PrintHappyFace/stdafx.cpp b/Chapter11/PrintHappyFace/stdafx.cpp new file mode 100644 index 0000000..039160b --- /dev/null +++ b/Chapter11/PrintHappyFace/stdafx.cpp @@ -0,0 +1,7 @@ +// stdafx.cpp : source file that includes just the standard includes +// PrintHappyFace.pch will be the pre-compiled header +// stdafx.obj will contain the pre-compiled type information + +#include "stdafx.h" + + diff --git a/Chapter11/PrintHappyFace/stdafx.h b/Chapter11/PrintHappyFace/stdafx.h new file mode 100644 index 0000000..46bef73 --- /dev/null +++ b/Chapter11/PrintHappyFace/stdafx.h @@ -0,0 +1,6 @@ +// stdafx.h : include file for standard system include files, +// or project specific include files that are used frequently, but +// are changed infrequently +#pragma once + +// TODO: reference additional headers your program requires here diff --git a/Chapter11/RegionEx/AssemblyInfo.cpp b/Chapter11/RegionEx/AssemblyInfo.cpp new file mode 100644 index 0000000..9d00177 --- /dev/null +++ b/Chapter11/RegionEx/AssemblyInfo.cpp @@ -0,0 +1,35 @@ +#include "stdafx.h" + +using namespace System::Reflection; +using namespace System::Runtime::CompilerServices; +using namespace System::Runtime::InteropServices; + +// +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +// +[assembly:AssemblyTitleAttribute("RegionEx")]; +[assembly:AssemblyDescriptionAttribute("")]; +[assembly:AssemblyConfigurationAttribute("")]; +[assembly:AssemblyCompanyAttribute("")]; +[assembly:AssemblyProductAttribute("RegionEx")]; +[assembly:AssemblyCopyrightAttribute("Copyright (c) 2005")]; +[assembly:AssemblyTrademarkAttribute("")]; +[assembly:AssemblyCultureAttribute("")]; + +// +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the value or you can default the Revision and Build Numbers +// by using the '*' as shown below: + +[assembly:AssemblyVersionAttribute("1.0.*")]; + +[assembly:ComVisible(false)]; + diff --git a/Chapter11/RegionEx/Form1.h b/Chapter11/RegionEx/Form1.h new file mode 100644 index 0000000..638e64b --- /dev/null +++ b/Chapter11/RegionEx/Form1.h @@ -0,0 +1,66 @@ +#pragma once + +namespace RegionEx { + + using namespace System; + using namespace System::ComponentModel; + using namespace System::Collections; + using namespace System::Windows::Forms; + using namespace System::Data; + using namespace System::Drawing; + + public ref class Form1 : public System::Windows::Forms::Form + { + public: + Form1(void) + { + InitializeComponent(); + + Drawing::Point point1 = Drawing::Point(25,25); + Drawing::Point point2 = Drawing::Point(100,100); + Drawing::Size size = Drawing::Size(200, 150); + Rectangle rect1 = Drawing::Rectangle(point1, size); + Rectangle rect2 = Drawing::Rectangle(point2, size); + + region = gcnew Drawing::Region(rect1); + region->Xor(rect2); + } + + protected: + ~Form1() + { + if (components) + { + delete components; + } + } + + private: + System::ComponentModel::Container ^components; + Drawing::Region ^region; + +#pragma region Windows Form Designer generated code + void InitializeComponent(void) + { + this->SuspendLayout(); + this->AutoScaleDimensions = System::Drawing::SizeF(6, 13); + this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font; + this->ClientSize = System::Drawing::Size(322, 273); + this->Name = L"Form1"; + this->Text = L"Filling A Region"; + this->Paint += + gcnew System::Windows::Forms::PaintEventHandler(this, + &Form1::Form1_Paint); + this->ResumeLayout(false); + } +#pragma endregion + + private: + System::Void Form1_Paint(System::Object^ sender, + System::Windows::Forms::PaintEventArgs^ e) + { + e->Graphics->FillRegion(Brushes::Blue, region); + } + }; +} + diff --git a/Chapter11/RegionEx/Form1.resx b/Chapter11/RegionEx/Form1.resx new file mode 100644 index 0000000..de824e1 --- /dev/null +++ b/Chapter11/RegionEx/Form1.resx @@ -0,0 +1,110 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Chapter11/RegionEx/RegionEx.cpp b/Chapter11/RegionEx/RegionEx.cpp new file mode 100644 index 0000000..6917c40 --- /dev/null +++ b/Chapter11/RegionEx/RegionEx.cpp @@ -0,0 +1,16 @@ +// RegionEx.cpp : main project file. + +#include "stdafx.h" +#include "Form1.h" + +using namespace RegionEx; + +[STAThreadAttribute] +int main(array ^args) +{ + // Enabling Windows XP visual effects before any controls are created + Application::EnableVisualStyles(); + // Create the main window and run it + Application::Run(gcnew Form1()); + return 0; +} diff --git a/Chapter11/RegionEx/RegionEx.vcproj b/Chapter11/RegionEx/RegionEx.vcproj new file mode 100644 index 0000000..e6d6509 --- /dev/null +++ b/Chapter11/RegionEx/RegionEx.vcproj @@ -0,0 +1,250 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Chapter11/RegionEx/stdafx.cpp b/Chapter11/RegionEx/stdafx.cpp new file mode 100644 index 0000000..436cd29 --- /dev/null +++ b/Chapter11/RegionEx/stdafx.cpp @@ -0,0 +1,7 @@ +// stdafx.cpp : source file that includes just the standard includes +// RegionEx.pch will be the pre-compiled header +// stdafx.obj will contain the pre-compiled type information + +#include "stdafx.h" + + diff --git a/Chapter11/RegionEx/stdafx.h b/Chapter11/RegionEx/stdafx.h new file mode 100644 index 0000000..46bef73 --- /dev/null +++ b/Chapter11/RegionEx/stdafx.h @@ -0,0 +1,6 @@ +// stdafx.h : include file for standard system include files, +// or project specific include files that are used frequently, but +// are changed infrequently +#pragma once + +// TODO: reference additional headers your program requires here diff --git a/Chapter11/ScrollingHappyFace/AssemblyInfo.cpp b/Chapter11/ScrollingHappyFace/AssemblyInfo.cpp new file mode 100644 index 0000000..7b4c675 --- /dev/null +++ b/Chapter11/ScrollingHappyFace/AssemblyInfo.cpp @@ -0,0 +1,35 @@ +#include "stdafx.h" + +using namespace System::Reflection; +using namespace System::Runtime::CompilerServices; +using namespace System::Runtime::InteropServices; + +// +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +// +[assembly:AssemblyTitleAttribute("ScrollingHappyFace")]; +[assembly:AssemblyDescriptionAttribute("")]; +[assembly:AssemblyConfigurationAttribute("")]; +[assembly:AssemblyCompanyAttribute("")]; +[assembly:AssemblyProductAttribute("ScrollingHappyFace")]; +[assembly:AssemblyCopyrightAttribute("Copyright (c) 2005")]; +[assembly:AssemblyTrademarkAttribute("")]; +[assembly:AssemblyCultureAttribute("")]; + +// +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the value or you can default the Revision and Build Numbers +// by using the '*' as shown below: + +[assembly:AssemblyVersionAttribute("1.0.*")]; + +[assembly:ComVisible(false)]; + diff --git a/Chapter11/ScrollingHappyFace/Form1.h b/Chapter11/ScrollingHappyFace/Form1.h new file mode 100644 index 0000000..93da792 --- /dev/null +++ b/Chapter11/ScrollingHappyFace/Form1.h @@ -0,0 +1,83 @@ +#pragma once + +namespace ScrollingHappyFace +{ + using namespace System; + using namespace System::ComponentModel; + using namespace System::Collections; + using namespace System::Windows::Forms; + using namespace System::Data; + using namespace System::Drawing; + + public ref class Form1 : public System::Windows::Forms::Form + { + public: + Form1(void) + { + InitializeComponent(); + } + + protected: + ~Form1() + { + if (components) + { + delete components; + } + } + + private: + System::ComponentModel::Container ^components; + +#pragma region Windows Form Designer generated code + void InitializeComponent(void) + { + this->SuspendLayout(); + + this->AutoScrollMinSize = System::Drawing::Size(400,400); + + this->AutoScaleDimensions = System::Drawing::SizeF(6, 13); + this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font; + this->ClientSize = System::Drawing::Size(292, 273); + this->Name = L"Form1"; + this->Text = L"Scrolling Happy Face"; + this->Paint += gcnew System::Windows::Forms::PaintEventHandler(this, &Form1::Form1_Paint); + this->ResumeLayout(false); + + } +#pragma endregion + + private: + System::Void Form1_Paint(System::Object^ sender, + System::Windows::Forms::PaintEventArgs^ e) + { + Graphics^ g = e->Graphics; + g->TranslateTransform((float)AutoScrollPosition.X, + (float)AutoScrollPosition.Y); + + Pen^ b4pen = gcnew Pen(Color::Black, 4); + + // Head + Rectangle rect = Drawing::Rectangle(25, 25, 250, 250); + g->FillEllipse(Brushes::Yellow, rect); + g->DrawEllipse(b4pen, rect); + + // Mouth + g->FillPie(Brushes::White, 100, 175, 100, 50, 0, 180); + g->DrawPie(b4pen, 100, 175, 100, 50, 0, 180); + + // Left Eye + rect = Drawing::Rectangle(100, 100, 25, 25); + g->FillEllipse(Brushes::White, rect); + g->DrawEllipse(b4pen, rect); + + // Right Eye + rect = Drawing::Rectangle(175, 100, 25, 25); + g->FillEllipse(Brushes::White, rect); + g->DrawEllipse(b4pen, rect); + + // Get rid of pen Created + delete b4pen; + } + }; +} \ No newline at end of file diff --git a/Chapter11/ScrollingHappyFace/Form1.resx b/Chapter11/ScrollingHappyFace/Form1.resx new file mode 100644 index 0000000..de824e1 --- /dev/null +++ b/Chapter11/ScrollingHappyFace/Form1.resx @@ -0,0 +1,110 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Chapter11/ScrollingHappyFace/ScrollingHappyFace.cpp b/Chapter11/ScrollingHappyFace/ScrollingHappyFace.cpp new file mode 100644 index 0000000..5e5ed11 --- /dev/null +++ b/Chapter11/ScrollingHappyFace/ScrollingHappyFace.cpp @@ -0,0 +1,16 @@ +// ScrollingHappyFace.cpp : main project file. + +#include "stdafx.h" +#include "Form1.h" + +using namespace ScrollingHappyFace; + +[STAThreadAttribute] +int main(array ^args) +{ + // Enabling Windows XP visual effects before any controls are created + Application::EnableVisualStyles(); + // Create the main window and run it + Application::Run(gcnew Form1()); + return 0; +} diff --git a/Chapter11/ScrollingHappyFace/ScrollingHappyFace.vcproj b/Chapter11/ScrollingHappyFace/ScrollingHappyFace.vcproj new file mode 100644 index 0000000..cc45ecc --- /dev/null +++ b/Chapter11/ScrollingHappyFace/ScrollingHappyFace.vcproj @@ -0,0 +1,250 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Chapter11/ScrollingHappyFace/stdafx.cpp b/Chapter11/ScrollingHappyFace/stdafx.cpp new file mode 100644 index 0000000..9d5103c --- /dev/null +++ b/Chapter11/ScrollingHappyFace/stdafx.cpp @@ -0,0 +1,7 @@ +// stdafx.cpp : source file that includes just the standard includes +// ScrollingHappyFace.pch will be the pre-compiled header +// stdafx.obj will contain the pre-compiled type information + +#include "stdafx.h" + + diff --git a/Chapter11/ScrollingHappyFace/stdafx.h b/Chapter11/ScrollingHappyFace/stdafx.h new file mode 100644 index 0000000..46bef73 --- /dev/null +++ b/Chapter11/ScrollingHappyFace/stdafx.h @@ -0,0 +1,6 @@ +// stdafx.h : include file for standard system include files, +// or project specific include files that are used frequently, but +// are changed infrequently +#pragma once + +// TODO: reference additional headers your program requires here diff --git a/Chapter11/SingleBuffering/AssemblyInfo.cpp b/Chapter11/SingleBuffering/AssemblyInfo.cpp new file mode 100644 index 0000000..895a4b6 --- /dev/null +++ b/Chapter11/SingleBuffering/AssemblyInfo.cpp @@ -0,0 +1,35 @@ +#include "stdafx.h" + +using namespace System::Reflection; +using namespace System::Runtime::CompilerServices; +using namespace System::Runtime::InteropServices; + +// +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +// +[assembly:AssemblyTitleAttribute("SingleBuffering")]; +[assembly:AssemblyDescriptionAttribute("")]; +[assembly:AssemblyConfigurationAttribute("")]; +[assembly:AssemblyCompanyAttribute("")]; +[assembly:AssemblyProductAttribute("SingleBuffering")]; +[assembly:AssemblyCopyrightAttribute("Copyright (c) 2005")]; +[assembly:AssemblyTrademarkAttribute("")]; +[assembly:AssemblyCultureAttribute("")]; + +// +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the value or you can default the Revision and Build Numbers +// by using the '*' as shown below: + +[assembly:AssemblyVersionAttribute("1.0.*")]; + +[assembly:ComVisible(false)]; + diff --git a/Chapter11/SingleBuffering/Form1.h b/Chapter11/SingleBuffering/Form1.h new file mode 100644 index 0000000..47f8f5a --- /dev/null +++ b/Chapter11/SingleBuffering/Form1.h @@ -0,0 +1,110 @@ +#pragma once + + +namespace SingleBuffering +{ + using namespace System; + using namespace System::ComponentModel; + using namespace System::Collections; + using namespace System::Windows::Forms; + using namespace System::Data; + using namespace System::Drawing; + + public ref class Form1 : public System::Windows::Forms::Form + { + public: + Form1(void) + { + InitializeComponent(); + X = -250; // Preset to be just left of window + } + + protected: + ~Form1() + { + if (components) + { + delete components; + } + } + private: + System::Windows::Forms::Timer^ timer1; + System::ComponentModel::IContainer^ components; + + float X; // Actual x coordinate of Happy face + + +#pragma region Windows Form Designer generated code + + void InitializeComponent(void) + { + this->components = (gcnew System::ComponentModel::Container()); + this->timer1 = + (gcnew System::Windows::Forms::Timer(this->components)); + this->SuspendLayout(); + // + // timer1 + // + this->timer1->Enabled = true; + this->timer1->Interval = 10; + this->timer1->Tick += + gcnew System::EventHandler(this, &Form1::timer1_Tick); + // + // Form1 + // + this->AutoScaleDimensions = System::Drawing::SizeF(6, 13); + this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font; + this->ClientSize = System::Drawing::Size(500, 300); + this->Name = L"Form1"; + this->Text = L"Form1"; + this->Paint += + gcnew System::Windows::Forms::PaintEventHandler(this, + &Form1::Form1_Paint); + this->ResumeLayout(false); + + } +#pragma endregion + private: + System::Void Form1_Paint(System::Object^ sender, + System::Windows::Forms::PaintEventArgs^ e) + { + Graphics^ g = e->Graphics; + + // Move image at end of line start from beginning + if (X < ClientRectangle.Width) + X += 1.0; + else + X = -250.0; + + g->TranslateTransform(X, 25.0); + + // redraw images from scratch + Pen^ b4pen = gcnew Pen(Color::Black, 4); + + Drawing::Rectangle Head = Drawing::Rectangle(0, 0, 250, 250); + g->FillEllipse(Brushes::Yellow, Head); + g->DrawEllipse(b4pen, Head); + + Drawing::Rectangle Mouth = Drawing::Rectangle(75, 150, 100, 50); + g->FillPie(Brushes::White, Mouth,0,180); + g->DrawPie(b4pen, Mouth, 0, 180); + + Drawing::Rectangle LEye = Drawing::Rectangle(75, 75, 25, 25); + g->FillEllipse(Brushes::White, LEye); + g->DrawEllipse(b4pen, LEye); + + Drawing::Rectangle REye = Drawing::Rectangle(150, 75, 25, 25); + g->FillEllipse(Brushes::White, REye); + g->DrawEllipse(b4pen, REye); + + delete b4pen; + } + + System::Void timer1_Tick(System::Object^ sender, System::EventArgs^ e) + { + // Move the image + Invalidate(); + } + }; +} + diff --git a/Chapter11/SingleBuffering/Form1.resx b/Chapter11/SingleBuffering/Form1.resx new file mode 100644 index 0000000..886d0de --- /dev/null +++ b/Chapter11/SingleBuffering/Form1.resx @@ -0,0 +1,123 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 17, 17 + + \ No newline at end of file diff --git a/Chapter11/SingleBuffering/SingleBuffering.cpp b/Chapter11/SingleBuffering/SingleBuffering.cpp new file mode 100644 index 0000000..761b334 --- /dev/null +++ b/Chapter11/SingleBuffering/SingleBuffering.cpp @@ -0,0 +1,16 @@ +// SingleBuffering.cpp : main project file. + +#include "stdafx.h" +#include "Form1.h" + +using namespace SingleBuffering; + +[STAThreadAttribute] +int main(array ^args) +{ + // Enabling Windows XP visual effects before any controls are created + Application::EnableVisualStyles(); + // Create the main window and run it + Application::Run(gcnew Form1()); + return 0; +} diff --git a/Chapter11/SingleBuffering/SingleBuffering.vcproj b/Chapter11/SingleBuffering/SingleBuffering.vcproj new file mode 100644 index 0000000..d69c132 --- /dev/null +++ b/Chapter11/SingleBuffering/SingleBuffering.vcproj @@ -0,0 +1,250 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Chapter11/SingleBuffering/stdafx.cpp b/Chapter11/SingleBuffering/stdafx.cpp new file mode 100644 index 0000000..2fc42b5 --- /dev/null +++ b/Chapter11/SingleBuffering/stdafx.cpp @@ -0,0 +1,7 @@ +// stdafx.cpp : source file that includes just the standard includes +// SingleBuffering.pch will be the pre-compiled header +// stdafx.obj will contain the pre-compiled type information + +#include "stdafx.h" + + diff --git a/Chapter11/SingleBuffering/stdafx.h b/Chapter11/SingleBuffering/stdafx.h new file mode 100644 index 0000000..46bef73 --- /dev/null +++ b/Chapter11/SingleBuffering/stdafx.h @@ -0,0 +1,6 @@ +// stdafx.h : include file for standard system include files, +// or project specific include files that are used frequently, but +// are changed infrequently +#pragma once + +// TODO: reference additional headers your program requires here diff --git a/Chapter11/StringRect/AssemblyInfo.cpp b/Chapter11/StringRect/AssemblyInfo.cpp new file mode 100644 index 0000000..f30ca73 --- /dev/null +++ b/Chapter11/StringRect/AssemblyInfo.cpp @@ -0,0 +1,35 @@ +#include "stdafx.h" + +using namespace System::Reflection; +using namespace System::Runtime::CompilerServices; +using namespace System::Runtime::InteropServices; + +// +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +// +[assembly:AssemblyTitleAttribute("StringRect")]; +[assembly:AssemblyDescriptionAttribute("")]; +[assembly:AssemblyConfigurationAttribute("")]; +[assembly:AssemblyCompanyAttribute("")]; +[assembly:AssemblyProductAttribute("StringRect")]; +[assembly:AssemblyCopyrightAttribute("Copyright (c) 2005")]; +[assembly:AssemblyTrademarkAttribute("")]; +[assembly:AssemblyCultureAttribute("")]; + +// +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the value or you can default the Revision and Build Numbers +// by using the '*' as shown below: + +[assembly:AssemblyVersionAttribute("1.0.*")]; + +[assembly:ComVisible(false)]; + diff --git a/Chapter11/StringRect/Form1.h b/Chapter11/StringRect/Form1.h new file mode 100644 index 0000000..713878b --- /dev/null +++ b/Chapter11/StringRect/Form1.h @@ -0,0 +1,62 @@ +#pragma once + +namespace StringRect +{ + using namespace System; + using namespace System::ComponentModel; + using namespace System::Collections; + using namespace System::Windows::Forms; + using namespace System::Data; + using namespace System::Drawing; + + public ref class Form1 : public System::Windows::Forms::Form + { + public: + Form1(void) + { + InitializeComponent(); + } + + protected: + ~Form1() + { + if (components) + { + delete components; + } + } + + private: + System::ComponentModel::Container ^components; + +#pragma region Windows Form Designer generated code + void InitializeComponent(void) + { + this->SuspendLayout(); + this->AutoScaleDimensions = System::Drawing::SizeF(6, 13); + this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font; + this->ClientSize = System::Drawing::Size(292, 273); + this->Name = L"Form1"; + this->Text = L"String in a Rectangle"; + this->Paint += + gcnew System::Windows::Forms::PaintEventHandler(this, + &Form1::Form1_Paint); + this->ResumeLayout(false); + } +#pragma endregion + + private: + System::Void Form1_Paint(System::Object^ sender, + System::Windows::Forms::PaintEventArgs^ e) + { + // Draw the string + e->Graphics->DrawString( + "Let's draw string to a rectangle and go a little " + "overboard on the size of the string that we place " + "inside of it", + gcnew Drawing::Font(gcnew FontFamily("Arial"), 12), + Brushes::Black, Drawing::RectangleF(20.0, 40.0, 260.0, 50.0)); + } + }; +} + diff --git a/Chapter11/StringRect/Form1.resx b/Chapter11/StringRect/Form1.resx new file mode 100644 index 0000000..de824e1 --- /dev/null +++ b/Chapter11/StringRect/Form1.resx @@ -0,0 +1,110 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Chapter11/StringRect/StringRect.cpp b/Chapter11/StringRect/StringRect.cpp new file mode 100644 index 0000000..236d8f7 --- /dev/null +++ b/Chapter11/StringRect/StringRect.cpp @@ -0,0 +1,16 @@ +// StringRect.cpp : main project file. + +#include "stdafx.h" +#include "Form1.h" + +using namespace StringRect; + +[STAThreadAttribute] +int main(array ^args) +{ + // Enabling Windows XP visual effects before any controls are created + Application::EnableVisualStyles(); + // Create the main window and run it + Application::Run(gcnew Form1()); + return 0; +} diff --git a/Chapter11/StringRect/StringRect.vcproj b/Chapter11/StringRect/StringRect.vcproj new file mode 100644 index 0000000..6065c76 --- /dev/null +++ b/Chapter11/StringRect/StringRect.vcproj @@ -0,0 +1,250 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Chapter11/StringRect/stdafx.cpp b/Chapter11/StringRect/stdafx.cpp new file mode 100644 index 0000000..4fdd513 --- /dev/null +++ b/Chapter11/StringRect/stdafx.cpp @@ -0,0 +1,7 @@ +// stdafx.cpp : source file that includes just the standard includes +// StringRect.pch will be the pre-compiled header +// stdafx.obj will contain the pre-compiled type information + +#include "stdafx.h" + + diff --git a/Chapter11/StringRect/stdafx.h b/Chapter11/StringRect/stdafx.h new file mode 100644 index 0000000..46bef73 --- /dev/null +++ b/Chapter11/StringRect/stdafx.h @@ -0,0 +1,6 @@ +// stdafx.h : include file for standard system include files, +// or project specific include files that are used frequently, but +// are changed infrequently +#pragma once + +// TODO: reference additional headers your program requires here diff --git a/Chapter11/TextureBrushEx/AssemblyInfo.cpp b/Chapter11/TextureBrushEx/AssemblyInfo.cpp new file mode 100644 index 0000000..aecf127 --- /dev/null +++ b/Chapter11/TextureBrushEx/AssemblyInfo.cpp @@ -0,0 +1,35 @@ +#include "stdafx.h" + +using namespace System::Reflection; +using namespace System::Runtime::CompilerServices; +using namespace System::Runtime::InteropServices; + +// +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +// +[assembly:AssemblyTitleAttribute("TextureBrushEx")]; +[assembly:AssemblyDescriptionAttribute("")]; +[assembly:AssemblyConfigurationAttribute("")]; +[assembly:AssemblyCompanyAttribute("")]; +[assembly:AssemblyProductAttribute("TextureBrushEx")]; +[assembly:AssemblyCopyrightAttribute("Copyright (c) 2005")]; +[assembly:AssemblyTrademarkAttribute("")]; +[assembly:AssemblyCultureAttribute("")]; + +// +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the value or you can default the Revision and Build Numbers +// by using the '*' as shown below: + +[assembly:AssemblyVersionAttribute("1.0.*")]; + +[assembly:ComVisible(false)]; + diff --git a/Chapter11/TextureBrushEx/Form1.h b/Chapter11/TextureBrushEx/Form1.h new file mode 100644 index 0000000..6d1c151 --- /dev/null +++ b/Chapter11/TextureBrushEx/Form1.h @@ -0,0 +1,68 @@ +#pragma once + +namespace TextureBrushEx +{ + using namespace System; + using namespace System::ComponentModel; + using namespace System::Collections; + using namespace System::Windows::Forms; + using namespace System::Data; + using namespace System::Drawing; + using namespace System::Drawing::Drawing2D; + + public ref class Form1 : public System::Windows::Forms::Form + { + public: + Form1(void) + { + InitializeComponent(); + } + + protected: + ~Form1() + { + if (components) + { + delete components; + } + } + + private: + System::ComponentModel::Container ^components; + +#pragma region Windows Form Designer generated code + + void InitializeComponent(void) + { + this->SuspendLayout(); + this->AutoScaleDimensions = System::Drawing::SizeF(6, 13); + this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font; + this->ClientSize = System::Drawing::Size(292, 273); + this->Name = L"Form1"; + this->Text = L"Texture Brush"; + this->Paint += + gcnew System::Windows::Forms::PaintEventHandler(this, + &Form1::Form1_Paint); + this->ResumeLayout(false); + + } +#pragma endregion + + private: + System::Void Form1_Paint(System::Object^ sender, + System::Windows::Forms::PaintEventArgs^ e) + { + // Load Image + Image^ bimage = gcnew Bitmap("Images\\CLICppCover.gif"); + // Create brush + TextureBrush^ tbsh = gcnew TextureBrush(bimage, + WrapMode::TileFlipXY); + + // Translate brush to same start location as rectangle + tbsh->TranslateTransform(25,25); + // Fill rectangle with brush + e->Graphics->FillRectangle(tbsh, 25, 25, 250, 250); + } + }; +} + diff --git a/Chapter11/TextureBrushEx/Form1.resx b/Chapter11/TextureBrushEx/Form1.resx new file mode 100644 index 0000000..de824e1 --- /dev/null +++ b/Chapter11/TextureBrushEx/Form1.resx @@ -0,0 +1,110 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Chapter11/TextureBrushEx/Images/CLICppCover.gif b/Chapter11/TextureBrushEx/Images/CLICppCover.gif new file mode 100644 index 0000000..b9c6832 Binary files /dev/null and b/Chapter11/TextureBrushEx/Images/CLICppCover.gif differ diff --git a/Chapter11/TextureBrushEx/TextureBrushEx.cpp b/Chapter11/TextureBrushEx/TextureBrushEx.cpp new file mode 100644 index 0000000..03eafef --- /dev/null +++ b/Chapter11/TextureBrushEx/TextureBrushEx.cpp @@ -0,0 +1,16 @@ +// TextureBrushEx.cpp : main project file. + +#include "stdafx.h" +#include "Form1.h" + +using namespace TextureBrushEx; + +[STAThreadAttribute] +int main(array ^args) +{ + // Enabling Windows XP visual effects before any controls are created + Application::EnableVisualStyles(); + // Create the main window and run it + Application::Run(gcnew Form1()); + return 0; +} diff --git a/Chapter11/TextureBrushEx/TextureBrushEx.vcproj b/Chapter11/TextureBrushEx/TextureBrushEx.vcproj new file mode 100644 index 0000000..21d1fdc --- /dev/null +++ b/Chapter11/TextureBrushEx/TextureBrushEx.vcproj @@ -0,0 +1,250 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Chapter11/TextureBrushEx/stdafx.cpp b/Chapter11/TextureBrushEx/stdafx.cpp new file mode 100644 index 0000000..0f33915 --- /dev/null +++ b/Chapter11/TextureBrushEx/stdafx.cpp @@ -0,0 +1,7 @@ +// stdafx.cpp : source file that includes just the standard includes +// TextureBrushEx.pch will be the pre-compiled header +// stdafx.obj will contain the pre-compiled type information + +#include "stdafx.h" + + diff --git a/Chapter11/TextureBrushEx/stdafx.h b/Chapter11/TextureBrushEx/stdafx.h new file mode 100644 index 0000000..46bef73 --- /dev/null +++ b/Chapter11/TextureBrushEx/stdafx.h @@ -0,0 +1,6 @@ +// stdafx.h : include file for standard system include files, +// or project specific include files that are used frequently, but +// are changed infrequently +#pragma once + +// TODO: reference additional headers your program requires here diff --git a/Chapter12/Chapter12.sln b/Chapter12/Chapter12.sln new file mode 100644 index 0000000..e82e6dd --- /dev/null +++ b/Chapter12/Chapter12.sln @@ -0,0 +1,56 @@ + +Microsoft Visual Studio Solution File, Format Version 9.00 +# Visual Studio 2005 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ConnectedBasics", "ConnectedBasics\ConnectedBasics.vcproj", "{2DC9A390-3E87-42EE-8B41-51CFF97B9BF9}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ConnectedQuery", "ConnectedQuery\ConnectedQuery.vcproj", "{A0E86769-5151-4BF7-93B8-4FA17F13C852}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ConnectedModify", "ConnectedModify\ConnectedModify.vcproj", "{910D4881-67F1-406F-A113-A2CFFF394516}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ConnectedScalar", "ConnectedScalar\ConnectedScalar.vcproj", "{13DD5229-6E0B-4854-84D1-D636709DB707}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Transactions", "Transactions\Transactions.vcproj", "{543DD624-E3EE-4F4A-916E-9BC69F37386F}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "MaintAuthors", "MaintAuthors\MaintAuthors.vcproj", "{D2015709-AED8-4CBE-BA7A-AF827598C993}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "MaintAuthorsDGV", "MaintAuthorsDGV\MaintAuthorsDGV.vcproj", "{4E9D3D57-F86E-46FC-80E8-44D7EE05CB07}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Win32 = Debug|Win32 + Release|Win32 = Release|Win32 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {2DC9A390-3E87-42EE-8B41-51CFF97B9BF9}.Debug|Win32.ActiveCfg = Debug|Win32 + {2DC9A390-3E87-42EE-8B41-51CFF97B9BF9}.Debug|Win32.Build.0 = Debug|Win32 + {2DC9A390-3E87-42EE-8B41-51CFF97B9BF9}.Release|Win32.ActiveCfg = Release|Win32 + {2DC9A390-3E87-42EE-8B41-51CFF97B9BF9}.Release|Win32.Build.0 = Release|Win32 + {A0E86769-5151-4BF7-93B8-4FA17F13C852}.Debug|Win32.ActiveCfg = Debug|Win32 + {A0E86769-5151-4BF7-93B8-4FA17F13C852}.Debug|Win32.Build.0 = Debug|Win32 + {A0E86769-5151-4BF7-93B8-4FA17F13C852}.Release|Win32.ActiveCfg = Release|Win32 + {A0E86769-5151-4BF7-93B8-4FA17F13C852}.Release|Win32.Build.0 = Release|Win32 + {910D4881-67F1-406F-A113-A2CFFF394516}.Debug|Win32.ActiveCfg = Debug|Win32 + {910D4881-67F1-406F-A113-A2CFFF394516}.Debug|Win32.Build.0 = Debug|Win32 + {910D4881-67F1-406F-A113-A2CFFF394516}.Release|Win32.ActiveCfg = Release|Win32 + {910D4881-67F1-406F-A113-A2CFFF394516}.Release|Win32.Build.0 = Release|Win32 + {13DD5229-6E0B-4854-84D1-D636709DB707}.Debug|Win32.ActiveCfg = Debug|Win32 + {13DD5229-6E0B-4854-84D1-D636709DB707}.Debug|Win32.Build.0 = Debug|Win32 + {13DD5229-6E0B-4854-84D1-D636709DB707}.Release|Win32.ActiveCfg = Release|Win32 + {13DD5229-6E0B-4854-84D1-D636709DB707}.Release|Win32.Build.0 = Release|Win32 + {543DD624-E3EE-4F4A-916E-9BC69F37386F}.Debug|Win32.ActiveCfg = Debug|Win32 + {543DD624-E3EE-4F4A-916E-9BC69F37386F}.Debug|Win32.Build.0 = Debug|Win32 + {543DD624-E3EE-4F4A-916E-9BC69F37386F}.Release|Win32.ActiveCfg = Release|Win32 + {543DD624-E3EE-4F4A-916E-9BC69F37386F}.Release|Win32.Build.0 = Release|Win32 + {D2015709-AED8-4CBE-BA7A-AF827598C993}.Debug|Win32.ActiveCfg = Debug|Win32 + {D2015709-AED8-4CBE-BA7A-AF827598C993}.Debug|Win32.Build.0 = Debug|Win32 + {D2015709-AED8-4CBE-BA7A-AF827598C993}.Release|Win32.ActiveCfg = Release|Win32 + {D2015709-AED8-4CBE-BA7A-AF827598C993}.Release|Win32.Build.0 = Release|Win32 + {4E9D3D57-F86E-46FC-80E8-44D7EE05CB07}.Debug|Win32.ActiveCfg = Debug|Win32 + {4E9D3D57-F86E-46FC-80E8-44D7EE05CB07}.Debug|Win32.Build.0 = Debug|Win32 + {4E9D3D57-F86E-46FC-80E8-44D7EE05CB07}.Release|Win32.ActiveCfg = Release|Win32 + {4E9D3D57-F86E-46FC-80E8-44D7EE05CB07}.Release|Win32.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/Chapter12/Chapter12.suo b/Chapter12/Chapter12.suo new file mode 100644 index 0000000..dd465a6 Binary files /dev/null and b/Chapter12/Chapter12.suo differ diff --git a/Chapter12/ConnectedBasics/AssemblyInfo.cpp b/Chapter12/ConnectedBasics/AssemblyInfo.cpp new file mode 100644 index 0000000..ecf7042 --- /dev/null +++ b/Chapter12/ConnectedBasics/AssemblyInfo.cpp @@ -0,0 +1,61 @@ +#using + +using namespace System::Reflection; +using namespace System::Runtime::CompilerServices; +using namespace System::Runtime::InteropServices; + +// +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +// +[assembly:AssemblyTitleAttribute("")]; +[assembly:AssemblyDescriptionAttribute("")]; +[assembly:AssemblyConfigurationAttribute("")]; +[assembly:AssemblyCompanyAttribute("")]; +[assembly:AssemblyProductAttribute("")]; +[assembly:AssemblyCopyrightAttribute("")]; +[assembly:AssemblyTrademarkAttribute("")]; +[assembly:AssemblyCultureAttribute("")]; + +// +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the value or you can default the Revision and Build Numbers +// by using the '*' as shown below: + +[assembly:AssemblyVersionAttribute("1.0.*")]; + +// +// In order to sign your assembly you must specify a key to use. Refer to the +// Microsoft .NET Framework documentation for more information on assembly signing. +// +// Use the attributes below to control which key is used for signing. +// +// Notes: +// (*) If no key is specified, the assembly is not signed. +// (*) KeyName refers to a key that has been installed in the Crypto Service +// Provider (CSP) on your machine. KeyFile refers to a file which contains +// a key. +// (*) If the KeyFile and the KeyName values are both specified, the +// following processing occurs: +// (1) If the KeyName can be found in the CSP, that key is used. +// (2) If the KeyName does not exist and the KeyFile does exist, the key +// in the KeyFile is installed into the CSP and used. +// (*) In order to create a KeyFile, you can use the sn.exe (Strong Name) utility. +// When specifying the KeyFile, the location of the KeyFile should be +// relative to the project directory. +// (*) Delay Signing is an advanced option - see the Microsoft .NET Framework +// documentation for more information on this. +// +[assembly:AssemblyDelaySignAttribute(false)]; +[assembly:AssemblyKeyFileAttribute("")]; +[assembly:AssemblyKeyNameAttribute("")]; + +[assembly:ComVisible(false)]; + diff --git a/Chapter12/ConnectedBasics/ConnectedBasics.cpp b/Chapter12/ConnectedBasics/ConnectedBasics.cpp new file mode 100644 index 0000000..e2d7910 --- /dev/null +++ b/Chapter12/ConnectedBasics/ConnectedBasics.cpp @@ -0,0 +1,36 @@ +using namespace System; +using namespace System::Data; +using namespace System::Data::SqlClient; + +void main() +{ + SqlConnection^ connection = gcnew SqlConnection(); + +#ifdef SQLAuth + // SQL Server authentication + connection->ConnectionString = + "User ID=sa; Password=;" + "Data Source=(local); Initial Catalog=DCV_DB;"; +#else + // Windows Integrated Security + connection->ConnectionString = + "Persist Security Info=False; Integrated Security=SSPI;" + "Data Source=(local); Initial Catalog=DCV_DB;"; +#endif + + try + { + connection->Open(); + Console::WriteLine("We got a connection!"); + } + catch (SqlException ^e) + { + Console::WriteLine("No connection the following error occurred: {0}", + e->Message); + } + finally + { + connection->Close(); + Console::WriteLine("The connection to the database has been closed"); + } +} diff --git a/Chapter12/ConnectedBasics/ConnectedBasics.vcproj b/Chapter12/ConnectedBasics/ConnectedBasics.vcproj new file mode 100644 index 0000000..72bb251 --- /dev/null +++ b/Chapter12/ConnectedBasics/ConnectedBasics.vcproj @@ -0,0 +1,203 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Chapter12/ConnectedModify/AssemblyInfo.cpp b/Chapter12/ConnectedModify/AssemblyInfo.cpp new file mode 100644 index 0000000..ecf7042 --- /dev/null +++ b/Chapter12/ConnectedModify/AssemblyInfo.cpp @@ -0,0 +1,61 @@ +#using + +using namespace System::Reflection; +using namespace System::Runtime::CompilerServices; +using namespace System::Runtime::InteropServices; + +// +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +// +[assembly:AssemblyTitleAttribute("")]; +[assembly:AssemblyDescriptionAttribute("")]; +[assembly:AssemblyConfigurationAttribute("")]; +[assembly:AssemblyCompanyAttribute("")]; +[assembly:AssemblyProductAttribute("")]; +[assembly:AssemblyCopyrightAttribute("")]; +[assembly:AssemblyTrademarkAttribute("")]; +[assembly:AssemblyCultureAttribute("")]; + +// +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the value or you can default the Revision and Build Numbers +// by using the '*' as shown below: + +[assembly:AssemblyVersionAttribute("1.0.*")]; + +// +// In order to sign your assembly you must specify a key to use. Refer to the +// Microsoft .NET Framework documentation for more information on assembly signing. +// +// Use the attributes below to control which key is used for signing. +// +// Notes: +// (*) If no key is specified, the assembly is not signed. +// (*) KeyName refers to a key that has been installed in the Crypto Service +// Provider (CSP) on your machine. KeyFile refers to a file which contains +// a key. +// (*) If the KeyFile and the KeyName values are both specified, the +// following processing occurs: +// (1) If the KeyName can be found in the CSP, that key is used. +// (2) If the KeyName does not exist and the KeyFile does exist, the key +// in the KeyFile is installed into the CSP and used. +// (*) In order to create a KeyFile, you can use the sn.exe (Strong Name) utility. +// When specifying the KeyFile, the location of the KeyFile should be +// relative to the project directory. +// (*) Delay Signing is an advanced option - see the Microsoft .NET Framework +// documentation for more information on this. +// +[assembly:AssemblyDelaySignAttribute(false)]; +[assembly:AssemblyKeyFileAttribute("")]; +[assembly:AssemblyKeyNameAttribute("")]; + +[assembly:ComVisible(false)]; + diff --git a/Chapter12/ConnectedModify/ConnectedModify.cpp b/Chapter12/ConnectedModify/ConnectedModify.cpp new file mode 100644 index 0000000..4be0465 --- /dev/null +++ b/Chapter12/ConnectedModify/ConnectedModify.cpp @@ -0,0 +1,66 @@ +#using +#using + +using namespace System; +using namespace System::Data; +using namespace System::Data::SqlClient; + +void main() +{ + String ^Name = "Doors"; + + SqlConnection ^connection = gcnew SqlConnection(); + +#ifdef SQLAuth + // SQL Server authentication + connection->ConnectionString = + "User ID=sa; Password=;" + "Data Source=(local); Initial Catalog=DCV_DB;"; +#else + // Windows Integrated Security + connection->ConnectionString = + "Persist Security Info=False; Integrated Security=SSPI;" + "Data Source=(local); Initial Catalog=DCV_DB;"; +#endif + + try + { + SqlCommand ^cmd = gcnew SqlCommand(); + cmd->Connection = connection; + connection->Open(); + + cmd->CommandType = CommandType::StoredProcedure; + cmd->CommandText = "InsertAuthor"; + + cmd->Parameters->Add(gcnew SqlParameter("@LastName",SqlDbType::VarChar)); + cmd->Parameters->Add(gcnew SqlParameter("@FirstName",SqlDbType::VarChar)); + + cmd->Parameters["@LastName"]->Value = "Dope"; + cmd->Parameters["@FirstName"]->Value = "John"; + + int affected = cmd->ExecuteNonQuery(); + Console::WriteLine("Insert - {0} rows are affected", affected); + + cmd->CommandType = CommandType::Text; + cmd->CommandText = "UPDATE Authors SET LastName = 'Doe'" + "WHERE LastName = 'Dope'"; + + affected = cmd->ExecuteNonQuery(); + Console::WriteLine("Update - {0} rows are affected", affected); + + cmd->CommandType = CommandType::Text; + cmd->CommandText = "DELETE FROM Authors WHERE LastName = 'Doe'"; + + affected = cmd->ExecuteNonQuery(); + Console::WriteLine("Delete - {0} rows are affected", affected); + } + catch (SqlException ^e) + { + Console::WriteLine("No connection the following error occurred: {0}", + e->Message); + } + finally + { + connection->Close(); + } +} \ No newline at end of file diff --git a/Chapter12/ConnectedModify/ConnectedModify.vcproj b/Chapter12/ConnectedModify/ConnectedModify.vcproj new file mode 100644 index 0000000..41f6734 --- /dev/null +++ b/Chapter12/ConnectedModify/ConnectedModify.vcproj @@ -0,0 +1,203 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Chapter12/ConnectedQuery/AssemblyInfo.cpp b/Chapter12/ConnectedQuery/AssemblyInfo.cpp new file mode 100644 index 0000000..ecf7042 --- /dev/null +++ b/Chapter12/ConnectedQuery/AssemblyInfo.cpp @@ -0,0 +1,61 @@ +#using + +using namespace System::Reflection; +using namespace System::Runtime::CompilerServices; +using namespace System::Runtime::InteropServices; + +// +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +// +[assembly:AssemblyTitleAttribute("")]; +[assembly:AssemblyDescriptionAttribute("")]; +[assembly:AssemblyConfigurationAttribute("")]; +[assembly:AssemblyCompanyAttribute("")]; +[assembly:AssemblyProductAttribute("")]; +[assembly:AssemblyCopyrightAttribute("")]; +[assembly:AssemblyTrademarkAttribute("")]; +[assembly:AssemblyCultureAttribute("")]; + +// +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the value or you can default the Revision and Build Numbers +// by using the '*' as shown below: + +[assembly:AssemblyVersionAttribute("1.0.*")]; + +// +// In order to sign your assembly you must specify a key to use. Refer to the +// Microsoft .NET Framework documentation for more information on assembly signing. +// +// Use the attributes below to control which key is used for signing. +// +// Notes: +// (*) If no key is specified, the assembly is not signed. +// (*) KeyName refers to a key that has been installed in the Crypto Service +// Provider (CSP) on your machine. KeyFile refers to a file which contains +// a key. +// (*) If the KeyFile and the KeyName values are both specified, the +// following processing occurs: +// (1) If the KeyName can be found in the CSP, that key is used. +// (2) If the KeyName does not exist and the KeyFile does exist, the key +// in the KeyFile is installed into the CSP and used. +// (*) In order to create a KeyFile, you can use the sn.exe (Strong Name) utility. +// When specifying the KeyFile, the location of the KeyFile should be +// relative to the project directory. +// (*) Delay Signing is an advanced option - see the Microsoft .NET Framework +// documentation for more information on this. +// +[assembly:AssemblyDelaySignAttribute(false)]; +[assembly:AssemblyKeyFileAttribute("")]; +[assembly:AssemblyKeyNameAttribute("")]; + +[assembly:ComVisible(false)]; + diff --git a/Chapter12/ConnectedQuery/ConnectedQuery.cpp b/Chapter12/ConnectedQuery/ConnectedQuery.cpp new file mode 100644 index 0000000..1189e22 --- /dev/null +++ b/Chapter12/ConnectedQuery/ConnectedQuery.cpp @@ -0,0 +1,87 @@ +#using +#using + +using namespace System; +using namespace System::Data; +using namespace System::Data::SqlClient; + +void main() +{ + String ^Name = "Doors"; + + SqlConnection ^connection = gcnew SqlConnection(); + +#ifdef SQLAuth + // SQL Server authentication + connection->ConnectionString = + "User ID=sa; Password=;" + "Data Source=(local); Initial Catalog=DCV_DB;"; +#else + // Windows Integrated Security + connection->ConnectionString = + "Persist Security Info=False; Integrated Security=SSPI;" + "Data Source=(local); Initial Catalog=DCV_DB;"; +#endif + + try + { + SqlCommand ^cmd = gcnew SqlCommand(); + cmd->Connection = connection; + + cmd->CommandType = CommandType::Text; + cmd->CommandText = + String::Format("SELECT FirstName, LastName FROM Authors " + "WHERE LastName = '{0}'", + Name); + + connection->Open(); + + SqlDataReader ^reader = cmd->ExecuteReader(); + + while(reader->Read()) + { + Console::WriteLine("{0} {1}", + reader["FirstName"], reader["LastName"]); + } + reader->Close(); + + // CREATE PROCEDURE dbo.StoriesWhereLastName + // ( + // @LastName NVARCHAR(32) = NULL + // ) + // AS + // /* SET NOCOUNT ON */ + + // SELECT StoryID, Headline, Story FROM Stories + // WHERE LastName = @LastName + // + // RETURN + + cmd->CommandType = CommandType::StoredProcedure; + cmd->CommandText = "StoriesWhereLastName"; + + cmd->Parameters->Add(gcnew SqlParameter("@LastName",SqlDbType::VarChar)); + cmd->Parameters["@LastName"]->Value = Name; + + reader = cmd->ExecuteReader(); + + Console::WriteLine("------------------------------------------------"); + while(reader->Read()) + { + Console::WriteLine(reader["StoryID"]); + Console::WriteLine(reader["Headline"]); + Console::WriteLine(reader["Story"]); + Console::WriteLine(); + } + reader->Close(); + } + catch (SqlException ^e) + { + Console::WriteLine("No connection the following error occurred: {0}", + e->Message); + } + finally + { + connection->Close(); + } +} \ No newline at end of file diff --git a/Chapter12/ConnectedQuery/ConnectedQuery.vcproj b/Chapter12/ConnectedQuery/ConnectedQuery.vcproj new file mode 100644 index 0000000..b7d5784 --- /dev/null +++ b/Chapter12/ConnectedQuery/ConnectedQuery.vcproj @@ -0,0 +1,203 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Chapter12/ConnectedScalar/AssemblyInfo.cpp b/Chapter12/ConnectedScalar/AssemblyInfo.cpp new file mode 100644 index 0000000..ecf7042 --- /dev/null +++ b/Chapter12/ConnectedScalar/AssemblyInfo.cpp @@ -0,0 +1,61 @@ +#using + +using namespace System::Reflection; +using namespace System::Runtime::CompilerServices; +using namespace System::Runtime::InteropServices; + +// +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +// +[assembly:AssemblyTitleAttribute("")]; +[assembly:AssemblyDescriptionAttribute("")]; +[assembly:AssemblyConfigurationAttribute("")]; +[assembly:AssemblyCompanyAttribute("")]; +[assembly:AssemblyProductAttribute("")]; +[assembly:AssemblyCopyrightAttribute("")]; +[assembly:AssemblyTrademarkAttribute("")]; +[assembly:AssemblyCultureAttribute("")]; + +// +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the value or you can default the Revision and Build Numbers +// by using the '*' as shown below: + +[assembly:AssemblyVersionAttribute("1.0.*")]; + +// +// In order to sign your assembly you must specify a key to use. Refer to the +// Microsoft .NET Framework documentation for more information on assembly signing. +// +// Use the attributes below to control which key is used for signing. +// +// Notes: +// (*) If no key is specified, the assembly is not signed. +// (*) KeyName refers to a key that has been installed in the Crypto Service +// Provider (CSP) on your machine. KeyFile refers to a file which contains +// a key. +// (*) If the KeyFile and the KeyName values are both specified, the +// following processing occurs: +// (1) If the KeyName can be found in the CSP, that key is used. +// (2) If the KeyName does not exist and the KeyFile does exist, the key +// in the KeyFile is installed into the CSP and used. +// (*) In order to create a KeyFile, you can use the sn.exe (Strong Name) utility. +// When specifying the KeyFile, the location of the KeyFile should be +// relative to the project directory. +// (*) Delay Signing is an advanced option - see the Microsoft .NET Framework +// documentation for more information on this. +// +[assembly:AssemblyDelaySignAttribute(false)]; +[assembly:AssemblyKeyFileAttribute("")]; +[assembly:AssemblyKeyNameAttribute("")]; + +[assembly:ComVisible(false)]; + diff --git a/Chapter12/ConnectedScalar/ConnectedScalar.cpp b/Chapter12/ConnectedScalar/ConnectedScalar.cpp new file mode 100644 index 0000000..c5b33f3 --- /dev/null +++ b/Chapter12/ConnectedScalar/ConnectedScalar.cpp @@ -0,0 +1,51 @@ +#using +#using + +using namespace System; +using namespace System::Data; +using namespace System::Data::SqlClient; + +void main() +{ + SqlConnection ^connection = gcnew SqlConnection(); + +#ifdef SQLAuth + // SQL Server authentication + connection->ConnectionString = + "User ID=sa; Password=;" + "Data Source=(local); Initial Catalog=DCV_DB;"; +#else + // Windows Integrated Security + connection->ConnectionString = + "Persist Security Info=False; Integrated Security=SSPI;" + "Data Source=(local); Initial Catalog=DCV_DB;"; +#endif + + try + { + SqlCommand ^cmd = gcnew SqlCommand(); + cmd->Connection = connection; + connection->Open(); + + cmd->CommandType = CommandType::Text; + cmd->CommandText = "SELECT COUNT(*) FROM Authors"; + + Object ^NumAuthors = cmd->ExecuteScalar(); + Console::WriteLine("The number of Authors are {0}", NumAuthors); + + cmd->CommandType = CommandType::Text; + cmd->CommandText = "SELECT SUM(AuthorID) FROM Authors"; + + Object ^UselessNum = cmd->ExecuteScalar(); + Console::WriteLine("The Sum of AuthorIDs for fun is {0}", UselessNum); + } + catch (SqlException ^e) + { + Console::WriteLine("No connection the following error occurred: {0}", + e->Message); + } + finally + { + connection->Close(); + } +} \ No newline at end of file diff --git a/Chapter12/ConnectedScalar/ConnectedScalar.vcproj b/Chapter12/ConnectedScalar/ConnectedScalar.vcproj new file mode 100644 index 0000000..7b5ff37 --- /dev/null +++ b/Chapter12/ConnectedScalar/ConnectedScalar.vcproj @@ -0,0 +1,203 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Chapter12/MaintAuthors/AssemblyInfo.cpp b/Chapter12/MaintAuthors/AssemblyInfo.cpp new file mode 100644 index 0000000..a1ea1fc --- /dev/null +++ b/Chapter12/MaintAuthors/AssemblyInfo.cpp @@ -0,0 +1,35 @@ +#include "stdafx.h" + +using namespace System::Reflection; +using namespace System::Runtime::CompilerServices; +using namespace System::Runtime::InteropServices; + +// +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +// +[assembly:AssemblyTitleAttribute("MaintAuthors")]; +[assembly:AssemblyDescriptionAttribute("")]; +[assembly:AssemblyConfigurationAttribute("")]; +[assembly:AssemblyCompanyAttribute("")]; +[assembly:AssemblyProductAttribute("MaintAuthors")]; +[assembly:AssemblyCopyrightAttribute("Copyright (c) 2005")]; +[assembly:AssemblyTrademarkAttribute("")]; +[assembly:AssemblyCultureAttribute("")]; + +// +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the value or you can default the Revision and Build Numbers +// by using the '*' as shown below: + +[assembly:AssemblyVersionAttribute("1.0.*")]; + +[assembly:ComVisible(false)]; + diff --git a/Chapter12/MaintAuthors/Form1.h b/Chapter12/MaintAuthors/Form1.h new file mode 100644 index 0000000..f012dba --- /dev/null +++ b/Chapter12/MaintAuthors/Form1.h @@ -0,0 +1,363 @@ +#pragma once + + +namespace MaintAuthors +{ + using namespace System; + using namespace System::ComponentModel; + using namespace System::Collections; + using namespace System::Windows::Forms; + using namespace System::Data; + using namespace System::Data::SqlClient; + using namespace System::Drawing; + + public ref class Form1 : public System::Windows::Forms::Form + { + public: + Form1(void) + { + InitializeComponent(); + + SqlConnection ^connect = gcnew SqlConnection(); + +#ifdef SQLAuth + // SQL Server authentication + connect->ConnectionString = + "User ID=sa; Password=;" + "Data Source=(local); Initial Catalog=DCV_DB;"; +#else + // Windows Integrated Security + connect->ConnectionString = + "Persist Security Info=False; Integrated Security=SSPI;" + "Data Source=(local); Initial Catalog=DCV_DB;"; +#endif + + dAdapt = gcnew SqlDataAdapter(); + dAdapt->MissingSchemaAction = MissingSchemaAction::AddWithKey; + + dAdapt->SelectCommand = gcnew SqlCommand("SELECT AuthorID, LastName, FirstName FROM Authors", connect); + + dAdapt->InsertCommand = gcnew SqlCommand("INSERT INTO Authors (LastName, FirstName) " + "VALUES (@LastName, @FirstName)", connect); + dAdapt->InsertCommand->Parameters->Add("@LastName", SqlDbType::VarChar, 50, "LastName"); + dAdapt->InsertCommand->Parameters->Add("@FirstName", SqlDbType::VarChar, 50, "FirstName"); + + + dAdapt->UpdateCommand = gcnew SqlCommand("UPDATE Authors SET LastName = @LastName, FirstName = @FirstName " + "WHERE AuthorID = @AuthorID", connect); + dAdapt->UpdateCommand->Parameters->Add("@LastName", SqlDbType::VarChar, 50, "LastName"); + dAdapt->UpdateCommand->Parameters->Add("@FirstName", SqlDbType::VarChar, 50, "FirstName"); + dAdapt->UpdateCommand->Parameters->Add("@AuthorID", SqlDbType::Int, 4, "AuthorID"); + + dAdapt->DeleteCommand = gcnew SqlCommand("DELETE FROM Authors WHERE AuthorID = @AuthorID", connect); + dAdapt->DeleteCommand->Parameters->Add("@AuthorID", SqlDbType::Int, 4, "AuthorID"); + + dSet = gcnew DataSet(); + dAdapt->Fill(dSet, "Authors"); + + DataTable ^dt = dSet->Tables["Authors"]; + + if (dt == nullptr) + throw gcnew Exception("No Authors Table"); + + IEnumerator ^Enum = dt->Rows->GetEnumerator(); + while(Enum->MoveNext()) + { + DataRow ^row = (DataRow^)(Enum->Current); + lbAuthors->Items->Add(ListBoxItem(row)); + } + CurrentAuthorID = -1; + } + + protected: + ~Form1() + { + if (components) + { + delete components; + } + } + + private: + System::Windows::Forms::Button^ bnRollback; + System::Windows::Forms::Button^ bnCommit; + System::Windows::Forms::Button^ bnDelete; + System::Windows::Forms::Button^ bnUpdate; + System::Windows::Forms::Button^ bnAdd; + System::Windows::Forms::ListBox^ lbAuthors; + System::Windows::Forms::TextBox^ tbLastName; + System::Windows::Forms::TextBox^ tbFirstName; + System::Windows::Forms::Label^ label2; + System::Windows::Forms::Label^ label1; + + System::ComponentModel::Container ^components; + + SqlDataAdapter ^dAdapt; + DataSet ^dSet; + int CurrentAuthorID; + +#pragma region Windows Form Designer generated code + void InitializeComponent(void) + { + this->bnRollback = (gcnew System::Windows::Forms::Button()); + this->bnCommit = (gcnew System::Windows::Forms::Button()); + this->bnDelete = (gcnew System::Windows::Forms::Button()); + this->bnUpdate = (gcnew System::Windows::Forms::Button()); + this->bnAdd = (gcnew System::Windows::Forms::Button()); + this->lbAuthors = (gcnew System::Windows::Forms::ListBox()); + this->tbLastName = (gcnew System::Windows::Forms::TextBox()); + this->tbFirstName = (gcnew System::Windows::Forms::TextBox()); + this->label2 = (gcnew System::Windows::Forms::Label()); + this->label1 = (gcnew System::Windows::Forms::Label()); + this->SuspendLayout(); + // + // bnRollback + // + this->bnRollback->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 8.25F, System::Drawing::FontStyle::Bold, System::Drawing::GraphicsUnit::Point, + static_cast(0))); + this->bnRollback->Location = System::Drawing::Point(312, 162); + this->bnRollback->Name = L"bnRollback"; + this->bnRollback->Size = System::Drawing::Size(75, 23); + this->bnRollback->TabIndex = 19; + this->bnRollback->Text = L"Rollback"; + this->bnRollback->Click += gcnew System::EventHandler(this, &Form1::bnRollback_Click); + // + // bnCommit + // + this->bnCommit->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 8.25F, System::Drawing::FontStyle::Bold, System::Drawing::GraphicsUnit::Point, + static_cast(0))); + this->bnCommit->Location = System::Drawing::Point(312, 132); + this->bnCommit->Margin = System::Windows::Forms::Padding(3, 0, 3, 3); + this->bnCommit->Name = L"bnCommit"; + this->bnCommit->Size = System::Drawing::Size(75, 23); + this->bnCommit->TabIndex = 18; + this->bnCommit->Text = L"Commit"; + this->bnCommit->Click += gcnew System::EventHandler(this, &Form1::bnCommit_Click); + // + // bnDelete + // + this->bnDelete->Location = System::Drawing::Point(312, 78); + this->bnDelete->Name = L"bnDelete"; + this->bnDelete->Size = System::Drawing::Size(75, 23); + this->bnDelete->TabIndex = 17; + this->bnDelete->Text = L"Delete"; + this->bnDelete->Click += gcnew System::EventHandler(this, &Form1::bnDelete_Click); + // + // bnUpdate + // + this->bnUpdate->Location = System::Drawing::Point(312, 46); + this->bnUpdate->Name = L"bnUpdate"; + this->bnUpdate->Size = System::Drawing::Size(75, 23); + this->bnUpdate->TabIndex = 16; + this->bnUpdate->Text = L"Update"; + this->bnUpdate->Click += gcnew System::EventHandler(this, &Form1::bnUpdate_Click); + // + // bnAdd + // + this->bnAdd->Location = System::Drawing::Point(312, 18); + this->bnAdd->Margin = System::Windows::Forms::Padding(3, 3, 3, 1); + this->bnAdd->Name = L"bnAdd"; + this->bnAdd->Size = System::Drawing::Size(75, 23); + this->bnAdd->TabIndex = 15; + this->bnAdd->Text = L"Add"; + this->bnAdd->Click += gcnew System::EventHandler(this, &Form1::bnAdd_Click); + // + // lbAuthors + // + this->lbAuthors->FormattingEnabled = true; + this->lbAuthors->Location = System::Drawing::Point(25, 95); + this->lbAuthors->Name = L"lbAuthors"; + this->lbAuthors->Size = System::Drawing::Size(257, 95); + this->lbAuthors->TabIndex = 14; + this->lbAuthors->SelectedIndexChanged += gcnew System::EventHandler(this, &Form1::lbAuthors_SelectedIndexChanged); + // + // tbLastName + // + this->tbLastName->Location = System::Drawing::Point(87, 51); + this->tbLastName->Margin = System::Windows::Forms::Padding(1, 3, 3, 3); + this->tbLastName->Name = L"tbLastName"; + this->tbLastName->Size = System::Drawing::Size(127, 20); + this->tbLastName->TabIndex = 13; + // + // tbFirstName + // + this->tbFirstName->Location = System::Drawing::Point(87, 24); + this->tbFirstName->Margin = System::Windows::Forms::Padding(1, 3, 3, 3); + this->tbFirstName->Name = L"tbFirstName"; + this->tbFirstName->Size = System::Drawing::Size(127, 20); + this->tbFirstName->TabIndex = 12; + // + // label2 + // + this->label2->AutoSize = true; + this->label2->Location = System::Drawing::Point(25, 57); + this->label2->Margin = System::Windows::Forms::Padding(3, 3, 2, 3); + this->label2->Name = L"label2"; + this->label2->Size = System::Drawing::Size(58, 13); + this->label2->TabIndex = 11; + this->label2->Text = L"Last Name"; + // + // label1 + // + this->label1->AutoSize = true; + this->label1->Location = System::Drawing::Point(25, 27); + this->label1->Margin = System::Windows::Forms::Padding(3, 3, 2, 3); + this->label1->Name = L"label1"; + this->label1->Size = System::Drawing::Size(57, 13); + this->label1->TabIndex = 10; + this->label1->Text = L"First Name"; + // + // Form1 + // + this->AutoScaleDimensions = System::Drawing::SizeF(6, 13); + this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font; + this->ClientSize = System::Drawing::Size(413, 208); + this->Controls->Add(this->bnRollback); + this->Controls->Add(this->bnCommit); + this->Controls->Add(this->bnDelete); + this->Controls->Add(this->bnUpdate); + this->Controls->Add(this->bnAdd); + this->Controls->Add(this->lbAuthors); + this->Controls->Add(this->tbLastName); + this->Controls->Add(this->tbFirstName); + this->Controls->Add(this->label2); + this->Controls->Add(this->label1); + this->Name = L"Form1"; + this->Text = L"Maintain Authors"; + this->ResumeLayout(false); + this->PerformLayout(); + + } + +#pragma endregion + + private: + String ^ListBoxItem(DataRow ^row) + { + return String::Format("{0} {1} {2}", + row["AuthorID"], + row["FirstName"], + row["LastName"]); + } + + System::Void bnAdd_Click(System::Object^ sender, System::EventArgs^ e) + { + // Make sure the text boxes are populated + if (tbFirstName->Text->Trim()->Length == 0 || + tbLastName->Text->Trim()->Length == 0) + return; + + // Create a new row in the DataTable + DataTable ^dt = dSet->Tables["Authors"]; + DataRow ^row = dt->NewRow(); + + // Update the columns with the new author information + row["FirstName"] = tbFirstName->Text; + row["LastName"] = tbLastName->Text; + + // Add the row to the Rows collection + dt->Rows->Add(row); + + // Add the new row to the list box + lbAuthors->Items->Add(ListBoxItem(row)); + + // blank out the text boxes + tbFirstName->Text = ""; + tbLastName->Text = ""; + } + + System::Void bnUpdate_Click(System::Object^ sender, System::EventArgs^ e) + { + // make sure we have a selected author from the listbox + if (CurrentAuthorID < 0) + return; + + // Select the author using its AuthorID + DataTable ^dt = dSet->Tables["Authors"]; + array^ row = + dt->Select(String::Format("AuthorID={0}", CurrentAuthorID)); + + // Since we know that AuthorID is unique only one row will be returned + // Update the row with the text box information + row[0]["FirstName"] = tbFirstName->Text; + row[0]["LastName"] = tbLastName->Text; + + // Update listbox + lbAuthors->Items->Insert(lbAuthors->SelectedIndex, ListBoxItem(row[0])); + lbAuthors->Items->RemoveAt(lbAuthors->SelectedIndex); + } + + System::Void bnDelete_Click(System::Object^ sender, System::EventArgs^ e) + { + // make sure we have a selected author from the listbox + if (CurrentAuthorID < 0) + return; + + // Select the author using its AuthorID + DataTable ^dt = dSet->Tables["Authors"]; + array^ row = + dt->Select(String::Format("AuthorID={0}", CurrentAuthorID)); + + // Since we know that AuthorID is unique only one row will be returned + // Delete the row + row[0]->Delete(); + + // all went well, delete the row from list box + lbAuthors->Items->RemoveAt(lbAuthors->SelectedIndex); + } + + System::Void bnCommit_Click(System::Object^ sender, System::EventArgs^ e) + { + dAdapt->Update(dSet, "Authors"); + dSet->AcceptChanges(); + + lbAuthors->Items->Clear(); + + DataTable ^dt = dSet->Tables["Authors"]; + + IEnumerator ^Enum = dt->Rows->GetEnumerator(); + while(Enum->MoveNext()) + { + DataRow ^row = (DataRow^)(Enum->Current); + lbAuthors->Items->Add(ListBoxItem(row)); + } + CurrentAuthorID = -1; + } + + System::Void bnRollback_Click(System::Object^ sender, System::EventArgs^ e) + { + dSet->RejectChanges(); + + lbAuthors->Items->Clear(); + + DataTable ^dt = dSet->Tables["Authors"]; + + IEnumerator ^Enum = dt->Rows->GetEnumerator(); + while(Enum->MoveNext()) + { + DataRow ^row = (DataRow^)(Enum->Current); + lbAuthors->Items->Add(ListBoxItem(row)); + } + CurrentAuthorID = -1; + } + + System::Void lbAuthors_SelectedIndexChanged(System::Object^ sender, System::EventArgs^ e) + { + array^ ASpace = gcnew array {(wchar_t)' '}; + + if (lbAuthors->SelectedItem == nullptr) + { + CurrentAuthorID = -1; + tbFirstName->Text = ""; + tbLastName->Text = ""; + return; + } + array^ split = lbAuthors->SelectedItem->ToString()->Split(ASpace); + + CurrentAuthorID = Convert::ToInt32(split[0]); + tbFirstName->Text = split[1]; + tbLastName->Text = split[2]; + } + }; +} + diff --git a/Chapter12/MaintAuthors/Form1.resx b/Chapter12/MaintAuthors/Form1.resx new file mode 100644 index 0000000..de824e1 --- /dev/null +++ b/Chapter12/MaintAuthors/Form1.resx @@ -0,0 +1,110 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Chapter12/MaintAuthors/MaintAuthors.cpp b/Chapter12/MaintAuthors/MaintAuthors.cpp new file mode 100644 index 0000000..a28e145 --- /dev/null +++ b/Chapter12/MaintAuthors/MaintAuthors.cpp @@ -0,0 +1,16 @@ +// MaintAuthors.cpp : main project file. + +#include "stdafx.h" +#include "Form1.h" + +using namespace MaintAuthors; + +[STAThreadAttribute] +int main(array ^args) +{ + // Enabling Windows XP visual effects before any controls are created + Application::EnableVisualStyles(); + // Create the main window and run it + Application::Run(gcnew Form1()); + return 0; +} diff --git a/Chapter12/MaintAuthors/MaintAuthors.vcproj b/Chapter12/MaintAuthors/MaintAuthors.vcproj new file mode 100644 index 0000000..a9647be --- /dev/null +++ b/Chapter12/MaintAuthors/MaintAuthors.vcproj @@ -0,0 +1,250 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Chapter12/MaintAuthors/stdafx.cpp b/Chapter12/MaintAuthors/stdafx.cpp new file mode 100644 index 0000000..198bfa9 --- /dev/null +++ b/Chapter12/MaintAuthors/stdafx.cpp @@ -0,0 +1,7 @@ +// stdafx.cpp : source file that includes just the standard includes +// MaintAuthors.pch will be the pre-compiled header +// stdafx.obj will contain the pre-compiled type information + +#include "stdafx.h" + + diff --git a/Chapter12/MaintAuthors/stdafx.h b/Chapter12/MaintAuthors/stdafx.h new file mode 100644 index 0000000..46bef73 --- /dev/null +++ b/Chapter12/MaintAuthors/stdafx.h @@ -0,0 +1,6 @@ +// stdafx.h : include file for standard system include files, +// or project specific include files that are used frequently, but +// are changed infrequently +#pragma once + +// TODO: reference additional headers your program requires here diff --git a/Chapter12/MaintAuthorsDGV/AssemblyInfo.cpp b/Chapter12/MaintAuthorsDGV/AssemblyInfo.cpp new file mode 100644 index 0000000..e1aeb41 --- /dev/null +++ b/Chapter12/MaintAuthorsDGV/AssemblyInfo.cpp @@ -0,0 +1,35 @@ +#include "stdafx.h" + +using namespace System::Reflection; +using namespace System::Runtime::CompilerServices; +using namespace System::Runtime::InteropServices; + +// +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +// +[assembly:AssemblyTitleAttribute("MaintAuthorsDGV")]; +[assembly:AssemblyDescriptionAttribute("")]; +[assembly:AssemblyConfigurationAttribute("")]; +[assembly:AssemblyCompanyAttribute("")]; +[assembly:AssemblyProductAttribute("MaintAuthorsDGV")]; +[assembly:AssemblyCopyrightAttribute("Copyright (c) 2005")]; +[assembly:AssemblyTrademarkAttribute("")]; +[assembly:AssemblyCultureAttribute("")]; + +// +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the value or you can default the Revision and Build Numbers +// by using the '*' as shown below: + +[assembly:AssemblyVersionAttribute("1.0.*")]; + +[assembly:ComVisible(false)]; + diff --git a/Chapter12/MaintAuthorsDGV/AuthorsDS.h b/Chapter12/MaintAuthorsDGV/AuthorsDS.h new file mode 100644 index 0000000..8ef1593 --- /dev/null +++ b/Chapter12/MaintAuthorsDGV/AuthorsDS.h @@ -0,0 +1,1020 @@ +#pragma once + +#using +#using +#using +#using +#using + +using namespace System::Security::Permissions; +[assembly:SecurityPermissionAttribute(SecurityAction::RequestMinimum, SkipVerification=false)]; +// +// This source code was auto-generated by xsd, Version=2.0.50630.0. +// +namespace MaintAuthorsDGV { + using namespace System; + + using namespace System; + ref class AuthorsDS; + + + [System::CodeDom::Compiler::GeneratedCodeAttribute(L"System.Data.Design.TypedDataSetGenerator", L"2.0.0.0"), + Serializable, + System::ComponentModel::DesignerCategoryAttribute(L"code"), + System::ComponentModel::ToolboxItem(true), + System::Xml::Serialization::XmlSchemaProviderAttribute(L"GetTypedDataSetSchema"), + System::Xml::Serialization::XmlRootAttribute(L"AuthorsDS"), + System::ComponentModel::Design::HelpKeywordAttribute(L"vs.data.DataSet"), + System::CLSCompliantAttribute(false)] + public ref class AuthorsDS : public System::Data::DataSet { + public : ref class AuthorsDataTable; + public : ref class AuthorsRow; + public : ref class AuthorsRowChangeEvent; + + private: MaintAuthorsDGV::AuthorsDS::AuthorsDataTable^ tableAuthors; + + private: System::Data::SchemaSerializationMode _schemaSerializationMode; + + public : delegate System::Void AuthorsRowChangeEventHandler(System::Object^ sender, MaintAuthorsDGV::AuthorsDS::AuthorsRowChangeEvent^ e); + + public: [System::Diagnostics::DebuggerNonUserCodeAttribute] + AuthorsDS(); + protected: [System::Diagnostics::DebuggerNonUserCodeAttribute] + AuthorsDS(System::Runtime::Serialization::SerializationInfo^ info, System::Runtime::Serialization::StreamingContext context); + public: [System::Diagnostics::DebuggerNonUserCodeAttribute, + System::ComponentModel::Browsable(false), + System::ComponentModel::DesignerSerializationVisibility(System::ComponentModel::DesignerSerializationVisibility::Content)] + property MaintAuthorsDGV::AuthorsDS::AuthorsDataTable^ Authors { + MaintAuthorsDGV::AuthorsDS::AuthorsDataTable^ get(); + } + + public: [System::Diagnostics::DebuggerNonUserCodeAttribute] + virtual property System::Data::SchemaSerializationMode SchemaSerializationMode { + System::Data::SchemaSerializationMode get() override; + System::Void set(System::Data::SchemaSerializationMode value) override; + } + + public: [System::Diagnostics::DebuggerNonUserCodeAttribute, + System::ComponentModel::DesignerSerializationVisibilityAttribute(System::ComponentModel::DesignerSerializationVisibility::Hidden)] + property System::Data::DataTableCollection^ Tables { + System::Data::DataTableCollection^ get() new; + } + + public: [System::Diagnostics::DebuggerNonUserCodeAttribute, + System::ComponentModel::DesignerSerializationVisibilityAttribute(System::ComponentModel::DesignerSerializationVisibility::Hidden)] + property System::Data::DataRelationCollection^ Relations { + System::Data::DataRelationCollection^ get() new; + } + + public: [System::Diagnostics::DebuggerNonUserCodeAttribute, + System::ComponentModel::DefaultValueAttribute(true)] + property System::Boolean EnforceConstraints { + System::Boolean get() new; + System::Void set(System::Boolean value) new; + } + + protected: [System::Diagnostics::DebuggerNonUserCodeAttribute] + virtual System::Void InitializeDerivedDataSet() override; + + public: [System::Diagnostics::DebuggerNonUserCodeAttribute] + virtual System::Data::DataSet^ Clone() override; + + protected: [System::Diagnostics::DebuggerNonUserCodeAttribute] + virtual System::Boolean ShouldSerializeTables() override; + + protected: [System::Diagnostics::DebuggerNonUserCodeAttribute] + virtual System::Boolean ShouldSerializeRelations() override; + + protected: [System::Diagnostics::DebuggerNonUserCodeAttribute] + virtual System::Void ReadXmlSerializable(System::Xml::XmlReader^ reader) override; + + protected: [System::Diagnostics::DebuggerNonUserCodeAttribute] + virtual System::Xml::Schema::XmlSchema^ GetSchemaSerializable() override; + + internal: [System::Diagnostics::DebuggerNonUserCodeAttribute] + System::Void InitVars(); + + internal: [System::Diagnostics::DebuggerNonUserCodeAttribute] + System::Void InitVars(System::Boolean initTable); + + private: [System::Diagnostics::DebuggerNonUserCodeAttribute] + System::Void InitClass(); + + private: [System::Diagnostics::DebuggerNonUserCodeAttribute] + System::Boolean ShouldSerializeAuthors(); + + private: [System::Diagnostics::DebuggerNonUserCodeAttribute] + System::Void SchemaChanged(System::Object^ sender, System::ComponentModel::CollectionChangeEventArgs^ e); + + public: [System::Diagnostics::DebuggerNonUserCodeAttribute] + static System::Xml::Schema::XmlSchemaComplexType^ GetTypedDataSetSchema(System::Xml::Schema::XmlSchemaSet^ xs); + + public : [System::CodeDom::Compiler::GeneratedCodeAttribute(L"System.Data.Design.TypedDataSetGenerator", L"2.0.0.0"), + System::Serializable, + System::Xml::Serialization::XmlSchemaProviderAttribute(L"GetTypedTableSchema")] + ref class AuthorsDataTable : public System::Data::DataTable, public System::Collections::IEnumerable { + + private: System::Data::DataColumn^ columnAuthorID; + + private: System::Data::DataColumn^ columnLastName; + + private: System::Data::DataColumn^ columnFirstName; + + public: event MaintAuthorsDGV::AuthorsDS::AuthorsRowChangeEventHandler^ AuthorsRowChanging; + + public: event MaintAuthorsDGV::AuthorsDS::AuthorsRowChangeEventHandler^ AuthorsRowChanged; + + public: event MaintAuthorsDGV::AuthorsDS::AuthorsRowChangeEventHandler^ AuthorsRowDeleting; + + public: event MaintAuthorsDGV::AuthorsDS::AuthorsRowChangeEventHandler^ AuthorsRowDeleted; + + public: [System::Diagnostics::DebuggerNonUserCodeAttribute] + AuthorsDataTable(); + internal: [System::Diagnostics::DebuggerNonUserCodeAttribute] + AuthorsDataTable(System::Data::DataTable^ table); + protected: [System::Diagnostics::DebuggerNonUserCodeAttribute] + AuthorsDataTable(System::Runtime::Serialization::SerializationInfo^ info, System::Runtime::Serialization::StreamingContext context); + public: [System::Diagnostics::DebuggerNonUserCodeAttribute] + property System::Data::DataColumn^ AuthorIDColumn { + System::Data::DataColumn^ get(); + } + + public: [System::Diagnostics::DebuggerNonUserCodeAttribute] + property System::Data::DataColumn^ LastNameColumn { + System::Data::DataColumn^ get(); + } + + public: [System::Diagnostics::DebuggerNonUserCodeAttribute] + property System::Data::DataColumn^ FirstNameColumn { + System::Data::DataColumn^ get(); + } + + public: [System::Diagnostics::DebuggerNonUserCodeAttribute, + System::ComponentModel::Browsable(false)] + property System::Int32 Count { + System::Int32 get(); + } + + public: [System::Diagnostics::DebuggerNonUserCodeAttribute] + property MaintAuthorsDGV::AuthorsDS::AuthorsRow^ default [System::Int32 ] { + MaintAuthorsDGV::AuthorsDS::AuthorsRow^ get(System::Int32 index); + } + + public: [System::Diagnostics::DebuggerNonUserCodeAttribute] + System::Void AddAuthorsRow(MaintAuthorsDGV::AuthorsDS::AuthorsRow^ row); + + public: [System::Diagnostics::DebuggerNonUserCodeAttribute] + MaintAuthorsDGV::AuthorsDS::AuthorsRow^ AddAuthorsRow(System::String^ LastName, System::String^ FirstName); + + public: [System::Diagnostics::DebuggerNonUserCodeAttribute] + MaintAuthorsDGV::AuthorsDS::AuthorsRow^ FindByAuthorID(System::Int32 AuthorID); + + public: [System::Diagnostics::DebuggerNonUserCodeAttribute] + virtual System::Collections::IEnumerator^ GetEnumerator(); + + public: [System::Diagnostics::DebuggerNonUserCodeAttribute] + virtual System::Data::DataTable^ Clone() override; + + protected: [System::Diagnostics::DebuggerNonUserCodeAttribute] + virtual System::Data::DataTable^ CreateInstance() override; + + internal: [System::Diagnostics::DebuggerNonUserCodeAttribute] + System::Void InitVars(); + + private: [System::Diagnostics::DebuggerNonUserCodeAttribute] + System::Void InitClass(); + + public: [System::Diagnostics::DebuggerNonUserCodeAttribute] + MaintAuthorsDGV::AuthorsDS::AuthorsRow^ NewAuthorsRow(); + + protected: [System::Diagnostics::DebuggerNonUserCodeAttribute] + virtual System::Data::DataRow^ NewRowFromBuilder(System::Data::DataRowBuilder^ builder) override; + + protected: [System::Diagnostics::DebuggerNonUserCodeAttribute] + virtual System::Type^ GetRowType() override; + + protected: [System::Diagnostics::DebuggerNonUserCodeAttribute] + virtual System::Void OnRowChanged(System::Data::DataRowChangeEventArgs^ e) override; + + protected: [System::Diagnostics::DebuggerNonUserCodeAttribute] + virtual System::Void OnRowChanging(System::Data::DataRowChangeEventArgs^ e) override; + + protected: [System::Diagnostics::DebuggerNonUserCodeAttribute] + virtual System::Void OnRowDeleted(System::Data::DataRowChangeEventArgs^ e) override; + + protected: [System::Diagnostics::DebuggerNonUserCodeAttribute] + virtual System::Void OnRowDeleting(System::Data::DataRowChangeEventArgs^ e) override; + + public: [System::Diagnostics::DebuggerNonUserCodeAttribute] + System::Void RemoveAuthorsRow(MaintAuthorsDGV::AuthorsDS::AuthorsRow^ row); + + public: [System::Diagnostics::DebuggerNonUserCodeAttribute] + static System::Xml::Schema::XmlSchemaComplexType^ GetTypedTableSchema(System::Xml::Schema::XmlSchemaSet^ xs); + }; + + public : [System::CodeDom::Compiler::GeneratedCodeAttribute(L"System.Data.Design.TypedDataSetGenerator", L"2.0.0.0")] + ref class AuthorsRow : public System::Data::DataRow { + + private: MaintAuthorsDGV::AuthorsDS::AuthorsDataTable^ tableAuthors; + + internal: [System::Diagnostics::DebuggerNonUserCodeAttribute] + AuthorsRow(System::Data::DataRowBuilder^ rb); + public: [System::Diagnostics::DebuggerNonUserCodeAttribute] + property System::Int32 AuthorID { + System::Int32 get(); + System::Void set(System::Int32 value); + } + + public: [System::Diagnostics::DebuggerNonUserCodeAttribute] + property System::String^ LastName { + System::String^ get(); + System::Void set(System::String^ value); + } + + public: [System::Diagnostics::DebuggerNonUserCodeAttribute] + property System::String^ FirstName { + System::String^ get(); + System::Void set(System::String^ value); + } + }; + + public : [System::CodeDom::Compiler::GeneratedCodeAttribute(L"System.Data.Design.TypedDataSetGenerator", L"2.0.0.0")] + ref class AuthorsRowChangeEvent : public System::EventArgs { + + private: MaintAuthorsDGV::AuthorsDS::AuthorsRow^ eventRow; + + private: System::Data::DataRowAction eventAction; + + public: [System::Diagnostics::DebuggerNonUserCodeAttribute] + AuthorsRowChangeEvent(MaintAuthorsDGV::AuthorsDS::AuthorsRow^ row, System::Data::DataRowAction action); + public: [System::Diagnostics::DebuggerNonUserCodeAttribute] + property MaintAuthorsDGV::AuthorsDS::AuthorsRow^ Row { + MaintAuthorsDGV::AuthorsDS::AuthorsRow^ get(); + } + + public: [System::Diagnostics::DebuggerNonUserCodeAttribute] + property System::Data::DataRowAction Action { + System::Data::DataRowAction get(); + } + }; + }; +} +namespace MaintAuthorsDGV { + + + inline AuthorsDS::AuthorsDS() { + this->BeginInit(); + this->InitClass(); + System::ComponentModel::CollectionChangeEventHandler^ schemaChangedHandler = gcnew System::ComponentModel::CollectionChangeEventHandler(this, &MaintAuthorsDGV::AuthorsDS::SchemaChanged); + __super::Tables->CollectionChanged += schemaChangedHandler; + __super::Relations->CollectionChanged += schemaChangedHandler; + this->EndInit(); + } + + inline AuthorsDS::AuthorsDS(System::Runtime::Serialization::SerializationInfo^ info, System::Runtime::Serialization::StreamingContext context) : + System::Data::DataSet(info, context) { + if (this->IsBinarySerialized(info, context) == true) { + this->InitVars(false); + System::ComponentModel::CollectionChangeEventHandler^ schemaChangedHandler1 = gcnew System::ComponentModel::CollectionChangeEventHandler(this, &MaintAuthorsDGV::AuthorsDS::SchemaChanged); + this->Tables->CollectionChanged += schemaChangedHandler1; + this->Relations->CollectionChanged += schemaChangedHandler1; + return; + } + System::String^ strSchema = (cli::safe_cast(info->GetValue(L"XmlSchema", System::String::typeid))); + if (this->DetermineSchemaSerializationMode(info, context) == System::Data::SchemaSerializationMode::IncludeSchema) { + System::Data::DataSet^ ds = (gcnew System::Data::DataSet()); + ds->EnforceConstraints = false; + ds->ReadXmlSchema((gcnew System::Xml::XmlTextReader((gcnew System::IO::StringReader(strSchema))))); + if (ds->Tables[L"Authors"] != nullptr) { + __super::Tables->Add((gcnew MaintAuthorsDGV::AuthorsDS::AuthorsDataTable(ds->Tables[L"Authors"]))); + } + this->DataSetName = ds->DataSetName; + this->Prefix = ds->Prefix; + this->Namespace = ds->Namespace; + this->Locale = ds->Locale; + this->CaseSensitive = ds->CaseSensitive; + this->EnforceConstraints = ds->EnforceConstraints; + this->Merge(ds, false, System::Data::MissingSchemaAction::Add); + this->InitVars(); + } + else { + this->ReadXmlSchema((gcnew System::Xml::XmlTextReader((gcnew System::IO::StringReader(strSchema))))); + } + this->GetSerializationData(info, context); + System::ComponentModel::CollectionChangeEventHandler^ schemaChangedHandler = gcnew System::ComponentModel::CollectionChangeEventHandler(this, &MaintAuthorsDGV::AuthorsDS::SchemaChanged); + __super::Tables->CollectionChanged += schemaChangedHandler; + this->Relations->CollectionChanged += schemaChangedHandler; + } + + inline MaintAuthorsDGV::AuthorsDS::AuthorsDataTable^ AuthorsDS::Authors::get() { + return this->tableAuthors; + } + + inline System::Data::SchemaSerializationMode AuthorsDS::SchemaSerializationMode::get() { + return this->_schemaSerializationMode; + } + inline System::Void AuthorsDS::SchemaSerializationMode::set(System::Data::SchemaSerializationMode value) { + this->_schemaSerializationMode = __identifier(value); + } + + inline System::Data::DataTableCollection^ AuthorsDS::Tables::get() { + return __super::Tables; + } + + inline System::Data::DataRelationCollection^ AuthorsDS::Relations::get() { + return __super::Relations; + } + + inline System::Boolean AuthorsDS::EnforceConstraints::get() { + return __super::EnforceConstraints; + } + inline System::Void AuthorsDS::EnforceConstraints::set(System::Boolean value) { + __super::EnforceConstraints = __identifier(value); + } + + inline System::Void AuthorsDS::InitializeDerivedDataSet() { + this->BeginInit(); + this->InitClass(); + this->EndInit(); + } + + inline System::Data::DataSet^ AuthorsDS::Clone() { + MaintAuthorsDGV::AuthorsDS^ cln = (cli::safe_cast(__super::Clone())); + cln->InitVars(); + return cln; + } + + inline System::Boolean AuthorsDS::ShouldSerializeTables() { + return false; + } + + inline System::Boolean AuthorsDS::ShouldSerializeRelations() { + return false; + } + + inline System::Void AuthorsDS::ReadXmlSerializable(System::Xml::XmlReader^ reader) { + if (this->DetermineSchemaSerializationMode(reader) == System::Data::SchemaSerializationMode::IncludeSchema) { + this->Reset(); + System::Data::DataSet^ ds = (gcnew System::Data::DataSet()); + ds->ReadXml(reader); + if (ds->Tables[L"Authors"] != nullptr) { + __super::Tables->Add((gcnew MaintAuthorsDGV::AuthorsDS::AuthorsDataTable(ds->Tables[L"Authors"]))); + } + this->DataSetName = ds->DataSetName; + this->Prefix = ds->Prefix; + this->Namespace = ds->Namespace; + this->Locale = ds->Locale; + this->CaseSensitive = ds->CaseSensitive; + this->EnforceConstraints = ds->EnforceConstraints; + this->Merge(ds, false, System::Data::MissingSchemaAction::Add); + this->InitVars(); + } + else { + this->ReadXml(reader); + this->InitVars(); + } + } + + inline System::Xml::Schema::XmlSchema^ AuthorsDS::GetSchemaSerializable() { + System::IO::MemoryStream^ stream = (gcnew System::IO::MemoryStream()); + this->WriteXmlSchema((gcnew System::Xml::XmlTextWriter(stream, nullptr))); + stream->Position = 0; + return System::Xml::Schema::XmlSchema::Read((gcnew System::Xml::XmlTextReader(stream)), nullptr); + } + + inline System::Void AuthorsDS::InitVars() { + this->InitVars(true); + } + + inline System::Void AuthorsDS::InitVars(System::Boolean initTable) { + this->tableAuthors = (cli::safe_cast(__super::Tables[L"Authors"])); + if (initTable == true) { + if (this->tableAuthors != nullptr) { + this->tableAuthors->InitVars(); + } + } + } + + inline System::Void AuthorsDS::InitClass() { + this->DataSetName = L"AuthorsDS"; + this->Prefix = L""; + this->Namespace = L"http://tempuri.org/AuthorsDS.xsd"; + this->EnforceConstraints = true; + this->tableAuthors = (gcnew MaintAuthorsDGV::AuthorsDS::AuthorsDataTable()); + __super::Tables->Add(this->tableAuthors); + } + + inline System::Boolean AuthorsDS::ShouldSerializeAuthors() { + return false; + } + + inline System::Void AuthorsDS::SchemaChanged(System::Object^ sender, System::ComponentModel::CollectionChangeEventArgs^ e) { + if (e->Action == System::ComponentModel::CollectionChangeAction::Remove) { + this->InitVars(); + } + } + + inline System::Xml::Schema::XmlSchemaComplexType^ AuthorsDS::GetTypedDataSetSchema(System::Xml::Schema::XmlSchemaSet^ xs) { + MaintAuthorsDGV::AuthorsDS^ ds = (gcnew MaintAuthorsDGV::AuthorsDS()); + System::Xml::Schema::XmlSchemaComplexType^ type = (gcnew System::Xml::Schema::XmlSchemaComplexType()); + System::Xml::Schema::XmlSchemaSequence^ sequence = (gcnew System::Xml::Schema::XmlSchemaSequence()); + xs->Add(ds->GetSchemaSerializable()); + System::Xml::Schema::XmlSchemaAny^ any = (gcnew System::Xml::Schema::XmlSchemaAny()); + any->Namespace = ds->Namespace; + sequence->Items->Add(any); + type->Particle = sequence; + return type; + } + + + inline AuthorsDS::AuthorsDataTable::AuthorsDataTable() { + this->TableName = L"Authors"; + this->BeginInit(); + this->InitClass(); + this->EndInit(); + } + + inline AuthorsDS::AuthorsDataTable::AuthorsDataTable(System::Data::DataTable^ table) { + this->TableName = table->TableName; + if (table->CaseSensitive != table->DataSet->CaseSensitive) { + this->CaseSensitive = table->CaseSensitive; + } + if (table->Locale->ToString() != table->DataSet->Locale->ToString()) { + this->Locale = table->Locale; + } + if (table->Namespace != table->DataSet->Namespace) { + this->Namespace = table->Namespace; + } + this->Prefix = table->Prefix; + this->MinimumCapacity = table->MinimumCapacity; + } + + inline AuthorsDS::AuthorsDataTable::AuthorsDataTable(System::Runtime::Serialization::SerializationInfo^ info, System::Runtime::Serialization::StreamingContext context) : + System::Data::DataTable(info, context) { + this->InitVars(); + } + + inline System::Data::DataColumn^ AuthorsDS::AuthorsDataTable::AuthorIDColumn::get() { + return this->columnAuthorID; + } + + inline System::Data::DataColumn^ AuthorsDS::AuthorsDataTable::LastNameColumn::get() { + return this->columnLastName; + } + + inline System::Data::DataColumn^ AuthorsDS::AuthorsDataTable::FirstNameColumn::get() { + return this->columnFirstName; + } + + inline System::Int32 AuthorsDS::AuthorsDataTable::Count::get() { + return this->Rows->Count; + } + + inline MaintAuthorsDGV::AuthorsDS::AuthorsRow^ AuthorsDS::AuthorsDataTable::default::get(System::Int32 index) { + return (cli::safe_cast(this->Rows[index])); + } + + inline System::Void AuthorsDS::AuthorsDataTable::AddAuthorsRow(MaintAuthorsDGV::AuthorsDS::AuthorsRow^ row) { + this->Rows->Add(row); + } + + inline MaintAuthorsDGV::AuthorsDS::AuthorsRow^ AuthorsDS::AuthorsDataTable::AddAuthorsRow(System::String^ LastName, + System::String^ FirstName) { + MaintAuthorsDGV::AuthorsDS::AuthorsRow^ rowAuthorsRow = (cli::safe_cast(this->NewRow())); + rowAuthorsRow->ItemArray = gcnew cli::array< System::Object^ >(3) {nullptr, LastName, FirstName}; + this->Rows->Add(rowAuthorsRow); + return rowAuthorsRow; + } + + inline MaintAuthorsDGV::AuthorsDS::AuthorsRow^ AuthorsDS::AuthorsDataTable::FindByAuthorID(System::Int32 AuthorID) { + return (cli::safe_cast(this->Rows->Find(gcnew cli::array< System::Object^ >(1) {AuthorID}))); + } + + inline System::Collections::IEnumerator^ AuthorsDS::AuthorsDataTable::GetEnumerator() { + return this->Rows->GetEnumerator(); + } + + inline System::Data::DataTable^ AuthorsDS::AuthorsDataTable::Clone() { + MaintAuthorsDGV::AuthorsDS::AuthorsDataTable^ cln = (cli::safe_cast(__super::Clone())); + cln->InitVars(); + return cln; + } + + inline System::Data::DataTable^ AuthorsDS::AuthorsDataTable::CreateInstance() { + return (gcnew MaintAuthorsDGV::AuthorsDS::AuthorsDataTable()); + } + + inline System::Void AuthorsDS::AuthorsDataTable::InitVars() { + this->columnAuthorID = __super::Columns[L"AuthorID"]; + this->columnLastName = __super::Columns[L"LastName"]; + this->columnFirstName = __super::Columns[L"FirstName"]; + } + + inline System::Void AuthorsDS::AuthorsDataTable::InitClass() { + this->columnAuthorID = (gcnew System::Data::DataColumn(L"AuthorID", System::Int32::typeid, nullptr, System::Data::MappingType::Element)); + __super::Columns->Add(this->columnAuthorID); + this->columnLastName = (gcnew System::Data::DataColumn(L"LastName", System::String::typeid, nullptr, System::Data::MappingType::Element)); + __super::Columns->Add(this->columnLastName); + this->columnFirstName = (gcnew System::Data::DataColumn(L"FirstName", System::String::typeid, nullptr, System::Data::MappingType::Element)); + __super::Columns->Add(this->columnFirstName); + this->Constraints->Add((gcnew System::Data::UniqueConstraint(L"Constraint1", gcnew cli::array< System::Data::DataColumn^ >(1) {this->columnAuthorID}, + true))); + this->columnAuthorID->AutoIncrement = true; + this->columnAuthorID->AutoIncrementSeed = -1; + this->columnAuthorID->AutoIncrementStep = -1; + this->columnAuthorID->AllowDBNull = false; + this->columnAuthorID->ReadOnly = true; + this->columnAuthorID->Unique = true; + this->columnLastName->AllowDBNull = false; + this->columnLastName->MaxLength = 50; + this->columnFirstName->AllowDBNull = false; + this->columnFirstName->MaxLength = 50; + this->Locale = (gcnew System::Globalization::CultureInfo(L"en-US")); + } + + inline MaintAuthorsDGV::AuthorsDS::AuthorsRow^ AuthorsDS::AuthorsDataTable::NewAuthorsRow() { + return (cli::safe_cast(this->NewRow())); + } + + inline System::Data::DataRow^ AuthorsDS::AuthorsDataTable::NewRowFromBuilder(System::Data::DataRowBuilder^ builder) { + return (gcnew MaintAuthorsDGV::AuthorsDS::AuthorsRow(builder)); + } + + inline System::Type^ AuthorsDS::AuthorsDataTable::GetRowType() { + return MaintAuthorsDGV::AuthorsDS::AuthorsRow::typeid; + } + + inline System::Void AuthorsDS::AuthorsDataTable::OnRowChanged(System::Data::DataRowChangeEventArgs^ e) { + __super::OnRowChanged(e); + { + this->AuthorsRowChanged(this, (gcnew MaintAuthorsDGV::AuthorsDS::AuthorsRowChangeEvent((cli::safe_cast(e->Row)), + e->Action))); + } + } + + inline System::Void AuthorsDS::AuthorsDataTable::OnRowChanging(System::Data::DataRowChangeEventArgs^ e) { + __super::OnRowChanging(e); + { + this->AuthorsRowChanging(this, (gcnew MaintAuthorsDGV::AuthorsDS::AuthorsRowChangeEvent((cli::safe_cast(e->Row)), + e->Action))); + } + } + + inline System::Void AuthorsDS::AuthorsDataTable::OnRowDeleted(System::Data::DataRowChangeEventArgs^ e) { + __super::OnRowDeleted(e); + { + this->AuthorsRowDeleted(this, (gcnew MaintAuthorsDGV::AuthorsDS::AuthorsRowChangeEvent((cli::safe_cast(e->Row)), + e->Action))); + } + } + + inline System::Void AuthorsDS::AuthorsDataTable::OnRowDeleting(System::Data::DataRowChangeEventArgs^ e) { + __super::OnRowDeleting(e); + { + this->AuthorsRowDeleting(this, (gcnew MaintAuthorsDGV::AuthorsDS::AuthorsRowChangeEvent((cli::safe_cast(e->Row)), + e->Action))); + } + } + + inline System::Void AuthorsDS::AuthorsDataTable::RemoveAuthorsRow(MaintAuthorsDGV::AuthorsDS::AuthorsRow^ row) { + this->Rows->Remove(row); + } + + inline System::Xml::Schema::XmlSchemaComplexType^ AuthorsDS::AuthorsDataTable::GetTypedTableSchema(System::Xml::Schema::XmlSchemaSet^ xs) { + System::Xml::Schema::XmlSchemaComplexType^ type = (gcnew System::Xml::Schema::XmlSchemaComplexType()); + System::Xml::Schema::XmlSchemaSequence^ sequence = (gcnew System::Xml::Schema::XmlSchemaSequence()); + MaintAuthorsDGV::AuthorsDS^ ds = (gcnew MaintAuthorsDGV::AuthorsDS()); + xs->Add(ds->GetSchemaSerializable()); + System::Xml::Schema::XmlSchemaAny^ any1 = (gcnew System::Xml::Schema::XmlSchemaAny()); + any1->Namespace = L"http://www.w3.org/2001/XMLSchema"; + any1->MinOccurs = System::Decimal(0); + any1->MaxOccurs = System::Decimal::MaxValue; + any1->ProcessContents = System::Xml::Schema::XmlSchemaContentProcessing::Lax; + sequence->Items->Add(any1); + System::Xml::Schema::XmlSchemaAny^ any2 = (gcnew System::Xml::Schema::XmlSchemaAny()); + any2->Namespace = L"urn:schemas-microsoft-com:xml-diffgram-v1"; + any2->MinOccurs = System::Decimal(1); + any2->ProcessContents = System::Xml::Schema::XmlSchemaContentProcessing::Lax; + sequence->Items->Add(any2); + System::Xml::Schema::XmlSchemaAttribute^ attribute1 = (gcnew System::Xml::Schema::XmlSchemaAttribute()); + attribute1->Name = L"namespace"; + attribute1->FixedValue = ds->Namespace; + type->Attributes->Add(attribute1); + System::Xml::Schema::XmlSchemaAttribute^ attribute2 = (gcnew System::Xml::Schema::XmlSchemaAttribute()); + attribute2->Name = L"tableTypeName"; + attribute2->FixedValue = L"AuthorsDataTable"; + type->Attributes->Add(attribute2); + type->Particle = sequence; + return type; + } + + + inline AuthorsDS::AuthorsRow::AuthorsRow(System::Data::DataRowBuilder^ rb) : + System::Data::DataRow(rb) { + this->tableAuthors = (cli::safe_cast(this->Table)); + } + + inline System::Int32 AuthorsDS::AuthorsRow::AuthorID::get() { + return (*cli::safe_cast(this[this->tableAuthors->AuthorIDColumn])); + } + inline System::Void AuthorsDS::AuthorsRow::AuthorID::set(System::Int32 value) { + this[this->tableAuthors->AuthorIDColumn] = value; + } + + inline System::String^ AuthorsDS::AuthorsRow::LastName::get() { + return (cli::safe_cast(this[this->tableAuthors->LastNameColumn])); + } + inline System::Void AuthorsDS::AuthorsRow::LastName::set(System::String^ value) { + this[this->tableAuthors->LastNameColumn] = value; + } + + inline System::String^ AuthorsDS::AuthorsRow::FirstName::get() { + return (cli::safe_cast(this[this->tableAuthors->FirstNameColumn])); + } + inline System::Void AuthorsDS::AuthorsRow::FirstName::set(System::String^ value) { + this[this->tableAuthors->FirstNameColumn] = value; + } + + + inline AuthorsDS::AuthorsRowChangeEvent::AuthorsRowChangeEvent(MaintAuthorsDGV::AuthorsDS::AuthorsRow^ row, System::Data::DataRowAction action) { + this->eventRow = row; + this->eventAction = action; + } + + inline MaintAuthorsDGV::AuthorsDS::AuthorsRow^ AuthorsDS::AuthorsRowChangeEvent::Row::get() { + return this->eventRow; + } + + inline System::Data::DataRowAction AuthorsDS::AuthorsRowChangeEvent::Action::get() { + return this->eventAction; + } +} +namespace MaintAuthorsDGV { + namespace AuthorsDSTableAdapters { + + using namespace System; + ref class AuthorsTableAdapter; + + + [System::CodeDom::Compiler::GeneratedCodeAttribute(L"System.Data.Design.TypedDataSetGenerator", L"2.0.0.0"), + System::ComponentModel::DesignerCategoryAttribute(L"code"), + System::ComponentModel::ToolboxItem(true), + System::ComponentModel::DataObjectAttribute(true), + System::ComponentModel::DesignerAttribute(L"Microsoft.VSDesigner.DataSource.Design.TableAdapterDesigner, Microsoft.VSDesigner" +L", Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"), + System::ComponentModel::Design::HelpKeywordAttribute(L"vs.data.TableAdapter"), + System::CLSCompliantAttribute(false)] + public ref class AuthorsTableAdapter : public System::ComponentModel::Component { + + private: System::Data::SqlClient::SqlDataAdapter^ _adapter; + + private: System::Data::SqlClient::SqlConnection^ _connection; + + private: cli::array< System::Data::SqlClient::SqlCommand^ >^ _commandCollection; + + private: System::Boolean _clearBeforeFill; + + public: [System::Diagnostics::DebuggerNonUserCodeAttribute] + AuthorsTableAdapter(); + private: [System::Diagnostics::DebuggerNonUserCodeAttribute] + property System::Data::SqlClient::SqlDataAdapter^ Adapter { + System::Data::SqlClient::SqlDataAdapter^ get(); + } + + internal: [System::Diagnostics::DebuggerNonUserCodeAttribute] + property System::Data::SqlClient::SqlConnection^ Connection { + System::Data::SqlClient::SqlConnection^ get(); + System::Void set(System::Data::SqlClient::SqlConnection^ value); + } + + protected: [System::Diagnostics::DebuggerNonUserCodeAttribute] + property cli::array< System::Data::SqlClient::SqlCommand^ >^ CommandCollection { + cli::array< System::Data::SqlClient::SqlCommand^ >^ get(); + } + + public: [System::Diagnostics::DebuggerNonUserCodeAttribute] + property System::Boolean ClearBeforeFill { + System::Boolean get(); + System::Void set(System::Boolean value); + } + + private: [System::Diagnostics::DebuggerNonUserCodeAttribute] + System::Void InitAdapter(); + + private: [System::Diagnostics::DebuggerNonUserCodeAttribute] + System::Void InitConnection(); + + private: [System::Diagnostics::DebuggerNonUserCodeAttribute] + System::Void InitCommandCollection(); + + public: [System::Diagnostics::DebuggerNonUserCodeAttribute] + [System::ComponentModel::Design::HelpKeywordAttribute(L"vs.data.TableAdapter")] + [System::ComponentModel::DataObjectMethodAttribute(System::ComponentModel::DataObjectMethodType::Fill, true)] + virtual System::Int32 Fill(MaintAuthorsDGV::AuthorsDS::AuthorsDataTable^ dataTable); + + public: [System::Diagnostics::DebuggerNonUserCodeAttribute] + [System::ComponentModel::Design::HelpKeywordAttribute(L"vs.data.TableAdapter")] + [System::ComponentModel::DataObjectMethodAttribute(System::ComponentModel::DataObjectMethodType::Select, true)] + virtual MaintAuthorsDGV::AuthorsDS::AuthorsDataTable^ GetData(); + + public: [System::Diagnostics::DebuggerNonUserCodeAttribute] + [System::ComponentModel::Design::HelpKeywordAttribute(L"vs.data.TableAdapter")] + virtual System::Int32 Update(MaintAuthorsDGV::AuthorsDS::AuthorsDataTable^ dataTable); + + public: [System::Diagnostics::DebuggerNonUserCodeAttribute] + [System::ComponentModel::Design::HelpKeywordAttribute(L"vs.data.TableAdapter")] + virtual System::Int32 Update(MaintAuthorsDGV::AuthorsDS^ dataSet); + + public: [System::Diagnostics::DebuggerNonUserCodeAttribute] + [System::ComponentModel::Design::HelpKeywordAttribute(L"vs.data.TableAdapter")] + virtual System::Int32 Update(System::Data::DataRow^ dataRow); + + public: [System::Diagnostics::DebuggerNonUserCodeAttribute] + [System::ComponentModel::Design::HelpKeywordAttribute(L"vs.data.TableAdapter")] + virtual System::Int32 Update(cli::array< System::Data::DataRow^ >^ dataRows); + + public: [System::Diagnostics::DebuggerNonUserCodeAttribute] + [System::ComponentModel::Design::HelpKeywordAttribute(L"vs.data.TableAdapter")] + [System::ComponentModel::DataObjectMethodAttribute(System::ComponentModel::DataObjectMethodType::Delete, true)] + virtual System::Int32 Delete(System::Int32 Original_AuthorID, System::String^ Original_LastName, System::String^ Original_FirstName); + + public: [System::Diagnostics::DebuggerNonUserCodeAttribute] + [System::ComponentModel::Design::HelpKeywordAttribute(L"vs.data.TableAdapter")] + [System::ComponentModel::DataObjectMethodAttribute(System::ComponentModel::DataObjectMethodType::Insert, true)] + virtual System::Int32 Insert(System::String^ LastName, System::String^ FirstName); + + public: [System::Diagnostics::DebuggerNonUserCodeAttribute] + [System::ComponentModel::Design::HelpKeywordAttribute(L"vs.data.TableAdapter")] + [System::ComponentModel::DataObjectMethodAttribute(System::ComponentModel::DataObjectMethodType::Update, true)] + virtual System::Int32 Update( + System::String^ LastName, + System::String^ FirstName, + System::Int32 Original_AuthorID, + System::String^ Original_LastName, + System::String^ Original_FirstName, + System::Int32 AuthorID); + }; + } +} +namespace MaintAuthorsDGV { + namespace AuthorsDSTableAdapters { + + + inline AuthorsTableAdapter::AuthorsTableAdapter() { + this->ClearBeforeFill = true; + } + + inline System::Data::SqlClient::SqlDataAdapter^ AuthorsTableAdapter::Adapter::get() { + if (this->_adapter == nullptr) { + this->InitAdapter(); + } + return this->_adapter; + } + + inline System::Data::SqlClient::SqlConnection^ AuthorsTableAdapter::Connection::get() { + if (this->_connection == nullptr) { + this->InitConnection(); + } + return this->_connection; + } + inline System::Void AuthorsTableAdapter::Connection::set(System::Data::SqlClient::SqlConnection^ value) { + this->_connection = __identifier(value); + if (this->Adapter->InsertCommand != nullptr) { + this->Adapter->InsertCommand->Connection = __identifier(value); + } + if (this->Adapter->DeleteCommand != nullptr) { + this->Adapter->DeleteCommand->Connection = __identifier(value); + } + if (this->Adapter->UpdateCommand != nullptr) { + this->Adapter->UpdateCommand->Connection = __identifier(value); + } + for ( System::Int32 i = 0; (i < this->CommandCollection->Length); i = (i + 1)) { + if (this->CommandCollection[i] != nullptr) { + (cli::safe_cast(this->CommandCollection[i]))->Connection = __identifier(value); + } + } + } + + inline cli::array< System::Data::SqlClient::SqlCommand^ >^ AuthorsTableAdapter::CommandCollection::get() { + if (this->_commandCollection == nullptr) { + this->InitCommandCollection(); + } + return this->_commandCollection; + } + + inline System::Boolean AuthorsTableAdapter::ClearBeforeFill::get() { + return this->_clearBeforeFill; + } + inline System::Void AuthorsTableAdapter::ClearBeforeFill::set(System::Boolean value) { + this->_clearBeforeFill = __identifier(value); + } + + inline System::Void AuthorsTableAdapter::InitAdapter() { + this->_adapter = (gcnew System::Data::SqlClient::SqlDataAdapter()); + System::Data::Common::DataTableMapping^ tableMapping = (gcnew System::Data::Common::DataTableMapping()); + tableMapping->SourceTable = L"Table"; + tableMapping->DataSetTable = L"Authors"; + tableMapping->ColumnMappings->Add(L"AuthorID", L"AuthorID"); + tableMapping->ColumnMappings->Add(L"LastName", L"LastName"); + tableMapping->ColumnMappings->Add(L"FirstName", L"FirstName"); + this->_adapter->TableMappings->Add(tableMapping); + this->_adapter->DeleteCommand = (gcnew System::Data::SqlClient::SqlCommand()); + this->_adapter->DeleteCommand->Connection = this->Connection; + this->_adapter->DeleteCommand->CommandText = L"DELETE FROM [dbo].[Authors] WHERE (([AuthorID] = @Original_AuthorID) AND ([LastNa" +L"me] = @Original_LastName) AND ([FirstName] = @Original_FirstName))"; + this->_adapter->DeleteCommand->CommandType = System::Data::CommandType::Text; + this->_adapter->DeleteCommand->Parameters->Add((gcnew System::Data::SqlClient::SqlParameter(L"@Original_AuthorID", System::Data::SqlDbType::Int, + 0, System::Data::ParameterDirection::Input, 0, 0, L"AuthorID", System::Data::DataRowVersion::Original, false, nullptr, + L"", L"", L""))); + this->_adapter->DeleteCommand->Parameters->Add((gcnew System::Data::SqlClient::SqlParameter(L"@Original_LastName", System::Data::SqlDbType::VarChar, + 0, System::Data::ParameterDirection::Input, 0, 0, L"LastName", System::Data::DataRowVersion::Original, false, nullptr, + L"", L"", L""))); + this->_adapter->DeleteCommand->Parameters->Add((gcnew System::Data::SqlClient::SqlParameter(L"@Original_FirstName", System::Data::SqlDbType::VarChar, + 0, System::Data::ParameterDirection::Input, 0, 0, L"FirstName", System::Data::DataRowVersion::Original, false, nullptr, + L"", L"", L""))); + this->_adapter->InsertCommand = (gcnew System::Data::SqlClient::SqlCommand()); + this->_adapter->InsertCommand->Connection = this->Connection; + this->_adapter->InsertCommand->CommandText = L"INSERT INTO [dbo].[Authors] ([LastName], [FirstName]) VALUES (@LastName, @FirstNa" +L"me);\r\nSELECT AuthorID, LastName, FirstName FROM Authors WHERE (AuthorID = SCOPE_" +L"IDENTITY())"; + this->_adapter->InsertCommand->CommandType = System::Data::CommandType::Text; + this->_adapter->InsertCommand->Parameters->Add((gcnew System::Data::SqlClient::SqlParameter(L"@LastName", System::Data::SqlDbType::VarChar, + 0, System::Data::ParameterDirection::Input, 0, 0, L"LastName", System::Data::DataRowVersion::Current, false, nullptr, + L"", L"", L""))); + this->_adapter->InsertCommand->Parameters->Add((gcnew System::Data::SqlClient::SqlParameter(L"@FirstName", System::Data::SqlDbType::VarChar, + 0, System::Data::ParameterDirection::Input, 0, 0, L"FirstName", System::Data::DataRowVersion::Current, false, nullptr, + L"", L"", L""))); + this->_adapter->UpdateCommand = (gcnew System::Data::SqlClient::SqlCommand()); + this->_adapter->UpdateCommand->Connection = this->Connection; + this->_adapter->UpdateCommand->CommandText = L"UPDATE [dbo].[Authors] SET [LastName] = @LastName, [FirstName] = @FirstName WHERE" +L" (([AuthorID] = @Original_AuthorID) AND ([LastName] = @Original_LastName) AND ([" +L"FirstName] = @Original_FirstName));\r\nSELECT AuthorID, LastName, FirstName FROM A" +L"uthors WHERE (AuthorID = @AuthorID)"; + this->_adapter->UpdateCommand->CommandType = System::Data::CommandType::Text; + this->_adapter->UpdateCommand->Parameters->Add((gcnew System::Data::SqlClient::SqlParameter(L"@LastName", System::Data::SqlDbType::VarChar, + 0, System::Data::ParameterDirection::Input, 0, 0, L"LastName", System::Data::DataRowVersion::Current, false, nullptr, + L"", L"", L""))); + this->_adapter->UpdateCommand->Parameters->Add((gcnew System::Data::SqlClient::SqlParameter(L"@FirstName", System::Data::SqlDbType::VarChar, + 0, System::Data::ParameterDirection::Input, 0, 0, L"FirstName", System::Data::DataRowVersion::Current, false, nullptr, + L"", L"", L""))); + this->_adapter->UpdateCommand->Parameters->Add((gcnew System::Data::SqlClient::SqlParameter(L"@Original_AuthorID", System::Data::SqlDbType::Int, + 0, System::Data::ParameterDirection::Input, 0, 0, L"AuthorID", System::Data::DataRowVersion::Original, false, nullptr, + L"", L"", L""))); + this->_adapter->UpdateCommand->Parameters->Add((gcnew System::Data::SqlClient::SqlParameter(L"@Original_LastName", System::Data::SqlDbType::VarChar, + 0, System::Data::ParameterDirection::Input, 0, 0, L"LastName", System::Data::DataRowVersion::Original, false, nullptr, + L"", L"", L""))); + this->_adapter->UpdateCommand->Parameters->Add((gcnew System::Data::SqlClient::SqlParameter(L"@Original_FirstName", System::Data::SqlDbType::VarChar, + 0, System::Data::ParameterDirection::Input, 0, 0, L"FirstName", System::Data::DataRowVersion::Original, false, nullptr, + L"", L"", L""))); + this->_adapter->UpdateCommand->Parameters->Add((gcnew System::Data::SqlClient::SqlParameter(L"@AuthorID", System::Data::SqlDbType::Int, + 4, System::Data::ParameterDirection::Input, 0, 0, L"AuthorID", System::Data::DataRowVersion::Current, false, nullptr, + L"", L"", L""))); + } + + inline System::Void AuthorsTableAdapter::InitConnection() { + this->_connection = (gcnew System::Data::SqlClient::SqlConnection()); + this->_connection->ConnectionString = L"Data Source=AMIDALA;Initial Catalog=DCV_DB;Integrated Security=True;Pooling=False" +L""; + } + + inline System::Void AuthorsTableAdapter::InitCommandCollection() { + this->_commandCollection = gcnew cli::array< System::Data::SqlClient::SqlCommand^ >(1); + this->_commandCollection[0] = (gcnew System::Data::SqlClient::SqlCommand()); + this->_commandCollection[0]->Connection = this->Connection; + this->_commandCollection[0]->CommandText = L"SELECT AuthorID, LastName, FirstName FROM dbo.Authors"; + this->_commandCollection[0]->CommandType = System::Data::CommandType::Text; + } + + inline System::Int32 AuthorsTableAdapter::Fill(MaintAuthorsDGV::AuthorsDS::AuthorsDataTable^ dataTable) { + this->Adapter->SelectCommand = this->CommandCollection[0]; + if (this->ClearBeforeFill == true) { + dataTable->Clear(); + } + System::Int32 returnValue = this->Adapter->Fill(dataTable); + return returnValue; + } + + inline MaintAuthorsDGV::AuthorsDS::AuthorsDataTable^ AuthorsTableAdapter::GetData() { + this->Adapter->SelectCommand = this->CommandCollection[0]; + MaintAuthorsDGV::AuthorsDS::AuthorsDataTable^ dataTable = (gcnew MaintAuthorsDGV::AuthorsDS::AuthorsDataTable()); + this->Adapter->Fill(dataTable); + return dataTable; + } + + inline System::Int32 AuthorsTableAdapter::Update(MaintAuthorsDGV::AuthorsDS::AuthorsDataTable^ dataTable) { + return this->Adapter->Update(dataTable); + } + + inline System::Int32 AuthorsTableAdapter::Update(MaintAuthorsDGV::AuthorsDS^ dataSet) { + return this->Adapter->Update(dataSet, L"Authors"); + } + + inline System::Int32 AuthorsTableAdapter::Update(System::Data::DataRow^ dataRow) { + return this->Adapter->Update(gcnew cli::array< System::Data::DataRow^ >(1) {dataRow}); + } + + inline System::Int32 AuthorsTableAdapter::Update(cli::array< System::Data::DataRow^ >^ dataRows) { + return this->Adapter->Update(dataRows); + } + + inline System::Int32 AuthorsTableAdapter::Delete(System::Int32 Original_AuthorID, System::String^ Original_LastName, + System::String^ Original_FirstName) { + this->Adapter->DeleteCommand->Parameters[0]->Value = static_cast(Original_AuthorID); + if (Original_LastName == nullptr) { + throw (gcnew System::ArgumentNullException(L"Original_LastName")); + } + else { + this->Adapter->DeleteCommand->Parameters[1]->Value = (cli::safe_cast(Original_LastName)); + } + if (Original_FirstName == nullptr) { + throw (gcnew System::ArgumentNullException(L"Original_FirstName")); + } + else { + this->Adapter->DeleteCommand->Parameters[2]->Value = (cli::safe_cast(Original_FirstName)); + } + System::Data::ConnectionState previousConnectionState = this->Adapter->DeleteCommand->Connection->State; + this->Adapter->DeleteCommand->Connection->Open(); + try { + System::Int32 returnValue = this->Adapter->DeleteCommand->ExecuteNonQuery(); + return returnValue; + } + finally { + if (previousConnectionState == System::Data::ConnectionState::Closed) { + this->Adapter->DeleteCommand->Connection->Close(); + } + } + } + + inline System::Int32 AuthorsTableAdapter::Insert(System::String^ LastName, System::String^ FirstName) { + if (LastName == nullptr) { + throw (gcnew System::ArgumentNullException(L"LastName")); + } + else { + this->Adapter->InsertCommand->Parameters[0]->Value = (cli::safe_cast(LastName)); + } + if (FirstName == nullptr) { + throw (gcnew System::ArgumentNullException(L"FirstName")); + } + else { + this->Adapter->InsertCommand->Parameters[1]->Value = (cli::safe_cast(FirstName)); + } + System::Data::ConnectionState previousConnectionState = this->Adapter->InsertCommand->Connection->State; + this->Adapter->InsertCommand->Connection->Open(); + try { + System::Int32 returnValue = this->Adapter->InsertCommand->ExecuteNonQuery(); + return returnValue; + } + finally { + if (previousConnectionState == System::Data::ConnectionState::Closed) { + this->Adapter->InsertCommand->Connection->Close(); + } + } + } + + inline System::Int32 AuthorsTableAdapter::Update( + System::String^ LastName, + System::String^ FirstName, + System::Int32 Original_AuthorID, + System::String^ Original_LastName, + System::String^ Original_FirstName, + System::Int32 AuthorID) { + if (LastName == nullptr) { + throw (gcnew System::ArgumentNullException(L"LastName")); + } + else { + this->Adapter->UpdateCommand->Parameters[0]->Value = (cli::safe_cast(LastName)); + } + if (FirstName == nullptr) { + throw (gcnew System::ArgumentNullException(L"FirstName")); + } + else { + this->Adapter->UpdateCommand->Parameters[1]->Value = (cli::safe_cast(FirstName)); + } + this->Adapter->UpdateCommand->Parameters[2]->Value = static_cast(Original_AuthorID); + if (Original_LastName == nullptr) { + throw (gcnew System::ArgumentNullException(L"Original_LastName")); + } + else { + this->Adapter->UpdateCommand->Parameters[3]->Value = (cli::safe_cast(Original_LastName)); + } + if (Original_FirstName == nullptr) { + throw (gcnew System::ArgumentNullException(L"Original_FirstName")); + } + else { + this->Adapter->UpdateCommand->Parameters[4]->Value = (cli::safe_cast(Original_FirstName)); + } + this->Adapter->UpdateCommand->Parameters[5]->Value = static_cast(AuthorID); + System::Data::ConnectionState previousConnectionState = this->Adapter->UpdateCommand->Connection->State; + this->Adapter->UpdateCommand->Connection->Open(); + try { + System::Int32 returnValue = this->Adapter->UpdateCommand->ExecuteNonQuery(); + return returnValue; + } + finally { + if (previousConnectionState == System::Data::ConnectionState::Closed) { + this->Adapter->UpdateCommand->Connection->Close(); + } + } + } + } +} diff --git a/Chapter12/MaintAuthorsDGV/AuthorsDS.xsc b/Chapter12/MaintAuthorsDGV/AuthorsDS.xsc new file mode 100644 index 0000000..5dbde4a --- /dev/null +++ b/Chapter12/MaintAuthorsDGV/AuthorsDS.xsc @@ -0,0 +1,10 @@ + + + + + + \ No newline at end of file diff --git a/Chapter12/MaintAuthorsDGV/AuthorsDS.xsd b/Chapter12/MaintAuthorsDGV/AuthorsDS.xsd new file mode 100644 index 0000000..3909605 --- /dev/null +++ b/Chapter12/MaintAuthorsDGV/AuthorsDS.xsd @@ -0,0 +1,113 @@ + + + + + + + + + + + + + + + + DELETE FROM [dbo].[Authors] WHERE (([AuthorID] = @Original_AuthorID) AND ([LastName] = @Original_LastName) AND ([FirstName] = @Original_FirstName)) + + + + + + + + + + + + + INSERT INTO [dbo].[Authors] ([LastName], [FirstName]) VALUES (@LastName, @FirstName); +SELECT AuthorID, LastName, FirstName FROM Authors WHERE (AuthorID = SCOPE_IDENTITY()) + + + + + + + + + + + SELECT AuthorID, LastName, FirstName FROM dbo.Authors + + + + + + + UPDATE [dbo].[Authors] SET [LastName] = @LastName, [FirstName] = @FirstName WHERE (([AuthorID] = @Original_AuthorID) AND ([LastName] = @Original_LastName) AND ([FirstName] = @Original_FirstName)); +SELECT AuthorID, LastName, FirstName FROM Authors WHERE (AuthorID = @AuthorID) + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Chapter12/MaintAuthorsDGV/AuthorsDS.xss b/Chapter12/MaintAuthorsDGV/AuthorsDS.xss new file mode 100644 index 0000000..4b6513d --- /dev/null +++ b/Chapter12/MaintAuthorsDGV/AuthorsDS.xss @@ -0,0 +1,12 @@ + + + + + + + + \ No newline at end of file diff --git a/Chapter12/MaintAuthorsDGV/Form1.h b/Chapter12/MaintAuthorsDGV/Form1.h new file mode 100644 index 0000000..f4e457e --- /dev/null +++ b/Chapter12/MaintAuthorsDGV/Form1.h @@ -0,0 +1,179 @@ +#pragma once + + +namespace MaintAuthorsDGV +{ + using namespace System; + using namespace System::ComponentModel; + using namespace System::Collections; + using namespace System::Windows::Forms; + using namespace System::Data; + using namespace System::Drawing; + + public ref class Form1 : public System::Windows::Forms::Form + { + public: + Form1(void) + { + InitializeComponent(); + } + + protected: + ~Form1() + { + if (components) + { + delete components; + } + } + + private: + System::Windows::Forms::DataGridView^ dataGridView1; + System::Windows::Forms::BindingSource^ authorsDSBindingSource; + MaintAuthorsDGV::AuthorsDS^ AuthorsDS; + MaintAuthorsDGV::AuthorsDSTableAdapters::AuthorsTableAdapter^ AuthorsTableAdapter; + System::Windows::Forms::Button^ bnCommit; + System::Windows::Forms::Button^ bnRollback; + private: System::Windows::Forms::DataGridViewTextBoxColumn^ authorIDDataGridViewTextBoxColumn; + private: System::Windows::Forms::DataGridViewTextBoxColumn^ lastNameDataGridViewTextBoxColumn; + private: System::Windows::Forms::DataGridViewTextBoxColumn^ firstNameDataGridViewTextBoxColumn; + + + + + + + System::ComponentModel::IContainer^ components; + +#pragma region Windows Form Designer generated code + + void InitializeComponent(void) + { + this->components = (gcnew System::ComponentModel::Container()); + System::Windows::Forms::DataGridViewCellStyle^ dataGridViewCellStyle1 = (gcnew System::Windows::Forms::DataGridViewCellStyle()); + this->dataGridView1 = (gcnew System::Windows::Forms::DataGridView()); + this->authorIDDataGridViewTextBoxColumn = (gcnew System::Windows::Forms::DataGridViewTextBoxColumn()); + this->lastNameDataGridViewTextBoxColumn = (gcnew System::Windows::Forms::DataGridViewTextBoxColumn()); + this->firstNameDataGridViewTextBoxColumn = (gcnew System::Windows::Forms::DataGridViewTextBoxColumn()); + this->authorsDSBindingSource = (gcnew System::Windows::Forms::BindingSource(this->components)); + this->AuthorsDS = (gcnew MaintAuthorsDGV::AuthorsDS()); + this->AuthorsTableAdapter = (gcnew MaintAuthorsDGV::AuthorsDSTableAdapters::AuthorsTableAdapter()); + this->bnCommit = (gcnew System::Windows::Forms::Button()); + this->bnRollback = (gcnew System::Windows::Forms::Button()); + (cli::safe_cast(this->dataGridView1))->BeginInit(); + (cli::safe_cast(this->authorsDSBindingSource))->BeginInit(); + (cli::safe_cast(this->AuthorsDS))->BeginInit(); + this->SuspendLayout(); + // + // dataGridView1 + // + this->dataGridView1->Anchor = static_cast((((System::Windows::Forms::AnchorStyles::Top | System::Windows::Forms::AnchorStyles::Bottom) + | System::Windows::Forms::AnchorStyles::Left) + | System::Windows::Forms::AnchorStyles::Right)); + this->dataGridView1->AutoGenerateColumns = false; + this->dataGridView1->ColumnHeadersHeightSizeMode = System::Windows::Forms::DataGridViewColumnHeadersHeightSizeMode::AutoSize; + this->dataGridView1->Columns->AddRange(gcnew cli::array< System::Windows::Forms::DataGridViewColumn^ >(3) {this->authorIDDataGridViewTextBoxColumn, + this->lastNameDataGridViewTextBoxColumn, this->firstNameDataGridViewTextBoxColumn}); + this->dataGridView1->DataSource = this->authorsDSBindingSource; + this->dataGridView1->ImeMode = System::Windows::Forms::ImeMode::Disable; + this->dataGridView1->Location = System::Drawing::Point(12, 13); + this->dataGridView1->Name = L"dataGridView1"; + this->dataGridView1->Size = System::Drawing::Size(403, 219); + this->dataGridView1->TabIndex = 0; + // + // authorIDDataGridViewTextBoxColumn + // + this->authorIDDataGridViewTextBoxColumn->DataPropertyName = L"AuthorID"; + dataGridViewCellStyle1->Alignment = System::Windows::Forms::DataGridViewContentAlignment::MiddleCenter; + this->authorIDDataGridViewTextBoxColumn->DefaultCellStyle = dataGridViewCellStyle1; + this->authorIDDataGridViewTextBoxColumn->HeaderText = L"AuthorID"; + this->authorIDDataGridViewTextBoxColumn->Name = L"authorIDDataGridViewTextBoxColumn"; + this->authorIDDataGridViewTextBoxColumn->ReadOnly = true; + this->authorIDDataGridViewTextBoxColumn->Width = 60; + // + // lastNameDataGridViewTextBoxColumn + // + this->lastNameDataGridViewTextBoxColumn->DataPropertyName = L"LastName"; + this->lastNameDataGridViewTextBoxColumn->HeaderText = L"LastName"; + this->lastNameDataGridViewTextBoxColumn->Name = L"lastNameDataGridViewTextBoxColumn"; + this->lastNameDataGridViewTextBoxColumn->Width = 150; + // + // firstNameDataGridViewTextBoxColumn + // + this->firstNameDataGridViewTextBoxColumn->DataPropertyName = L"FirstName"; + this->firstNameDataGridViewTextBoxColumn->HeaderText = L"FirstName"; + this->firstNameDataGridViewTextBoxColumn->Name = L"firstNameDataGridViewTextBoxColumn"; + this->firstNameDataGridViewTextBoxColumn->Width = 150; + // + // authorsDSBindingSource + // + this->authorsDSBindingSource->DataMember = L"Authors"; + this->authorsDSBindingSource->DataSource = this->AuthorsDS; + // + // AuthorsDS + // + this->AuthorsDS->DataSetName = L"AuthorsDS"; + // + // AuthorsTableAdapter + // + this->AuthorsTableAdapter->ClearBeforeFill = true; + // + // bnCommit + // + this->bnCommit->Location = System::Drawing::Point(120, 238); + this->bnCommit->Name = L"bnCommit"; + this->bnCommit->Size = System::Drawing::Size(75, 23); + this->bnCommit->TabIndex = 1; + this->bnCommit->Text = L"Commit"; + this->bnCommit->UseVisualStyleBackColor = true; + this->bnCommit->Click += gcnew System::EventHandler(this, &Form1::bnCommit_Click); + // + // bnRollback + // + this->bnRollback->Location = System::Drawing::Point(225, 238); + this->bnRollback->Name = L"bnRollback"; + this->bnRollback->Size = System::Drawing::Size(75, 23); + this->bnRollback->TabIndex = 2; + this->bnRollback->Text = L"Rollback"; + this->bnRollback->UseVisualStyleBackColor = true; + this->bnRollback->Click += gcnew System::EventHandler(this, &Form1::bnRollback_Click); + // + // Form1 + // + this->AutoScaleDimensions = System::Drawing::SizeF(6, 13); + this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font; + this->ClientSize = System::Drawing::Size(423, 273); + this->Controls->Add(this->bnRollback); + this->Controls->Add(this->bnCommit); + this->Controls->Add(this->dataGridView1); + this->Name = L"Form1"; + this->Text = L"Maintain Authors using a DataGridView"; + this->Load += gcnew System::EventHandler(this, &Form1::Form1_Load); + (cli::safe_cast(this->dataGridView1))->EndInit(); + (cli::safe_cast(this->authorsDSBindingSource))->EndInit(); + (cli::safe_cast(this->AuthorsDS))->EndInit(); + this->ResumeLayout(false); + + } + +#pragma endregion + + private: + System::Void Form1_Load(System::Object^ sender, System::EventArgs^ e) + { + this->AuthorsTableAdapter->Fill(this->AuthorsDS->Authors); + } + + System::Void bnCommit_Click(System::Object^ sender, System::EventArgs^ e) + { + this->AuthorsTableAdapter->Update(this->AuthorsDS->Authors); + this->AuthorsDS->AcceptChanges(); + } + + System::Void bnRollback_Click(System::Object^ sender, System::EventArgs^ e) + { + this->AuthorsDS->RejectChanges(); + } + }; +} + diff --git a/Chapter12/MaintAuthorsDGV/Form1.resx b/Chapter12/MaintAuthorsDGV/Form1.resx new file mode 100644 index 0000000..bade238 --- /dev/null +++ b/Chapter12/MaintAuthorsDGV/Form1.resx @@ -0,0 +1,129 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 121, 17 + + + 17, 17 + + + 295, 17 + + \ No newline at end of file diff --git a/Chapter12/MaintAuthorsDGV/MaintAuthorsDGV.cpp b/Chapter12/MaintAuthorsDGV/MaintAuthorsDGV.cpp new file mode 100644 index 0000000..ee3596e --- /dev/null +++ b/Chapter12/MaintAuthorsDGV/MaintAuthorsDGV.cpp @@ -0,0 +1,16 @@ +// MaintAuthorsDGV.cpp : main project file. + +#include "stdafx.h" +#include "Form1.h" + +using namespace MaintAuthorsDGV; + +[STAThreadAttribute] +int main(array ^args) +{ + // Enabling Windows XP visual effects before any controls are created + Application::EnableVisualStyles(); + // Create the main window and run it + Application::Run(gcnew Form1()); + return 0; +} diff --git a/Chapter12/MaintAuthorsDGV/MaintAuthorsDGV.vcproj b/Chapter12/MaintAuthorsDGV/MaintAuthorsDGV.vcproj new file mode 100644 index 0000000..2354f8c --- /dev/null +++ b/Chapter12/MaintAuthorsDGV/MaintAuthorsDGV.vcproj @@ -0,0 +1,266 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Chapter12/MaintAuthorsDGV/stdafx.cpp b/Chapter12/MaintAuthorsDGV/stdafx.cpp new file mode 100644 index 0000000..aaec3b5 --- /dev/null +++ b/Chapter12/MaintAuthorsDGV/stdafx.cpp @@ -0,0 +1,7 @@ +// stdafx.cpp : source file that includes just the standard includes +// MaintAuthorsDGV.pch will be the pre-compiled header +// stdafx.obj will contain the pre-compiled type information + +#include "stdafx.h" + + diff --git a/Chapter12/MaintAuthorsDGV/stdafx.h b/Chapter12/MaintAuthorsDGV/stdafx.h new file mode 100644 index 0000000..3d5f019 --- /dev/null +++ b/Chapter12/MaintAuthorsDGV/stdafx.h @@ -0,0 +1,8 @@ +// stdafx.h : include file for standard system include files, +// or project specific include files that are used frequently, but +// are changed infrequently +#pragma once + +// TODO: reference additional headers your program requires here + +#include "AuthorsDS.h" diff --git a/Chapter12/Transactions/AssemblyInfo.cpp b/Chapter12/Transactions/AssemblyInfo.cpp new file mode 100644 index 0000000..ecf7042 --- /dev/null +++ b/Chapter12/Transactions/AssemblyInfo.cpp @@ -0,0 +1,61 @@ +#using + +using namespace System::Reflection; +using namespace System::Runtime::CompilerServices; +using namespace System::Runtime::InteropServices; + +// +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +// +[assembly:AssemblyTitleAttribute("")]; +[assembly:AssemblyDescriptionAttribute("")]; +[assembly:AssemblyConfigurationAttribute("")]; +[assembly:AssemblyCompanyAttribute("")]; +[assembly:AssemblyProductAttribute("")]; +[assembly:AssemblyCopyrightAttribute("")]; +[assembly:AssemblyTrademarkAttribute("")]; +[assembly:AssemblyCultureAttribute("")]; + +// +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the value or you can default the Revision and Build Numbers +// by using the '*' as shown below: + +[assembly:AssemblyVersionAttribute("1.0.*")]; + +// +// In order to sign your assembly you must specify a key to use. Refer to the +// Microsoft .NET Framework documentation for more information on assembly signing. +// +// Use the attributes below to control which key is used for signing. +// +// Notes: +// (*) If no key is specified, the assembly is not signed. +// (*) KeyName refers to a key that has been installed in the Crypto Service +// Provider (CSP) on your machine. KeyFile refers to a file which contains +// a key. +// (*) If the KeyFile and the KeyName values are both specified, the +// following processing occurs: +// (1) If the KeyName can be found in the CSP, that key is used. +// (2) If the KeyName does not exist and the KeyFile does exist, the key +// in the KeyFile is installed into the CSP and used. +// (*) In order to create a KeyFile, you can use the sn.exe (Strong Name) utility. +// When specifying the KeyFile, the location of the KeyFile should be +// relative to the project directory. +// (*) Delay Signing is an advanced option - see the Microsoft .NET Framework +// documentation for more information on this. +// +[assembly:AssemblyDelaySignAttribute(false)]; +[assembly:AssemblyKeyFileAttribute("")]; +[assembly:AssemblyKeyNameAttribute("")]; + +[assembly:ComVisible(false)]; + diff --git a/Chapter12/Transactions/Transactions.cpp b/Chapter12/Transactions/Transactions.cpp new file mode 100644 index 0000000..91ba6bf --- /dev/null +++ b/Chapter12/Transactions/Transactions.cpp @@ -0,0 +1,86 @@ +#using +#using + +using namespace System; +using namespace System::Data; +using namespace System::Data::SqlClient; + +void main() +{ + String ^Name = "Doors"; + + SqlConnection ^connection = gcnew SqlConnection(); + SqlTransaction ^transaction; + +#ifdef SQLAuth + // SQL Server authentication + connection->ConnectionString = + "User ID=sa; Password=;" + "Data Source=(local); Initial Catalog=DCV_DB;"; +#else + // Windows Integrated Security + connection->ConnectionString = + "Persist Security Info=False; Integrated Security=SSPI;" + "Data Source=(local); Initial Catalog=DCV_DB;"; +#endif + + try + { + connection->Open(); + + SqlCommand ^cmd = gcnew SqlCommand(); + + transaction = connection->BeginTransaction( + IsolationLevel::Serializable, "AuthorTransaction"); + + cmd->Connection = connection; + cmd->Transaction = transaction; + + cmd->CommandType = CommandType::StoredProcedure; + cmd->CommandText = "InsertAuthor"; + + cmd->Parameters->Add(gcnew SqlParameter("@LastName", SqlDbType::Char,32)); + cmd->Parameters->Add(gcnew SqlParameter("@FirstName",SqlDbType::Char,32)); + + cmd->Parameters["@LastName"]->Value = "Dope"; + cmd->Parameters["@FirstName"]->Value = "John"; + + int affected = cmd->ExecuteNonQuery(); + if (affected <= 0) + throw gcnew Exception("Insert Failed"); + Console::WriteLine("Insert - {0} rows are affected", affected); + + cmd->CommandType = CommandType::Text; + cmd->CommandText = "UPDATE Authors SET LastName = 'Doe'" + "WHERE LastName = 'Dope'"; + + affected = cmd->ExecuteNonQuery(); + if (affected <= 0) + throw gcnew Exception("Insert Failed"); + Console::WriteLine("Update - {0} rows are affected", affected); + + // This transaction will return 0 affected rows + // because "Does" does not exist. + // Thus, the if condition throws an execption which causes all + // Transactions to be rolled back. + cmd->CommandType = CommandType::Text; + cmd->CommandText = "DELETE FROM Authors WHERE LastName = 'Does'"; + + affected = cmd->ExecuteNonQuery(); + if (affected <= 0) + throw gcnew Exception("Insert Failed"); + Console::WriteLine("Delete - {0} rows are affected", affected); + + transaction->Commit(); + } + catch (Exception ^e) + { + transaction->Rollback("AuthorTransaction"); + Console::WriteLine("Transaction Not completed"); + Console::WriteLine("SQL error occurred: {0}", e->Message); + } + finally + { + connection->Close(); + } +} \ No newline at end of file diff --git a/Chapter12/Transactions/Transactions.vcproj b/Chapter12/Transactions/Transactions.vcproj new file mode 100644 index 0000000..5384e8f --- /dev/null +++ b/Chapter12/Transactions/Transactions.vcproj @@ -0,0 +1,203 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Chapter13/ADONET/ADONET.cpp b/Chapter13/ADONET/ADONET.cpp new file mode 100644 index 0000000..0f5a1c3 --- /dev/null +++ b/Chapter13/ADONET/ADONET.cpp @@ -0,0 +1,72 @@ +#using +#using + +using namespace System; +using namespace System::Data; +using namespace System::Data::SqlClient; +using namespace System::Xml; + +String ^indent(int depth) +{ + String ^ind = ""; + return ind->PadLeft(depth*4, ' '); +} + +void Navigate(XmlNode ^node, int depth) +{ + if (node == nullptr) + return; + + Console::WriteLine("{0}: Name='{1}' Value='{2}'", + String::Concat(indent(depth),node->NodeType.ToString()), + node->Name, node->Value); + + if (node->Attributes != nullptr) + { + for (int i = 0; i < node->Attributes->Count; i++) + { + Console::WriteLine("{0}Attribute: Name='{1}' Value='{2}'", + indent(depth+1),node->Attributes[i]->Name, + node->Attributes[i]->Value); + } + } + + Navigate(node->FirstChild, depth+1); + Navigate(node->NextSibling, depth); +} + + +void main() +{ + XmlDocument ^doc = gcnew XmlDocument(); + + try + { + SqlConnection ^connect = gcnew SqlConnection(); + +#ifdef SQLAuth + // SQL Server authentication + connect->ConnectionString = + "User ID=sa; Password=;" + "Data Source=(local); Initial Catalog=DCV_DB;"; +#else + // Windows Integrated Security + connect->ConnectionString = + "Persist Security Info=False; Integrated Security=SSPI;" + "Data Source=(local); Initial Catalog=DCV_DB;"; +#endif + SqlDataAdapter ^dAdapt = gcnew SqlDataAdapter(); + DataSet ^dSet = gcnew DataSet(); + dAdapt->SelectCommand = gcnew SqlCommand("SELECT * FROM Authors", connect); + + dAdapt->Fill(dSet, "Authors"); + XmlDataDocument ^doc = gcnew XmlDataDocument(dSet); + + // Recursive navigation of the DOM tree + Navigate(doc->DocumentElement, 0); + } + catch (Exception ^e) + { + Console::WriteLine("Error Occurred: {0}", e->Message); + } +} \ No newline at end of file diff --git a/Chapter13/ADONET/ADONET.vcproj b/Chapter13/ADONET/ADONET.vcproj new file mode 100644 index 0000000..486023d --- /dev/null +++ b/Chapter13/ADONET/ADONET.vcproj @@ -0,0 +1,199 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Chapter13/Chapter13.sln b/Chapter13/Chapter13.sln new file mode 100644 index 0000000..a47a170 --- /dev/null +++ b/Chapter13/Chapter13.sln @@ -0,0 +1,74 @@ + +Microsoft Visual Studio Solution File, Format Version 9.00 +# Visual Studio 2005 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ReadXML", "ReadXML\ReadXML.vcproj", "{D00271E6-BDAF-4E82-879A-5BC30AA0CA45}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "WriteXML", "WriteXML\WriteXML.vcproj", "{314A147C-FF24-4F95-B3F7-D2F953620D1D}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ValidateXML", "ValidateXML\ValidateXML.vcproj", "{882E402F-CC5E-40B1-A10C-86AA940CF753}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "UpdateXML", "UpdateXML\UpdateXML.vcproj", "{EF8C3541-9E23-4E87-B18C-BF6DE184BEFC}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ReadXMLDOM", "ReadXMLDOM\ReadXMLDOM.vcproj", "{BBBC1AAF-2CC1-4A2D-9AFB-DFAD1C7880BE}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "UpdateXMLDOM", "UpdateXMLDOM\UpdateXMLDOM.vcproj", "{29A75193-75C6-4DCA-A4AD-7DDC5E8F8A67}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "WriteXMLDOM", "WriteXMLDOM\WriteXMLDOM.vcproj", "{BDFE0437-F82D-4122-8300-EDA6AE18B1CE}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ReadXPathNav", "ReadXPathNav\ReadXPathNav.vcproj", "{6A038BFE-BBEB-4A71-B1CB-219CA2A6820F}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "XPathEx", "XPathEx\XPathEx.vcproj", "{1B8BF33C-B38F-4D07-8316-D94A4BA63904}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ADONET", "ADONET\ADONET.vcproj", "{51028C21-628E-4C21-B7A1-AEC200038428}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Win32 = Debug|Win32 + Release|Win32 = Release|Win32 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {D00271E6-BDAF-4E82-879A-5BC30AA0CA45}.Debug|Win32.ActiveCfg = Debug|Win32 + {D00271E6-BDAF-4E82-879A-5BC30AA0CA45}.Debug|Win32.Build.0 = Debug|Win32 + {D00271E6-BDAF-4E82-879A-5BC30AA0CA45}.Release|Win32.ActiveCfg = Release|Win32 + {D00271E6-BDAF-4E82-879A-5BC30AA0CA45}.Release|Win32.Build.0 = Release|Win32 + {314A147C-FF24-4F95-B3F7-D2F953620D1D}.Debug|Win32.ActiveCfg = Debug|Win32 + {314A147C-FF24-4F95-B3F7-D2F953620D1D}.Debug|Win32.Build.0 = Debug|Win32 + {314A147C-FF24-4F95-B3F7-D2F953620D1D}.Release|Win32.ActiveCfg = Release|Win32 + {314A147C-FF24-4F95-B3F7-D2F953620D1D}.Release|Win32.Build.0 = Release|Win32 + {882E402F-CC5E-40B1-A10C-86AA940CF753}.Debug|Win32.ActiveCfg = Debug|Win32 + {882E402F-CC5E-40B1-A10C-86AA940CF753}.Debug|Win32.Build.0 = Debug|Win32 + {882E402F-CC5E-40B1-A10C-86AA940CF753}.Release|Win32.ActiveCfg = Release|Win32 + {882E402F-CC5E-40B1-A10C-86AA940CF753}.Release|Win32.Build.0 = Release|Win32 + {EF8C3541-9E23-4E87-B18C-BF6DE184BEFC}.Debug|Win32.ActiveCfg = Debug|Win32 + {EF8C3541-9E23-4E87-B18C-BF6DE184BEFC}.Debug|Win32.Build.0 = Debug|Win32 + {EF8C3541-9E23-4E87-B18C-BF6DE184BEFC}.Release|Win32.ActiveCfg = Release|Win32 + {EF8C3541-9E23-4E87-B18C-BF6DE184BEFC}.Release|Win32.Build.0 = Release|Win32 + {BBBC1AAF-2CC1-4A2D-9AFB-DFAD1C7880BE}.Debug|Win32.ActiveCfg = Debug|Win32 + {BBBC1AAF-2CC1-4A2D-9AFB-DFAD1C7880BE}.Debug|Win32.Build.0 = Debug|Win32 + {BBBC1AAF-2CC1-4A2D-9AFB-DFAD1C7880BE}.Release|Win32.ActiveCfg = Release|Win32 + {BBBC1AAF-2CC1-4A2D-9AFB-DFAD1C7880BE}.Release|Win32.Build.0 = Release|Win32 + {29A75193-75C6-4DCA-A4AD-7DDC5E8F8A67}.Debug|Win32.ActiveCfg = Debug|Win32 + {29A75193-75C6-4DCA-A4AD-7DDC5E8F8A67}.Debug|Win32.Build.0 = Debug|Win32 + {29A75193-75C6-4DCA-A4AD-7DDC5E8F8A67}.Release|Win32.ActiveCfg = Release|Win32 + {29A75193-75C6-4DCA-A4AD-7DDC5E8F8A67}.Release|Win32.Build.0 = Release|Win32 + {BDFE0437-F82D-4122-8300-EDA6AE18B1CE}.Debug|Win32.ActiveCfg = Debug|Win32 + {BDFE0437-F82D-4122-8300-EDA6AE18B1CE}.Debug|Win32.Build.0 = Debug|Win32 + {BDFE0437-F82D-4122-8300-EDA6AE18B1CE}.Release|Win32.ActiveCfg = Release|Win32 + {BDFE0437-F82D-4122-8300-EDA6AE18B1CE}.Release|Win32.Build.0 = Release|Win32 + {6A038BFE-BBEB-4A71-B1CB-219CA2A6820F}.Debug|Win32.ActiveCfg = Debug|Win32 + {6A038BFE-BBEB-4A71-B1CB-219CA2A6820F}.Debug|Win32.Build.0 = Debug|Win32 + {6A038BFE-BBEB-4A71-B1CB-219CA2A6820F}.Release|Win32.ActiveCfg = Release|Win32 + {6A038BFE-BBEB-4A71-B1CB-219CA2A6820F}.Release|Win32.Build.0 = Release|Win32 + {1B8BF33C-B38F-4D07-8316-D94A4BA63904}.Debug|Win32.ActiveCfg = Debug|Win32 + {1B8BF33C-B38F-4D07-8316-D94A4BA63904}.Debug|Win32.Build.0 = Debug|Win32 + {1B8BF33C-B38F-4D07-8316-D94A4BA63904}.Release|Win32.ActiveCfg = Release|Win32 + {1B8BF33C-B38F-4D07-8316-D94A4BA63904}.Release|Win32.Build.0 = Release|Win32 + {51028C21-628E-4C21-B7A1-AEC200038428}.Debug|Win32.ActiveCfg = Debug|Win32 + {51028C21-628E-4C21-B7A1-AEC200038428}.Debug|Win32.Build.0 = Debug|Win32 + {51028C21-628E-4C21-B7A1-AEC200038428}.Release|Win32.ActiveCfg = Release|Win32 + {51028C21-628E-4C21-B7A1-AEC200038428}.Release|Win32.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/Chapter13/Chapter13.suo b/Chapter13/Chapter13.suo new file mode 100644 index 0000000..aeddcb3 Binary files /dev/null and b/Chapter13/Chapter13.suo differ diff --git a/Chapter13/ReadXML/Monsters.xml b/Chapter13/ReadXML/Monsters.xml new file mode 100644 index 0000000..f7568a5 --- /dev/null +++ b/Chapter13/ReadXML/Monsters.xml @@ -0,0 +1,25 @@ + + + + + + Goblin + + Dagger + + + + Succubus + + Claw + Dagger + + + + Red Dragon + + Bite + Claw + Wing + + \ No newline at end of file diff --git a/Chapter13/ReadXML/ReadXML.cpp b/Chapter13/ReadXML/ReadXML.cpp new file mode 100644 index 0000000..c521114 --- /dev/null +++ b/Chapter13/ReadXML/ReadXML.cpp @@ -0,0 +1,106 @@ +#using + +using namespace System; +using namespace System::Xml; + + +String ^indent(Int32 depth) +{ + String ^ind = ""; + return ind->PadLeft(depth*3, ' '); +} + +void main() +{ + XmlReader ^reader; + + try + { + reader = XmlReader::Create("Monsters.xml"); + + while (reader->Read()) + { + switch (reader->NodeType) + { + case XmlNodeType::Comment: + Console::WriteLine( + "{0}Comment node: Value='{1}'", + indent(reader->Depth), reader->Value); + break; + case XmlNodeType::Element: + Console::WriteLine( + "{0}Element node: Name='{1}'", + indent(reader->Depth), reader->Name); + + if (reader->HasAttributes) + { + while (reader->MoveToNextAttribute()) + { + Console::WriteLine( + "{0}Attribute node: Name='{1}' Value='{2}'", + indent(reader->Depth), reader->Name, + reader->Value); + } + reader->MoveToElement(); + } + + if (reader->IsEmptyElement) + { + Console::WriteLine( + "{0}End Element node: Name='{1}'", + indent(reader->Depth), reader->Name); + } + break; + case XmlNodeType::EndElement: + Console::WriteLine( + "{0}End Element node: Name='{1}'", + indent(reader->Depth), reader->Name); + break; + case XmlNodeType::Text: + Console::WriteLine( + "{0}Text node: Value='{1}'", + indent(reader->Depth), reader->Value); + break; + case XmlNodeType::XmlDeclaration: + Console::WriteLine( + "Xml Declaration node: Name='{1}'", + indent(reader->Depth), reader->Name); + + if (reader->HasAttributes) + { + while (reader->MoveToNextAttribute()) + { + Console::WriteLine( + "{0}Attribute node: Name='{1}' Value='{2}'", + indent(reader->Depth), reader->Name, + reader->Value); + } + } + reader->MoveToElement(); + Console::WriteLine( + "End Xml Declaration node: Name='{1}'", + indent(reader->Depth), reader->Name); + break; + case XmlNodeType::Whitespace: + // Ignore white space + break; + default: + Console::WriteLine( + "***UKNOWN*** node: Name='{1}' Value='{2}'", + indent(reader->Depth), reader->Name, reader->Value); + } + } + } + catch (XmlException ^e) + { + Console::WriteLine("\nReadXML Aborted with error: {0}", + e->Message); + } + finally + { + if (reader->ReadState != ReadState::Closed) + { + reader->Close(); + } + } +} \ No newline at end of file diff --git a/Chapter13/ReadXML/ReadXML.vcproj b/Chapter13/ReadXML/ReadXML.vcproj new file mode 100644 index 0000000..ced7c00 --- /dev/null +++ b/Chapter13/ReadXML/ReadXML.vcproj @@ -0,0 +1,203 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Chapter13/ReadXMLDOM/Monsters.xml b/Chapter13/ReadXMLDOM/Monsters.xml new file mode 100644 index 0000000..f7568a5 --- /dev/null +++ b/Chapter13/ReadXMLDOM/Monsters.xml @@ -0,0 +1,25 @@ + + + + + + Goblin + + Dagger + + + + Succubus + + Claw + Dagger + + + + Red Dragon + + Bite + Claw + Wing + + \ No newline at end of file diff --git a/Chapter13/ReadXMLDOM/ReadXMLDOM.cpp b/Chapter13/ReadXMLDOM/ReadXMLDOM.cpp new file mode 100644 index 0000000..eb0d945 --- /dev/null +++ b/Chapter13/ReadXMLDOM/ReadXMLDOM.cpp @@ -0,0 +1,53 @@ +using namespace System; +using namespace System::Xml; + +String ^indent(int depth) +{ + String ^ind = ""; + return ind->PadLeft(depth*4, ' '); +} + +void Navigate(XmlNode ^node, int depth) +{ + if (node == nullptr) + return; + + Console::WriteLine("{0}: Name='{1}' Value='{2}'", + String::Concat(indent(depth),node->NodeType.ToString()), + node->Name, node->Value); + + if (node->Attributes != nullptr) + { + for (int i = 0; i < node->Attributes->Count; i++) + { + Console::WriteLine("{0}Attribute: Name='{1}' Value='{2}'", + indent(depth+1),node->Attributes[i]->Name, + node->Attributes[i]->Value); + } + } + + Navigate(node->FirstChild, depth+1); + Navigate(node->NextSibling, depth); +} + + +void main() +{ + XmlDocument ^doc = gcnew XmlDocument(); + + try + { + XmlReader ^reader = XmlReader::Create("Monsters.xml"); + doc->Load(reader); + reader->Close(); + + XmlNode ^node = doc->FirstChild; // I want the Xml Declaration + + // Recursive navigation of the DOM tree + Navigate(node, 0); + } + catch (Exception ^e) + { + Console::WriteLine("Error Occurred: {0}", e->Message); + } +} \ No newline at end of file diff --git a/Chapter13/ReadXMLDOM/ReadXMLDOM.vcproj b/Chapter13/ReadXMLDOM/ReadXMLDOM.vcproj new file mode 100644 index 0000000..6bf4291 --- /dev/null +++ b/Chapter13/ReadXMLDOM/ReadXMLDOM.vcproj @@ -0,0 +1,203 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Chapter13/ReadXPathNav/Monsters.xml b/Chapter13/ReadXPathNav/Monsters.xml new file mode 100644 index 0000000..f7568a5 --- /dev/null +++ b/Chapter13/ReadXPathNav/Monsters.xml @@ -0,0 +1,25 @@ + + + + + + Goblin + + Dagger + + + + Succubus + + Claw + Dagger + + + + Red Dragon + + Bite + Claw + Wing + + \ No newline at end of file diff --git a/Chapter13/ReadXPathNav/ReadXPathNav.cpp b/Chapter13/ReadXPathNav/ReadXPathNav.cpp new file mode 100644 index 0000000..59e8c45 --- /dev/null +++ b/Chapter13/ReadXPathNav/ReadXPathNav.cpp @@ -0,0 +1,51 @@ +using namespace System; +using namespace System::Xml; +using namespace System::Xml::XPath; + +String ^indent(int depth) +{ + String ^ind = ""; + return ind->PadLeft(depth*4, ' '); +} + +void Navigate(XPathNavigator ^nav, int depth) +{ + Console::WriteLine("{0}: Name='{1}' Value='{2}'", + String::Concat(indent(depth), nav->NodeType.ToString()), + nav->Name, nav->Value); + + if (nav->HasAttributes) + { + nav->MoveToFirstAttribute(); + do { + Console::WriteLine("{0} Attribute: Name='{1}' Value='{2}'", + indent(depth+1),nav->Name, nav->Value); + } + while(nav->MoveToNextAttribute()); + nav->MoveToParent(); + } + + if (nav->MoveToFirstChild()) + { + Navigate(nav, depth+1); + nav->MoveToParent(); + } + if (nav->MoveToNext()) + Navigate(nav, depth); +} + +void main() +{ + XmlDocument ^doc = gcnew XmlDocument(); + try + { + doc->Load("Monsters.xml"); + XPathNavigator ^nav = doc->CreateNavigator(); + nav->MoveToRoot(); + Navigate(nav, 0); + } + catch (Exception ^e) + { + Console::WriteLine("Error Occurred: {0}", e->Message); + } +} \ No newline at end of file diff --git a/Chapter13/ReadXPathNav/ReadXPathNav.vcproj b/Chapter13/ReadXPathNav/ReadXPathNav.vcproj new file mode 100644 index 0000000..9bc2b61 --- /dev/null +++ b/Chapter13/ReadXPathNav/ReadXPathNav.vcproj @@ -0,0 +1,203 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Chapter13/UpdateXML/Monsters.xml b/Chapter13/UpdateXML/Monsters.xml new file mode 100644 index 0000000..f7568a5 --- /dev/null +++ b/Chapter13/UpdateXML/Monsters.xml @@ -0,0 +1,25 @@ + + + + + + Goblin + + Dagger + + + + Succubus + + Claw + Dagger + + + + Red Dragon + + Bite + Claw + Wing + + \ No newline at end of file diff --git a/Chapter13/UpdateXML/New_Monsters.xml b/Chapter13/UpdateXML/New_Monsters.xml new file mode 100644 index 0000000..e7081ef --- /dev/null +++ b/Chapter13/UpdateXML/New_Monsters.xml @@ -0,0 +1,28 @@ + + + + + + Goblin + False + + Dagger + + + + Succubus + False + + Claw + Dagger + + + + Red Dragon + False + + Bite + Claw + Wing + + \ No newline at end of file diff --git a/Chapter13/UpdateXML/UpdateXML.cpp b/Chapter13/UpdateXML/UpdateXML.cpp new file mode 100644 index 0000000..76ab82c --- /dev/null +++ b/Chapter13/UpdateXML/UpdateXML.cpp @@ -0,0 +1,69 @@ +using namespace System; +using namespace System::Xml; + +void main() +{ + XmlReader ^reader; + XmlWriter ^writer; + try + { + reader = XmlReader::Create("Monsters.xml"); + + XmlWriterSettings ^settings = gcnew XmlWriterSettings(); + settings->Indent = true; + settings->IndentChars = (" "); + + writer = XmlWriter::Create("New_Monsters.xml", settings); + + while (reader->Read()) + { + switch (reader->NodeType) + { + case XmlNodeType::Comment: + writer->WriteComment(reader->Value); + break; + case XmlNodeType::Element: + writer->WriteStartElement(reader->Name); + writer->WriteAttributes(reader, false); + if (reader->IsEmptyElement) + writer->WriteEndElement(); + break; + case XmlNodeType::EndElement: + writer->WriteEndElement(); + + // *** Add new Monster Element + if (reader->Name->Equals("Name")) + { + writer->WriteStartElement("Encountered"); + writer->WriteString("False"); + writer->WriteEndElement(); + } + break; + case XmlNodeType::Text: + writer->WriteString(reader->Value); + break; + case XmlNodeType::XmlDeclaration: + writer->WriteStartDocument(); + break; + } + } + writer->Flush(); + + Console::WriteLine("Done"); + } + catch (Exception ^e) + { + Console::WriteLine("XML Update Aborted -- {0}", e->Message); + } + finally + { + if (writer->WriteState != WriteState::Closed) + { + writer->Close(); + } + if (reader->ReadState != ReadState::Closed) + { + reader->Close(); + } + } +} diff --git a/Chapter13/UpdateXML/UpdateXML.vcproj b/Chapter13/UpdateXML/UpdateXML.vcproj new file mode 100644 index 0000000..7b93263 --- /dev/null +++ b/Chapter13/UpdateXML/UpdateXML.vcproj @@ -0,0 +1,207 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Chapter13/UpdateXMLDOM/Monsters.xml b/Chapter13/UpdateXMLDOM/Monsters.xml new file mode 100644 index 0000000..f7568a5 --- /dev/null +++ b/Chapter13/UpdateXMLDOM/Monsters.xml @@ -0,0 +1,25 @@ + + + + + + Goblin + + Dagger + + + + Succubus + + Claw + Dagger + + + + Red Dragon + + Bite + Claw + Wing + + \ No newline at end of file diff --git a/Chapter13/UpdateXMLDOM/New_Monsters.xml b/Chapter13/UpdateXMLDOM/New_Monsters.xml new file mode 100644 index 0000000..9f7ed70 --- /dev/null +++ b/Chapter13/UpdateXMLDOM/New_Monsters.xml @@ -0,0 +1,25 @@ + + + + + + Goblin + + Saber + + + + Succubus + + Claw + Dagger + + + + Red Dragon + + Bite + Claw + Wing + + \ No newline at end of file diff --git a/Chapter13/UpdateXMLDOM/UpdateXMLDOM.cpp b/Chapter13/UpdateXMLDOM/UpdateXMLDOM.cpp new file mode 100644 index 0000000..c217df7 --- /dev/null +++ b/Chapter13/UpdateXMLDOM/UpdateXMLDOM.cpp @@ -0,0 +1,42 @@ +using namespace System; +using namespace System::Xml; + +void Navigate(XmlNode ^node) +{ + if (node == nullptr) + return; + + if (node->Value != nullptr && node->Value->Equals("Dagger")) + { + if (node->ParentNode->ParentNode["Name"]->FirstChild->Value-> + Equals("Goblin")) + { + node->Value = "Saber"; + node->ParentNode->Attributes["Damage"]->Value = "1d8"; + } + } + + Navigate(node->FirstChild); + Navigate(node->NextSibling); +} + + +void main() +{ + XmlDocument ^doc = gcnew XmlDocument(); + + try + { + doc->Load("Monsters.xml"); + XmlNode ^root = doc->DocumentElement; + + // Recursive navigation of the DOM tree + Navigate(root); + + doc->Save("New_Monsters.xml"); + } + catch (Exception ^e) + { + Console::WriteLine("Error Occurred: {0}", e->Message ); + } +} \ No newline at end of file diff --git a/Chapter13/UpdateXMLDOM/UpdateXMLDOM.vcproj b/Chapter13/UpdateXMLDOM/UpdateXMLDOM.vcproj new file mode 100644 index 0000000..7379d35 --- /dev/null +++ b/Chapter13/UpdateXMLDOM/UpdateXMLDOM.vcproj @@ -0,0 +1,207 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Chapter13/ValidateXML/Monsters.dtd b/Chapter13/ValidateXML/Monsters.dtd new file mode 100644 index 0000000..6cb7f27 --- /dev/null +++ b/Chapter13/ValidateXML/Monsters.dtd @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/Chapter13/ValidateXML/Monsters.h b/Chapter13/ValidateXML/Monsters.h new file mode 100644 index 0000000..2a4c7fc --- /dev/null +++ b/Chapter13/ValidateXML/Monsters.h @@ -0,0 +1,1533 @@ +#pragma once + +#using +#using +#using +#using + +using namespace System::Security::Permissions; +[assembly:SecurityPermissionAttribute(SecurityAction::RequestMinimum, SkipVerification=false)]; +// +// This source code was auto-generated by xsd, Version=2.0.50630.0. +// +namespace ValidateXML { + using namespace System; + + using namespace System; + ref class MonsterList; + + + [System::CodeDom::Compiler::GeneratedCodeAttribute(L"System.Data.Design.TypedDataSetGenerator", L"2.0.0.0"), + Serializable, + System::ComponentModel::DesignerCategoryAttribute(L"code"), + System::ComponentModel::ToolboxItem(true), + System::Xml::Serialization::XmlSchemaProviderAttribute(L"GetTypedDataSetSchema"), + System::Xml::Serialization::XmlRootAttribute(L"MonsterList"), + System::ComponentModel::Design::HelpKeywordAttribute(L"vs.data.DataSet"), + System::CLSCompliantAttribute(false)] + public ref class MonsterList : public System::Data::DataSet { + public : ref class MonsterDataTable; + public : ref class HitDiceDataTable; + public : ref class WeaponDataTable; + public : ref class MonsterRow; + public : ref class HitDiceRow; + public : ref class WeaponRow; + public : ref class MonsterRowChangeEvent; + public : ref class HitDiceRowChangeEvent; + public : ref class WeaponRowChangeEvent; + + private: ValidateXML::MonsterList::MonsterDataTable^ tableMonster; + + private: ValidateXML::MonsterList::HitDiceDataTable^ tableHitDice; + + private: ValidateXML::MonsterList::WeaponDataTable^ tableWeapon; + + private: System::Data::DataRelation^ relationMonster_HitDice; + + private: System::Data::DataRelation^ relationMonster_Weapon; + + private: System::Data::SchemaSerializationMode _schemaSerializationMode; + + public : delegate System::Void MonsterRowChangeEventHandler(System::Object^ sender, ValidateXML::MonsterList::MonsterRowChangeEvent^ e); + + public : delegate System::Void HitDiceRowChangeEventHandler(System::Object^ sender, ValidateXML::MonsterList::HitDiceRowChangeEvent^ e); + + public : delegate System::Void WeaponRowChangeEventHandler(System::Object^ sender, ValidateXML::MonsterList::WeaponRowChangeEvent^ e); + + public: [System::Diagnostics::DebuggerNonUserCodeAttribute] + MonsterList(); + protected: [System::Diagnostics::DebuggerNonUserCodeAttribute] + MonsterList(System::Runtime::Serialization::SerializationInfo^ info, System::Runtime::Serialization::StreamingContext context); + public: [System::Diagnostics::DebuggerNonUserCodeAttribute, + System::ComponentModel::Browsable(false), + System::ComponentModel::DesignerSerializationVisibility(System::ComponentModel::DesignerSerializationVisibility::Content)] + property ValidateXML::MonsterList::MonsterDataTable^ Monster { + ValidateXML::MonsterList::MonsterDataTable^ get(); + } + + public: [System::Diagnostics::DebuggerNonUserCodeAttribute, + System::ComponentModel::Browsable(false), + System::ComponentModel::DesignerSerializationVisibility(System::ComponentModel::DesignerSerializationVisibility::Content)] + property ValidateXML::MonsterList::HitDiceDataTable^ HitDice { + ValidateXML::MonsterList::HitDiceDataTable^ get(); + } + + public: [System::Diagnostics::DebuggerNonUserCodeAttribute, + System::ComponentModel::Browsable(false), + System::ComponentModel::DesignerSerializationVisibility(System::ComponentModel::DesignerSerializationVisibility::Content)] + property ValidateXML::MonsterList::WeaponDataTable^ Weapon { + ValidateXML::MonsterList::WeaponDataTable^ get(); + } + + public: [System::Diagnostics::DebuggerNonUserCodeAttribute] + virtual property System::Data::SchemaSerializationMode SchemaSerializationMode { + System::Data::SchemaSerializationMode get() override; + System::Void set(System::Data::SchemaSerializationMode value) override; + } + + public: [System::Diagnostics::DebuggerNonUserCodeAttribute, + System::ComponentModel::DesignerSerializationVisibilityAttribute(System::ComponentModel::DesignerSerializationVisibility::Hidden)] + property System::Data::DataTableCollection^ Tables { + System::Data::DataTableCollection^ get() new; + } + + public: [System::Diagnostics::DebuggerNonUserCodeAttribute, + System::ComponentModel::DesignerSerializationVisibilityAttribute(System::ComponentModel::DesignerSerializationVisibility::Hidden)] + property System::Data::DataRelationCollection^ Relations { + System::Data::DataRelationCollection^ get() new; + } + + public: [System::Diagnostics::DebuggerNonUserCodeAttribute, + System::ComponentModel::DefaultValueAttribute(true)] + property System::Boolean EnforceConstraints { + System::Boolean get() new; + System::Void set(System::Boolean value) new; + } + + protected: [System::Diagnostics::DebuggerNonUserCodeAttribute] + virtual System::Void InitializeDerivedDataSet() override; + + public: [System::Diagnostics::DebuggerNonUserCodeAttribute] + virtual System::Data::DataSet^ Clone() override; + + protected: [System::Diagnostics::DebuggerNonUserCodeAttribute] + virtual System::Boolean ShouldSerializeTables() override; + + protected: [System::Diagnostics::DebuggerNonUserCodeAttribute] + virtual System::Boolean ShouldSerializeRelations() override; + + protected: [System::Diagnostics::DebuggerNonUserCodeAttribute] + virtual System::Void ReadXmlSerializable(System::Xml::XmlReader^ reader) override; + + protected: [System::Diagnostics::DebuggerNonUserCodeAttribute] + virtual System::Xml::Schema::XmlSchema^ GetSchemaSerializable() override; + + internal: [System::Diagnostics::DebuggerNonUserCodeAttribute] + System::Void InitVars(); + + internal: [System::Diagnostics::DebuggerNonUserCodeAttribute] + System::Void InitVars(System::Boolean initTable); + + private: [System::Diagnostics::DebuggerNonUserCodeAttribute] + System::Void InitClass(); + + private: [System::Diagnostics::DebuggerNonUserCodeAttribute] + System::Boolean ShouldSerializeMonster(); + + private: [System::Diagnostics::DebuggerNonUserCodeAttribute] + System::Boolean ShouldSerializeHitDice(); + + private: [System::Diagnostics::DebuggerNonUserCodeAttribute] + System::Boolean ShouldSerializeWeapon(); + + private: [System::Diagnostics::DebuggerNonUserCodeAttribute] + System::Void SchemaChanged(System::Object^ sender, System::ComponentModel::CollectionChangeEventArgs^ e); + + public: [System::Diagnostics::DebuggerNonUserCodeAttribute] + static System::Xml::Schema::XmlSchemaComplexType^ GetTypedDataSetSchema(System::Xml::Schema::XmlSchemaSet^ xs); + + public : [System::CodeDom::Compiler::GeneratedCodeAttribute(L"System.Data.Design.TypedDataSetGenerator", L"2.0.0.0"), + System::Serializable, + System::Xml::Serialization::XmlSchemaProviderAttribute(L"GetTypedTableSchema")] + ref class MonsterDataTable : public System::Data::DataTable, public System::Collections::IEnumerable { + + private: System::Data::DataColumn^ columnName; + + private: System::Data::DataColumn^ columnMonster_Id; + + public: event ValidateXML::MonsterList::MonsterRowChangeEventHandler^ MonsterRowChanging; + + public: event ValidateXML::MonsterList::MonsterRowChangeEventHandler^ MonsterRowChanged; + + public: event ValidateXML::MonsterList::MonsterRowChangeEventHandler^ MonsterRowDeleting; + + public: event ValidateXML::MonsterList::MonsterRowChangeEventHandler^ MonsterRowDeleted; + + public: [System::Diagnostics::DebuggerNonUserCodeAttribute] + MonsterDataTable(); + internal: [System::Diagnostics::DebuggerNonUserCodeAttribute] + MonsterDataTable(System::Data::DataTable^ table); + protected: [System::Diagnostics::DebuggerNonUserCodeAttribute] + MonsterDataTable(System::Runtime::Serialization::SerializationInfo^ info, System::Runtime::Serialization::StreamingContext context); + public: [System::Diagnostics::DebuggerNonUserCodeAttribute] + property System::Data::DataColumn^ NameColumn { + System::Data::DataColumn^ get(); + } + + public: [System::Diagnostics::DebuggerNonUserCodeAttribute] + property System::Data::DataColumn^ Monster_IdColumn { + System::Data::DataColumn^ get(); + } + + public: [System::Diagnostics::DebuggerNonUserCodeAttribute, + System::ComponentModel::Browsable(false)] + property System::Int32 Count { + System::Int32 get(); + } + + public: [System::Diagnostics::DebuggerNonUserCodeAttribute] + property ValidateXML::MonsterList::MonsterRow^ default [System::Int32 ] { + ValidateXML::MonsterList::MonsterRow^ get(System::Int32 index); + } + + public: [System::Diagnostics::DebuggerNonUserCodeAttribute] + System::Void AddMonsterRow(ValidateXML::MonsterList::MonsterRow^ row); + + public: [System::Diagnostics::DebuggerNonUserCodeAttribute] + ValidateXML::MonsterList::MonsterRow^ AddMonsterRow(System::String^ Name); + + public: [System::Diagnostics::DebuggerNonUserCodeAttribute] + virtual System::Collections::IEnumerator^ GetEnumerator(); + + public: [System::Diagnostics::DebuggerNonUserCodeAttribute] + virtual System::Data::DataTable^ Clone() override; + + protected: [System::Diagnostics::DebuggerNonUserCodeAttribute] + virtual System::Data::DataTable^ CreateInstance() override; + + internal: [System::Diagnostics::DebuggerNonUserCodeAttribute] + System::Void InitVars(); + + private: [System::Diagnostics::DebuggerNonUserCodeAttribute] + System::Void InitClass(); + + public: [System::Diagnostics::DebuggerNonUserCodeAttribute] + ValidateXML::MonsterList::MonsterRow^ NewMonsterRow(); + + protected: [System::Diagnostics::DebuggerNonUserCodeAttribute] + virtual System::Data::DataRow^ NewRowFromBuilder(System::Data::DataRowBuilder^ builder) override; + + protected: [System::Diagnostics::DebuggerNonUserCodeAttribute] + virtual System::Type^ GetRowType() override; + + protected: [System::Diagnostics::DebuggerNonUserCodeAttribute] + virtual System::Void OnRowChanged(System::Data::DataRowChangeEventArgs^ e) override; + + protected: [System::Diagnostics::DebuggerNonUserCodeAttribute] + virtual System::Void OnRowChanging(System::Data::DataRowChangeEventArgs^ e) override; + + protected: [System::Diagnostics::DebuggerNonUserCodeAttribute] + virtual System::Void OnRowDeleted(System::Data::DataRowChangeEventArgs^ e) override; + + protected: [System::Diagnostics::DebuggerNonUserCodeAttribute] + virtual System::Void OnRowDeleting(System::Data::DataRowChangeEventArgs^ e) override; + + public: [System::Diagnostics::DebuggerNonUserCodeAttribute] + System::Void RemoveMonsterRow(ValidateXML::MonsterList::MonsterRow^ row); + + public: [System::Diagnostics::DebuggerNonUserCodeAttribute] + static System::Xml::Schema::XmlSchemaComplexType^ GetTypedTableSchema(System::Xml::Schema::XmlSchemaSet^ xs); + }; + + public : [System::CodeDom::Compiler::GeneratedCodeAttribute(L"System.Data.Design.TypedDataSetGenerator", L"2.0.0.0"), + System::Serializable, + System::Xml::Serialization::XmlSchemaProviderAttribute(L"GetTypedTableSchema")] + ref class HitDiceDataTable : public System::Data::DataTable, public System::Collections::IEnumerable { + + private: System::Data::DataColumn^ columnDice; + + private: System::Data::DataColumn^ columnDefault; + + private: System::Data::DataColumn^ columnMonster_Id; + + public: event ValidateXML::MonsterList::HitDiceRowChangeEventHandler^ HitDiceRowChanging; + + public: event ValidateXML::MonsterList::HitDiceRowChangeEventHandler^ HitDiceRowChanged; + + public: event ValidateXML::MonsterList::HitDiceRowChangeEventHandler^ HitDiceRowDeleting; + + public: event ValidateXML::MonsterList::HitDiceRowChangeEventHandler^ HitDiceRowDeleted; + + public: [System::Diagnostics::DebuggerNonUserCodeAttribute] + HitDiceDataTable(); + internal: [System::Diagnostics::DebuggerNonUserCodeAttribute] + HitDiceDataTable(System::Data::DataTable^ table); + protected: [System::Diagnostics::DebuggerNonUserCodeAttribute] + HitDiceDataTable(System::Runtime::Serialization::SerializationInfo^ info, System::Runtime::Serialization::StreamingContext context); + public: [System::Diagnostics::DebuggerNonUserCodeAttribute] + property System::Data::DataColumn^ DiceColumn { + System::Data::DataColumn^ get(); + } + + public: [System::Diagnostics::DebuggerNonUserCodeAttribute] + property System::Data::DataColumn^ DefaultColumn { + System::Data::DataColumn^ get(); + } + + public: [System::Diagnostics::DebuggerNonUserCodeAttribute] + property System::Data::DataColumn^ Monster_IdColumn { + System::Data::DataColumn^ get(); + } + + public: [System::Diagnostics::DebuggerNonUserCodeAttribute, + System::ComponentModel::Browsable(false)] + property System::Int32 Count { + System::Int32 get(); + } + + public: [System::Diagnostics::DebuggerNonUserCodeAttribute] + property ValidateXML::MonsterList::HitDiceRow^ default [System::Int32 ] { + ValidateXML::MonsterList::HitDiceRow^ get(System::Int32 index); + } + + public: [System::Diagnostics::DebuggerNonUserCodeAttribute] + System::Void AddHitDiceRow(ValidateXML::MonsterList::HitDiceRow^ row); + + public: [System::Diagnostics::DebuggerNonUserCodeAttribute] + ValidateXML::MonsterList::HitDiceRow^ AddHitDiceRow(System::String^ Dice, System::Byte Default, ValidateXML::MonsterList::MonsterRow^ parentMonsterRowByMonster_HitDice); + + public: [System::Diagnostics::DebuggerNonUserCodeAttribute] + virtual System::Collections::IEnumerator^ GetEnumerator(); + + public: [System::Diagnostics::DebuggerNonUserCodeAttribute] + virtual System::Data::DataTable^ Clone() override; + + protected: [System::Diagnostics::DebuggerNonUserCodeAttribute] + virtual System::Data::DataTable^ CreateInstance() override; + + internal: [System::Diagnostics::DebuggerNonUserCodeAttribute] + System::Void InitVars(); + + private: [System::Diagnostics::DebuggerNonUserCodeAttribute] + System::Void InitClass(); + + public: [System::Diagnostics::DebuggerNonUserCodeAttribute] + ValidateXML::MonsterList::HitDiceRow^ NewHitDiceRow(); + + protected: [System::Diagnostics::DebuggerNonUserCodeAttribute] + virtual System::Data::DataRow^ NewRowFromBuilder(System::Data::DataRowBuilder^ builder) override; + + protected: [System::Diagnostics::DebuggerNonUserCodeAttribute] + virtual System::Type^ GetRowType() override; + + protected: [System::Diagnostics::DebuggerNonUserCodeAttribute] + virtual System::Void OnRowChanged(System::Data::DataRowChangeEventArgs^ e) override; + + protected: [System::Diagnostics::DebuggerNonUserCodeAttribute] + virtual System::Void OnRowChanging(System::Data::DataRowChangeEventArgs^ e) override; + + protected: [System::Diagnostics::DebuggerNonUserCodeAttribute] + virtual System::Void OnRowDeleted(System::Data::DataRowChangeEventArgs^ e) override; + + protected: [System::Diagnostics::DebuggerNonUserCodeAttribute] + virtual System::Void OnRowDeleting(System::Data::DataRowChangeEventArgs^ e) override; + + public: [System::Diagnostics::DebuggerNonUserCodeAttribute] + System::Void RemoveHitDiceRow(ValidateXML::MonsterList::HitDiceRow^ row); + + public: [System::Diagnostics::DebuggerNonUserCodeAttribute] + static System::Xml::Schema::XmlSchemaComplexType^ GetTypedTableSchema(System::Xml::Schema::XmlSchemaSet^ xs); + }; + + public : [System::CodeDom::Compiler::GeneratedCodeAttribute(L"System.Data.Design.TypedDataSetGenerator", L"2.0.0.0"), + System::Serializable, + System::Xml::Serialization::XmlSchemaProviderAttribute(L"GetTypedTableSchema")] + ref class WeaponDataTable : public System::Data::DataTable, public System::Collections::IEnumerable { + + private: System::Data::DataColumn^ columnNumber; + + private: System::Data::DataColumn^ columnDamage; + + private: System::Data::DataColumn^ columnWeapon_text; + + private: System::Data::DataColumn^ columnMonster_Id; + + public: event ValidateXML::MonsterList::WeaponRowChangeEventHandler^ WeaponRowChanging; + + public: event ValidateXML::MonsterList::WeaponRowChangeEventHandler^ WeaponRowChanged; + + public: event ValidateXML::MonsterList::WeaponRowChangeEventHandler^ WeaponRowDeleting; + + public: event ValidateXML::MonsterList::WeaponRowChangeEventHandler^ WeaponRowDeleted; + + public: [System::Diagnostics::DebuggerNonUserCodeAttribute] + WeaponDataTable(); + internal: [System::Diagnostics::DebuggerNonUserCodeAttribute] + WeaponDataTable(System::Data::DataTable^ table); + protected: [System::Diagnostics::DebuggerNonUserCodeAttribute] + WeaponDataTable(System::Runtime::Serialization::SerializationInfo^ info, System::Runtime::Serialization::StreamingContext context); + public: [System::Diagnostics::DebuggerNonUserCodeAttribute] + property System::Data::DataColumn^ NumberColumn { + System::Data::DataColumn^ get(); + } + + public: [System::Diagnostics::DebuggerNonUserCodeAttribute] + property System::Data::DataColumn^ DamageColumn { + System::Data::DataColumn^ get(); + } + + public: [System::Diagnostics::DebuggerNonUserCodeAttribute] + property System::Data::DataColumn^ Weapon_textColumn { + System::Data::DataColumn^ get(); + } + + public: [System::Diagnostics::DebuggerNonUserCodeAttribute] + property System::Data::DataColumn^ Monster_IdColumn { + System::Data::DataColumn^ get(); + } + + public: [System::Diagnostics::DebuggerNonUserCodeAttribute, + System::ComponentModel::Browsable(false)] + property System::Int32 Count { + System::Int32 get(); + } + + public: [System::Diagnostics::DebuggerNonUserCodeAttribute] + property ValidateXML::MonsterList::WeaponRow^ default [System::Int32 ] { + ValidateXML::MonsterList::WeaponRow^ get(System::Int32 index); + } + + public: [System::Diagnostics::DebuggerNonUserCodeAttribute] + System::Void AddWeaponRow(ValidateXML::MonsterList::WeaponRow^ row); + + public: [System::Diagnostics::DebuggerNonUserCodeAttribute] + ValidateXML::MonsterList::WeaponRow^ AddWeaponRow(System::Byte Number, System::String^ Damage, System::String^ Weapon_text, + ValidateXML::MonsterList::MonsterRow^ parentMonsterRowByMonster_Weapon); + + public: [System::Diagnostics::DebuggerNonUserCodeAttribute] + virtual System::Collections::IEnumerator^ GetEnumerator(); + + public: [System::Diagnostics::DebuggerNonUserCodeAttribute] + virtual System::Data::DataTable^ Clone() override; + + protected: [System::Diagnostics::DebuggerNonUserCodeAttribute] + virtual System::Data::DataTable^ CreateInstance() override; + + internal: [System::Diagnostics::DebuggerNonUserCodeAttribute] + System::Void InitVars(); + + private: [System::Diagnostics::DebuggerNonUserCodeAttribute] + System::Void InitClass(); + + public: [System::Diagnostics::DebuggerNonUserCodeAttribute] + ValidateXML::MonsterList::WeaponRow^ NewWeaponRow(); + + protected: [System::Diagnostics::DebuggerNonUserCodeAttribute] + virtual System::Data::DataRow^ NewRowFromBuilder(System::Data::DataRowBuilder^ builder) override; + + protected: [System::Diagnostics::DebuggerNonUserCodeAttribute] + virtual System::Type^ GetRowType() override; + + protected: [System::Diagnostics::DebuggerNonUserCodeAttribute] + virtual System::Void OnRowChanged(System::Data::DataRowChangeEventArgs^ e) override; + + protected: [System::Diagnostics::DebuggerNonUserCodeAttribute] + virtual System::Void OnRowChanging(System::Data::DataRowChangeEventArgs^ e) override; + + protected: [System::Diagnostics::DebuggerNonUserCodeAttribute] + virtual System::Void OnRowDeleted(System::Data::DataRowChangeEventArgs^ e) override; + + protected: [System::Diagnostics::DebuggerNonUserCodeAttribute] + virtual System::Void OnRowDeleting(System::Data::DataRowChangeEventArgs^ e) override; + + public: [System::Diagnostics::DebuggerNonUserCodeAttribute] + System::Void RemoveWeaponRow(ValidateXML::MonsterList::WeaponRow^ row); + + public: [System::Diagnostics::DebuggerNonUserCodeAttribute] + static System::Xml::Schema::XmlSchemaComplexType^ GetTypedTableSchema(System::Xml::Schema::XmlSchemaSet^ xs); + }; + + public : [System::CodeDom::Compiler::GeneratedCodeAttribute(L"System.Data.Design.TypedDataSetGenerator", L"2.0.0.0")] + ref class MonsterRow : public System::Data::DataRow { + + private: ValidateXML::MonsterList::MonsterDataTable^ tableMonster; + + internal: [System::Diagnostics::DebuggerNonUserCodeAttribute] + MonsterRow(System::Data::DataRowBuilder^ rb); + public: [System::Diagnostics::DebuggerNonUserCodeAttribute] + property System::String^ Name { + System::String^ get(); + System::Void set(System::String^ value); + } + + public: [System::Diagnostics::DebuggerNonUserCodeAttribute] + property System::Int32 Monster_Id { + System::Int32 get(); + System::Void set(System::Int32 value); + } + + public: [System::Diagnostics::DebuggerNonUserCodeAttribute] + cli::array< ValidateXML::MonsterList::HitDiceRow^ >^ GetHitDiceRows(); + + public: [System::Diagnostics::DebuggerNonUserCodeAttribute] + cli::array< ValidateXML::MonsterList::WeaponRow^ >^ GetWeaponRows(); + }; + + public : [System::CodeDom::Compiler::GeneratedCodeAttribute(L"System.Data.Design.TypedDataSetGenerator", L"2.0.0.0")] + ref class HitDiceRow : public System::Data::DataRow { + + private: ValidateXML::MonsterList::HitDiceDataTable^ tableHitDice; + + internal: [System::Diagnostics::DebuggerNonUserCodeAttribute] + HitDiceRow(System::Data::DataRowBuilder^ rb); + public: [System::Diagnostics::DebuggerNonUserCodeAttribute] + property System::String^ Dice { + System::String^ get(); + System::Void set(System::String^ value); + } + + public: [System::Diagnostics::DebuggerNonUserCodeAttribute] + property System::Byte Default { + System::Byte get(); + System::Void set(System::Byte value); + } + + public: [System::Diagnostics::DebuggerNonUserCodeAttribute] + property System::Int32 Monster_Id { + System::Int32 get(); + System::Void set(System::Int32 value); + } + + public: [System::Diagnostics::DebuggerNonUserCodeAttribute] + property ValidateXML::MonsterList::MonsterRow^ MonsterRow { + ValidateXML::MonsterList::MonsterRow^ get(); + System::Void set(ValidateXML::MonsterList::MonsterRow^ value); + } + + public: [System::Diagnostics::DebuggerNonUserCodeAttribute] + System::Boolean IsMonster_IdNull(); + + public: [System::Diagnostics::DebuggerNonUserCodeAttribute] + System::Void SetMonster_IdNull(); + }; + + public : [System::CodeDom::Compiler::GeneratedCodeAttribute(L"System.Data.Design.TypedDataSetGenerator", L"2.0.0.0")] + ref class WeaponRow : public System::Data::DataRow { + + private: ValidateXML::MonsterList::WeaponDataTable^ tableWeapon; + + internal: [System::Diagnostics::DebuggerNonUserCodeAttribute] + WeaponRow(System::Data::DataRowBuilder^ rb); + public: [System::Diagnostics::DebuggerNonUserCodeAttribute] + property System::Byte Number { + System::Byte get(); + System::Void set(System::Byte value); + } + + public: [System::Diagnostics::DebuggerNonUserCodeAttribute] + property System::String^ Damage { + System::String^ get(); + System::Void set(System::String^ value); + } + + public: [System::Diagnostics::DebuggerNonUserCodeAttribute] + property System::String^ Weapon_text { + System::String^ get(); + System::Void set(System::String^ value); + } + + public: [System::Diagnostics::DebuggerNonUserCodeAttribute] + property System::Int32 Monster_Id { + System::Int32 get(); + System::Void set(System::Int32 value); + } + + public: [System::Diagnostics::DebuggerNonUserCodeAttribute] + property ValidateXML::MonsterList::MonsterRow^ MonsterRow { + ValidateXML::MonsterList::MonsterRow^ get(); + System::Void set(ValidateXML::MonsterList::MonsterRow^ value); + } + + public: [System::Diagnostics::DebuggerNonUserCodeAttribute] + System::Boolean IsMonster_IdNull(); + + public: [System::Diagnostics::DebuggerNonUserCodeAttribute] + System::Void SetMonster_IdNull(); + }; + + public : [System::CodeDom::Compiler::GeneratedCodeAttribute(L"System.Data.Design.TypedDataSetGenerator", L"2.0.0.0")] + ref class MonsterRowChangeEvent : public System::EventArgs { + + private: ValidateXML::MonsterList::MonsterRow^ eventRow; + + private: System::Data::DataRowAction eventAction; + + public: [System::Diagnostics::DebuggerNonUserCodeAttribute] + MonsterRowChangeEvent(ValidateXML::MonsterList::MonsterRow^ row, System::Data::DataRowAction action); + public: [System::Diagnostics::DebuggerNonUserCodeAttribute] + property ValidateXML::MonsterList::MonsterRow^ Row { + ValidateXML::MonsterList::MonsterRow^ get(); + } + + public: [System::Diagnostics::DebuggerNonUserCodeAttribute] + property System::Data::DataRowAction Action { + System::Data::DataRowAction get(); + } + }; + + public : [System::CodeDom::Compiler::GeneratedCodeAttribute(L"System.Data.Design.TypedDataSetGenerator", L"2.0.0.0")] + ref class HitDiceRowChangeEvent : public System::EventArgs { + + private: ValidateXML::MonsterList::HitDiceRow^ eventRow; + + private: System::Data::DataRowAction eventAction; + + public: [System::Diagnostics::DebuggerNonUserCodeAttribute] + HitDiceRowChangeEvent(ValidateXML::MonsterList::HitDiceRow^ row, System::Data::DataRowAction action); + public: [System::Diagnostics::DebuggerNonUserCodeAttribute] + property ValidateXML::MonsterList::HitDiceRow^ Row { + ValidateXML::MonsterList::HitDiceRow^ get(); + } + + public: [System::Diagnostics::DebuggerNonUserCodeAttribute] + property System::Data::DataRowAction Action { + System::Data::DataRowAction get(); + } + }; + + public : [System::CodeDom::Compiler::GeneratedCodeAttribute(L"System.Data.Design.TypedDataSetGenerator", L"2.0.0.0")] + ref class WeaponRowChangeEvent : public System::EventArgs { + + private: ValidateXML::MonsterList::WeaponRow^ eventRow; + + private: System::Data::DataRowAction eventAction; + + public: [System::Diagnostics::DebuggerNonUserCodeAttribute] + WeaponRowChangeEvent(ValidateXML::MonsterList::WeaponRow^ row, System::Data::DataRowAction action); + public: [System::Diagnostics::DebuggerNonUserCodeAttribute] + property ValidateXML::MonsterList::WeaponRow^ Row { + ValidateXML::MonsterList::WeaponRow^ get(); + } + + public: [System::Diagnostics::DebuggerNonUserCodeAttribute] + property System::Data::DataRowAction Action { + System::Data::DataRowAction get(); + } + }; + }; +} +namespace ValidateXML { + + + inline MonsterList::MonsterList() { + this->BeginInit(); + this->InitClass(); + System::ComponentModel::CollectionChangeEventHandler^ schemaChangedHandler = gcnew System::ComponentModel::CollectionChangeEventHandler(this, &ValidateXML::MonsterList::SchemaChanged); + __super::Tables->CollectionChanged += schemaChangedHandler; + __super::Relations->CollectionChanged += schemaChangedHandler; + this->EndInit(); + } + + inline MonsterList::MonsterList(System::Runtime::Serialization::SerializationInfo^ info, System::Runtime::Serialization::StreamingContext context) : + System::Data::DataSet(info, context) { + if (this->IsBinarySerialized(info, context) == true) { + this->InitVars(false); + System::ComponentModel::CollectionChangeEventHandler^ schemaChangedHandler1 = gcnew System::ComponentModel::CollectionChangeEventHandler(this, &ValidateXML::MonsterList::SchemaChanged); + this->Tables->CollectionChanged += schemaChangedHandler1; + this->Relations->CollectionChanged += schemaChangedHandler1; + return; + } + System::String^ strSchema = (cli::safe_cast(info->GetValue(L"XmlSchema", System::String::typeid))); + if (this->DetermineSchemaSerializationMode(info, context) == System::Data::SchemaSerializationMode::IncludeSchema) { + System::Data::DataSet^ ds = (gcnew System::Data::DataSet()); + ds->EnforceConstraints = false; + ds->ReadXmlSchema((gcnew System::Xml::XmlTextReader((gcnew System::IO::StringReader(strSchema))))); + if (ds->Tables[L"Monster"] != nullptr) { + __super::Tables->Add((gcnew ValidateXML::MonsterList::MonsterDataTable(ds->Tables[L"Monster"]))); + } + if (ds->Tables[L"HitDice"] != nullptr) { + __super::Tables->Add((gcnew ValidateXML::MonsterList::HitDiceDataTable(ds->Tables[L"HitDice"]))); + } + if (ds->Tables[L"Weapon"] != nullptr) { + __super::Tables->Add((gcnew ValidateXML::MonsterList::WeaponDataTable(ds->Tables[L"Weapon"]))); + } + this->DataSetName = ds->DataSetName; + this->Prefix = ds->Prefix; + this->Namespace = ds->Namespace; + this->Locale = ds->Locale; + this->CaseSensitive = ds->CaseSensitive; + this->EnforceConstraints = ds->EnforceConstraints; + this->Merge(ds, false, System::Data::MissingSchemaAction::Add); + this->InitVars(); + } + else { + this->ReadXmlSchema((gcnew System::Xml::XmlTextReader((gcnew System::IO::StringReader(strSchema))))); + } + this->GetSerializationData(info, context); + System::ComponentModel::CollectionChangeEventHandler^ schemaChangedHandler = gcnew System::ComponentModel::CollectionChangeEventHandler(this, &ValidateXML::MonsterList::SchemaChanged); + __super::Tables->CollectionChanged += schemaChangedHandler; + this->Relations->CollectionChanged += schemaChangedHandler; + } + + inline ValidateXML::MonsterList::MonsterDataTable^ MonsterList::Monster::get() { + return this->tableMonster; + } + + inline ValidateXML::MonsterList::HitDiceDataTable^ MonsterList::HitDice::get() { + return this->tableHitDice; + } + + inline ValidateXML::MonsterList::WeaponDataTable^ MonsterList::Weapon::get() { + return this->tableWeapon; + } + + inline System::Data::SchemaSerializationMode MonsterList::SchemaSerializationMode::get() { + return this->_schemaSerializationMode; + } + inline System::Void MonsterList::SchemaSerializationMode::set(System::Data::SchemaSerializationMode value) { + this->_schemaSerializationMode = __identifier(value); + } + + inline System::Data::DataTableCollection^ MonsterList::Tables::get() { + return __super::Tables; + } + + inline System::Data::DataRelationCollection^ MonsterList::Relations::get() { + return __super::Relations; + } + + inline System::Boolean MonsterList::EnforceConstraints::get() { + return __super::EnforceConstraints; + } + inline System::Void MonsterList::EnforceConstraints::set(System::Boolean value) { + __super::EnforceConstraints = __identifier(value); + } + + inline System::Void MonsterList::InitializeDerivedDataSet() { + this->BeginInit(); + this->InitClass(); + this->EndInit(); + } + + inline System::Data::DataSet^ MonsterList::Clone() { + ValidateXML::MonsterList^ cln = (cli::safe_cast(__super::Clone())); + cln->InitVars(); + return cln; + } + + inline System::Boolean MonsterList::ShouldSerializeTables() { + return false; + } + + inline System::Boolean MonsterList::ShouldSerializeRelations() { + return false; + } + + inline System::Void MonsterList::ReadXmlSerializable(System::Xml::XmlReader^ reader) { + if (this->DetermineSchemaSerializationMode(reader) == System::Data::SchemaSerializationMode::IncludeSchema) { + this->Reset(); + System::Data::DataSet^ ds = (gcnew System::Data::DataSet()); + ds->ReadXml(reader); + if (ds->Tables[L"Monster"] != nullptr) { + __super::Tables->Add((gcnew ValidateXML::MonsterList::MonsterDataTable(ds->Tables[L"Monster"]))); + } + if (ds->Tables[L"HitDice"] != nullptr) { + __super::Tables->Add((gcnew ValidateXML::MonsterList::HitDiceDataTable(ds->Tables[L"HitDice"]))); + } + if (ds->Tables[L"Weapon"] != nullptr) { + __super::Tables->Add((gcnew ValidateXML::MonsterList::WeaponDataTable(ds->Tables[L"Weapon"]))); + } + this->DataSetName = ds->DataSetName; + this->Prefix = ds->Prefix; + this->Namespace = ds->Namespace; + this->Locale = ds->Locale; + this->CaseSensitive = ds->CaseSensitive; + this->EnforceConstraints = ds->EnforceConstraints; + this->Merge(ds, false, System::Data::MissingSchemaAction::Add); + this->InitVars(); + } + else { + this->ReadXml(reader); + this->InitVars(); + } + } + + inline System::Xml::Schema::XmlSchema^ MonsterList::GetSchemaSerializable() { + System::IO::MemoryStream^ stream = (gcnew System::IO::MemoryStream()); + this->WriteXmlSchema((gcnew System::Xml::XmlTextWriter(stream, nullptr))); + stream->Position = 0; + return System::Xml::Schema::XmlSchema::Read((gcnew System::Xml::XmlTextReader(stream)), nullptr); + } + + inline System::Void MonsterList::InitVars() { + this->InitVars(true); + } + + inline System::Void MonsterList::InitVars(System::Boolean initTable) { + this->tableMonster = (cli::safe_cast(__super::Tables[L"Monster"])); + if (initTable == true) { + if (this->tableMonster != nullptr) { + this->tableMonster->InitVars(); + } + } + this->tableHitDice = (cli::safe_cast(__super::Tables[L"HitDice"])); + if (initTable == true) { + if (this->tableHitDice != nullptr) { + this->tableHitDice->InitVars(); + } + } + this->tableWeapon = (cli::safe_cast(__super::Tables[L"Weapon"])); + if (initTable == true) { + if (this->tableWeapon != nullptr) { + this->tableWeapon->InitVars(); + } + } + this->relationMonster_HitDice = this->Relations[L"Monster_HitDice"]; + this->relationMonster_Weapon = this->Relations[L"Monster_Weapon"]; + } + + inline System::Void MonsterList::InitClass() { + this->DataSetName = L"MonsterList"; + this->Prefix = L""; + this->EnforceConstraints = true; + this->tableMonster = (gcnew ValidateXML::MonsterList::MonsterDataTable()); + __super::Tables->Add(this->tableMonster); + this->tableHitDice = (gcnew ValidateXML::MonsterList::HitDiceDataTable()); + __super::Tables->Add(this->tableHitDice); + this->tableWeapon = (gcnew ValidateXML::MonsterList::WeaponDataTable()); + __super::Tables->Add(this->tableWeapon); + System::Data::ForeignKeyConstraint^ fkc; + fkc = (gcnew System::Data::ForeignKeyConstraint(L"Monster_HitDice", gcnew cli::array< System::Data::DataColumn^ >(1) {this->tableMonster->Monster_IdColumn}, + gcnew cli::array< System::Data::DataColumn^ >(1) {this->tableHitDice->Monster_IdColumn})); + this->tableHitDice->Constraints->Add(fkc); + fkc->AcceptRejectRule = System::Data::AcceptRejectRule::None; + fkc->DeleteRule = System::Data::Rule::Cascade; + fkc->UpdateRule = System::Data::Rule::Cascade; + fkc = (gcnew System::Data::ForeignKeyConstraint(L"Monster_Weapon", gcnew cli::array< System::Data::DataColumn^ >(1) {this->tableMonster->Monster_IdColumn}, + gcnew cli::array< System::Data::DataColumn^ >(1) {this->tableWeapon->Monster_IdColumn})); + this->tableWeapon->Constraints->Add(fkc); + fkc->AcceptRejectRule = System::Data::AcceptRejectRule::None; + fkc->DeleteRule = System::Data::Rule::Cascade; + fkc->UpdateRule = System::Data::Rule::Cascade; + this->relationMonster_HitDice = (gcnew System::Data::DataRelation(L"Monster_HitDice", gcnew cli::array< System::Data::DataColumn^ >(1) {this->tableMonster->Monster_IdColumn}, + gcnew cli::array< System::Data::DataColumn^ >(1) {this->tableHitDice->Monster_IdColumn}, false)); + this->relationMonster_HitDice->Nested = true; + this->Relations->Add(this->relationMonster_HitDice); + this->relationMonster_Weapon = (gcnew System::Data::DataRelation(L"Monster_Weapon", gcnew cli::array< System::Data::DataColumn^ >(1) {this->tableMonster->Monster_IdColumn}, + gcnew cli::array< System::Data::DataColumn^ >(1) {this->tableWeapon->Monster_IdColumn}, false)); + this->relationMonster_Weapon->Nested = true; + this->Relations->Add(this->relationMonster_Weapon); + } + + inline System::Boolean MonsterList::ShouldSerializeMonster() { + return false; + } + + inline System::Boolean MonsterList::ShouldSerializeHitDice() { + return false; + } + + inline System::Boolean MonsterList::ShouldSerializeWeapon() { + return false; + } + + inline System::Void MonsterList::SchemaChanged(System::Object^ sender, System::ComponentModel::CollectionChangeEventArgs^ e) { + if (e->Action == System::ComponentModel::CollectionChangeAction::Remove) { + this->InitVars(); + } + } + + inline System::Xml::Schema::XmlSchemaComplexType^ MonsterList::GetTypedDataSetSchema(System::Xml::Schema::XmlSchemaSet^ xs) { + ValidateXML::MonsterList^ ds = (gcnew ValidateXML::MonsterList()); + System::Xml::Schema::XmlSchemaComplexType^ type = (gcnew System::Xml::Schema::XmlSchemaComplexType()); + System::Xml::Schema::XmlSchemaSequence^ sequence = (gcnew System::Xml::Schema::XmlSchemaSequence()); + xs->Add(ds->GetSchemaSerializable()); + System::Xml::Schema::XmlSchemaAny^ any = (gcnew System::Xml::Schema::XmlSchemaAny()); + any->Namespace = ds->Namespace; + sequence->Items->Add(any); + type->Particle = sequence; + return type; + } + + + inline MonsterList::MonsterDataTable::MonsterDataTable() { + this->TableName = L"Monster"; + this->BeginInit(); + this->InitClass(); + this->EndInit(); + } + + inline MonsterList::MonsterDataTable::MonsterDataTable(System::Data::DataTable^ table) { + this->TableName = table->TableName; + if (table->CaseSensitive != table->DataSet->CaseSensitive) { + this->CaseSensitive = table->CaseSensitive; + } + if (table->Locale->ToString() != table->DataSet->Locale->ToString()) { + this->Locale = table->Locale; + } + if (table->Namespace != table->DataSet->Namespace) { + this->Namespace = table->Namespace; + } + this->Prefix = table->Prefix; + this->MinimumCapacity = table->MinimumCapacity; + } + + inline MonsterList::MonsterDataTable::MonsterDataTable(System::Runtime::Serialization::SerializationInfo^ info, System::Runtime::Serialization::StreamingContext context) : + System::Data::DataTable(info, context) { + this->InitVars(); + } + + inline System::Data::DataColumn^ MonsterList::MonsterDataTable::NameColumn::get() { + return this->columnName; + } + + inline System::Data::DataColumn^ MonsterList::MonsterDataTable::Monster_IdColumn::get() { + return this->columnMonster_Id; + } + + inline System::Int32 MonsterList::MonsterDataTable::Count::get() { + return this->Rows->Count; + } + + inline ValidateXML::MonsterList::MonsterRow^ MonsterList::MonsterDataTable::default::get(System::Int32 index) { + return (cli::safe_cast(this->Rows[index])); + } + + inline System::Void MonsterList::MonsterDataTable::AddMonsterRow(ValidateXML::MonsterList::MonsterRow^ row) { + this->Rows->Add(row); + } + + inline ValidateXML::MonsterList::MonsterRow^ MonsterList::MonsterDataTable::AddMonsterRow(System::String^ Name) { + ValidateXML::MonsterList::MonsterRow^ rowMonsterRow = (cli::safe_cast(this->NewRow())); + rowMonsterRow->ItemArray = gcnew cli::array< System::Object^ >(2) {Name, nullptr}; + this->Rows->Add(rowMonsterRow); + return rowMonsterRow; + } + + inline System::Collections::IEnumerator^ MonsterList::MonsterDataTable::GetEnumerator() { + return this->Rows->GetEnumerator(); + } + + inline System::Data::DataTable^ MonsterList::MonsterDataTable::Clone() { + ValidateXML::MonsterList::MonsterDataTable^ cln = (cli::safe_cast(__super::Clone())); + cln->InitVars(); + return cln; + } + + inline System::Data::DataTable^ MonsterList::MonsterDataTable::CreateInstance() { + return (gcnew ValidateXML::MonsterList::MonsterDataTable()); + } + + inline System::Void MonsterList::MonsterDataTable::InitVars() { + this->columnName = __super::Columns[L"Name"]; + this->columnMonster_Id = __super::Columns[L"Monster_Id"]; + } + + inline System::Void MonsterList::MonsterDataTable::InitClass() { + this->columnName = (gcnew System::Data::DataColumn(L"Name", System::String::typeid, nullptr, System::Data::MappingType::Element)); + __super::Columns->Add(this->columnName); + this->columnMonster_Id = (gcnew System::Data::DataColumn(L"Monster_Id", System::Int32::typeid, nullptr, System::Data::MappingType::Hidden)); + __super::Columns->Add(this->columnMonster_Id); + this->Constraints->Add((gcnew System::Data::UniqueConstraint(L"Constraint1", gcnew cli::array< System::Data::DataColumn^ >(1) {this->columnMonster_Id}, + true))); + this->columnName->AllowDBNull = false; + this->columnMonster_Id->AutoIncrement = true; + this->columnMonster_Id->AllowDBNull = false; + this->columnMonster_Id->Unique = true; + } + + inline ValidateXML::MonsterList::MonsterRow^ MonsterList::MonsterDataTable::NewMonsterRow() { + return (cli::safe_cast(this->NewRow())); + } + + inline System::Data::DataRow^ MonsterList::MonsterDataTable::NewRowFromBuilder(System::Data::DataRowBuilder^ builder) { + return (gcnew ValidateXML::MonsterList::MonsterRow(builder)); + } + + inline System::Type^ MonsterList::MonsterDataTable::GetRowType() { + return ValidateXML::MonsterList::MonsterRow::typeid; + } + + inline System::Void MonsterList::MonsterDataTable::OnRowChanged(System::Data::DataRowChangeEventArgs^ e) { + __super::OnRowChanged(e); + { + this->MonsterRowChanged(this, (gcnew ValidateXML::MonsterList::MonsterRowChangeEvent((cli::safe_cast(e->Row)), + e->Action))); + } + } + + inline System::Void MonsterList::MonsterDataTable::OnRowChanging(System::Data::DataRowChangeEventArgs^ e) { + __super::OnRowChanging(e); + { + this->MonsterRowChanging(this, (gcnew ValidateXML::MonsterList::MonsterRowChangeEvent((cli::safe_cast(e->Row)), + e->Action))); + } + } + + inline System::Void MonsterList::MonsterDataTable::OnRowDeleted(System::Data::DataRowChangeEventArgs^ e) { + __super::OnRowDeleted(e); + { + this->MonsterRowDeleted(this, (gcnew ValidateXML::MonsterList::MonsterRowChangeEvent((cli::safe_cast(e->Row)), + e->Action))); + } + } + + inline System::Void MonsterList::MonsterDataTable::OnRowDeleting(System::Data::DataRowChangeEventArgs^ e) { + __super::OnRowDeleting(e); + { + this->MonsterRowDeleting(this, (gcnew ValidateXML::MonsterList::MonsterRowChangeEvent((cli::safe_cast(e->Row)), + e->Action))); + } + } + + inline System::Void MonsterList::MonsterDataTable::RemoveMonsterRow(ValidateXML::MonsterList::MonsterRow^ row) { + this->Rows->Remove(row); + } + + inline System::Xml::Schema::XmlSchemaComplexType^ MonsterList::MonsterDataTable::GetTypedTableSchema(System::Xml::Schema::XmlSchemaSet^ xs) { + System::Xml::Schema::XmlSchemaComplexType^ type = (gcnew System::Xml::Schema::XmlSchemaComplexType()); + System::Xml::Schema::XmlSchemaSequence^ sequence = (gcnew System::Xml::Schema::XmlSchemaSequence()); + ValidateXML::MonsterList^ ds = (gcnew ValidateXML::MonsterList()); + xs->Add(ds->GetSchemaSerializable()); + System::Xml::Schema::XmlSchemaAny^ any1 = (gcnew System::Xml::Schema::XmlSchemaAny()); + any1->Namespace = L"http://www.w3.org/2001/XMLSchema"; + any1->MinOccurs = System::Decimal(0); + any1->MaxOccurs = System::Decimal::MaxValue; + any1->ProcessContents = System::Xml::Schema::XmlSchemaContentProcessing::Lax; + sequence->Items->Add(any1); + System::Xml::Schema::XmlSchemaAny^ any2 = (gcnew System::Xml::Schema::XmlSchemaAny()); + any2->Namespace = L"urn:schemas-microsoft-com:xml-diffgram-v1"; + any2->MinOccurs = System::Decimal(1); + any2->ProcessContents = System::Xml::Schema::XmlSchemaContentProcessing::Lax; + sequence->Items->Add(any2); + System::Xml::Schema::XmlSchemaAttribute^ attribute1 = (gcnew System::Xml::Schema::XmlSchemaAttribute()); + attribute1->Name = L"namespace"; + attribute1->FixedValue = ds->Namespace; + type->Attributes->Add(attribute1); + System::Xml::Schema::XmlSchemaAttribute^ attribute2 = (gcnew System::Xml::Schema::XmlSchemaAttribute()); + attribute2->Name = L"tableTypeName"; + attribute2->FixedValue = L"MonsterDataTable"; + type->Attributes->Add(attribute2); + type->Particle = sequence; + return type; + } + + + inline MonsterList::HitDiceDataTable::HitDiceDataTable() { + this->TableName = L"HitDice"; + this->BeginInit(); + this->InitClass(); + this->EndInit(); + } + + inline MonsterList::HitDiceDataTable::HitDiceDataTable(System::Data::DataTable^ table) { + this->TableName = table->TableName; + if (table->CaseSensitive != table->DataSet->CaseSensitive) { + this->CaseSensitive = table->CaseSensitive; + } + if (table->Locale->ToString() != table->DataSet->Locale->ToString()) { + this->Locale = table->Locale; + } + if (table->Namespace != table->DataSet->Namespace) { + this->Namespace = table->Namespace; + } + this->Prefix = table->Prefix; + this->MinimumCapacity = table->MinimumCapacity; + } + + inline MonsterList::HitDiceDataTable::HitDiceDataTable(System::Runtime::Serialization::SerializationInfo^ info, System::Runtime::Serialization::StreamingContext context) : + System::Data::DataTable(info, context) { + this->InitVars(); + } + + inline System::Data::DataColumn^ MonsterList::HitDiceDataTable::DiceColumn::get() { + return this->columnDice; + } + + inline System::Data::DataColumn^ MonsterList::HitDiceDataTable::DefaultColumn::get() { + return this->columnDefault; + } + + inline System::Data::DataColumn^ MonsterList::HitDiceDataTable::Monster_IdColumn::get() { + return this->columnMonster_Id; + } + + inline System::Int32 MonsterList::HitDiceDataTable::Count::get() { + return this->Rows->Count; + } + + inline ValidateXML::MonsterList::HitDiceRow^ MonsterList::HitDiceDataTable::default::get(System::Int32 index) { + return (cli::safe_cast(this->Rows[index])); + } + + inline System::Void MonsterList::HitDiceDataTable::AddHitDiceRow(ValidateXML::MonsterList::HitDiceRow^ row) { + this->Rows->Add(row); + } + + inline ValidateXML::MonsterList::HitDiceRow^ MonsterList::HitDiceDataTable::AddHitDiceRow(System::String^ Dice, System::Byte Default, + ValidateXML::MonsterList::MonsterRow^ parentMonsterRowByMonster_HitDice) { + ValidateXML::MonsterList::HitDiceRow^ rowHitDiceRow = (cli::safe_cast(this->NewRow())); + rowHitDiceRow->ItemArray = gcnew cli::array< System::Object^ >(3) {Dice, Default, parentMonsterRowByMonster_HitDice[1]}; + this->Rows->Add(rowHitDiceRow); + return rowHitDiceRow; + } + + inline System::Collections::IEnumerator^ MonsterList::HitDiceDataTable::GetEnumerator() { + return this->Rows->GetEnumerator(); + } + + inline System::Data::DataTable^ MonsterList::HitDiceDataTable::Clone() { + ValidateXML::MonsterList::HitDiceDataTable^ cln = (cli::safe_cast(__super::Clone())); + cln->InitVars(); + return cln; + } + + inline System::Data::DataTable^ MonsterList::HitDiceDataTable::CreateInstance() { + return (gcnew ValidateXML::MonsterList::HitDiceDataTable()); + } + + inline System::Void MonsterList::HitDiceDataTable::InitVars() { + this->columnDice = __super::Columns[L"Dice"]; + this->columnDefault = __super::Columns[L"Default"]; + this->columnMonster_Id = __super::Columns[L"Monster_Id"]; + } + + inline System::Void MonsterList::HitDiceDataTable::InitClass() { + this->columnDice = (gcnew System::Data::DataColumn(L"Dice", System::String::typeid, nullptr, System::Data::MappingType::Attribute)); + __super::Columns->Add(this->columnDice); + this->columnDefault = (gcnew System::Data::DataColumn(L"Default", System::Byte::typeid, nullptr, System::Data::MappingType::Attribute)); + __super::Columns->Add(this->columnDefault); + this->columnMonster_Id = (gcnew System::Data::DataColumn(L"Monster_Id", System::Int32::typeid, nullptr, System::Data::MappingType::Hidden)); + __super::Columns->Add(this->columnMonster_Id); + this->columnDice->AllowDBNull = false; + this->columnDice->Namespace = L""; + this->columnDefault->AllowDBNull = false; + this->columnDefault->Namespace = L""; + } + + inline ValidateXML::MonsterList::HitDiceRow^ MonsterList::HitDiceDataTable::NewHitDiceRow() { + return (cli::safe_cast(this->NewRow())); + } + + inline System::Data::DataRow^ MonsterList::HitDiceDataTable::NewRowFromBuilder(System::Data::DataRowBuilder^ builder) { + return (gcnew ValidateXML::MonsterList::HitDiceRow(builder)); + } + + inline System::Type^ MonsterList::HitDiceDataTable::GetRowType() { + return ValidateXML::MonsterList::HitDiceRow::typeid; + } + + inline System::Void MonsterList::HitDiceDataTable::OnRowChanged(System::Data::DataRowChangeEventArgs^ e) { + __super::OnRowChanged(e); + { + this->HitDiceRowChanged(this, (gcnew ValidateXML::MonsterList::HitDiceRowChangeEvent((cli::safe_cast(e->Row)), + e->Action))); + } + } + + inline System::Void MonsterList::HitDiceDataTable::OnRowChanging(System::Data::DataRowChangeEventArgs^ e) { + __super::OnRowChanging(e); + { + this->HitDiceRowChanging(this, (gcnew ValidateXML::MonsterList::HitDiceRowChangeEvent((cli::safe_cast(e->Row)), + e->Action))); + } + } + + inline System::Void MonsterList::HitDiceDataTable::OnRowDeleted(System::Data::DataRowChangeEventArgs^ e) { + __super::OnRowDeleted(e); + { + this->HitDiceRowDeleted(this, (gcnew ValidateXML::MonsterList::HitDiceRowChangeEvent((cli::safe_cast(e->Row)), + e->Action))); + } + } + + inline System::Void MonsterList::HitDiceDataTable::OnRowDeleting(System::Data::DataRowChangeEventArgs^ e) { + __super::OnRowDeleting(e); + { + this->HitDiceRowDeleting(this, (gcnew ValidateXML::MonsterList::HitDiceRowChangeEvent((cli::safe_cast(e->Row)), + e->Action))); + } + } + + inline System::Void MonsterList::HitDiceDataTable::RemoveHitDiceRow(ValidateXML::MonsterList::HitDiceRow^ row) { + this->Rows->Remove(row); + } + + inline System::Xml::Schema::XmlSchemaComplexType^ MonsterList::HitDiceDataTable::GetTypedTableSchema(System::Xml::Schema::XmlSchemaSet^ xs) { + System::Xml::Schema::XmlSchemaComplexType^ type = (gcnew System::Xml::Schema::XmlSchemaComplexType()); + System::Xml::Schema::XmlSchemaSequence^ sequence = (gcnew System::Xml::Schema::XmlSchemaSequence()); + ValidateXML::MonsterList^ ds = (gcnew ValidateXML::MonsterList()); + xs->Add(ds->GetSchemaSerializable()); + System::Xml::Schema::XmlSchemaAny^ any1 = (gcnew System::Xml::Schema::XmlSchemaAny()); + any1->Namespace = L"http://www.w3.org/2001/XMLSchema"; + any1->MinOccurs = System::Decimal(0); + any1->MaxOccurs = System::Decimal::MaxValue; + any1->ProcessContents = System::Xml::Schema::XmlSchemaContentProcessing::Lax; + sequence->Items->Add(any1); + System::Xml::Schema::XmlSchemaAny^ any2 = (gcnew System::Xml::Schema::XmlSchemaAny()); + any2->Namespace = L"urn:schemas-microsoft-com:xml-diffgram-v1"; + any2->MinOccurs = System::Decimal(1); + any2->ProcessContents = System::Xml::Schema::XmlSchemaContentProcessing::Lax; + sequence->Items->Add(any2); + System::Xml::Schema::XmlSchemaAttribute^ attribute1 = (gcnew System::Xml::Schema::XmlSchemaAttribute()); + attribute1->Name = L"namespace"; + attribute1->FixedValue = ds->Namespace; + type->Attributes->Add(attribute1); + System::Xml::Schema::XmlSchemaAttribute^ attribute2 = (gcnew System::Xml::Schema::XmlSchemaAttribute()); + attribute2->Name = L"tableTypeName"; + attribute2->FixedValue = L"HitDiceDataTable"; + type->Attributes->Add(attribute2); + type->Particle = sequence; + return type; + } + + + inline MonsterList::WeaponDataTable::WeaponDataTable() { + this->TableName = L"Weapon"; + this->BeginInit(); + this->InitClass(); + this->EndInit(); + } + + inline MonsterList::WeaponDataTable::WeaponDataTable(System::Data::DataTable^ table) { + this->TableName = table->TableName; + if (table->CaseSensitive != table->DataSet->CaseSensitive) { + this->CaseSensitive = table->CaseSensitive; + } + if (table->Locale->ToString() != table->DataSet->Locale->ToString()) { + this->Locale = table->Locale; + } + if (table->Namespace != table->DataSet->Namespace) { + this->Namespace = table->Namespace; + } + this->Prefix = table->Prefix; + this->MinimumCapacity = table->MinimumCapacity; + } + + inline MonsterList::WeaponDataTable::WeaponDataTable(System::Runtime::Serialization::SerializationInfo^ info, System::Runtime::Serialization::StreamingContext context) : + System::Data::DataTable(info, context) { + this->InitVars(); + } + + inline System::Data::DataColumn^ MonsterList::WeaponDataTable::NumberColumn::get() { + return this->columnNumber; + } + + inline System::Data::DataColumn^ MonsterList::WeaponDataTable::DamageColumn::get() { + return this->columnDamage; + } + + inline System::Data::DataColumn^ MonsterList::WeaponDataTable::Weapon_textColumn::get() { + return this->columnWeapon_text; + } + + inline System::Data::DataColumn^ MonsterList::WeaponDataTable::Monster_IdColumn::get() { + return this->columnMonster_Id; + } + + inline System::Int32 MonsterList::WeaponDataTable::Count::get() { + return this->Rows->Count; + } + + inline ValidateXML::MonsterList::WeaponRow^ MonsterList::WeaponDataTable::default::get(System::Int32 index) { + return (cli::safe_cast(this->Rows[index])); + } + + inline System::Void MonsterList::WeaponDataTable::AddWeaponRow(ValidateXML::MonsterList::WeaponRow^ row) { + this->Rows->Add(row); + } + + inline ValidateXML::MonsterList::WeaponRow^ MonsterList::WeaponDataTable::AddWeaponRow(System::Byte Number, System::String^ Damage, + System::String^ Weapon_text, ValidateXML::MonsterList::MonsterRow^ parentMonsterRowByMonster_Weapon) { + ValidateXML::MonsterList::WeaponRow^ rowWeaponRow = (cli::safe_cast(this->NewRow())); + rowWeaponRow->ItemArray = gcnew cli::array< System::Object^ >(4) {Number, Damage, Weapon_text, parentMonsterRowByMonster_Weapon[1]}; + this->Rows->Add(rowWeaponRow); + return rowWeaponRow; + } + + inline System::Collections::IEnumerator^ MonsterList::WeaponDataTable::GetEnumerator() { + return this->Rows->GetEnumerator(); + } + + inline System::Data::DataTable^ MonsterList::WeaponDataTable::Clone() { + ValidateXML::MonsterList::WeaponDataTable^ cln = (cli::safe_cast(__super::Clone())); + cln->InitVars(); + return cln; + } + + inline System::Data::DataTable^ MonsterList::WeaponDataTable::CreateInstance() { + return (gcnew ValidateXML::MonsterList::WeaponDataTable()); + } + + inline System::Void MonsterList::WeaponDataTable::InitVars() { + this->columnNumber = __super::Columns[L"Number"]; + this->columnDamage = __super::Columns[L"Damage"]; + this->columnWeapon_text = __super::Columns[L"Weapon_text"]; + this->columnMonster_Id = __super::Columns[L"Monster_Id"]; + } + + inline System::Void MonsterList::WeaponDataTable::InitClass() { + this->columnNumber = (gcnew System::Data::DataColumn(L"Number", System::Byte::typeid, nullptr, System::Data::MappingType::Attribute)); + __super::Columns->Add(this->columnNumber); + this->columnDamage = (gcnew System::Data::DataColumn(L"Damage", System::String::typeid, nullptr, System::Data::MappingType::Attribute)); + __super::Columns->Add(this->columnDamage); + this->columnWeapon_text = (gcnew System::Data::DataColumn(L"Weapon_text", System::String::typeid, nullptr, System::Data::MappingType::SimpleContent)); + __super::Columns->Add(this->columnWeapon_text); + this->columnMonster_Id = (gcnew System::Data::DataColumn(L"Monster_Id", System::Int32::typeid, nullptr, System::Data::MappingType::Hidden)); + __super::Columns->Add(this->columnMonster_Id); + this->columnNumber->AllowDBNull = false; + this->columnNumber->Namespace = L""; + this->columnDamage->AllowDBNull = false; + this->columnDamage->Namespace = L""; + this->columnWeapon_text->AllowDBNull = false; + } + + inline ValidateXML::MonsterList::WeaponRow^ MonsterList::WeaponDataTable::NewWeaponRow() { + return (cli::safe_cast(this->NewRow())); + } + + inline System::Data::DataRow^ MonsterList::WeaponDataTable::NewRowFromBuilder(System::Data::DataRowBuilder^ builder) { + return (gcnew ValidateXML::MonsterList::WeaponRow(builder)); + } + + inline System::Type^ MonsterList::WeaponDataTable::GetRowType() { + return ValidateXML::MonsterList::WeaponRow::typeid; + } + + inline System::Void MonsterList::WeaponDataTable::OnRowChanged(System::Data::DataRowChangeEventArgs^ e) { + __super::OnRowChanged(e); + { + this->WeaponRowChanged(this, (gcnew ValidateXML::MonsterList::WeaponRowChangeEvent((cli::safe_cast(e->Row)), + e->Action))); + } + } + + inline System::Void MonsterList::WeaponDataTable::OnRowChanging(System::Data::DataRowChangeEventArgs^ e) { + __super::OnRowChanging(e); + { + this->WeaponRowChanging(this, (gcnew ValidateXML::MonsterList::WeaponRowChangeEvent((cli::safe_cast(e->Row)), + e->Action))); + } + } + + inline System::Void MonsterList::WeaponDataTable::OnRowDeleted(System::Data::DataRowChangeEventArgs^ e) { + __super::OnRowDeleted(e); + { + this->WeaponRowDeleted(this, (gcnew ValidateXML::MonsterList::WeaponRowChangeEvent((cli::safe_cast(e->Row)), + e->Action))); + } + } + + inline System::Void MonsterList::WeaponDataTable::OnRowDeleting(System::Data::DataRowChangeEventArgs^ e) { + __super::OnRowDeleting(e); + { + this->WeaponRowDeleting(this, (gcnew ValidateXML::MonsterList::WeaponRowChangeEvent((cli::safe_cast(e->Row)), + e->Action))); + } + } + + inline System::Void MonsterList::WeaponDataTable::RemoveWeaponRow(ValidateXML::MonsterList::WeaponRow^ row) { + this->Rows->Remove(row); + } + + inline System::Xml::Schema::XmlSchemaComplexType^ MonsterList::WeaponDataTable::GetTypedTableSchema(System::Xml::Schema::XmlSchemaSet^ xs) { + System::Xml::Schema::XmlSchemaComplexType^ type = (gcnew System::Xml::Schema::XmlSchemaComplexType()); + System::Xml::Schema::XmlSchemaSequence^ sequence = (gcnew System::Xml::Schema::XmlSchemaSequence()); + ValidateXML::MonsterList^ ds = (gcnew ValidateXML::MonsterList()); + xs->Add(ds->GetSchemaSerializable()); + System::Xml::Schema::XmlSchemaAny^ any1 = (gcnew System::Xml::Schema::XmlSchemaAny()); + any1->Namespace = L"http://www.w3.org/2001/XMLSchema"; + any1->MinOccurs = System::Decimal(0); + any1->MaxOccurs = System::Decimal::MaxValue; + any1->ProcessContents = System::Xml::Schema::XmlSchemaContentProcessing::Lax; + sequence->Items->Add(any1); + System::Xml::Schema::XmlSchemaAny^ any2 = (gcnew System::Xml::Schema::XmlSchemaAny()); + any2->Namespace = L"urn:schemas-microsoft-com:xml-diffgram-v1"; + any2->MinOccurs = System::Decimal(1); + any2->ProcessContents = System::Xml::Schema::XmlSchemaContentProcessing::Lax; + sequence->Items->Add(any2); + System::Xml::Schema::XmlSchemaAttribute^ attribute1 = (gcnew System::Xml::Schema::XmlSchemaAttribute()); + attribute1->Name = L"namespace"; + attribute1->FixedValue = ds->Namespace; + type->Attributes->Add(attribute1); + System::Xml::Schema::XmlSchemaAttribute^ attribute2 = (gcnew System::Xml::Schema::XmlSchemaAttribute()); + attribute2->Name = L"tableTypeName"; + attribute2->FixedValue = L"WeaponDataTable"; + type->Attributes->Add(attribute2); + type->Particle = sequence; + return type; + } + + + inline MonsterList::MonsterRow::MonsterRow(System::Data::DataRowBuilder^ rb) : + System::Data::DataRow(rb) { + this->tableMonster = (cli::safe_cast(this->Table)); + } + + inline System::String^ MonsterList::MonsterRow::Name::get() { + return (cli::safe_cast(this[this->tableMonster->NameColumn])); + } + inline System::Void MonsterList::MonsterRow::Name::set(System::String^ value) { + this[this->tableMonster->NameColumn] = value; + } + + inline System::Int32 MonsterList::MonsterRow::Monster_Id::get() { + return (*cli::safe_cast(this[this->tableMonster->Monster_IdColumn])); + } + inline System::Void MonsterList::MonsterRow::Monster_Id::set(System::Int32 value) { + this[this->tableMonster->Monster_IdColumn] = value; + } + + inline cli::array< ValidateXML::MonsterList::HitDiceRow^ >^ MonsterList::MonsterRow::GetHitDiceRows() { + return (cli::safe_cast^ >(__super::GetChildRows(this->Table->ChildRelations[L"Monster_HitDice"]))); + } + + inline cli::array< ValidateXML::MonsterList::WeaponRow^ >^ MonsterList::MonsterRow::GetWeaponRows() { + return (cli::safe_cast^ >(__super::GetChildRows(this->Table->ChildRelations[L"Monster_Weapon"]))); + } + + + inline MonsterList::HitDiceRow::HitDiceRow(System::Data::DataRowBuilder^ rb) : + System::Data::DataRow(rb) { + this->tableHitDice = (cli::safe_cast(this->Table)); + } + + inline System::String^ MonsterList::HitDiceRow::Dice::get() { + return (cli::safe_cast(this[this->tableHitDice->DiceColumn])); + } + inline System::Void MonsterList::HitDiceRow::Dice::set(System::String^ value) { + this[this->tableHitDice->DiceColumn] = value; + } + + inline System::Byte MonsterList::HitDiceRow::Default::get() { + return (*cli::safe_cast(this[this->tableHitDice->DefaultColumn])); + } + inline System::Void MonsterList::HitDiceRow::Default::set(System::Byte value) { + this[this->tableHitDice->DefaultColumn] = value; + } + + inline System::Int32 MonsterList::HitDiceRow::Monster_Id::get() { + try { + return (*cli::safe_cast(this[this->tableHitDice->Monster_IdColumn])); + } + catch (System::InvalidCastException^ e) { + throw (gcnew System::Data::StrongTypingException(L"The value for column \'Monster_Id\' in table \'HitDice\' is DBNull.", + e)); + } + } + inline System::Void MonsterList::HitDiceRow::Monster_Id::set(System::Int32 value) { + this[this->tableHitDice->Monster_IdColumn] = value; + } + + inline ValidateXML::MonsterList::MonsterRow^ MonsterList::HitDiceRow::MonsterRow::get() { + return (cli::safe_cast(this->GetParentRow(this->Table->ParentRelations[L"Monster_HitDice"]))); + } + inline System::Void MonsterList::HitDiceRow::MonsterRow::set(ValidateXML::MonsterList::MonsterRow^ value) { + this->SetParentRow(value, this->Table->ParentRelations[L"Monster_HitDice"]); + } + + inline System::Boolean MonsterList::HitDiceRow::IsMonster_IdNull() { + return this->IsNull(this->tableHitDice->Monster_IdColumn); + } + + inline System::Void MonsterList::HitDiceRow::SetMonster_IdNull() { + this[this->tableHitDice->Monster_IdColumn] = System::Convert::DBNull; + } + + + inline MonsterList::WeaponRow::WeaponRow(System::Data::DataRowBuilder^ rb) : + System::Data::DataRow(rb) { + this->tableWeapon = (cli::safe_cast(this->Table)); + } + + inline System::Byte MonsterList::WeaponRow::Number::get() { + return (*cli::safe_cast(this[this->tableWeapon->NumberColumn])); + } + inline System::Void MonsterList::WeaponRow::Number::set(System::Byte value) { + this[this->tableWeapon->NumberColumn] = value; + } + + inline System::String^ MonsterList::WeaponRow::Damage::get() { + return (cli::safe_cast(this[this->tableWeapon->DamageColumn])); + } + inline System::Void MonsterList::WeaponRow::Damage::set(System::String^ value) { + this[this->tableWeapon->DamageColumn] = value; + } + + inline System::String^ MonsterList::WeaponRow::Weapon_text::get() { + return (cli::safe_cast(this[this->tableWeapon->Weapon_textColumn])); + } + inline System::Void MonsterList::WeaponRow::Weapon_text::set(System::String^ value) { + this[this->tableWeapon->Weapon_textColumn] = value; + } + + inline System::Int32 MonsterList::WeaponRow::Monster_Id::get() { + try { + return (*cli::safe_cast(this[this->tableWeapon->Monster_IdColumn])); + } + catch (System::InvalidCastException^ e) { + throw (gcnew System::Data::StrongTypingException(L"The value for column \'Monster_Id\' in table \'Weapon\' is DBNull.", + e)); + } + } + inline System::Void MonsterList::WeaponRow::Monster_Id::set(System::Int32 value) { + this[this->tableWeapon->Monster_IdColumn] = value; + } + + inline ValidateXML::MonsterList::MonsterRow^ MonsterList::WeaponRow::MonsterRow::get() { + return (cli::safe_cast(this->GetParentRow(this->Table->ParentRelations[L"Monster_Weapon"]))); + } + inline System::Void MonsterList::WeaponRow::MonsterRow::set(ValidateXML::MonsterList::MonsterRow^ value) { + this->SetParentRow(value, this->Table->ParentRelations[L"Monster_Weapon"]); + } + + inline System::Boolean MonsterList::WeaponRow::IsMonster_IdNull() { + return this->IsNull(this->tableWeapon->Monster_IdColumn); + } + + inline System::Void MonsterList::WeaponRow::SetMonster_IdNull() { + this[this->tableWeapon->Monster_IdColumn] = System::Convert::DBNull; + } + + + inline MonsterList::MonsterRowChangeEvent::MonsterRowChangeEvent(ValidateXML::MonsterList::MonsterRow^ row, System::Data::DataRowAction action) { + this->eventRow = row; + this->eventAction = action; + } + + inline ValidateXML::MonsterList::MonsterRow^ MonsterList::MonsterRowChangeEvent::Row::get() { + return this->eventRow; + } + + inline System::Data::DataRowAction MonsterList::MonsterRowChangeEvent::Action::get() { + return this->eventAction; + } + + + inline MonsterList::HitDiceRowChangeEvent::HitDiceRowChangeEvent(ValidateXML::MonsterList::HitDiceRow^ row, System::Data::DataRowAction action) { + this->eventRow = row; + this->eventAction = action; + } + + inline ValidateXML::MonsterList::HitDiceRow^ MonsterList::HitDiceRowChangeEvent::Row::get() { + return this->eventRow; + } + + inline System::Data::DataRowAction MonsterList::HitDiceRowChangeEvent::Action::get() { + return this->eventAction; + } + + + inline MonsterList::WeaponRowChangeEvent::WeaponRowChangeEvent(ValidateXML::MonsterList::WeaponRow^ row, System::Data::DataRowAction action) { + this->eventRow = row; + this->eventAction = action; + } + + inline ValidateXML::MonsterList::WeaponRow^ MonsterList::WeaponRowChangeEvent::Row::get() { + return this->eventRow; + } + + inline System::Data::DataRowAction MonsterList::WeaponRowChangeEvent::Action::get() { + return this->eventAction; + } +} diff --git a/Chapter13/ValidateXML/Monsters.xml b/Chapter13/ValidateXML/Monsters.xml new file mode 100644 index 0000000..f9b8a2b --- /dev/null +++ b/Chapter13/ValidateXML/Monsters.xml @@ -0,0 +1,12 @@ + + + + + + + Goblin + Dagger + + + + \ No newline at end of file diff --git a/Chapter13/ValidateXML/Monsters.xsd b/Chapter13/ValidateXML/Monsters.xsd new file mode 100644 index 0000000..402b88e --- /dev/null +++ b/Chapter13/ValidateXML/Monsters.xsd @@ -0,0 +1,32 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Chapter13/ValidateXML/Monsters.xsx b/Chapter13/ValidateXML/Monsters.xsx new file mode 100644 index 0000000..b3fd871 --- /dev/null +++ b/Chapter13/ValidateXML/Monsters.xsx @@ -0,0 +1,10 @@ + + + + + + + + + + \ No newline at end of file diff --git a/Chapter13/ValidateXML/ValidateXML.cpp b/Chapter13/ValidateXML/ValidateXML.cpp new file mode 100644 index 0000000..7d59463 --- /dev/null +++ b/Chapter13/ValidateXML/ValidateXML.cpp @@ -0,0 +1,50 @@ +using namespace System; +using namespace System::Xml; +using namespace System::Xml::Schema; + +ref class ValidateXML +{ +public: + ValidateXML(String ^filename) + { + XmlReader ^vreader; + try + { + XmlReaderSettings ^settings = gcnew XmlReaderSettings(); + settings->ProhibitDtd = false; + settings->ValidationType = ValidationType::DTD; + settings->ValidationEventHandler += + gcnew ValidationEventHandler(this, + &ValidateXML::ValidationHandler); + + vreader = XmlReader::Create("Monsters.xml", settings); + + while(vreader->Read()) + { + // ... Process nodes just like XmlTextReader() + } + Console::WriteLine("Finished Processing"); + } + catch (Exception ^e) + { + Console::WriteLine(e->Message); + } + finally + { + if (vreader->ReadState != ReadState::Closed) + { + vreader->Close(); + } + } + } + + void ValidationHandler(Object ^sender, ValidationEventArgs ^e) + { + Console::WriteLine(e->Message); + } +}; + +void main() +{ + gcnew ValidateXML("Monsters.xml"); +} \ No newline at end of file diff --git a/Chapter13/ValidateXML/ValidateXML.vcproj b/Chapter13/ValidateXML/ValidateXML.vcproj new file mode 100644 index 0000000..e9a8823 --- /dev/null +++ b/Chapter13/ValidateXML/ValidateXML.vcproj @@ -0,0 +1,215 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Chapter13/WriteXML/Goblin.xml b/Chapter13/WriteXML/Goblin.xml new file mode 100644 index 0000000..07c80ed --- /dev/null +++ b/Chapter13/WriteXML/Goblin.xml @@ -0,0 +1,13 @@ + + + + + Goblin + + Dagger + + \ No newline at end of file diff --git a/Chapter13/WriteXML/WriteXML.cpp b/Chapter13/WriteXML/WriteXML.cpp new file mode 100644 index 0000000..2a6af70 --- /dev/null +++ b/Chapter13/WriteXML/WriteXML.cpp @@ -0,0 +1,57 @@ +using namespace System; +using namespace System::Xml; + +void main() +{ + XmlWriter ^writer; + try + { + XmlWriterSettings ^settings = gcnew XmlWriterSettings(); + settings->Indent = true; + settings->IndentChars = (" "); + settings->NewLineOnAttributes = true; + + writer = XmlWriter::Create("Goblin.xml", settings); + + writer->WriteStartDocument(); + + writer->WriteStartElement("MonsterList"); + + writer->WriteComment("Program Generated Easy Monster"); + writer->WriteStartElement("Monster"); + + writer->WriteStartElement("Name"); + writer->WriteString("Goblin"); + writer->WriteEndElement(); + + writer->WriteStartElement("HitDice"); + writer->WriteAttributeString("Dice", "1d8"); + writer->WriteAttributeString("Default", "4"); + writer->WriteEndElement(); + + writer->WriteStartElement("Weapon"); + writer->WriteAttributeString("Number", "1"); + writer->WriteAttributeString("Damage", "1d4"); + writer->WriteString("Dagger"); + writer->WriteEndElement(); + + // The folling not needed with WriteEndDocument + // writer->WriteEndElement(); + // writer->WriteEndElement(); + + writer->WriteEndDocument(); + + writer->Flush(); + } + catch (Exception ^e) + { + Console::WriteLine("XML Writer Aborted -- {0}", e->Message); + } + finally + { + if (writer->WriteState != WriteState::Closed) + { + writer->Close(); + } + } +} \ No newline at end of file diff --git a/Chapter13/WriteXML/WriteXML.vcproj b/Chapter13/WriteXML/WriteXML.vcproj new file mode 100644 index 0000000..feb82c2 --- /dev/null +++ b/Chapter13/WriteXML/WriteXML.vcproj @@ -0,0 +1,203 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Chapter13/WriteXMLDOM/Monsters.xml b/Chapter13/WriteXMLDOM/Monsters.xml new file mode 100644 index 0000000..6cfe12e --- /dev/null +++ b/Chapter13/WriteXMLDOM/Monsters.xml @@ -0,0 +1,25 @@ + + + + + + Goblin + + Dagger + + + + Succubus + + Claw + Dagger + + + + Red Dragon + + Bite + Claw + Wing + + \ No newline at end of file diff --git a/Chapter13/WriteXMLDOM/New_Monsters.xml b/Chapter13/WriteXMLDOM/New_Monsters.xml new file mode 100644 index 0000000..ca990fe --- /dev/null +++ b/Chapter13/WriteXMLDOM/New_Monsters.xml @@ -0,0 +1,30 @@ + + + + + + Goblin + + Dagger + + + Skeleton + + Claw + + + + Succubus + + Claw + Dagger + + + + Red Dragon + + Bite + Claw + Wing + + \ No newline at end of file diff --git a/Chapter13/WriteXMLDOM/WriteXMLDOM.cpp b/Chapter13/WriteXMLDOM/WriteXMLDOM.cpp new file mode 100644 index 0000000..d26bcce --- /dev/null +++ b/Chapter13/WriteXMLDOM/WriteXMLDOM.cpp @@ -0,0 +1,58 @@ +using namespace System; +using namespace System::Xml; + +XmlElement ^CreateMonster(XmlDocument ^doc) +{ + XmlElement ^skeleton = doc->CreateElement("Monster"); + + // Skeleton + XmlElement ^name = doc->CreateElement("Name"); + name->AppendChild(doc->CreateTextNode("Skeleton")); + skeleton->AppendChild(name); + + // + XmlElement ^hitdice = doc->CreateElement("HitDice"); + XmlAttribute ^att = doc->CreateAttribute("Dice"); + att->Value = "1/2 d12"; + hitdice->Attributes->Append(att); + att = doc->CreateAttribute("Default"); + att->Value = "3"; + hitdice->Attributes->Append(att); + skeleton->AppendChild(hitdice); + + // Claw + XmlElement ^weapon = doc->CreateElement("Weapon"); + att = doc->CreateAttribute("Number"); + att->Value = "2"; + weapon->Attributes->Append(att); + att = doc->CreateAttribute("Damage"); + att->Value = "1d3-1"; + weapon->Attributes->Append(att); + weapon->AppendChild(doc->CreateTextNode("Claw")); + skeleton->AppendChild(weapon); + + return skeleton; +} + +void main() +{ + XmlDocument ^doc = gcnew XmlDocument(); + + try + { + doc->Load("Monsters.xml"); + XmlNode ^root = doc->DocumentElement; + + // Skip comment and goblin + XmlNode ^child = root->FirstChild->NextSibling; + + // Insert new monster + root->InsertAfter(CreateMonster(doc), child); + + doc->Save("New_Monsters.xml"); + } + catch (Exception ^e) + { + Console::WriteLine("Error Occurred: {0}", e->Message ); + } +} diff --git a/Chapter13/WriteXMLDOM/WriteXMLDOM.vcproj b/Chapter13/WriteXMLDOM/WriteXMLDOM.vcproj new file mode 100644 index 0000000..205e687 --- /dev/null +++ b/Chapter13/WriteXMLDOM/WriteXMLDOM.vcproj @@ -0,0 +1,207 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Chapter13/XPathEx/Monsters.xml b/Chapter13/XPathEx/Monsters.xml new file mode 100644 index 0000000..f7568a5 --- /dev/null +++ b/Chapter13/XPathEx/Monsters.xml @@ -0,0 +1,25 @@ + + + + + + Goblin + + Dagger + + + + Succubus + + Claw + Dagger + + + + Red Dragon + + Bite + Claw + Wing + + \ No newline at end of file diff --git a/Chapter13/XPathEx/XPathEx.cpp b/Chapter13/XPathEx/XPathEx.cpp new file mode 100644 index 0000000..85422de --- /dev/null +++ b/Chapter13/XPathEx/XPathEx.cpp @@ -0,0 +1,93 @@ +using namespace System; +using namespace System::Xml; +using namespace System::Xml::XPath; +using namespace System::Collections; + +void GetMonsters(XPathNavigator ^nav) +{ + XPathNodeIterator ^list = + nav->Select("/MonsterList/Monster/Name"); + + Console::WriteLine("Monsters\n--------"); + while (list->MoveNext()) + { + XPathNavigator ^n = list->Current; + Console::WriteLine(n->Value); + } + +// The required code to do the same as above if no +// XPathNavigator concatenation occurred. +/* + list = nav->Select("/MonsterList/Monster/Name"); + + Console::WriteLine("Monsters\n--------"); + while (list->MoveNext()) + { + XPathNavigator ^n = list->Current; + n->MoveToFirstChild(); + Console::WriteLine(n->Value); + } +*/ +} + +void GetDragonsWeapons(XmlNode ^node) +{ + XmlNodeList ^list = + node->SelectNodes("//Monster[Name='Red Dragon']/Weapon"); + + Console::WriteLine("\nDragon's Weapons\n----------------"); + + IEnumerator ^en = list->GetEnumerator(); + while (en->MoveNext()) + { + XmlNode ^n = (XmlNode^)en->Current; + Console::WriteLine(n->FirstChild->Value); + } +} + +void GetGoblinSuccubusHitDice(XPathNavigator ^nav) +{ + XPathNodeIterator ^list = + nav->Select("//Monster[Name='Goblin' or Name='Succubus']/HitDice/@Dice"); + + Console::WriteLine("\nGoblin & Succubus HD\n--------------------"); + while (list->MoveNext()) + { + XPathNavigator ^n = list->Current; + Console::WriteLine(n->Value); + } +} + +void GetSingleAttackWeapons(XPathNavigator ^nav) +{ + XPathNodeIterator ^list = + nav->Select("//Weapon[@Number <= 1]"); + + Console::WriteLine("\nSingle Attack Weapons\n---------------------"); + while (list->MoveNext()) + { + XPathNavigator ^n = list->Current; + Console::WriteLine(n->Value); + } +} + +void main() +{ + XmlDocument ^doc = gcnew XmlDocument(); + + try + { + doc->Load("Monsters.xml"); + XPathNavigator ^nav = doc->CreateNavigator(); + nav->MoveToRoot(); + + GetMonsters(nav); + GetDragonsWeapons(doc->DocumentElement); + GetGoblinSuccubusHitDice(nav); + GetSingleAttackWeapons(nav); + } + catch (Exception ^e) + { + Console::WriteLine("Error Occurred: {0}", e->Message ); + } +} \ No newline at end of file diff --git a/Chapter13/XPathEx/XPathEx.vcproj b/Chapter13/XPathEx/XPathEx.vcproj new file mode 100644 index 0000000..3da5fca --- /dev/null +++ b/Chapter13/XPathEx/XPathEx.vcproj @@ -0,0 +1,203 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Chapter14/Chapter14.sln b/Chapter14/Chapter14.sln new file mode 100644 index 0000000..f9f264e --- /dev/null +++ b/Chapter14/Chapter14.sln @@ -0,0 +1,26 @@ + +Microsoft Visual Studio Solution File, Format Version 9.00 +# Visual Studio 2005 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Simple", "Simple\Simple.vcproj", "{1DEB33AB-BB5B-4A30-8EAA-4B960DAA3465}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "SimpleCtrl", "SimpleCtrl\SimpleCtrl.vcproj", "{A386B412-F376-41A3-AF34-0FBB3982C188}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Win32 = Debug|Win32 + Release|Win32 = Release|Win32 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {1DEB33AB-BB5B-4A30-8EAA-4B960DAA3465}.Debug|Win32.ActiveCfg = Debug|Win32 + {1DEB33AB-BB5B-4A30-8EAA-4B960DAA3465}.Debug|Win32.Build.0 = Debug|Win32 + {1DEB33AB-BB5B-4A30-8EAA-4B960DAA3465}.Release|Win32.ActiveCfg = Release|Win32 + {1DEB33AB-BB5B-4A30-8EAA-4B960DAA3465}.Release|Win32.Build.0 = Release|Win32 + {A386B412-F376-41A3-AF34-0FBB3982C188}.Debug|Win32.ActiveCfg = Debug|Win32 + {A386B412-F376-41A3-AF34-0FBB3982C188}.Debug|Win32.Build.0 = Debug|Win32 + {A386B412-F376-41A3-AF34-0FBB3982C188}.Release|Win32.ActiveCfg = Release|Win32 + {A386B412-F376-41A3-AF34-0FBB3982C188}.Release|Win32.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/Chapter14/Chapter14.suo b/Chapter14/Chapter14.suo new file mode 100644 index 0000000..8696626 Binary files /dev/null and b/Chapter14/Chapter14.suo differ diff --git a/Chapter14/Simple/AssemblyInfo.cpp b/Chapter14/Simple/AssemblyInfo.cpp new file mode 100644 index 0000000..c1849bf --- /dev/null +++ b/Chapter14/Simple/AssemblyInfo.cpp @@ -0,0 +1,35 @@ +#include "stdafx.h" + +using namespace System::Reflection; +using namespace System::Runtime::CompilerServices; +using namespace System::Runtime::InteropServices; + +// +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +// +[assembly:AssemblyTitleAttribute("Simple")]; +[assembly:AssemblyDescriptionAttribute("")]; +[assembly:AssemblyConfigurationAttribute("")]; +[assembly:AssemblyCompanyAttribute("")]; +[assembly:AssemblyProductAttribute("Simple")]; +[assembly:AssemblyCopyrightAttribute("Copyright (c) 2005")]; +[assembly:AssemblyTrademarkAttribute("")]; +[assembly:AssemblyCultureAttribute("")]; + +// +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the value or you can default the Revision and Build Numbers +// by using the '*' as shown below: + +[assembly:AssemblyVersionAttribute("1.0.*")]; + +[assembly:ComVisible(false)]; + diff --git a/Chapter14/Simple/ProjectInstaller.cpp b/Chapter14/Simple/ProjectInstaller.cpp new file mode 100644 index 0000000..b1d5754 --- /dev/null +++ b/Chapter14/Simple/ProjectInstaller.cpp @@ -0,0 +1,2 @@ +#include "StdAfx.h" +#include "ProjectInstaller.h" diff --git a/Chapter14/Simple/ProjectInstaller.h b/Chapter14/Simple/ProjectInstaller.h new file mode 100644 index 0000000..0177941 --- /dev/null +++ b/Chapter14/Simple/ProjectInstaller.h @@ -0,0 +1,70 @@ +#pragma once + +using namespace System; +using namespace System::ComponentModel; +using namespace System::Collections; +using namespace System::Configuration::Install; + + +namespace Simple +{ + [RunInstaller(true)] + public ref class ProjectInstaller : public System::Configuration::Install::Installer + { + public: + ProjectInstaller(void) + { + InitializeComponent(); + } + + protected: + ~ProjectInstaller() + { + if (components) + { + delete components; + } + } + private: + System::ServiceProcess::ServiceProcessInstaller^ serviceProcessInstaller1; + System::ServiceProcess::ServiceInstaller^ serviceInstaller1; + System::Diagnostics::EventLogInstaller^ eventLogInstaller1; + + System::ComponentModel::Container ^components; + +#pragma region Windows Form Designer generated code + + void InitializeComponent(void) + { + this->serviceProcessInstaller1 = (gcnew System::ServiceProcess::ServiceProcessInstaller()); + this->serviceInstaller1 = (gcnew System::ServiceProcess::ServiceInstaller()); + this->eventLogInstaller1 = (gcnew System::Diagnostics::EventLogInstaller()); + // + // serviceProcessInstaller1 + // + this->serviceProcessInstaller1->Account = System::ServiceProcess::ServiceAccount::LocalSystem; + this->serviceProcessInstaller1->Password = nullptr; + this->serviceProcessInstaller1->Username = nullptr; + // + // serviceInstaller1 + // + this->serviceInstaller1->ServiceName = L"SimpleWinService"; + // + // eventLogInstaller1 + // + this->eventLogInstaller1->CategoryCount = 0; + this->eventLogInstaller1->CategoryResourceFile = nullptr; + this->eventLogInstaller1->Log = L"Application"; + this->eventLogInstaller1->MessageResourceFile = nullptr; + this->eventLogInstaller1->ParameterResourceFile = nullptr; + this->eventLogInstaller1->Source = L"SimpleWinService"; + // + // ProjectInstaller + // + this->Installers->AddRange(gcnew cli::array< System::Configuration::Install::Installer^ >(3) {this->serviceProcessInstaller1, + this->serviceInstaller1, this->eventLogInstaller1}); + + } +#pragma endregion + }; +} diff --git a/Chapter14/Simple/ProjectInstaller.resx b/Chapter14/Simple/ProjectInstaller.resx new file mode 100644 index 0000000..40f2a64 --- /dev/null +++ b/Chapter14/Simple/ProjectInstaller.resx @@ -0,0 +1,132 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 17, 54 + + + 187, 17 + + + 187, 54 + + + False + + \ No newline at end of file diff --git a/Chapter14/Simple/Simple.vcproj b/Chapter14/Simple/Simple.vcproj new file mode 100644 index 0000000..79acb78 --- /dev/null +++ b/Chapter14/Simple/Simple.vcproj @@ -0,0 +1,265 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Chapter14/Simple/SimpleWinService.cpp b/Chapter14/Simple/SimpleWinService.cpp new file mode 100644 index 0000000..48c1d18 --- /dev/null +++ b/Chapter14/Simple/SimpleWinService.cpp @@ -0,0 +1,78 @@ +// Simple.cpp : main Windows Service project file. + +#include "stdafx.h" +//#include +#include "SimpleWinService.h" + +using namespace Simple; +using namespace System::Collections; +using namespace System::ServiceProcess; +//using namespace System::Text; +//using namespace System::Security::Policy; +//using namespace System::Reflection; + +void main() +{ +#ifndef COMMANDLINE_DEBUG + + array^ ServicesToRun; + + // More than one user Service may run within the same process. To add + // another service to this process, change the following line to + // create a second service object. For example, + // + // ServicesToRun = gcnew array + // { + // gcnew Service1(), + // gcnew Service2() + // }; + // + ServicesToRun = gcnew array { gcnew SimpleWinService() }; + ServiceBase::Run(ServicesToRun); + +#else + + SimpleWinService ^svc = gcnew SimpleWinService(); + svc->OnStart(nullptr); + Console::WriteLine("Any key stop stop"); + Console::ReadLine(); + svc->OnStop(); + +#endif +} + + +//To install/uninstall the service, type: "Simple.exe -Install [-u]" +//int _tmain(int argc, _TCHAR* argv[]) +//{ +// if (argc >= 2) +// { +// if (argv[1][0] == _T('/')) +// { +// argv[1][0] = _T('-'); +// } +// +// if (_tcsicmp(argv[1], _T("-Install")) == 0) +// { +// array^ myargs = System::Environment::GetCommandLineArgs(); +// array^ args = gcnew array(myargs->Length - 1); +// +// // Set args[0] with the full path to the assembly, +// Assembly^ assem = Assembly::GetExecutingAssembly(); +// args[0] = assem->Location; +// +// Array::Copy(myargs, 2, args, 1, args->Length - 1); +// AppDomain^ dom = AppDomain::CreateDomain(L"execDom"); +// Type^ type = System::Object::typeid; +// String^ path = type->Assembly->Location; +// StringBuilder^ sb = gcnew StringBuilder(path->Substring(0, path->LastIndexOf(L"\\"))); +// sb->Append(L"\\InstallUtil.exe"); +// Evidence^ evidence = gcnew Evidence(); +// dom->ExecuteAssembly(sb->ToString(), evidence, args); +// } +// } +// else +// { +// ServiceBase::Run(gcnew SimpleWinService()); +// } +//} diff --git a/Chapter14/Simple/SimpleWinService.h b/Chapter14/Simple/SimpleWinService.h new file mode 100644 index 0000000..1d5501a --- /dev/null +++ b/Chapter14/Simple/SimpleWinService.h @@ -0,0 +1,117 @@ +#pragma once + +using namespace System; +using namespace System::Collections; +using namespace System::ServiceProcess; +using namespace System::ComponentModel; + + +namespace Simple +{ + public ref class SimpleWinService : public System::ServiceProcess::ServiceBase + { + private: + double interval; + + public: + SimpleWinService() + { + InitializeComponent(); + interval = 15000; // 15 seconds - default + } + protected: + ~SimpleWinService() + { + if (components) + { + delete components; + } + } + +#ifdef COMMANDLINE_DEBUG + public: +#endif + virtual void OnStart(array^ args) override + { + eventLog1->WriteEntry("SimpleWinService Started"); + + if (args == nullptr || args->Length == 0) + eventLog1->WriteEntry("Empty args"); + else + { + for each (String ^s in args) + { + eventLog1->WriteEntry(s); + } + } + + this->timer = gcnew System::Timers::Timer(interval); + this->timer->Elapsed += + gcnew System::Timers::ElapsedEventHandler(this, + &SimpleWinService::timer_Tick); + this->timer->Start(); + } + + virtual void OnStop() override + { + this->timer->Stop(); + eventLog1->WriteEntry("SimpleWinService Stopped"); + } + + virtual void OnPause() override + { + this->timer->Stop(); + eventLog1->WriteEntry("SimpleWinService Paused"); + } + + virtual void OnContinue() override + { + eventLog1->WriteEntry("SimpleWinService Continued"); + this->timer->Start(); + } + + virtual void OnCustomCommand(int cmd) override + { + if (cmd == 150) + this->timer->Interval = 15000; + else + this->timer->Interval = 20000; + } + + private: + System::Diagnostics::EventLog^ eventLog1; + System::Timers::Timer^ timer; + + System::ComponentModel::Container ^components; + +#pragma region Windows Form Designer generated code + + void InitializeComponent(void) + { + this->eventLog1 = (gcnew System::Diagnostics::EventLog()); + (cli::safe_cast(this->eventLog1))->BeginInit(); + // + // eventLog1 + // + this->eventLog1->Log = L"Application"; + this->eventLog1->Source = L"SimpleWinService"; + // + // SimpleWinService + // + this->CanPauseAndContinue = true; + this->ServiceName = L"SimpleWinService"; + (cli::safe_cast(this->eventLog1))->EndInit(); + } + +#pragma endregion + + private: + void timer_Tick(System::Object^ sender, + System::Timers::ElapsedEventArgs^ e) + { + this->timer->Stop(); + eventLog1->WriteEntry("SimpleWinService Elapsed Event Occurred"); + this->timer->Start(); + } + }; +} diff --git a/Chapter14/Simple/SimpleWinService.resx b/Chapter14/Simple/SimpleWinService.resx new file mode 100644 index 0000000..10aaa1b --- /dev/null +++ b/Chapter14/Simple/SimpleWinService.resx @@ -0,0 +1,126 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 17, 17 + + + False + + \ No newline at end of file diff --git a/Chapter14/Simple/stdafx.cpp b/Chapter14/Simple/stdafx.cpp new file mode 100644 index 0000000..9e5e4c6 --- /dev/null +++ b/Chapter14/Simple/stdafx.cpp @@ -0,0 +1,5 @@ +// stdafx.cpp : source file that includes just the standard includes +// Simple.pch will be the pre-compiled header +// stdafx.obj will contain the pre-compiled type information + +#include "stdafx.h" \ No newline at end of file diff --git a/Chapter14/Simple/stdafx.h b/Chapter14/Simple/stdafx.h new file mode 100644 index 0000000..47964b1 --- /dev/null +++ b/Chapter14/Simple/stdafx.h @@ -0,0 +1,7 @@ +// stdafx.h : include file for standard system include files, +// or project specific include files that are used frequently, but +// are changed infrequently +#pragma once + +// TODO: reference additional headers your program requires here + diff --git a/Chapter14/SimpleCtrl/AssemblyInfo.cpp b/Chapter14/SimpleCtrl/AssemblyInfo.cpp new file mode 100644 index 0000000..91887b2 --- /dev/null +++ b/Chapter14/SimpleCtrl/AssemblyInfo.cpp @@ -0,0 +1,35 @@ +#include "stdafx.h" + +using namespace System::Reflection; +using namespace System::Runtime::CompilerServices; +using namespace System::Runtime::InteropServices; + +// +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +// +[assembly:AssemblyTitleAttribute("SimpleCtrl")]; +[assembly:AssemblyDescriptionAttribute("")]; +[assembly:AssemblyConfigurationAttribute("")]; +[assembly:AssemblyCompanyAttribute("")]; +[assembly:AssemblyProductAttribute("SimpleCtrl")]; +[assembly:AssemblyCopyrightAttribute("Copyright (c) 2005")]; +[assembly:AssemblyTrademarkAttribute("")]; +[assembly:AssemblyCultureAttribute("")]; + +// +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the value or you can default the Revision and Build Numbers +// by using the '*' as shown below: + +[assembly:AssemblyVersionAttribute("1.0.*")]; + +[assembly:ComVisible(false)]; + diff --git a/Chapter14/SimpleCtrl/Form1.h b/Chapter14/SimpleCtrl/Form1.h new file mode 100644 index 0000000..810d386 --- /dev/null +++ b/Chapter14/SimpleCtrl/Form1.h @@ -0,0 +1,170 @@ +#pragma once + + +namespace SimpleCtrl +{ + using namespace System; + using namespace System::ComponentModel; + using namespace System::Collections; + using namespace System::Windows::Forms; + using namespace System::Data; + using namespace System::Drawing; + using namespace System::ServiceProcess; + + public ref class Form1 : public System::Windows::Forms::Form + { + public: + Form1(void) + { + InitializeComponent(); + } + + protected: + ~Form1() + { + if (components) + { + delete components; + } + } + + private: + System::ServiceProcess::ServiceController^ serviceController1; + System::Windows::Forms::Button^ bnIntv20; + System::Windows::Forms::Button^ bnIntv15; + System::Windows::Forms::Button^ bnStop; + System::Windows::Forms::Button^ bnStart; + + System::ComponentModel::Container ^components; + +#pragma region Windows Form Designer generated code + + void InitializeComponent(void) + { + this->serviceController1 = (gcnew System::ServiceProcess::ServiceController()); + this->bnIntv20 = (gcnew System::Windows::Forms::Button()); + this->bnIntv15 = (gcnew System::Windows::Forms::Button()); + this->bnStop = (gcnew System::Windows::Forms::Button()); + this->bnStart = (gcnew System::Windows::Forms::Button()); + this->SuspendLayout(); + // + // serviceController1 + // + this->serviceController1->MachineName = L"amidala"; + this->serviceController1->ServiceName = L"SimpleWinService"; + // + // bnIntv20 + // + this->bnIntv20->Location = System::Drawing::Point(150, 44); + this->bnIntv20->Name = L"bnIntv20"; + this->bnIntv20->Size = System::Drawing::Size(75, 23); + this->bnIntv20->TabIndex = 6; + this->bnIntv20->Text = L"Interval 20"; + this->bnIntv20->Click += gcnew System::EventHandler(this, &Form1::bnIntv20_Click); + // + // bnIntv15 + // + this->bnIntv15->Location = System::Drawing::Point(150, 15); + this->bnIntv15->Name = L"bnIntv15"; + this->bnIntv15->Size = System::Drawing::Size(75, 23); + this->bnIntv15->TabIndex = 5; + this->bnIntv15->Text = L"Interval 15"; + this->bnIntv15->Click += gcnew System::EventHandler(this, &Form1::bnIntv15_Click); + // + // bnStop + // + this->bnStop->Location = System::Drawing::Point(32, 44); + this->bnStop->Name = L"bnStop"; + this->bnStop->Size = System::Drawing::Size(75, 23); + this->bnStop->TabIndex = 7; + this->bnStop->Text = L"Stop"; + this->bnStop->Click += gcnew System::EventHandler(this, &Form1::bnStop_Click); + // + // bnStart + // + this->bnStart->Location = System::Drawing::Point(32, 15); + this->bnStart->Name = L"bnStart"; + this->bnStart->Size = System::Drawing::Size(75, 23); + this->bnStart->TabIndex = 4; + this->bnStart->Text = L"Start"; + this->bnStart->Click += gcnew System::EventHandler(this, &Form1::bnStart_Click); + // + // Form1 + // + this->AutoScaleDimensions = System::Drawing::SizeF(6, 13); + this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font; + this->ClientSize = System::Drawing::Size(256, 83); + this->Controls->Add(this->bnIntv20); + this->Controls->Add(this->bnIntv15); + this->Controls->Add(this->bnStop); + this->Controls->Add(this->bnStart); + this->Name = L"Form1"; + this->Text = L"SimpleWinService Controller"; + this->ResumeLayout(false); + + } +#pragma endregion + + private: + System::Void bnStart_Click(System::Object^ sender, System::EventArgs^ e) + { + serviceController1->Refresh(); + + if (serviceController1->Status == ServiceControllerStatus::Stopped) + { + serviceController1->Start(); + MessageBox::Show("SimpleWinService Started"); + } + else + { + MessageBox::Show("SimpleWinService Running"); + } + } + + System::Void bnStop_Click(System::Object^ sender, System::EventArgs^ e) + { + serviceController1->Refresh(); + + if (serviceController1->Status == ServiceControllerStatus::Running) + { + serviceController1->Stop(); + MessageBox::Show("SimpleWinService Stopped"); + } + else + { + MessageBox::Show("SimpleWinService Not Running"); + } + } + + System::Void bnIntv15_Click(System::Object^ sender, System::EventArgs^ e) + { + serviceController1->Refresh(); + + if (serviceController1->Status == ServiceControllerStatus::Running) + { + serviceController1->ExecuteCommand(150); + MessageBox::Show("SimpleWinService Interval in 15 seconds"); + } + else + { + MessageBox::Show("SimpleWinService Not Running"); + } + } + + System::Void bnIntv20_Click(System::Object^ sender, System::EventArgs^ e) + { + serviceController1->Refresh(); + + if (serviceController1->Status == ServiceControllerStatus::Running) + { + serviceController1->ExecuteCommand(200); + MessageBox::Show("SimpleWinService Interval in 20 seconds"); + } + else + { + MessageBox::Show("SimpleWinService Not Running"); + } + } + }; +} + diff --git a/Chapter14/SimpleCtrl/Form1.resx b/Chapter14/SimpleCtrl/Form1.resx new file mode 100644 index 0000000..38ccc8d --- /dev/null +++ b/Chapter14/SimpleCtrl/Form1.resx @@ -0,0 +1,123 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 17, 17 + + \ No newline at end of file diff --git a/Chapter14/SimpleCtrl/SimpleCtrl.cpp b/Chapter14/SimpleCtrl/SimpleCtrl.cpp new file mode 100644 index 0000000..cbd7986 --- /dev/null +++ b/Chapter14/SimpleCtrl/SimpleCtrl.cpp @@ -0,0 +1,16 @@ +// SimpleCtrl.cpp : main project file. + +#include "stdafx.h" +#include "Form1.h" + +using namespace SimpleCtrl; + +[STAThreadAttribute] +int main(array ^args) +{ + // Enabling Windows XP visual effects before any controls are created + Application::EnableVisualStyles(); + // Create the main window and run it + Application::Run(gcnew Form1()); + return 0; +} diff --git a/Chapter14/SimpleCtrl/SimpleCtrl.vcproj b/Chapter14/SimpleCtrl/SimpleCtrl.vcproj new file mode 100644 index 0000000..a3b4f1b --- /dev/null +++ b/Chapter14/SimpleCtrl/SimpleCtrl.vcproj @@ -0,0 +1,254 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Chapter14/SimpleCtrl/stdafx.cpp b/Chapter14/SimpleCtrl/stdafx.cpp new file mode 100644 index 0000000..b139169 --- /dev/null +++ b/Chapter14/SimpleCtrl/stdafx.cpp @@ -0,0 +1,7 @@ +// stdafx.cpp : source file that includes just the standard includes +// SimpleCtrl.pch will be the pre-compiled header +// stdafx.obj will contain the pre-compiled type information + +#include "stdafx.h" + + diff --git a/Chapter14/SimpleCtrl/stdafx.h b/Chapter14/SimpleCtrl/stdafx.h new file mode 100644 index 0000000..46bef73 --- /dev/null +++ b/Chapter14/SimpleCtrl/stdafx.h @@ -0,0 +1,6 @@ +// stdafx.h : include file for standard system include files, +// or project specific include files that are used frequently, but +// are changed infrequently +#pragma once + +// TODO: reference additional headers your program requires here diff --git a/Chapter15/AuthorWS/AssemblyInfo.cpp b/Chapter15/AuthorWS/AssemblyInfo.cpp new file mode 100644 index 0000000..40fb432 --- /dev/null +++ b/Chapter15/AuthorWS/AssemblyInfo.cpp @@ -0,0 +1,35 @@ +#include "stdafx.h" + +using namespace System::Reflection; +using namespace System::Runtime::CompilerServices; +using namespace System::Runtime::InteropServices; + +// +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +// +[assembly:AssemblyTitleAttribute("AuthorWS")]; +[assembly:AssemblyDescriptionAttribute("")]; +[assembly:AssemblyConfigurationAttribute("")]; +[assembly:AssemblyCompanyAttribute("")]; +[assembly:AssemblyProductAttribute("AuthorWS")]; +[assembly:AssemblyCopyrightAttribute("Copyright (c) 2005")]; +[assembly:AssemblyTrademarkAttribute("")]; +[assembly:AssemblyCultureAttribute("")]; + +// +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the value or you can default the Revision and Build Numbers +// by using the '*' as shown below: + +[assembly:AssemblyVersionAttribute("1.0.*")]; + +[assembly:ComVisible(false)]; + diff --git a/Chapter15/AuthorWS/AuthorWS.asmx b/Chapter15/AuthorWS/AuthorWS.asmx new file mode 100644 index 0000000..05d4928 --- /dev/null +++ b/Chapter15/AuthorWS/AuthorWS.asmx @@ -0,0 +1,2 @@ +<%@ WebService Class=AuthorWS.AuthorWSClass %> + diff --git a/Chapter15/AuthorWS/AuthorWS.vcproj b/Chapter15/AuthorWS/AuthorWS.vcproj new file mode 100644 index 0000000..c43bd62 --- /dev/null +++ b/Chapter15/AuthorWS/AuthorWS.vcproj @@ -0,0 +1,266 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Chapter15/AuthorWS/AuthorWSClass.cpp b/Chapter15/AuthorWS/AuthorWSClass.cpp new file mode 100644 index 0000000..98509d6 --- /dev/null +++ b/Chapter15/AuthorWS/AuthorWSClass.cpp @@ -0,0 +1,49 @@ +// AuthorWS.cpp : main project file. + +#include "stdafx.h" +#include "AuthorWSClass.h" +#include "Global.asax.h" + + +namespace AuthorWS +{ + DataSet^ AuthorWSClass::GetAuthors() + { + SqlDataAdapter ^dAdapt; + DataSet ^dSet; + + dAdapt = gcnew SqlDataAdapter(); + dAdapt->MissingSchemaAction = MissingSchemaAction::AddWithKey; + + dAdapt->SelectCommand = gcnew SqlCommand("SELECT AuthorID, LastName, FirstName FROM Authors", sqlConnection); + + dSet = gcnew DataSet(); + dAdapt->Fill(dSet, "Authors"); + + return dSet; + } + +void AuthorWSClass::UpdateAuthors(DataSet ^dSet) +{ + SqlDataAdapter ^dAdapt; + + dAdapt = gcnew SqlDataAdapter(); + dAdapt->MissingSchemaAction = MissingSchemaAction::AddWithKey; + + dAdapt->InsertCommand = gcnew SqlCommand("INSERT INTO Authors (LastName, FirstName) " + "VALUES (@LastName, @FirstName)", sqlConnection); + dAdapt->InsertCommand->Parameters->Add("@LastName", SqlDbType::VarChar, 50, "LastName"); + dAdapt->InsertCommand->Parameters->Add("@FirstName", SqlDbType::VarChar, 50, "FirstName"); + + dAdapt->UpdateCommand = gcnew SqlCommand("UPDATE Authors SET LastName = @LastName, FirstName = @FirstName " + "WHERE AuthorID = @AuthorID", sqlConnection); + dAdapt->UpdateCommand->Parameters->Add("@LastName", SqlDbType::VarChar, 50, "LastName"); + dAdapt->UpdateCommand->Parameters->Add("@FirstName", SqlDbType::VarChar, 50, "FirstName"); + dAdapt->UpdateCommand->Parameters->Add("@AuthorID", SqlDbType::Int, 4, "AuthorID"); + + dAdapt->DeleteCommand = gcnew SqlCommand("DELETE FROM Authors WHERE AuthorID = @AuthorID", sqlConnection); + dAdapt->DeleteCommand->Parameters->Add("@AuthorID", SqlDbType::Int, 4, "AuthorID"); + + dAdapt->Update(dSet, "Authors"); + } +}; diff --git a/Chapter15/AuthorWS/AuthorWSClass.h b/Chapter15/AuthorWS/AuthorWSClass.h new file mode 100644 index 0000000..b82b7d7 --- /dev/null +++ b/Chapter15/AuthorWS/AuthorWSClass.h @@ -0,0 +1,61 @@ +// AuthorWSClass.h + +#pragma once + +using namespace System; +using namespace System::Data; +using namespace System::Data::SqlClient; +using namespace System::Web; +using namespace System::Web::Services; + +namespace AuthorWS { + + [WebServiceBinding(ConformsTo=WsiProfiles::BasicProfile1_1, + EmitConformanceClaims = true)] + [WebService(Namespace="http://managedcpp.net", + Description = "Author table access Web Service")] + public ref class AuthorWSClass : public System::Web::Services::WebService + { + + public: + AuthorWSClass() + { + InitializeComponent(); + } + + protected: + ~AuthorWSClass() + { + if (components) + { + delete components; + } + } + + private: + System::Data::SqlClient::SqlConnection^ sqlConnection; + System::ComponentModel::Container ^components; + +#pragma region Windows Form Designer generated code + + void InitializeComponent() + { + this->sqlConnection = gcnew System::Data::SqlClient::SqlConnection(); + // + // sqlConnection + // + this->sqlConnection->ConnectionString = L"Server=Amidala;Integrated Security=True;Database=DCV_DB"; + + this->sqlConnection->FireInfoMessageEventOnUserErrors = false; + } + +#pragma endregion + + public: + [WebMethod(Description = "Method to retrieve All Authors from the database")] + DataSet ^GetAuthors(); + + [WebMethod(Description = "Method to Commit changed made on client with Server database")] + void UpdateAuthors(DataSet ^dSet); + }; +} diff --git a/Chapter15/AuthorWS/Global.asax b/Chapter15/AuthorWS/Global.asax new file mode 100644 index 0000000..2bc4a71 --- /dev/null +++ b/Chapter15/AuthorWS/Global.asax @@ -0,0 +1 @@ +<%@ Application Codebehind="Global.asax.h" Inherits="AuthorWS.Global" %> diff --git a/Chapter15/AuthorWS/Global.asax.h b/Chapter15/AuthorWS/Global.asax.h new file mode 100644 index 0000000..175dbc7 --- /dev/null +++ b/Chapter15/AuthorWS/Global.asax.h @@ -0,0 +1,47 @@ +#include "stdafx.h" + +using namespace System; +using namespace System::Web; +using namespace System::Collections; +using namespace System::ComponentModel; +using namespace System::Web::SessionState; + +namespace AuthorWS { + + /// + /// Summary description for Global. + /// + public ref class Global : public System::Web::HttpApplication + { + protected: + void Application_Start(Object ^sender, EventArgs ^e) + { + + } + + void Session_Start(Object ^sender, EventArgs ^e) + { + + } + + void Application_BeginRequest(Object ^sender, EventArgs ^e) + { + + } + + void Application_EndRequest(Object ^sender, EventArgs ^e) + { + + } + + void Session_End(Object ^sender, EventArgs ^e) + { + + } + + void Application_End(Object ^sender, EventArgs ^e) + { + + } + }; +} diff --git a/Chapter15/AuthorWS/Web.config b/Chapter15/AuthorWS/Web.config new file mode 100644 index 0000000..4015a21 --- /dev/null +++ b/Chapter15/AuthorWS/Web.config @@ -0,0 +1,90 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Chapter15/AuthorWS/stdafx.cpp b/Chapter15/AuthorWS/stdafx.cpp new file mode 100644 index 0000000..9f8cbcf --- /dev/null +++ b/Chapter15/AuthorWS/stdafx.cpp @@ -0,0 +1,5 @@ +// stdafx.cpp : source file that includes just the standard includes +// AuthorWS.pch will be the pre-compiled header +// stdafx.obj will contain the pre-compiled type information + +#include "stdafx.h" diff --git a/Chapter15/AuthorWS/stdafx.h b/Chapter15/AuthorWS/stdafx.h new file mode 100644 index 0000000..e16d986 --- /dev/null +++ b/Chapter15/AuthorWS/stdafx.h @@ -0,0 +1,7 @@ +// stdafx.h : include file for standard system include files, +// or project specific include files that are used frequently, but +// are changed infrequently +// + +#pragma once + diff --git a/Chapter15/Chapter15.sln b/Chapter15/Chapter15.sln new file mode 100644 index 0000000..377b436 --- /dev/null +++ b/Chapter15/Chapter15.sln @@ -0,0 +1,38 @@ + +Microsoft Visual Studio Solution File, Format Version 9.00 +# Visual Studio 2005 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "FindZipCode", "FindZipCode\FindZipCode.vcproj", "{2D375A1D-4D62-47C2-B74E-D991BB107874}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ZipCodeConsoleClient", "ZipCodeConsoleClient\ZipCodeConsoleClient.vcproj", "{8FDE3EE4-0FCB-4F40-AE91-E6B4FACEF235}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "AuthorWS", "AuthorWS\AuthorWS.vcproj", "{AE8DD29F-92B7-499F-ADD4-184841D3626B}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "MaintAuthors", "MaintAuthors\MaintAuthors.vcproj", "{2E1A13FE-3617-4CE3-9617-ACF9134393E5}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Win32 = Debug|Win32 + Release|Win32 = Release|Win32 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {2D375A1D-4D62-47C2-B74E-D991BB107874}.Debug|Win32.ActiveCfg = Debug|Win32 + {2D375A1D-4D62-47C2-B74E-D991BB107874}.Debug|Win32.Build.0 = Debug|Win32 + {2D375A1D-4D62-47C2-B74E-D991BB107874}.Release|Win32.ActiveCfg = Release|Win32 + {2D375A1D-4D62-47C2-B74E-D991BB107874}.Release|Win32.Build.0 = Release|Win32 + {8FDE3EE4-0FCB-4F40-AE91-E6B4FACEF235}.Debug|Win32.ActiveCfg = Debug|Win32 + {8FDE3EE4-0FCB-4F40-AE91-E6B4FACEF235}.Debug|Win32.Build.0 = Debug|Win32 + {8FDE3EE4-0FCB-4F40-AE91-E6B4FACEF235}.Release|Win32.ActiveCfg = Release|Win32 + {8FDE3EE4-0FCB-4F40-AE91-E6B4FACEF235}.Release|Win32.Build.0 = Release|Win32 + {AE8DD29F-92B7-499F-ADD4-184841D3626B}.Debug|Win32.ActiveCfg = Debug|Win32 + {AE8DD29F-92B7-499F-ADD4-184841D3626B}.Debug|Win32.Build.0 = Debug|Win32 + {AE8DD29F-92B7-499F-ADD4-184841D3626B}.Release|Win32.ActiveCfg = Release|Win32 + {AE8DD29F-92B7-499F-ADD4-184841D3626B}.Release|Win32.Build.0 = Release|Win32 + {2E1A13FE-3617-4CE3-9617-ACF9134393E5}.Debug|Win32.ActiveCfg = Debug|Win32 + {2E1A13FE-3617-4CE3-9617-ACF9134393E5}.Debug|Win32.Build.0 = Debug|Win32 + {2E1A13FE-3617-4CE3-9617-ACF9134393E5}.Release|Win32.ActiveCfg = Release|Win32 + {2E1A13FE-3617-4CE3-9617-ACF9134393E5}.Release|Win32.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/Chapter15/Chapter15.suo b/Chapter15/Chapter15.suo new file mode 100644 index 0000000..33d9815 Binary files /dev/null and b/Chapter15/Chapter15.suo differ diff --git a/Chapter15/FindZipCode/AssemblyInfo.cpp b/Chapter15/FindZipCode/AssemblyInfo.cpp new file mode 100644 index 0000000..c907f72 --- /dev/null +++ b/Chapter15/FindZipCode/AssemblyInfo.cpp @@ -0,0 +1,35 @@ +#include "stdafx.h" + +using namespace System::Reflection; +using namespace System::Runtime::CompilerServices; +using namespace System::Runtime::InteropServices; + +// +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +// +[assembly:AssemblyTitleAttribute("FindZipCode")]; +[assembly:AssemblyDescriptionAttribute("")]; +[assembly:AssemblyConfigurationAttribute("")]; +[assembly:AssemblyCompanyAttribute("")]; +[assembly:AssemblyProductAttribute("FindZipCode")]; +[assembly:AssemblyCopyrightAttribute("Copyright (c) 2005")]; +[assembly:AssemblyTrademarkAttribute("")]; +[assembly:AssemblyCultureAttribute("")]; + +// +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the value or you can default the Revision and Build Numbers +// by using the '*' as shown below: + +[assembly:AssemblyVersionAttribute("1.0.*")]; + +[assembly:ComVisible(false)]; + diff --git a/Chapter15/FindZipCode/FindZipCode.asmx b/Chapter15/FindZipCode/FindZipCode.asmx new file mode 100644 index 0000000..ed38897 --- /dev/null +++ b/Chapter15/FindZipCode/FindZipCode.asmx @@ -0,0 +1,2 @@ +<%@ WebService Class=FindZipCode.FindZipCodeClass %> + diff --git a/Chapter15/FindZipCode/FindZipCode.vcproj b/Chapter15/FindZipCode/FindZipCode.vcproj new file mode 100644 index 0000000..1543d05 --- /dev/null +++ b/Chapter15/FindZipCode/FindZipCode.vcproj @@ -0,0 +1,266 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Chapter15/FindZipCode/FindZipCodeClass.cpp b/Chapter15/FindZipCode/FindZipCodeClass.cpp new file mode 100644 index 0000000..96d1ddb --- /dev/null +++ b/Chapter15/FindZipCode/FindZipCodeClass.cpp @@ -0,0 +1,21 @@ +// FindZipCode.cpp : main project file. + +#include "stdafx.h" +#include "FindZipCodeClass.h" +#include "Global.asax.h" + + +namespace FindZipCode +{ + int FindZipCodeClass::GetZip(String ^city, String ^state) + { + // Obviously very simplified + if (city->Equals("Louisville") && state->Equals("KY")) + return 40241; + else if (city->Equals("San Jose") && state->Equals("CA")) + return 95138; + else + throw gcnew Exception("Zip Code not found"); + } +}; + diff --git a/Chapter15/FindZipCode/FindZipCodeClass.h b/Chapter15/FindZipCode/FindZipCodeClass.h new file mode 100644 index 0000000..cb81d24 --- /dev/null +++ b/Chapter15/FindZipCode/FindZipCodeClass.h @@ -0,0 +1,46 @@ +// FindZipCodeClass.h + +#pragma once + +using namespace System; +using namespace System::Web; +using namespace System::Web::Services; + +namespace FindZipCode { + + [WebServiceBinding(ConformsTo=WsiProfiles::BasicProfile1_1, + EmitConformanceClaims = true)] + [WebService(Namespace="http://managedcpp.net", + Description = "Zip code retrieval service")] + public ref class FindZipCodeClass : public WebService + { + + public: + FindZipCodeClass() + { + InitializeComponent(); + } + + protected: + ~FindZipCodeClass() + { + if (components) + { + delete components; + } + } + + private: + System::ComponentModel::Container ^components; + +#pragma region Windows Form Designer generated code + void InitializeComponent() + { + } +#pragma endregion + + public: + [WebMethod(Description = "Get the zip code from city and state")] + int GetZip(String ^city, String ^state); + }; +} diff --git a/Chapter15/FindZipCode/Global.asax b/Chapter15/FindZipCode/Global.asax new file mode 100644 index 0000000..28d16bc --- /dev/null +++ b/Chapter15/FindZipCode/Global.asax @@ -0,0 +1 @@ +<%@ Application Codebehind="Global.asax.h" Inherits="FindZipCode.Global" %> diff --git a/Chapter15/FindZipCode/Global.asax.h b/Chapter15/FindZipCode/Global.asax.h new file mode 100644 index 0000000..11b1e67 --- /dev/null +++ b/Chapter15/FindZipCode/Global.asax.h @@ -0,0 +1,47 @@ +#include "stdafx.h" + +using namespace System; +using namespace System::Web; +using namespace System::Collections; +using namespace System::ComponentModel; +using namespace System::Web::SessionState; + +namespace FindZipCode { + + /// + /// Summary description for Global. + /// + public ref class Global : public System::Web::HttpApplication + { + protected: + void Application_Start(Object ^sender, EventArgs ^e) + { + + } + + void Session_Start(Object ^sender, EventArgs ^e) + { + + } + + void Application_BeginRequest(Object ^sender, EventArgs ^e) + { + + } + + void Application_EndRequest(Object ^sender, EventArgs ^e) + { + + } + + void Session_End(Object ^sender, EventArgs ^e) + { + + } + + void Application_End(Object ^sender, EventArgs ^e) + { + + } + }; +} diff --git a/Chapter15/FindZipCode/Web.config b/Chapter15/FindZipCode/Web.config new file mode 100644 index 0000000..cd893c1 --- /dev/null +++ b/Chapter15/FindZipCode/Web.config @@ -0,0 +1,90 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Chapter15/FindZipCode/stdafx.cpp b/Chapter15/FindZipCode/stdafx.cpp new file mode 100644 index 0000000..8c0328c --- /dev/null +++ b/Chapter15/FindZipCode/stdafx.cpp @@ -0,0 +1,5 @@ +// stdafx.cpp : source file that includes just the standard includes +// FindZipCode.pch will be the pre-compiled header +// stdafx.obj will contain the pre-compiled type information + +#include "stdafx.h" diff --git a/Chapter15/FindZipCode/stdafx.h b/Chapter15/FindZipCode/stdafx.h new file mode 100644 index 0000000..e16d986 --- /dev/null +++ b/Chapter15/FindZipCode/stdafx.h @@ -0,0 +1,7 @@ +// stdafx.h : include file for standard system include files, +// or project specific include files that are used frequently, but +// are changed infrequently +// + +#pragma once + diff --git a/Chapter15/MaintAuthors/AssemblyInfo.cpp b/Chapter15/MaintAuthors/AssemblyInfo.cpp new file mode 100644 index 0000000..a1ea1fc --- /dev/null +++ b/Chapter15/MaintAuthors/AssemblyInfo.cpp @@ -0,0 +1,35 @@ +#include "stdafx.h" + +using namespace System::Reflection; +using namespace System::Runtime::CompilerServices; +using namespace System::Runtime::InteropServices; + +// +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +// +[assembly:AssemblyTitleAttribute("MaintAuthors")]; +[assembly:AssemblyDescriptionAttribute("")]; +[assembly:AssemblyConfigurationAttribute("")]; +[assembly:AssemblyCompanyAttribute("")]; +[assembly:AssemblyProductAttribute("MaintAuthors")]; +[assembly:AssemblyCopyrightAttribute("Copyright (c) 2005")]; +[assembly:AssemblyTrademarkAttribute("")]; +[assembly:AssemblyCultureAttribute("")]; + +// +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the value or you can default the Revision and Build Numbers +// by using the '*' as shown below: + +[assembly:AssemblyVersionAttribute("1.0.*")]; + +[assembly:ComVisible(false)]; + diff --git a/Chapter15/MaintAuthors/AuthorWS.h b/Chapter15/MaintAuthors/AuthorWS.h new file mode 100644 index 0000000..645bd26 --- /dev/null +++ b/Chapter15/MaintAuthors/AuthorWS.h @@ -0,0 +1,203 @@ +#pragma once + +#using +#using +#using +#using +#using +#using + +using namespace System::Security::Permissions; +[assembly:SecurityPermissionAttribute(SecurityAction::RequestMinimum, SkipVerification=false)]; +// +// This source code was auto-generated by wsdl, Version=2.0.50630.0. +// +namespace AuthorWS { + using namespace System::Diagnostics; + using namespace System::Web::Services; + using namespace System::ComponentModel; + using namespace System::Web::Services::Protocols; + using namespace System; + using namespace System::Xml::Serialization; + using namespace System::Data; + + using namespace System; + ref class AuthorWSClass; + ref class GetAuthorsCompletedEventArgs; + + + /// + [System::CodeDom::Compiler::GeneratedCodeAttribute(L"wsdl", L"2.0.50630.0")] + public delegate System::Void GetAuthorsCompletedEventHandler(System::Object^ sender, AuthorWS::GetAuthorsCompletedEventArgs^ e); + + /// + [System::CodeDom::Compiler::GeneratedCodeAttribute(L"wsdl", L"2.0.50630.0")] + public delegate System::Void UpdateAuthorsCompletedEventHandler(System::Object^ sender, System::ComponentModel::AsyncCompletedEventArgs^ e); + + /// + [System::CodeDom::Compiler::GeneratedCodeAttribute(L"wsdl", L"2.0.50630.0"), + System::Diagnostics::DebuggerStepThroughAttribute, + System::ComponentModel::DesignerCategoryAttribute(L"code"), + System::Web::Services::WebServiceBindingAttribute(Name=L"AuthorWSClassSoap", Namespace=L"http://managedcpp.net")] + public ref class AuthorWSClass : public System::Web::Services::Protocols::SoapHttpClientProtocol { + + private: System::Threading::SendOrPostCallback^ GetAuthorsOperationCompleted; + + private: System::Threading::SendOrPostCallback^ UpdateAuthorsOperationCompleted; + + /// + public: event AuthorWS::GetAuthorsCompletedEventHandler^ GetAuthorsCompleted; + + /// + public: event AuthorWS::UpdateAuthorsCompletedEventHandler^ UpdateAuthorsCompleted; + + /// + public: AuthorWSClass(); + /// + public: [System::Web::Services::Protocols::SoapDocumentMethodAttribute(L"http://managedcpp.net/GetAuthors", RequestNamespace=L"http://managedcpp.net", + ResponseNamespace=L"http://managedcpp.net", Use=System::Web::Services::Description::SoapBindingUse::Literal, ParameterStyle=System::Web::Services::Protocols::SoapParameterStyle::Wrapped)] + System::Data::DataSet^ GetAuthors(); + + /// + public: System::IAsyncResult^ BeginGetAuthors(System::AsyncCallback^ callback, System::Object^ asyncState); + + /// + public: System::Data::DataSet^ EndGetAuthors(System::IAsyncResult^ asyncResult); + + /// + public: System::Void GetAuthorsAsync(); + + /// + public: System::Void GetAuthorsAsync(System::Object^ userState); + + private: System::Void OnGetAuthorsOperationCompleted(System::Object^ arg); + + /// + public: [System::Web::Services::Protocols::SoapDocumentMethodAttribute(L"http://managedcpp.net/UpdateAuthors", RequestNamespace=L"http://managedcpp.net", + ResponseNamespace=L"http://managedcpp.net", Use=System::Web::Services::Description::SoapBindingUse::Literal, ParameterStyle=System::Web::Services::Protocols::SoapParameterStyle::Wrapped)] + System::Void UpdateAuthors(System::Data::DataSet^ dSet); + + /// + public: System::IAsyncResult^ BeginUpdateAuthors(System::Data::DataSet^ dSet, System::AsyncCallback^ callback, + System::Object^ asyncState); + + /// + public: System::Void EndUpdateAuthors(System::IAsyncResult^ asyncResult); + + /// + public: System::Void UpdateAuthorsAsync(System::Data::DataSet^ dSet); + + /// + public: System::Void UpdateAuthorsAsync(System::Data::DataSet^ dSet, System::Object^ userState); + + private: System::Void OnUpdateAuthorsOperationCompleted(System::Object^ arg); + + /// + public: System::Void CancelAsync(System::Object^ userState) new; + }; + + /// + [System::CodeDom::Compiler::GeneratedCodeAttribute(L"wsdl", L"2.0.50630.0"), + System::Diagnostics::DebuggerStepThroughAttribute, + System::ComponentModel::DesignerCategoryAttribute(L"code")] + public ref class GetAuthorsCompletedEventArgs : public System::ComponentModel::AsyncCompletedEventArgs { + + private: cli::array< System::Object^ >^ results; + + internal: GetAuthorsCompletedEventArgs(cli::array< System::Object^ >^ results, System::Exception^ exception, System::Boolean cancelled, + System::Object^ userState); + /// + public: property System::Data::DataSet^ Result { + System::Data::DataSet^ get(); + } + }; +} +namespace AuthorWS { + + + inline AuthorWSClass::AuthorWSClass() { + this->Url = L"http://localhost/AuthorWS/AuthorWS.asmx"; + } + + inline System::Data::DataSet^ AuthorWSClass::GetAuthors() { + cli::array< System::Object^ >^ results = this->Invoke(L"GetAuthors", gcnew cli::array< System::Object^ >(0)); + return (cli::safe_cast(results[0])); + } + + inline System::IAsyncResult^ AuthorWSClass::BeginGetAuthors(System::AsyncCallback^ callback, System::Object^ asyncState) { + return this->BeginInvoke(L"GetAuthors", gcnew cli::array< System::Object^ >(0), callback, asyncState); + } + + inline System::Data::DataSet^ AuthorWSClass::EndGetAuthors(System::IAsyncResult^ asyncResult) { + cli::array< System::Object^ >^ results = this->EndInvoke(asyncResult); + return (cli::safe_cast(results[0])); + } + + inline System::Void AuthorWSClass::GetAuthorsAsync() { + this->GetAuthorsAsync(nullptr); + } + + inline System::Void AuthorWSClass::GetAuthorsAsync(System::Object^ userState) { + if (this->GetAuthorsOperationCompleted == nullptr) { + this->GetAuthorsOperationCompleted = gcnew System::Threading::SendOrPostCallback(this, &AuthorWS::AuthorWSClass::OnGetAuthorsOperationCompleted); + } + this->InvokeAsync(L"GetAuthors", gcnew cli::array< System::Object^ >(0), this->GetAuthorsOperationCompleted, userState); + } + + inline System::Void AuthorWSClass::OnGetAuthorsOperationCompleted(System::Object^ arg) { + { + System::Web::Services::Protocols::InvokeCompletedEventArgs^ invokeArgs = (cli::safe_cast(arg)); + this->GetAuthorsCompleted(this, (gcnew AuthorWS::GetAuthorsCompletedEventArgs(invokeArgs->Results, invokeArgs->Error, + invokeArgs->Cancelled, invokeArgs->UserState))); + } + } + + inline System::Void AuthorWSClass::UpdateAuthors(System::Data::DataSet^ dSet) { + this->Invoke(L"UpdateAuthors", gcnew cli::array< System::Object^ >(1) {dSet}); + } + + inline System::IAsyncResult^ AuthorWSClass::BeginUpdateAuthors(System::Data::DataSet^ dSet, System::AsyncCallback^ callback, + System::Object^ asyncState) { + return this->BeginInvoke(L"UpdateAuthors", gcnew cli::array< System::Object^ >(1) {dSet}, callback, asyncState); + } + + inline System::Void AuthorWSClass::EndUpdateAuthors(System::IAsyncResult^ asyncResult) { + this->EndInvoke(asyncResult); + } + + inline System::Void AuthorWSClass::UpdateAuthorsAsync(System::Data::DataSet^ dSet) { + this->UpdateAuthorsAsync(dSet, nullptr); + } + + inline System::Void AuthorWSClass::UpdateAuthorsAsync(System::Data::DataSet^ dSet, System::Object^ userState) { + if (this->UpdateAuthorsOperationCompleted == nullptr) { + this->UpdateAuthorsOperationCompleted = gcnew System::Threading::SendOrPostCallback(this, &AuthorWS::AuthorWSClass::OnUpdateAuthorsOperationCompleted); + } + this->InvokeAsync(L"UpdateAuthors", gcnew cli::array< System::Object^ >(1) {dSet}, this->UpdateAuthorsOperationCompleted, + userState); + } + + inline System::Void AuthorWSClass::OnUpdateAuthorsOperationCompleted(System::Object^ arg) { + { + System::Web::Services::Protocols::InvokeCompletedEventArgs^ invokeArgs = (cli::safe_cast(arg)); + this->UpdateAuthorsCompleted(this, (gcnew System::ComponentModel::AsyncCompletedEventArgs(invokeArgs->Error, invokeArgs->Cancelled, + invokeArgs->UserState))); + } + } + + inline System::Void AuthorWSClass::CancelAsync(System::Object^ userState) { + __super::CancelAsync(userState); + } + + + inline GetAuthorsCompletedEventArgs::GetAuthorsCompletedEventArgs(cli::array< System::Object^ >^ results, System::Exception^ exception, + System::Boolean cancelled, System::Object^ userState) : + System::ComponentModel::AsyncCompletedEventArgs(exception, cancelled, userState) { + this->results = results; + } + + inline System::Data::DataSet^ GetAuthorsCompletedEventArgs::Result::get() { + this->RaiseExceptionIfNecessary(); + return (cli::safe_cast(this->results[0])); + } +} diff --git a/Chapter15/MaintAuthors/AuthorWS/AuthorWS.disco b/Chapter15/MaintAuthors/AuthorWS/AuthorWS.disco new file mode 100644 index 0000000..d944cc4 --- /dev/null +++ b/Chapter15/MaintAuthors/AuthorWS/AuthorWS.disco @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Chapter15/MaintAuthors/AuthorWS/AuthorWS.wsdl b/Chapter15/MaintAuthors/AuthorWS/AuthorWS.wsdl new file mode 100644 index 0000000..8c9a43c --- /dev/null +++ b/Chapter15/MaintAuthors/AuthorWS/AuthorWS.wsdl @@ -0,0 +1,120 @@ + + + Author table access Web Service + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Method to retrieve All Authors from the database + + + + + Method to Commit changed made on client with Server database + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Author table access Web Service + + + + + + + + \ No newline at end of file diff --git a/Chapter15/MaintAuthors/AuthorWS/results.discomap b/Chapter15/MaintAuthors/AuthorWS/results.discomap new file mode 100644 index 0000000..9466cc8 --- /dev/null +++ b/Chapter15/MaintAuthors/AuthorWS/results.discomap @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/Chapter15/MaintAuthors/Form1.h b/Chapter15/MaintAuthors/Form1.h new file mode 100644 index 0000000..e65c4ef --- /dev/null +++ b/Chapter15/MaintAuthors/Form1.h @@ -0,0 +1,306 @@ +#pragma once + + +namespace MaintAuthors { + + using namespace System; + using namespace System::ComponentModel; + using namespace System::Collections; + using namespace System::Windows::Forms; + using namespace System::Data; + using namespace System::Drawing; + + public ref class Form1 : public System::Windows::Forms::Form + { + public: + Form1(void) + { + InitializeComponent(); + + authors = gcnew AuthorWS::AuthorWSClass(); + dSet = authors->GetAuthors(); + + DataTable ^dt = dSet->Tables["Authors"]; + + if (dt == nullptr) + throw gcnew Exception("No Authors Table"); + + for each (DataRow ^row in dt->Rows::get()) + { + lbAuthors->Items->Add(ListBoxItem(row)); + } + + CurrentAuthorID = -1; + } + + protected: + ~Form1() + { + if (components) + { + delete components; + } + } + + private: + System::Windows::Forms::Button^ bnRollback; + System::Windows::Forms::Button^ bnCommit; + System::Windows::Forms::Button^ bnDelete; + System::Windows::Forms::Button^ bnUpdate; + System::Windows::Forms::Button^ bnAdd; + System::Windows::Forms::ListBox^ lbAuthors; + System::Windows::Forms::TextBox^ tbLastName; + System::Windows::Forms::TextBox^ tbFirstName; + System::Windows::Forms::Label^ label2; + System::Windows::Forms::Label^ label1; + + System::ComponentModel::Container ^components; + + DataSet ^dSet; + int CurrentAuthorID; + AuthorWS::AuthorWSClass ^authors; + +#pragma region Windows Form Designer generated code + + void InitializeComponent(void) + { + this->bnRollback = (gcnew System::Windows::Forms::Button()); + this->bnCommit = (gcnew System::Windows::Forms::Button()); + this->bnDelete = (gcnew System::Windows::Forms::Button()); + this->bnUpdate = (gcnew System::Windows::Forms::Button()); + this->bnAdd = (gcnew System::Windows::Forms::Button()); + this->lbAuthors = (gcnew System::Windows::Forms::ListBox()); + this->tbLastName = (gcnew System::Windows::Forms::TextBox()); + this->tbFirstName = (gcnew System::Windows::Forms::TextBox()); + this->label2 = (gcnew System::Windows::Forms::Label()); + this->label1 = (gcnew System::Windows::Forms::Label()); + this->SuspendLayout(); + // + // bnRollback + // + this->bnRollback->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 8.25F, System::Drawing::FontStyle::Bold, System::Drawing::GraphicsUnit::Point, + static_cast(0))); + this->bnRollback->Location = System::Drawing::Point(322, 168); + this->bnRollback->Name = L"bnRollback"; + this->bnRollback->Size = System::Drawing::Size(75, 23); + this->bnRollback->TabIndex = 29; + this->bnRollback->Text = L"Rollback"; + this->bnRollback->Click += gcnew System::EventHandler(this, &Form1::bnRollback_Click); + // + // bnCommit + // + this->bnCommit->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 8.25F, System::Drawing::FontStyle::Bold, System::Drawing::GraphicsUnit::Point, + static_cast(0))); + this->bnCommit->Location = System::Drawing::Point(322, 138); + this->bnCommit->Margin = System::Windows::Forms::Padding(3, 0, 3, 3); + this->bnCommit->Name = L"bnCommit"; + this->bnCommit->Size = System::Drawing::Size(75, 23); + this->bnCommit->TabIndex = 28; + this->bnCommit->Text = L"Commit"; + this->bnCommit->Click += gcnew System::EventHandler(this, &Form1::bnCommit_Click); + // + // bnDelete + // + this->bnDelete->Location = System::Drawing::Point(322, 84); + this->bnDelete->Name = L"bnDelete"; + this->bnDelete->Size = System::Drawing::Size(75, 23); + this->bnDelete->TabIndex = 27; + this->bnDelete->Text = L"Delete"; + this->bnDelete->Click += gcnew System::EventHandler(this, &Form1::bnDelete_Click); + // + // bnUpdate + // + this->bnUpdate->Location = System::Drawing::Point(322, 52); + this->bnUpdate->Name = L"bnUpdate"; + this->bnUpdate->Size = System::Drawing::Size(75, 23); + this->bnUpdate->TabIndex = 26; + this->bnUpdate->Text = L"Update"; + this->bnUpdate->Click += gcnew System::EventHandler(this, &Form1::bnUpdate_Click); + // + // bnAdd + // + this->bnAdd->Location = System::Drawing::Point(322, 24); + this->bnAdd->Margin = System::Windows::Forms::Padding(3, 3, 3, 1); + this->bnAdd->Name = L"bnAdd"; + this->bnAdd->Size = System::Drawing::Size(75, 23); + this->bnAdd->TabIndex = 25; + this->bnAdd->Text = L"Add"; + this->bnAdd->Click += gcnew System::EventHandler(this, &Form1::bnAdd_Click); + // + // lbAuthors + // + this->lbAuthors->FormattingEnabled = true; + this->lbAuthors->Location = System::Drawing::Point(35, 101); + this->lbAuthors->Name = L"lbAuthors"; + this->lbAuthors->Size = System::Drawing::Size(257, 95); + this->lbAuthors->TabIndex = 24; + this->lbAuthors->SelectedIndexChanged += gcnew System::EventHandler(this, &Form1::lbAuthors_SelectedIndexChanged); + // + // tbLastName + // + this->tbLastName->Location = System::Drawing::Point(97, 57); + this->tbLastName->Margin = System::Windows::Forms::Padding(1, 3, 3, 3); + this->tbLastName->Name = L"tbLastName"; + this->tbLastName->Size = System::Drawing::Size(127, 20); + this->tbLastName->TabIndex = 23; + // + // tbFirstName + // + this->tbFirstName->Location = System::Drawing::Point(97, 30); + this->tbFirstName->Margin = System::Windows::Forms::Padding(1, 3, 3, 3); + this->tbFirstName->Name = L"tbFirstName"; + this->tbFirstName->Size = System::Drawing::Size(127, 20); + this->tbFirstName->TabIndex = 22; + // + // label2 + // + this->label2->AutoSize = true; + this->label2->Location = System::Drawing::Point(35, 63); + this->label2->Margin = System::Windows::Forms::Padding(3, 3, 2, 3); + this->label2->Name = L"label2"; + this->label2->Size = System::Drawing::Size(58, 13); + this->label2->TabIndex = 21; + this->label2->Text = L"Last Name"; + // + // label1 + // + this->label1->AutoSize = true; + this->label1->Location = System::Drawing::Point(35, 33); + this->label1->Margin = System::Windows::Forms::Padding(3, 3, 2, 3); + this->label1->Name = L"label1"; + this->label1->Size = System::Drawing::Size(57, 13); + this->label1->TabIndex = 20; + this->label1->Text = L"First Name"; + // + // Form1 + // + this->AutoScaleDimensions = System::Drawing::SizeF(6, 13); + this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font; + this->ClientSize = System::Drawing::Size(432, 220); + this->Controls->Add(this->bnRollback); + this->Controls->Add(this->bnCommit); + this->Controls->Add(this->bnDelete); + this->Controls->Add(this->bnUpdate); + this->Controls->Add(this->bnAdd); + this->Controls->Add(this->lbAuthors); + this->Controls->Add(this->tbLastName); + this->Controls->Add(this->tbFirstName); + this->Controls->Add(this->label2); + this->Controls->Add(this->label1); + this->Name = L"Form1"; + this->Text = L"Maintain Authors using a Web Service"; + this->ResumeLayout(false); + this->PerformLayout(); + } + +#pragma endregion + + private: + String ^ListBoxItem(DataRow ^row) + { + return String::Format("{0} {1} {2}", + row["AuthorID"], + row["FirstName"], + row["LastName"]); + } + + System::Void bnRollback_Click(System::Object^ sender, System::EventArgs^ e) + { + dSet->RejectChanges(); + + lbAuthors->Items->Clear(); + + DataTable ^dt = dSet->Tables["Authors"]; + + for each (DataRow^ row in dt->Rows::get()) + { + lbAuthors->Items->Add(ListBoxItem(row)); + } + CurrentAuthorID = -1; + } + + System::Void bnCommit_Click(System::Object^ sender, System::EventArgs^ e) + { + authors->UpdateAuthors(dSet->GetChanges()); + dSet->AcceptChanges(); + + lbAuthors->Items->Clear(); + + DataTable ^dt = dSet->Tables["Authors"]; + + for each (DataRow^ row in dt->Rows::get()) + { + lbAuthors->Items->Add(ListBoxItem(row)); + } + CurrentAuthorID = -1; + } + + System::Void bnDelete_Click(System::Object^ sender, System::EventArgs^ e) + { + if (CurrentAuthorID < 0) + return; + + DataTable ^dt = dSet->Tables["Authors"]; + array^ row = dt->Select(String::Format("AuthorID={0}", CurrentAuthorID)); + + row[0]->Delete(); + + lbAuthors->Items->RemoveAt(lbAuthors->SelectedIndex); + } + + System::Void bnUpdate_Click(System::Object^ sender, System::EventArgs^ e) + { + if (CurrentAuthorID < 0) + return; + + DataTable ^dt = dSet->Tables["Authors"]; + array^ row = dt->Select(String::Format("AuthorID={0}", CurrentAuthorID)); + + row[0]["FirstName"] = tbFirstName->Text; + row[0]["LastName"] = tbLastName->Text; + + lbAuthors->Items->Insert(lbAuthors->SelectedIndex, ListBoxItem(row[0])); + lbAuthors->Items->RemoveAt(lbAuthors->SelectedIndex); + } + + System::Void bnAdd_Click(System::Object^ sender, System::EventArgs^ e) + { + if (tbFirstName->Text->Trim()->Length == 0 || + tbLastName->Text->Trim()->Length == 0) + return; + + DataTable ^dt = dSet->Tables["Authors"]; + + DataRow ^row = dt->NewRow(); + + row["FirstName"] = tbFirstName->Text; + row["LastName"] = tbLastName->Text; + + dt->Rows->Add(row); + + lbAuthors->Items->Add(ListBoxItem(row)); + + tbFirstName->Text = ""; + tbLastName->Text = ""; + } + + System::Void lbAuthors_SelectedIndexChanged(System::Object^ sender, System::EventArgs^ e) + { + array^ ASpace = gcnew array{' '}; + + if (lbAuthors->SelectedItem == nullptr) + { + CurrentAuthorID = -1; + tbFirstName->Text = ""; + tbLastName->Text = ""; + return; + } + array^ split = lbAuthors->SelectedItem->ToString()->Split(ASpace); + + CurrentAuthorID = Convert::ToInt32(split[0]); + tbFirstName->Text = split[1]; + tbLastName->Text = split[2]; + } + }; +} + diff --git a/Chapter15/MaintAuthors/Form1.resx b/Chapter15/MaintAuthors/Form1.resx new file mode 100644 index 0000000..de824e1 --- /dev/null +++ b/Chapter15/MaintAuthors/Form1.resx @@ -0,0 +1,110 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Chapter15/MaintAuthors/MaintAuthors.cpp b/Chapter15/MaintAuthors/MaintAuthors.cpp new file mode 100644 index 0000000..a28e145 --- /dev/null +++ b/Chapter15/MaintAuthors/MaintAuthors.cpp @@ -0,0 +1,16 @@ +// MaintAuthors.cpp : main project file. + +#include "stdafx.h" +#include "Form1.h" + +using namespace MaintAuthors; + +[STAThreadAttribute] +int main(array ^args) +{ + // Enabling Windows XP visual effects before any controls are created + Application::EnableVisualStyles(); + // Create the main window and run it + Application::Run(gcnew Form1()); + return 0; +} diff --git a/Chapter15/MaintAuthors/MaintAuthors.vcproj b/Chapter15/MaintAuthors/MaintAuthors.vcproj new file mode 100644 index 0000000..4d08392 --- /dev/null +++ b/Chapter15/MaintAuthors/MaintAuthors.vcproj @@ -0,0 +1,282 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Chapter15/MaintAuthors/MaintAuthors.vcproj.vspscc b/Chapter15/MaintAuthors/MaintAuthors.vcproj.vspscc new file mode 100644 index 0000000..515391c --- /dev/null +++ b/Chapter15/MaintAuthors/MaintAuthors.vcproj.vspscc @@ -0,0 +1,11 @@ +"" +{ +"FILE_VERSION" = "9237" +"ENLISTMENT_CHOICE" = "NEVER" +"PROJECT_FILE_RELATIVE_PATH" = "" +"NUMBER_OF_EXCLUDED_FILES" = "1" +"EXCLUDED_FILE0" = "AuthorWS.h" +"ORIGINAL_PROJECT_FILE_PATH" = "" +"NUMBER_OF_NESTED_PROJECTS" = "0" +"SOURCE_CONTROL_SETTINGS_PROVIDER" = "PROJECT" +} diff --git a/Chapter15/MaintAuthors/stdafx.cpp b/Chapter15/MaintAuthors/stdafx.cpp new file mode 100644 index 0000000..198bfa9 --- /dev/null +++ b/Chapter15/MaintAuthors/stdafx.cpp @@ -0,0 +1,7 @@ +// stdafx.cpp : source file that includes just the standard includes +// MaintAuthors.pch will be the pre-compiled header +// stdafx.obj will contain the pre-compiled type information + +#include "stdafx.h" + + diff --git a/Chapter15/MaintAuthors/stdafx.h b/Chapter15/MaintAuthors/stdafx.h new file mode 100644 index 0000000..eb54e97 --- /dev/null +++ b/Chapter15/MaintAuthors/stdafx.h @@ -0,0 +1,8 @@ +// stdafx.h : include file for standard system include files, +// or project specific include files that are used frequently, but +// are changed infrequently +#pragma once + +// TODO: reference additional headers your program requires here + +#include "WebService.h" \ No newline at end of file diff --git a/Chapter15/MaintAuthors/webservice.h b/Chapter15/MaintAuthors/webservice.h new file mode 100644 index 0000000..dd57fc9 --- /dev/null +++ b/Chapter15/MaintAuthors/webservice.h @@ -0,0 +1,2 @@ + +#include "AuthorWS.h" diff --git a/Chapter15/ZipCodeConsoleClient/AssemblyInfo.cpp b/Chapter15/ZipCodeConsoleClient/AssemblyInfo.cpp new file mode 100644 index 0000000..9ca2b81 --- /dev/null +++ b/Chapter15/ZipCodeConsoleClient/AssemblyInfo.cpp @@ -0,0 +1,35 @@ +#include "stdafx.h" + +using namespace System::Reflection; +using namespace System::Runtime::CompilerServices; +using namespace System::Runtime::InteropServices; + +// +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +// +[assembly:AssemblyTitleAttribute("ZipCodeConsoleClient")]; +[assembly:AssemblyDescriptionAttribute("")]; +[assembly:AssemblyConfigurationAttribute("")]; +[assembly:AssemblyCompanyAttribute("")]; +[assembly:AssemblyProductAttribute("ZipCodeConsoleClient")]; +[assembly:AssemblyCopyrightAttribute("Copyright (c) 2005")]; +[assembly:AssemblyTrademarkAttribute("")]; +[assembly:AssemblyCultureAttribute("")]; + +// +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the value or you can default the Revision and Build Numbers +// by using the '*' as shown below: + +[assembly:AssemblyVersionAttribute("1.0.*")]; + +[assembly:ComVisible(false)]; + diff --git a/Chapter15/ZipCodeConsoleClient/FindZipCode.h b/Chapter15/ZipCodeConsoleClient/FindZipCode.h new file mode 100644 index 0000000..464928e --- /dev/null +++ b/Chapter15/ZipCodeConsoleClient/FindZipCode.h @@ -0,0 +1,142 @@ +#pragma once + +#using +#using +#using +#using +#using + +using namespace System::Security::Permissions; +[assembly:SecurityPermissionAttribute(SecurityAction::RequestMinimum, SkipVerification=false)]; +// +// This source code was auto-generated by wsdl, Version=2.0.50630.0. +// +namespace FindZipCode { + using namespace System::Diagnostics; + using namespace System::Web::Services; + using namespace System::ComponentModel; + using namespace System::Web::Services::Protocols; + using namespace System; + using namespace System::Xml::Serialization; + + using namespace System; + ref class FindZipCodeClass; + ref class GetZipCompletedEventArgs; + + + /// + [System::CodeDom::Compiler::GeneratedCodeAttribute(L"wsdl", L"2.0.50630.0")] + public delegate System::Void GetZipCompletedEventHandler(System::Object^ sender, FindZipCode::GetZipCompletedEventArgs^ e); + + /// + [System::CodeDom::Compiler::GeneratedCodeAttribute(L"wsdl", L"2.0.50630.0"), + System::Diagnostics::DebuggerStepThroughAttribute, + System::ComponentModel::DesignerCategoryAttribute(L"code"), + System::Web::Services::WebServiceBindingAttribute(Name=L"FindZipCodeClassSoap", Namespace=L"http://managedcpp.net")] + public ref class FindZipCodeClass : public System::Web::Services::Protocols::SoapHttpClientProtocol { + + private: System::Threading::SendOrPostCallback^ GetZipOperationCompleted; + + /// + public: event FindZipCode::GetZipCompletedEventHandler^ GetZipCompleted; + + /// + public: FindZipCodeClass(); + /// + public: [System::Web::Services::Protocols::SoapDocumentMethodAttribute(L"http://managedcpp.net/GetZip", RequestNamespace=L"http://managedcpp.net", + ResponseNamespace=L"http://managedcpp.net", Use=System::Web::Services::Description::SoapBindingUse::Literal, ParameterStyle=System::Web::Services::Protocols::SoapParameterStyle::Wrapped)] + System::Int32 GetZip(System::String^ city, System::String^ state); + + /// + public: System::IAsyncResult^ BeginGetZip(System::String^ city, System::String^ state, System::AsyncCallback^ callback, + System::Object^ asyncState); + + /// + public: System::Int32 EndGetZip(System::IAsyncResult^ asyncResult); + + /// + public: System::Void GetZipAsync(System::String^ city, System::String^ state); + + /// + public: System::Void GetZipAsync(System::String^ city, System::String^ state, System::Object^ userState); + + private: System::Void OnGetZipOperationCompleted(System::Object^ arg); + + /// + public: System::Void CancelAsync(System::Object^ userState) new; + }; + + /// + [System::CodeDom::Compiler::GeneratedCodeAttribute(L"wsdl", L"2.0.50630.0"), + System::Diagnostics::DebuggerStepThroughAttribute, + System::ComponentModel::DesignerCategoryAttribute(L"code")] + public ref class GetZipCompletedEventArgs : public System::ComponentModel::AsyncCompletedEventArgs { + + private: cli::array< System::Object^ >^ results; + + internal: GetZipCompletedEventArgs(cli::array< System::Object^ >^ results, System::Exception^ exception, System::Boolean cancelled, + System::Object^ userState); + /// + public: property System::Int32 Result { + System::Int32 get(); + } + }; +} +namespace FindZipCode { + + + inline FindZipCodeClass::FindZipCodeClass() { + this->Url = L"http://localhost/FindZipCode/FindZipCode.asmx"; + } + + inline System::Int32 FindZipCodeClass::GetZip(System::String^ city, System::String^ state) { + cli::array< System::Object^ >^ results = this->Invoke(L"GetZip", gcnew cli::array< System::Object^ >(2) {city, + state}); + return (*cli::safe_cast(results[0])); + } + + inline System::IAsyncResult^ FindZipCodeClass::BeginGetZip(System::String^ city, System::String^ state, System::AsyncCallback^ callback, + System::Object^ asyncState) { + return this->BeginInvoke(L"GetZip", gcnew cli::array< System::Object^ >(2) {city, state}, callback, asyncState); + } + + inline System::Int32 FindZipCodeClass::EndGetZip(System::IAsyncResult^ asyncResult) { + cli::array< System::Object^ >^ results = this->EndInvoke(asyncResult); + return (*cli::safe_cast(results[0])); + } + + inline System::Void FindZipCodeClass::GetZipAsync(System::String^ city, System::String^ state) { + this->GetZipAsync(city, state, nullptr); + } + + inline System::Void FindZipCodeClass::GetZipAsync(System::String^ city, System::String^ state, System::Object^ userState) { + if (this->GetZipOperationCompleted == nullptr) { + this->GetZipOperationCompleted = gcnew System::Threading::SendOrPostCallback(this, &FindZipCode::FindZipCodeClass::OnGetZipOperationCompleted); + } + this->InvokeAsync(L"GetZip", gcnew cli::array< System::Object^ >(2) {city, state}, this->GetZipOperationCompleted, userState); + } + + inline System::Void FindZipCodeClass::OnGetZipOperationCompleted(System::Object^ arg) { + { + System::Web::Services::Protocols::InvokeCompletedEventArgs^ invokeArgs = (cli::safe_cast(arg)); + this->GetZipCompleted(this, (gcnew FindZipCode::GetZipCompletedEventArgs(invokeArgs->Results, invokeArgs->Error, + invokeArgs->Cancelled, invokeArgs->UserState))); + } + } + + inline System::Void FindZipCodeClass::CancelAsync(System::Object^ userState) { + __super::CancelAsync(userState); + } + + + inline GetZipCompletedEventArgs::GetZipCompletedEventArgs(cli::array< System::Object^ >^ results, System::Exception^ exception, + System::Boolean cancelled, System::Object^ userState) : + System::ComponentModel::AsyncCompletedEventArgs(exception, cancelled, userState) { + this->results = results; + } + + inline System::Int32 GetZipCompletedEventArgs::Result::get() { + this->RaiseExceptionIfNecessary(); + return (*cli::safe_cast(this->results[0])); + } +} diff --git a/Chapter15/ZipCodeConsoleClient/FindZipCode/FindZipCode.disco b/Chapter15/ZipCodeConsoleClient/FindZipCode/FindZipCode.disco new file mode 100644 index 0000000..b0de888 --- /dev/null +++ b/Chapter15/ZipCodeConsoleClient/FindZipCode/FindZipCode.disco @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Chapter15/ZipCodeConsoleClient/FindZipCode/FindZipCode.wsdl b/Chapter15/ZipCodeConsoleClient/FindZipCode/FindZipCode.wsdl new file mode 100644 index 0000000..96e6db8 --- /dev/null +++ b/Chapter15/ZipCodeConsoleClient/FindZipCode/FindZipCode.wsdl @@ -0,0 +1,69 @@ + + + Zip code retrieval service + + + + + + + + + + + + + + + + + + + + + + + + + + + + Get the zip code from city and state + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Zip code retrieval service + + + + + + + + \ No newline at end of file diff --git a/Chapter15/ZipCodeConsoleClient/FindZipCode/results.discomap b/Chapter15/ZipCodeConsoleClient/FindZipCode/results.discomap new file mode 100644 index 0000000..bac5acf --- /dev/null +++ b/Chapter15/ZipCodeConsoleClient/FindZipCode/results.discomap @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/Chapter15/ZipCodeConsoleClient/ZipCodeConsoleClient.cpp b/Chapter15/ZipCodeConsoleClient/ZipCodeConsoleClient.cpp new file mode 100644 index 0000000..be5d712 --- /dev/null +++ b/Chapter15/ZipCodeConsoleClient/ZipCodeConsoleClient.cpp @@ -0,0 +1,21 @@ +// ZipCodeConsoleClient.cpp : main project file. + +#include "stdafx.h" + +using namespace System; + +void main() +{ + FindZipCode::FindZipCodeClass ^fzc = gcnew FindZipCode::FindZipCodeClass(); + + try + { + Console::WriteLine(fzc->GetZip("Louisville", "KY").ToString()); + Console::WriteLine(fzc->GetZip("San Jose", "CA").ToString()); + Console::WriteLine(fzc->GetZip("xx", "cc").ToString()); + } + catch (Exception ^e) + { + Console::WriteLine(e->Message); + } +} diff --git a/Chapter15/ZipCodeConsoleClient/ZipCodeConsoleClient.vcproj b/Chapter15/ZipCodeConsoleClient/ZipCodeConsoleClient.vcproj new file mode 100644 index 0000000..002e218 --- /dev/null +++ b/Chapter15/ZipCodeConsoleClient/ZipCodeConsoleClient.vcproj @@ -0,0 +1,260 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Chapter15/ZipCodeConsoleClient/ZipCodeConsoleClient.vcproj.vspscc b/Chapter15/ZipCodeConsoleClient/ZipCodeConsoleClient.vcproj.vspscc new file mode 100644 index 0000000..112c03a --- /dev/null +++ b/Chapter15/ZipCodeConsoleClient/ZipCodeConsoleClient.vcproj.vspscc @@ -0,0 +1,11 @@ +"" +{ +"FILE_VERSION" = "9237" +"ENLISTMENT_CHOICE" = "NEVER" +"PROJECT_FILE_RELATIVE_PATH" = "" +"NUMBER_OF_EXCLUDED_FILES" = "1" +"EXCLUDED_FILE0" = "FindZipCode.h" +"ORIGINAL_PROJECT_FILE_PATH" = "" +"NUMBER_OF_NESTED_PROJECTS" = "0" +"SOURCE_CONTROL_SETTINGS_PROVIDER" = "PROJECT" +} diff --git a/Chapter15/ZipCodeConsoleClient/resource.h b/Chapter15/ZipCodeConsoleClient/resource.h new file mode 100644 index 0000000..d5ac7c4 --- /dev/null +++ b/Chapter15/ZipCodeConsoleClient/resource.h @@ -0,0 +1,3 @@ +//{{NO_DEPENDENCIES}} +// Microsoft Visual C++ generated include file. +// Used by app.rc diff --git a/Chapter15/ZipCodeConsoleClient/stdafx.cpp b/Chapter15/ZipCodeConsoleClient/stdafx.cpp new file mode 100644 index 0000000..1ea9cef --- /dev/null +++ b/Chapter15/ZipCodeConsoleClient/stdafx.cpp @@ -0,0 +1,7 @@ +// stdafx.cpp : source file that includes just the standard includes +// ZipCodeConsoleClient.pch will be the pre-compiled header +// stdafx.obj will contain the pre-compiled type information + +#include "stdafx.h" + + diff --git a/Chapter15/ZipCodeConsoleClient/stdafx.h b/Chapter15/ZipCodeConsoleClient/stdafx.h new file mode 100644 index 0000000..09ad803 --- /dev/null +++ b/Chapter15/ZipCodeConsoleClient/stdafx.h @@ -0,0 +1,10 @@ +// stdafx.h : include file for standard system include files, +// or project specific include files that are used frequently, but +// are changed infrequently +// + +#pragma once + +// TODO: reference additional headers your program requires here + +#include "WebService.h" \ No newline at end of file diff --git a/Chapter15/ZipCodeConsoleClient/webservice.h b/Chapter15/ZipCodeConsoleClient/webservice.h new file mode 100644 index 0000000..d3b7b67 --- /dev/null +++ b/Chapter15/ZipCodeConsoleClient/webservice.h @@ -0,0 +1,3 @@ + +#include "FindZipCode.h" +#include "FindZipCode.h" diff --git a/Chapter16/AbortingThreads/AbortingThreads.cpp b/Chapter16/AbortingThreads/AbortingThreads.cpp new file mode 100644 index 0000000..9255bc7 --- /dev/null +++ b/Chapter16/AbortingThreads/AbortingThreads.cpp @@ -0,0 +1,56 @@ +using namespace System; +using namespace System::Threading; + +ref class MyThread +{ +public: + static void ThreadFunc(Object ^Name); +}; + +void MyThread::ThreadFunc(Object ^Name) +{ + Thread ^thr = Thread::CurrentThread; + try + { + for (int i = 0; i < 100; i++) + { + Console::WriteLine("{0} {1}", Name, i.ToString()); + Thread::Sleep(1); + } + return; + } + catch (ThreadAbortException^) + { + Console::WriteLine("{0} Aborted", Name); + // Reset the abort so that the meoth will continue processing + // thr->ResetAbort(); + } +} + + +void main() +{ + Console::WriteLine("Main Program Starts"); + + Thread ^thr1 = gcnew Thread(gcnew ParameterizedThreadStart(&MyThread::ThreadFunc)); + Thread ^thr2 = gcnew Thread(gcnew ParameterizedThreadStart(&MyThread::ThreadFunc)); + + thr1->Start("Thread1"); + thr2->Start("Thread2"); + + Thread::Sleep(20); + thr1->Abort(); + Thread::Sleep(40); + thr2->Abort(); + + try + { + thr1->Start(); + } + catch (ThreadStateException ^tse) + { + Console::WriteLine(tse->ToString()); + } + + Console::WriteLine("Main Program Ends"); +} \ No newline at end of file diff --git a/Chapter16/AbortingThreads/AbortingThreads.vcproj b/Chapter16/AbortingThreads/AbortingThreads.vcproj new file mode 100644 index 0000000..7388b6a --- /dev/null +++ b/Chapter16/AbortingThreads/AbortingThreads.vcproj @@ -0,0 +1,197 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Chapter16/AbortingThreads/AbortingThreads.vcproj.AMIDALA.Stephen Fraser.user b/Chapter16/AbortingThreads/AbortingThreads.vcproj.AMIDALA.Stephen Fraser.user new file mode 100644 index 0000000..196a6d1 --- /dev/null +++ b/Chapter16/AbortingThreads/AbortingThreads.vcproj.AMIDALA.Stephen Fraser.user @@ -0,0 +1,65 @@ + + + + + + + + + + + diff --git a/Chapter16/Chapter16.sln b/Chapter16/Chapter16.sln new file mode 100644 index 0000000..64dc7f6 --- /dev/null +++ b/Chapter16/Chapter16.sln @@ -0,0 +1,86 @@ + +Microsoft Visual Studio Solution File, Format Version 9.00 +# Visual Studio 2005 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "StartingThreads", "StartingThreads\StartingThreads.vcproj", "{12E4D18A-0CC2-4DEC-80C3-CF619799E3EF}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "AbortingThreads", "AbortingThreads\AbortingThreads.vcproj", "{0365E0AB-D32A-4F52-9223-4C79B12D4CB5}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "SleepingThreads", "SleepingThreads\SleepingThreads.vcproj", "{3F5D8D39-3E7A-453C-BAF3-B037EC8D91CF}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "JoiningThreads", "JoiningThreads\JoiningThreads.vcproj", "{438199D3-8E2C-4D8D-AB7C-1E08608F61C8}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ISRingThreads", "ISRingThreads\ISRingThreads.vcproj", "{466A40DE-9A2C-4369-8E3B-53CF577CABF0}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ThreadPooling", "ThreadPooling\ThreadPooling.vcproj", "{A1B8A0EF-89C4-4F96-B9F7-A3A0FCE81983}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ThreadStaticVars", "ThreadStaticVars\ThreadStaticVars.vcproj", "{E775EDCF-8DBB-435A-A427-0DAD70909A6B}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "InterlockedVars", "InterlockedVars\InterlockedVars.vcproj", "{256A2DDF-3A2F-4E8A-92AD-329EFC7A1C73}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "SyncByMonitor", "SyncByMonitor\SyncByMonitor.vcproj", "{2D6ED8F7-5967-487D-960C-C8157EDED988}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "MutexSpawn", "MutexSpawn\MutexSpawn.vcproj", "{E6C613A3-6C7B-4163-A4FB-B50103CB83E1}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "SyncByMutex", "SyncByMutex\SyncByMutex.vcproj", "{4CDE32AF-A428-4A2C-9DD1-C9F27141C0F7}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "SyncByRWLock", "SyncByRWLock\SyncByRWLock.vcproj", "{C4200CD6-2FFC-43F1-BB05-8DD744324417}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Win32 = Debug|Win32 + Release|Win32 = Release|Win32 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {12E4D18A-0CC2-4DEC-80C3-CF619799E3EF}.Debug|Win32.ActiveCfg = Debug|Win32 + {12E4D18A-0CC2-4DEC-80C3-CF619799E3EF}.Debug|Win32.Build.0 = Debug|Win32 + {12E4D18A-0CC2-4DEC-80C3-CF619799E3EF}.Release|Win32.ActiveCfg = Release|Win32 + {12E4D18A-0CC2-4DEC-80C3-CF619799E3EF}.Release|Win32.Build.0 = Release|Win32 + {0365E0AB-D32A-4F52-9223-4C79B12D4CB5}.Debug|Win32.ActiveCfg = Debug|Win32 + {0365E0AB-D32A-4F52-9223-4C79B12D4CB5}.Debug|Win32.Build.0 = Debug|Win32 + {0365E0AB-D32A-4F52-9223-4C79B12D4CB5}.Release|Win32.ActiveCfg = Release|Win32 + {0365E0AB-D32A-4F52-9223-4C79B12D4CB5}.Release|Win32.Build.0 = Release|Win32 + {3F5D8D39-3E7A-453C-BAF3-B037EC8D91CF}.Debug|Win32.ActiveCfg = Debug|Win32 + {3F5D8D39-3E7A-453C-BAF3-B037EC8D91CF}.Debug|Win32.Build.0 = Debug|Win32 + {3F5D8D39-3E7A-453C-BAF3-B037EC8D91CF}.Release|Win32.ActiveCfg = Release|Win32 + {3F5D8D39-3E7A-453C-BAF3-B037EC8D91CF}.Release|Win32.Build.0 = Release|Win32 + {438199D3-8E2C-4D8D-AB7C-1E08608F61C8}.Debug|Win32.ActiveCfg = Debug|Win32 + {438199D3-8E2C-4D8D-AB7C-1E08608F61C8}.Debug|Win32.Build.0 = Debug|Win32 + {438199D3-8E2C-4D8D-AB7C-1E08608F61C8}.Release|Win32.ActiveCfg = Release|Win32 + {438199D3-8E2C-4D8D-AB7C-1E08608F61C8}.Release|Win32.Build.0 = Release|Win32 + {466A40DE-9A2C-4369-8E3B-53CF577CABF0}.Debug|Win32.ActiveCfg = Debug|Win32 + {466A40DE-9A2C-4369-8E3B-53CF577CABF0}.Debug|Win32.Build.0 = Debug|Win32 + {466A40DE-9A2C-4369-8E3B-53CF577CABF0}.Release|Win32.ActiveCfg = Release|Win32 + {466A40DE-9A2C-4369-8E3B-53CF577CABF0}.Release|Win32.Build.0 = Release|Win32 + {A1B8A0EF-89C4-4F96-B9F7-A3A0FCE81983}.Debug|Win32.ActiveCfg = Debug|Win32 + {A1B8A0EF-89C4-4F96-B9F7-A3A0FCE81983}.Debug|Win32.Build.0 = Debug|Win32 + {A1B8A0EF-89C4-4F96-B9F7-A3A0FCE81983}.Release|Win32.ActiveCfg = Release|Win32 + {A1B8A0EF-89C4-4F96-B9F7-A3A0FCE81983}.Release|Win32.Build.0 = Release|Win32 + {E775EDCF-8DBB-435A-A427-0DAD70909A6B}.Debug|Win32.ActiveCfg = Debug|Win32 + {E775EDCF-8DBB-435A-A427-0DAD70909A6B}.Debug|Win32.Build.0 = Debug|Win32 + {E775EDCF-8DBB-435A-A427-0DAD70909A6B}.Release|Win32.ActiveCfg = Release|Win32 + {E775EDCF-8DBB-435A-A427-0DAD70909A6B}.Release|Win32.Build.0 = Release|Win32 + {256A2DDF-3A2F-4E8A-92AD-329EFC7A1C73}.Debug|Win32.ActiveCfg = Debug|Win32 + {256A2DDF-3A2F-4E8A-92AD-329EFC7A1C73}.Debug|Win32.Build.0 = Debug|Win32 + {256A2DDF-3A2F-4E8A-92AD-329EFC7A1C73}.Release|Win32.ActiveCfg = Release|Win32 + {256A2DDF-3A2F-4E8A-92AD-329EFC7A1C73}.Release|Win32.Build.0 = Release|Win32 + {2D6ED8F7-5967-487D-960C-C8157EDED988}.Debug|Win32.ActiveCfg = Debug|Win32 + {2D6ED8F7-5967-487D-960C-C8157EDED988}.Debug|Win32.Build.0 = Debug|Win32 + {2D6ED8F7-5967-487D-960C-C8157EDED988}.Release|Win32.ActiveCfg = Release|Win32 + {2D6ED8F7-5967-487D-960C-C8157EDED988}.Release|Win32.Build.0 = Release|Win32 + {E6C613A3-6C7B-4163-A4FB-B50103CB83E1}.Debug|Win32.ActiveCfg = Debug|Win32 + {E6C613A3-6C7B-4163-A4FB-B50103CB83E1}.Debug|Win32.Build.0 = Debug|Win32 + {E6C613A3-6C7B-4163-A4FB-B50103CB83E1}.Release|Win32.ActiveCfg = Release|Win32 + {E6C613A3-6C7B-4163-A4FB-B50103CB83E1}.Release|Win32.Build.0 = Release|Win32 + {4CDE32AF-A428-4A2C-9DD1-C9F27141C0F7}.Debug|Win32.ActiveCfg = Debug|Win32 + {4CDE32AF-A428-4A2C-9DD1-C9F27141C0F7}.Debug|Win32.Build.0 = Debug|Win32 + {4CDE32AF-A428-4A2C-9DD1-C9F27141C0F7}.Release|Win32.ActiveCfg = Release|Win32 + {4CDE32AF-A428-4A2C-9DD1-C9F27141C0F7}.Release|Win32.Build.0 = Release|Win32 + {C4200CD6-2FFC-43F1-BB05-8DD744324417}.Debug|Win32.ActiveCfg = Debug|Win32 + {C4200CD6-2FFC-43F1-BB05-8DD744324417}.Debug|Win32.Build.0 = Debug|Win32 + {C4200CD6-2FFC-43F1-BB05-8DD744324417}.Release|Win32.ActiveCfg = Release|Win32 + {C4200CD6-2FFC-43F1-BB05-8DD744324417}.Release|Win32.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/Chapter16/Chapter16.suo b/Chapter16/Chapter16.suo new file mode 100644 index 0000000..116d6b5 Binary files /dev/null and b/Chapter16/Chapter16.suo differ diff --git a/Chapter16/ISRingThreads/ISRingThreads.cpp b/Chapter16/ISRingThreads/ISRingThreads.cpp new file mode 100644 index 0000000..94e5b06 --- /dev/null +++ b/Chapter16/ISRingThreads/ISRingThreads.cpp @@ -0,0 +1,61 @@ +using namespace System; +using namespace System::Threading; + +ref class MyThread +{ +public: + static void ThreadFunc1(); + static void ThreadFunc2(); +}; + +void MyThread::ThreadFunc1() +{ + Console::WriteLine("Before long sleep"); + try + { + Thread::Sleep(Timeout::Infinite); + } + catch(ThreadInterruptedException^){/*continue processing*/} + Console::WriteLine("After long sleep"); +} + +void MyThread::ThreadFunc2() +{ + for (int i = 0; i < 5; i++) + { + Console::WriteLine("Thread {0}",i.ToString()); + Thread::Sleep(2); + } +} + + +void main() +{ + Thread ^thr1 = gcnew Thread(gcnew ThreadStart(&MyThread::ThreadFunc1)); + Thread ^thr2 = gcnew Thread(gcnew ThreadStart(&MyThread::ThreadFunc2)); + + Console::WriteLine("Sleep/interrupt thread"); + thr1->Start(); + + Thread::Sleep(4); + for (int i = 0; i < 4; i++) + { + Console::WriteLine("**Main2 {0}", i.ToString()); + Thread::Sleep(2); + } + thr1->Interrupt(); + thr1->Join(); + + Console::WriteLine("\nSuspend/resume thread"); + thr2->Start(); + + Thread::Sleep(8); + thr2->Suspend(); + + for (int i = 0; i < 4; i++) + { + Console::WriteLine("**Main1 {0}", i.ToString()); + Thread::Sleep(2); + } + thr2->Resume(); +} \ No newline at end of file diff --git a/Chapter16/ISRingThreads/ISRingThreads.vcproj b/Chapter16/ISRingThreads/ISRingThreads.vcproj new file mode 100644 index 0000000..88dd0fd --- /dev/null +++ b/Chapter16/ISRingThreads/ISRingThreads.vcproj @@ -0,0 +1,197 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Chapter16/ISRingThreads/ISRingThreads.vcproj.AMIDALA.Stephen Fraser.user b/Chapter16/ISRingThreads/ISRingThreads.vcproj.AMIDALA.Stephen Fraser.user new file mode 100644 index 0000000..196a6d1 --- /dev/null +++ b/Chapter16/ISRingThreads/ISRingThreads.vcproj.AMIDALA.Stephen Fraser.user @@ -0,0 +1,65 @@ + + + + + + + + + + + diff --git a/Chapter16/InterlockedVars/InterlockedVars.cpp b/Chapter16/InterlockedVars/InterlockedVars.cpp new file mode 100644 index 0000000..6990ebd --- /dev/null +++ b/Chapter16/InterlockedVars/InterlockedVars.cpp @@ -0,0 +1,41 @@ +using namespace System; +using namespace System::Threading; + +ref class MyThread +{ + static int iVal; + +public: + + static MyThread() + { + iVal = 5; + } + + void ThreadFunc(); +}; + +void MyThread::ThreadFunc() +{ + while (Interlocked::Increment(iVal) < 15) + { + Thread ^thr = Thread::CurrentThread; + Console::WriteLine("{0} {1}", thr->Name, iVal); + Thread::Sleep(1); + } +} + + +void main() +{ + MyThread ^myThr1 = gcnew MyThread(); + + Thread ^thr1 = gcnew Thread(gcnew ThreadStart(myThr1, &MyThread::ThreadFunc)); + Thread ^thr2 = gcnew Thread(gcnew ThreadStart(myThr1, &MyThread::ThreadFunc)); + + thr1->Name = "Thread1"; + thr2->Name = "Thread2"; + + thr1->Start(); + thr2->Start(); +} \ No newline at end of file diff --git a/Chapter16/InterlockedVars/InterlockedVars.vcproj b/Chapter16/InterlockedVars/InterlockedVars.vcproj new file mode 100644 index 0000000..e351f5d --- /dev/null +++ b/Chapter16/InterlockedVars/InterlockedVars.vcproj @@ -0,0 +1,197 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Chapter16/InterlockedVars/InterlockedVars.vcproj.AMIDALA.Stephen Fraser.user b/Chapter16/InterlockedVars/InterlockedVars.vcproj.AMIDALA.Stephen Fraser.user new file mode 100644 index 0000000..196a6d1 --- /dev/null +++ b/Chapter16/InterlockedVars/InterlockedVars.vcproj.AMIDALA.Stephen Fraser.user @@ -0,0 +1,65 @@ + + + + + + + + + + + diff --git a/Chapter16/JoiningThreads/JoiningThreads.cpp b/Chapter16/JoiningThreads/JoiningThreads.cpp new file mode 100644 index 0000000..3ec15eb --- /dev/null +++ b/Chapter16/JoiningThreads/JoiningThreads.cpp @@ -0,0 +1,32 @@ +using namespace System; +using namespace System::Threading; + +ref class MyThread +{ +public: + static void ThreadFunc(Object ^Name); +}; + +void MyThread::ThreadFunc(Object ^Name) +{ + for (int i = 0; i < 5; i++) + { + Console::WriteLine("{0} {1}", Name, i.ToString()); + Thread::Sleep(1); + } +} + +void main() +{ + Console::WriteLine("Before starting thread"); + + Thread ^thr1 = gcnew Thread(gcnew ParameterizedThreadStart(&MyThread::ThreadFunc)); + Thread ^thr2 = gcnew Thread(gcnew ParameterizedThreadStart(&MyThread::ThreadFunc)); + + thr1->Start("Thread1"); + thr1->Join(); + + thr2->Start("Thread2"); + + Console::WriteLine("End of Main"); +} \ No newline at end of file diff --git a/Chapter16/JoiningThreads/JoiningThreads.vcproj b/Chapter16/JoiningThreads/JoiningThreads.vcproj new file mode 100644 index 0000000..c553df3 --- /dev/null +++ b/Chapter16/JoiningThreads/JoiningThreads.vcproj @@ -0,0 +1,197 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Chapter16/JoiningThreads/JoiningThreads.vcproj.AMIDALA.Stephen Fraser.user b/Chapter16/JoiningThreads/JoiningThreads.vcproj.AMIDALA.Stephen Fraser.user new file mode 100644 index 0000000..196a6d1 --- /dev/null +++ b/Chapter16/JoiningThreads/JoiningThreads.vcproj.AMIDALA.Stephen Fraser.user @@ -0,0 +1,65 @@ + + + + + + + + + + + diff --git a/Chapter16/MutexSpawn/MutexSpawn.cpp b/Chapter16/MutexSpawn/MutexSpawn.cpp new file mode 100644 index 0000000..e01873f --- /dev/null +++ b/Chapter16/MutexSpawn/MutexSpawn.cpp @@ -0,0 +1,23 @@ +using namespace System; +using namespace System::Diagnostics; +using namespace System::Threading; + + +void main() +{ + Process^ proc1 = gcnew Process(); + proc1->StartInfo->FileName = "../debug/SyncByMutex.exe"; + proc1->StartInfo->Arguments = "1"; + proc1->StartInfo->UseShellExecute = false; + proc1->StartInfo->RedirectStandardInput = true; + proc1->Start(); + + Process^ proc2 = gcnew Process(); + proc2->StartInfo->FileName = "../debug/SyncByMutex.exe"; + proc2->StartInfo->Arguments = "2"; + proc2->StartInfo->UseShellExecute = false; + proc2->StartInfo->RedirectStandardInput = true; + proc2->Start(); + + Thread::Sleep(5000); // Added just to clean up console display +} \ No newline at end of file diff --git a/Chapter16/MutexSpawn/MutexSpawn.vcproj b/Chapter16/MutexSpawn/MutexSpawn.vcproj new file mode 100644 index 0000000..08f10f8 --- /dev/null +++ b/Chapter16/MutexSpawn/MutexSpawn.vcproj @@ -0,0 +1,197 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Chapter16/MutexSpawn/MutexSpawn.vcproj.AMIDALA.Stephen Fraser.user b/Chapter16/MutexSpawn/MutexSpawn.vcproj.AMIDALA.Stephen Fraser.user new file mode 100644 index 0000000..196a6d1 --- /dev/null +++ b/Chapter16/MutexSpawn/MutexSpawn.vcproj.AMIDALA.Stephen Fraser.user @@ -0,0 +1,65 @@ + + + + + + + + + + + diff --git a/Chapter16/SleepingThreads/SleepingThreads.cpp b/Chapter16/SleepingThreads/SleepingThreads.cpp new file mode 100644 index 0000000..2d4ca1d --- /dev/null +++ b/Chapter16/SleepingThreads/SleepingThreads.cpp @@ -0,0 +1,41 @@ +using namespace System; +using namespace System::Threading; + +ref class MyThread +{ +public: + static void ThreadFunc(); +}; + +void MyThread::ThreadFunc() +{ + for (int i = 0; i < 101; i++) + { + Thread ^thr = Thread::CurrentThread; + if (i % 10 == 0) + Console::WriteLine("{0} {1}", thr->Name, i.ToString()); + Thread::Sleep(10); + } +} + + +void main() +{ + Console::WriteLine("Main Program Starts"); + + Thread ^thr1 = gcnew Thread(gcnew ThreadStart(&MyThread::ThreadFunc)); + Thread ^thr2 = gcnew Thread(gcnew ThreadStart(&MyThread::ThreadFunc)); + + thr1->Name = "Thread1"; + thr2->Name = "Thread2"; + + thr1->Start(); + thr2->Start(); + + int iHour = 0; + int iMin = 0; + int iSec = 1; + Thread::Sleep(TimeSpan(iHour, iMin, iSec)); + + Console::WriteLine("Main Program Ends"); +} \ No newline at end of file diff --git a/Chapter16/SleepingThreads/SleepingThreads.vcproj b/Chapter16/SleepingThreads/SleepingThreads.vcproj new file mode 100644 index 0000000..8ad1754 --- /dev/null +++ b/Chapter16/SleepingThreads/SleepingThreads.vcproj @@ -0,0 +1,197 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Chapter16/SleepingThreads/SleepingThreads.vcproj.AMIDALA.Stephen Fraser.user b/Chapter16/SleepingThreads/SleepingThreads.vcproj.AMIDALA.Stephen Fraser.user new file mode 100644 index 0000000..196a6d1 --- /dev/null +++ b/Chapter16/SleepingThreads/SleepingThreads.vcproj.AMIDALA.Stephen Fraser.user @@ -0,0 +1,65 @@ + + + + + + + + + + + diff --git a/Chapter16/StartingThreads/StartingThreads.cpp b/Chapter16/StartingThreads/StartingThreads.cpp new file mode 100644 index 0000000..f62f66d --- /dev/null +++ b/Chapter16/StartingThreads/StartingThreads.cpp @@ -0,0 +1,54 @@ +using namespace System; +using namespace System::Threading; + +ref class MyThread +{ +public: + static void StaticThread(); + void NonStaticThread(Object ^name); +}; + +void MyThread::StaticThread() +{ + for (int i = 0; i < 50000001; i++) + { + if (i % 10000000 == 0) + Console::WriteLine("Static Thread {0}", i.ToString()); + } +} + +void MyThread::NonStaticThread(Object ^name) +{ + for (int i = 0; i < 50000001; i++) + { + if (i % 10000000 == 0) + Console::WriteLine("Member {0} Thread {1}", + name, // Parameter passed + i.ToString()); + } +} + +void main() +{ + Console::WriteLine("Main Program Starts"); + + // Creating a thread start delegate for a static method + ThreadStart ^thrStart = gcnew ThreadStart(&MyThread::StaticThread); + // Use the ThreadStart to create a Thread pointer Object + Thread ^thr1 = gcnew Thread(thrStart); + + MyThread ^myThr = gcnew MyThread(); + // Creating a Thread reference object in one line from a member method + Thread ^thr2 = gcnew Thread( + gcnew ParameterizedThreadStart(myThr, &MyThread::NonStaticThread)); + +// Uncomment for background vs foreground exploration +// thr1->IsBackground = true; +// thr2->IsBackground = true; + + // Actually starting the pointer and reference threads + thr1->Start(); + thr2->Start("Parameterized"); + + Console::WriteLine("Main Program Ends"); +} \ No newline at end of file diff --git a/Chapter16/StartingThreads/StartingThreads.vcproj b/Chapter16/StartingThreads/StartingThreads.vcproj new file mode 100644 index 0000000..b1cc836 --- /dev/null +++ b/Chapter16/StartingThreads/StartingThreads.vcproj @@ -0,0 +1,197 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Chapter16/StartingThreads/StartingThreads.vcproj.AMIDALA.Stephen Fraser.user b/Chapter16/StartingThreads/StartingThreads.vcproj.AMIDALA.Stephen Fraser.user new file mode 100644 index 0000000..196a6d1 --- /dev/null +++ b/Chapter16/StartingThreads/StartingThreads.vcproj.AMIDALA.Stephen Fraser.user @@ -0,0 +1,65 @@ + + + + + + + + + + + diff --git a/Chapter16/SyncByMonitor/SyncByMonitor.cpp b/Chapter16/SyncByMonitor/SyncByMonitor.cpp new file mode 100644 index 0000000..4679b4a --- /dev/null +++ b/Chapter16/SyncByMonitor/SyncByMonitor.cpp @@ -0,0 +1,75 @@ +using namespace System; +using namespace System::Threading; + +ref class MyThread +{ + static Object^ MonitorObject = gcnew Object(); + +public: + void TFuncOne(); + void TFuncTwo(); + void TFuncThree(); +}; + +void MyThread::TFuncOne() +{ + Console::WriteLine("TFuncOne enters monitor"); + Monitor::Enter(MonitorObject); + for (int i = 0; i < 3; i++) + { + Console::WriteLine("TFuncOne Waits {0}", i); + Monitor::Wait(MonitorObject); + Console::WriteLine("TFuncOne Pulses {0}", i); + Monitor::Pulse(MonitorObject); + Thread::Sleep(1); + } + Monitor::Exit(MonitorObject); + Console::WriteLine("TFuncOne exits monitor"); +} + +void MyThread::TFuncTwo() +{ + Console::WriteLine("TFuncTwo enters monitor"); + Monitor::Enter(MonitorObject); + for (int i = 0; i < 3; i++) + { + Console::WriteLine("TFuncTwo Pulses {0}", i); + Monitor::Pulse(MonitorObject); + Thread::Sleep(1); + Console::WriteLine("TFuncTwo Waits {0}", i); + Monitor::Wait(MonitorObject); + } + Monitor::Exit(MonitorObject); + Console::WriteLine("TFuncTwo exits monitor"); +} + +void MyThread::TFuncThree() +{ + if (!Monitor::TryEnter(MonitorObject)) + { + Console::WriteLine("TFuncThree was not able to lock"); + return; + } + Console::WriteLine("TFuncThree got a lock"); + + Monitor::Exit(MonitorObject); + Console::WriteLine("TFuncThree exits monitor"); +} + + +void main() +{ + MyThread ^myThr1 = gcnew MyThread(); + + (gcnew Thread(gcnew ThreadStart(myThr1, &MyThread::TFuncOne)))->Start(); + Thread::Sleep(2); + + (gcnew Thread(gcnew ThreadStart(myThr1, &MyThread::TFuncTwo)))->Start(); + Thread::Sleep(2); + + for (int i = 0; i < 2; i++) + { + (gcnew Thread(gcnew ThreadStart(myThr1, &MyThread::TFuncThree)))->Start(); + Thread::Sleep(50); + } +} \ No newline at end of file diff --git a/Chapter16/SyncByMonitor/SyncByMonitor.vcproj b/Chapter16/SyncByMonitor/SyncByMonitor.vcproj new file mode 100644 index 0000000..7d06c35 --- /dev/null +++ b/Chapter16/SyncByMonitor/SyncByMonitor.vcproj @@ -0,0 +1,197 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Chapter16/SyncByMonitor/SyncByMonitor.vcproj.AMIDALA.Stephen Fraser.user b/Chapter16/SyncByMonitor/SyncByMonitor.vcproj.AMIDALA.Stephen Fraser.user new file mode 100644 index 0000000..196a6d1 --- /dev/null +++ b/Chapter16/SyncByMonitor/SyncByMonitor.vcproj.AMIDALA.Stephen Fraser.user @@ -0,0 +1,65 @@ + + + + + + + + + + + diff --git a/Chapter16/SyncByMutex/SyncByMutex.cpp b/Chapter16/SyncByMutex/SyncByMutex.cpp new file mode 100644 index 0000000..acac7e4 --- /dev/null +++ b/Chapter16/SyncByMutex/SyncByMutex.cpp @@ -0,0 +1,43 @@ +using namespace System; +using namespace System::Threading; + +ref class MyThread +{ + static Mutex ^m = gcnew Mutex(false, "SyncByMutex"); +public: + static void ThreadFunc(); +}; + +void MyThread::ThreadFunc() +{ + Random^ Rand = gcnew Random; + + Thread ^thr = Thread::CurrentThread; + + for (int i = 0; i < 4; i++) + { + m->WaitOne(); + + Console::WriteLine("{0} Enter - {1}", thr->Name, i); + Thread::Sleep(Rand->Next(20, 100)); // Simulate Work + Console::WriteLine("{0} Exit - {1}", thr->Name, i); + m->ReleaseMutex(); + + Thread::Sleep(Rand->Next(20, 100)); + } +} + +int main(int argc, char *argv[]) +{ + MyThread ^myThr = gcnew MyThread(); + + Thread ^thr1 = gcnew Thread(gcnew ThreadStart(&MyThread::ThreadFunc)); + Thread ^thr2 = gcnew Thread(gcnew ThreadStart(&MyThread::ThreadFunc)); + + thr1->Name = String::Format("Process {0} - Thread 1", gcnew String(argv[1])); + thr2->Name = String::Format("Process {0} - Thread 2", gcnew String(argv[1])); + + thr1->Start(); + Thread::Sleep(50); + thr2->Start(); +} diff --git a/Chapter16/SyncByMutex/SyncByMutex.vcproj b/Chapter16/SyncByMutex/SyncByMutex.vcproj new file mode 100644 index 0000000..3d2dd6f --- /dev/null +++ b/Chapter16/SyncByMutex/SyncByMutex.vcproj @@ -0,0 +1,197 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Chapter16/SyncByMutex/SyncByMutex.vcproj.AMIDALA.Stephen Fraser.user b/Chapter16/SyncByMutex/SyncByMutex.vcproj.AMIDALA.Stephen Fraser.user new file mode 100644 index 0000000..196a6d1 --- /dev/null +++ b/Chapter16/SyncByMutex/SyncByMutex.vcproj.AMIDALA.Stephen Fraser.user @@ -0,0 +1,65 @@ + + + + + + + + + + + diff --git a/Chapter16/SyncByRWLock/SyncByRWLock.cpp b/Chapter16/SyncByRWLock/SyncByRWLock.cpp new file mode 100644 index 0000000..1f7a2d8 --- /dev/null +++ b/Chapter16/SyncByRWLock/SyncByRWLock.cpp @@ -0,0 +1,69 @@ +using namespace System; +using namespace System::Threading; + +ref class MyThread +{ + static ReaderWriterLock ^RWLock = gcnew ReaderWriterLock(); + static int iVal = 4; + +public: + static void ReaderThread(); + static void WriterThread(); +}; + +void MyThread::ReaderThread() +{ + String ^thrName = Thread::CurrentThread->Name; + while (true) + { + try + { + RWLock->AcquireReaderLock(2); + + Console::WriteLine("Reading in {0}. iVal is {1}", + thrName, iVal); + + RWLock->ReleaseReaderLock(); + Thread::Sleep(4); + } + catch (ApplicationException^) + { + Console::WriteLine("Reading in {0}. Timed out", thrName); + } + } +} + +void MyThread::WriterThread() +{ + while (iVal > 0) + { + RWLock->AcquireWriterLock(-1); + + Interlocked::Decrement(iVal); + Console::WriteLine("Writing iVal to {0}", iVal); + Thread::Sleep(20); + + RWLock->ReleaseWriterLock(); + } +} + + +void main() +{ + Thread ^thr1 = gcnew Thread(gcnew ThreadStart(&MyThread::ReaderThread)); + Thread ^thr2 = gcnew Thread(gcnew ThreadStart(&MyThread::ReaderThread)); + Thread ^thr3 = gcnew Thread(gcnew ThreadStart(&MyThread::WriterThread)); + + thr1->Name = "Thread1"; + thr2->Name = "Thread2"; + + thr1->IsBackground = true; + thr2->IsBackground = true; + + thr1->Start(); + thr2->Start(); + thr3->Start(); + + thr3->Join(); + Thread::Sleep(2); +} \ No newline at end of file diff --git a/Chapter16/SyncByRWLock/SyncByRWLock.vcproj b/Chapter16/SyncByRWLock/SyncByRWLock.vcproj new file mode 100644 index 0000000..8ede595 --- /dev/null +++ b/Chapter16/SyncByRWLock/SyncByRWLock.vcproj @@ -0,0 +1,197 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Chapter16/SyncByRWLock/SyncByRWLock.vcproj.AMIDALA.Stephen Fraser.user b/Chapter16/SyncByRWLock/SyncByRWLock.vcproj.AMIDALA.Stephen Fraser.user new file mode 100644 index 0000000..196a6d1 --- /dev/null +++ b/Chapter16/SyncByRWLock/SyncByRWLock.vcproj.AMIDALA.Stephen Fraser.user @@ -0,0 +1,65 @@ + + + + + + + + + + + diff --git a/Chapter16/ThreadPooling/ThreadPooling.cpp b/Chapter16/ThreadPooling/ThreadPooling.cpp new file mode 100644 index 0000000..c74cf7d --- /dev/null +++ b/Chapter16/ThreadPooling/ThreadPooling.cpp @@ -0,0 +1,31 @@ +using namespace System; +using namespace System::Threading; + +ref class MyThread +{ +public: + void ThreadFunc(Object^ stateInfo); +}; + +void MyThread::ThreadFunc(Object^ stateInfo) +{ + for (int i = 0; i < 10; i++) + { + Console::WriteLine("{0} {1}", stateInfo, i.ToString()); + Thread::Sleep(100); + } +} + + +void main() +{ + Console::WriteLine("Main Program Starts"); + + MyThread ^myThr1 = gcnew MyThread(); + + ThreadPool::QueueUserWorkItem(gcnew WaitCallback(myThr1, &MyThread::ThreadFunc), "Thread1"); + ThreadPool::QueueUserWorkItem(gcnew WaitCallback(myThr1, &MyThread::ThreadFunc), "Thread2"); + + Thread::Sleep(2000); + Console::WriteLine("Main Program Ends"); +} \ No newline at end of file diff --git a/Chapter16/ThreadPooling/ThreadPooling.vcproj b/Chapter16/ThreadPooling/ThreadPooling.vcproj new file mode 100644 index 0000000..3983918 --- /dev/null +++ b/Chapter16/ThreadPooling/ThreadPooling.vcproj @@ -0,0 +1,197 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Chapter16/ThreadPooling/ThreadPooling.vcproj.AMIDALA.Stephen Fraser.user b/Chapter16/ThreadPooling/ThreadPooling.vcproj.AMIDALA.Stephen Fraser.user new file mode 100644 index 0000000..196a6d1 --- /dev/null +++ b/Chapter16/ThreadPooling/ThreadPooling.vcproj.AMIDALA.Stephen Fraser.user @@ -0,0 +1,65 @@ + + + + + + + + + + + diff --git a/Chapter16/ThreadStaticVars/ThreadStaticVars.cpp b/Chapter16/ThreadStaticVars/ThreadStaticVars.cpp new file mode 100644 index 0000000..00828ac --- /dev/null +++ b/Chapter16/ThreadStaticVars/ThreadStaticVars.cpp @@ -0,0 +1,61 @@ +using namespace System; +using namespace System::Threading; + +ref class MyThread +{ +public: + + [ThreadStatic] + static int ^iVal; + +public: + static MyThread() + { + iVal = gcnew int; + } + + void ThreadFunc(); + void SubThreadFunc(); +}; + +void MyThread::ThreadFunc() +{ + iVal = gcnew int; + iVal = 7; + + SubThreadFunc(); +} + +void MyThread::SubThreadFunc() +{ + int max = *iVal + 5; + + while (*iVal < max) + { + Thread ^thr = Thread::CurrentThread; + Console::WriteLine("{0} {1}", thr->Name, iVal->ToString()); + Thread::Sleep(1); + (*iVal)++; + } +} + + +void main() +{ + Console::WriteLine("Before starting thread"); + + MyThread ^myThr1 = gcnew MyThread(); + + Thread ^thr1 = gcnew Thread(gcnew ThreadStart(myThr1, &MyThread::ThreadFunc)); + Thread ^thr2 = gcnew Thread(gcnew ThreadStart(myThr1, &MyThread::ThreadFunc)); + + Thread::CurrentThread->Name = "Main"; + thr1->Name = "Thread1"; + thr2->Name = "Thread2"; + + thr1->Start(); + thr2->Start(); + + myThr1->iVal = 5; + myThr1->SubThreadFunc(); +} \ No newline at end of file diff --git a/Chapter16/ThreadStaticVars/ThreadStaticVars.vcproj b/Chapter16/ThreadStaticVars/ThreadStaticVars.vcproj new file mode 100644 index 0000000..ad7cd35 --- /dev/null +++ b/Chapter16/ThreadStaticVars/ThreadStaticVars.vcproj @@ -0,0 +1,197 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Chapter16/ThreadStaticVars/ThreadStaticVars.vcproj.AMIDALA.Stephen Fraser.user b/Chapter16/ThreadStaticVars/ThreadStaticVars.vcproj.AMIDALA.Stephen Fraser.user new file mode 100644 index 0000000..196a6d1 --- /dev/null +++ b/Chapter16/ThreadStaticVars/ThreadStaticVars.vcproj.AMIDALA.Stephen Fraser.user @@ -0,0 +1,65 @@ + + + + + + + + + + + diff --git a/Chapter17/Async_TcpServer/Async_TcpServer.vcproj b/Chapter17/Async_TcpServer/Async_TcpServer.vcproj new file mode 100644 index 0000000..1d6ae7e --- /dev/null +++ b/Chapter17/Async_TcpServer/Async_TcpServer.vcproj @@ -0,0 +1,197 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Chapter17/Async_TcpServer/Async_TcpServer.vcproj.AMIDALA.Stephen Fraser.user b/Chapter17/Async_TcpServer/Async_TcpServer.vcproj.AMIDALA.Stephen Fraser.user new file mode 100644 index 0000000..196a6d1 --- /dev/null +++ b/Chapter17/Async_TcpServer/Async_TcpServer.vcproj.AMIDALA.Stephen Fraser.user @@ -0,0 +1,65 @@ + + + + + + + + + + + diff --git a/Chapter17/Async_TcpServer/TcpServer_Async.cpp b/Chapter17/Async_TcpServer/TcpServer_Async.cpp new file mode 100644 index 0000000..48f4798 --- /dev/null +++ b/Chapter17/Async_TcpServer/TcpServer_Async.cpp @@ -0,0 +1,104 @@ +using namespace System; +using namespace System::Net; +using namespace System::Net::Sockets; +using namespace System::Threading; +using namespace System::Text; + +ref class StateObject +{ +public: + property int bufSize; + property Socket ^workSocket; + property array^ message; + + StateObject(Socket^ sock, int bufsize) + { + workSocket = sock; + bufSize = bufsize; + message = gcnew array(bufsize); + } +}; + +ref class TcpServer +{ +public: + static void AcceptCB(IAsyncResult^ iar); + static void SendCB(IAsyncResult^ iar); + static void ReceiveCB(IAsyncResult^ iar); +}; + +void TcpServer::AcceptCB(IAsyncResult^ iar) +{ + TcpListener^ tcpListener = (TcpListener^)iar->AsyncState; + Socket^ client = tcpListener->EndAcceptSocket(iar); + + IPEndPoint^ clientEP = (IPEndPoint^)client->RemoteEndPoint; + + Console::WriteLine("Connected on IP: {0} Port: {1}", + clientEP->Address, clientEP->Port); + + // Send socket successful connection message + array^ msg = Encoding::ASCII->GetBytes( + String::Format("Successfully connection to the server on port {0}", + clientEP->Port)); + client->BeginSend(msg, 0, msg->Length, SocketFlags::None, + gcnew AsyncCallback(&TcpServer::SendCB), client); + + // Get message from client + StateObject^ so = gcnew StateObject(client, 1024); + client->BeginReceive(so->message, 0, so->bufSize, + SocketFlags::None, gcnew AsyncCallback(&TcpServer::ReceiveCB), so); + + // Get the next socket connection + Console::WriteLine("Waiting for client connections. [Return to Exit]"); + tcpListener->BeginAcceptSocket(gcnew AsyncCallback(&TcpServer::AcceptCB), + tcpListener); +} + +void TcpServer::SendCB(IAsyncResult^ iar) +{ + Socket^ client = (Socket^)iar->AsyncState; + client->EndSend(iar); +} + +void TcpServer::ReceiveCB(IAsyncResult^ iar) +{ + StateObject^ so = (StateObject^)iar->AsyncState; + Socket^ client = so->workSocket; + IPEndPoint^ clientEP = (IPEndPoint^)client->RemoteEndPoint; + + int rcv; + if ((rcv = client->EndReceive(iar)) > 0) // get message + { + Console::WriteLine("Port[{0}] {1}", + clientEP->Port, Encoding::ASCII->GetString(so->message, 0, rcv)); + + // echo message + client->BeginSend(so->message, 0, rcv, SocketFlags::None, + gcnew AsyncCallback(&TcpServer::SendCB), client); + + // set up for next receive + so = gcnew StateObject(client, 1024); + client->BeginReceive(so->message, 0, so->bufSize, + SocketFlags::None, gcnew AsyncCallback(&TcpServer::ReceiveCB), so); + } + else // connection closed + { + client->Close(); + Console::WriteLine("Connection to IP: {0} Port {1} closed.", + clientEP->Address, clientEP->Port); + } +} + +void main() +{ + TcpListener^ socket = gcnew TcpListener(IPAddress::Any, 12345); + socket->Start(); + + Console::WriteLine("Waiting for client connections. [Return to Exit]"); + socket->BeginAcceptSocket(gcnew AsyncCallback(&TcpServer::AcceptCB), + socket); + + // Exit on return key + Console::ReadLine(); +} diff --git a/Chapter17/Chapter17.sln b/Chapter17/Chapter17.sln new file mode 100644 index 0000000..1cddd07 --- /dev/null +++ b/Chapter17/Chapter17.sln @@ -0,0 +1,104 @@ + +Microsoft Visual Studio Solution File, Format Version 9.00 +# Visual Studio 2005 +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "TcpExamples", "TcpExamples", "{262B74DC-AF8B-400B-8042-177E0FE07FC3}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "TcpServer", "TcpServer\TcpServer.vcproj", "{2DF10409-F3FD-40CC-827C-F58CBDD447D2}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "TcpClient", "TcpClient\TcpClient.vcproj", "{21186920-C26D-4DC7-A84E-15CFF728BEA9}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "UdpExamples", "UdpExamples", "{F66037C4-6C9A-4FBE-BDD4-46044ED1A2E2}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "UdpServer", "UdpServer\UdpServer.vcproj", "{680773DE-337A-481B-BEDE-C4EDE38458AE}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "UdpClient", "UdpClient\UdpClient.vcproj", "{80D51950-3950-490A-A413-C487099357E0}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "UDPConnect", "UDPConnect\UDPConnect.vcproj", "{5F0372B3-D304-413F-9F85-D7F521ADA1CE}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "TcpServer_Listener", "TcpServer_Listener\TcpServer_Listener.vcproj", "{4BE01550-900E-4EE7-80F1-E77727106545}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "TcpServer_Stream", "TcpServer_Stream\TcpServer_Stream.vcproj", "{ADBFAC2E-BB43-4BB4-886D-EAD55D75BED8}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "TcpClient_Stream", "TcpClient_Stream\TcpClient_Stream.vcproj", "{A6DEC7F3-6890-4852-8B54-5D1B8380A98D}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "UdpServer_Helper", "UdpServer_Helper\UdpServer_Helper.vcproj", "{01F30092-DE91-49EF-ADBD-6D8227E5965E}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "UdpClient_Helper", "UdpClient_Helper\UdpClient_Helper.vcproj", "{E8E67426-A286-4250-A65F-7A9E4BB94B9B}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "UdpClient_Timeout", "UdpClient_Timeout\UdpClient_Timeout.vcproj", "{466B48CD-83CF-4A10-A236-7578C1E9E5C1}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "TcpServer_Async", "Async_TcpServer\Async_TcpServer.vcproj", "{F1A2C267-0CA7-4DEC-961C-E04F0856652E}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Win32 = Debug|Win32 + Release|Win32 = Release|Win32 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {2DF10409-F3FD-40CC-827C-F58CBDD447D2}.Debug|Win32.ActiveCfg = Debug|Win32 + {2DF10409-F3FD-40CC-827C-F58CBDD447D2}.Debug|Win32.Build.0 = Debug|Win32 + {2DF10409-F3FD-40CC-827C-F58CBDD447D2}.Release|Win32.ActiveCfg = Release|Win32 + {2DF10409-F3FD-40CC-827C-F58CBDD447D2}.Release|Win32.Build.0 = Release|Win32 + {21186920-C26D-4DC7-A84E-15CFF728BEA9}.Debug|Win32.ActiveCfg = Debug|Win32 + {21186920-C26D-4DC7-A84E-15CFF728BEA9}.Debug|Win32.Build.0 = Debug|Win32 + {21186920-C26D-4DC7-A84E-15CFF728BEA9}.Release|Win32.ActiveCfg = Release|Win32 + {21186920-C26D-4DC7-A84E-15CFF728BEA9}.Release|Win32.Build.0 = Release|Win32 + {680773DE-337A-481B-BEDE-C4EDE38458AE}.Debug|Win32.ActiveCfg = Debug|Win32 + {680773DE-337A-481B-BEDE-C4EDE38458AE}.Debug|Win32.Build.0 = Debug|Win32 + {680773DE-337A-481B-BEDE-C4EDE38458AE}.Release|Win32.ActiveCfg = Release|Win32 + {680773DE-337A-481B-BEDE-C4EDE38458AE}.Release|Win32.Build.0 = Release|Win32 + {80D51950-3950-490A-A413-C487099357E0}.Debug|Win32.ActiveCfg = Debug|Win32 + {80D51950-3950-490A-A413-C487099357E0}.Debug|Win32.Build.0 = Debug|Win32 + {80D51950-3950-490A-A413-C487099357E0}.Release|Win32.ActiveCfg = Release|Win32 + {80D51950-3950-490A-A413-C487099357E0}.Release|Win32.Build.0 = Release|Win32 + {5F0372B3-D304-413F-9F85-D7F521ADA1CE}.Debug|Win32.ActiveCfg = Debug|Win32 + {5F0372B3-D304-413F-9F85-D7F521ADA1CE}.Debug|Win32.Build.0 = Debug|Win32 + {5F0372B3-D304-413F-9F85-D7F521ADA1CE}.Release|Win32.ActiveCfg = Release|Win32 + {5F0372B3-D304-413F-9F85-D7F521ADA1CE}.Release|Win32.Build.0 = Release|Win32 + {4BE01550-900E-4EE7-80F1-E77727106545}.Debug|Win32.ActiveCfg = Debug|Win32 + {4BE01550-900E-4EE7-80F1-E77727106545}.Debug|Win32.Build.0 = Debug|Win32 + {4BE01550-900E-4EE7-80F1-E77727106545}.Release|Win32.ActiveCfg = Release|Win32 + {4BE01550-900E-4EE7-80F1-E77727106545}.Release|Win32.Build.0 = Release|Win32 + {ADBFAC2E-BB43-4BB4-886D-EAD55D75BED8}.Debug|Win32.ActiveCfg = Debug|Win32 + {ADBFAC2E-BB43-4BB4-886D-EAD55D75BED8}.Debug|Win32.Build.0 = Debug|Win32 + {ADBFAC2E-BB43-4BB4-886D-EAD55D75BED8}.Release|Win32.ActiveCfg = Release|Win32 + {ADBFAC2E-BB43-4BB4-886D-EAD55D75BED8}.Release|Win32.Build.0 = Release|Win32 + {A6DEC7F3-6890-4852-8B54-5D1B8380A98D}.Debug|Win32.ActiveCfg = Debug|Win32 + {A6DEC7F3-6890-4852-8B54-5D1B8380A98D}.Debug|Win32.Build.0 = Debug|Win32 + {A6DEC7F3-6890-4852-8B54-5D1B8380A98D}.Release|Win32.ActiveCfg = Release|Win32 + {A6DEC7F3-6890-4852-8B54-5D1B8380A98D}.Release|Win32.Build.0 = Release|Win32 + {01F30092-DE91-49EF-ADBD-6D8227E5965E}.Debug|Win32.ActiveCfg = Debug|Win32 + {01F30092-DE91-49EF-ADBD-6D8227E5965E}.Debug|Win32.Build.0 = Debug|Win32 + {01F30092-DE91-49EF-ADBD-6D8227E5965E}.Release|Win32.ActiveCfg = Release|Win32 + {01F30092-DE91-49EF-ADBD-6D8227E5965E}.Release|Win32.Build.0 = Release|Win32 + {E8E67426-A286-4250-A65F-7A9E4BB94B9B}.Debug|Win32.ActiveCfg = Debug|Win32 + {E8E67426-A286-4250-A65F-7A9E4BB94B9B}.Debug|Win32.Build.0 = Debug|Win32 + {E8E67426-A286-4250-A65F-7A9E4BB94B9B}.Release|Win32.ActiveCfg = Release|Win32 + {E8E67426-A286-4250-A65F-7A9E4BB94B9B}.Release|Win32.Build.0 = Release|Win32 + {466B48CD-83CF-4A10-A236-7578C1E9E5C1}.Debug|Win32.ActiveCfg = Debug|Win32 + {466B48CD-83CF-4A10-A236-7578C1E9E5C1}.Debug|Win32.Build.0 = Debug|Win32 + {466B48CD-83CF-4A10-A236-7578C1E9E5C1}.Release|Win32.ActiveCfg = Release|Win32 + {466B48CD-83CF-4A10-A236-7578C1E9E5C1}.Release|Win32.Build.0 = Release|Win32 + {F1A2C267-0CA7-4DEC-961C-E04F0856652E}.Debug|Win32.ActiveCfg = Debug|Win32 + {F1A2C267-0CA7-4DEC-961C-E04F0856652E}.Debug|Win32.Build.0 = Debug|Win32 + {F1A2C267-0CA7-4DEC-961C-E04F0856652E}.Release|Win32.ActiveCfg = Release|Win32 + {F1A2C267-0CA7-4DEC-961C-E04F0856652E}.Release|Win32.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(NestedProjects) = preSolution + {2DF10409-F3FD-40CC-827C-F58CBDD447D2} = {262B74DC-AF8B-400B-8042-177E0FE07FC3} + {21186920-C26D-4DC7-A84E-15CFF728BEA9} = {262B74DC-AF8B-400B-8042-177E0FE07FC3} + {4BE01550-900E-4EE7-80F1-E77727106545} = {262B74DC-AF8B-400B-8042-177E0FE07FC3} + {ADBFAC2E-BB43-4BB4-886D-EAD55D75BED8} = {262B74DC-AF8B-400B-8042-177E0FE07FC3} + {A6DEC7F3-6890-4852-8B54-5D1B8380A98D} = {262B74DC-AF8B-400B-8042-177E0FE07FC3} + {F1A2C267-0CA7-4DEC-961C-E04F0856652E} = {262B74DC-AF8B-400B-8042-177E0FE07FC3} + {680773DE-337A-481B-BEDE-C4EDE38458AE} = {F66037C4-6C9A-4FBE-BDD4-46044ED1A2E2} + {80D51950-3950-490A-A413-C487099357E0} = {F66037C4-6C9A-4FBE-BDD4-46044ED1A2E2} + {5F0372B3-D304-413F-9F85-D7F521ADA1CE} = {F66037C4-6C9A-4FBE-BDD4-46044ED1A2E2} + {01F30092-DE91-49EF-ADBD-6D8227E5965E} = {F66037C4-6C9A-4FBE-BDD4-46044ED1A2E2} + {E8E67426-A286-4250-A65F-7A9E4BB94B9B} = {F66037C4-6C9A-4FBE-BDD4-46044ED1A2E2} + {466B48CD-83CF-4A10-A236-7578C1E9E5C1} = {F66037C4-6C9A-4FBE-BDD4-46044ED1A2E2} + EndGlobalSection +EndGlobal diff --git a/Chapter17/Chapter17.suo b/Chapter17/Chapter17.suo new file mode 100644 index 0000000..80daaf8 Binary files /dev/null and b/Chapter17/Chapter17.suo differ diff --git a/Chapter17/TcpClient/TcpClient.cpp b/Chapter17/TcpClient/TcpClient.cpp new file mode 100644 index 0000000..a522910 --- /dev/null +++ b/Chapter17/TcpClient/TcpClient.cpp @@ -0,0 +1,47 @@ +using namespace System; +using namespace System::Net; +using namespace System::Net::Sockets; +using namespace System::Threading; +using namespace System::Text; + +void main() +{ + Socket^ server = gcnew Socket(AddressFamily::InterNetwork, + SocketType::Stream, ProtocolType::Tcp); + try + { + IPEndPoint^ iped = + gcnew IPEndPoint(IPAddress::Parse("127.0.0.1"), 12345); + server->Connect(iped); + } + catch (SocketException^ se) + { + Console::WriteLine("Connection to server failed with error: {0}", + se->Message); + return; + } + + array^ msg = gcnew array(1024); + int rcv = server->Receive(msg); + + Console::WriteLine(Encoding::ASCII->GetString(msg, 0, rcv)); + + while (true) + { + Console::Write("Message ('q' to quit): "); + String^ input = Console::ReadLine(); + + if (input->ToLower()->Equals("q")) + break; + + msg = Encoding::ASCII->GetBytes(input); + server->Send(msg, msg->Length, SocketFlags::None); + + msg = gcnew array(1024); + rcv = server->Receive(msg); + Console::WriteLine(Encoding::ASCII->GetString(msg, 0, rcv)); + } + Console::WriteLine("Ended connection with server."); + server->Shutdown(SocketShutdown::Both); + server->Close(); +} diff --git a/Chapter17/TcpClient/TcpClient.vcproj b/Chapter17/TcpClient/TcpClient.vcproj new file mode 100644 index 0000000..40337d5 --- /dev/null +++ b/Chapter17/TcpClient/TcpClient.vcproj @@ -0,0 +1,197 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Chapter17/TcpClient/TcpClient.vcproj.AMIDALA.Stephen Fraser.user b/Chapter17/TcpClient/TcpClient.vcproj.AMIDALA.Stephen Fraser.user new file mode 100644 index 0000000..196a6d1 --- /dev/null +++ b/Chapter17/TcpClient/TcpClient.vcproj.AMIDALA.Stephen Fraser.user @@ -0,0 +1,65 @@ + + + + + + + + + + + diff --git a/Chapter17/TcpClient_Stream/TcpClient_Stream.cpp b/Chapter17/TcpClient_Stream/TcpClient_Stream.cpp new file mode 100644 index 0000000..7d263bb --- /dev/null +++ b/Chapter17/TcpClient_Stream/TcpClient_Stream.cpp @@ -0,0 +1,54 @@ +using namespace System; +using namespace System::IO; +using namespace System::Net; +using namespace System::Net::Sockets; + +void main() +{ + TcpClient^ server; + StreamWriter^ writer; + StreamReader^ reader; + String^ msg; + + try + { + server = gcnew TcpClient("127.0.0.1", 12345); + + writer = gcnew StreamWriter(server->GetStream()); + reader = gcnew StreamReader(server->GetStream()); + } + catch (SocketException^ se) + { + Console::WriteLine("Connection to server failed with error: {0}", + se->Message); + return; + } + + msg = reader->ReadLine(); + + Console::WriteLine(msg); + + while (true) + { + Console::Write("Message ('q' to quit): "); + msg = Console::ReadLine(); + + if (msg->ToLower()->Equals("q")) + break; + + try + { + writer->WriteLine(msg); + writer->Flush(); + + msg = reader->ReadLine(); + Console::WriteLine(msg); + } + catch (IOException^) + { + break; // connection lost + } + } + Console::WriteLine("Ended connection with server."); + server->Close(); +} diff --git a/Chapter17/TcpClient_Stream/TcpClient_Stream.vcproj b/Chapter17/TcpClient_Stream/TcpClient_Stream.vcproj new file mode 100644 index 0000000..3b5243e --- /dev/null +++ b/Chapter17/TcpClient_Stream/TcpClient_Stream.vcproj @@ -0,0 +1,197 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Chapter17/TcpClient_Stream/TcpClient_Stream.vcproj.AMIDALA.Stephen Fraser.user b/Chapter17/TcpClient_Stream/TcpClient_Stream.vcproj.AMIDALA.Stephen Fraser.user new file mode 100644 index 0000000..196a6d1 --- /dev/null +++ b/Chapter17/TcpClient_Stream/TcpClient_Stream.vcproj.AMIDALA.Stephen Fraser.user @@ -0,0 +1,65 @@ + + + + + + + + + + + diff --git a/Chapter17/TcpServer/TcpServer.cpp b/Chapter17/TcpServer/TcpServer.cpp new file mode 100644 index 0000000..717ba97 --- /dev/null +++ b/Chapter17/TcpServer/TcpServer.cpp @@ -0,0 +1,66 @@ +using namespace System; +using namespace System::Net; +using namespace System::Net::Sockets; +using namespace System::Threading; +using namespace System::Text; + +ref class TcpServer +{ +public: + void ProcessThread(Object ^clientObj); +}; + +void TcpServer::ProcessThread(Object ^clientObj) +{ + Socket^ client = (Socket^)clientObj; + IPEndPoint^ clientEP = (IPEndPoint^)client->RemoteEndPoint; + + Console::WriteLine("Connected on IP: {0} Port: {1}", + clientEP->Address, clientEP->Port); + + array^ msg = Encoding::ASCII->GetBytes( + String::Format("Successfully connection to the server on port {0}", + clientEP->Port)); + client->Send(msg); + + int rcv; + while (true) + { + msg = gcnew array(1024); + + if ((rcv = client->Receive(msg)) == 0) + break; + + Console::WriteLine("Port[{0}] {1}", + clientEP->Port, Encoding::ASCII->GetString(msg, 0, rcv)); + + client->Send(msg, rcv, SocketFlags::None); + } + client->Close(); + Console::WriteLine("Connection to IP: {0} Port {1} closed.", + clientEP->Address, clientEP->Port); +} + +void main() +{ + TcpServer^ server = gcnew TcpServer(); + + Socket^ tcpListener = gcnew Socket(AddressFamily::InterNetwork, + SocketType::Stream, ProtocolType::Tcp); + + IPEndPoint^ iped = gcnew IPEndPoint(IPAddress::Any, 12345); + tcpListener->Bind(iped); + + tcpListener->Listen((int)SocketOptionName::MaxConnections); + + + while(true) + { + Console::WriteLine("Waiting for client connection."); + Socket^ client = tcpListener->Accept(); + + Thread ^thr = gcnew Thread( + gcnew ParameterizedThreadStart(server, &TcpServer::ProcessThread)); + thr->Start(client); + } +} diff --git a/Chapter17/TcpServer/TcpServer.vcproj b/Chapter17/TcpServer/TcpServer.vcproj new file mode 100644 index 0000000..2ebaaf5 --- /dev/null +++ b/Chapter17/TcpServer/TcpServer.vcproj @@ -0,0 +1,197 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Chapter17/TcpServer/TcpServer.vcproj.AMIDALA.Stephen Fraser.user b/Chapter17/TcpServer/TcpServer.vcproj.AMIDALA.Stephen Fraser.user new file mode 100644 index 0000000..196a6d1 --- /dev/null +++ b/Chapter17/TcpServer/TcpServer.vcproj.AMIDALA.Stephen Fraser.user @@ -0,0 +1,65 @@ + + + + + + + + + + + diff --git a/Chapter17/TcpServer_Listener/TcpServer_Listener.cpp b/Chapter17/TcpServer_Listener/TcpServer_Listener.cpp new file mode 100644 index 0000000..4eceb64 --- /dev/null +++ b/Chapter17/TcpServer_Listener/TcpServer_Listener.cpp @@ -0,0 +1,60 @@ +using namespace System; +using namespace System::Net; +using namespace System::Net::Sockets; +using namespace System::Threading; +using namespace System::Text; + +ref class TcpServer +{ +public: + void ProcessThread(Object ^clientObj); +}; + +void TcpServer::ProcessThread(Object ^clientObj) +{ + Socket^ client = (Socket^)clientObj; + IPEndPoint^ clientEP = (IPEndPoint^)client->RemoteEndPoint; + + Console::WriteLine("Connected on IP: {0} Port: {1}", + clientEP->Address, clientEP->Port); + + array^ msg = Encoding::ASCII->GetBytes( + String::Format("Successfully connection to the server on port {0}", + clientEP->Port)); + client->Send(msg); + + int rcv; + while (true) + { + msg = gcnew array(1024); + + if ((rcv = client->Receive(msg)) == 0) + break; + + Console::WriteLine("Port[{0}] {1}", + clientEP->Port, Encoding::ASCII->GetString(msg, 0, rcv)); + + client->Send(msg, rcv, SocketFlags::None); + } + client->Close(); + Console::WriteLine("Connection to IP: {0} Port {1} closed.", + clientEP->Address, clientEP->Port); +} + +void main() +{ + TcpServer^ server = gcnew TcpServer(); + + TcpListener^ socket = gcnew TcpListener(IPAddress::Any, 12345); + socket->Start(); + + while(true) + { + Console::WriteLine("Waiting for client connection."); + Socket^ client = socket->AcceptSocket(); + + Thread ^thr = gcnew Thread( + gcnew ParameterizedThreadStart(server, &TcpServer::ProcessThread)); + thr->Start(client); + } +} diff --git a/Chapter17/TcpServer_Listener/TcpServer_Listener.vcproj b/Chapter17/TcpServer_Listener/TcpServer_Listener.vcproj new file mode 100644 index 0000000..f5001e3 --- /dev/null +++ b/Chapter17/TcpServer_Listener/TcpServer_Listener.vcproj @@ -0,0 +1,197 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Chapter17/TcpServer_Listener/TcpServer_Listener.vcproj.AMIDALA.Stephen Fraser.user b/Chapter17/TcpServer_Listener/TcpServer_Listener.vcproj.AMIDALA.Stephen Fraser.user new file mode 100644 index 0000000..196a6d1 --- /dev/null +++ b/Chapter17/TcpServer_Listener/TcpServer_Listener.vcproj.AMIDALA.Stephen Fraser.user @@ -0,0 +1,65 @@ + + + + + + + + + + + diff --git a/Chapter17/TcpServer_Stream/TcpServer_Stream.cpp b/Chapter17/TcpServer_Stream/TcpServer_Stream.cpp new file mode 100644 index 0000000..607a794 --- /dev/null +++ b/Chapter17/TcpServer_Stream/TcpServer_Stream.cpp @@ -0,0 +1,67 @@ +using namespace System; +using namespace System::IO; +using namespace System::Net; +using namespace System::Net::Sockets; +using namespace System::Threading; + +ref class TcpServer +{ +public: + void ProcessThread(Object ^clientObj); +}; + +void TcpServer::ProcessThread(Object ^clientObj) +{ + TcpClient^ client = (TcpClient^)clientObj; + + IPEndPoint^ clientEP = (IPEndPoint^)client->Client->RemoteEndPoint; + + Console::WriteLine("Connected on IP: {0} Port: {1}", + clientEP->Address, clientEP->Port); + + StreamWriter^ writer = gcnew StreamWriter(client->GetStream()); + StreamReader^ reader = gcnew StreamReader(client->GetStream()); + + writer->WriteLine("Successfully connection to the server on port {0}", + clientEP->Port); + writer->Flush(); + + String^ msg; + while (true) + { + try + { + msg = reader->ReadLine(); + Console::WriteLine("Port[{0}] {1}", clientEP->Port, msg); + + writer->WriteLine(msg); + writer->Flush(); + } + catch (IOException^) + { + break; // connection lost + } + } + client->Close(); + + Console::WriteLine("Connection to IP: {0} Port {1} closed.", + clientEP->Address, clientEP->Port); +} + +void main() +{ + TcpServer^ server = gcnew TcpServer(); + + TcpListener^ socket = gcnew TcpListener(IPAddress::Any, 12345); + socket->Start(); + + while(true) + { + Console::WriteLine("Waiting for client connection."); + TcpClient^ client = socket->AcceptTcpClient(); + + Thread ^thr = gcnew Thread( + gcnew ParameterizedThreadStart(server, &TcpServer::ProcessThread)); + thr->Start(client); + } +} diff --git a/Chapter17/TcpServer_Stream/TcpServer_Stream.vcproj b/Chapter17/TcpServer_Stream/TcpServer_Stream.vcproj new file mode 100644 index 0000000..82e1fdf --- /dev/null +++ b/Chapter17/TcpServer_Stream/TcpServer_Stream.vcproj @@ -0,0 +1,197 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Chapter17/TcpServer_Stream/TcpServer_Stream.vcproj.AMIDALA.Stephen Fraser.user b/Chapter17/TcpServer_Stream/TcpServer_Stream.vcproj.AMIDALA.Stephen Fraser.user new file mode 100644 index 0000000..196a6d1 --- /dev/null +++ b/Chapter17/TcpServer_Stream/TcpServer_Stream.vcproj.AMIDALA.Stephen Fraser.user @@ -0,0 +1,65 @@ + + + + + + + + + + + diff --git a/Chapter17/UDPConnect/UDPConnect.cpp b/Chapter17/UDPConnect/UDPConnect.cpp new file mode 100644 index 0000000..6857116 --- /dev/null +++ b/Chapter17/UDPConnect/UDPConnect.cpp @@ -0,0 +1,30 @@ +using namespace System; +using namespace System::Net; +using namespace System::Net::Sockets; +using namespace System::Text; + +void main() +{ + Socket^ socket = gcnew Socket(AddressFamily::InterNetwork, SocketType::Dgram, ProtocolType::Udp); + + EndPoint^ Remote = gcnew IPEndPoint(IPAddress::Parse("127.0.0.1"), 54321); + socket->Connect(Remote); + + while (true) + { + Console::Write("Message ('q' to quit): "); + String^ input = Console::ReadLine(); + + if (input->ToLower()->Equals("q")) + break; + + array^ message = Encoding::ASCII->GetBytes(input); + socket->Send(message); + + message = gcnew array(1024); + int recv = socket->Receive(message); + + Console::WriteLine("[{0}] {1}", + Remote->ToString(), Encoding::ASCII->GetString(message, 0, recv)); + } +} diff --git a/Chapter17/UDPConnect/UDPConnect.vcproj b/Chapter17/UDPConnect/UDPConnect.vcproj new file mode 100644 index 0000000..fb19d27 --- /dev/null +++ b/Chapter17/UDPConnect/UDPConnect.vcproj @@ -0,0 +1,197 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Chapter17/UDPConnect/UDPConnect.vcproj.AMIDALA.Stephen Fraser.user b/Chapter17/UDPConnect/UDPConnect.vcproj.AMIDALA.Stephen Fraser.user new file mode 100644 index 0000000..196a6d1 --- /dev/null +++ b/Chapter17/UDPConnect/UDPConnect.vcproj.AMIDALA.Stephen Fraser.user @@ -0,0 +1,65 @@ + + + + + + + + + + + diff --git a/Chapter17/UdpClient/UdpClient.cpp b/Chapter17/UdpClient/UdpClient.cpp new file mode 100644 index 0000000..3adb8dc --- /dev/null +++ b/Chapter17/UdpClient/UdpClient.cpp @@ -0,0 +1,31 @@ +using namespace System; +using namespace System::Net; +using namespace System::Net::Sockets; +using namespace System::Text; + +void main() +{ + Socket^ socket = gcnew Socket(AddressFamily::InterNetwork, SocketType::Dgram, ProtocolType::Udp); + + //IPEndPoint^ ipep = gcnew IPEndPoint(IPAddress::Any, 54322); + //socket->Bind(ipep); + + EndPoint^ Remote = gcnew IPEndPoint(IPAddress::Parse("127.0.0.1"), 54321); + + while (true) + { + Console::Write("Message ('q' to quit): "); + String^ input = Console::ReadLine(); + + if (input->ToLower()->Equals("q")) + break; + + array^ message = Encoding::ASCII->GetBytes(input); + socket->SendTo(message, Remote); + + message = gcnew array(1024); + int recv = socket->ReceiveFrom(message, Remote); + Console::WriteLine("[{0}] {1}", + Remote->ToString(), Encoding::ASCII->GetString(message, 0, recv)); + } +} diff --git a/Chapter17/UdpClient/UdpClient.vcproj b/Chapter17/UdpClient/UdpClient.vcproj new file mode 100644 index 0000000..6d5bc02 --- /dev/null +++ b/Chapter17/UdpClient/UdpClient.vcproj @@ -0,0 +1,197 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Chapter17/UdpClient/UdpClient.vcproj.AMIDALA.Stephen Fraser.user b/Chapter17/UdpClient/UdpClient.vcproj.AMIDALA.Stephen Fraser.user new file mode 100644 index 0000000..196a6d1 --- /dev/null +++ b/Chapter17/UdpClient/UdpClient.vcproj.AMIDALA.Stephen Fraser.user @@ -0,0 +1,65 @@ + + + + + + + + + + + diff --git a/Chapter17/UdpClient_Helper/UdpClient_Helper.cpp b/Chapter17/UdpClient_Helper/UdpClient_Helper.cpp new file mode 100644 index 0000000..1020523 --- /dev/null +++ b/Chapter17/UdpClient_Helper/UdpClient_Helper.cpp @@ -0,0 +1,29 @@ +using namespace System; +using namespace System::Net; +using namespace System::Net::Sockets; +using namespace System::Text; + +void main() +{ + UdpClient^ client = gcnew UdpClient(); + + IPEndPoint^ Remote = + gcnew IPEndPoint(IPAddress::Parse("127.0.0.1"), 54321); + + while (true) + { + Console::Write("Message ('q' to quit): "); + String^ input = Console::ReadLine(); + + if (input->ToLower()->Equals("q")) + break; + + array^ message = Encoding::ASCII->GetBytes(input); + client->Send(message, message->Length, Remote); + + message = client->Receive(Remote); + Console::WriteLine("[{0}] {1}", + Remote->ToString(), + Encoding::ASCII->GetString(message, 0, message->Length)); + } +} diff --git a/Chapter17/UdpClient_Helper/UdpClient_Helper.vcproj b/Chapter17/UdpClient_Helper/UdpClient_Helper.vcproj new file mode 100644 index 0000000..2735ee8 --- /dev/null +++ b/Chapter17/UdpClient_Helper/UdpClient_Helper.vcproj @@ -0,0 +1,197 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Chapter17/UdpClient_Helper/UdpClient_Helper.vcproj.AMIDALA.Stephen Fraser.user b/Chapter17/UdpClient_Helper/UdpClient_Helper.vcproj.AMIDALA.Stephen Fraser.user new file mode 100644 index 0000000..196a6d1 --- /dev/null +++ b/Chapter17/UdpClient_Helper/UdpClient_Helper.vcproj.AMIDALA.Stephen Fraser.user @@ -0,0 +1,65 @@ + + + + + + + + + + + diff --git a/Chapter17/UdpClient_Timeout/UdpClient_Timeout.cpp b/Chapter17/UdpClient_Timeout/UdpClient_Timeout.cpp new file mode 100644 index 0000000..0d1a86b --- /dev/null +++ b/Chapter17/UdpClient_Timeout/UdpClient_Timeout.cpp @@ -0,0 +1,43 @@ +using namespace System; +using namespace System::Net; +using namespace System::Net::Sockets; +using namespace System::Text; + +void main() +{ + Socket^ socket = gcnew Socket(AddressFamily::InterNetwork, SocketType::Dgram, ProtocolType::Udp); + + EndPoint^ Remote = gcnew IPEndPoint(IPAddress::Parse("127.0.0.1"), 54321); + + if ((int)socket->GetSocketOption(SocketOptionLevel::Socket, + SocketOptionName::ReceiveTimeout) < 5000) + { + socket->SetSocketOption(SocketOptionLevel::Socket, + SocketOptionName::ReceiveTimeout, 5000 ); + } + + while (true) + { + Console::Write("Message ('q' to quit): "); + String^ input = Console::ReadLine(); + + if (input->ToLower()->Equals("q")) + break; + + array^ message = Encoding::ASCII->GetBytes(input); + socket->SendTo(message, Remote); + + message = gcnew array(1024); + try + { + int recv = socket->ReceiveFrom(message, Remote); + Console::WriteLine("[{0}] {1}", + Remote->ToString(), Encoding::ASCII->GetString(message, 0, recv)); + } + catch (SocketException^) + { + Console::WriteLine("Receive failed with a time out."); + Console::WriteLine("Make sure server is running."); + } + } +} diff --git a/Chapter17/UdpClient_Timeout/UdpClient_Timeout.vcproj b/Chapter17/UdpClient_Timeout/UdpClient_Timeout.vcproj new file mode 100644 index 0000000..b9e11d0 --- /dev/null +++ b/Chapter17/UdpClient_Timeout/UdpClient_Timeout.vcproj @@ -0,0 +1,197 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Chapter17/UdpClient_Timeout/UdpClient_Timeout.vcproj.AMIDALA.Stephen Fraser.user b/Chapter17/UdpClient_Timeout/UdpClient_Timeout.vcproj.AMIDALA.Stephen Fraser.user new file mode 100644 index 0000000..196a6d1 --- /dev/null +++ b/Chapter17/UdpClient_Timeout/UdpClient_Timeout.vcproj.AMIDALA.Stephen Fraser.user @@ -0,0 +1,65 @@ + + + + + + + + + + + diff --git a/Chapter17/UdpServer/UdpServer.cpp b/Chapter17/UdpServer/UdpServer.cpp new file mode 100644 index 0000000..a153800 --- /dev/null +++ b/Chapter17/UdpServer/UdpServer.cpp @@ -0,0 +1,27 @@ +using namespace System; +using namespace System::Net; +using namespace System::Net::Sockets; +using namespace System::Text; + +void main() +{ + Socket^ socket = gcnew Socket(AddressFamily::InterNetwork, SocketType::Dgram, ProtocolType::Udp); + IPEndPoint^ ipep = gcnew IPEndPoint(IPAddress::Any, 54321); + + socket->Bind(ipep); + + Console::WriteLine("Waiting for client connection."); + + while(true) + { + array^ message = gcnew array(1024); + EndPoint^ Remote = (EndPoint^) gcnew IPEndPoint(IPAddress::Any, 0); + + int recv = socket->ReceiveFrom(message, Remote); + + Console::WriteLine("[{0}] {1}", + Remote->ToString(), Encoding::ASCII->GetString(message, 0, recv)); + + socket->SendTo(message, recv, SocketFlags::None, Remote); + } +} diff --git a/Chapter17/UdpServer/UdpServer.vcproj b/Chapter17/UdpServer/UdpServer.vcproj new file mode 100644 index 0000000..6900dc9 --- /dev/null +++ b/Chapter17/UdpServer/UdpServer.vcproj @@ -0,0 +1,197 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Chapter17/UdpServer/UdpServer.vcproj.AMIDALA.Stephen Fraser.user b/Chapter17/UdpServer/UdpServer.vcproj.AMIDALA.Stephen Fraser.user new file mode 100644 index 0000000..196a6d1 --- /dev/null +++ b/Chapter17/UdpServer/UdpServer.vcproj.AMIDALA.Stephen Fraser.user @@ -0,0 +1,65 @@ + + + + + + + + + + + diff --git a/Chapter17/UdpServer_Helper/UdpServer_Helper.cpp b/Chapter17/UdpServer_Helper/UdpServer_Helper.cpp new file mode 100644 index 0000000..655993d --- /dev/null +++ b/Chapter17/UdpServer_Helper/UdpServer_Helper.cpp @@ -0,0 +1,27 @@ +using namespace System; +using namespace System::Net; +using namespace System::Net::Sockets; +using namespace System::Text; + +void main() +{ + IPEndPoint^ ipep = gcnew IPEndPoint(IPAddress::Any, 54321); + UdpClient^ server = gcnew UdpClient(ipep); + + Console::WriteLine("Waiting for client connection."); + + array^ message; + + while(true) + { + IPEndPoint^ Remote = gcnew IPEndPoint(IPAddress::Any, 0); + + message = server->Receive(Remote); + + Console::WriteLine("[{0}] [{1}]", + Remote->ToString(), Encoding::ASCII->GetString(message, 0, + message->Length)); + + server->Send(message, message->Length, Remote); + } +} diff --git a/Chapter17/UdpServer_Helper/UdpServer_Helper.vcproj b/Chapter17/UdpServer_Helper/UdpServer_Helper.vcproj new file mode 100644 index 0000000..aef110c --- /dev/null +++ b/Chapter17/UdpServer_Helper/UdpServer_Helper.vcproj @@ -0,0 +1,197 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Chapter17/UdpServer_Helper/UdpServer_Helper.vcproj.AMIDALA.Stephen Fraser.user b/Chapter17/UdpServer_Helper/UdpServer_Helper.vcproj.AMIDALA.Stephen Fraser.user new file mode 100644 index 0000000..196a6d1 --- /dev/null +++ b/Chapter17/UdpServer_Helper/UdpServer_Helper.vcproj.AMIDALA.Stephen Fraser.user @@ -0,0 +1,65 @@ + + + + + + + + + + + diff --git a/Chapter18/Chapter18.sln b/Chapter18/Chapter18.sln new file mode 100644 index 0000000..27a119e --- /dev/null +++ b/Chapter18/Chapter18.sln @@ -0,0 +1,80 @@ + +Microsoft Visual Studio Solution File, Format Version 9.00 +# Visual Studio 2005 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Reflecting", "Reflecting\Reflecting.vcproj", "{D57C7994-C5CA-4C31-BF87-63EFE42A7AD2}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Invoking", "Invoking\Invoking.vcproj", "{F16AA69E-6497-4512-A248-64BA097A3253}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Documentation", "Documentation\Documentation.vcproj", "{488B8693-1B6C-4804-B07A-02DEAC4CC4D0}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "DocumentationWriter", "DocumentationWriter\DocumentationWriter.vcproj", "{536903C6-2D97-4849-BB44-08ADD3623504}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "DocTestLib", "DocTestLib\DocTestLib.vcproj", "{3D5C227D-FAA6-48F9-88D1-40B325FF95F4}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ReferenceSharedAssembly", "ReferenceSharedAssembly\ReferenceSharedAssembly.vcproj", "{963F7AE5-DE33-4FFB-B0BE-5702B6240D9C}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "SharedAssembly", "SharedAssembly\SharedAssembly.vcproj", "{8B79896F-DC22-4EA5-B482-244AA45AE13E}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "EmbeddingResources", "EmbeddingResources\EmbeddingResources.vcproj", "{A8E0EDAF-FB78-45A8-B932-54DDC1ECF5C1}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "MultiCultureDate", "MultiCultureDate\MultiCultureDate.vcproj", "{9CB4E403-6500-4704-AB0A-9E1637CDFB87}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "MultiCultureApp", "MultiCultureApp\MultiCultureApp.vcproj", "{0C2FECB4-DF56-4184-BCCC-7533F216F31D}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "MultiCultureConsole", "MultiCultureConsole\MultiCultureConsole.vcproj", "{CDEE9252-3489-4FA9-B4EC-A03F189600F6}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Win32 = Debug|Win32 + Release|Win32 = Release|Win32 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {D57C7994-C5CA-4C31-BF87-63EFE42A7AD2}.Debug|Win32.ActiveCfg = Debug|Win32 + {D57C7994-C5CA-4C31-BF87-63EFE42A7AD2}.Debug|Win32.Build.0 = Debug|Win32 + {D57C7994-C5CA-4C31-BF87-63EFE42A7AD2}.Release|Win32.ActiveCfg = Release|Win32 + {D57C7994-C5CA-4C31-BF87-63EFE42A7AD2}.Release|Win32.Build.0 = Release|Win32 + {F16AA69E-6497-4512-A248-64BA097A3253}.Debug|Win32.ActiveCfg = Debug|Win32 + {F16AA69E-6497-4512-A248-64BA097A3253}.Debug|Win32.Build.0 = Debug|Win32 + {F16AA69E-6497-4512-A248-64BA097A3253}.Release|Win32.ActiveCfg = Release|Win32 + {F16AA69E-6497-4512-A248-64BA097A3253}.Release|Win32.Build.0 = Release|Win32 + {488B8693-1B6C-4804-B07A-02DEAC4CC4D0}.Debug|Win32.ActiveCfg = Debug|Win32 + {488B8693-1B6C-4804-B07A-02DEAC4CC4D0}.Debug|Win32.Build.0 = Debug|Win32 + {488B8693-1B6C-4804-B07A-02DEAC4CC4D0}.Release|Win32.ActiveCfg = Release|Win32 + {488B8693-1B6C-4804-B07A-02DEAC4CC4D0}.Release|Win32.Build.0 = Release|Win32 + {536903C6-2D97-4849-BB44-08ADD3623504}.Debug|Win32.ActiveCfg = Debug|Win32 + {536903C6-2D97-4849-BB44-08ADD3623504}.Debug|Win32.Build.0 = Debug|Win32 + {536903C6-2D97-4849-BB44-08ADD3623504}.Release|Win32.ActiveCfg = Release|Win32 + {536903C6-2D97-4849-BB44-08ADD3623504}.Release|Win32.Build.0 = Release|Win32 + {3D5C227D-FAA6-48F9-88D1-40B325FF95F4}.Debug|Win32.ActiveCfg = Debug|Win32 + {3D5C227D-FAA6-48F9-88D1-40B325FF95F4}.Debug|Win32.Build.0 = Debug|Win32 + {3D5C227D-FAA6-48F9-88D1-40B325FF95F4}.Release|Win32.ActiveCfg = Release|Win32 + {3D5C227D-FAA6-48F9-88D1-40B325FF95F4}.Release|Win32.Build.0 = Release|Win32 + {963F7AE5-DE33-4FFB-B0BE-5702B6240D9C}.Debug|Win32.ActiveCfg = Debug|Win32 + {963F7AE5-DE33-4FFB-B0BE-5702B6240D9C}.Debug|Win32.Build.0 = Debug|Win32 + {963F7AE5-DE33-4FFB-B0BE-5702B6240D9C}.Release|Win32.ActiveCfg = Release|Win32 + {963F7AE5-DE33-4FFB-B0BE-5702B6240D9C}.Release|Win32.Build.0 = Release|Win32 + {8B79896F-DC22-4EA5-B482-244AA45AE13E}.Debug|Win32.ActiveCfg = Debug|Win32 + {8B79896F-DC22-4EA5-B482-244AA45AE13E}.Debug|Win32.Build.0 = Debug|Win32 + {8B79896F-DC22-4EA5-B482-244AA45AE13E}.Release|Win32.ActiveCfg = Release|Win32 + {8B79896F-DC22-4EA5-B482-244AA45AE13E}.Release|Win32.Build.0 = Release|Win32 + {A8E0EDAF-FB78-45A8-B932-54DDC1ECF5C1}.Debug|Win32.ActiveCfg = Debug|Win32 + {A8E0EDAF-FB78-45A8-B932-54DDC1ECF5C1}.Debug|Win32.Build.0 = Debug|Win32 + {A8E0EDAF-FB78-45A8-B932-54DDC1ECF5C1}.Release|Win32.ActiveCfg = Release|Win32 + {A8E0EDAF-FB78-45A8-B932-54DDC1ECF5C1}.Release|Win32.Build.0 = Release|Win32 + {9CB4E403-6500-4704-AB0A-9E1637CDFB87}.Debug|Win32.ActiveCfg = Debug|Win32 + {9CB4E403-6500-4704-AB0A-9E1637CDFB87}.Debug|Win32.Build.0 = Debug|Win32 + {9CB4E403-6500-4704-AB0A-9E1637CDFB87}.Release|Win32.ActiveCfg = Release|Win32 + {9CB4E403-6500-4704-AB0A-9E1637CDFB87}.Release|Win32.Build.0 = Release|Win32 + {0C2FECB4-DF56-4184-BCCC-7533F216F31D}.Debug|Win32.ActiveCfg = Debug|Win32 + {0C2FECB4-DF56-4184-BCCC-7533F216F31D}.Debug|Win32.Build.0 = Debug|Win32 + {0C2FECB4-DF56-4184-BCCC-7533F216F31D}.Release|Win32.ActiveCfg = Release|Win32 + {0C2FECB4-DF56-4184-BCCC-7533F216F31D}.Release|Win32.Build.0 = Release|Win32 + {CDEE9252-3489-4FA9-B4EC-A03F189600F6}.Debug|Win32.ActiveCfg = Debug|Win32 + {CDEE9252-3489-4FA9-B4EC-A03F189600F6}.Debug|Win32.Build.0 = Debug|Win32 + {CDEE9252-3489-4FA9-B4EC-A03F189600F6}.Release|Win32.ActiveCfg = Release|Win32 + {CDEE9252-3489-4FA9-B4EC-A03F189600F6}.Release|Win32.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/Chapter18/Chapter18.suo b/Chapter18/Chapter18.suo new file mode 100644 index 0000000..a38e961 Binary files /dev/null and b/Chapter18/Chapter18.suo differ diff --git a/Chapter18/DocTestLib/AssemblyInfo.cpp b/Chapter18/DocTestLib/AssemblyInfo.cpp new file mode 100644 index 0000000..871b3a8 --- /dev/null +++ b/Chapter18/DocTestLib/AssemblyInfo.cpp @@ -0,0 +1,59 @@ +using namespace System::Reflection; +using namespace System::Runtime::CompilerServices; +using namespace System::Runtime::InteropServices; + +// +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +// +[assembly:AssemblyTitleAttribute("DocTestLib")]; +[assembly:AssemblyDescriptionAttribute("")]; +[assembly:AssemblyConfigurationAttribute("")]; +[assembly:AssemblyCompanyAttribute("")]; +[assembly:AssemblyProductAttribute("DocTestLib")]; +[assembly:AssemblyCopyrightAttribute("Copyright @ 2005")]; +[assembly:AssemblyTrademarkAttribute("")]; +[assembly:AssemblyCultureAttribute("")]; + +// +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the value or you can default the Revision and Build Numbers +// by using the '*' as shown below: + +[assembly:AssemblyVersionAttribute("1.0.*")]; + +// +// In order to sign your assembly you must specify a key to use. Refer to the +// Microsoft .NET Framework documentation for more information on assembly signing. +// +// Use the attributes below to control which key is used for signing. +// +// Notes: +// (*) If no key is specified, the assembly is not signed. +// (*) KeyName refers to a key that has been installed in the Crypto Service +// Provider (CSP) on your machine. KeyFile refers to a file which contains +// a key. +// (*) If the KeyFile and the KeyName values are both specified, the +// following processing occurs: +// (1) If the KeyName can be found in the CSP, that key is used. +// (2) If the KeyName does not exist and the KeyFile does exist, the key +// in the KeyFile is installed into the CSP and used. +// (*) In order to create a KeyFile, you can use the sn.exe (Strong Name) utility. +// When specifying the KeyFile, the location of the KeyFile should be +// relative to the project directory. +// (*) Delay Signing is an advanced option - see the Microsoft .NET Framework +// documentation for more information on this. +// +[assembly:AssemblyDelaySignAttribute(false)]; +[assembly:AssemblyKeyFileAttribute("")]; +[assembly:AssemblyKeyNameAttribute("")]; + +[assembly:ComVisible(false)]; + diff --git a/Chapter18/DocTestLib/DocTestLib.cpp b/Chapter18/DocTestLib/DocTestLib.cpp new file mode 100644 index 0000000..bb7acdc --- /dev/null +++ b/Chapter18/DocTestLib/DocTestLib.cpp @@ -0,0 +1,2 @@ +#include "DocTestLib.h" + diff --git a/Chapter18/DocTestLib/DocTestLib.h b/Chapter18/DocTestLib/DocTestLib.h new file mode 100644 index 0000000..f7706f3 --- /dev/null +++ b/Chapter18/DocTestLib/DocTestLib.h @@ -0,0 +1,35 @@ +// DocTestLib.h + +#pragma once + +using namespace System; +using namespace Documentation; + +namespace DocTestLib +{ + [Description("Stephen Fraser", + "This is TestClass1 to test the documentation Attribute.")] + [History("Stephen Fraser", "Original Version.", ModifyDate="11/27/02")] + [History("Stephen Fraser", "Added DoesNothing Method to do nothing.")] + public ref class TestClass1 + { + public: + [Description("Stephen Fraser", + "This is default constructor for TextClass1.")] + TestClass1() {} + + [Description("Stephen Fraser", + "This is method does nothing for TestClass1.")] + void DoesNothing() {} + + [Description("Stephen Fraser", "Added Variable property.")] + [History("Stephen Fraser", "Removed extra CodeDoc Attribute")] + property String^ Variable; + }; + + [Description("Stephen Fraser", + "This is TestClass2 to test the documentation Attribute.")] + public ref class TestClass2 + { + }; +} diff --git a/Chapter18/DocTestLib/DocTestLib.vcproj b/Chapter18/DocTestLib/DocTestLib.vcproj new file mode 100644 index 0000000..5bab27b --- /dev/null +++ b/Chapter18/DocTestLib/DocTestLib.vcproj @@ -0,0 +1,217 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Chapter18/DocTestLib/DocTestLib.vcproj.AMIDALA.Stephen Fraser.user b/Chapter18/DocTestLib/DocTestLib.vcproj.AMIDALA.Stephen Fraser.user new file mode 100644 index 0000000..b1fac18 --- /dev/null +++ b/Chapter18/DocTestLib/DocTestLib.vcproj.AMIDALA.Stephen Fraser.user @@ -0,0 +1,65 @@ + + + + + + + + + + + diff --git a/Chapter18/Documentation/AssemblyInfo.cpp b/Chapter18/Documentation/AssemblyInfo.cpp new file mode 100644 index 0000000..bd00466 --- /dev/null +++ b/Chapter18/Documentation/AssemblyInfo.cpp @@ -0,0 +1,59 @@ +using namespace System::Reflection; +using namespace System::Runtime::CompilerServices; +using namespace System::Runtime::InteropServices; + +// +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +// +[assembly:AssemblyTitleAttribute("Documentation")]; +[assembly:AssemblyDescriptionAttribute("")]; +[assembly:AssemblyConfigurationAttribute("")]; +[assembly:AssemblyCompanyAttribute("")]; +[assembly:AssemblyProductAttribute("Documentation")]; +[assembly:AssemblyCopyrightAttribute("Copyright @ 2005")]; +[assembly:AssemblyTrademarkAttribute("")]; +[assembly:AssemblyCultureAttribute("")]; + +// +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the value or you can default the Revision and Build Numbers +// by using the '*' as shown below: + +[assembly:AssemblyVersionAttribute("1.0.*")]; + +// +// In order to sign your assembly you must specify a key to use. Refer to the +// Microsoft .NET Framework documentation for more information on assembly signing. +// +// Use the attributes below to control which key is used for signing. +// +// Notes: +// (*) If no key is specified, the assembly is not signed. +// (*) KeyName refers to a key that has been installed in the Crypto Service +// Provider (CSP) on your machine. KeyFile refers to a file which contains +// a key. +// (*) If the KeyFile and the KeyName values are both specified, the +// following processing occurs: +// (1) If the KeyName can be found in the CSP, that key is used. +// (2) If the KeyName does not exist and the KeyFile does exist, the key +// in the KeyFile is installed into the CSP and used. +// (*) In order to create a KeyFile, you can use the sn.exe (Strong Name) utility. +// When specifying the KeyFile, the location of the KeyFile should be +// relative to the project directory. +// (*) Delay Signing is an advanced option - see the Microsoft .NET Framework +// documentation for more information on this. +// +[assembly:AssemblyDelaySignAttribute(false)]; +[assembly:AssemblyKeyFileAttribute("")]; +[assembly:AssemblyKeyNameAttribute("")]; + +[assembly:ComVisible(false)]; + diff --git a/Chapter18/Documentation/Documentation.cpp b/Chapter18/Documentation/Documentation.cpp new file mode 100644 index 0000000..cc6f061 --- /dev/null +++ b/Chapter18/Documentation/Documentation.cpp @@ -0,0 +1,57 @@ +#include "Documentation.h" + +namespace Documentation +{ + // ------------- DescriptionAttribute ------------------- + + DescriptionAttribute::DescriptionAttribute(String ^Author, String ^Description) + { + mAuthor = Author; + mDescription = Description; + mCompileDate = DateTime::Now; + } + + String^ DescriptionAttribute::Author::get() + { + return mAuthor; + } + + String^ DescriptionAttribute::Description::get() + { + return mDescription; + } + + String^ DescriptionAttribute::CompileDate::get() + { + return mCompileDate.ToShortDateString(); + } + + // ------------- HistoryAttribute ------------------- + + HistoryAttribute::HistoryAttribute(String ^Author, String ^Description) + { + mAuthor = Author; + mDescription = Description; + mModifyDate = DateTime::Now; + } + + String^ HistoryAttribute::Author::get() + { + return mAuthor; + } + + String^ HistoryAttribute::Description::get() + { + return mDescription; + } + + String^ HistoryAttribute::ModifyDate::get() + { + return mModifyDate.ToShortDateString(); + } + + void HistoryAttribute::ModifyDate::set(String ^value) + { + mModifyDate = Convert::ToDateTime(value); + } +} \ No newline at end of file diff --git a/Chapter18/Documentation/Documentation.h b/Chapter18/Documentation/Documentation.h new file mode 100644 index 0000000..a1bbab9 --- /dev/null +++ b/Chapter18/Documentation/Documentation.h @@ -0,0 +1,42 @@ +#pragma once + +using namespace System; +using namespace System::Text; +using namespace System::Reflection; + +namespace Documentation +{ + [AttributeUsage(AttributeTargets::All, Inherited=true, AllowMultiple=false)] + public ref class DescriptionAttribute : public Attribute + { + String ^mAuthor; + DateTime mCompileDate; + String ^mDescription; + + public: + DescriptionAttribute(String ^Author, String ^Description); + + property String^ Author { String^ get(); } + property String^ Description { String^ get(); } + property String^ CompileDate { String^ get(); } + }; + + [AttributeUsage(AttributeTargets::All, Inherited=true, AllowMultiple=true)] + public ref class HistoryAttribute : public Attribute + { + String ^mAuthor; + DateTime mModifyDate; + String ^mDescription; + + public: + HistoryAttribute(String ^Author, String ^Description); + + property String^ Author { String^ get(); } + property String^ Description { String^ get(); } + property String^ ModifyDate + { + String^ get(); + void set(String^ value); + } + }; +} diff --git a/Chapter18/Documentation/Documentation.vcproj b/Chapter18/Documentation/Documentation.vcproj new file mode 100644 index 0000000..c580c92 --- /dev/null +++ b/Chapter18/Documentation/Documentation.vcproj @@ -0,0 +1,213 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Chapter18/Documentation/Documentation.vcproj.AMIDALA.Stephen Fraser.user b/Chapter18/Documentation/Documentation.vcproj.AMIDALA.Stephen Fraser.user new file mode 100644 index 0000000..b1fac18 --- /dev/null +++ b/Chapter18/Documentation/Documentation.vcproj.AMIDALA.Stephen Fraser.user @@ -0,0 +1,65 @@ + + + + + + + + + + + diff --git a/Chapter18/DocumentationWriter/AssemblyInfo.cpp b/Chapter18/DocumentationWriter/AssemblyInfo.cpp new file mode 100644 index 0000000..22eab83 --- /dev/null +++ b/Chapter18/DocumentationWriter/AssemblyInfo.cpp @@ -0,0 +1,40 @@ +#include "stdafx.h" + +using namespace System; +using namespace System::Reflection; +using namespace System::Runtime::CompilerServices; +using namespace System::Runtime::InteropServices; +using namespace System::Security::Permissions; + +// +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +// +[assembly:AssemblyTitleAttribute("DocumentationWriter")]; +[assembly:AssemblyDescriptionAttribute("")]; +[assembly:AssemblyConfigurationAttribute("")]; +[assembly:AssemblyCompanyAttribute("")]; +[assembly:AssemblyProductAttribute("DocumentationWriter")]; +[assembly:AssemblyCopyrightAttribute("Copyright (c) 2005")]; +[assembly:AssemblyTrademarkAttribute("")]; +[assembly:AssemblyCultureAttribute("")]; + +// +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the value or you can default the Revision and Build Numbers +// by using the '*' as shown below: + +[assembly:AssemblyVersionAttribute("1.0.*")]; + +[assembly:ComVisible(false)]; + +[assembly:CLSCompliantAttribute(true)]; + +[assembly:SecurityPermission(SecurityAction::RequestMinimum, UnmanagedCode = true)]; diff --git a/Chapter18/DocumentationWriter/DocumentationWriter.cpp b/Chapter18/DocumentationWriter/DocumentationWriter.cpp new file mode 100644 index 0000000..f8cebb5 --- /dev/null +++ b/Chapter18/DocumentationWriter/DocumentationWriter.cpp @@ -0,0 +1,91 @@ +// DocumentationWriter.cpp : main project file. + +#include "stdafx.h" + +using namespace System; +using namespace Reflection; +using namespace Documentation; + +void DisplayDescription(Attribute ^attr) +{ + if (attr != nullptr) + { + DescriptionAttribute ^cd = (DescriptionAttribute^)attr; + Console::WriteLine(" Author: {0} -- Compiled: {1}", + cd->Author, cd->CompileDate); + Console::WriteLine(" Description: {0}", cd->Description); + Console::WriteLine(" ---- Change History ----"); + } + else + Console::WriteLine(" No Documentation"); +} + +void DisplayHistory(array^ attr) +{ + if (attr->Length > 0) + { + for each (HistoryAttribute^ cd in attr) + { + Console::WriteLine(" Author: {0} -- Modified: {1}", + cd->Author, cd->ModifyDate); + Console::WriteLine(" Description: {0}", cd->Description); + } + } + else + Console::WriteLine(" No changes"); +} + +void DisplayAttributes(MemberInfo ^info) +{ + DisplayDescription(Attribute::GetCustomAttribute(info, DescriptionAttribute::typeid)); + DisplayHistory(info->GetCustomAttributes(HistoryAttribute::typeid, true)); +} + +void PrintClassInfo(Type ^type) +{ + Console::WriteLine("Class: {0}", type->ToString()); + DisplayAttributes(type); + + array^ constructors = type->GetConstructors(); + for (int i = 0; i < constructors->Length; i++) + { + Console::WriteLine("Constructor: {0}", constructors[i]->ToString()); + DisplayAttributes(constructors[i]); + } + + array ^ methods = type->GetMethods((BindingFlags) + (BindingFlags::Public|BindingFlags::Instance|BindingFlags::DeclaredOnly)); + for (int i = 0; i < methods->Length; i++) + { + Console::WriteLine("Method: {0}", methods[i]->ToString()); + DisplayAttributes(methods[i]); + } + + array^ properties = type->GetProperties((BindingFlags) + (BindingFlags::Public|BindingFlags::Instance|BindingFlags::DeclaredOnly)); + for (int i = 0; i < properties->Length; i++) + { + Console::WriteLine("Property: {0}", properties[i]->ToString()); + DisplayAttributes(properties[i]); + } +} + +int main(array ^args) +{ + try + { + Assembly ^assembly = Assembly::LoadFrom(args[0]); + + array^ types = assembly->GetTypes(); + + for (int i = 0; i < types->Length; i++) + { + PrintClassInfo(types[i]); + Console::WriteLine(); + } + } + catch(System::IO::FileNotFoundException^) + { + Console::WriteLine("Can't find assembly: {0}\n", args[0]); + } +} diff --git a/Chapter18/DocumentationWriter/DocumentationWriter.vcproj b/Chapter18/DocumentationWriter/DocumentationWriter.vcproj new file mode 100644 index 0000000..5876765 --- /dev/null +++ b/Chapter18/DocumentationWriter/DocumentationWriter.vcproj @@ -0,0 +1,232 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Chapter18/DocumentationWriter/DocumentationWriter.vcproj.AMIDALA.Stephen Fraser.user b/Chapter18/DocumentationWriter/DocumentationWriter.vcproj.AMIDALA.Stephen Fraser.user new file mode 100644 index 0000000..196a6d1 --- /dev/null +++ b/Chapter18/DocumentationWriter/DocumentationWriter.vcproj.AMIDALA.Stephen Fraser.user @@ -0,0 +1,65 @@ + + + + + + + + + + + diff --git a/Chapter18/DocumentationWriter/stdafx.cpp b/Chapter18/DocumentationWriter/stdafx.cpp new file mode 100644 index 0000000..f2424a2 --- /dev/null +++ b/Chapter18/DocumentationWriter/stdafx.cpp @@ -0,0 +1,7 @@ +// stdafx.cpp : source file that includes just the standard includes +// DocumentationWriter.pch will be the pre-compiled header +// stdafx.obj will contain the pre-compiled type information + +#include "stdafx.h" + + diff --git a/Chapter18/DocumentationWriter/stdafx.h b/Chapter18/DocumentationWriter/stdafx.h new file mode 100644 index 0000000..39986bd --- /dev/null +++ b/Chapter18/DocumentationWriter/stdafx.h @@ -0,0 +1,8 @@ +// stdafx.h : include file for standard system include files, +// or project specific include files that are used frequently, but +// are changed infrequently +// + +#pragma once + +// TODO: reference additional headers your program requires here diff --git a/Chapter18/EmbeddingResources/Animal.resx b/Chapter18/EmbeddingResources/Animal.resx new file mode 100644 index 0000000..b01d864 --- /dev/null +++ b/Chapter18/EmbeddingResources/Animal.resx @@ -0,0 +1,54 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 1.0.0.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + Dog + + + Cat + + + Horse + + + Cow + + \ No newline at end of file diff --git a/Chapter18/EmbeddingResources/AssemblyInfo.cpp b/Chapter18/EmbeddingResources/AssemblyInfo.cpp new file mode 100644 index 0000000..aba4c6c --- /dev/null +++ b/Chapter18/EmbeddingResources/AssemblyInfo.cpp @@ -0,0 +1,59 @@ +using namespace System::Reflection; +using namespace System::Runtime::CompilerServices; +using namespace System::Runtime::InteropServices; + +// +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +// +[assembly:AssemblyTitleAttribute("EmbeddingResources")]; +[assembly:AssemblyDescriptionAttribute("")]; +[assembly:AssemblyConfigurationAttribute("")]; +[assembly:AssemblyCompanyAttribute("")]; +[assembly:AssemblyProductAttribute("EmbeddingResources")]; +[assembly:AssemblyCopyrightAttribute("Copyright @ 2005")]; +[assembly:AssemblyTrademarkAttribute("")]; +[assembly:AssemblyCultureAttribute("")]; + +// +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the value or you can default the Revision and Build Numbers +// by using the '*' as shown below: + +[assembly:AssemblyVersionAttribute("1.0.*")]; + +// +// In order to sign your assembly you must specify a key to use. Refer to the +// Microsoft .NET Framework documentation for more information on assembly signing. +// +// Use the attributes below to control which key is used for signing. +// +// Notes: +// (*) If no key is specified, the assembly is not signed. +// (*) KeyName refers to a key that has been installed in the Crypto Service +// Provider (CSP) on your machine. KeyFile refers to a file which contains +// a key. +// (*) If the KeyFile and the KeyName values are both specified, the +// following processing occurs: +// (1) If the KeyName can be found in the CSP, that key is used. +// (2) If the KeyName does not exist and the KeyFile does exist, the key +// in the KeyFile is installed into the CSP and used. +// (*) In order to create a KeyFile, you can use the sn.exe (Strong Name) utility. +// When specifying the KeyFile, the location of the KeyFile should be +// relative to the project directory. +// (*) Delay Signing is an advanced option - see the Microsoft .NET Framework +// documentation for more information on this. +// +[assembly:AssemblyDelaySignAttribute(false)]; +[assembly:AssemblyKeyFileAttribute("")]; +[assembly:AssemblyKeyNameAttribute("")]; + +[assembly:ComVisible(false)]; + diff --git a/Chapter18/EmbeddingResources/Color.txt b/Chapter18/EmbeddingResources/Color.txt new file mode 100644 index 0000000..bd2488f --- /dev/null +++ b/Chapter18/EmbeddingResources/Color.txt @@ -0,0 +1,4 @@ +Color1 = Blue +Color2 = Red +Color3 = Yellow +Color4 = Green \ No newline at end of file diff --git a/Chapter18/EmbeddingResources/EmbeddingResources.cpp b/Chapter18/EmbeddingResources/EmbeddingResources.cpp new file mode 100644 index 0000000..5bf2532 --- /dev/null +++ b/Chapter18/EmbeddingResources/EmbeddingResources.cpp @@ -0,0 +1,33 @@ +using namespace System; +using namespace System::Collections; +using namespace System::Reflection; +using namespace System::Resources; + +void main() +{ + Console::WriteLine("*** ResourceReader ***"); + ResourceReader ^rreader = gcnew ResourceReader("Fruit.resources"); + IDictionaryEnumerator ^denum = rreader->GetEnumerator(); + while (denum->MoveNext()) + { + Console::WriteLine("{0} = {1}", denum->Key, denum->Value); + } + rreader->Close(); + + ResourceManager ^rmgr; + + Console::WriteLine("\n*** ResourceManager From File ***"); + rmgr = ResourceManager::CreateFileBasedResourceManager("Fruit", "", nullptr); + Console::WriteLine(rmgr->GetString("Fruit1")); + Console::WriteLine(rmgr->GetString("Fruit2")); + Console::WriteLine(rmgr->GetString("Fruit3")); + Console::WriteLine(rmgr->GetString("Fruit4")); + + Console::WriteLine("\n*** ResourceManager From Assembly ***"); + Assembly ^assembly = Assembly::GetExecutingAssembly(); + rmgr = gcnew ResourceManager("Fruit", assembly); + Console::WriteLine(rmgr->GetObject("Fruit1")); + Console::WriteLine(rmgr->GetObject("Fruit2")); + Console::WriteLine(rmgr->GetObject("Fruit3")); + Console::WriteLine(rmgr->GetObject("Fruit4")); +} diff --git a/Chapter18/EmbeddingResources/EmbeddingResources.vcproj b/Chapter18/EmbeddingResources/EmbeddingResources.vcproj new file mode 100644 index 0000000..4ad1d0f --- /dev/null +++ b/Chapter18/EmbeddingResources/EmbeddingResources.vcproj @@ -0,0 +1,244 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Chapter18/EmbeddingResources/EmbeddingResources.vcproj.AMIDALA.Stephen Fraser.user b/Chapter18/EmbeddingResources/EmbeddingResources.vcproj.AMIDALA.Stephen Fraser.user new file mode 100644 index 0000000..196a6d1 --- /dev/null +++ b/Chapter18/EmbeddingResources/EmbeddingResources.vcproj.AMIDALA.Stephen Fraser.user @@ -0,0 +1,65 @@ + + + + + + + + + + + diff --git a/Chapter18/EmbeddingResources/fruit.resources b/Chapter18/EmbeddingResources/fruit.resources new file mode 100644 index 0000000..d64d266 Binary files /dev/null and b/Chapter18/EmbeddingResources/fruit.resources differ diff --git a/Chapter18/EmbeddingResources/fruit.txt b/Chapter18/EmbeddingResources/fruit.txt new file mode 100644 index 0000000..ec9acf3 --- /dev/null +++ b/Chapter18/EmbeddingResources/fruit.txt @@ -0,0 +1,4 @@ +Fruit1 = Apple +Fruit2 = Orange +Fruit3 = Grape +Fruit4 = Lemon diff --git a/Chapter18/Invoking/AssemblyInfo.cpp b/Chapter18/Invoking/AssemblyInfo.cpp new file mode 100644 index 0000000..b2dc606 --- /dev/null +++ b/Chapter18/Invoking/AssemblyInfo.cpp @@ -0,0 +1,40 @@ +#include "stdafx.h" + +using namespace System; +using namespace System::Reflection; +using namespace System::Runtime::CompilerServices; +using namespace System::Runtime::InteropServices; +using namespace System::Security::Permissions; + +// +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +// +[assembly:AssemblyTitleAttribute("Invoking")]; +[assembly:AssemblyDescriptionAttribute("")]; +[assembly:AssemblyConfigurationAttribute("")]; +[assembly:AssemblyCompanyAttribute("")]; +[assembly:AssemblyProductAttribute("Invoking")]; +[assembly:AssemblyCopyrightAttribute("Copyright (c) 2005")]; +[assembly:AssemblyTrademarkAttribute("")]; +[assembly:AssemblyCultureAttribute("")]; + +// +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the value or you can default the Revision and Build Numbers +// by using the '*' as shown below: + +[assembly:AssemblyVersionAttribute("1.0.*")]; + +[assembly:ComVisible(false)]; + +[assembly:CLSCompliantAttribute(true)]; + +[assembly:SecurityPermission(SecurityAction::RequestMinimum, UnmanagedCode = true)]; diff --git a/Chapter18/Invoking/Form1.h b/Chapter18/Invoking/Form1.h new file mode 100644 index 0000000..a8a9c69 --- /dev/null +++ b/Chapter18/Invoking/Form1.h @@ -0,0 +1,163 @@ +#pragma once + + +namespace Invoking { + + using namespace System; + using namespace System::ComponentModel; + using namespace System::Collections; + using namespace System::Windows::Forms; + using namespace System::Data; + using namespace System::Drawing; + using namespace System::Reflection; + + /// + /// 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. + /// + public ref class Form1 : public System::Windows::Forms::Form + { + public: + Form1(void) + { + InitializeComponent(); + // + //TODO: Add the constructor code here + // + } + + protected: + /// + /// Clean up any resources being used. + /// + ~Form1() + { + if (components) + { + delete components; + } + } + private: System::Windows::Forms::Label^ lbColor; + protected: + private: System::Windows::Forms::ComboBox^ cbColor; + + private: array ^ colors; + + private: + /// + /// Required designer variable. + /// + System::ComponentModel::Container ^components; + +#pragma region Windows Form Designer generated code + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + void InitializeComponent(void) + { + this->lbColor = (gcnew System::Windows::Forms::Label()); + this->cbColor = (gcnew System::Windows::Forms::ComboBox()); + this->SuspendLayout(); + // + // lbColor + // + this->lbColor->BorderStyle = System::Windows::Forms::BorderStyle::FixedSingle; + this->lbColor->Location = System::Drawing::Point(14, 42); + this->lbColor->Name = L"lbColor"; + this->lbColor->Size = System::Drawing::Size(264, 62); + this->lbColor->TabIndex = 3; + this->lbColor->Text = L"None"; + this->lbColor->TextAlign = System::Drawing::ContentAlignment::MiddleCenter; + // + // cbColor + // + this->cbColor->FormattingEnabled = true; + this->cbColor->Location = System::Drawing::Point(14, 14); + this->cbColor->Name = L"cbColor"; + this->cbColor->Size = System::Drawing::Size(264, 21); + this->cbColor->TabIndex = 2; + this->cbColor->SelectedIndexChanged += gcnew System::EventHandler(this, &Form1::cbColor_SelectedIndexChanged); + // + // Form1 + // + this->AutoScaleDimensions = System::Drawing::SizeF(6, 13); + this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font; + this->ClientSize = System::Drawing::Size(292, 118); + this->Controls->Add(this->lbColor); + this->Controls->Add(this->cbColor); + this->Name = L"Form1"; + this->Text = L"System Drawing Colors"; + this->Load += gcnew System::EventHandler(this, &Form1::Form1_Load); + this->ResumeLayout(false); + + } +#pragma endregion + private: + System::Void Form1_Load(System::Object^ sender, System::EventArgs^ e) + { + Type^ colorType = Color::typeid; + colors = colorType->GetProperties(); + + for (int i = 0; i < colors->Length; i++) + { + if (colors[i]->ToString()->IndexOf("System.Drawing.Color") >= 0) + cbColor->Items->Add(colors[i]->ToString()); + } + cbColor->SelectedIndex = 0; + } + + System::Void cbColor_SelectedIndexChanged(System::Object^ sender, System::EventArgs^ e) + { + static bool alternateWrite = true; + PropertyInfo ^ColorProp = colors[cbColor->SelectedIndex]; + + MethodInfo ^PropMethod = ColorProp->GetGetMethod(); + + lbColor->BackColor = (Color)PropMethod->Invoke(nullptr,nullptr); + + Assembly ^assembly = Assembly::Load("Invoking"); + + Type ^type; + if (alternateWrite) + type = assembly->GetType("Invoking.Writer1"); + else + type = assembly->GetType("Invoking.Writer2"); + + alternateWrite = !alternateWrite; + + MethodInfo ^ColorMethod = type->GetMethod("aColor"); + + Object ^writerInst = Activator::CreateInstance(type); + + array ^ args = gcnew array (1); + args[0] = PropMethod->Invoke(nullptr,nullptr); + + lbColor->Text = (String^)ColorMethod->Invoke(writerInst, args); + } + }; + + ref class Writer1 + { + public: + String ^aColor(Color ^col) + { + return String::Format("[Writer 1] {0}", col->ToString()); + } + }; + + ref class Writer2 + { + public: + String ^aColor(Color ^col) + { + return String::Format("[Writer 2] {0}", col->ToString()); + } + }; +} + diff --git a/Chapter18/Invoking/Form1.resx b/Chapter18/Invoking/Form1.resx new file mode 100644 index 0000000..7080a7d --- /dev/null +++ b/Chapter18/Invoking/Form1.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Chapter18/Invoking/Invoking.cpp b/Chapter18/Invoking/Invoking.cpp new file mode 100644 index 0000000..fea2ebe --- /dev/null +++ b/Chapter18/Invoking/Invoking.cpp @@ -0,0 +1,18 @@ +// Invoking.cpp : main project file. + +#include "stdafx.h" +#include "Form1.h" + +using namespace Invoking; + +[STAThreadAttribute] +int main(array ^args) +{ + // Enabling Windows XP visual effects before any controls are created + Application::EnableVisualStyles(); + Application::SetCompatibleTextRenderingDefault(false); + + // Create the main window and run it + Application::Run(gcnew Form1()); + return 0; +} diff --git a/Chapter18/Invoking/Invoking.vcproj b/Chapter18/Invoking/Invoking.vcproj new file mode 100644 index 0000000..9b8c950 --- /dev/null +++ b/Chapter18/Invoking/Invoking.vcproj @@ -0,0 +1,250 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Chapter18/Invoking/Invoking.vcproj.AMIDALA.Stephen Fraser.user b/Chapter18/Invoking/Invoking.vcproj.AMIDALA.Stephen Fraser.user new file mode 100644 index 0000000..196a6d1 --- /dev/null +++ b/Chapter18/Invoking/Invoking.vcproj.AMIDALA.Stephen Fraser.user @@ -0,0 +1,65 @@ + + + + + + + + + + + diff --git a/Chapter18/Invoking/stdafx.cpp b/Chapter18/Invoking/stdafx.cpp new file mode 100644 index 0000000..bbf6ea3 --- /dev/null +++ b/Chapter18/Invoking/stdafx.cpp @@ -0,0 +1,7 @@ +// stdafx.cpp : source file that includes just the standard includes +// Invoking.pch will be the pre-compiled header +// stdafx.obj will contain the pre-compiled type information + +#include "stdafx.h" + + diff --git a/Chapter18/Invoking/stdafx.h b/Chapter18/Invoking/stdafx.h new file mode 100644 index 0000000..46bef73 --- /dev/null +++ b/Chapter18/Invoking/stdafx.h @@ -0,0 +1,6 @@ +// stdafx.h : include file for standard system include files, +// or project specific include files that are used frequently, but +// are changed infrequently +#pragma once + +// TODO: reference additional headers your program requires here diff --git a/Chapter18/MultiCultureApp/AssemblyInfo.cpp b/Chapter18/MultiCultureApp/AssemblyInfo.cpp new file mode 100644 index 0000000..fe1b796 --- /dev/null +++ b/Chapter18/MultiCultureApp/AssemblyInfo.cpp @@ -0,0 +1,40 @@ +#include "stdafx.h" + +using namespace System; +using namespace System::Reflection; +using namespace System::Runtime::CompilerServices; +using namespace System::Runtime::InteropServices; +using namespace System::Security::Permissions; + +// +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +// +[assembly:AssemblyTitleAttribute("MultiCultureApp")]; +[assembly:AssemblyDescriptionAttribute("")]; +[assembly:AssemblyConfigurationAttribute("")]; +[assembly:AssemblyCompanyAttribute("")]; +[assembly:AssemblyProductAttribute("MultiCultureApp")]; +[assembly:AssemblyCopyrightAttribute("Copyright (c) 2005")]; +[assembly:AssemblyTrademarkAttribute("")]; +[assembly:AssemblyCultureAttribute("")]; + +// +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the value or you can default the Revision and Build Numbers +// by using the '*' as shown below: + +[assembly:AssemblyVersionAttribute("1.0.*")]; + +[assembly:ComVisible(false)]; + +[assembly:CLSCompliantAttribute(true)]; + +[assembly:SecurityPermission(SecurityAction::RequestMinimum, UnmanagedCode = true)]; diff --git a/Chapter18/MultiCultureApp/Form1.de-DE.resx b/Chapter18/MultiCultureApp/Form1.de-DE.resx new file mode 100644 index 0000000..5226b60 --- /dev/null +++ b/Chapter18/MultiCultureApp/Form1.de-DE.resx @@ -0,0 +1,136 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + + 113, 9 + + + 265, 23 + + + Hallo, ist mein Name Stephen + + + 390, 43 + + + Deutsch + + \ No newline at end of file diff --git a/Chapter18/MultiCultureApp/Form1.fr-FR.resx b/Chapter18/MultiCultureApp/Form1.fr-FR.resx new file mode 100644 index 0000000..352f62d --- /dev/null +++ b/Chapter18/MultiCultureApp/Form1.fr-FR.resx @@ -0,0 +1,133 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + + 247, 49 + + + Bonjour, mon nom est Stephen + + + 390, 67 + + + Français + + \ No newline at end of file diff --git a/Chapter18/MultiCultureApp/Form1.h b/Chapter18/MultiCultureApp/Form1.h new file mode 100644 index 0000000..848d5c3 --- /dev/null +++ b/Chapter18/MultiCultureApp/Form1.h @@ -0,0 +1,69 @@ +#pragma once + + +namespace MultiCultureApp +{ + using namespace System; + using namespace System::ComponentModel; + using namespace System::Collections; + using namespace System::Windows::Forms; + using namespace System::Data; + using namespace System::Drawing; + using namespace System::Globalization; + using namespace System::Threading; + + public ref class Form1 : public System::Windows::Forms::Form + { + public: + Form1(void) + { + Thread::CurrentThread->CurrentCulture = gcnew CultureInfo("fr-fr"); + Thread::CurrentThread->CurrentUICulture = Thread::CurrentThread->CurrentCulture; + InitializeComponent(); + } + + protected: + ~Form1() + { + if (components) + { + delete components; + } + } + private: + System::Windows::Forms::Label^ lbHello; + System::ComponentModel::Container ^components; + +#pragma region Windows Form Designer generated code + +void InitializeComponent(void) +{ + System::ComponentModel::ComponentResourceManager^ resources = (gcnew System::ComponentModel::ComponentResourceManager(Form1::typeid)); + this->lbHello = (gcnew System::Windows::Forms::Label()); + this->SuspendLayout(); + // + // lbHello + // + this->lbHello->AccessibleDescription = nullptr; + this->lbHello->AccessibleName = nullptr; + resources->ApplyResources(this->lbHello, L"lbHello"); + this->lbHello->Name = L"lbHello"; + // + // Form1 + // + this->AccessibleDescription = nullptr; + this->AccessibleName = nullptr; + resources->ApplyResources(this, L"$this"); + this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font; + this->BackgroundImage = nullptr; + this->Controls->Add(this->lbHello); + this->Font = nullptr; + this->Icon = nullptr; + this->Name = L"Form1"; + this->ResumeLayout(false); + +} +#pragma endregion + }; +} + diff --git a/Chapter18/MultiCultureApp/Form1.resx b/Chapter18/MultiCultureApp/Form1.resx new file mode 100644 index 0000000..5554966 --- /dev/null +++ b/Chapter18/MultiCultureApp/Form1.resx @@ -0,0 +1,167 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Windows.Forms.Form, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + lbHello + + + $this + + + System.Windows.Forms.Label, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + + 12, 9 + + + 390, 48 + + + 0 + + + 364, 23 + + + Hello, my name is Stephen + + + English + + + Microsoft Sans Serif, 12pt, style=Bold + + + + 0 + + + 6, 13 + + + Form1 + + + True + + \ No newline at end of file diff --git a/Chapter18/MultiCultureApp/MultiCultureApp.cpp b/Chapter18/MultiCultureApp/MultiCultureApp.cpp new file mode 100644 index 0000000..e85f5f7 --- /dev/null +++ b/Chapter18/MultiCultureApp/MultiCultureApp.cpp @@ -0,0 +1,18 @@ +// MultiCultureApp.cpp : main project file. + +#include "stdafx.h" +#include "Form1.h" + +using namespace MultiCultureApp; + +[STAThreadAttribute] +int main(array ^args) +{ + // Enabling Windows XP visual effects before any controls are created + Application::EnableVisualStyles(); + Application::SetCompatibleTextRenderingDefault(false); + + // Create the main window and run it + Application::Run(gcnew Form1()); + return 0; +} diff --git a/Chapter18/MultiCultureApp/MultiCultureApp.vcproj b/Chapter18/MultiCultureApp/MultiCultureApp.vcproj new file mode 100644 index 0000000..bd396e9 --- /dev/null +++ b/Chapter18/MultiCultureApp/MultiCultureApp.vcproj @@ -0,0 +1,260 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Chapter18/MultiCultureApp/MultiCultureApp.vcproj.AMIDALA.Stephen Fraser.user b/Chapter18/MultiCultureApp/MultiCultureApp.vcproj.AMIDALA.Stephen Fraser.user new file mode 100644 index 0000000..196a6d1 --- /dev/null +++ b/Chapter18/MultiCultureApp/MultiCultureApp.vcproj.AMIDALA.Stephen Fraser.user @@ -0,0 +1,65 @@ + + + + + + + + + + + diff --git a/Chapter18/MultiCultureApp/stdafx.cpp b/Chapter18/MultiCultureApp/stdafx.cpp new file mode 100644 index 0000000..68e4fe1 --- /dev/null +++ b/Chapter18/MultiCultureApp/stdafx.cpp @@ -0,0 +1,7 @@ +// stdafx.cpp : source file that includes just the standard includes +// MultiCultureApp.pch will be the pre-compiled header +// stdafx.obj will contain the pre-compiled type information + +#include "stdafx.h" + + diff --git a/Chapter18/MultiCultureApp/stdafx.h b/Chapter18/MultiCultureApp/stdafx.h new file mode 100644 index 0000000..46bef73 --- /dev/null +++ b/Chapter18/MultiCultureApp/stdafx.h @@ -0,0 +1,6 @@ +// stdafx.h : include file for standard system include files, +// or project specific include files that are used frequently, but +// are changed infrequently +#pragma once + +// TODO: reference additional headers your program requires here diff --git a/Chapter18/MultiCultureConsole/Colors.fr-fr.resx b/Chapter18/MultiCultureConsole/Colors.fr-fr.resx new file mode 100644 index 0000000..9e27569 --- /dev/null +++ b/Chapter18/MultiCultureConsole/Colors.fr-fr.resx @@ -0,0 +1,54 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 1.0.0.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + Rouge + + + Bleu + + + Vert + + + Jaune + + \ No newline at end of file diff --git a/Chapter18/MultiCultureConsole/Colors.resx b/Chapter18/MultiCultureConsole/Colors.resx new file mode 100644 index 0000000..872efb5 --- /dev/null +++ b/Chapter18/MultiCultureConsole/Colors.resx @@ -0,0 +1,54 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 1.0.0.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + Red + + + Blue + + + Green + + + Yellow + + \ No newline at end of file diff --git a/Chapter18/MultiCultureConsole/MultiCultureConsole.cpp b/Chapter18/MultiCultureConsole/MultiCultureConsole.cpp new file mode 100644 index 0000000..67ee616 --- /dev/null +++ b/Chapter18/MultiCultureConsole/MultiCultureConsole.cpp @@ -0,0 +1,24 @@ +using namespace System; +using namespace System::Reflection; +using namespace System::Resources; +using namespace System::Threading; +using namespace System::Globalization; + +void main() +{ + Assembly ^assembly = Assembly::GetExecutingAssembly(); + ResourceManager ^rmgr = + gcnew ResourceManager("MulticultureConsole.Colors", assembly); + + Console::WriteLine(rmgr->GetObject("Color1")); + Console::WriteLine(rmgr->GetObject("Color2")); + Console::WriteLine(rmgr->GetObject("Color3")); + Console::WriteLine(rmgr->GetObject("Color4")); + + Thread::CurrentThread->CurrentUICulture = gcnew CultureInfo("fr-fr"); + + Console::WriteLine(rmgr->GetObject("Color1")); + Console::WriteLine(rmgr->GetObject("Color2")); + Console::WriteLine(rmgr->GetObject("Color3")); + Console::WriteLine(rmgr->GetObject("Color4")); +} \ No newline at end of file diff --git a/Chapter18/MultiCultureConsole/MultiCultureConsole.vcproj b/Chapter18/MultiCultureConsole/MultiCultureConsole.vcproj new file mode 100644 index 0000000..94f0d77 --- /dev/null +++ b/Chapter18/MultiCultureConsole/MultiCultureConsole.vcproj @@ -0,0 +1,227 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Chapter18/MultiCultureConsole/MultiCultureConsole.vcproj.AMIDALA.Stephen Fraser.user b/Chapter18/MultiCultureConsole/MultiCultureConsole.vcproj.AMIDALA.Stephen Fraser.user new file mode 100644 index 0000000..196a6d1 --- /dev/null +++ b/Chapter18/MultiCultureConsole/MultiCultureConsole.vcproj.AMIDALA.Stephen Fraser.user @@ -0,0 +1,65 @@ + + + + + + + + + + + diff --git a/Chapter18/MultiCultureDate/MultiCultureDate.cpp b/Chapter18/MultiCultureDate/MultiCultureDate.cpp new file mode 100644 index 0000000..319c961 --- /dev/null +++ b/Chapter18/MultiCultureDate/MultiCultureDate.cpp @@ -0,0 +1,12 @@ +using namespace System; +using namespace System::Globalization; + +void main() +{ + DateTime dt = DateTime::Now; + + Console::WriteLine("en-us {0}", dt.ToString("D", gcnew CultureInfo("en-us"))); + Console::WriteLine("en-gb {0}", dt.ToString("D", gcnew CultureInfo("en-gb"))); + Console::WriteLine("fr-fr {0}", dt.ToString("D", gcnew CultureInfo("fr-fr"))); + Console::WriteLine("de-de {0}", dt.ToString("D", gcnew CultureInfo("de-de"))); +} \ No newline at end of file diff --git a/Chapter18/MultiCultureDate/MultiCultureDate.vcproj b/Chapter18/MultiCultureDate/MultiCultureDate.vcproj new file mode 100644 index 0000000..d72de8a --- /dev/null +++ b/Chapter18/MultiCultureDate/MultiCultureDate.vcproj @@ -0,0 +1,197 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Chapter18/MultiCultureDate/MultiCultureDate.vcproj.AMIDALA.Stephen Fraser.user b/Chapter18/MultiCultureDate/MultiCultureDate.vcproj.AMIDALA.Stephen Fraser.user new file mode 100644 index 0000000..196a6d1 --- /dev/null +++ b/Chapter18/MultiCultureDate/MultiCultureDate.vcproj.AMIDALA.Stephen Fraser.user @@ -0,0 +1,65 @@ + + + + + + + + + + + diff --git a/Chapter18/ReferenceSharedAssembly/ReferenceSharedAssembly.cpp b/Chapter18/ReferenceSharedAssembly/ReferenceSharedAssembly.cpp new file mode 100644 index 0000000..b7e0da6 --- /dev/null +++ b/Chapter18/ReferenceSharedAssembly/ReferenceSharedAssembly.cpp @@ -0,0 +1,8 @@ +using namespace System; +using namespace SharedAssembly; + +void main() +{ + SharedClass ^sa = gcnew SharedClass(); + Console::WriteLine(sa->Version); +} diff --git a/Chapter18/ReferenceSharedAssembly/ReferenceSharedAssembly.exe.config b/Chapter18/ReferenceSharedAssembly/ReferenceSharedAssembly.exe.config new file mode 100644 index 0000000..8539b7f --- /dev/null +++ b/Chapter18/ReferenceSharedAssembly/ReferenceSharedAssembly.exe.config @@ -0,0 +1,12 @@ + + + + + + + + + + diff --git a/Chapter18/ReferenceSharedAssembly/ReferenceSharedAssembly.vcproj b/Chapter18/ReferenceSharedAssembly/ReferenceSharedAssembly.vcproj new file mode 100644 index 0000000..ec04b65 --- /dev/null +++ b/Chapter18/ReferenceSharedAssembly/ReferenceSharedAssembly.vcproj @@ -0,0 +1,206 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Chapter18/ReferenceSharedAssembly/ReferenceSharedAssembly.vcproj.AMIDALA.Stephen Fraser.user b/Chapter18/ReferenceSharedAssembly/ReferenceSharedAssembly.vcproj.AMIDALA.Stephen Fraser.user new file mode 100644 index 0000000..196a6d1 --- /dev/null +++ b/Chapter18/ReferenceSharedAssembly/ReferenceSharedAssembly.vcproj.AMIDALA.Stephen Fraser.user @@ -0,0 +1,65 @@ + + + + + + + + + + + diff --git a/Chapter18/Reflecting/AssemblyInfo.cpp b/Chapter18/Reflecting/AssemblyInfo.cpp new file mode 100644 index 0000000..ac80439 --- /dev/null +++ b/Chapter18/Reflecting/AssemblyInfo.cpp @@ -0,0 +1,40 @@ +#include "stdafx.h" + +using namespace System; +using namespace System::Reflection; +using namespace System::Runtime::CompilerServices; +using namespace System::Runtime::InteropServices; +using namespace System::Security::Permissions; + +// +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +// +[assembly:AssemblyTitleAttribute("Reflecting")]; +[assembly:AssemblyDescriptionAttribute("")]; +[assembly:AssemblyConfigurationAttribute("")]; +[assembly:AssemblyCompanyAttribute("")]; +[assembly:AssemblyProductAttribute("Reflecting")]; +[assembly:AssemblyCopyrightAttribute("Copyright (c) 2005")]; +[assembly:AssemblyTrademarkAttribute("")]; +[assembly:AssemblyCultureAttribute("")]; + +// +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the value or you can default the Revision and Build Numbers +// by using the '*' as shown below: + +[assembly:AssemblyVersionAttribute("1.0.*")]; + +[assembly:ComVisible(false)]; + +[assembly:CLSCompliantAttribute(true)]; + +[assembly:SecurityPermission(SecurityAction::RequestMinimum, UnmanagedCode = true)]; diff --git a/Chapter18/Reflecting/Form1.h b/Chapter18/Reflecting/Form1.h new file mode 100644 index 0000000..636c0f0 --- /dev/null +++ b/Chapter18/Reflecting/Form1.h @@ -0,0 +1,252 @@ +#pragma once + + +namespace Reflecting +{ + using namespace System; + using namespace System::ComponentModel; + using namespace System::Collections; + using namespace System::Windows::Forms; + using namespace System::Data; + using namespace System::Drawing; + using namespace System::Reflection; + + public ref class Form1 : public System::Windows::Forms::Form + { + public: + Form1(void) + { + InitializeComponent(); + } + + protected: + ~Form1() + { + if (components) + { + delete components; + } + } + + private: + System::Windows::Forms::Label^ label3; + System::Windows::Forms::Label^ label4; + System::Windows::Forms::Label^ label5; + System::Windows::Forms::ListBox^ lbMethods; + System::Windows::Forms::ListBox^ lbProperties; + System::Windows::Forms::ListBox^ lbVariables; + System::Windows::Forms::GroupBox^ groupBox1; + System::Windows::Forms::ComboBox^ cbDataTypes; + System::Windows::Forms::ComboBox^ cbAssemblies; + System::Windows::Forms::Label^ label2; + System::Windows::Forms::Label^ label1; + + array^ types; + static array^ assemblies = + { + "System", + "System.Drawing", + "System.Xml", + "System.Windows.Forms", + "System.Data", + "mscorlib" + }; + + System::ComponentModel::Container ^components; + +#pragma region Windows Form Designer generated code + + void InitializeComponent(void) + { + this->label3 = (gcnew System::Windows::Forms::Label()); + this->label4 = (gcnew System::Windows::Forms::Label()); + this->label5 = (gcnew System::Windows::Forms::Label()); + this->lbMethods = (gcnew System::Windows::Forms::ListBox()); + this->lbProperties = (gcnew System::Windows::Forms::ListBox()); + this->lbVariables = (gcnew System::Windows::Forms::ListBox()); + this->groupBox1 = (gcnew System::Windows::Forms::GroupBox()); + this->cbDataTypes = (gcnew System::Windows::Forms::ComboBox()); + this->cbAssemblies = (gcnew System::Windows::Forms::ComboBox()); + this->label2 = (gcnew System::Windows::Forms::Label()); + this->label1 = (gcnew System::Windows::Forms::Label()); + this->groupBox1->SuspendLayout(); + this->SuspendLayout(); + // + // label3 + // + this->label3->AutoSize = true; + this->label3->Location = System::Drawing::Point(15, 94); + this->label3->Name = L"label3"; + this->label3->Size = System::Drawing::Size(51, 13); + this->label3->TabIndex = 11; + this->label3->Text = L"Methods:"; + // + // label4 + // + this->label4->AutoSize = true; + this->label4->Location = System::Drawing::Point(320, 94); + this->label4->Name = L"label4"; + this->label4->Size = System::Drawing::Size(57, 13); + this->label4->TabIndex = 12; + this->label4->Text = L"Properties:"; + // + // label5 + // + this->label5->AutoSize = true; + this->label5->Location = System::Drawing::Point(585, 94); + this->label5->Name = L"label5"; + this->label5->Size = System::Drawing::Size(53, 13); + this->label5->TabIndex = 13; + this->label5->Text = L"Variables:"; + // + // lbMethods + // + this->lbMethods->FormattingEnabled = true; + this->lbMethods->Location = System::Drawing::Point(15, 114); + this->lbMethods->Name = L"lbMethods"; + this->lbMethods->Size = System::Drawing::Size(293, 251); + this->lbMethods->TabIndex = 14; + // + // lbProperties + // + this->lbProperties->FormattingEnabled = true; + this->lbProperties->Location = System::Drawing::Point(320, 114); + this->lbProperties->Name = L"lbProperties"; + this->lbProperties->Size = System::Drawing::Size(250, 251); + this->lbProperties->TabIndex = 15; + // + // lbVariables + // + this->lbVariables->FormattingEnabled = true; + this->lbVariables->Location = System::Drawing::Point(585, 114); + this->lbVariables->Name = L"lbVariables"; + this->lbVariables->Size = System::Drawing::Size(202, 251); + this->lbVariables->TabIndex = 16; + // + // groupBox1 + // + this->groupBox1->Controls->Add(this->cbDataTypes); + this->groupBox1->Controls->Add(this->cbAssemblies); + this->groupBox1->Controls->Add(this->label2); + this->groupBox1->Controls->Add(this->label1); + this->groupBox1->Location = System::Drawing::Point(14, 12); + this->groupBox1->Name = L"groupBox1"; + this->groupBox1->Size = System::Drawing::Size(443, 72); + this->groupBox1->TabIndex = 10; + this->groupBox1->TabStop = false; + // + // cbDataTypes + // + this->cbDataTypes->FormattingEnabled = true; + this->cbDataTypes->Location = System::Drawing::Point(120, 41); + this->cbDataTypes->Name = L"cbDataTypes"; + this->cbDataTypes->Size = System::Drawing::Size(287, 21); + this->cbDataTypes->TabIndex = 3; + this->cbDataTypes->SelectedIndexChanged += gcnew System::EventHandler(this, &Form1::cbDataTypes_SelectedIndexChanged); + // + // cbAssemblies + // + this->cbAssemblies->FormattingEnabled = true; + this->cbAssemblies->Location = System::Drawing::Point(120, 16); + this->cbAssemblies->Name = L"cbAssemblies"; + this->cbAssemblies->Size = System::Drawing::Size(287, 21); + this->cbAssemblies->TabIndex = 2; + this->cbAssemblies->SelectedIndexChanged += gcnew System::EventHandler(this, &Form1::cbAssemblies_SelectedIndexChanged); + // + // label2 + // + this->label2->AutoSize = true; + this->label2->Location = System::Drawing::Point(24, 44); + this->label2->Name = L"label2"; + this->label2->Size = System::Drawing::Size(87, 13); + this->label2->TabIndex = 1; + this->label2->Text = L"Select data type:"; + // + // label1 + // + this->label1->AutoSize = true; + this->label1->Location = System::Drawing::Point(24, 19); + this->label1->Name = L"label1"; + this->label1->Size = System::Drawing::Size(86, 13); + this->label1->TabIndex = 0; + this->label1->Text = L"Select assembly:"; + // + // Form1 + // + this->AutoScaleDimensions = System::Drawing::SizeF(6, 13); + this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font; + this->ClientSize = System::Drawing::Size(801, 377); + this->Controls->Add(this->label3); + this->Controls->Add(this->label4); + this->Controls->Add(this->label5); + this->Controls->Add(this->lbMethods); + this->Controls->Add(this->lbProperties); + this->Controls->Add(this->lbVariables); + this->Controls->Add(this->groupBox1); + this->Name = L"Form1"; + this->Text = L"Assembly Viewer"; + this->Load += gcnew System::EventHandler(this, &Form1::Form1_Load); + this->groupBox1->ResumeLayout(false); + this->groupBox1->PerformLayout(); + this->ResumeLayout(false); + this->PerformLayout(); + } + +#pragma endregion + + private: + System::Void Form1_Load(System::Object^ sender, System::EventArgs^ e) + { + for each (String ^assembly in assemblies) + { + cbAssemblies->Items->Add(assembly); + } + cbAssemblies->SelectedIndex = 0; + } + + private: + System::Void cbAssemblies_SelectedIndexChanged(System::Object^ sender, System::EventArgs^ e) + { + Assembly^ assembly = Assembly::LoadWithPartialName( + assemblies[cbAssemblies->SelectedIndex]); + + types = assembly->GetTypes(); + + cbDataTypes->Items->Clear(); + + for (int i = 0; i < types->Length; i++) + { + cbDataTypes->Items->Add(types[i]->ToString()); + } + cbDataTypes->SelectedIndex = 0; + } + + private: + System::Void cbDataTypes_SelectedIndexChanged(System::Object^ sender, System::EventArgs^ e) + { + Type ^type = types[cbDataTypes->SelectedIndex]; + + array ^ methods = type->GetMethods(); + lbMethods->Items->Clear(); + for (int i = 0; i < methods->Length; i++) + { + lbMethods->Items->Add(methods[i]->ToString()); + } + + array ^ properties = type->GetProperties(); + lbProperties->Items->Clear(); + for (int i = 0; i < properties->Length; i++) + { + lbProperties->Items->Add(properties[i]->ToString()); + } + + array ^ variables = type->GetFields(); + lbVariables->Items->Clear(); + for (int i = 0; i < variables->Length; i++) + { + lbVariables->Items->Add(variables[i]->ToString()); + } + } + }; +} + diff --git a/Chapter18/Reflecting/Form1.resx b/Chapter18/Reflecting/Form1.resx new file mode 100644 index 0000000..7080a7d --- /dev/null +++ b/Chapter18/Reflecting/Form1.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Chapter18/Reflecting/Reflecting.cpp b/Chapter18/Reflecting/Reflecting.cpp new file mode 100644 index 0000000..7a04eac --- /dev/null +++ b/Chapter18/Reflecting/Reflecting.cpp @@ -0,0 +1,18 @@ +// Reflecting.cpp : main project file. + +#include "stdafx.h" +#include "Form1.h" + +using namespace Reflecting; + +[STAThreadAttribute] +int main(array ^args) +{ + // Enabling Windows XP visual effects before any controls are created + Application::EnableVisualStyles(); + Application::SetCompatibleTextRenderingDefault(false); + + // Create the main window and run it + Application::Run(gcnew Form1()); + return 0; +} diff --git a/Chapter18/Reflecting/Reflecting.vcproj b/Chapter18/Reflecting/Reflecting.vcproj new file mode 100644 index 0000000..b4a2038 --- /dev/null +++ b/Chapter18/Reflecting/Reflecting.vcproj @@ -0,0 +1,250 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Chapter18/Reflecting/Reflecting.vcproj.AMIDALA.Stephen Fraser.user b/Chapter18/Reflecting/Reflecting.vcproj.AMIDALA.Stephen Fraser.user new file mode 100644 index 0000000..8e1b0da --- /dev/null +++ b/Chapter18/Reflecting/Reflecting.vcproj.AMIDALA.Stephen Fraser.user @@ -0,0 +1,65 @@ + + + + + + + + + + + diff --git a/Chapter18/Reflecting/stdafx.cpp b/Chapter18/Reflecting/stdafx.cpp new file mode 100644 index 0000000..dacea22 --- /dev/null +++ b/Chapter18/Reflecting/stdafx.cpp @@ -0,0 +1,7 @@ +// stdafx.cpp : source file that includes just the standard includes +// Reflecting.pch will be the pre-compiled header +// stdafx.obj will contain the pre-compiled type information + +#include "stdafx.h" + + diff --git a/Chapter18/Reflecting/stdafx.h b/Chapter18/Reflecting/stdafx.h new file mode 100644 index 0000000..46bef73 --- /dev/null +++ b/Chapter18/Reflecting/stdafx.h @@ -0,0 +1,6 @@ +// stdafx.h : include file for standard system include files, +// or project specific include files that are used frequently, but +// are changed infrequently +#pragma once + +// TODO: reference additional headers your program requires here diff --git a/Chapter18/SharedAssembly/AssemblyInfo.cpp b/Chapter18/SharedAssembly/AssemblyInfo.cpp new file mode 100644 index 0000000..4d7d3b4 --- /dev/null +++ b/Chapter18/SharedAssembly/AssemblyInfo.cpp @@ -0,0 +1,57 @@ +using namespace System::Reflection; +using namespace System::Runtime::CompilerServices; +using namespace System::Runtime::InteropServices; + +// +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +// +[assembly:AssemblyTitleAttribute("A Shared Assembly")]; +[assembly:AssemblyDescriptionAttribute("An assembly that knows its version")]; +[assembly:AssemblyConfigurationAttribute("Release Version")]; +[assembly:AssemblyCompanyAttribute("ProCppCLI")]; +[assembly:AssemblyProductAttribute("Pro C++/CLI Series")]; +[assembly:AssemblyCopyrightAttribute("Copyright (C) by Stephen Fraser 2005")]; +[assembly:AssemblyTrademarkAttribute("ProCppCLI is a Trademark of blah")]; +[assembly:AssemblyCultureAttribute("")]; +// +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the value or you can default the Revision and Build Numbers +// by using the '*' as shown below: + +[assembly:AssemblyVersionAttribute("1.1.0.0")]; + +// +// In order to sign your assembly you must specify a key to use. Refer to the +// Microsoft .NET Framework documentation for more information on assembly signing. +// +// Use the attributes below to control which key is used for signing. +// +// Notes: +// (*) If no key is specified, the assembly is not signed. +// (*) KeyName refers to a key that has been installed in the Crypto Service +// Provider (CSP) on your machine. KeyFile refers to a file which contains +// a key. +// (*) If the KeyFile and the KeyName values are both specified, the +// following processing occurs: +// (1) If the KeyName can be found in the CSP, that key is used. +// (2) If the KeyName does not exist and the KeyFile does exist, the key +// in the KeyFile is installed into the CSP and used. +// (*) In order to create a KeyFile, you can use the sn.exe (Strong Name) utility. +// When specifying the KeyFile, the location of the KeyFile should be +// relative to the project directory. +// (*) Delay Signing is an advanced option - see the Microsoft .NET Framework +// documentation for more information on this. +// +[assembly:AssemblyDelaySignAttribute(false)]; +[assembly:AssemblyKeyFileAttribute("SharedAssembly.snk")]; +[assembly:AssemblyKeyNameAttribute("")]; + +[assembly:ComVisible(false)]; diff --git a/Chapter18/SharedAssembly/SharedAssembly.cpp b/Chapter18/SharedAssembly/SharedAssembly.cpp new file mode 100644 index 0000000..74e7d26 --- /dev/null +++ b/Chapter18/SharedAssembly/SharedAssembly.cpp @@ -0,0 +1,2 @@ +#include "SharedAssembly.h" + diff --git a/Chapter18/SharedAssembly/SharedAssembly.h b/Chapter18/SharedAssembly/SharedAssembly.h new file mode 100644 index 0000000..7faa06d --- /dev/null +++ b/Chapter18/SharedAssembly/SharedAssembly.h @@ -0,0 +1,20 @@ +#pragma once + +using namespace System; +using namespace System::Reflection; + +namespace SharedAssembly +{ + public ref class SharedClass + { + public: + property System::Version^ Version + { + System::Version^ get() + { + Assembly ^assembly = Assembly::GetExecutingAssembly(); + return assembly->GetName()->Version; + } + } + }; +} diff --git a/Chapter18/SharedAssembly/SharedAssembly.snk b/Chapter18/SharedAssembly/SharedAssembly.snk new file mode 100644 index 0000000..b387952 Binary files /dev/null and b/Chapter18/SharedAssembly/SharedAssembly.snk differ diff --git a/Chapter18/SharedAssembly/SharedAssembly.vcproj b/Chapter18/SharedAssembly/SharedAssembly.vcproj new file mode 100644 index 0000000..20a594f --- /dev/null +++ b/Chapter18/SharedAssembly/SharedAssembly.vcproj @@ -0,0 +1,213 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Chapter18/SharedAssembly/SharedAssembly.vcproj.AMIDALA.Stephen Fraser.user b/Chapter18/SharedAssembly/SharedAssembly.vcproj.AMIDALA.Stephen Fraser.user new file mode 100644 index 0000000..b1fac18 --- /dev/null +++ b/Chapter18/SharedAssembly/SharedAssembly.vcproj.AMIDALA.Stephen Fraser.user @@ -0,0 +1,65 @@ + + + + + + + + + + + diff --git a/Chapter19/AssertDenyPermit/AssemblyInfo.cpp b/Chapter19/AssertDenyPermit/AssemblyInfo.cpp new file mode 100644 index 0000000..72bdf1d --- /dev/null +++ b/Chapter19/AssertDenyPermit/AssemblyInfo.cpp @@ -0,0 +1,35 @@ +#include "stdafx.h" + +using namespace System::Reflection; +using namespace System::Runtime::CompilerServices; +using namespace System::Runtime::InteropServices; + +// +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +// +[assembly:AssemblyTitleAttribute("AssertDenyPermit")]; +[assembly:AssemblyDescriptionAttribute("")]; +[assembly:AssemblyConfigurationAttribute("")]; +[assembly:AssemblyCompanyAttribute("")]; +[assembly:AssemblyProductAttribute("AssertDenyPermit")]; +[assembly:AssemblyCopyrightAttribute("Copyright (c) 2005")]; +[assembly:AssemblyTrademarkAttribute("")]; +[assembly:AssemblyCultureAttribute("")]; + +// +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the value or you can default the Revision and Build Numbers +// by using the '*' as shown below: + +[assembly:AssemblyVersionAttribute("1.0.*")]; + +[assembly:ComVisible(false)]; + diff --git a/Chapter19/AssertDenyPermit/AssertDenyPermit.cpp b/Chapter19/AssertDenyPermit/AssertDenyPermit.cpp new file mode 100644 index 0000000..3f89d35 --- /dev/null +++ b/Chapter19/AssertDenyPermit/AssertDenyPermit.cpp @@ -0,0 +1,64 @@ +// AssertDenyPermit.cpp : main project file. + +#include "stdafx.h" + +using namespace System; +using namespace System::IO; +using namespace System::Security; +using namespace System::Security::Permissions; + +void AssertRead() +{ + CodeAccessPermission ^permission = + gcnew FileIOPermission(FileIOPermissionAccess::Read, "C:\\"); + + permission->Assert(); + StreamReader ^sr = File::OpenText("C:\\TestFile.txt"); + String ^s = sr->ReadLine(); + sr->Close(); + permission->RevertAssert(); + Console::WriteLine("Successful Read"); +} + +void NoAssertRead() +{ + StreamReader ^sr = File::OpenText("C:\\TestFile.txt"); + String ^s = sr->ReadLine(); + sr->Close(); + Console::WriteLine("Successful Read"); +} + +void main() +{ + // Deny Reading C: + CodeAccessPermission ^permissionRead = + gcnew FileIOPermission(FileIOPermissionAccess::Read, "C:\\"); + + permissionRead->Deny(); + try + { + AssertRead(); + NoAssertRead(); + } + catch(SecurityException^) + { + Console::WriteLine("Failed To Read"); + } + permissionRead->RevertDeny(); + + // Only allow Writing to C: + CodeAccessPermission ^permissionWrite = + gcnew FileIOPermission(FileIOPermissionAccess::Write, "C:\\"); + + permissionWrite->PermitOnly(); + try + { + AssertRead(); + NoAssertRead(); + } + catch(SecurityException^) + { + Console::WriteLine("Failed To Read\n"); + } + permissionWrite->RevertPermitOnly(); +} diff --git a/Chapter19/AssertDenyPermit/AssertDenyPermit.vcproj b/Chapter19/AssertDenyPermit/AssertDenyPermit.vcproj new file mode 100644 index 0000000..ce03ee6 --- /dev/null +++ b/Chapter19/AssertDenyPermit/AssertDenyPermit.vcproj @@ -0,0 +1,250 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Chapter19/AssertDenyPermit/ReadMe.txt b/Chapter19/AssertDenyPermit/ReadMe.txt new file mode 100644 index 0000000..817bddc --- /dev/null +++ b/Chapter19/AssertDenyPermit/ReadMe.txt @@ -0,0 +1,28 @@ +======================================================================== + APPLICATION : AssertDenyPermit Project Overview +======================================================================== + +AppWizard has created this AssertDenyPermit Application for you. + +This file contains a summary of what you will find in each of the files that +make up your AssertDenyPermit application. + +AssertDenyPermit.vcproj + This is the main project file for VC++ projects generated using an Application Wizard. + It contains information about the version of Visual C++ that generated the file, and + information about the platforms, configurations, and project features selected with the + Application Wizard. + +AssertDenyPermit.cpp + This is the main application source file. + +AssemblyInfo.cpp + Contains custom attributes for modifying assembly metadata. + +///////////////////////////////////////////////////////////////////////////// +Other notes: + +AppWizard uses "TODO:" to indicate parts of the source code you +should add to or customize. + +///////////////////////////////////////////////////////////////////////////// diff --git a/Chapter19/AssertDenyPermit/app.ico b/Chapter19/AssertDenyPermit/app.ico new file mode 100644 index 0000000..3a5525f Binary files /dev/null and b/Chapter19/AssertDenyPermit/app.ico differ diff --git a/Chapter19/AssertDenyPermit/app.rc b/Chapter19/AssertDenyPermit/app.rc new file mode 100644 index 0000000..807aa89 --- /dev/null +++ b/Chapter19/AssertDenyPermit/app.rc @@ -0,0 +1,63 @@ +// Microsoft Visual C++ generated resource script. +// +#include "resource.h" + +#define APSTUDIO_READONLY_SYMBOLS + +///////////////////////////////////////////////////////////////////////////// +#undef APSTUDIO_READONLY_SYMBOLS + +///////////////////////////////////////////////////////////////////////////// +// English (U.S.) resources + + +///////////////////////////////////////////////////////////////////////////// +// +// Icon +// + +// Icon placed first or with lowest ID value becomes application icon + +LANGUAGE 9, 1 +#pragma code_page(1252) +1 ICON "app.ico" + +#ifdef APSTUDIO_INVOKED +///////////////////////////////////////////////////////////////////////////// +// +// TEXTINCLUDE +// + +1 TEXTINCLUDE +BEGIN + "resource.h\0" + "\0" +END + +2 TEXTINCLUDE +BEGIN + "#include ""afxres.h""\r\n" + "\0" +END + +3 TEXTINCLUDE +BEGIN + "\0" +END + +#endif // APSTUDIO_INVOKED + +///////////////////////////////////////////////////////////////////////////// + + + +#ifndef APSTUDIO_INVOKED +///////////////////////////////////////////////////////////////////////////// +// +// Generated from the TEXTINCLUDE 3 resource. +// + + +///////////////////////////////////////////////////////////////////////////// +#endif // not APSTUDIO_INVOKED + diff --git a/Chapter19/AssertDenyPermit/resource.h b/Chapter19/AssertDenyPermit/resource.h new file mode 100644 index 0000000..d5ac7c4 --- /dev/null +++ b/Chapter19/AssertDenyPermit/resource.h @@ -0,0 +1,3 @@ +//{{NO_DEPENDENCIES}} +// Microsoft Visual C++ generated include file. +// Used by app.rc diff --git a/Chapter19/AssertDenyPermit/stdafx.cpp b/Chapter19/AssertDenyPermit/stdafx.cpp new file mode 100644 index 0000000..17378da --- /dev/null +++ b/Chapter19/AssertDenyPermit/stdafx.cpp @@ -0,0 +1,7 @@ +// stdafx.cpp : source file that includes just the standard includes +// AssertDenyPermit.pch will be the pre-compiled header +// stdafx.obj will contain the pre-compiled type information + +#include "stdafx.h" + + diff --git a/Chapter19/AssertDenyPermit/stdafx.h b/Chapter19/AssertDenyPermit/stdafx.h new file mode 100644 index 0000000..39986bd --- /dev/null +++ b/Chapter19/AssertDenyPermit/stdafx.h @@ -0,0 +1,8 @@ +// stdafx.h : include file for standard system include files, +// or project specific include files that are used frequently, but +// are changed infrequently +// + +#pragma once + +// TODO: reference additional headers your program requires here diff --git a/Chapter19/CASSecurity/AssemblyInfo.cpp b/Chapter19/CASSecurity/AssemblyInfo.cpp new file mode 100644 index 0000000..2fd8a17 --- /dev/null +++ b/Chapter19/CASSecurity/AssemblyInfo.cpp @@ -0,0 +1,35 @@ +#include "stdafx.h" + +using namespace System::Reflection; +using namespace System::Runtime::CompilerServices; +using namespace System::Runtime::InteropServices; + +// +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +// +[assembly:AssemblyTitleAttribute("CASSecurity")]; +[assembly:AssemblyDescriptionAttribute("")]; +[assembly:AssemblyConfigurationAttribute("")]; +[assembly:AssemblyCompanyAttribute("")]; +[assembly:AssemblyProductAttribute("CASSecurity")]; +[assembly:AssemblyCopyrightAttribute("Copyright (c) 2005")]; +[assembly:AssemblyTrademarkAttribute("")]; +[assembly:AssemblyCultureAttribute("")]; + +// +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the value or you can default the Revision and Build Numbers +// by using the '*' as shown below: + +[assembly:AssemblyVersionAttribute("1.0.*")]; + +[assembly:ComVisible(false)]; + diff --git a/Chapter19/CASSecurity/CASSecurity.cpp b/Chapter19/CASSecurity/CASSecurity.cpp new file mode 100644 index 0000000..f28b723 --- /dev/null +++ b/Chapter19/CASSecurity/CASSecurity.cpp @@ -0,0 +1,16 @@ +// CASSecurity.cpp : main project file. + +#include "stdafx.h" +#include "Form1.h" + +using namespace CASSecurity; + +[STAThreadAttribute] +int main(array ^args) +{ + // Enabling Windows XP visual effects before any controls are created + Application::EnableVisualStyles(); + // Create the main window and run it + Application::Run(gcnew Form1()); + return 0; +} diff --git a/Chapter19/CASSecurity/CASSecurity.vcproj b/Chapter19/CASSecurity/CASSecurity.vcproj new file mode 100644 index 0000000..4259216 --- /dev/null +++ b/Chapter19/CASSecurity/CASSecurity.vcproj @@ -0,0 +1,272 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Chapter19/CASSecurity/Form1.h b/Chapter19/CASSecurity/Form1.h new file mode 100644 index 0000000..7c3b103 --- /dev/null +++ b/Chapter19/CASSecurity/Form1.h @@ -0,0 +1,133 @@ +#pragma once +using namespace System; +using namespace System::ComponentModel; +using namespace System::Collections; +using namespace System::IO; +using namespace System::Windows::Forms; +using namespace System::Data; +using namespace System::Drawing; + +using namespace System::Security; +using namespace System::Security::Permissions; + + +namespace CASSecurity +{ + + public ref class Form1 : public System::Windows::Forms::Form + { + public: + Form1(void) + { + InitializeComponent(); + + try + { + (gcnew FileIOPermission(FileIOPermissionAccess::Read, "C:\\"))->Demand(); + } + catch(Exception^) + { + bnReadFile->Enabled = false; + } + + try + { + (gcnew FileIOPermission(FileIOPermissionAccess::Write, "C:\\"))->Demand(); + } + catch(Exception^) + { + bnWriteFile->Enabled = false; + } + } + + protected: + ~Form1() + { + if (components) + { + delete components; + } + } + private: + System::Windows::Forms::Label^ lbOutput; + System::Windows::Forms::Button^ bnWriteFile; + System::Windows::Forms::Button^ bnReadFile; + System::ComponentModel::Container ^components; + +#pragma region Windows Form Designer generated code + + void InitializeComponent(void) + { + this->lbOutput = (gcnew System::Windows::Forms::Label()); + this->bnWriteFile = (gcnew System::Windows::Forms::Button()); + this->bnReadFile = (gcnew System::Windows::Forms::Button()); + this->SuspendLayout(); + // + // lbOutput + // + this->lbOutput->AutoSize = true; + this->lbOutput->Location = System::Drawing::Point(68, 71); + this->lbOutput->Name = L"lbOutput"; + this->lbOutput->Size = System::Drawing::Size(0, 13); + this->lbOutput->TabIndex = 5; + // + // bnWriteFile + // + this->bnWriteFile->Location = System::Drawing::Point(170, 30); + this->bnWriteFile->Name = L"bnWriteFile"; + this->bnWriteFile->Size = System::Drawing::Size(75, 23); + this->bnWriteFile->TabIndex = 4; + this->bnWriteFile->Text = L"Write File"; + this->bnWriteFile->UseVisualStyleBackColor = true; + this->bnWriteFile->Click += + gcnew System::EventHandler(this, &Form1::bnWriteFile_Click); + // + // bnReadFile + // + this->bnReadFile->Location = System::Drawing::Point(48, 30); + this->bnReadFile->Name = L"bnReadFile"; + this->bnReadFile->Size = System::Drawing::Size(75, 23); + this->bnReadFile->TabIndex = 3; + this->bnReadFile->Text = L"Read File"; + this->bnReadFile->UseVisualStyleBackColor = true; + this->bnReadFile->Click += + gcnew System::EventHandler(this, &Form1::bnReadFile_Click); + // + // Form1 + // + this->AutoScaleDimensions = System::Drawing::SizeF(6, 13); + this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font; + this->ClientSize = System::Drawing::Size(292, 110); + this->Controls->Add(this->lbOutput); + this->Controls->Add(this->bnWriteFile); + this->Controls->Add(this->bnReadFile); + this->Name = L"Form1"; + this->Text = L"CAS Security Test"; + this->ResumeLayout(false); + this->PerformLayout(); + + } +#pragma endregion + + private: + System::Void bnReadFile_Click(System::Object^ sender, + System::EventArgs^ e) + { + StreamReader ^sr = File::OpenText("C:\\TestFile.txt"); + String ^s = sr->ReadLine(); + sr->Close(); + lbOutput->Text = s; + } + + private: + System::Void bnWriteFile_Click(System::Object^ sender, + System::EventArgs^ e) + { + StreamWriter ^sw = File::CreateText("C:\\TestFile.txt"); + sw->WriteLine("This is a test. This is only a test."); + sw->Close(); + lbOutput->Text = "Wrote text to file."; + } + }; +} + diff --git a/Chapter19/CASSecurity/Form1.resx b/Chapter19/CASSecurity/Form1.resx new file mode 100644 index 0000000..de824e1 --- /dev/null +++ b/Chapter19/CASSecurity/Form1.resx @@ -0,0 +1,110 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Chapter19/CASSecurity/ReadMe.txt b/Chapter19/CASSecurity/ReadMe.txt new file mode 100644 index 0000000..ce603ae --- /dev/null +++ b/Chapter19/CASSecurity/ReadMe.txt @@ -0,0 +1,33 @@ +======================================================================== + APPLICATION : CASSecurity Project Overview +======================================================================== + +AppWizard has created this CASSecurity Application for you. + +This file contains a summary of what you will find in each of the files that +make up your CASSecurity application. + +CASSecurity.vcproj + This is the main project file for VC++ projects generated using an Application Wizard. + It contains information about the version of Visual C++ that generated the file, and + information about the platforms, configurations, and project features selected with the + Application Wizard. + +CASSecurity.cpp + This is the main application source file. + Contains the code to display the form. + +Form1.h + Contains the implementation of your form class and InitializeComponent() function. + +AssemblyInfo.cpp + Contains custom attributes for modifying assembly metadata. + +///////////////////////////////////////////////////////////////////////////// +Other standard files: + +StdAfx.h, StdAfx.cpp + These files are used to build a precompiled header (PCH) file + named CASSecurity.pch and a precompiled types file named StdAfx.obj. + +///////////////////////////////////////////////////////////////////////////// diff --git a/Chapter19/CASSecurity/app.ico b/Chapter19/CASSecurity/app.ico new file mode 100644 index 0000000..3a5525f Binary files /dev/null and b/Chapter19/CASSecurity/app.ico differ diff --git a/Chapter19/CASSecurity/app.rc b/Chapter19/CASSecurity/app.rc new file mode 100644 index 0000000..807aa89 --- /dev/null +++ b/Chapter19/CASSecurity/app.rc @@ -0,0 +1,63 @@ +// Microsoft Visual C++ generated resource script. +// +#include "resource.h" + +#define APSTUDIO_READONLY_SYMBOLS + +///////////////////////////////////////////////////////////////////////////// +#undef APSTUDIO_READONLY_SYMBOLS + +///////////////////////////////////////////////////////////////////////////// +// English (U.S.) resources + + +///////////////////////////////////////////////////////////////////////////// +// +// Icon +// + +// Icon placed first or with lowest ID value becomes application icon + +LANGUAGE 9, 1 +#pragma code_page(1252) +1 ICON "app.ico" + +#ifdef APSTUDIO_INVOKED +///////////////////////////////////////////////////////////////////////////// +// +// TEXTINCLUDE +// + +1 TEXTINCLUDE +BEGIN + "resource.h\0" + "\0" +END + +2 TEXTINCLUDE +BEGIN + "#include ""afxres.h""\r\n" + "\0" +END + +3 TEXTINCLUDE +BEGIN + "\0" +END + +#endif // APSTUDIO_INVOKED + +///////////////////////////////////////////////////////////////////////////// + + + +#ifndef APSTUDIO_INVOKED +///////////////////////////////////////////////////////////////////////////// +// +// Generated from the TEXTINCLUDE 3 resource. +// + + +///////////////////////////////////////////////////////////////////////////// +#endif // not APSTUDIO_INVOKED + diff --git a/Chapter19/CASSecurity/resource.h b/Chapter19/CASSecurity/resource.h new file mode 100644 index 0000000..d5ac7c4 --- /dev/null +++ b/Chapter19/CASSecurity/resource.h @@ -0,0 +1,3 @@ +//{{NO_DEPENDENCIES}} +// Microsoft Visual C++ generated include file. +// Used by app.rc diff --git a/Chapter19/CASSecurity/stdafx.cpp b/Chapter19/CASSecurity/stdafx.cpp new file mode 100644 index 0000000..86326ce --- /dev/null +++ b/Chapter19/CASSecurity/stdafx.cpp @@ -0,0 +1,7 @@ +// stdafx.cpp : source file that includes just the standard includes +// CASSecurity.pch will be the pre-compiled header +// stdafx.obj will contain the pre-compiled type information + +#include "stdafx.h" + + diff --git a/Chapter19/CASSecurity/stdafx.h b/Chapter19/CASSecurity/stdafx.h new file mode 100644 index 0000000..46bef73 --- /dev/null +++ b/Chapter19/CASSecurity/stdafx.h @@ -0,0 +1,6 @@ +// stdafx.h : include file for standard system include files, +// or project specific include files that are used frequently, but +// are changed infrequently +#pragma once + +// TODO: reference additional headers your program requires here diff --git a/Chapter19/Chapter19.sln b/Chapter19/Chapter19.sln new file mode 100644 index 0000000..477d28a --- /dev/null +++ b/Chapter19/Chapter19.sln @@ -0,0 +1,104 @@ + +Microsoft Visual Studio Solution File, Format Version 9.00 +# Visual Studio 2005 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "SetSecurity", "SetSecurity\SetSecurity.vcproj", "{02BD6EEB-F758-4CCC-9374-2B36BFAF03DF}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "RemoveSecurity", "RemoveSecurity\RemoveSecurity.vcproj", "{8793DD60-C6D6-4837-9747-4ED70B43005B}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "PrincipalIdentity", "PrincipalIdentity\PrincipalIdentity.vcproj", "{6932E750-A729-4D5D-8848-C0B913BB9BF4}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "RoleBasedSecurity", "RoleBasedSecurity\RoleBasedSecurity.vcproj", "{53D3B2F5-45A0-4452-9853-B67A3280C3F7}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "CASSecurity", "CASSecurity\CASSecurity.vcproj", "{38AA823C-B6A3-477E-B9F6-2E55F0DF5C24}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "AssertDenyPermit", "AssertDenyPermit\AssertDenyPermit.vcproj", "{0E1222E4-441C-44ED-84D9-B75F74CD2770}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|.NET = Debug|.NET + Debug|Any CPU = Debug|Any CPU + Debug|Mixed Platforms = Debug|Mixed Platforms + Debug|Win32 = Debug|Win32 + Release|.NET = Release|.NET + Release|Any CPU = Release|Any CPU + Release|Mixed Platforms = Release|Mixed Platforms + Release|Win32 = Release|Win32 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {02BD6EEB-F758-4CCC-9374-2B36BFAF03DF}.Debug|.NET.ActiveCfg = Debug|Win32 + {02BD6EEB-F758-4CCC-9374-2B36BFAF03DF}.Debug|Any CPU.ActiveCfg = Debug|Win32 + {02BD6EEB-F758-4CCC-9374-2B36BFAF03DF}.Debug|Mixed Platforms.ActiveCfg = Debug|Win32 + {02BD6EEB-F758-4CCC-9374-2B36BFAF03DF}.Debug|Mixed Platforms.Build.0 = Debug|Win32 + {02BD6EEB-F758-4CCC-9374-2B36BFAF03DF}.Debug|Win32.ActiveCfg = Debug|Win32 + {02BD6EEB-F758-4CCC-9374-2B36BFAF03DF}.Debug|Win32.Build.0 = Debug|Win32 + {02BD6EEB-F758-4CCC-9374-2B36BFAF03DF}.Release|.NET.ActiveCfg = Release|Win32 + {02BD6EEB-F758-4CCC-9374-2B36BFAF03DF}.Release|Any CPU.ActiveCfg = Release|Win32 + {02BD6EEB-F758-4CCC-9374-2B36BFAF03DF}.Release|Mixed Platforms.ActiveCfg = Release|Win32 + {02BD6EEB-F758-4CCC-9374-2B36BFAF03DF}.Release|Mixed Platforms.Build.0 = Release|Win32 + {02BD6EEB-F758-4CCC-9374-2B36BFAF03DF}.Release|Win32.ActiveCfg = Release|Win32 + {02BD6EEB-F758-4CCC-9374-2B36BFAF03DF}.Release|Win32.Build.0 = Release|Win32 + {8793DD60-C6D6-4837-9747-4ED70B43005B}.Debug|.NET.ActiveCfg = Debug|Win32 + {8793DD60-C6D6-4837-9747-4ED70B43005B}.Debug|Any CPU.ActiveCfg = Debug|Win32 + {8793DD60-C6D6-4837-9747-4ED70B43005B}.Debug|Mixed Platforms.ActiveCfg = Debug|Win32 + {8793DD60-C6D6-4837-9747-4ED70B43005B}.Debug|Mixed Platforms.Build.0 = Debug|Win32 + {8793DD60-C6D6-4837-9747-4ED70B43005B}.Debug|Win32.ActiveCfg = Debug|Win32 + {8793DD60-C6D6-4837-9747-4ED70B43005B}.Debug|Win32.Build.0 = Debug|Win32 + {8793DD60-C6D6-4837-9747-4ED70B43005B}.Release|.NET.ActiveCfg = Release|Win32 + {8793DD60-C6D6-4837-9747-4ED70B43005B}.Release|Any CPU.ActiveCfg = Release|Win32 + {8793DD60-C6D6-4837-9747-4ED70B43005B}.Release|Mixed Platforms.ActiveCfg = Release|Win32 + {8793DD60-C6D6-4837-9747-4ED70B43005B}.Release|Mixed Platforms.Build.0 = Release|Win32 + {8793DD60-C6D6-4837-9747-4ED70B43005B}.Release|Win32.ActiveCfg = Release|Win32 + {8793DD60-C6D6-4837-9747-4ED70B43005B}.Release|Win32.Build.0 = Release|Win32 + {6932E750-A729-4D5D-8848-C0B913BB9BF4}.Debug|.NET.ActiveCfg = Debug|Win32 + {6932E750-A729-4D5D-8848-C0B913BB9BF4}.Debug|Any CPU.ActiveCfg = Debug|Win32 + {6932E750-A729-4D5D-8848-C0B913BB9BF4}.Debug|Mixed Platforms.ActiveCfg = Debug|Win32 + {6932E750-A729-4D5D-8848-C0B913BB9BF4}.Debug|Mixed Platforms.Build.0 = Debug|Win32 + {6932E750-A729-4D5D-8848-C0B913BB9BF4}.Debug|Win32.ActiveCfg = Debug|Win32 + {6932E750-A729-4D5D-8848-C0B913BB9BF4}.Debug|Win32.Build.0 = Debug|Win32 + {6932E750-A729-4D5D-8848-C0B913BB9BF4}.Release|.NET.ActiveCfg = Release|Win32 + {6932E750-A729-4D5D-8848-C0B913BB9BF4}.Release|Any CPU.ActiveCfg = Release|Win32 + {6932E750-A729-4D5D-8848-C0B913BB9BF4}.Release|Mixed Platforms.ActiveCfg = Release|Win32 + {6932E750-A729-4D5D-8848-C0B913BB9BF4}.Release|Mixed Platforms.Build.0 = Release|Win32 + {6932E750-A729-4D5D-8848-C0B913BB9BF4}.Release|Win32.ActiveCfg = Release|Win32 + {6932E750-A729-4D5D-8848-C0B913BB9BF4}.Release|Win32.Build.0 = Release|Win32 + {53D3B2F5-45A0-4452-9853-B67A3280C3F7}.Debug|.NET.ActiveCfg = Debug|Win32 + {53D3B2F5-45A0-4452-9853-B67A3280C3F7}.Debug|Any CPU.ActiveCfg = Debug|Win32 + {53D3B2F5-45A0-4452-9853-B67A3280C3F7}.Debug|Mixed Platforms.ActiveCfg = Debug|Win32 + {53D3B2F5-45A0-4452-9853-B67A3280C3F7}.Debug|Mixed Platforms.Build.0 = Debug|Win32 + {53D3B2F5-45A0-4452-9853-B67A3280C3F7}.Debug|Win32.ActiveCfg = Debug|Win32 + {53D3B2F5-45A0-4452-9853-B67A3280C3F7}.Debug|Win32.Build.0 = Debug|Win32 + {53D3B2F5-45A0-4452-9853-B67A3280C3F7}.Release|.NET.ActiveCfg = Release|Win32 + {53D3B2F5-45A0-4452-9853-B67A3280C3F7}.Release|Any CPU.ActiveCfg = Release|Win32 + {53D3B2F5-45A0-4452-9853-B67A3280C3F7}.Release|Mixed Platforms.ActiveCfg = Release|Win32 + {53D3B2F5-45A0-4452-9853-B67A3280C3F7}.Release|Mixed Platforms.Build.0 = Release|Win32 + {53D3B2F5-45A0-4452-9853-B67A3280C3F7}.Release|Win32.ActiveCfg = Release|Win32 + {53D3B2F5-45A0-4452-9853-B67A3280C3F7}.Release|Win32.Build.0 = Release|Win32 + {38AA823C-B6A3-477E-B9F6-2E55F0DF5C24}.Debug|.NET.ActiveCfg = Debug|Win32 + {38AA823C-B6A3-477E-B9F6-2E55F0DF5C24}.Debug|Any CPU.ActiveCfg = Debug|Win32 + {38AA823C-B6A3-477E-B9F6-2E55F0DF5C24}.Debug|Mixed Platforms.ActiveCfg = Debug|Win32 + {38AA823C-B6A3-477E-B9F6-2E55F0DF5C24}.Debug|Mixed Platforms.Build.0 = Debug|Win32 + {38AA823C-B6A3-477E-B9F6-2E55F0DF5C24}.Debug|Win32.ActiveCfg = Debug|Win32 + {38AA823C-B6A3-477E-B9F6-2E55F0DF5C24}.Debug|Win32.Build.0 = Debug|Win32 + {38AA823C-B6A3-477E-B9F6-2E55F0DF5C24}.Release|.NET.ActiveCfg = Release|Win32 + {38AA823C-B6A3-477E-B9F6-2E55F0DF5C24}.Release|Any CPU.ActiveCfg = Release|Win32 + {38AA823C-B6A3-477E-B9F6-2E55F0DF5C24}.Release|Mixed Platforms.ActiveCfg = Release|Win32 + {38AA823C-B6A3-477E-B9F6-2E55F0DF5C24}.Release|Mixed Platforms.Build.0 = Release|Win32 + {38AA823C-B6A3-477E-B9F6-2E55F0DF5C24}.Release|Win32.ActiveCfg = Release|Win32 + {38AA823C-B6A3-477E-B9F6-2E55F0DF5C24}.Release|Win32.Build.0 = Release|Win32 + {0E1222E4-441C-44ED-84D9-B75F74CD2770}.Debug|.NET.ActiveCfg = Debug|Win32 + {0E1222E4-441C-44ED-84D9-B75F74CD2770}.Debug|Any CPU.ActiveCfg = Debug|Win32 + {0E1222E4-441C-44ED-84D9-B75F74CD2770}.Debug|Mixed Platforms.ActiveCfg = Debug|Win32 + {0E1222E4-441C-44ED-84D9-B75F74CD2770}.Debug|Mixed Platforms.Build.0 = Debug|Win32 + {0E1222E4-441C-44ED-84D9-B75F74CD2770}.Debug|Win32.ActiveCfg = Debug|Win32 + {0E1222E4-441C-44ED-84D9-B75F74CD2770}.Debug|Win32.Build.0 = Debug|Win32 + {0E1222E4-441C-44ED-84D9-B75F74CD2770}.Release|.NET.ActiveCfg = Release|Win32 + {0E1222E4-441C-44ED-84D9-B75F74CD2770}.Release|Any CPU.ActiveCfg = Release|Win32 + {0E1222E4-441C-44ED-84D9-B75F74CD2770}.Release|Mixed Platforms.ActiveCfg = Release|Win32 + {0E1222E4-441C-44ED-84D9-B75F74CD2770}.Release|Mixed Platforms.Build.0 = Release|Win32 + {0E1222E4-441C-44ED-84D9-B75F74CD2770}.Release|Win32.ActiveCfg = Release|Win32 + {0E1222E4-441C-44ED-84D9-B75F74CD2770}.Release|Win32.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/Chapter19/Chapter19.suo b/Chapter19/Chapter19.suo new file mode 100644 index 0000000..a9b3396 Binary files /dev/null and b/Chapter19/Chapter19.suo differ diff --git a/Chapter19/PrincipalIdentity/AssemblyInfo.cpp b/Chapter19/PrincipalIdentity/AssemblyInfo.cpp new file mode 100644 index 0000000..22c8564 --- /dev/null +++ b/Chapter19/PrincipalIdentity/AssemblyInfo.cpp @@ -0,0 +1,35 @@ +#include "stdafx.h" + +using namespace System::Reflection; +using namespace System::Runtime::CompilerServices; +using namespace System::Runtime::InteropServices; + +// +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +// +[assembly:AssemblyTitleAttribute("PrincipalIdentity")]; +[assembly:AssemblyDescriptionAttribute("")]; +[assembly:AssemblyConfigurationAttribute("")]; +[assembly:AssemblyCompanyAttribute("")]; +[assembly:AssemblyProductAttribute("PrincipalIdentity")]; +[assembly:AssemblyCopyrightAttribute("Copyright (c) 2005")]; +[assembly:AssemblyTrademarkAttribute("")]; +[assembly:AssemblyCultureAttribute("")]; + +// +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the value or you can default the Revision and Build Numbers +// by using the '*' as shown below: + +[assembly:AssemblyVersionAttribute("1.0.*")]; + +[assembly:ComVisible(false)]; + diff --git a/Chapter19/PrincipalIdentity/PrincipalIdentity.cpp b/Chapter19/PrincipalIdentity/PrincipalIdentity.cpp new file mode 100644 index 0000000..f76e943 --- /dev/null +++ b/Chapter19/PrincipalIdentity/PrincipalIdentity.cpp @@ -0,0 +1,59 @@ +// PrincipalIdentity.cpp : main project file. + +#include "stdafx.h" + +using namespace System; +using namespace System::Security; +using namespace System::Security::Principal; +using namespace System::Threading; + +void main() +{ + // set policy from UnauthenticatedPrincipal to WindowsPrincipal + AppDomain::CurrentDomain->SetPrincipalPolicy( + PrincipalPolicy::WindowsPrincipal); + + // ---------------------------------------------------------------------- + // Get Windows Principal and Identity + // ---------------------------------------------------------------------- + + Console::WriteLine("Windows Principal & Identity"); + Console::WriteLine("----------------------------"); + + WindowsPrincipal ^wPrinc = (WindowsPrincipal^)Thread::CurrentPrincipal; + + Console::WriteLine("Is an Administrator?: {0}", + wPrinc->IsInRole(WindowsBuiltInRole::Administrator)); + Console::WriteLine("Is a Hacker?: {0}", wPrinc->IsInRole("Hacker")); + + WindowsIdentity ^wIdent = (WindowsIdentity^)wPrinc->Identity; + + Console::WriteLine("\nWindows Login Name: {0}", wIdent->Name); + Console::WriteLine("Authentication Type: {0}", wIdent->AuthenticationType); + Console::WriteLine("Is Authenticated: {0}", wIdent->IsAuthenticated); + Console::WriteLine("Is System Account: {0}", wIdent->IsSystem); + + // ---------------------------------------------------------------------- + // Create (Hacker) Principal and Identity + // ---------------------------------------------------------------------- + + Console::WriteLine("\n\nGeneric Principal & Identity"); + Console::WriteLine("----------------------------"); + + array^ rolesArray = {"Hacker"}; + + // Set the principal to a new generic principal. + Thread::CurrentPrincipal = + gcnew GenericPrincipal(gcnew GenericIdentity("John Doe"), rolesArray); + + GenericPrincipal ^gPrinc = (GenericPrincipal^)Thread::CurrentPrincipal; + + Console::WriteLine("Is an Administrator?: {0}", + gPrinc->IsInRole("BUILTIN\\Administrator")); + Console::WriteLine("Is a Hacker?: {0}", gPrinc->IsInRole("Hacker")); + + GenericIdentity ^gIdent = (GenericIdentity^)gPrinc->Identity; + + Console::WriteLine("\nUser Name: {0}", gIdent->Name); + Console::WriteLine("Is Authenticated: {0}\n", gIdent->IsAuthenticated); +} diff --git a/Chapter19/PrincipalIdentity/PrincipalIdentity.vcproj b/Chapter19/PrincipalIdentity/PrincipalIdentity.vcproj new file mode 100644 index 0000000..320aa71 --- /dev/null +++ b/Chapter19/PrincipalIdentity/PrincipalIdentity.vcproj @@ -0,0 +1,250 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Chapter19/PrincipalIdentity/ReadMe.txt b/Chapter19/PrincipalIdentity/ReadMe.txt new file mode 100644 index 0000000..bab2b05 --- /dev/null +++ b/Chapter19/PrincipalIdentity/ReadMe.txt @@ -0,0 +1,28 @@ +======================================================================== + APPLICATION : PrincipalIdentity Project Overview +======================================================================== + +AppWizard has created this PrincipalIdentity Application for you. + +This file contains a summary of what you will find in each of the files that +make up your PrincipalIdentity application. + +PrincipalIdentity.vcproj + This is the main project file for VC++ projects generated using an Application Wizard. + It contains information about the version of Visual C++ that generated the file, and + information about the platforms, configurations, and project features selected with the + Application Wizard. + +PrincipalIdentity.cpp + This is the main application source file. + +AssemblyInfo.cpp + Contains custom attributes for modifying assembly metadata. + +///////////////////////////////////////////////////////////////////////////// +Other notes: + +AppWizard uses "TODO:" to indicate parts of the source code you +should add to or customize. + +///////////////////////////////////////////////////////////////////////////// diff --git a/Chapter19/PrincipalIdentity/app.ico b/Chapter19/PrincipalIdentity/app.ico new file mode 100644 index 0000000..3a5525f Binary files /dev/null and b/Chapter19/PrincipalIdentity/app.ico differ diff --git a/Chapter19/PrincipalIdentity/app.rc b/Chapter19/PrincipalIdentity/app.rc new file mode 100644 index 0000000..807aa89 --- /dev/null +++ b/Chapter19/PrincipalIdentity/app.rc @@ -0,0 +1,63 @@ +// Microsoft Visual C++ generated resource script. +// +#include "resource.h" + +#define APSTUDIO_READONLY_SYMBOLS + +///////////////////////////////////////////////////////////////////////////// +#undef APSTUDIO_READONLY_SYMBOLS + +///////////////////////////////////////////////////////////////////////////// +// English (U.S.) resources + + +///////////////////////////////////////////////////////////////////////////// +// +// Icon +// + +// Icon placed first or with lowest ID value becomes application icon + +LANGUAGE 9, 1 +#pragma code_page(1252) +1 ICON "app.ico" + +#ifdef APSTUDIO_INVOKED +///////////////////////////////////////////////////////////////////////////// +// +// TEXTINCLUDE +// + +1 TEXTINCLUDE +BEGIN + "resource.h\0" + "\0" +END + +2 TEXTINCLUDE +BEGIN + "#include ""afxres.h""\r\n" + "\0" +END + +3 TEXTINCLUDE +BEGIN + "\0" +END + +#endif // APSTUDIO_INVOKED + +///////////////////////////////////////////////////////////////////////////// + + + +#ifndef APSTUDIO_INVOKED +///////////////////////////////////////////////////////////////////////////// +// +// Generated from the TEXTINCLUDE 3 resource. +// + + +///////////////////////////////////////////////////////////////////////////// +#endif // not APSTUDIO_INVOKED + diff --git a/Chapter19/PrincipalIdentity/resource.h b/Chapter19/PrincipalIdentity/resource.h new file mode 100644 index 0000000..d5ac7c4 --- /dev/null +++ b/Chapter19/PrincipalIdentity/resource.h @@ -0,0 +1,3 @@ +//{{NO_DEPENDENCIES}} +// Microsoft Visual C++ generated include file. +// Used by app.rc diff --git a/Chapter19/PrincipalIdentity/stdafx.cpp b/Chapter19/PrincipalIdentity/stdafx.cpp new file mode 100644 index 0000000..02db58a --- /dev/null +++ b/Chapter19/PrincipalIdentity/stdafx.cpp @@ -0,0 +1,7 @@ +// stdafx.cpp : source file that includes just the standard includes +// PrincipalIdentity.pch will be the pre-compiled header +// stdafx.obj will contain the pre-compiled type information + +#include "stdafx.h" + + diff --git a/Chapter19/PrincipalIdentity/stdafx.h b/Chapter19/PrincipalIdentity/stdafx.h new file mode 100644 index 0000000..39986bd --- /dev/null +++ b/Chapter19/PrincipalIdentity/stdafx.h @@ -0,0 +1,8 @@ +// stdafx.h : include file for standard system include files, +// or project specific include files that are used frequently, but +// are changed infrequently +// + +#pragma once + +// TODO: reference additional headers your program requires here diff --git a/Chapter19/RemoveSecurity/AssemblyInfo.cpp b/Chapter19/RemoveSecurity/AssemblyInfo.cpp new file mode 100644 index 0000000..0e8358c --- /dev/null +++ b/Chapter19/RemoveSecurity/AssemblyInfo.cpp @@ -0,0 +1,61 @@ +#include "stdafx.h" + +using namespace System::Reflection; +using namespace System::Runtime::CompilerServices; +using namespace System::Runtime::InteropServices; + +// +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +// +[assembly:AssemblyTitleAttribute("RemoveSecurity")]; +[assembly:AssemblyDescriptionAttribute("")]; +[assembly:AssemblyConfigurationAttribute("")]; +[assembly:AssemblyCompanyAttribute("")]; +[assembly:AssemblyProductAttribute("RemoveSecurity")]; +[assembly:AssemblyCopyrightAttribute("Copyright @ 2005")]; +[assembly:AssemblyTrademarkAttribute("")]; +[assembly:AssemblyCultureAttribute("")]; + +// +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the value or you can default the Revision and Build Numbers +// by using the '*' as shown below: + +[assembly:AssemblyVersionAttribute("1.0.*")]; + +// +// In order to sign your assembly you must specify a key to use. Refer to the +// Microsoft .NET Framework documentation for more information on assembly signing. +// +// Use the attributes below to control which key is used for signing. +// +// Notes: +// (*) If no key is specified, the assembly is not signed. +// (*) KeyName refers to a key that has been installed in the Crypto Service +// Provider (CSP) on your machine. KeyFile refers to a file which contains +// a key. +// (*) If the KeyFile and the KeyName values are both specified, the +// following processing occurs: +// (1) If the KeyName can be found in the CSP, that key is used. +// (2) If the KeyName does not exist and the KeyFile does exist, the key +// in the KeyFile is installed into the CSP and used. +// (*) In order to create a KeyFile, you can use the sn.exe (Strong Name) utility. +// When specifying the KeyFile, the location of the KeyFile should be +// relative to the project directory. +// (*) Delay Signing is an advanced option - see the Microsoft .NET Framework +// documentation for more information on this. +// +[assembly:AssemblyDelaySignAttribute(false)]; +[assembly:AssemblyKeyFileAttribute("")]; +[assembly:AssemblyKeyNameAttribute("")]; + +[assembly:ComVisible(false)]; + diff --git a/Chapter19/RemoveSecurity/ReadMe.txt b/Chapter19/RemoveSecurity/ReadMe.txt new file mode 100644 index 0000000..b4619a2 --- /dev/null +++ b/Chapter19/RemoveSecurity/ReadMe.txt @@ -0,0 +1,28 @@ +======================================================================== + APPLICATION : RemoveSecurity Project Overview +======================================================================== + +AppWizard has created this RemoveSecurity Application for you. + +This file contains a summary of what you will find in each of the files that +make up your RemoveSecurity application. + +RemoveSecurity.vcproj + This is the main project file for VC++ projects generated using an Application Wizard. + It contains information about the version of Visual C++ that generated the file, and + information about the platforms, configurations, and project features selected with the + Application Wizard. + +RemoveSecurity.cpp + This is the main application source file. + +AssemblyInfo.cpp + Contains custom attributes for modifying assembly metadata. + +///////////////////////////////////////////////////////////////////////////// +Other notes: + +AppWizard uses "TODO:" to indicate parts of the source code you +should add to or customize. + +///////////////////////////////////////////////////////////////////////////// diff --git a/Chapter19/RemoveSecurity/RemoveSecurity.cpp b/Chapter19/RemoveSecurity/RemoveSecurity.cpp new file mode 100644 index 0000000..594e851 --- /dev/null +++ b/Chapter19/RemoveSecurity/RemoveSecurity.cpp @@ -0,0 +1,35 @@ +using namespace System; +using namespace System::Security; +using namespace System::Security::Permissions; +using namespace System::Security::Policy; + +void main() +{ + CodeGroup^ machine; + + // Iterate through policy hierarchy to get Machine Code group + System::Collections::IEnumerator^ ph = SecurityManager::PolicyHierarchy(); + while( ph->MoveNext() ) + { + PolicyLevel^ machinePolicyLevel = (PolicyLevel^)ph->Current; + if (machinePolicyLevel->Label == "Machine") + { + machine = machinePolicyLevel->RootCodeGroup; + break; + } + } + + // Iterate backwards removing all instance of “ReadOnly Secure Group” + for (int i = machine->Children->Count - 1; i >= 0; i--) + { + if(((CodeGroup^)machine->Children[i])->Name == "ReadOnly Secure Group") + { + machine->RemoveChild(((CodeGroup^)machine->Children[i])); + } + } + + // Save changes + SecurityManager::SavePolicy(); + + Console::WriteLine("Removed C:\\ File ReadOnly Secure Group"); +} diff --git a/Chapter19/RemoveSecurity/RemoveSecurity.vcproj b/Chapter19/RemoveSecurity/RemoveSecurity.vcproj new file mode 100644 index 0000000..fa058c3 --- /dev/null +++ b/Chapter19/RemoveSecurity/RemoveSecurity.vcproj @@ -0,0 +1,197 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Chapter19/RemoveSecurity/app.ico b/Chapter19/RemoveSecurity/app.ico new file mode 100644 index 0000000..3a5525f Binary files /dev/null and b/Chapter19/RemoveSecurity/app.ico differ diff --git a/Chapter19/RemoveSecurity/app.rc b/Chapter19/RemoveSecurity/app.rc new file mode 100644 index 0000000..6be44ad --- /dev/null +++ b/Chapter19/RemoveSecurity/app.rc @@ -0,0 +1,52 @@ +// Microsoft Visual C++ generated resource script. +// +#include "resource.h" + +#define APSTUDIO_READONLY_SYMBOLS + +///////////////////////////////////////////////////////////////////////////// +#undef APSTUDIO_READONLY_SYMBOLS + +///////////////////////////////////////////////////////////////////////////// +// English (U.S.) resources + + +///////////////////////////////////////////////////////////////////////////// +// +// Icon +// + +// Icon placed first or with lowest ID value becomes application icon + +LANGUAGE 9, 1 +#pragma code_page(1252) +1 ICON "app.ico" + +#ifdef APSTUDIO_INVOKED +///////////////////////////////////////////////////////////////////////////// +// +// TEXTINCLUDE +// + +1 TEXTINCLUDE +BEGIN + "resource.h\0" + "\0" +END + +#endif // APSTUDIO_INVOKED + +///////////////////////////////////////////////////////////////////////////// + + + +#ifndef APSTUDIO_INVOKED +///////////////////////////////////////////////////////////////////////////// +// +// Generated from the TEXTINCLUDE 3 resource. +// + + +///////////////////////////////////////////////////////////////////////////// +#endif // not APSTUDIO_INVOKED + diff --git a/Chapter19/RemoveSecurity/resource.h b/Chapter19/RemoveSecurity/resource.h new file mode 100644 index 0000000..d5ac7c4 --- /dev/null +++ b/Chapter19/RemoveSecurity/resource.h @@ -0,0 +1,3 @@ +//{{NO_DEPENDENCIES}} +// Microsoft Visual C++ generated include file. +// Used by app.rc diff --git a/Chapter19/RemoveSecurity/stdafx.cpp b/Chapter19/RemoveSecurity/stdafx.cpp new file mode 100644 index 0000000..83b1c67 --- /dev/null +++ b/Chapter19/RemoveSecurity/stdafx.cpp @@ -0,0 +1,7 @@ +// stdafx.cpp : source file that includes just the standard includes +// RemoveSecurity.pch will be the pre-compiled header +// stdafx.obj will contain the pre-compiled type information + +#include "stdafx.h" + + diff --git a/Chapter19/RemoveSecurity/stdafx.h b/Chapter19/RemoveSecurity/stdafx.h new file mode 100644 index 0000000..5acdcf6 --- /dev/null +++ b/Chapter19/RemoveSecurity/stdafx.h @@ -0,0 +1,10 @@ +// stdafx.h : include file for standard system include files, +// or project specific include files that are used frequently, but +// are changed infrequently +// + +#pragma once + +#include + +// TODO: reference additional headers your program requires here diff --git a/Chapter19/RoleBasedSecurity/AssemblyInfo.cpp b/Chapter19/RoleBasedSecurity/AssemblyInfo.cpp new file mode 100644 index 0000000..9952b6a --- /dev/null +++ b/Chapter19/RoleBasedSecurity/AssemblyInfo.cpp @@ -0,0 +1,35 @@ +#include "stdafx.h" + +using namespace System::Reflection; +using namespace System::Runtime::CompilerServices; +using namespace System::Runtime::InteropServices; + +// +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +// +[assembly:AssemblyTitleAttribute("RoleBasedSecurity")]; +[assembly:AssemblyDescriptionAttribute("")]; +[assembly:AssemblyConfigurationAttribute("")]; +[assembly:AssemblyCompanyAttribute("")]; +[assembly:AssemblyProductAttribute("RoleBasedSecurity")]; +[assembly:AssemblyCopyrightAttribute("Copyright (c) 2005")]; +[assembly:AssemblyTrademarkAttribute("")]; +[assembly:AssemblyCultureAttribute("")]; + +// +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the value or you can default the Revision and Build Numbers +// by using the '*' as shown below: + +[assembly:AssemblyVersionAttribute("1.0.*")]; + +[assembly:ComVisible(false)]; + diff --git a/Chapter19/RoleBasedSecurity/ReadMe.txt b/Chapter19/RoleBasedSecurity/ReadMe.txt new file mode 100644 index 0000000..de6fd47 --- /dev/null +++ b/Chapter19/RoleBasedSecurity/ReadMe.txt @@ -0,0 +1,28 @@ +======================================================================== + APPLICATION : RoleBasedSecurity Project Overview +======================================================================== + +AppWizard has created this RoleBasedSecurity Application for you. + +This file contains a summary of what you will find in each of the files that +make up your RoleBasedSecurity application. + +RoleBasedSecurity.vcproj + This is the main project file for VC++ projects generated using an Application Wizard. + It contains information about the version of Visual C++ that generated the file, and + information about the platforms, configurations, and project features selected with the + Application Wizard. + +RoleBasedSecurity.cpp + This is the main application source file. + +AssemblyInfo.cpp + Contains custom attributes for modifying assembly metadata. + +///////////////////////////////////////////////////////////////////////////// +Other notes: + +AppWizard uses "TODO:" to indicate parts of the source code you +should add to or customize. + +///////////////////////////////////////////////////////////////////////////// diff --git a/Chapter19/RoleBasedSecurity/RoleBasedSecurity.cpp b/Chapter19/RoleBasedSecurity/RoleBasedSecurity.cpp new file mode 100644 index 0000000..2b351f9 --- /dev/null +++ b/Chapter19/RoleBasedSecurity/RoleBasedSecurity.cpp @@ -0,0 +1,67 @@ +// RoleBasedSecurity.cpp : main project file. + +#include "stdafx.h" + +using namespace System; +using namespace System::Security; +using namespace System::Security::Principal; +using namespace System::Security::Permissions; +using namespace System::Threading; + +[PrincipalPermissionAttribute(SecurityAction::Demand, Role = "NotAHacker")] +void DeclarativeSecurity() +{ + Console::WriteLine("I'm in the Declarative Security Function"); +} + +void DemandSecurity() +{ + (gcnew PrincipalPermission(nullptr, "NotAHacker"))->Demand(); + + Console::WriteLine("I'm in the Demand Security Function\n"); +} + +void main() +{ + try + { + DeclarativeSecurity(); + + } + catch (SecurityException^) + { + Console::WriteLine("SECURITY ERROR in Declarative Security Function"); + } + + try + { + DemandSecurity(); + } + catch (SecurityException^) + { + Console::WriteLine("SECURITY ERROR in Demand Security Function\n"); + } + + Console::WriteLine("Set CurrentPrincipal to John with role of NotAHacker"); + array^ rolesArray = {"NotAHacker"}; + Thread::CurrentPrincipal = gcnew GenericPrincipal( + gcnew GenericIdentity( "John" ), + rolesArray ); + try + { + DeclarativeSecurity(); + } + catch (SecurityException^) + { + Console::WriteLine("SECURITY ERROR in Declarative Security Function"); + } + + try + { + DemandSecurity(); + } + catch (SecurityException^) + { + Console::WriteLine("SECURITY ERROR in Demand Security Function"); + } +} diff --git a/Chapter19/RoleBasedSecurity/RoleBasedSecurity.vcproj b/Chapter19/RoleBasedSecurity/RoleBasedSecurity.vcproj new file mode 100644 index 0000000..cfaa98c --- /dev/null +++ b/Chapter19/RoleBasedSecurity/RoleBasedSecurity.vcproj @@ -0,0 +1,250 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Chapter19/RoleBasedSecurity/app.ico b/Chapter19/RoleBasedSecurity/app.ico new file mode 100644 index 0000000..3a5525f Binary files /dev/null and b/Chapter19/RoleBasedSecurity/app.ico differ diff --git a/Chapter19/RoleBasedSecurity/app.rc b/Chapter19/RoleBasedSecurity/app.rc new file mode 100644 index 0000000..807aa89 --- /dev/null +++ b/Chapter19/RoleBasedSecurity/app.rc @@ -0,0 +1,63 @@ +// Microsoft Visual C++ generated resource script. +// +#include "resource.h" + +#define APSTUDIO_READONLY_SYMBOLS + +///////////////////////////////////////////////////////////////////////////// +#undef APSTUDIO_READONLY_SYMBOLS + +///////////////////////////////////////////////////////////////////////////// +// English (U.S.) resources + + +///////////////////////////////////////////////////////////////////////////// +// +// Icon +// + +// Icon placed first or with lowest ID value becomes application icon + +LANGUAGE 9, 1 +#pragma code_page(1252) +1 ICON "app.ico" + +#ifdef APSTUDIO_INVOKED +///////////////////////////////////////////////////////////////////////////// +// +// TEXTINCLUDE +// + +1 TEXTINCLUDE +BEGIN + "resource.h\0" + "\0" +END + +2 TEXTINCLUDE +BEGIN + "#include ""afxres.h""\r\n" + "\0" +END + +3 TEXTINCLUDE +BEGIN + "\0" +END + +#endif // APSTUDIO_INVOKED + +///////////////////////////////////////////////////////////////////////////// + + + +#ifndef APSTUDIO_INVOKED +///////////////////////////////////////////////////////////////////////////// +// +// Generated from the TEXTINCLUDE 3 resource. +// + + +///////////////////////////////////////////////////////////////////////////// +#endif // not APSTUDIO_INVOKED + diff --git a/Chapter19/RoleBasedSecurity/resource.h b/Chapter19/RoleBasedSecurity/resource.h new file mode 100644 index 0000000..d5ac7c4 --- /dev/null +++ b/Chapter19/RoleBasedSecurity/resource.h @@ -0,0 +1,3 @@ +//{{NO_DEPENDENCIES}} +// Microsoft Visual C++ generated include file. +// Used by app.rc diff --git a/Chapter19/RoleBasedSecurity/stdafx.cpp b/Chapter19/RoleBasedSecurity/stdafx.cpp new file mode 100644 index 0000000..5d6936d --- /dev/null +++ b/Chapter19/RoleBasedSecurity/stdafx.cpp @@ -0,0 +1,7 @@ +// stdafx.cpp : source file that includes just the standard includes +// RoleBasedSecurity.pch will be the pre-compiled header +// stdafx.obj will contain the pre-compiled type information + +#include "stdafx.h" + + diff --git a/Chapter19/RoleBasedSecurity/stdafx.h b/Chapter19/RoleBasedSecurity/stdafx.h new file mode 100644 index 0000000..39986bd --- /dev/null +++ b/Chapter19/RoleBasedSecurity/stdafx.h @@ -0,0 +1,8 @@ +// stdafx.h : include file for standard system include files, +// or project specific include files that are used frequently, but +// are changed infrequently +// + +#pragma once + +// TODO: reference additional headers your program requires here diff --git a/Chapter19/SetSecurity/AssemblyInfo.cpp b/Chapter19/SetSecurity/AssemblyInfo.cpp new file mode 100644 index 0000000..50764ae --- /dev/null +++ b/Chapter19/SetSecurity/AssemblyInfo.cpp @@ -0,0 +1,61 @@ +#include "stdafx.h" + +using namespace System::Reflection; +using namespace System::Runtime::CompilerServices; +using namespace System::Runtime::InteropServices; + +// +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +// +[assembly:AssemblyTitleAttribute("SetSecurity")]; +[assembly:AssemblyDescriptionAttribute("")]; +[assembly:AssemblyConfigurationAttribute("")]; +[assembly:AssemblyCompanyAttribute("")]; +[assembly:AssemblyProductAttribute("SetSecurity")]; +[assembly:AssemblyCopyrightAttribute("Copyright @ 2005")]; +[assembly:AssemblyTrademarkAttribute("")]; +[assembly:AssemblyCultureAttribute("")]; + +// +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the value or you can default the Revision and Build Numbers +// by using the '*' as shown below: + +[assembly:AssemblyVersionAttribute("1.0.*")]; + +// +// In order to sign your assembly you must specify a key to use. Refer to the +// Microsoft .NET Framework documentation for more information on assembly signing. +// +// Use the attributes below to control which key is used for signing. +// +// Notes: +// (*) If no key is specified, the assembly is not signed. +// (*) KeyName refers to a key that has been installed in the Crypto Service +// Provider (CSP) on your machine. KeyFile refers to a file which contains +// a key. +// (*) If the KeyFile and the KeyName values are both specified, the +// following processing occurs: +// (1) If the KeyName can be found in the CSP, that key is used. +// (2) If the KeyName does not exist and the KeyFile does exist, the key +// in the KeyFile is installed into the CSP and used. +// (*) In order to create a KeyFile, you can use the sn.exe (Strong Name) utility. +// When specifying the KeyFile, the location of the KeyFile should be +// relative to the project directory. +// (*) Delay Signing is an advanced option - see the Microsoft .NET Framework +// documentation for more information on this. +// +[assembly:AssemblyDelaySignAttribute(false)]; +[assembly:AssemblyKeyFileAttribute("")]; +[assembly:AssemblyKeyNameAttribute("")]; + +[assembly:ComVisible(false)]; + diff --git a/Chapter19/SetSecurity/ReadMe.txt b/Chapter19/SetSecurity/ReadMe.txt new file mode 100644 index 0000000..ce0ef63 --- /dev/null +++ b/Chapter19/SetSecurity/ReadMe.txt @@ -0,0 +1,28 @@ +======================================================================== + APPLICATION : SetSecurity Project Overview +======================================================================== + +AppWizard has created this SetSecurity Application for you. + +This file contains a summary of what you will find in each of the files that +make up your SetSecurity application. + +SetSecurity.vcproj + This is the main project file for VC++ projects generated using an Application Wizard. + It contains information about the version of Visual C++ that generated the file, and + information about the platforms, configurations, and project features selected with the + Application Wizard. + +SetSecurity.cpp + This is the main application source file. + +AssemblyInfo.cpp + Contains custom attributes for modifying assembly metadata. + +///////////////////////////////////////////////////////////////////////////// +Other notes: + +AppWizard uses "TODO:" to indicate parts of the source code you +should add to or customize. + +///////////////////////////////////////////////////////////////////////////// diff --git a/Chapter19/SetSecurity/SetSecurity.cpp b/Chapter19/SetSecurity/SetSecurity.cpp new file mode 100644 index 0000000..4f9b03f --- /dev/null +++ b/Chapter19/SetSecurity/SetSecurity.cpp @@ -0,0 +1,47 @@ +using namespace System; +using namespace System::Security; +using namespace System::Security::Permissions; +using namespace System::Security::Policy; + +void main() +{ + // Create a new permission set + PermissionSet^ permSet = gcnew PermissionSet(PermissionState::None); + + // Add permissions to the permission set. + permSet->AddPermission( + gcnew SecurityPermission(PermissionState::Unrestricted)); + permSet->AddPermission(gcnew UIPermission(PermissionState::Unrestricted)); + permSet->AddPermission(gcnew FileIOPermission(FileIOPermissionAccess::Read, + "C:\\")); + + // Create Policy Statement + PolicyStatement^ policy = gcnew PolicyStatement(permSet); + + // Create Membership condition + IMembershipCondition^ membership = + gcnew UrlMembershipCondition("http://192.168.1.102/Chapter19/*"); + + // Create Code group + CodeGroup^ codeGroup = gcnew UnionCodeGroup(membership, policy); + codeGroup->Description = "C:\\ ReadOnly permission for Application URL"; + codeGroup->Name = "ReadOnly Secure Group"; + + // Find the machine policy level + System::Collections::IEnumerator^ ph = SecurityManager::PolicyHierarchy(); + + while( ph->MoveNext() ) + { + PolicyLevel^ pl = (PolicyLevel^)ph->Current; + if( pl->Label == "Machine" ) + { + // Add code group to Machine policy + pl->RootCodeGroup->AddChild(codeGroup); + break; + } + } + // Save changes + SecurityManager::SavePolicy(); + + Console::WriteLine("Added C:\\ ReadOnly Secure Group"); +} diff --git a/Chapter19/SetSecurity/SetSecurity.vcproj b/Chapter19/SetSecurity/SetSecurity.vcproj new file mode 100644 index 0000000..d1938f6 --- /dev/null +++ b/Chapter19/SetSecurity/SetSecurity.vcproj @@ -0,0 +1,197 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Chapter19/SetSecurity/app.ico b/Chapter19/SetSecurity/app.ico new file mode 100644 index 0000000..3a5525f Binary files /dev/null and b/Chapter19/SetSecurity/app.ico differ diff --git a/Chapter19/SetSecurity/app.rc b/Chapter19/SetSecurity/app.rc new file mode 100644 index 0000000..6be44ad --- /dev/null +++ b/Chapter19/SetSecurity/app.rc @@ -0,0 +1,52 @@ +// Microsoft Visual C++ generated resource script. +// +#include "resource.h" + +#define APSTUDIO_READONLY_SYMBOLS + +///////////////////////////////////////////////////////////////////////////// +#undef APSTUDIO_READONLY_SYMBOLS + +///////////////////////////////////////////////////////////////////////////// +// English (U.S.) resources + + +///////////////////////////////////////////////////////////////////////////// +// +// Icon +// + +// Icon placed first or with lowest ID value becomes application icon + +LANGUAGE 9, 1 +#pragma code_page(1252) +1 ICON "app.ico" + +#ifdef APSTUDIO_INVOKED +///////////////////////////////////////////////////////////////////////////// +// +// TEXTINCLUDE +// + +1 TEXTINCLUDE +BEGIN + "resource.h\0" + "\0" +END + +#endif // APSTUDIO_INVOKED + +///////////////////////////////////////////////////////////////////////////// + + + +#ifndef APSTUDIO_INVOKED +///////////////////////////////////////////////////////////////////////////// +// +// Generated from the TEXTINCLUDE 3 resource. +// + + +///////////////////////////////////////////////////////////////////////////// +#endif // not APSTUDIO_INVOKED + diff --git a/Chapter19/SetSecurity/resource.h b/Chapter19/SetSecurity/resource.h new file mode 100644 index 0000000..d5ac7c4 --- /dev/null +++ b/Chapter19/SetSecurity/resource.h @@ -0,0 +1,3 @@ +//{{NO_DEPENDENCIES}} +// Microsoft Visual C++ generated include file. +// Used by app.rc diff --git a/Chapter19/SetSecurity/stdafx.cpp b/Chapter19/SetSecurity/stdafx.cpp new file mode 100644 index 0000000..4ecdf0e --- /dev/null +++ b/Chapter19/SetSecurity/stdafx.cpp @@ -0,0 +1,7 @@ +// stdafx.cpp : source file that includes just the standard includes +// SetSecurity.pch will be the pre-compiled header +// stdafx.obj will contain the pre-compiled type information + +#include "stdafx.h" + + diff --git a/Chapter19/SetSecurity/stdafx.h b/Chapter19/SetSecurity/stdafx.h new file mode 100644 index 0000000..5acdcf6 --- /dev/null +++ b/Chapter19/SetSecurity/stdafx.h @@ -0,0 +1,10 @@ +// stdafx.h : include file for standard system include files, +// or project specific include files that are used frequently, but +// are changed infrequently +// + +#pragma once + +#include + +// TODO: reference additional headers your program requires here diff --git a/Chapter20/Chapter20.sln b/Chapter20/Chapter20.sln new file mode 100644 index 0000000..aedbef5 --- /dev/null +++ b/Chapter20/Chapter20.sln @@ -0,0 +1,68 @@ + +Microsoft Visual Studio Solution File, Format Version 9.00 +# Visual Studio 2005 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "IntPtrArith", "IntPtrArith\IntPtrArith.vcproj", "{8A3B5612-376E-4B94-B591-3A1A9006428D}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "IntPtr", "IntPtrMoving\IntPtrMoving.vcproj", "{AD1044A0-4AEC-46D1-B0CC-3B17AA534A0F}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "MixManUnman", "MixManUnman\MixManUnman.vcproj", "{8F7C524D-7538-4402-8958-5A3077DBAD46}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "PinPtr", "PinPtr\PinPtr.vcproj", "{B914BACA-F360-4BA9-A138-4CDDA4C9AC2E}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "PinIntPtr", "PinIntPtr\PinIntPtr.vcproj", "{1E5B45D2-4BCC-4BD8-8280-870C8052A422}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "UMArray", "UMArray\UMArray.vcproj", "{673059DC-8799-42FA-8864-A150B1DC2CEC}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "MixManUnmanClass", "MixManUnmanClass\MixManUnmanClass.vcproj", "{4CF1A97E-2016-46CA-B5DC-86F7C2F25FA9}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "VcclrEx", "VcclrEx\VcclrEx.vcproj", "{DA1EDA92-3FD0-4224-A5EA-98B301906C36}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "MixManUnmanHello", "MixManUnmanHello\MixManUnmanHello.vcproj", "{B587D523-95B3-400A-A4A3-3DE4664F677B}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Win32 = Debug|Win32 + Release|Win32 = Release|Win32 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {8A3B5612-376E-4B94-B591-3A1A9006428D}.Debug|Win32.ActiveCfg = Debug|Win32 + {8A3B5612-376E-4B94-B591-3A1A9006428D}.Debug|Win32.Build.0 = Debug|Win32 + {8A3B5612-376E-4B94-B591-3A1A9006428D}.Release|Win32.ActiveCfg = Release|Win32 + {8A3B5612-376E-4B94-B591-3A1A9006428D}.Release|Win32.Build.0 = Release|Win32 + {AD1044A0-4AEC-46D1-B0CC-3B17AA534A0F}.Debug|Win32.ActiveCfg = Debug|Win32 + {AD1044A0-4AEC-46D1-B0CC-3B17AA534A0F}.Debug|Win32.Build.0 = Debug|Win32 + {AD1044A0-4AEC-46D1-B0CC-3B17AA534A0F}.Release|Win32.ActiveCfg = Release|Win32 + {AD1044A0-4AEC-46D1-B0CC-3B17AA534A0F}.Release|Win32.Build.0 = Release|Win32 + {8F7C524D-7538-4402-8958-5A3077DBAD46}.Debug|Win32.ActiveCfg = Debug|Win32 + {8F7C524D-7538-4402-8958-5A3077DBAD46}.Debug|Win32.Build.0 = Debug|Win32 + {8F7C524D-7538-4402-8958-5A3077DBAD46}.Release|Win32.ActiveCfg = Release|Win32 + {8F7C524D-7538-4402-8958-5A3077DBAD46}.Release|Win32.Build.0 = Release|Win32 + {B914BACA-F360-4BA9-A138-4CDDA4C9AC2E}.Debug|Win32.ActiveCfg = Debug|Win32 + {B914BACA-F360-4BA9-A138-4CDDA4C9AC2E}.Debug|Win32.Build.0 = Debug|Win32 + {B914BACA-F360-4BA9-A138-4CDDA4C9AC2E}.Release|Win32.ActiveCfg = Release|Win32 + {B914BACA-F360-4BA9-A138-4CDDA4C9AC2E}.Release|Win32.Build.0 = Release|Win32 + {1E5B45D2-4BCC-4BD8-8280-870C8052A422}.Debug|Win32.ActiveCfg = Debug|Win32 + {1E5B45D2-4BCC-4BD8-8280-870C8052A422}.Debug|Win32.Build.0 = Debug|Win32 + {1E5B45D2-4BCC-4BD8-8280-870C8052A422}.Release|Win32.ActiveCfg = Release|Win32 + {1E5B45D2-4BCC-4BD8-8280-870C8052A422}.Release|Win32.Build.0 = Release|Win32 + {673059DC-8799-42FA-8864-A150B1DC2CEC}.Debug|Win32.ActiveCfg = Debug|Win32 + {673059DC-8799-42FA-8864-A150B1DC2CEC}.Debug|Win32.Build.0 = Debug|Win32 + {673059DC-8799-42FA-8864-A150B1DC2CEC}.Release|Win32.ActiveCfg = Release|Win32 + {673059DC-8799-42FA-8864-A150B1DC2CEC}.Release|Win32.Build.0 = Release|Win32 + {4CF1A97E-2016-46CA-B5DC-86F7C2F25FA9}.Debug|Win32.ActiveCfg = Debug|Win32 + {4CF1A97E-2016-46CA-B5DC-86F7C2F25FA9}.Debug|Win32.Build.0 = Debug|Win32 + {4CF1A97E-2016-46CA-B5DC-86F7C2F25FA9}.Release|Win32.ActiveCfg = Release|Win32 + {4CF1A97E-2016-46CA-B5DC-86F7C2F25FA9}.Release|Win32.Build.0 = Release|Win32 + {DA1EDA92-3FD0-4224-A5EA-98B301906C36}.Debug|Win32.ActiveCfg = Debug|Win32 + {DA1EDA92-3FD0-4224-A5EA-98B301906C36}.Debug|Win32.Build.0 = Debug|Win32 + {DA1EDA92-3FD0-4224-A5EA-98B301906C36}.Release|Win32.ActiveCfg = Release|Win32 + {DA1EDA92-3FD0-4224-A5EA-98B301906C36}.Release|Win32.Build.0 = Release|Win32 + {B587D523-95B3-400A-A4A3-3DE4664F677B}.Debug|Win32.ActiveCfg = Debug|Win32 + {B587D523-95B3-400A-A4A3-3DE4664F677B}.Debug|Win32.Build.0 = Debug|Win32 + {B587D523-95B3-400A-A4A3-3DE4664F677B}.Release|Win32.ActiveCfg = Release|Win32 + {B587D523-95B3-400A-A4A3-3DE4664F677B}.Release|Win32.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/Chapter20/Chapter20.suo b/Chapter20/Chapter20.suo new file mode 100644 index 0000000..c013429 Binary files /dev/null and b/Chapter20/Chapter20.suo differ diff --git a/Chapter20/IntPtrArith/IntPtrArith.cpp b/Chapter20/IntPtrArith/IntPtrArith.cpp new file mode 100644 index 0000000..325553d --- /dev/null +++ b/Chapter20/IntPtrArith/IntPtrArith.cpp @@ -0,0 +1,18 @@ + +using namespace System; + +void main() +{ + array^ primes = gcnew array {1,2,3,5,7,11,13,17}; + + interior_ptr ip = &primes[0]; + + int total = 0; + while(ip != &primes[0] + primes->Length) + { + total += *ip; + ip++; + } + + Console::WriteLine("Sum of the first 8 prime numbers is {0}", total); +} diff --git a/Chapter20/IntPtrArith/IntPtrArith.vcproj b/Chapter20/IntPtrArith/IntPtrArith.vcproj new file mode 100644 index 0000000..89a5cce --- /dev/null +++ b/Chapter20/IntPtrArith/IntPtrArith.vcproj @@ -0,0 +1,197 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Chapter20/IntPtrMoving/IntPtr.cpp b/Chapter20/IntPtrMoving/IntPtr.cpp new file mode 100644 index 0000000..3fea8aa --- /dev/null +++ b/Chapter20/IntPtrMoving/IntPtr.cpp @@ -0,0 +1,26 @@ +using namespace System; + +ref class Point +{ +public: + int X; +}; + +void main() +{ + Point ^p = gcnew Point(); + + interior_ptr ip1 = &p; // pointer to Point + + (*ip1)->X = 1; + + Console::WriteLine("(&ip1)={0:X}\tp->X={1}\t(*ip1)->X={2}", + (int)&ip1, p->X, (*ip1)->X); + + interior_ptr ip2 = &p->X; // pointer to Member variable X + + *ip2 += (*ip1)->X; + + Console::WriteLine("(&ip2)={0:X}\t*ip2={1}", + (int)&ip2, *ip2); +} diff --git a/Chapter20/IntPtrMoving/IntPtrMoving.vcproj b/Chapter20/IntPtrMoving/IntPtrMoving.vcproj new file mode 100644 index 0000000..d50f1af --- /dev/null +++ b/Chapter20/IntPtrMoving/IntPtrMoving.vcproj @@ -0,0 +1,197 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Chapter20/MixManUnman/MixManUnman.cpp b/Chapter20/MixManUnman/MixManUnman.cpp new file mode 100644 index 0000000..e251151 --- /dev/null +++ b/Chapter20/MixManUnman/MixManUnman.cpp @@ -0,0 +1,21 @@ +using namespace System; + +#pragma unmanaged + +int UMadd(int a, int b) +{ + return a + b; +} + +#pragma managed + +int Madd(int a, int b) +{ + return a + b; +} + +void main() +{ + Console::WriteLine("Unmanaged Add 2 + 2: {0}", UMadd(2, 2)); + Console::WriteLine("Managed Add 3 + 3: {0}", Madd(3, 3)); +} diff --git a/Chapter20/MixManUnman/MixManUnman.vcproj b/Chapter20/MixManUnman/MixManUnman.vcproj new file mode 100644 index 0000000..d1060cd --- /dev/null +++ b/Chapter20/MixManUnman/MixManUnman.vcproj @@ -0,0 +1,197 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Chapter20/MixManUnmanClass/MixManUnmanClass.cpp b/Chapter20/MixManUnmanClass/MixManUnmanClass.cpp new file mode 100644 index 0000000..f7c9e29 --- /dev/null +++ b/Chapter20/MixManUnmanClass/MixManUnmanClass.cpp @@ -0,0 +1,105 @@ +using namespace System; + +class ClassMember {}; +ref class RefClassMember {}; +value class ValueClassMember {}; + +class Class +{ +public: +// RefClassMember rc; // can't embed instance ref class +// RefClassMember ^hrc; // can't embed handle to ref class + ValueClassMember vc; +// ValueClassMember ^hvc; // can't embed managed value class + ValueClassMember *pvc; + ClassMember c; + ClassMember *pc; + + int x; + void write() { Console::WriteLine("Class x: {0}", x); } +}; + +ref class RefClass +{ +public: + RefClassMember rc; + RefClassMember ^hrc; + ValueClassMember vc; + ValueClassMember ^hvc; + ValueClassMember *pvc; +// ClassMember c; // can't embed instance of class + ClassMember *pc; + + int x; + void write() { Console::WriteLine("RefClass x: {0}", x); } +}; + +value class ValueClass +{ +public: +// RefClassMember rc; // can't embed instance ref class + RefClassMember ^hrc; + ValueClassMember vc; + ValueClassMember ^hvc; + ValueClassMember *pvc; +// ClassMember c; // can't embed instance of class + ClassMember *pc; + + int x; + void write() { Console::WriteLine("ValueClass x: {0}", x); } +}; + +class ClassChildClassParent : public Class {}; // OK +//class ClassChildRefClassParent : public RefClass {}; // Error +//class ClassChildValueClassParent : public ValueClass {}; // Error + +//ref class RefClassChildClassParent : public Class {}; // Error +ref class RefClassChildRefClassParent : public RefClass {}; // OK +//ref class RefClassChildValueClassParent : public ValueClass {}; // Error + +//value class ValueClassChildClassParent : public Class {}; // Error +//value class ValueClassChildRefClassParent : public RefClass {}; // Error +//value class ValueClassChildValueClassParent : public ValueClass {}; // Error + +void main() +{ + // Stack + Class _class; + RefClass refclass; // Not really on the stack + ValueClass valueclass; + + // Handle +// Class ^hclass = gcnew Class(); // Not allowed + RefClass ^hrefclass = gcnew RefClass(); + ValueClass ^hvalueclass = gcnew ValueClass(); + + // Pointer + Class *pclass = new Class(); +// RefClass *prefclass = new RefClass(); // Not allowed + ValueClass *pvalueclass = &valueclass; + + // Reference + Class &rfclass = *new Class(); +// RefClass &rfrefclass = *gcnew RefClass(); // Not allowed + ValueClass &rfvalueclass = valueclass; + + _class.x = 1; + refclass.x = 2; + valueclass.x = 3; + hrefclass->x = 4; + hvalueclass->x = 5; + pclass->x = 6; + pvalueclass->x = 7; + rfclass.x = 8; + rfvalueclass.x = 9; + + _class.write(); // prints 1 + refclass.write(); // prints 2 + valueclass.write(); // prints 9 + hrefclass->write(); // prints 4 + hvalueclass->write(); // prints 5 + pclass->write(); // prints 6 + pvalueclass->write(); // prints 9 + rfclass.write(); // prints 8 + rfvalueclass.write(); // prints 9 +} diff --git a/Chapter20/MixManUnmanClass/MixManUnmanClass.vcproj b/Chapter20/MixManUnmanClass/MixManUnmanClass.vcproj new file mode 100644 index 0000000..ab4ea97 --- /dev/null +++ b/Chapter20/MixManUnmanClass/MixManUnmanClass.vcproj @@ -0,0 +1,197 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Chapter20/MixManUnmanHello/MixManUnmanHello.cpp b/Chapter20/MixManUnmanHello/MixManUnmanHello.cpp new file mode 100644 index 0000000..97d3942 --- /dev/null +++ b/Chapter20/MixManUnmanHello/MixManUnmanHello.cpp @@ -0,0 +1,13 @@ +#include "stdio.h" +#include "vcclr.h" + +using namespace System; + +void main() +{ + String ^hstr = "Hello World!"; + + pin_ptr pstr = PtrToStringChars(hstr); + + wprintf(pstr); +} diff --git a/Chapter20/MixManUnmanHello/MixManUnmanHello.vcproj b/Chapter20/MixManUnmanHello/MixManUnmanHello.vcproj new file mode 100644 index 0000000..4dcd2ae --- /dev/null +++ b/Chapter20/MixManUnmanHello/MixManUnmanHello.vcproj @@ -0,0 +1,197 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Chapter20/PinIntPtr/PinIntPtr.cpp b/Chapter20/PinIntPtr/PinIntPtr.cpp new file mode 100644 index 0000000..4a7ec65 --- /dev/null +++ b/Chapter20/PinIntPtr/PinIntPtr.cpp @@ -0,0 +1,32 @@ +using namespace System; + +value class Test +{ +public: + int i; +}; + +#pragma unmanaged + +void incr (int *i) +{ + (*i) += 10; +} + +#pragma managed + +void main () +{ + Test ^test = gcnew Test(); + interior_ptr ip = &test->i; + (*ip) = 5; + +// incr( ip ); // invalid + + pin_ptr i = ip; // i is a pinned int pointer + + incr( i ); // pinned pointer to interior pointer passed to a + // native function call expecting a native pointer + + Console::WriteLine ( test->i ); +} diff --git a/Chapter20/PinIntPtr/PinIntPtr.vcproj b/Chapter20/PinIntPtr/PinIntPtr.vcproj new file mode 100644 index 0000000..8073f07 --- /dev/null +++ b/Chapter20/PinIntPtr/PinIntPtr.vcproj @@ -0,0 +1,197 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Chapter20/PinPtr/PinPtr.cpp b/Chapter20/PinPtr/PinPtr.cpp new file mode 100644 index 0000000..c053a7e --- /dev/null +++ b/Chapter20/PinPtr/PinPtr.cpp @@ -0,0 +1,69 @@ +#include + +using namespace System; + +ref class RTest +{ +public: + int i; + RTest() + { + i = 0; + } +}; + +value class VTest +{ +public: + int i; +}; + +#pragma unmanaged + +void incr (int *i) +{ + (*i) += 10; +} + +#pragma managed + +void incr (VTest *t) +{ + t->i += 20; +} + + + +void main () +{ + RTest ^rtest = gcnew RTest(); // rtest is a reference type + + pin_ptr i = &(rtest->i); // i is a pinned int pointer + + incr( i ); // pointer to managed data passed as + // parameter of unmanaged function call + + Console::WriteLine ( rtest->i ); + + + VTest ^vtest = gcnew VTest; // vtest is a boxed value type + vtest->i = 0; + + pin_ptr ptest = &*vtest; // ptest is a pinned value type. + // the &* says give the address of the + // inderection of vtest + + incr( ptest ); // pointer to value type passed as + // parameter of unmanaged function call + + Console::WriteLine ( vtest->i ); + + + array^ arr = gcnew array {'M', 'C', '+', '+'}; + + pin_ptr p = &arr[1]; // ENTIRE array is pinned + unsigned char *cp = p; + printf("%s\n", --cp); // cp bytes will not move during call + // notice the negative pointer arithmetic + // into the array. +} diff --git a/Chapter20/PinPtr/PinPtr.vcproj b/Chapter20/PinPtr/PinPtr.vcproj new file mode 100644 index 0000000..0a03c63 --- /dev/null +++ b/Chapter20/PinPtr/PinPtr.vcproj @@ -0,0 +1,197 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Chapter20/UMArray/UMArray.cpp b/Chapter20/UMArray/UMArray.cpp new file mode 100644 index 0000000..2ff739c --- /dev/null +++ b/Chapter20/UMArray/UMArray.cpp @@ -0,0 +1,12 @@ +using namespace System; + +void main() +{ + int UMarray[5] = {2, 3, 5, 7, 11}; + + for (int i = 0; i < 5; i++) + { + Console::Write("{0} ", UMarray[i]); + } + Console::WriteLine(" -- End of array"); +} diff --git a/Chapter20/UMArray/UMArray.vcproj b/Chapter20/UMArray/UMArray.vcproj new file mode 100644 index 0000000..46f772d --- /dev/null +++ b/Chapter20/UMArray/UMArray.vcproj @@ -0,0 +1,197 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Chapter20/VcclrEx/VcclrEx.cpp b/Chapter20/VcclrEx/VcclrEx.cpp new file mode 100644 index 0000000..8c67b84 --- /dev/null +++ b/Chapter20/VcclrEx/VcclrEx.cpp @@ -0,0 +1,37 @@ +#include "stdio.h" +#include "vcclr.h" + +using namespace System; + +ref class MClass +{ +public: + int x; + ~MClass() { Console::WriteLine("MClass disposed"); } +protected: + !MClass() { Console::WriteLine("MClass finalized"); } +}; + +#pragma unmanaged // works with or without this line + +class UMClass +{ +public: + gcroot mclass; + + ~UMClass() { printf("UMClass deleted\n"); } +}; + +#pragma managed + +void main() +{ + UMClass *umc = new UMClass(); + umc->mclass = gcnew MClass(); + + umc->mclass->x = 4; + Console::WriteLine("Managed Print {0}", umc->mclass->x); + printf("Unmanaged Print %d\n", umc->mclass->x); + + delete umc; +} diff --git a/Chapter20/VcclrEx/VcclrEx.vcproj b/Chapter20/VcclrEx/VcclrEx.vcproj new file mode 100644 index 0000000..2dec32e --- /dev/null +++ b/Chapter20/VcclrEx/VcclrEx.vcproj @@ -0,0 +1,197 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Chapter21/Chapter21.sln b/Chapter21/Chapter21.sln new file mode 100644 index 0000000..000e4f8 --- /dev/null +++ b/Chapter21/Chapter21.sln @@ -0,0 +1,68 @@ + +Microsoft Visual Studio Solution File, Format Version 9.00 +# Visual Studio 2005 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "NativeCode", "NativeCode\NativeCode.vcproj", "{9C938A36-2BB3-4820-B782-924883D27940}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "SimplePInvoke", "SimplePInvoke\SimplePInvoke.vcproj", "{A1BFB470-2C46-491A-BD81-D4A943053137}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "DllOldWay", "DllOldWay\DllOldWay.vcproj", "{2CDFEB2C-17C0-4CCE-91BB-2BC16468C48A}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "StaticMethodPInvoke", "StaticMethodPInvoke\StaticMethodPInvoke.vcproj", "{1C2313CB-B629-4781-A41D-A19C98C1A42A}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ManualCOM", "ManualCom\ManualCom.vcproj", "{8BAA222C-D5C0-4F6A-95C5-CDD1391B86E3}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "LateBindCOM", "LateBindCOM\LateBindCOM.vcproj", "{B8D18C75-FA37-4FDC-A81B-1BC0396C5CBA}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "SimpleCOM", "SimpleCOM\SimpleCOM.vcproj", "{2191D55A-4697-4176-9671-43F2C6B789A5}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "TestCOM", "TestCOM\TestCOM.vcproj", "{A86485E0-93D2-4C26-9F05-C06910FABBB3}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ClassMarshal", "ClassMarshal\ClassMarshal.vcproj", "{1C689598-F9B1-49C4-AD76-CCF553984CC5}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Win32 = Debug|Win32 + Release|Win32 = Release|Win32 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {9C938A36-2BB3-4820-B782-924883D27940}.Debug|Win32.ActiveCfg = Debug|Win32 + {9C938A36-2BB3-4820-B782-924883D27940}.Debug|Win32.Build.0 = Debug|Win32 + {9C938A36-2BB3-4820-B782-924883D27940}.Release|Win32.ActiveCfg = Release|Win32 + {9C938A36-2BB3-4820-B782-924883D27940}.Release|Win32.Build.0 = Release|Win32 + {A1BFB470-2C46-491A-BD81-D4A943053137}.Debug|Win32.ActiveCfg = Debug|Win32 + {A1BFB470-2C46-491A-BD81-D4A943053137}.Debug|Win32.Build.0 = Debug|Win32 + {A1BFB470-2C46-491A-BD81-D4A943053137}.Release|Win32.ActiveCfg = Release|Win32 + {A1BFB470-2C46-491A-BD81-D4A943053137}.Release|Win32.Build.0 = Release|Win32 + {2CDFEB2C-17C0-4CCE-91BB-2BC16468C48A}.Debug|Win32.ActiveCfg = Debug|Win32 + {2CDFEB2C-17C0-4CCE-91BB-2BC16468C48A}.Debug|Win32.Build.0 = Debug|Win32 + {2CDFEB2C-17C0-4CCE-91BB-2BC16468C48A}.Release|Win32.ActiveCfg = Release|Win32 + {2CDFEB2C-17C0-4CCE-91BB-2BC16468C48A}.Release|Win32.Build.0 = Release|Win32 + {1C2313CB-B629-4781-A41D-A19C98C1A42A}.Debug|Win32.ActiveCfg = Debug|Win32 + {1C2313CB-B629-4781-A41D-A19C98C1A42A}.Debug|Win32.Build.0 = Debug|Win32 + {1C2313CB-B629-4781-A41D-A19C98C1A42A}.Release|Win32.ActiveCfg = Release|Win32 + {1C2313CB-B629-4781-A41D-A19C98C1A42A}.Release|Win32.Build.0 = Release|Win32 + {8BAA222C-D5C0-4F6A-95C5-CDD1391B86E3}.Debug|Win32.ActiveCfg = Debug|Win32 + {8BAA222C-D5C0-4F6A-95C5-CDD1391B86E3}.Debug|Win32.Build.0 = Debug|Win32 + {8BAA222C-D5C0-4F6A-95C5-CDD1391B86E3}.Release|Win32.ActiveCfg = Release|Win32 + {8BAA222C-D5C0-4F6A-95C5-CDD1391B86E3}.Release|Win32.Build.0 = Release|Win32 + {B8D18C75-FA37-4FDC-A81B-1BC0396C5CBA}.Debug|Win32.ActiveCfg = Debug|Win32 + {B8D18C75-FA37-4FDC-A81B-1BC0396C5CBA}.Debug|Win32.Build.0 = Debug|Win32 + {B8D18C75-FA37-4FDC-A81B-1BC0396C5CBA}.Release|Win32.ActiveCfg = Release|Win32 + {B8D18C75-FA37-4FDC-A81B-1BC0396C5CBA}.Release|Win32.Build.0 = Release|Win32 + {2191D55A-4697-4176-9671-43F2C6B789A5}.Debug|Win32.ActiveCfg = Debug|Win32 + {2191D55A-4697-4176-9671-43F2C6B789A5}.Debug|Win32.Build.0 = Debug|Win32 + {2191D55A-4697-4176-9671-43F2C6B789A5}.Release|Win32.ActiveCfg = Release|Win32 + {2191D55A-4697-4176-9671-43F2C6B789A5}.Release|Win32.Build.0 = Release|Win32 + {A86485E0-93D2-4C26-9F05-C06910FABBB3}.Debug|Win32.ActiveCfg = Debug|Win32 + {A86485E0-93D2-4C26-9F05-C06910FABBB3}.Debug|Win32.Build.0 = Debug|Win32 + {A86485E0-93D2-4C26-9F05-C06910FABBB3}.Release|Win32.ActiveCfg = Release|Win32 + {A86485E0-93D2-4C26-9F05-C06910FABBB3}.Release|Win32.Build.0 = Release|Win32 + {1C689598-F9B1-49C4-AD76-CCF553984CC5}.Debug|Win32.ActiveCfg = Debug|Win32 + {1C689598-F9B1-49C4-AD76-CCF553984CC5}.Debug|Win32.Build.0 = Debug|Win32 + {1C689598-F9B1-49C4-AD76-CCF553984CC5}.Release|Win32.ActiveCfg = Release|Win32 + {1C689598-F9B1-49C4-AD76-CCF553984CC5}.Release|Win32.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/Chapter21/Chapter21.suo b/Chapter21/Chapter21.suo new file mode 100644 index 0000000..4280eed Binary files /dev/null and b/Chapter21/Chapter21.suo differ diff --git a/Chapter21/ClassMarshal/AssemblyInfo.cpp b/Chapter21/ClassMarshal/AssemblyInfo.cpp new file mode 100644 index 0000000..48e0a5b --- /dev/null +++ b/Chapter21/ClassMarshal/AssemblyInfo.cpp @@ -0,0 +1,35 @@ +#include "stdafx.h" + +using namespace System::Reflection; +using namespace System::Runtime::CompilerServices; +using namespace System::Runtime::InteropServices; + +// +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +// +[assembly:AssemblyTitleAttribute("ClassMarshal")]; +[assembly:AssemblyDescriptionAttribute("")]; +[assembly:AssemblyConfigurationAttribute("")]; +[assembly:AssemblyCompanyAttribute("")]; +[assembly:AssemblyProductAttribute("ClassMarshal")]; +[assembly:AssemblyCopyrightAttribute("Copyright (c) 2005")]; +[assembly:AssemblyTrademarkAttribute("")]; +[assembly:AssemblyCultureAttribute("")]; + +// +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the value or you can default the Revision and Build Numbers +// by using the '*' as shown below: + +[assembly:AssemblyVersionAttribute("1.0.*")]; + +[assembly:ComVisible(false)]; + diff --git a/Chapter21/ClassMarshal/ClassMarshal.cpp b/Chapter21/ClassMarshal/ClassMarshal.cpp new file mode 100644 index 0000000..8a05e90 --- /dev/null +++ b/Chapter21/ClassMarshal/ClassMarshal.cpp @@ -0,0 +1,53 @@ +// ClassMarshal.cpp : main project file. + +#include "stdafx.h" + +using namespace System; +using namespace System::Runtime::InteropServices; + +[StructLayout(LayoutKind::Sequential)] +ref class rRec +{ +public: + int width; + int height; + + rRec(int iwidth, int iheight) + { + width = iwidth; + height = iheight; + } +}; + +[StructLayout(LayoutKind::Sequential)] +value class vRec +{ +public: + int width; + int height; + + vRec(int iwidth, int iheight) + { + width = iwidth; + height = iheight; + } +}; + +// By value +[DllImportAttribute("NativeCode.dll")] +extern "C" bool vIsSquare(vRec rec); + +// by reference +[DllImportAttribute("NativeCode.dll")] +extern "C" bool rIsSquare(rRec^ rec); + +void main() +{ + // By Value + vRec vrec(3,3); + Console::WriteLine("value rec a square? {0}", vIsSquare(vrec)); + + // By Reference + rRec ^rrec = gcnew rRec(2,3); + Console::WriteLine("ref rec a square? {0}", rIsSquare(rrec)); +} diff --git a/Chapter21/ClassMarshal/ClassMarshal.vcproj b/Chapter21/ClassMarshal/ClassMarshal.vcproj new file mode 100644 index 0000000..ed9a60f --- /dev/null +++ b/Chapter21/ClassMarshal/ClassMarshal.vcproj @@ -0,0 +1,228 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Chapter21/ClassMarshal/stdafx.cpp b/Chapter21/ClassMarshal/stdafx.cpp new file mode 100644 index 0000000..4f8901c --- /dev/null +++ b/Chapter21/ClassMarshal/stdafx.cpp @@ -0,0 +1,7 @@ +// stdafx.cpp : source file that includes just the standard includes +// ClassMarshal.pch will be the pre-compiled header +// stdafx.obj will contain the pre-compiled type information + +#include "stdafx.h" + + diff --git a/Chapter21/ClassMarshal/stdafx.h b/Chapter21/ClassMarshal/stdafx.h new file mode 100644 index 0000000..39986bd --- /dev/null +++ b/Chapter21/ClassMarshal/stdafx.h @@ -0,0 +1,8 @@ +// stdafx.h : include file for standard system include files, +// or project specific include files that are used frequently, but +// are changed infrequently +// + +#pragma once + +// TODO: reference additional headers your program requires here diff --git a/Chapter21/DllOldWay/AssemblyInfo.cpp b/Chapter21/DllOldWay/AssemblyInfo.cpp new file mode 100644 index 0000000..1486dc6 --- /dev/null +++ b/Chapter21/DllOldWay/AssemblyInfo.cpp @@ -0,0 +1,35 @@ +#include "stdafx.h" + +using namespace System::Reflection; +using namespace System::Runtime::CompilerServices; +using namespace System::Runtime::InteropServices; + +// +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +// +[assembly:AssemblyTitleAttribute("DllOldWay")]; +[assembly:AssemblyDescriptionAttribute("")]; +[assembly:AssemblyConfigurationAttribute("")]; +[assembly:AssemblyCompanyAttribute("")]; +[assembly:AssemblyProductAttribute("DllOldWay")]; +[assembly:AssemblyCopyrightAttribute("Copyright (c) 2005")]; +[assembly:AssemblyTrademarkAttribute("")]; +[assembly:AssemblyCultureAttribute("")]; + +// +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the value or you can default the Revision and Build Numbers +// by using the '*' as shown below: + +[assembly:AssemblyVersionAttribute("1.0.*")]; + +[assembly:ComVisible(false)]; + diff --git a/Chapter21/DllOldWay/DllOldWay.cpp b/Chapter21/DllOldWay/DllOldWay.cpp new file mode 100644 index 0000000..870f447 --- /dev/null +++ b/Chapter21/DllOldWay/DllOldWay.cpp @@ -0,0 +1,19 @@ +// DllOldWay.cpp : main project file. + +#include "stdafx.h" +#include "windows.h" + +extern "C" __declspec(dllimport) long square(long value); + +using namespace System; + +int main(array ^args) +{ + long Squareof4 = square(4); + + Console::WriteLine(L"The square of 4 is {0}", Squareof4); + + MessageBox(0, L"Hello World!", L"A Message Box", 0); + + return 0; +} diff --git a/Chapter21/DllOldWay/DllOldWay.vcproj b/Chapter21/DllOldWay/DllOldWay.vcproj new file mode 100644 index 0000000..2e5438e --- /dev/null +++ b/Chapter21/DllOldWay/DllOldWay.vcproj @@ -0,0 +1,228 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Chapter21/DllOldWay/stdafx.cpp b/Chapter21/DllOldWay/stdafx.cpp new file mode 100644 index 0000000..8386c43 --- /dev/null +++ b/Chapter21/DllOldWay/stdafx.cpp @@ -0,0 +1,7 @@ +// stdafx.cpp : source file that includes just the standard includes +// DllOldWay.pch will be the pre-compiled header +// stdafx.obj will contain the pre-compiled type information + +#include "stdafx.h" + + diff --git a/Chapter21/DllOldWay/stdafx.h b/Chapter21/DllOldWay/stdafx.h new file mode 100644 index 0000000..39986bd --- /dev/null +++ b/Chapter21/DllOldWay/stdafx.h @@ -0,0 +1,8 @@ +// stdafx.h : include file for standard system include files, +// or project specific include files that are used frequently, but +// are changed infrequently +// + +#pragma once + +// TODO: reference additional headers your program requires here diff --git a/Chapter21/LateBindCOM/AssemblyInfo.cpp b/Chapter21/LateBindCOM/AssemblyInfo.cpp new file mode 100644 index 0000000..f61584d --- /dev/null +++ b/Chapter21/LateBindCOM/AssemblyInfo.cpp @@ -0,0 +1,35 @@ +#include "stdafx.h" + +using namespace System::Reflection; +using namespace System::Runtime::CompilerServices; +using namespace System::Runtime::InteropServices; + +// +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +// +[assembly:AssemblyTitleAttribute("LateBindCOM")]; +[assembly:AssemblyDescriptionAttribute("")]; +[assembly:AssemblyConfigurationAttribute("")]; +[assembly:AssemblyCompanyAttribute("")]; +[assembly:AssemblyProductAttribute("LateBindCOM")]; +[assembly:AssemblyCopyrightAttribute("Copyright (c) 2005")]; +[assembly:AssemblyTrademarkAttribute("")]; +[assembly:AssemblyCultureAttribute("")]; + +// +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the value or you can default the Revision and Build Numbers +// by using the '*' as shown below: + +[assembly:AssemblyVersionAttribute("1.0.*")]; + +[assembly:ComVisible(false)]; + diff --git a/Chapter21/LateBindCOM/LateBindCOM.cpp b/Chapter21/LateBindCOM/LateBindCOM.cpp new file mode 100644 index 0000000..30dfb37 --- /dev/null +++ b/Chapter21/LateBindCOM/LateBindCOM.cpp @@ -0,0 +1,39 @@ +// LateBindCOM.cpp : main project file. + +#include "stdafx.h" + +using namespace System; +using namespace System::Reflection; + +int main(array ^args) +{ + Type ^typeTestCom = Type::GetTypeFromProgID(L"CTestCOM.CTestCOM"); + + if (typeTestCom == nullptr) + { + Console::WriteLine("Getting CTestCOM.CTestCOM failed"); + return -1; + } + + try + { + Object ^TestComLBnd = Activator::CreateInstance(typeTestCom); + + array^ param = gcnew array { 4 }; + + Object ^ret = typeTestCom->InvokeMember( + L"Square", + Reflection::BindingFlags::InvokeMethod, + nullptr, + TestComLBnd, + param); + + Console::WriteLine("Square of 4 is {0}", ret); + } + catch (Exception ^ex) + { + Console::WriteLine("Error when invoking Square method: {0}", + ex->Message); + } + return 0; +} diff --git a/Chapter21/LateBindCOM/LateBindCOM.vcproj b/Chapter21/LateBindCOM/LateBindCOM.vcproj new file mode 100644 index 0000000..d92c647 --- /dev/null +++ b/Chapter21/LateBindCOM/LateBindCOM.vcproj @@ -0,0 +1,228 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Chapter21/LateBindCOM/stdafx.cpp b/Chapter21/LateBindCOM/stdafx.cpp new file mode 100644 index 0000000..fb65f2f --- /dev/null +++ b/Chapter21/LateBindCOM/stdafx.cpp @@ -0,0 +1,7 @@ +// stdafx.cpp : source file that includes just the standard includes +// LateBindCOM.pch will be the pre-compiled header +// stdafx.obj will contain the pre-compiled type information + +#include "stdafx.h" + + diff --git a/Chapter21/LateBindCOM/stdafx.h b/Chapter21/LateBindCOM/stdafx.h new file mode 100644 index 0000000..39986bd --- /dev/null +++ b/Chapter21/LateBindCOM/stdafx.h @@ -0,0 +1,8 @@ +// stdafx.h : include file for standard system include files, +// or project specific include files that are used frequently, but +// are changed infrequently +// + +#pragma once + +// TODO: reference additional headers your program requires here diff --git a/Chapter21/ManualCom/ManualCOM.cpp b/Chapter21/ManualCom/ManualCOM.cpp new file mode 100644 index 0000000..13a2ffa --- /dev/null +++ b/Chapter21/ManualCom/ManualCOM.cpp @@ -0,0 +1,17 @@ +// Compile from command line using +// cl /clr:safe ManualCOM + +#using + +using namespace System; +using namespace TestCOM; + +int main(array ^args) +{ + CTestCOMClass^ test = gcnew CTestCOMClass(); + + long ret = test->Square(4); + + Console::WriteLine("The Square of 4 is {0}", ret); + return 0; +} diff --git a/Chapter21/ManualCom/ManualCom.vcproj b/Chapter21/ManualCom/ManualCom.vcproj new file mode 100644 index 0000000..16bf872 --- /dev/null +++ b/Chapter21/ManualCom/ManualCom.vcproj @@ -0,0 +1,202 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Chapter21/ManualCom/TestCom.dll b/Chapter21/ManualCom/TestCom.dll new file mode 100644 index 0000000..e889410 Binary files /dev/null and b/Chapter21/ManualCom/TestCom.dll differ diff --git a/Chapter21/NativeCode/NativeCode.cpp b/Chapter21/NativeCode/NativeCode.cpp new file mode 100644 index 0000000..57f8dc7 --- /dev/null +++ b/Chapter21/NativeCode/NativeCode.cpp @@ -0,0 +1,30 @@ +#include "stdafx.h" +#include "string.h" +#include "stdio.h" +#include + +extern "C" __declspec(dllexport) long square(long value) +{ + return value * value; +} + +extern "C" +{ + struct Rec + { + int width; + int height; + }; + + // By reference + __declspec(dllexport) bool rIsSquare(Rec *rec) + { + return rec->width == rec->height; + } + + // By value + __declspec(dllexport) bool vIsSquare(Rec rec) + { + return rec.width == rec.height; + } +} \ No newline at end of file diff --git a/Chapter21/NativeCode/NativeCode.vcproj b/Chapter21/NativeCode/NativeCode.vcproj new file mode 100644 index 0000000..dfdbd22 --- /dev/null +++ b/Chapter21/NativeCode/NativeCode.vcproj @@ -0,0 +1,215 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Chapter21/NativeCode/stdafx.cpp b/Chapter21/NativeCode/stdafx.cpp new file mode 100644 index 0000000..a812c10 --- /dev/null +++ b/Chapter21/NativeCode/stdafx.cpp @@ -0,0 +1,8 @@ +// stdafx.cpp : source file that includes just the standard includes +// NativeCode.pch will be the pre-compiled header +// stdafx.obj will contain the pre-compiled type information + +#include "stdafx.h" + +// TODO: reference any additional headers you need in STDAFX.H +// and not in this file diff --git a/Chapter21/NativeCode/stdafx.h b/Chapter21/NativeCode/stdafx.h new file mode 100644 index 0000000..c3afe5b --- /dev/null +++ b/Chapter21/NativeCode/stdafx.h @@ -0,0 +1,32 @@ +// stdafx.h : include file for standard system include files, +// or project specific include files that are used frequently, but +// are changed infrequently +// + +#pragma once + +// Modify the following defines if you have to target a platform prior to the ones specified below. +// Refer to MSDN for the latest info on corresponding values for different platforms. +#ifndef WINVER // Allow use of features specific to Windows XP or later. +#define WINVER 0x0501 // Change this to the appropriate value to target other versions of Windows. +#endif + +#ifndef _WIN32_WINNT // Allow use of features specific to Windows XP or later. +#define _WIN32_WINNT 0x0501 // Change this to the appropriate value to target other versions of Windows. +#endif + +#ifndef _WIN32_WINDOWS // Allow use of features specific to Windows 98 or later. +#define _WIN32_WINDOWS 0x0410 // Change this to the appropriate value to target Windows Me or later. +#endif + +#ifndef _WIN32_IE // Allow use of features specific to IE 6.0 or later. +#define _WIN32_IE 0x0600 // Change this to the appropriate value to target other versions of IE. +#endif + +#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers +// Windows Header Files: +#include + + + +// TODO: reference additional headers your program requires here diff --git a/Chapter21/SimpleCOM/AssemblyInfo.cpp b/Chapter21/SimpleCOM/AssemblyInfo.cpp new file mode 100644 index 0000000..4ca017e --- /dev/null +++ b/Chapter21/SimpleCOM/AssemblyInfo.cpp @@ -0,0 +1,35 @@ +#include "stdafx.h" + +using namespace System::Reflection; +using namespace System::Runtime::CompilerServices; +using namespace System::Runtime::InteropServices; + +// +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +// +[assembly:AssemblyTitleAttribute("SimpleCOM")]; +[assembly:AssemblyDescriptionAttribute("")]; +[assembly:AssemblyConfigurationAttribute("")]; +[assembly:AssemblyCompanyAttribute("")]; +[assembly:AssemblyProductAttribute("SimpleCOM")]; +[assembly:AssemblyCopyrightAttribute("Copyright (c) 2005")]; +[assembly:AssemblyTrademarkAttribute("")]; +[assembly:AssemblyCultureAttribute("")]; + +// +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the value or you can default the Revision and Build Numbers +// by using the '*' as shown below: + +[assembly:AssemblyVersionAttribute("1.0.*")]; + +[assembly:ComVisible(false)]; + diff --git a/Chapter21/SimpleCOM/Interop/Interop.TestCOM.1.0.dll b/Chapter21/SimpleCOM/Interop/Interop.TestCOM.1.0.dll new file mode 100644 index 0000000..c876da9 Binary files /dev/null and b/Chapter21/SimpleCOM/Interop/Interop.TestCOM.1.0.dll differ diff --git a/Chapter21/SimpleCOM/SimpleCOM.cpp b/Chapter21/SimpleCOM/SimpleCOM.cpp new file mode 100644 index 0000000..dce1362 --- /dev/null +++ b/Chapter21/SimpleCOM/SimpleCOM.cpp @@ -0,0 +1,27 @@ +// SimpleCOM.cpp : main project file. + +#include "stdafx.h" + +using namespace System; +using namespace TestCOM; + + +int main(array ^args) +{ + CTestCOMClass^ test = gcnew CTestCOMClass(); + + try + { + long ret = test->Square(4); + + Console::WriteLine("The Square of 4 is {0}", ret); + } + catch (Exception^ ex) + { + Console::WriteLine("Oops an exception occurred: {0}", ex->Message); + } + + Console::WriteLine(System::Runtime::InteropServices::Marshal::ReleaseComObject(test)); + + return 0; +} diff --git a/Chapter21/SimpleCOM/SimpleCOM.vcproj b/Chapter21/SimpleCOM/SimpleCOM.vcproj new file mode 100644 index 0000000..62e21c8 --- /dev/null +++ b/Chapter21/SimpleCOM/SimpleCOM.vcproj @@ -0,0 +1,233 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Chapter21/SimpleCOM/stdafx.cpp b/Chapter21/SimpleCOM/stdafx.cpp new file mode 100644 index 0000000..ba293d2 --- /dev/null +++ b/Chapter21/SimpleCOM/stdafx.cpp @@ -0,0 +1,7 @@ +// stdafx.cpp : source file that includes just the standard includes +// SimpleCOM.pch will be the pre-compiled header +// stdafx.obj will contain the pre-compiled type information + +#include "stdafx.h" + + diff --git a/Chapter21/SimpleCOM/stdafx.h b/Chapter21/SimpleCOM/stdafx.h new file mode 100644 index 0000000..39986bd --- /dev/null +++ b/Chapter21/SimpleCOM/stdafx.h @@ -0,0 +1,8 @@ +// stdafx.h : include file for standard system include files, +// or project specific include files that are used frequently, but +// are changed infrequently +// + +#pragma once + +// TODO: reference additional headers your program requires here diff --git a/Chapter21/SimplePInvoke/AssemblyInfo.cpp b/Chapter21/SimplePInvoke/AssemblyInfo.cpp new file mode 100644 index 0000000..626c3e6 --- /dev/null +++ b/Chapter21/SimplePInvoke/AssemblyInfo.cpp @@ -0,0 +1,35 @@ +#include "stdafx.h" + +using namespace System::Reflection; +using namespace System::Runtime::CompilerServices; +using namespace System::Runtime::InteropServices; + +// +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +// +[assembly:AssemblyTitleAttribute("SimplePInvoke")]; +[assembly:AssemblyDescriptionAttribute("")]; +[assembly:AssemblyConfigurationAttribute("")]; +[assembly:AssemblyCompanyAttribute("")]; +[assembly:AssemblyProductAttribute("SimplePInvoke")]; +[assembly:AssemblyCopyrightAttribute("Copyright (c) 2005")]; +[assembly:AssemblyTrademarkAttribute("")]; +[assembly:AssemblyCultureAttribute("")]; + +// +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the value or you can default the Revision and Build Numbers +// by using the '*' as shown below: + +[assembly:AssemblyVersionAttribute("1.0.*")]; + +[assembly:ComVisible(false)]; + diff --git a/Chapter21/SimplePInvoke/SimplePInvoke.cpp b/Chapter21/SimplePInvoke/SimplePInvoke.cpp new file mode 100644 index 0000000..faf3d96 --- /dev/null +++ b/Chapter21/SimplePInvoke/SimplePInvoke.cpp @@ -0,0 +1,37 @@ +// SimplePInvoke.cpp : main project file. + +#include "stdafx.h" + +using namespace System; +using namespace System::Text; +using namespace System::Runtime::InteropServices; + +[DllImportAttribute("C:\\Chapter21\\Debug\\NativeCode.dll", + CallingConvention=CallingConvention::StdCall)] +extern "C" long square(long value); + +[DllImport("User32.dll", CharSet=CharSet::Auto, + CallingConvention=CallingConvention::StdCall)] +extern "C" int MessageBox(int hWnd, String^ text, String^ caption, + unsigned int type); + +[DllImport("msvcr70", CharSet=CharSet::Ansi)] +extern "C" int strcpy([MarshalAs(UnmanagedType::LPStr)] StringBuilder^ dest, + [MarshalAs(UnmanagedType::LPStr)] String^ source); + +int main(array ^args) +{ + long Squareof4 = square(4); + + Console::WriteLine(L"The square of 4 is {0}", Squareof4); + + MessageBox(0, L"Hello World!", L"A Message Box", 0); + + StringBuilder^ dest = gcnew StringBuilder(); + String^ source = "Hello"; + strcpy(dest, source); + Console::WriteLine(dest); + + return 0; +} + diff --git a/Chapter21/SimplePInvoke/SimplePInvoke.vcproj b/Chapter21/SimplePInvoke/SimplePInvoke.vcproj new file mode 100644 index 0000000..fff6c62 --- /dev/null +++ b/Chapter21/SimplePInvoke/SimplePInvoke.vcproj @@ -0,0 +1,228 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Chapter21/SimplePInvoke/stdafx.cpp b/Chapter21/SimplePInvoke/stdafx.cpp new file mode 100644 index 0000000..c93bf0c --- /dev/null +++ b/Chapter21/SimplePInvoke/stdafx.cpp @@ -0,0 +1,7 @@ +// stdafx.cpp : source file that includes just the standard includes +// SimplePInvoke.pch will be the pre-compiled header +// stdafx.obj will contain the pre-compiled type information + +#include "stdafx.h" + + diff --git a/Chapter21/SimplePInvoke/stdafx.h b/Chapter21/SimplePInvoke/stdafx.h new file mode 100644 index 0000000..39986bd --- /dev/null +++ b/Chapter21/SimplePInvoke/stdafx.h @@ -0,0 +1,8 @@ +// stdafx.h : include file for standard system include files, +// or project specific include files that are used frequently, but +// are changed infrequently +// + +#pragma once + +// TODO: reference additional headers your program requires here diff --git a/Chapter21/StaticMethodPInvoke/AssemblyInfo.cpp b/Chapter21/StaticMethodPInvoke/AssemblyInfo.cpp new file mode 100644 index 0000000..b27550d --- /dev/null +++ b/Chapter21/StaticMethodPInvoke/AssemblyInfo.cpp @@ -0,0 +1,35 @@ +#include "stdafx.h" + +using namespace System::Reflection; +using namespace System::Runtime::CompilerServices; +using namespace System::Runtime::InteropServices; + +// +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +// +[assembly:AssemblyTitleAttribute("StaticMethodPInvoke")]; +[assembly:AssemblyDescriptionAttribute("")]; +[assembly:AssemblyConfigurationAttribute("")]; +[assembly:AssemblyCompanyAttribute("")]; +[assembly:AssemblyProductAttribute("StaticMethodPInvoke")]; +[assembly:AssemblyCopyrightAttribute("Copyright (c) 2005")]; +[assembly:AssemblyTrademarkAttribute("")]; +[assembly:AssemblyCultureAttribute("")]; + +// +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the value or you can default the Revision and Build Numbers +// by using the '*' as shown below: + +[assembly:AssemblyVersionAttribute("1.0.*")]; + +[assembly:ComVisible(false)]; + diff --git a/Chapter21/StaticMethodPInvoke/StaticMethodPInvoke.cpp b/Chapter21/StaticMethodPInvoke/StaticMethodPInvoke.cpp new file mode 100644 index 0000000..57d6be1 --- /dev/null +++ b/Chapter21/StaticMethodPInvoke/StaticMethodPInvoke.cpp @@ -0,0 +1,28 @@ +// StaticMethodPInvoke.cpp : main project file. + +#include "stdafx.h" + +using namespace System; +using namespace System::Runtime::InteropServices; + +ref class SimpleClass +{ +public: + [DllImport("NativeCode")] + static long square(long value); + + [DllImport("User32", CharSet=CharSet::Auto)] + static int MessageBox(int hWnd, String^ text, String^ caption, + unsigned int type); +}; + +int main(array ^args) +{ + long Squareof4 = SimpleClass::square(4); + + Console::WriteLine(L"The square of 4 is {0}", Squareof4); + + SimpleClass::MessageBox(0, L"Hello World!", L"A Message Box", 0); + + return 0; +} diff --git a/Chapter21/StaticMethodPInvoke/StaticMethodPInvoke.vcproj b/Chapter21/StaticMethodPInvoke/StaticMethodPInvoke.vcproj new file mode 100644 index 0000000..8a364e7 --- /dev/null +++ b/Chapter21/StaticMethodPInvoke/StaticMethodPInvoke.vcproj @@ -0,0 +1,228 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Chapter21/StaticMethodPInvoke/stdafx.cpp b/Chapter21/StaticMethodPInvoke/stdafx.cpp new file mode 100644 index 0000000..92436ba --- /dev/null +++ b/Chapter21/StaticMethodPInvoke/stdafx.cpp @@ -0,0 +1,7 @@ +// stdafx.cpp : source file that includes just the standard includes +// StaticMethodPInvoke.pch will be the pre-compiled header +// stdafx.obj will contain the pre-compiled type information + +#include "stdafx.h" + + diff --git a/Chapter21/StaticMethodPInvoke/stdafx.h b/Chapter21/StaticMethodPInvoke/stdafx.h new file mode 100644 index 0000000..39986bd --- /dev/null +++ b/Chapter21/StaticMethodPInvoke/stdafx.h @@ -0,0 +1,8 @@ +// stdafx.h : include file for standard system include files, +// or project specific include files that are used frequently, but +// are changed infrequently +// + +#pragma once + +// TODO: reference additional headers your program requires here diff --git a/Chapter21/TestCOM/TestCOM.cpp b/Chapter21/TestCOM/TestCOM.cpp new file mode 100644 index 0000000..b343a24 --- /dev/null +++ b/Chapter21/TestCOM/TestCOM.cpp @@ -0,0 +1,35 @@ +// Compile from command line using +// cl /LD TestCOM +// regsvr32 TestCOM.dll + +#define _ATL_ATTRIBUTES +#include +#include + +[module(name="TestCOM",type="dll")]; + +// ITestCOM interface with Square method +[dual] +__interface ITestCOM : IDispatch +{ + [id(0x01)] HRESULT Square([in]LONG Value, [out,retval]LONG* Result); +}; + +// coclass CTestCOM implements the ITestCOM interface +[coclass, threading="both"] +class CTestCOM : public ITestCOM +{ + HRESULT Square(LONG Value, LONG* Result) + { + if (Value > 0x0ffff) + { + *Result = -1; + return E_INVALIDARG; + } + else + { + *Result = Value * Value; + return S_OK; + } + } +}; diff --git a/Chapter21/TestCOM/TestCOM.vcproj b/Chapter21/TestCOM/TestCOM.vcproj new file mode 100644 index 0000000..6f290ac --- /dev/null +++ b/Chapter21/TestCOM/TestCOM.vcproj @@ -0,0 +1,196 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/LICENSE.txt b/LICENSE.txt new file mode 100644 index 0000000..ec2f635 --- /dev/null +++ b/LICENSE.txt @@ -0,0 +1,27 @@ +Freeware License, some rights reserved + +Copyright (c) 2006 Stephen R.G. Fraser + +Permission is hereby granted, free of charge, to anyone obtaining a copy +of this software and associated documentation files (the "Software"), +to work with the Software within the limits of freeware distribution and fair use. +This includes the rights to use, copy, and modify the Software for personal use. +Users are also allowed and encouraged to submit corrections and modifications +to the Software for the benefit of other users. + +It is not allowed to reuse, modify, or redistribute the Software for +commercial use in any way, or for a user’s educational materials such as books +or blog articles without prior permission from the copyright holder. + +The above copyright notice and this permission notice need to be included +in all copies or substantial portions of the software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS OR APRESS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + + diff --git a/README.md b/README.md new file mode 100644 index 0000000..f67f581 --- /dev/null +++ b/README.md @@ -0,0 +1,15 @@ +#Apress Source Code + +This repository accompanies [*Pro Visual C++/CLI and the .NET 2.0 Platform*](http://www.apress.com/9781590596401) by Stephen R.G. Fraser (Apress, 2006). + +![Cover image](9781590596401.jpg) + +Download the files as a zip using the green button, or clone the repository to your machine using Git. + +##Releases + +Release v1.0 corresponds to the code in the published book, without corrections or updates. + +##Contributions + +See the file Contributing.md for more information on how you can contribute to this repository. diff --git a/ReadMe.txt b/ReadMe.txt new file mode 100644 index 0000000..412c545 --- /dev/null +++ b/ReadMe.txt @@ -0,0 +1,26 @@ +------------ +Installation +------------ + +There is nothing special about installing the code for this book. All you need to do is unzip the files into a directory of your choosing. Once unzipped, you will find a directory for each chapter (which has source code). Most chapters have a project file which you will double click to start Visual Studio 2005. The chapters that don't have a project file have a batch file for building the programs that make up the chapter. For these directories you can use any editor to edit the source code contained within them (though, I used Visual Studio 2005 for these as well). + + +------- +Updates +------- + +You have a choice of getting your updates from either www.apress.com or www.procppcli.net. The most up-to-date will be found on www.procppcli.net as I maintain this site. + + +---------------- +Online Community +---------------- + +As I stated in my book, I will continue to provide information on C++/CLI on my Web site www.procppcli.net. I will also make the site available to other authors and developers to write about or provide code written in C++/CLI. The site currently has a FAQ, Discussion, article and download areas. I plan in the future (if demand supports it) a job site. I am also open for suggestions. + + +--- + +Stephen R. G. Fraser + + \ No newline at end of file diff --git a/contributing.md b/contributing.md new file mode 100644 index 0000000..f6005ad --- /dev/null +++ b/contributing.md @@ -0,0 +1,14 @@ +# Contributing to Apress Source Code + +Copyright for Apress source code belongs to the author(s). However, under fair use you are encouraged to fork and contribute minor corrections and updates for the benefit of the author(s) and other readers. + +## How to Contribute + +1. Make sure you have a GitHub account. +2. Fork the repository for the relevant book. +3. Create a new branch on which to make your change, e.g. +`git checkout -b my_code_contribution` +4. Commit your change. Include a commit message describing the correction. Please note that if your commit message is not clear, the correction will not be accepted. +5. Submit a pull request. + +Thank you for your contribution! \ No newline at end of file