Monday, January 19, 2009

Speed up OS boot process using all the processors you got

Well this is a trick that most of your know already. Anyway for those who does not know this and for those who actually have a Dual Core and Quad Core machines, you could use all these processors on Windows right from the Boot process. Here is how you do it.

Go to Windows Run (Windows + R) and type in msconfig.

image

Now in the application launched, go to the Boot tab.

image

Click on the advanced options and you should see something like this.

image

My machine has two cores so I could check the Number of Processors and set the number to 2.

Hopefully this helps you.

Wednesday, January 14, 2009

Aero Glass inside Window

Taken from http://blogs.msdn.com/adam_nathan/archive/2006/05/04/589686.aspx

Modified a little such that you can extend GlassWindow instead of Window and your XAML changes from <Window to <local:GlassWindow

   1: public class GlassWindow : Window


   2:    {


   3:        protected override void OnSourceInitialized(EventArgs e)


   4:        {


   5:            base.OnSourceInitialized(e);


   6:            GlassHelper.ExtendGlassFrame(this, new Thickness(-1));


   7:        }


   8:    }


   9:    public class GlassHelper


  10:    {


  11:        public static bool ExtendGlassFrame(Window window, Thickness margin)


  12:        {


  13:            if (!DwmIsCompositionEnabled())


  14:                return false;


  15:  


  16:            IntPtr hwnd = new WindowInteropHelper(window).Handle;


  17:            if (hwnd == IntPtr.Zero)


  18:                throw new InvalidOperationException("The Window must be shown before extending glass.");


  19:  


  20:            //Set the background to transparent from both the WPF and Win32 perspectives


  21:            //window.Background = Brushes.Transparent;


  22:            HwndSource.FromHwnd(hwnd).CompositionTarget.BackgroundColor = Colors.Transparent;


  23:  


  24:            MARGINS margins = new MARGINS(margin);


  25:            DwmExtendFrameIntoClientArea(hwnd, ref margins);


  26:            return true;


  27:        }


  28:  


  29:        [DllImport("dwmapi.dll", PreserveSig = false)]


  30:        static extern void DwmExtendFrameIntoClientArea(IntPtr hwnd, ref MARGINS margins);


  31:  


  32:        [DllImport("dwmapi.dll", PreserveSig = false)]


  33:        static extern bool DwmIsCompositionEnabled();


  34:    }


  35:    struct MARGINS


  36:    {


  37:        public MARGINS(Thickness t)


  38:        {


  39:            Left = (int)t.Left;


  40:            Right = (int)t.Right;


  41:            Top = (int)t.Top;


  42:            Bottom = (int)t.Bottom;


  43:        }


  44:        public int Left;


  45:        public int Right;


  46:        public int Top;


  47:        public int Bottom;


  48:    }




usage





   1: /// <summary>


   2:    /// Interaction logic for Window1.xaml


   3:    /// </summary>


   4:    public partial class Window1 : GlassWindow


   5:    {


   6:        public Window1()


   7:        {


   8:            InitializeComponent();


   9:        }


  10:    }




XAML changes to





   1: <local:GlassWindow x:Class="TryUserapp.Window1"


   2:     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"


   3:     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"


   4:     Title="Window1" Height="600" Width="600"


   5:     xmlns:local="clr-namespace:TryUserapp" WindowStyle="None"


   6:     >


   7:     <local:GlassWindow.Background>


   8:         <LinearGradientBrush EndPoint="1,0.5" StartPoint="0,0.5">            


   9:             <GradientStop Color="#CC101010" Offset="1"/>            


  10:             <GradientStop Color="#AA101010" Offset="0.01"/>            


  11:         </LinearGradientBrush>


  12:     </local:GlassWindow.Background>


  13:     <!-- -->


  14: </local:GlassWindow>


Tuesday, January 13, 2009

Button Looks in WPF

image

Smaller sized button.

image

The trick is to place a rectangle first, with the color of your choice. Then place another rectangle, with half the height on the top of this one and then give it a LinearGradientBrush, but half the height and place it on the top portion of the first rectangle. I would share more information on this, once my friend Ashish actually teaches me how to do this kind of stuff. Anyway, the XAML for this one is shown below.

   1: <Grid x:Name="LayoutRoot">


   2:         <Rectangle Fill="#FFF01717" Stroke="#FF000000" StrokeThickness="2"


   3: RadiusX="5.5" RadiusY="5.5" HorizontalAlignment="Stretch"


   4: Margin="240,163,247,0" VerticalAlignment="Top" Height="80" Width="241">


   5: <Rectangle.BitmapEffect><EmbossBitmapEffect Relief="1"/></Rectangle.BitmapEffect>


   6: </Rectangle>


   7:         <Rectangle Opacity="0.5" Stroke="{x:Null}" RadiusX="5.5"


   8: RadiusY="5.5" Margin="240,165,247,0" VerticalAlignment="Top"


   9: Height="38" Width="241">


  10:             <Rectangle.OpacityMask>


  11:                 <LinearGradientBrush EndPoint="1,0.5" StartPoint="0,0.5">


  12:                     <GradientStop Color="#FFFA1010" Offset="1"/>


  13:                     <GradientStop Color="#FFFFFFFF" Offset="0.01"/>


  14:                 </LinearGradientBrush>


  15:             </Rectangle.OpacityMask>


  16:             <Rectangle.Fill>


  17:                 <LinearGradientBrush EndPoint="0,0" StartPoint="0,1">


  18:                     <GradientStop Color="#FFE41818" Offset="0"/>


  19:                     <GradientStop Color="#FFFFFFFF" Offset="1"/>


  20:                 </LinearGradientBrush>


  21:             </Rectangle.Fill>


  22:         </Rectangle>


  23:     </Grid>


Monday, January 12, 2009

WPF Concepts : Real World Items that I need to learn

I have been researching on various UX elements that I plan to implement in my upcoming application and I thought I would make a list of the concepts that I should be learning and implement.

  1. Writing Custom Panels
    • For Element Flow
    • Mac Like Tray with Fish Eye behaviour
  2. Understanding HitTest
  3. Efficiently use Views to mimic an MDF like behavior.
  4. Scrolling Panel, like in the iPhone.

More as I recall.

Internet Explorer using 800+ MB

image

Quick snapshot taken at work

IE taking around 800 MB of memory while Visual Studio taking only 270 MB!

I would say "what the f**k is that?"

Sunday, January 11, 2009

Digging into Composite WPF applications

I am currently digging deep into Composite WPF applications for our side project which I am working along with a friend of mine. For anyone who wish to get started with Composite WPF application design and development, I recommend you first watch the screen-cast by Jason Dolinger on WPF Model-View-ViewModel and then go ahead to watch the DnrTV show on Prism by Brian Noyes.

With information from both the videos, I made a lot of notes on paper but I am having trouble implementing the same ideas to an application of mine. Anyway I hope to resolve this issue with time and I just need a quick start. In that process, I have looked at some slides by Noyes from a talk on Prism. The following is my observations (which might be incorrect) and notes on CompositeWPF and as well as on Model-View-ViewModel pattern in WPF.

A composite WPF application has the following parts

  1. Container – PRISM uses Unity Container by default. But it allows the developer to use any container of their choice. The Container is used to perform dependency injection (inversion-of-control). My understanding of dependency injection is – Project X would not refer to Project Y and yet be able to load Y at runtime. This makes both X and Y as loosely coupled as possible. By inversion-of-control, we mean that the control of generation of objects and dependent objects is moved from the host object to the container.
  2. Bootstrapper – Bootstrapper is a class (derives from UnityBootstrapper in CompositeWPF) that is used to manage the startup of the Shell program or the main window. The Bootstrapper also performs configurations as required – configuration of the container, configure the regions mapping using regions-mapping-adapter, creates the shell, initializes the modules. An instance of BootStrapper is created and Run() is called from the Initialize() method of the App.xaml. When bootstrapper is used, we remove the StartupUri  from the App.xaml. The bootstrapper is not a required component but is recommended. I usually go with any thing that is recommended.
  3. Shell – A Shell is a WPF Window – the main Window. This is the window that would be instantiated and shown from the Bootstrapper class. Shell knows nothing about the modules and is just the UI Container for the application (the root UI element).
  4. Modules – A module is an independent and loosely coupled unit of the composite application. It might be a GUI module with WPF Views inside the module or might just be a service module which provides the required services used by the application. One major addition that PRISM brings to WPF with CompositeWPF is the ability to load modules as and when required instead of referencing to the modules. This makes the application to be capable of extensions (like the Eclipse – the most popular extensible application). Some of the module loaders are StaticModuleLoader, DirectoryModuleLoader, etc.
  5. Views – Views reside in module. View is the visual aspect of the application. When we talk about views, i think it would be a good time to talk slightly about MV-VM pattern. In the MV-VM pattern, the code-behind or the View is kept very clean. Not much code would be written and the view goes through the ViewModel to interact with the Model. Model would have no idea about the View and View only deals with the ViewModel. View updates the model from the ViewModel using Two-way databinding, an excellent feature of WPF. In Jason’s talk, he actually mentions that a clean MV-VM implementation is one in whose View, the controls would not be required to have x:Name specified. I like this litmus test in particular since it is the most easiest way to ensure the MV-VM being followed. Composite View is a view that is composed other views and it is responsible for composing itself of the the child views. It might have content of its own.
  6. Services – Model are the data objects which are displayed/modified via the Views. But these objects are to be created using a service. For example, InternetQuoteService generates Quote objects to give to the QuoteManager application. Services also sit in the modules and typically follow the singleton instance model.

So why do we need to use CompositeWPF (CAL or PRISM or shit)?

Look at the baseline architecture of the Composite Application Library.

Cc707906.a9a1000e-510c-43eb-b8d0-8e8c7cdd604c(en-us,MSDN.10).png

If you would not use CAL, then you have the additional burden to implement all the portions that is in BLUE. And you should not forget that the design that you come up might not actually be a great design and using CAL helps you take advantage from the experience of the architects in the patterns & practices team. To summarize, the CAL provides the following services:

  1. Logging
  2. Region Managers
  3. Event Aggregators
  4. Module Enumerators
  5. Module Loaders

The Unity API

First of all, I read this amazing article on Dependency Injection/IoC and Unity which I unfortunately lost the link to. (remember I formatted my laptop). Anyway , get a good link and understand what dependency injection is and then you need to know that the unity api has the following important methods.

  • Register – tell the container that it is responsible for creating this object.
  • Resolve – fetch an object from container which was Register-ed.
  • BuildUp – inject dependencies into the existing object
  • Configure – Register based on the configuration information.

I would be writing more on my experiences and I feel I have invested a lot of time, just trying to understand the LOB aspect of WPF applications. I know how the UI should look in our application but want to do it the correct way from the beginning. Hopefully, I would have the basic structure for the application ready, as soon as possible.

If you are into CompositeWPF and are looking for someone to discuss ideas or for any other general discussion, you can reach me at krishna.bhargav@hotmail.com

Impact of community participation on my blog

For about one and half month, I was very much involved with the WPF community on MSDN. At that time, I had around 50 visitors everyday, which to my standards is a pretty leap. If you look at the graph that compares the visitors, you notice a decent hike in the number of visitors.

image

Notice the region with highest number of visitors between October 2008 and December 2008 which was when I was very active on MSDN community. Then I stopped my activity since I went lazy and then my visitors dropped – which makes sense.

So fellow bloggers, if you want visitors, then be active on the community. My numbers are not high but at least they were doubled with my participation on MSDN community.

Best Source Code Formatting Plug-in for Windows Live Writer

I use Windows Live Writer to write the blog posts and it is one tool that I always have it installed. Since I write developer posts, sometimes I need to post code snippets and this would be easier if we use one of the many code-formatting plug-ins that are available. But personally, I prefer the Code snippet plug-in. You can get it here. Just look at how nicely the code is formatted.

By default, your code snippet can look something like this.

   1: public class TestClass


   2: {


   3:     public string TestProperty { get; set;}


   4:  


   5:     public string AnotherProperty


   6:     {


   7:         get


   8:         {


   9:             return "Nothing";


  10:         }


  11:     }


  12:  


  13:     public static void RunProgram(string item)


  14:     {


  15:         int i = 200;


  16:         if(i==0x23 && item == "krishna bhargava")


  17:             Console.WriteLine("This program is crap");


  18:     }    


  19: }






You can notice that the source code snippet is cut-off and the scrollbar should be used. Personally, I believe that this annoys the user to great extent. Readers like to glance at the code and derive their own conclusions, without actually reading it thoroughly. Thus, it is good to have source code listed something like shown below.





   1: public class TestClass


   2: {


   3:     public string TestProperty { get; set;}


   4:  


   5:     public string AnotherProperty


   6:     {


   7:         get


   8:         {


   9:             return "Nothing";


  10:         }


  11:     }


  12:  


  13:     public static void RunProgram(string item)


  14:     {


  15:         int i = 200;


  16:         if(i==0x23 && item == "krishna bhargava")


  17:             Console.WriteLine("This program is crap");


  18:     }    


  19: }




You can do that by going into the source mode and modifying the style on the container div. The source code is placed inside a div when the plug-in I mentioned is used. In the style attribute of the container div, remove the property height: 253px; (the height might vary or might not be present) and also remove the max-height property. You can otherwise change the max-height property to something you like so that you can still limit the size of the source code section. Also removing "overflow: true” property allows you to remove the scrollbar altogether.



Anyway, if you are looking for source code plug-in for Windows Live Writer and if you like the code formatting displayed on this page, then you should get the plug-in.



Formatting problem in Blogspot.



image



If you try to use the code snippet plug-in in Blogger hosted blogs, then the source code could look something like shown above. This is because the blogspot engine somehow inserts <br/> tags between each lines making them look very ugly. You can fix this by going to the blogger dashboard of your account –> Layout –> Edit HTML. Scroll down until you see some styles being listed. Somewhere in between, insert the following CSS style:





   1: br


   2: {


   3:     display: none;


   4: }




Then the result should be what you want it to be.

Thursday, January 08, 2009

Running Windows 7 : Experience


I am writing my first blog post for the year 2009 from Windows 7 BETA, which was made available today to MSDN subscribers. I was more than excited to have it installed on my laptop (Dell XPS, 1 GB RAM). And I would like to share some of my experiences with the OS over here.

Installation

Like many said, it is not blazingly fast. It was pretty decent since the initial copying files took longer than expected and the actual GUI based installation was faster. I assume, more files than required were copied during the initialization of the set up. Overall, it went on pretty smooth and I think within 30 minutes I had my machine up and running. I do not exactly remember how long it took me to install Vista, but Windows 7 is pretty fast (though not as fast as in the reviews, may be my HDD is old and is too slow for that).

Initial Look.

Few interesting things – for me – the wall paper looks awesome – a fish floating on the desktop.

image
Notice the build number, since it is BETA. The installation keys are not available on the MSDN subscribers page at the time of this writing, so I have not yet activated my copy of Windows.

Startup, Shutdown and Restart

Start-up was fast – much faster than what Vista gave me. Moreover, I enabled the option to use both the cores on my machine during the BOOT process (using msconfig). I think it has decent effect on the boot performance. I wanted to try No Gui Boot but haven’t had the heart to take the risk.

Shutdown – I initially had few issues shutting the system down. It was not responding for a while, but the last few times I tried, it went on smooth. I think it has to do something with me starting the machine up in safe mode and then restarting the machine. But when it works, it is fast.

Restart – pretty fast.

New Taskbar

The new taskbar has a lot of feel. I think the taskbar is moving towards the OS X style but the difference is that the taskbar is 100% of the width in the Windows 7. The shortcut WIN + T, gives a nice summary of windows on your desktop, just above the taskbar. You can maximize a window by pressing Win + Up Arrow or by simply moving the window to the top of the screen. This is more of an easter egg than intuitive.

image

Also in the image, you can see the list of new shortcuts for windows 7. Quick Launch is gone and is replaced with the task bar itself where you can pin your applications. On my task bar, the first one is IE, so WIN + 1 launches IE. This, I think, would be very useful once we get the feel of the shortcuts. The window arrangement is pretty sweet too – OS X like feature to hide all windows by moving the mouse to the bottom right corner and brining up the gadgets (this actually sets transparency of the windows to 0, so they are invisible and if you have any gadgets, they appear). The Show Desktop is now the little rectangle very next to the time. Click that button, you get your desktop.

Start menu

The start menu also behaves differently. Applications can also be pinned to start menu (just like in the case of task bar)

image

Notice the Pin to Taskbar and Pin to Start Menu options in the context menu of the files.

image

Notice the Context Menu has changed – it is now more like a preview window than context menu. You can also pin a window to task bar from here.

Powershell ISE

Great news for geeks is that Powershell along with the new IDE (Powershell ISE) comes pre-installed. The Powershell ISE is very good and I believe it is WPF based, given its smooth zooming functionality (Ctrl + +). Zoomed ISE is shown below.

image

You can run powershell commands as well as write PS scripts. It has debugging capabilities too. I remember seeing something like in PowerGUI or not sure if it is the same one that I saw few months back. But this tool looks promising.

Mounting ISO

I tried to make Daemon Tools work on Windows 7 but the SPTD driver that is required does not get installed on Windows 7. So I installed Virtual CloneDVD. Initially even this did not work – the software got installed successfully but failed to show any new drives inside the Explorer. But after I rebooted the machine into SAFE MODE, I could see the new drives added. Then I switched back to normal boot and it worked.

Installing Visual Studio 2008 SP1, Silverlight on Windows 7

I had no issues with installing the VS 2008 SP1, Resharper 4.1, Silverlight 2 Runtime and PowerCommands. So far, things are working as expected.

Themes

There are new theme packs to change the looks of the windows shell. Not all are up to my taste, so I decided to stick with the default one. But there are some good themes, if you did like to try.

image 
The context menu on the desktop now includes Screen Resolution option.

image

Wireless

The Wireless settings were taken care at the beginning of the set up and it has been very good so far. The wireless repair, I read, is repaired automatically, if required.

UAC

The UAC is still on by default but the better news is that it does not block you from using other programs, if there are any running. It shows a shield like icon in the task bar and you get the UAC prompt when you click that. This is way better than the previous one in Vista.

ReadyBoost

ReadyBoost – using Flash Stick as paging cache to speed up paging is still present. I haven’t actually tried it to see if it made it any better.

Connecting to a projector

The image below shows the options (Win + P) and it looks sweet. This is way better and I am not sure if it is already present in Vista (haven’t used it before). Since I connect my machine to my HDTV, this is a really cool discovery for me.

image

Ribbon UI

Ribbon based UI, the one that came with Office 2007 is not everywhere. By this I mean, explorer does not have ribbon UI but Paint and Wordpad sure does.

image

Calculator

image

Calculator is improved – two more modes added (Programmer, Statistics). The Options are increased and shown in the image is the templates option. More on calculator later.

ANNOYANCES

There are some areas which I think needs certain improvements.

1. The wireless status icon color is deceiving. The color contrast between connection level and no connection is not good enough and when the connection is 100%, the icon appears as if there is no connection.

2. The shutdown that failed – it almost made my heart skip. I removed my Vista install, the one which I used for over 1.5 year to use this. So i was worried.

3. The taskbar is good but it does not display any text or name of the application. If you want to see the text, then you need to hover on the icon. I like visual information but little text would sometimes make more sense than the icons – at least in the beginning. Not many of us remember the icons of rarely used programs.

4. For some reason, my external HDD did not show up in the explorer when I connected it for the first time, during the first boot. It just worked fine from the next boot. No clue on why it happened.

OVERALL – 4/5

Excepting the annoyances listed, the experience so far is very good. The UX is improved vastly though most of the UI looks like Vista, it is the feel that has changed drastically. My system rating was 2.0 given my age old HDD on the laptop but on a 1 GB machine, the OS is very fast and I feel it is even better than XP. Performance is good – starts up fast, shuts down fast, reboots fast – that is great news for others, for me it does not matter since I hardly shut down my laptop. Users versed with Vista would find no issues working around the UI since the UI principles are the same. And since I liked it, I consider Windows 7 (even the BETA) to be worthy of trying out.

Though, the post is not exactly descriptive, I tried to show as many images as I can. I hope to cover more details in subsequent posts.