Microsoft Visual Studio 2010 and .NET Framework 4 Released

Today, Microsoft released Visual Studio 2010 and the .NET Framework 4. A lot of new features are included. One of them is a completely new editor.

“Visual Studio 2010 and .NET Framework 4 have something for every developer. The new editor, now using Windows Presentation Foundation, delivers a more flexible, feature-rich environment that supports concepts such as the use of multiple monitors. This enables a developer to have one monitor with code, another with the user interface designer, and yet another with database structure.”

Visual C++ 2010 also includes a lot of new features, some of them are:

  • MSBuild and multi-targeting
  • IntelliSense and Browsing (#include auto completion, call hierarchy, red squiggles, find all references, class wizard)
  • C++ compiler changes (static_assert, auto keyword, lambda, decltype, rvalue references)
  • Ribbon designer
  • Deployment changes
  • Task dialog support
  • Restart manager support

Read the full press release here or watch the keynote.

Later this week, Silverlight 4 will also be released to the web (RTW). At that time, an update for Visual Studio 2010 will also become available that will allow you to develop applications using Silverlight 4.

Share

Overview of New Features in Visual C++ 2010

A friend of mine, Marius Bancila, wrote several blog posts with details about new features in Visual C++ 2010.

He touches the following features:

  • MSBuild and multi-targeting
  • IntelliSense and Browsing (#include auto completion, call hierarchy, red squiggles, find all references, class wizard)
  • C++ compiler changes (static_assert, auto keyword, lambda, decltype, rvalue references)
  • Ribbon designer
  • Deployment changes
  • Task dialog support
  • Restart manager support

You can read his posts here. They give you a good idea of new features in VC++ 2010 🙂

Share

How To Handle Custom URL Protocols with the Microsoft WebBrowser Control

Now that you know “How To Use the Microsoft WebBrowser Control to Render HTML from Memory” and “How To Navigate to an Anchor in the Microsoft WebBrowser Control when Rendering HTML from Memory“, it’s time to learn how to handle custom URL protocols to tailor the navigation inside the WebBrowser Control to fit your application. The following demonstrates a custom URL protocol called “app”:

<a href="app://some.target">Test</a>

When you would put this link in a normal Internet Explorer window, clicking the link will generate an error because IE does not know how to handle the APP protocol. The name APP is chosen arbitrarily. You can use whatever you want. Handling these custom protocols in your C++ application is actually pretty simple and it doesn’t even involve any real COM coding like in the previous articles. The first thing you need to do is to add a handler for the BeforeNavigate2 handler. Open the resource editor and open your dialog with the WebBrowser control. Right click the WebBrowser control and select “Add Event Handler…”. Select “BeforeNavigate2” as message type, select the appropriate class and click “Add and Edit”. This handler will be called right before the WebBrowser control will navigate to a new page. To handle the custom protocol, implement the handler as follows:

void CMyDlg::BeforeNavigate2Explorer(LPDISPATCH pDisp, VARIANT* URL, VARIANT* Flags,
    VARIANT* TargetFrameName, VARIANT* PostData, VARIANT* Headers, BOOL* Cancel)
{
    const wchar_t* cpszProtocolName = L"app";
    const wchar_t* cpszProtocolSeparator = L"://";

    // We only handle VT_BSTR.
    if (URL->vt != VT_BSTR)
        return;

    // Check the protocol of the URL
    CString str = URL->bstrVal;
    int iPos = str.Find(cpszProtocolSeparator);
    if (iPos == -1)    // Unable to figure out protocol
        return;

    // Extract protocol and check if it's our APP protocol
    CString strProtocol = str.Mid(0, iPos);
    if (strProtocol.CompareNoCase(cpszProtocolName))
        return;    // not our APP protocol

    // It's our APP protocol, so start processing it.
    // Start by preventing Internet Explorer from handling the protocol.
    *Cancel = TRUE;

    // Extract target URL
    CString strTarget = str.Mid(iPos+wcslen(cpszProtocolSeparator));
    strTarget.TrimRight(L"/");

    // Now we are ready to process our protocol.
    // For this demo, I just render a new HTML page with the name
    // of the URL target without the protocol part of the string.
    CString strHTML;
    strHTML.Format(L"My APP protocol processing: \"%s\"", strTarget);
    WriteHTML(strHTML);
}

The flow is pretty straightforward. The URL protocol is extracted; if it’s not our protocol, we let Internet Explorer handle the URL for us. If it is our custom “APP” protocol, we first set Cancel to TRUE which will prevent Internet Explorer from handling this URL protocol. Once that is done, we are completely free to implement the handling of the “APP” protocol however we want. As demonstration I just write a new HTML document from memory which will just mention that we are processing an “APP” protocol URL and that will also display the target part of the URL.

You can quickly test the code with the following piece of HTML rendered from memory:

WriteHTML(L"<html><body>"
    L"<p><a href=\"app://FirstAppProtocolTestLink\">test 1</a></p>"
    L"<p><a href=\"APP://SecondAppProtocolTestLink.Withdots\">test 2</a></p>"
    L"</body></html>");

Run the application, click on the “test 1” or “test 2” link and see what happens.

That’s it for handling custom URL protocols in C++ 🙂

Share

How To Navigate to an Anchor in the Microsoft WebBrowser Control when Rendering HTML from Memory

In my previous blog entry titled “How To Use the Microsoft WebBrowser Control to Render HTML from Memory” I described a method how you could use the Microsoft WebBrowser Control to display HTML from memory. One commenter said that it was not possible to navigate to an anchor in the body onload handler. I did some research and it seems all navigation within the rendered page is not working. For example, the following piece of HTML code will not work correctly:

<a href="#n25">Jump to anchor n25</a>
<a name="n25">25</a>

It took me a while to find a workaround, so that’s why I’m posting it now for other people to use. Basically, we cannot use the standard navigation techniques. I tried several possible workaround and the only one that I got working properly is by manually scrolling the window until the requested anchor is visible. It sounds complicated, but it really works pretty nicely. I wrote this little wrapper function to do all the hard work.

void CMyDlg::ScrollToAnchor(const wchar_t* anchor)
{
    IDispatch* pHtmlDoc = m_explorer.get_Document();
    if (!pHtmlDoc)
        return;
    CComPtr<IHTMLDocument2> doc2;
    doc2.Attach((IHTMLDocument2*)pHtmlDoc);
    if (doc2)
    {
        CComPtr<IHTMLElementCollection> anchors;
        HRESULT hr = doc2->get_anchors(&anchors);
        if (SUCCEEDED(hr) && anchors)
        {
            _variant_t index = 0;
            _variant_t str = anchor;
            IDispatch *pdisp;
            hr = anchors->item(str, index, &pdisp);
            if (SUCCEEDED(hr) && pdisp)
            {
                CComPtr<IHTMLElement> el;
                hr = pdisp->QueryInterface(IID_IHTMLElement, (void**)&el);
                if (SUCCEEDED(hr) && el)
                {
                    long yTotal = 0;
                    while (1)
                    {
                        long y;
                        el->get_offsetTop(&y);
                        yTotal += y;
                        CComPtr<IHTMLElement> el2;
                        hr = el->get_offsetParent(&el2);
                        if (SUCCEEDED(hr) && el2)
                            el = el2;
                        else
                            break;
                    }
                    CComPtr<IHTMLWindow2> wnd;
                    hr = doc2->get_parentWindow(&wnd);
                    if (SUCCEEDED(hr) && wnd)
                        wnd->scrollTo(0, yTotal);
                }
            }
        }
    }
}

What it does is it gets a pointer to the document. Then gets a list of all the anchors in the document and get the anchor with the given name out of that list. Once we have the target element, we calculate the offset from the top of the document. This is done in a while loop, because the target anchor could be inside another element like a div or a table. After calculating the offset, we get a pointer to the HTML window and call the scrollTo function to make it scroll to the anchor position.

Now the only thing you need to do is to render your HTML using the method in my previous blog entry and then call this new ScrollToAnchor function with the name of the anchor to which you want to scroll.

Share

“Windows Phone 7 Series” Becomes “Windows Phone 7”

It seems Microsoft listened to all the complains about the long name for the new Windows phone. The Microsoft Windows Phone twitter page just had the following message:

“Tis the season for Series finales. We’ve got one too – dropping the ‘Series’ and keeping the ‘Windows Phone 7.’ Done.”

Excellent, “Windows Phone 7” sounds much better without the strange “Series” behind it 🙂

Share

Microsoft MVP VC++ 2010 Award

I got the confirmation email from Microsoft that my MVP (Most Valuable Professional) award for Visual C++ is extended for 2010 🙂

See my MVP profile.

Share

Start Developing Applications for Windows Phone 7 Series

The Windows Phone Application Platform was revealed at MIX 2010. If you couldn’t make it to Las Vegas to attend MIX, you can find the keynotes and sessions here. They explain in great details the Windows Phone 7 Series and how to develop applications for it.

The WP7S developer platform contains 2 frameworks:

  • Silverlight: to make rich interactive applications
  • XNA: to make complex 2D/3D games

Code is written in C#.

Everyone can start writing applications for the new phone platform. You only need to download 1 free package. This packages contains:

  • Visual Studio 2010 Express for Windows Phone CTP
  • Windows Phone Emulator CTP
  • Silverlight for Windows Phone CTP
  • XNA 4.0 Game Studio CTP

Download the package to get started. Only Windows Vista and Windows 7 are officially supported to run the tools. Note that the tools are currently in CTP state so they are not yet final. If you want to use Expression Blend you have to download it separately.

More information can be found on the Windows Phone 7 Series Developer Site, where you can also find developer guides, more detailed information, Windows Marketplace submission guidelines, forums, a few code samples etc…

Share

How To Use the Microsoft WebBrowser Control to Render HTML from Memory

Microsoft has a WebBrowser control that is actually an Internet Explorer control that you can use to display HTML in your own applications. More information about this WebBrowser control can be found on MSDN. By using this control it’s very easy to display online or offline webpages. However, it’s not immediately obvious how to make it display HTML that you might have in a memory buffer. Of course, one solution is to write the HTML to a temporary file and then load that file using the WebBrowser control, but obviously there is a better way for doing this which I will explain below.

The first thing you have to do is to add the WebBrowser control to your dialog. So, in Visual Studio, open the resource editor and then open the dialog onto which you want to put the WebBrowser control. Once the dialog is opened in the resource editor, right click on an empty space on the dialog and select “Insert ActiveX Control…”. This will open a new window in which you can select “Microsoft Web Browser” and then click OK. Visual Studio will automatically create a wrapper class for this ActiveX control which will probably be called explorer.h and explorer.cpp while the wrapper class will most likely be called CExplorer.

Now, right click the WebBrowser control on your dialog and select “Add Variable”. Make a variable with category set to “Control” and with the variable type set to the wrapper class “CExplorer” and hit OK.

Now we can start writing code. The first thing required is to load up some basic document; I use about:blank. Do this in your OnInitDialog handler as follows.

COleVariant loc(L"about:blank");
m_explorer.Navigate2(loc, NULL, NULL, NULL, NULL); 

The above is very important. If you don’t load an initial document, the WebBrowser control will not render any HTML that you try to push to it. This also means that before you can start writing HTML from memory in the WebBrowser control, you have to wait until the initial document has been fully loaded. This can be done with the “DocumentComplete” event. In the dialog editor, right the WebBrowser control and click on “Add Event Handler…”. Select “DocumentComplete” as message type, select the appropriate class and click “Add and Edit”. You can use that handler to change a boolean variable in your code to mark whether the document has been fully loaded. When it is fully loaded you can start writing HTML from memory to it.

Once that is finished, you can add the following helper function:

#include <MsHTML.h>
void CMyDlg::WriteHTML(const wchar_t* html)
{
	IDispatch* pHtmlDoc = m_explorer.get_Document();
	if (!pHtmlDoc)
		return;
	CComPtr<IHTMLDocument2> doc2;
	doc2.Attach((IHTMLDocument2*)pHtmlDoc);
	if (!doc2)
		return;
	 // Creates a new one-dimensional array
	SAFEARRAY* psaStrings = SafeArrayCreateVector(VT_VARIANT, 0, 1);
	if (!psaStrings)
		return;
	BSTR bstr = SysAllocString(html);
	if (bstr)
	{
		VARIANT* param;
		HRESULT hr = SafeArrayAccessData(psaStrings, (LPVOID*)&param);
		if (SUCCEEDED(hr))
		{
			param->vt = VT_BSTR;
			param->bstrVal = bstr;
			hr = SafeArrayUnaccessData(psaStrings);
			if (SUCCEEDED(hr))
			{
				doc2->write(psaStrings);
				doc2->close();
			}
		}
	}
	// SafeArrayDestroy calls SysFreeString for each BSTR!
	if (psaStrings)
		SafeArrayDestroy(psaStrings);
}

With the above function, it’s very easy to dynamically create and display HTML from memory. For example:

WriteHTML(L"<html><body><h1>My Header</h1><p>Some text below the header</p></body></html>");

Note that the above code is expecting a Unicode build. If you don’t use Unicode, you need to change the wchar_t types and you need to change the way how you allocate the BSTR variable.

That’s it. Pretty easy if you know how to do it, but it took me some time to figure it out.

[ Update: Fixed some typos and added mshtml.h reference. ]

[ Update 2: Added a call to “doc2->close();” after “doc2->write()” and added code to check the result of the doc2.Attach() call. ]

Share

Windows 2000, XP SP2 and Vista End of Life Support

This is a message to everyone who is running an older version of Windows. There are a few End of Life Support dates coming up, so it’s important to keep that in mind to avoid running unsupported versions of Windows.

Windows 2000 Professional and Windows 2000 Server are approaching 10 years since their launch and both products will go out of support on July 13, 2010.

Windows XP was launched back in 2001. While support for the product will continue, Service Pack 2 will go out of support on July 13, 2010. From that date onwards, Microsoft will no longer support or provide free security updates for Windows XP SP2.  Please install the free Service Pack 3 for Windows XP to have the most secure and supported Windows XP platform.

Finally, Windows Vista with no Service Packs installed will end support on April 13 2010.  Please install the free Service Pack 2 for Windows Vista to have the most secure and supported Windows Vista platform.

Share

Breaking Change for RValue References in Visual Studio 2010 RC

The Release Candidate of Visual Studio 2010 has changed the behaviour of RValue references slightly compared to the implementation in the Visual Studio 2010 beta versions. This is because the C++0x standard commitee has changed the RValue reference feature a bit and Visual Studio 2010 RC has incorporated those standard changes. Unfortunately, this might lead to compiler errors when you try to build code that is following the old standard. Let me give an example. Previously using a beta version of Visual Studio 2010 that was using the old C++0x standard, the following code would compile without any problems.

#include <iostream>
using namespace std;
// Increment value by 1 using RValue reference parameter.
int increment(int&& value)
{
   cout << "value = " << value << endl;
   value++;
   return value;
}
int main()
{
   int a = 10;
   int b = 20;
   // Increment a
   int result = increment(a);
   cout << "  a=" << a << ", b=" << b << ", result=" << result << endl;
   // Increment b
   result = increment(b);
   cout << "  a=" << a << ", b=" << b << ", result=" << result << endl;
   // Increment an expression
   result = increment(a + b);
   cout << "  a=" << a << ", b=" << b << ", result=" << result << endl;
   // Increment a literal
   result = increment(3);
   cout << "  a=" << a << ", b=" << b << ", result=" << result << endl;
   return 0;
} 

However, when trying to compile this using the latest release candidate of Visual Studio 2010, you will get the following errors:

rvalue_test.cpp(18): error C2664: 'increment' : cannot convert parameter 1 from 'int' to 'int &&'
          You cannot bind an lvalue to an rvalue reference
rvalue_test.cpp(21): error C2664: 'increment' : cannot convert parameter 1 from 'int' to 'int &&'
          You cannot bind an lvalue to an rvalue reference

These are related to the lines that are trying to increment a and b. Incrementing an expression or a literal still works as before. To get rid of those errors, you need to convert the lvalue to an rvalue. You can use the std::move function for this as shown in red below.

#include <iostream>
using namespace std;
// Increment value by 1 using RValue reference parameter.
int increment(int&& value)
{
   cout << "value = " << value << endl;
   value++;
   return value;
}
int main()
{
   int a = 10;
   int b = 20;
   // Increment a
   int result = increment(std::move(a));
   cout << "  a=" << a << ", b=" << b << ", result=" << result << endl;
   // Increment b
   result = increment(std::move(b));
   cout << "  a=" << a << ", b=" << b << ", result=" << result << endl;
   // Increment an expression
   result = increment(a + b);
   cout << "  a=" << a << ", b=" << b << ", result=" << result << endl;
   // Increment a literal
   result = increment(3);
   cout << "  a=" << a << ", b=" << b << ", result=" << result << endl;
   return 0;
}

This now compiles without any errors and produces the following output:

value = 10
  a=11, b=20, result=11
value = 20
  a=11, b=21, result=21
value = 32
  a=11, b=21, result=33
value = 3
  a=11, b=21, result=4

Now, it again works as expected 🙂

Share

Visual Studio 2010 Licensing White Paper

Microsoft has released a white paper for Visual Studio 2010 licensing which provides an overview of the complete Visual Studio 2010 product line. The paper also gives a number of example deployment scenarios and the licensing requirements for those.

Client editions in the Visual Studio 2010 product line include:

  • Microsoft Visual Studio 2010 Ultimate with MSDN
  • Microsoft Visual Studio 2010 Premium with MSDN
  • Microsoft Visual Studio 2010 Professional with MSDN
  • Microsoft Visual Studio Test Professional 2010 with MSDN

(Visual Studio 2010 products can be purchased without an MSDN subscription in certain channels.)

Server products in the Visual Studio 2010 product line include:

  • Microsoft Visual Studio Team Foundation Server 2010
  • Microsoft Visual Studio Lab Management 2010

Volume licensing customers who need a definitive guide to licensing terms and conditions should reference the Microsoft Licensing Product Use Rights (PUR) and applicable licensing agreements. For retail customers, the license terms are specified in the End User Licensing Agreement (EULA) included with the product.

Share

Visual Studio 2010 and .NET Framework 4 Release Candidate

Microsoft has released the Release Candidate version of Visual Studio 2010 and the .NET Framework 4.

See Scott Guthrie blog post about it.

Right now it’s available for MSDN subscribers.
On Wednesday 10th of February everyone will be able to get their hands on it 🙂

Two important things to know (from Scott Guthrie blog post):

  • If you have previously installed VS 2010 Beta 2 on your computer you should use Add/Remove Programs (within Windows Control Panel) to remove VS 2010 Beta2 and .NET 4 Beta2 before installing the VS 2010 RC.  Note that VS 2010 RC can be installed on the same machine side-by-side with VS 2008 and VS 2005.
  • Silverlight 3 projects are supported with today’s VS 2010 RC build – however Silverlight 4 projects are not yet supported.  We will be adding VS 2010 RC support for SL4 with the next public Silverlight 4 drop. If you are doing active Silverlight 4 development today we recommend staying with the VS10 Beta 2 build for now.
Share

Microsoft Office 2010 Beta

Microsoft has just released a beta version of Office 2010.

The following programs are available in this beta version:

  • Word
  • PowerPoint
  • Outlook
  • Excel
  • OneNote
  • Access
  • Publisher
  • InfoPath
  • SharePoint Workspace
  • Communicator

Separately available beta programs are:

  • Microsoft Visio 2010
  • Microsoft Project 2010

Get all the details.

Share

Trip to Budapest Photo Album

I’m just back from another small trip to Budapest, just 2 days.

I have uploaded some pictures of the trip. See them here. Enjoy :)

Share

Happy New Year 2010

2010

Happy New Year
Sretna Nova Godina
Gelukkig Nieuwjaar
🙂

Share

Axialis Black Friday till Cyber Monday Promotion

I’m a big fan of Axialis IconWorkshop. A while ago I wrote a small review of it which you can find here.

It seems Axialis is having a special promotion this weekend. From Black Friday until Cyber Monday you get 50% discount on all products. Find out more.

Share

Trip to Warsaw Photo Album

Last week I was in Warsaw (Poland) on a business trip. Unfortunately, I didn’t have much time to go see things because it was already dark after work. However, I did try to take some pictures. You can see them here.

Share

Trip to Tokyo Photo Album

In October 2009 I went to Tokyo with some friends for a week.

Some pictures of the trip can be seen in a new photo album. 🙂

Share

Trip to Panama Photo Album

In September 2009 I went to Panama with KrisKras.

I have created a photo album about the trip. See it here. Enjoy 🙂

Share

Trip to Budapest Photo Album

In August 2009 I went to Budapest for a short city trip with some friends.

I have uploaded some pictures to a photo album. See them here. Enjoy 🙂

Share