Blog

Linq is cool.

var types = from type in System.Reflection.Assembly.GetExecutingAssembly().GetTypes()
	let attr = Attribute.GetCustomAttribute(type, typeof(PreferencePageAttribute), true)
	where attr != null
	select new { Attribute = attr as PreferencePageAttribute, Type = type };
Posted on January 13th, 2008 in .NET, Code, SzótárNo Comments

Vista-style menus in .NET

Update: you might want to check out the WindowsFormsAero project, which uses an improved version of this code, if you’re looking for a way to get vista-like/aero-style menus for System.Windows.Forms. (July 2008)

Ever noticed that .NET-style menus are ugly?

Windows Vista comes with a new style of menus (which allow images, too), and a few updates to the UxTheme API, including the ability to render these themed menus. When the .NET framework was designed, however, this functionality wasn’t available; and you can see this clearly by looking at a default MenuStrip.

But ToolStrip allows you to give it a new renderer (via its Renderer property), and you can write a ToolStripRenderer that draws menus using UxTheme with not too much effort.

And that’s exactly what I’ve done, and you can have the source code. Do what you like with it. It only really works with menu bars and context menu bars, because I didn’t need it for anything else.

You can apply it in one of two ways, both pretty simple.

  • toolStrip1.Renderer = new NativeToolStripRenderer();
  • NativeToolStripRenderer.SetToolStripRenderer(menuStrip, contextMenuStrip);

Here’s some screenshots:
Using Aero (Vista) Theme (120dpi)
Using Luna (XP) Theme (120dpi)
Using Windows Classic Theme (120dpi)

If you do use this, here are some scenarios to test:

  • Starting with Aero on, and turning it on/off and switching into classic mode a few times
  • Starting with Aero off, and turning it on/off and switching into classic mode a few times

In a similar vein, there is also a WindowsVistaRenderer on The Code Project, which draws the sort of dark toolbars you can see in Windows Media Player 11, Windows Photo Gallery, etc.

Comments welcome!
- Lee

Posted on December 9th, 2007 in .NET, Code, GDNet, SzótárComments Off

Fractals with Canvas 3D

If you have the beta of Firefox 3 and feel like watching some hypnotic fractals, I recently made a demo using the Canvas 3D preview. It’s done using an OpenGL 2.0 fragment shader, so the precision isn’t amazing - there’s only so much you can do with 32-bit floating point numbers… But it’s not too bad if you can’t zoom in.

See it here. It requires the canvas 3d extension to be enabled, and OpenGL 2.0 support.

Julia Set 1 Julia Set 2

Posted on December 6th, 2007 in Uncategorised1 Comment

PropertyGrid

I quite like PropertyGrid. Here’s a simple dictionary editor made by binding a PropertyGrid to a DictionaryInfo object. :)

Dictionary Info Editor Selecting an Encoding

Posted on December 6th, 2007 in Code, SzótárComments Off

And the prize for worst installer of 2006 goes to…

Visual Studio 2005 Professional SP1!

It’s brilliant. Here are the installation steps, along with rough times.

  1. Extract 460MB .msp (windows installer patch) file from the executable into the user’s temp directory. (a few minutes).
  2. Run the 460MB patch file. This will cause it to validate the file’s digital signature. It reads the entire 460MB file into memory, and performs the verification. About 20 minutes.
  3. Copy the 460MB patch file into the parent directory (not move, copy) with a random name. A few seconds
  4. Run the second version of the 460MB patch file. This will also validate the file’s digital signature. About 20 minutes.
  5. Copy the 460MB patch file into C:\Windows\Installer. There are now 3 copies of it. If you previously installed SP1 and it broke (which it probably will), it won’t overwrite the existing one, because it chose a random name in step 3. So you may have any number of these 460MB patch files lying around on your windows partition.
  6. “Gathering required information”. It does this for about 2 hours.
  7. “Configuring <product name>”. It does this for about 30 minutes.

If you don’t have about 4 gigabytes of space free on your system partition (less if you move your temp directories elsewhere), don’t install this. It won’t install, the “retry” button you get when the install fails doesn’t work, and the installer will roll back all its changes.

…Or will it? As it happens, it doesn’t. If you’re unlucky enough to have experienced this, you’ll probably find that no .NET 2.0 application will run at all. Visual studio 2005 won’t run, neither will Office 2007, etc. The error message should be “The application failed to initialize properly (0xc0150004). Click on OK to terminate the application.”.

If you get this, Microsoft’s recommended workaround is to uninstall visual studio 2005, uninstall the .NET 2.0 framework, delete the policy files, and reinstall. A nice and quick procedure! In fact, that didn’t even work for me. Visual studio 2005 wouldn’t uninstall, presumably because ngen wouldn’t work, and the .NET 2.0 framework wouldn’t uninstall because it said things were using it.

Microsoft responded with: If you run into this problem again or for other people seeing this post after a search, first run “ngen update” from the command line (in %WINDIR%\Microsoft.NET\Framework\v2.0.50757) to fix the NGEN issues.. Unfortunately this wouldn’t work either, as ngen refused to even start up (0xc0150004 again).

At this point it was looking like a reinstall of windows might be in order, then I looked further down in the the the thread, at xumix’s post:

I managed to fix the problem:

  • go to c:\WINDOWS\WinSxS
  • search for 8.0.50727.163 AND 8.0.50727.762, then delete all files/folders that have this numbers in their name
  • then free up space and try to reinstall the SP1

Posted by xumix on 25/12/2006 at 01:12

So I tried this, and it was instantly fixed. How interesting. I don’t think I’ll be following the last part of his advice, in fact, I think I’m going to stay away from SP1… That sucks, because I believe it fixes this bug :(

Posted on December 29th, 2006 in Uncategorised1 Comment

The eightfold path to Enlightenment

1. Can you change £1 for me?
2. Can you change £2 for me?
3. Can you change £3 for me?
4. Can you give me £3?
5. Do you want your face smashed in?
6. I’m a nice guy, and I need the money
7. I’m seriously going to wait out here, smash your face in, and steal your money and pizza
8. I <3 Middlesbrough

Posted on January 20th, 2006 in Uncategorised16 Comments

Gamedev has a new theme…

Or will do, hopefully. I’m currently writing a new theme for www.gamedev.net. A sneak preview is available here, and at my GDNet Journal. Note that the journal doesn’t display all the images correctly yet, due to a bug which I have yet to report…
Screenshot of pink theme for Gamedev.net
A possible benefit of all this is that if they use my theme on the website, I’ll get a free year’s subscription of GDNet+, which works out at around 20 quid :D

A staff member (JohnHattan) said

My votes in the above are for Classic Black 2 (pretty), Pink! (funny), and Slim (decent alternative).

so perhaps I have a chance of getting my theme made available to people :)

Posted on December 9th, 2005 in GDNetComments Off