Windows 7 Developer Guide

Build applications on a solid foundation; enable richer application experiences; and integrate the best of Windows and web services. The features and technologies of the Windows 7 operating system enable you to build the next generation of software applications. Download this guide to read descriptions of those features and see vivid screen shots from the pre-Beta version of Windows 7 released at PDC.

Windows 7 Developer Guide Download Page:
http://code.msdn.microsoft.com/……./ProjectReleases.aspx?ReleaseId=1702
Note: URLs are subject to change.
If you find a bad link please report it to us as soon as possible.

LINQ: Deferred Execution

The following example shows how query execution is deferred until the results is enumerated.

 static void TryLinq()
 {
     int i = 0;
     int[] numbers = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };

     // fake values for the query only (10 values)

     var result = from n in numbers select Increment(ref i);

     Console.WriteLine("After query i = {0}", i); // i still 0

     Console.WriteLine();

     Console.WriteLine("Enumerating results:");
     foreach (var v in result)
     {
         Console.WriteLine("v = {0},ti = {1}", v, i);
         // i is incremented every loop
     }

     Console.WriteLine("Press any key to continue . . .");
     Console.ReadKey(true);

     // Result:-

     // After query i = 0
     //
     // Enumerating results:
     // v = 1,  i = 1
     // v = 2,  i = 2
     // .............
     // v = 9,  i = 9
     // v = 10, i = 10

     // What you get?
     // Deferred-Execution / Lazy-Execution
     // - Query doesn't execute until you
     //   begin retrieving it's results.
     // - Every time you try get a value
     //   the query executes on this value only.
 }

 static int Increment(ref int i) { return ++i; }

Next is an example shows how you can execute the query immediately.

static void TryLinq()
{
    int i = 0;
    int[] numbers = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
    // fake values for the query only (10 values)

    var result =
        (from n in numbers select Increment(ref i)).ToList();
    // The last call tries to get the value immediately.

    Console.WriteLine("After query i = {0}", i); // i is 10

    Console.WriteLine();

    Console.WriteLine("Enumerating results:");
    foreach (var v in result)
    {
        Console.WriteLine("v = {0},ti = {1}", v, i);
        // i still 10 every loop
    }

    Console.WriteLine("Press any key to continue . . .");
    Console.ReadKey(true);

    // Result:-

    // After query i = 10
    //
    // Enumerating results:
    // v = 1,  i = 10
    // v = 2,  i = 10
    // .............
    // v = 9,  i = 10
    // v = 10, i = 10

    // What you get?
    // Deferred-Execution / Lazy-Execution
    // - Query doesn't execute until you
    //   begin retrieving it's results.
    // - Every time you try get a value the
    //   query executes on this value only.
    // - You can immediate-execute the query by
    //   calling some conversation methods like
    //   ToList or ToQuery.
}

static int Increment(ref int i) { return ++i; }

What you get?
Deferred-Execution / Lazy-Execution

  • Query doesn’t execute until you begin retrieving it’s results.
  • Every time you try get a value the query executes on this value only.
  • You can execute the query immediately by calling a conversation method like ToList() or ToQuery().

Creating a Message Box Directly using API

Download the example (C#)

.NET Framework contains holes that you can’t overcome using the managed code. Then you must dig into the API to overcome this.

Some of the overcomes in the .NET is the way that you can’t show a message box that contains a Help button!

Figure 1 shows an error message box while loading a project in Visual Basic 6.

Visual Basic File Could Not Be Loaded

To overcome this, API provides you with two functions for creating a message box.

These functions are MessageBox and MessageBoxEx.
Confused?
Yeah, They are two distinct functions, but they’re the same on how they work, and also they share the same input parameters, except that the MessageBoxEx includes a parameter in the last called wLanguageId. But it’s reserved. Means that you can safely ignore this parameter.

The syntax of both functions (in C) is as follows:

int MessageBox(
    HWND hWnd,
    LPCTSTR lpText,
    LPCTSTR lpCaption,
    UINT uType);

int MessageBoxEx(
    HWND hWnd,
    LPCTSTR lpText,
    LPCTSTR lpCaption,
    UINT uType,
    WORD wLanguageId );

Parameters:
hWnd:
A handle to the owner window of the message box. If this parameter is NULL, the message box has no owner window.
lpText:
A string contains the message to be displayed.
lpCaption:
A string contains the message box caption. If this parameter is null, the Default title Error is used.
uType:
Specifies the contents and behavior of the dialog box. (we will return to discuss this later)
wLanguageId (MessageBoxEx):
Reserved.

uType:
This parameter specifies the contents and behavior of the message box, and can be a combination of flags from the following groups of flags:

  • To indicate the buttons displayed in the message box, specify one of the following values:
    MB_OK = 0x0 (default)
    OK button.
    MB_OKCANCEL = 0x1
    OK and Cancel buttons.
    MB_ABORTRETRYIGNORE = 0x2
    Abort, Retry, and Ignore buttons.
    MB_YESNOCANCEL = 0x3
    Yes, No, and Cancel buttons.
    MB_YESNO = 0x4
    Yes and No buttons.
    MB_RETRYCANCEL = 0x5
    Retry and Cancel buttons.
    MB_HELP = 0x4000
    Help button. This flag is the only that can be used with a combination with any other buttons flag.
  • To display an icon in the message box, specify one of the following values:
    MB_ICONHAND = 0x10
    A stop-sign icon appears in the message box.
    MB_ICONQUESTION = 0x20
    A stop-sign icon appears in the message box.
    MB_ICONEXCLAMATION = 0x30
    An exclamation-point icon appears in the message box.
    MB_ICONASTERISK = 0x40
    An icon consisting of a lowercase letter i in a circle appears in the message box.
    MB_ICONERROR = MB_ICONHAND
    MB_ICONSTOP = MB_ICONHAND
    MB_ICONWARNING = MB_ICONEXCLAMATION
    MB_ICONINFORMATION = MB_ICONASTERISK
  • To indicate the default button, specify one of the following values:
    MB_DEFBUTTON1 = 0x0 (default)
    The first button is the default.
    MB_DEFBUTTON2 = 0x100
    The second button is the default.
    MB_DEFBUTTON3 = 0x200
    The third button is the default.
    MB_DEFBUTTON4 = 0x300
    The fourth button is the default. (Will be the Help button if you specify MB_HELP)
  • To indicate the modality of the dialog box, specify one of the following values:
    MB_APPLMODAL = 0x0 (default)
    The user must respond to the message box before continuing work in the window identified by the hWnd parameter. However, the user can move to the windows of other threads and work in those windows.
    MB_SYSTEMMODAL = 0x1000
    Same as MB_APPLMODAL except that the message box has the is shown as top most. Use system-modal message boxes to notify the user of serious, potentially damaging errors that require immediate attention (for example, running out of memory). This flag has no effect on the user’s ability to interact with windows other than those associated with hWnd.
    MB_TASKMODAL = 0x2000
    Same as MB_APPLMODAL except that all the top-level windows belonging to the current thread are disabled if the hWnd parameter is NULL. Use this flag when the calling application or library does not have a window handle available but still needs to prevent input to other windows in the calling thread without suspending other threads.
  • To specify other options, use one or more of the following values:
    MB_DEFAULT_DESKTOP_ONLY = 0x20000
    The message is displayed on the default desktop.
    MB_TOPMOST = 0x40000
    The message is shown top most. (with the WS_EX_TOPMOST window style)
    MB_RIGHT = 0x80000
    The text is right-justified.
    MB_RTLREADING = 0x100000
    Displays message and caption text using right-to-left reading order on Hebrew and Arabic systems.
    MB_SERVICE_NOTIFICATION = 0x200000
    The message is displayed on the active desktop, even if no user logged on to the computer.

Return Value:
Both MessageBox and MessageBoxEx return an integer.
If the function fails, the return value is zero.
If the function succeeds, the return value is one of the following value:

  • IDOK = 1
    The user clicked the OK button.
  • IDCANCEL = 2
    The user clicked the Cancel button or pressed the ESC key.
  • IDABORT = 3
    The user clicked the Abort button.
  • IDRETRY = 4
    The user clicked the Retry button.
  • IDIGNORE = 5
    The user clicked the Ignore button.
  • IDYES = 6
    The user clicked the Yes button.
  • IDNO = 7
    The user clicked the No button.
  • IDTRYAGAIN = 10
    The user clicked the Try Again button.
  • IDCONTINUE = 11
    The user clicked the Continue button.

But what if user clicked the Help button?
There’s no return value named for clicking the help button! That’s because clicking the Help button doesn’t close the message box! Instead it’s sending a WM_HELP message to the owner which equals pressing F1.
So, You can handle this in .NET using the HelpRequested event.

Creating a .NET Example
First, Create the flags that can be used to specify message box options.

// Flags

public static class MBIcons
{
    public const int MB_ICONHAND = 0x10;
    public const int MB_ICONQUESTION = 0x20;
    public const int MB_ICONEXCLAMATION = 0x30;
    public const int MB_ICONASTERISK = 0x40;

    public const int MB_ICONERROR = MB_ICONHAND;
    public const int MB_ICONSTOP = MB_ICONHAND;
    public const int MB_ICONWARNING = MB_ICONEXCLAMATION;
    public const int MB_ICONINFORMATION = MB_ICONASTERISK;
}
public static class MBDefButton
{
    public const int MB_DEFBUTTON1 = 0x0;
    public const int MB_DEFBUTTON2 = 0x100;
    public const int MB_DEFBUTTON3 = 0x200;
    public const int MB_DEFBUTTON4 = 0x300;
}
public static class MBButton
{
    public const int MB_OK = 0x0;
    public const int MB_OKCANCEL = 0x1;
    public const int MB_ABORTRETRYIGNORE = 0x2;
    public const int MB_YESNOCANCEL = 0x3;
    public const int MB_YESNO = 0x4;
    public const int MB_RETRYCANCEL = 0x5;

    public const int MB_HELP = 0x4000;
}
public static class MBModal
{
    public const int MB_APPLMODAL = 0x0;
    public const int MB_SYSTEMMODAL = 0x1000;
    public const int MB_TASKMODAL = 0x2000;
}
public static class MBOptions
{
    public const int MB_DEFAULT_DESKTOP_ONLY = 0x20000;
    public const int MB_TOPMOST = 0x40000;
    public const int MB_RIGHT = 0x80000;
    public const int MB_RTLREADING = 0x100000;
    public const int MB_SERVICE_NOTIFICATION = 0x200000;
}

Second, Create the message box return value enumeration.

public enum MBReturn
{
    IDOK = 1,
    IDCANCEL = 2,
    IDABORT = 3,
    IDRETRY = 4,
    IDIGNORE = 5,
    IDYES = 6,
    IDNO = 7,
    IDTRYAGAIN = 10,
    IDCONTINUE = 11,
}

Third, Create the P/Invoke methods.
P/Invoke stands for Platform Invocation a way for calling unmanaged functions.

[DllImport("user32.dll")]
public static extern int MessageBox(
    IntPtr hWnd, string lpText,
    string lpCaption, uint uType);

[DllImport("user32.dll")]
public static extern int MessageBoxEx(
    IntPtr hWnd, string lpText,
    string lpCaption, uint uType,
    ushort wLanguageId);

Code Explanation:
DllImport Attribute:
This attribute is added to the P/Invoke method to indicate the DLL that expose that function. In the case of these functions the DLL is user32.dll.
static extern modifiers:
P/Invoke methods must specify the two modifiers.
extern means that the method is implemented externally, while static means that that method belongs to the type itself not the object.
IntPtr struct:
The managed type that can be used to represent a pointer or an handle in the unmanaged code.

Marshaling
In unmanaged code there’s some types that doesn’t exist in the managed environment, But using marshaling you can overcome this problem.
Marshaling is the process of converting a managed type into unmanaged type.
We have seen in the last code some examples of this.
An example is HWND which is a pointer to a handle in the memory. Which .NET doesn’t provide this type! But, It provides a similar type named IntPtr.
Another example is the WORD which is 16-bit unsigned integer. But, The .NET Framework includes an equivalent thats UInt16 or simply ushort (in C#).

Finally, Call the unmanaged function.

static void Main()
{
    // You can replace IntPtr.Zero
    // with Form.Handle if you want to
    // specify the form as an owner
    MBReturn ret = (MBReturn)MessageBoxEx(IntPtr.Zero,
        "'C:StockPrjcrviewer.dll' could not be loaded" +
        "--Continue Loading Project?", "Microsoft Visual Basic",
        MBButton.MB_YESNO | MBButton.MB_HELP |
        MBIcons.MB_ICONQUESTION | MBSpecial.MB_TOPMOST |
        MBDefButton.MB_DEFBUTTON1, 0);
    Console.WriteLine("User clicked: {0}", ret.ToString());
}

Congratulations!

You have completed the lesson.

Download the example (C#)

Links to standalone .NET Framework 2.0 SP2 core and language pack installer packages

The .NET Framework 3.5 SP1 was released last fall along with Visual Studio 2008 SP1. The .NET Framework 3.5 SP1 installs the .NET Framework 2.0 SP2 and the .NET Framework 3.0 SP2 behind the scenes as prerequisites.  Initially, the only way to get the .NET Framework 2.0 SP2 was to install the full .NET Framework 3.5 SP1 package.

Last week, a standalone installer package for the .NET Framework 2.0 SP2 was posted on the Microsoft Download Center.  There are x86, x64 and ia64 versions of this package, and the package allows you to install the .NET Framework 2.0 SP2 on Windows 2000, Windows XP and Windows Server 2003 without needing to install any .NET Framework 3.0 or 3.5 packages.

Note that there is not a standalone package for the .NET Framework 2.0 SP2 for Windows Vista or Windows Server 2008.  In order to install the .NET Framework 2.0 SP2 on those operating systems, you will still have to install the .NET Framework 3.5 SP1.

Here are links to download locations for the .NET Framework 2.0 SP2:

For the language packs, you will need to go to the above link and change the language drop-down to the language that you want to download the language pack for, then download the files listed in the language-specific version of the download page.

Source- Tech Today

Working with Strings with Combining Characters

هذه المقالة متوفرة أيضا باللغة العربية، اقرأها هنا.

Contents

Contents of this article:

  • Contents
  • Introduction
  • Writing Arabic Diacritics
  • Using the Character Map Application
  • Enumerating a String with Only Base Characters
  • Enumerating a String with Combining Characters
  • Comparing Strings
  • Try it out!

Introduction

In some languages, like Arabic and Hebrew, you combine some characters with combining characters based on the pronunciation of the word.

Combining characters are characters (like diacritics, etc.) that are combined with base characters to change the pronunciation of the word (sometimes called vocalization.)

Some examples of combining characters are diacritics:

Base Character Combining Character(s) Result
1
Combining a single character

Arabic Letter Teh
Arabic Letter Teh
0x062A

Arabic Damma
Arabic Damma
0x064F
Arabic Letter Teh + Damma.gif
Letter Teh + Damma
2
Combining two characters
Arabic Letter Teh
Arabic Letter Teh
0x062A

Arabic Shadda
Arabic Shadda
0x0651

Arabic Fathatan
Arabic Fathatan
0x064B

Arabic Letter Teh + Shadda + Fathatan
Letter Teh + Shadda + Fathatan

When you combine a character with another one then you end up with two characters. When you combine two characters with a base one you end up with 3 characters combined in one, and so on.

Writing Arabic diacritics

The following table summarizes up the Arabic diacritics and the keyboard shortcut for each character:

Unicode Representation Character Name Shortcut
0x064B Arabic Fathatan Fathatan Shift + W
0x064C Arabic Dammatan Dammatan Shift + R
0x064D Arabic Kasratan Kasratan Shift + S
0x064E Arabic Fatha Fatha Shift + Q
0x064F Arabic Damma Damma Shift + E
0x0650 Arabic Kasra Kasra Shift + A
0x0651 Arabic Shadda Shadda Shift + ~
0x0652 Arabic Sukun Sukun Shift + X

Using the Character Map Application

Microsoft Windows comes with an application that help you browsing the characters that a font supports. This application is called, Character Map.

You can access this application by typing charmap.exe into Run, or pressing Start->Programs->Accessories->System Tools->Character Map.

Character Map application

Enumerating a String with Base Characters

Now we are going to try an example. This example uses a simple word,Word Muhammad (Mohammad; the name of the Islam prophet.)

Word Muhammad Details

This word (with the diacritics) is consisted of 9 characters, sequentially as following:

  1. Meem
  2. Damma (a combining character combined with the previous Meem)
  3. Kashida
  4. Hah
  5. Meem
  6. Shadda (a combining character)
  7. Fatha (a combining character both Shadda and Fatha are combined with the Meem)
  8. Kashida
  9. Dal

After characters combined with their bases we end up with 6 characters, sequentially as following:

  1. Meem (have a Damma above)
  2. Kashida
  3. Hah
  4. Meem (have a Shadda and a Fatha above)
  5. Kashida
  6. Dal

The following code simply enumerates the string and displays a message box with each character along with its index:

// C#

string name = "مُـحمَّـد"
string result = String.Empty;

for (int i = 0; i < name.Length; i++)
result += String.Format("{0}t{1}b", i, name(i));

MessageBox.Show(result);

' VB.NET

Dim name As String = "مُـحمَّـد"
Dim result As String = String.Empty

For i As Integer = 0 To name.Length – 1
result &= String.Format("{0}{1}{2}{3}", i, vbTab, name(i), vbNewLine)
Next

MessageBox.Show(result)

What we get? When enumerating the string, we enumerate its base characters only.

Enumerating a String with Combining Characters

.NET Framework provides a way for enumerating strings with combining characters, it is via the TextElementEnumerator and StringInfo types (both reside in namespace System.Globalization.)

The following code demonstrates how you can enumerate a string along with its combining characters:

// C#

string name = "مُـحمَّـد";
string result = String.Empty;

TextElementEnumerator enumerator =
StringInfo.GetTextElementEnumerator(name);

while (enumerator.MoveNext())
result += String.Format("{0}t{1}b",
enumerator.ElementIndex, enumerator.Current);

MessageBox.Show(result);
' VB.NET

Dim name As String = "مُـحمَّـد"
Dim result As String = String.Empty

Dim enumerator As TextElementEnumerator = _
StringInfo.GetTextElementEnumerator(name)

While enumerator.MoveNext()
result &= String.Format("{0}{1}{2}{3}", _
enumerator.ElementIndex, vbTab, _
enumerator.Current, vbNewLine)
End While

MessageBox.Show(result)

Comparing Strings

Sometimes, you will be faced with a situation where you need to compare two identical strings differ only by their diacritics (combining characters) for instance. If you were to compare them using the common way (using String.Compare for instance) they would be different because of the combining characters.

To overcome this you will need to use a special overload of String.Compare method:

The Kashida, isn’t of the Arabic alphabets. It’s most likely be a space! So the option CompareOptions.IgnoreSymbols ignores it from comparison.

// C#

string name1 = "محمد";
string name2 = "مُـحمَّـد";

// 1st check
if (name1 == name2)
MessageBox.Show("Strings are identical");
else
MessageBox.Show("Strings are different!");

// 2nd check
if (String.Compare(name1, name2) == 0)
MessageBox.Show("Strings are identical");
else
MessageBox.Show("Strings are different!");

// 3rd
if (String.Compare(name1, name2,
System.Threading.Thread.CurrentThread.CurrentCulture,
CompareOptions.IgnoreSymbols) == 0)
MessageBox.Show("Strings are identical");
else
MessageBox.Show("Strings are different!");
' VB.NET

Dim name1 As String = "محمد"
Dim name2 As String = "مُـحمَّـد"

' 1st check
If (name1 = name2) Then
MessageBox.Show("Strings are identical")
Else
MessageBox.Show("Strings are different!")
End If

' 2nd check
If (String.Compare(name1, name2) = 0) Then
MessageBox.Show("Strings are identical")
Else
MessageBox.Show("Strings are different!")
End If

' 3rd check
If (String.Compare(name1, name2, _
System.Threading.Thread.CurrentThread.CurrentCulture, _
CompareOptions.IgnoreSymbols) = 0) Then
MessageBox.Show("Strings are identical")
Else
MessageBox.Show("Strings are different!")
End If

Localized Visual Studio 2008 in 9 new languages

Visual Studio 2008 has been localized into Arabic, Czech, Hebrew, Hindi, Polish, Tamil, Turkish, Malayalam and Oriya as a free “CLIP” download package.

“CLIP” stand for “Captions Language Interface Pack”. It’s basically an add-on with localized user interface that you install on top of the English version of Visual Studio. The CLIP package allows you to see translations of menus, button and so on as tooltips when running Visual Studio.

It’s designed for users who use the English version, but want to see the most common user interface in their own language as well.

The translations in the CLIP package are a joint-effort between Microsoft and local communities.

When you hover your mouse over a menu or command, a separate box (or a tooltip depending on your setup) will display the translation in the local language. You can also add your own translation for user interface items.

CLIP in Visual Studio 2008

Just Like a Magic:
A smart way from Microsoft. CLIP gets Microsoft not to provide another copies from it’s products for native languages (e.g. Arabic, Turkish). But, The downward side is that CLIP isn’t specific for Visual Studio 2008 or even any product! CLIP is for everything. Just point in a word and CLIP checks the dictionary and returns it’s equivalent in the selected language.
That’s may be OK for many users using many applications in English. But, If you consider using it for VS2008 it will be really useless. Because of, these CLIP packages contain only the common words (like, File, Edit, View). However, It doesn’t contain the translation of such words, as a simple example, ‘Console’!!!

Source: Microsoft Terminology Blog