Who is calling me? The *69 service in .NET


I recently started a project where I needed to add logging to an existing codebase. One of the requirements is that the class and method is logged along with the severity, message, exception (if there is one), date and time, etc, etc, etc. It started out not looking pretty with constants added to each class for just the class name or writing out typeof(blah).FullName and the method name each and every time, a message needed to be logged. I figured there had to be better way and parsing Environment.StackTrace (type string) didn’t seem to be it.

Looking through System.Diagnostics, I stumbled upon the StackTrace class and from there it was a skip, hop and a jump to figure out how to unwind the stack and get the information I needed.

StackTrace stackTrace = new StackTrace(1); //skip at least this frame
for (int frameCounter = 0; frameCounter < stackTrace.FrameCount; frameCounter ++)
{
    StackFrame frame = stackTrace.GetFrame(frameCounter);
    MethodBase method = frame.GetMethod();

    Console.WriteLine("Class: {0}, Method: {1}",
        method.DeclaringType.FullName,
        method.Name);
}

Simples.

Read more

Adventures in Windows Mobile Marketplace – Part 1

Let me first prefix this series with that I still use my iPhone for daily use.  Though, I so want Windows Mobile to succeed.  Partly it is my self interest in already knowing the development stack and not owning a mac and zero interest in learning Objective C.

Recently I upgraded my HTC Touch HD to Windows Mobile 6.5 which finally included the Marketplace app.  Like a kid in a candy store, I quickly started browsing to find some cool apps that would enable my Touch HD for daily use.  What I found though was slim pickings – i.e., 16 games (total).  Now, it is still early – the marketplace only launched on Oct 6th, 2009.

So I thought, hey, I wonder what would be required to be an “early” adopter.  And that is when mBubbleWrap was born. 

Read more

Windows 7 Taskbar Thumbnail Buttons and .NET

If you have been using Windows 7, then you have probably noticed the 3 little buttons just below the Windows Media Player thumbnail if you hover over it in the taskbar.  In this sample, I’m going to demonstrate how you can easily add your own – and when I say easy I mean easier than boiling water – that easy.

Read more

Interop’ng with Vista (Displaying Battery Power in the Taskbar) – Part 2

After a couple of days of developing (see previous post: Interop’ng with Vista (Displaying Battery Power in the Taskbar), I had a fairly working little utility to display the current battery status for my laptop working.  But what it had in functionality it lacked in appearance.

myMojo Battery Power Monitor v1

Every once in a while, I would pick up the project again, do some more Googling and try out a few more things but without any lock on getting the transparency to work.  All directions pointed at implementing the IDeskBand2 interface rather than the IDeskBand, though any attempt would just crash explorer when I would add the utility to the Taskbar.  So more Googling, more attempts later, I finally stumbled upon an excellent post which worked - http://cgeers.wordpress.com/2008/02/16/internet-explorer-toolbar/

I still implemented IDeskBand interface though overriding the OnPaintBackground using Geer’s supplied code

#region Transparency
[DllImport("uxtheme", ExactSpelling = true)]
public extern static Int32 DrawThemeParentBackground(IntPtr hWnd, IntPtr hdc, ref Rectangle pRect);
protected override void OnPaintBackground(PaintEventArgs e)
        {
            if (this.BackColor == Color.Transparent)
            {
                IntPtr hdc = e.Graphics.GetHdc();
                Rectangle rec = new Rectangle(e.ClipRectangle.Left,
                    e.ClipRectangle.Top, e.ClipRectangle.Width, e.ClipRectangle.Height);
                DrawThemeParentBackground(this.Handle, hdc, ref rec);
                e.Graphics.ReleaseHdc(hdc);
            }
            else
            {
                base.OnPaintBackground(e);
            }
        }
#endregion

and voila!

myMojo Battery Power Monitor v2

(and changing the progress bar to a set of images helped a lot)

Read more

Complete List of Visual Studio 2008 Keyboard Shortcuts

Read more