When you create a WPF application, the start-up window is by default one from the same project (by default called Window1.xaml).

< Application x:Class="WpfApplication1.App"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    StartupUri="Window1.xaml" >
    < Application.Resources >

    < /Application.Resources >
< /Application >

But what if you want to use a window from another project (class library)? The pack URI scheme, used by WPF, allows you to identify and load files from:

  • the current assembly
  • a referenced assembly
  • a location relative to an assembly
  • the site of origin for the application

The format of the pack URI is pack://authority/path. The authority identifies the type of package and the path the location of a part inside a package. There are two authorities supported by WPF:

  • application:/// identifies application data files (known at compile time)
  • siteoforigin:/// identifies site of origin files

To use resource files from a referenced assembly you need to use the application:/// authority, and the path must have the form AssemblyShortName[;Version][;PublicKey];component/Path. Version and PublicKey are optional.

Let’s say you want to use a XAML called SampleWindow.xaml from a referenced assembly called WpfDemoLib. The App.xaml file should look like this:

< Application x:Class="WpfApplication1.App"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    StartupUri="pack://application:,,,/WpfDemoLib;component/SampleWindow.xaml" >
    < Application.Resources >

    < /Application.Resources >
< /Application >

You can learn more about pack URIs in WPF from MSDN.

, , , , Hits for this post: 15020 .

This Tuesday a Texas court ruled that Microsoft can no longer sell Microsoft Word in USA because of a patent infringement (U.S. Patent No. 5,787,449). Canadian based company i4i accused Microsoft of willingly violating this patent on a method for reading XML. Microsoft was found guilty and ruled to pay $240 millions, plus other fines for each day before the final judgment. Moreover, they can’t sell Word versions that break the patent.

You can read more about this here and here.

, , , Hits for this post: 9479 .

Arad. Pod peste soseaua de centura. Doua benzi pe sens. Momentan in reparatii.

S-a inchis un sens (stanga in imaginile de mai jos), si s-a circulat pe cealalta parte in ambele sensuri. Acum nici doua luni s-a inversat traficul, circulandu-se pe partea reparata. Iata cum arata podul recent renovat.

Podul aflat in renovare

Podul aflat in renovare

Jumatarea reamenajata deja si data in folosita in aceasta vara

Jumatarea reamenajata deja si data in folosita in aceasta vara

Calitatea asfaltului se vede foarte clar aici

Calitatea asfaltului se vede foarte clar aici

Valuri, valuri, valuri de asfalt

Valuri, valuri, valuri de asfalt

In aceasta tara numai se fura, se insala, se duce cu zaharelul. Iar constructiile sunt cele mai dezastruoase. Toate proiectele se duc la capat intru-un timp de 3-4 ori mai lung decat cel preconizat, cu costuri de cateva ori mai mari, si cu o calitate ZERO! Nu inteleg cum e posibil ca un drum dat in folosita acum nici doua luni sa fie plin de valuri de asfalt. RUSINE, RUSINE, RUSINE!!!

, , Hits for this post: 7798 .

Sometimes you want to customize a file dialog, maybe to provide a preview for images or files in general. Fortunately, the common file dialog can be easily extended to achieve this. I will explain in this post how to do that.

There are several things one needs to do to extend the file dialog. First step is to create a dialog template. There are several properties (styles that have to be set on this template).

  • WS_CHILD, necessary because this dialog is a child of the original file dialog
  • WS_CLIPSIBLINGS, required so that the child dialog box does not paint over the original file dialog
  • DS_3DLOOK, so that consistency of the look of the controls in the child dialog and the original dialog is preserved
  • DS_CONTROL, allows the user to navigate through the controls of the customized dialog with TAB or navigation keys

When using the template, the following should be done for the OPENFILENAME structure:

  • if the template is a resource in an application or DLL library, then:
    • Flags should contain OFN_ENABLETEMPLATE
    • hInstance must point to the module containing the resource
    • lpTemplateName should contain the template name
  • if the template is already in memory then
    • Flags should contain OFN_ENABLETEMPLATEHANDLE
    • hInstance member must identify the memory object that contains the template

The following code shows how to display a customized file dialog with a template with the ID set to “DIALOG_PREVIEW”:

	CFileDialog fileDialog(TRUE, NULL, NULL, OFN_HIDEREADONLY, _T("All files (*.*)|*.*||"));

	fileDialog.m_ofn.Flags |= OFN_ENABLETEMPLATE;
	fileDialog.m_ofn.hInstance = AfxGetInstanceHandle();
	fileDialog.m_ofn.lpTemplateName = _T("DIALOG_PREVIEW");

	fileDialog.DoModal();

The common file dialog is expanded on the sides so that the new controls have enough space. There are several rules that apply to this repositioning. I will explain them and exemplify with some images.

  • By default all the controls from the custom dialog are placed below the controls from the original file dialog. The following images show a simple dialog template with a check box and a static control (for a preview). By default, these controls are placed at the bottom of the dialog.
    Simple dialog template

    Simple dialog template


    Custom dialog with preview controls placed at the bottom

    Custom dialog with preview controls placed at the bottom

  • If the dialog template contains a static control with the id stc32 (defined in DLG.h), the controls will be positioned relative to this control (with the original dialog being displayed in its placed, in the original size).
    • all controls above and to the left of stc32 are positioned above and to the left of the original controls, with the same amount.
      Template with stc32 control position on the right and middle

      Template with stc32 control position on the right and middle


      Custom File Fialog with Preview controls on the top left

      Custom File Fialog with Preview controls on the top left

    • all controls below and to the right of stc32 are positioned below and to the right of the original controls.
      Template with stc32 control position on the left and middle

      Template with stc32 control position on the left and middle


      Custom File Fialog with Preview controls on the top and on the right

      Custom File Fialog with Preview controls on the top and on the right

Base on that, if you want to place the preview controls on the right (as I would do), you’d have to place the stc32 control on the left of all the controls from your template. In other words, the template needs to look like this:

Template with stc32 on the left of all controls

Template with stc32 on the left of all controls

The resulting file dialog would look like this:

Custom File Dialog with Preview Controls on the right side

Custom File Dialog with Preview Controls on the right side

Note: In the above images the stc32 control had the border style set one one hand to make the control visible on the dialog template and on the other hand to have the the original file dialog controls more visible within the resulting file dialog. You wouldn’t do that with an actual file dialog.

As you could see from the sample code above, it’s very simple to extend the common file dialog. Of course, the part I haven’t shown so far is how to make use of these additional controls. But that is very simple. You just derive CFileDialog, add handlers for the new controls, implement all the logic you want, and instead of instantiating a CFileDialog object you instantiate an object of your derived class. In a following post I will explain how you can add preview functionality to such a custom file dialog.

You can read more about this topic in the following articles:

, , , , Hits for this post: 18960 .

Concepts were supposed to be an important new feature in C++0x. They were meant to allow programmers to specify properties (like constraints) for templates, allow compilers to do some optimization and tools to do some formal checking on the code. After years of debate, the standard committee found them “untried, risky and controversial” and ruled them out last month during their meeting in Frankfurt.

Danny Kalev, a former member of the C++ standard committee, wrote about this controversial removal, and later interviewed Bjarne Stroustrup about the concepts and the future of C++. You can read this interview, published on DevX.com, here.

You can find more about concepts in this paper by Bjarne Stroustrup.

, , , Hits for this post: 10657 .

Windows 7 RTM and Windows Server 2008 R2 RTM are now available for download on MSDN for MSDN and TechNet subscribers. Currently, the only available bits are in English. The other languages will become available on October 1st. Volume License customers with an existing Software Assurance license will be able to download the bits starting tomorrow.

For more information on these releases check the Windows Team Blog.

Update: Windows Server 2008 R2 is not yet available.

, , , , , , Hits for this post: 14582 .

I run across this site featuring hundreds of amazing circle crop pictures, taken by Lucy Pringle, one of world’s leading crop circles photographers. For the record, I don’t believe they have anything to do with things from outer space. They are all man made. But I must admit, lots of them are amazing. Here are some samples:

Jellyfish crop circle - photo by Lucy Pringle

Jellyfish crop circle - photo by Lucy Pringle

3D corridor - photo by Lucy Pringle

3D corridor - photo by Lucy Pringle

See hundreds of other images here.

Hits for this post: 3868 .