Archive for 2008

Slightly better WinForms Vista-style menus: Media::Rebar, and more!

I’ve recently refactored my WinForms NativeToolStripRenderer component: it’s now leaner and meaner, supporting some interesting vista styles, as well as right-to-left menus. Overall, it’s quite a bit better. (Thanks to windowsformsaero for improving the code somewhat).

The code is at http://code.google.com/p/szotar/source/browse/trunk/Client/Szotar.WindowsForms/Base/NativeToolStripRenderer.cs. Note that this ToolStripRenderer works fine with context menus, too.

To use this on all toolbars in your application, do the following near the start of your program:

ToolStripManager.Renderer = new ToolStripAeroRenderer(ToolbarTheme.Toolbar);

If you want different styles for different toolbars, set the renderer for that toolbar only when the form loads:

mainMenu.Renderer = contextMenu.Renderer = toolStripPanel.Renderer = new ToolStripAeroRenderer(ToolbarTheme.Toolbar);

Setting the Renderer for a ToolStripPanel should automatically render all of the contained ToolStrips in that style.

As I mentioned earlier, the renderer supports 3 new styles, which are new in Windows Vista:

  • Media::Rebar - like Windows Media Player
  • Communications::Rebar - like Windows Mail
  • BrowserTabBar::Rebar - like Internet Explorer 7 and 8
  • Help::Rebar - like Windows Help

On to screenshots:

Posted on Wednesday, December 10th, 2008 in .NET, Code | No Comments

Getting MozillaBuild 1.3 to work on 64-bit Windows Vista

There are a few things you need to do before it works. Firstly, you may get “\Microsoft was not expected at this time.” when you run start-msvc9.bat. Secondly, you may get “bash: fork: Resource temporarily unavailable” when you get into bash.

bash: fork: Resource temporarily unavailable

This was solved for me by copying the files in this archive into my C:\mozilla-build\msys\ directory.

\Microsoft was not expected at this time.

This probably happens because you’re using Windows x64 and MozillaBuild doesn’t like the C:\Program Files (x86) directory. I don’t know, cmd.exe isn’t very helpful. In my case, it was fixed by commenting out the following lines in start-msvc9.bat:

    set PATH=%SDKDIR%\bin;%PATH%
    set LIB=%SDKDIR%\lib;%LIB%;%MOZBUILDDIR%atlthunk_compat

    if "%USEPSDKATL%"=="1" (
        if "%USEPSDKIDL%"=="1" (
            set INCLUDE=%SDKDIR%\include;%PSDKDIR%\include\atl;%PSDKDIR%\include;%INCLUDE%
        ) else (
            set INCLUDE=%SDKDIR%\include;%PSDKDIR%\include\atl;%INCLUDE%
        )
    ) else (
        if "%USEPSDKIDL%"=="1" (
            set INCLUDE=%SDKDIR%\include;%SDKDIR%\include\atl;%PSDKDIR%\include;%INCLUDE%
        ) else (
            set INCLUDE=%SDKDIR%\include;%SDKDIR%\include\atl;%INCLUDE%
        )
    )

This code is for VC9 express, so it isn’t a problem for me, because I have the professional edition. If, like me, you’re not using the express edition, you can change it to something like this (or just remove it, if you feel lucky):

    REM ~ rem This call always fails with \Microsoft was unexpected at this time.
    REM ~ set PATH=%SDKDIR%\bin;%PATH%
    REM ~ set LIB=%SDKDIR%\lib;%LIB%;%MOZBUILDDIR%atlthunk_compat

    REM ~ if "%USEPSDKATL%"=="1" (
        REM ~ if "%USEPSDKIDL%"=="1" (
            REM ~ set INCLUDE=%SDKDIR%\include;%PSDKDIR%\include\atl;%PSDKDIR%\include;%INCLUDE%
        REM ~ ) else (
            REM ~ set INCLUDE=%SDKDIR%\include;%PSDKDIR%\include\atl;%INCLUDE%
        REM ~ )
    REM ~ ) else (
        REM ~ if "%USEPSDKIDL%"=="1" (
            REM ~ set INCLUDE=%SDKDIR%\include;%SDKDIR%\include\atl;%PSDKDIR%\include;%INCLUDE%
        REM ~ ) else (
            REM ~ set INCLUDE=%SDKDIR%\include;%SDKDIR%\include\atl;%INCLUDE%
        REM ~ )
    REM ~ )

If you’re using Visual C++ Express 2008, you may want try this instead.

Posted on Sunday, September 7th, 2008 in Code | No Comments

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 };
var directories = from name in Directory.GetDirectories(Path)
                  select new FileMenuItem(P.Combine(Path, name), false);
var files = from name in Directory.GetFiles(Path)
            select new FileMenuItem(P.Combine(Path, name), false);
return directories.Concat(files).OfType<IMenuItem>().ToList();
return Items.Skip(ScrollIndex).Take(ScrollViewCount);

It feels almost like Haskell. :)

Posted on Sunday, January 13th, 2008 in .NET, Code, Szótár | No Comments