Attention: We are retiring the ASP.NET Community Blogs. Learn more >

David Cumps

#region .Net Blog

  • Custom Run Box (Resource Hacking)

    It's time for a new article, but not about C# this time. I'll tell you how to modify Windows, we'll change the Run box and make it look like this:



    First of all the disclaimer: This article is purely informational, you don't have to do anything because I tell so, everything you do is on your own risk and I am not responssible when anything goes wrong.

    With that out of the way, grab the tools if you don't have them yet:

    We'll begin by copying shell32.dll to a safe place.

    Copy it two times, one which we'll be editing, and one which is a backup.

    Open it in ResHacker and you'll see a list on the left side showing all available resources.



    Now select the 'Dialog' resource, and look at 1003. You'll notice it's the Run box.



    We'll start by adding a bitmap to place on our Run box. Go to 'Bitmap' and select 'Action', 'Add a new Resource'.



    Here you select a bmp file and give it the name RUNGFX. You can get the bmp I used here: Runbox.bmp.



    Press 'Add Resource' and now you can see it's added.



    Now we'll go back to the 'Dialog' 1003, 1033 and replace the existing script with this one:

    1003 DIALOGEX 0, 0, 188, 83
    STYLE DS_FIXEDSYS | DS_MODALFRAME | DS_NOIDLEMSG | DS_CONTEXTHELP | WS_POPUP | WS_CAPTION | WS_SYSMENU
    CAPTION ":: run ::"
    LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
    FONT 8, "MS SHELL DLG"
    {
    CONTROL "", 12298, COMBOBOX, CBS_DROPDOWN | CBS_AUTOHSCROLL | CBS_DISABLENOSCROLL | WS_CHILD | WS_VISIBLE | WS_VSCROLL | WS_TABSTOP, 3, 53, 181, 198
    CONTROL "R", 12306, BUTTON, BS_AUTOCHECKBOX | WS_CHILD | WS_VISIBLE | WS_DISABLED | WS_TABSTOP, 21, 90, 1, 1
    CONTROL "Run", 1, BUTTON, BS_PUSHBUTTON | WS_CHILD | WS_VISIBLE | WS_TABSTOP, 3, 67, 59, 14 , 0x00020000
    CONTROL "Cancel", 2, BUTTON, BS_PUSHBUTTON | WS_CHILD | WS_VISIBLE | WS_TABSTOP, 63, 67, 59, 14 , 0x00020000
    CONTROL "Find", 12288, BUTTON, BS_PUSHBUTTON | WS_CHILD | WS_VISIBLE | WS_TABSTOP, 124, 67, 59, 14 , 0x00020000
    CONTROL "RUNGFX", 0, STATIC, SS_BITMAP | WS_CHILD | WS_VISIBLE | WS_GROUP, 3, 3, 181, 48
    }

    To make your life easier, and to be sure you don't make a mistake due to your browser word wrapping the script, copy paste it from this text file: runscript.txt.

    When you have replaced it you press 'Compile Script'.



    And now you'll see the preview has changed to our new runbox!



    Press CTRL+S to save the modified dll.

    The last thing we need to do is to use Replacer to replace our existing shell32.dll in SYSTEM32 with our new file. You can't just copy it in there because Windows File Protection would replace it with a backup. Therefore we use Replacer, just follow the instructions Replacer shows and you'll be fine. Replacer also prompts you to make a backup, make sure you make one, you never know what can go wrong.

    When the file is replaced (Replacer replaces the file itself along with the one in dllcache) you have to reboot and when everything went fine, you now have a new Run box! A really good looking one, different from everyone else.

    Some notes:
    If you move the controls around, make sure to not place any above or behind the bitmap, it could give problems. Also don't include a bitmap bigger then your box. Make sure you leave a bit of spaces from the edges, when you put the bitmap against the border, it won't show up.

  • Drivers License Progress

    Today I took the theoretical drivers license exam. And I passed it! With 0 mistakes! :)

    The only thing that's left now is the practical exam. But that's still a couple of months away.

  • ConvertToProperties Macro

    For everyone who received .NET Magazine #5, there's an article in there at page 53 about cleaning up your code.

    Jan Tielens mentions a ConvertToProperties macro, which is really sweet!

    But there has been a printing error or something, the link went missing on page 55 in the bottom box. (http://xxx/...)

    So, here is it: Create Property Macro for C#.

    The version on the site doesn't correspond to the screenshots, it doesn't use mVariable (any more?), but replaces it with _variable (which I prefer).

    Be sure to get this macro! It saves you a lot off time ;)

  • Passed another year!

    Exams are over and I got my results. I passed with 'Highest Distinction', you can only guess how happy I am :p

    Dutch details at: www.cumps.be

    Now only a half year of school left, and then it's time to do an interim at a company :)

  • Passing bitwise OR enum values

    Everyone who has ever used a Regex knows this form of parameter:

    1Regex r = new Regex("", RegexOptions.Singleline | RegexOptions.IgnoreCase);
    I often wondered how to do that as well and because nobody ever taught me that at school, I had to figure it out myself. And today I did, and I'm sharing :)

    This is very usefull if you have a class that takes a lot of options and you don't want to add a bool for each possible option.

    First you need to create an enum with the possible options, and number them binary. (eg: 1, 2, 4, 8, 16, ...)
    1  public enum Pars {
    
    2 One = 1,
    3 Two = 2,
    4 Three = 4,
    5 Four = 8,
    6 Five = 16,
    7 Six = 32,
    8 Seven = 64
    9 } /* Pars */
    Next you need to have a method which takes this enum as a parameter, after which you can extract each of the possible options from it with a bitwise AND:
    1  private static void TestPars(Pars options) {
    
    2 if ((options & Pars.One) == Pars.One) { Console.WriteLine("One"); }
    3 if ((options & Pars.Two) == Pars.Two) { Console.WriteLine("Two"); }
    4 if ((options & Pars.Three) == Pars.Three) { Console.WriteLine("Three"); }
    5 if ((options & Pars.Four) == Pars.Four) { Console.WriteLine("Four"); }
    6 if ((options & Pars.Five) == Pars.Five) { Console.WriteLine("Five"); }
    7 if ((options & Pars.Six) == Pars.Six) { Console.WriteLine("Six"); }
    8 if ((options & Pars.Seven) == Pars.Seven) { Console.WriteLine("Seven"); }
    9 } /* TestPars */
    When all this is done, you call the method, passing the options you want with a bitwise OR between them, like this:
    1  static void Main(string[] args) {
    
    2 TestPars(Pars.Three | Pars.Five | Pars.Seven);
    3 }
    This example will print Three, Five and Seven.

    How does it work internally?

    Here are the rules for the bitwise operators:

    Bitwise OR:
    0101 (expression1)
    1100 (expression2)
    ----
    1101 (result)

    Bitwise AND:
    0101 (expression1)
    1100 (expression2)
    ----
    0100 (result)

    Now, our enum has the following binary values:

    1 - 0001
    2 - 0010
    3 - 0100
    4 - 1000
    ...

    If for example we pass the options One and Two along, we combine them with the bitwise OR, creating 0011.

    And if we want to check if Four was passed along, in our if we check if the options combined bitwise with Four result in Four.

    0011
    0100
    ----
    0000

    Four was not passed.

    If we check with Two we get the following:

    0011
    0010
    ----
    0010

    And 0010 = Two, our if = true, and Two was passed along.

    A lot of you will say "well duh, that's basics". Could be true, but I never learnt it at school, and never ever had the need for it, but now I wanted to know, and I guess there are more people out there who haven't learnt it either.

  • Troubleshooting DotNetNuke 2.1.2 Installation

    I had a lot off trouble installing DotNetNuke. This popular portal application kept me busy for an entire afternoon and night.

    First I got ASP.NET errors about columns missing in tables, then about stored procedures. When those were gone, the application itself managed to hang IE.

    So, for everyone else who might be suffering from this, or will give it a try and encounters the same, here's my installation guide for 2.1.2:

    The SQL errors occured when using SQL Server as Data Provider, the IE errors always occur.

    This step is for everyone using SQL Server:

    • Download DotNetNuke_2.0.4.zip.
    • Extract this, follow the normal installation procedure, this version doesn't give any problems.
    • Open the site so that it creates the tables and stored procedures.
    • Download DotNetNuke_2.1.2.zip.
    • Delete all files from 2.0.4 but keep your SQL Server tables.
    • Extract 2.1.2 in the same location.
    • Open the site, now you got passed the missing columns errors!
    This step is for everyone:
    • Download DotNetNuke_2.1.1.zip.
    • Extract this to a temporary location and get the file spmenu.js from controls\SolpartMenu.
    • Copy this file to 2.1.2 overwriting it.
    • You now fixed the IE errors!
    And at this point you got a working DotNetNuke 2.1.2 version, which you can begin skinning etc.

    Let's hope future versions don't require so much hasstle.

  • Won at the DigiKids 2004 Awards!

    I'm happy! A site I created for someone has won a price at the DigiKids 2004 Awards.

    I heard there were 120 submissions, and the one I created ended up with the 10 best sites! This is a very nice extra as a student, now I can tell something I coded lasted between 120 others! :)

    The results are in Dutch, but if anyone is interested: Prijs van de Minister van Onderwijs - Communicatorprijs.

    Some extra info about the site: Connectedly