Arian Kulp's Blog
opinion, insight, and occasional code

Office 2007: Search Commands

If you haven't seen this yet, it's very cool.  We all know that Office has way more in there than most people ever see.  The 2007 ribbon made a big difference in making the commands more visible, but it still doesn't reveal everything in the default views.  If you are ever unsure where to find a command, or better yet, if it exists, the Search Commands toolbar is for you!

I've only had it installed for a few days, but I just love it.  It can be faster than trying to remember where something is, and I've found features that I wasn't aware of a few times.  Cooler still, when it shows your search results (which are the actual buttons themselves!) they indicate how to find them (or if they are currently hidden).  It has a simple purpose and it works very well.  I'm kicking myself since I bet it would have been a great VSTO sample app to create!

 

image

 

Source: http://www.officelabs.com/projects/searchcommands/Pages/default.aspx

File recovery

If you've ever deleted a file when you should have really sent it to Recycle Bin, perhaps you have an idea of how I felt last night when I deleted 1GB worth of video files for my older son's school project.  First I "lost" about a dozen files. I still have no idea what went wrong.  Windows Movie Maker all of a sudden showed X's for clips.  The containing folder was just empty.  I had imported some additional videos into a subfolder of that one using Picasa, but I can't imagine it would just wipe out the parent during an import! 

Then to make things worse, the deletion/disappearance got me thinking about files/folders that I didn't need.  I deleted a few folders that I didn't need (not recycle, but SHIFT+DELETE to actually delete them).  Then I did it.  I accidentally deleted the remainder of his project's video clips.  I just sat there for a second slack-jawed.  What the #@$* is wrong with me that I just carelessly deleted more files?!

At this point I didn't know what to do. I have used undelete utilities in the past, but given how much happens in the background with Vista (and Picasa, and Windows Movie Maker) I was sure that there would be nothing left to recover.  On another computer I downloaded and unpacked NTFSUndelete.  I didn't expect much.  It churned and churned for several hours.  Actually, I had to abort it since it locked up at one point.  The second time it succeeded and found my files!  I couldn't believe it!

At the same time, I figured I should try to recover from the camera's memory card (FAT32).  Sadly some of the files would have overwritten others due to the way we shot/uploaded/shot the clips.  Since NTFSUndelete is only for NTFS volumes, I tried FreeUndelete.  Miraculously this worked did the trick!  A few videos couldn't be recovered, but between this recovery and what was on the hard drive, I ended up getting everything back.

Now that I think of it, I should have immediately powered down and booted with MiniPE (not sure how legit this is...).  It doesn't touch the hard drive (it boots from CD) and includes some good file recovery tools on it.  From within Windows though, I would definitely recommend either FreeUndelete or NTFSUndelete.  They are both free and both work well.  Just be sure to download them on a different computer and run them from a memory stick!

http://officerecovery.com/freeundelete/ (anything...)

http://ntfsundelete.com/ (only NTFS)

Stupid Forms Tricks!

Wow.  I've just learned something that should be a no-brainer.  It's not like this has happened that often, but there have been a few times that I've tried to use a StatusStrip control in a UI (Dock = Bottom) with some other control filling the rest of the form (Dock=Full).  I've always given up since the Fill control always goes behind the StatusStrip (presumably any Dock=Bottom control).  My "solution" has been to eliminate the docking and size the larger control explicitly above the StatusStrip, then anchor it in all directions.  Not a great solution.

The anchor handles of the Fill component are at the bottom of the form

Figure 1:Notice the anchor handles (of the Fill component) at the bottom

The solution to this dilemma is so simple I'm just kicking myself!  It turns out that all you need to do (with both controls docked properly) is select the Fill control and bring it to front.  That's it:

The bring-to-front button is in the Layout toolbar

Figure 2: The "Bring to Front" button

Not the larger control is properly set in z-order.

The Fill component is now placed above the StatusStrip as expected

Figure 3: Now the anchor handles are in the right place!

Thought I've searched for a better solution in the past, I've always given up before finding it.  Lo and behold, this was my lucky day!

 

Source: http://www.tek-tips.com/viewthread.cfm?qid=1457018&page=3

Javascript Image Resizing

I have an ASP.NET project where I need to resize images on the client.  Why would you need to do that?  Well, you don't always know the images you are displaying.  If you are storing the images, or want to pre-fetch them, then you can build thumbnails on the server.  On the other hand, if you just have arbitrary images (most likely user-embedded) you may want a consistent thumbnail size without knowing anything about them to begin with.

I did lots of searching on this topic and never did find exactly what I needed, hence this post.  My end solution relies on a combination of JavaScript and minimal CSS.

If you've ever tried to resize images on the client side, you know how easy it seems (at first).  Just set the height and width attributes of the img element.  What's wrong with this approach?  Well I'm sure you've seen the squashed images that result from this.  If you don't know the original dimensions, you can't calculate the new resized dimensions to maintain the aspect ratio.  In the course of my searching, I came across this older post by Tom Davies.

This works very well, but isn't quite as flexible as I wanted.  For one thing, it only uses one dimension for the thumbnail bounding box.  I wanted to be able to set separate sizes.  I also wanted to prevent the image from sizing large initially as it loads, then "snapping" into its resized form.  This looks funky, but it also proved to ruin layout in Firefox (once it made room for the large format, it never seemed to layout again with the smaller size).  The simple solution to the layout issue is to enclose the img element in a div which is set with overlap: hidden.  This allows the image to load however it needs to but it never takes up more space than its box.

Some things that I learned: you need the actual dimensions of the image in order to calculate the new size.  If you set either height or width (thinking it will allow better layout), the element will then report that number as its dimension.  This makes it imperative that you leave those attributes out of your images.

I also learned that you can't set the display css property to none.  This causes the image to not even be loaded in IE (though it still raises the onload event).  If it isn't loaded, it will return zeroes for dimensions.  Setting visibility: hidden is fine as it preserves layout.  This is what I did, in combination with overlap: hidden so the thumbnail pane would appear blank until it was loaded and resized.

I used one CSS class for thumbnails (in conjunction with overriding the onload event), and a second class to indicate thumbnails that have been sized (to prevent double-work for whatever reason).  You could write a function to enumerate all elements of your thumbnail class if you wanted to once the document completely finished loading, but this worked well for me.  I simply call ResizeImage(this, 50,50) and it passes the element (no calling GetElementById()) and size at the same time.

The function is here:

function ResizeImage(image, maxwidth, maxheight)
{
    if (image.className == "Thumbnail")
    {
        w = image.width;
        h = image.height;
                
        if( w == 0 || h == 0 )
        {
            image.width = maxwidth;
            image.height = maxheight;
        }
        else if (w > h)
        {
            if (w > maxwidth) image.width = maxwidth;
        }
        else
        {
            if (h > maxheight) image.height = maxheight;
        }
                
        image.className = "ScaledThumbnail";
    }
}

The "zero" case is a bit unfortunate, and possibly even ineffective, but is intended to deal with an image that hasn't completed loading yet. It might be better to abort and leave this image alone (without modifying the CSS class), but likely the function wouldn't be called on it a second time.

The surrounding DIV tag can be given a border if desired, but I've had trouble keeping the box at the right dimensions across browsers -- and centering the image within the box for multiple browsers is not an exercise for the faint-at-heart.  This method makes it easy to resize images on the client, but you'll need to decide what to do with it then!

Record your Skype calls

(via LifeHacker)

I'm digging the Call Graph call record for Skype.  It works well and does what it's advertised to do.  I can't find any bitrate or other settings unfortunately, but the files seem to be small enough and pretty clear.  For clean integration into Skype + free, you really can't go wrong!

http://callgraph.in

I love UPS!

Not the delivery service (though I love them too), but Uninterruptible Power Supplies.  I just had a circuit breaker blow three times (until I figured out what was causing the problem!), but nothing bad happened to my systems.  Considering how much I always have running, just having the power disappear is a Very Bad Thing(TM).  I recently bought a ~$30 UPS power supply which is more of a fat circuit breaker strip.  It's not all that powerful, but it's more than sufficient to keep me going for five minutes while I reset a circuit breaker.  What a great investment!  Don't wait until it's too late to pick up one of these...

 image

Ticked off

I was deploying some files to IIS on a Windows Server 2003 box and I ran into quite a problem.  I kept getting an error:

Ticks must be between DateTime.MinValue.Ticks and DateTime.MaxValue.Ticks.  Parameter name: Ticks

when I would try to hit some of the pages.  It was clearly not code related, and the stack trace indicated a problem with the compiler itself.  I found posts talking about this error when you used serialized objects between different versions of the .NET Framework (something to do with changes to the DateTime object from 1.1 to 2.0), but that clearly wasn't it.

I finally found the problem.  It's a weird one!  As I was browsing around the web folder, I noticed something funny.  The Date Modified property for the files in question were... blank!  Nada.  Nothing.  I can't figure out quite how this happened, but that was it.  I opened the files and saved them (touch).  The problem disappeared.

The only thing I could think of was the fact that the files were dragged out of a ZIP file (using the built-in ZIP Folders features of Windows 2003).  I tried this again, but did not get the same effect.  I don't know how it happened the first time, but the fix was definitely easy enough!

My guess is that the compiler gets a request for the file, and compares the Date Modified property to see if the contents have changed in order to know if it should recompile.  Obviously the check failed with a blank date.  I'm not even sure what that would mean behind the scenes.  Was it NULL?  Was it some early date that Windows supports internally but DateTime doesn't?  I don't know.  I do know that it's a quick fix if I ever see it again!

I hope this can help save someone else frustration!

UPDATE (3/31): It just happened again and I've taken a screenshot this time.  One other theory is that this is related to TortoiseSVN (a Subversion client).  I exported some files and moved them to my working directory and then couldn't even build the project due to date-related issues:

Windows Explorer showing blank

Coding 4 Fun - Startup Optimizer

After a long delay, I've published another Coding 4 Fun article.  This one is a good start toward optimizing Windows startup.  It scans your Startup folder and will start the items at boot-time instead of Windows.  The advantage is that it can insert a delay between each application, or even wait for an idle CPU before launching one.  It uses user controls, a background worker, threading, and a number of other cool features.  This will be my last XP/VS2005 article.  Everyone should be on Visual Studio 2008 now!  As for Vista, well I'll try to make things work in both OS's unless it's a very Vista-specific feature that I'm exploiting.  Enjoy!

[Article link]