Tuesday, February 21, 2012

SingleWindow MutliProcess App


If you are using Google Chrome browser then you must have noticed that when you start Google Chrome, many chrome.exe processes appears in Windows Task Manager. Many people think that why there are so many chrome.exe processes are running when I have started only once Google Chrome browser, well that's because for every tab and every enabled extension chrome creates a new process to give you seamless experience of browsing even if any one of the tab or extension hangs due to any reason. When I first noticed about the Single chrome window with multiple tabs running each process for every tab, I wondered and thought they must have wrote awesome code to achieve this and never thought it would be so easy in reality. ;)
Here is how they might have done this -
Well that's very simple, you need to create a Main application window and then write your code in such a way that by any IPC technique when you get Handle for top most window you create new window as child window of this Main application window.
In C++, Win32 API you can create top main window using CreateWindow/Ex function, when you want to create a child window with different process create a new process of the same executable. Then pass this HWND to this process using any of the IPC method or simply in command line arguments to this new process, and design your code in such a way that when you get handle then you create new window using same CreateWindow/Ex api with this handle as parent handle and there it is. You get your SingleWindow multi process application. I will attach a sample code for this later.. :)
TIP: By SingleWindow I mean a single main application window with which user usually interact.

No comments:

Post a Comment

Ads Inside Post