Now to complete the toolset required to make a great spyware / browser hijacking application, we’ll make Internet Explorer navigate to the address we set.
Like before, open an Internet Explorer browser and obtain a handle to the address field.
And the result:
This time we won’t be reading the text from a window, we’ll be setting it.
Like last time, open an Internet Explorer browser and obtain a handle to the address field.
And the result:
Note that we have not navigated to the address, we have only set it!
So we have a handle, what process does it belong to? Our goal is to obtain a .NET System.Diagnostics.Process object that corresponds to the owner process of the handle we input.
Let’s first open up an Internet Explorer window, just leave it at the start page, whatever yours is.
Now fire up Winspector and locate the Internet Explorer window, you’ll see the handle in HEX format in the treeview.
And the result:
First of all, to manipulate and use the Win32 API, we must know about the system itself, the windows, the controls and so forth. Visual Studio comes bundled with Spy++ which enables us to identity the various windows and controls of application, but honestly, it’s pretty bad. Instead you should download Winspector.
Threads & processes
Each application/window in Windows belongs to a given thread under a given process. A process may have multiple threads and windows, but a thread and a window can only belong to a single process.
Windows & handles
Usually we refer to a window as the overall container of visual representation of data in Windows, in this case it’s a bit more detailed though. In all API work a window is a standard Win32 control, that could be a button, a toolbar, a label, a window (as per the usual definition) and so forth. Each window is assigned a handle, and by using this handle we can uniquely reference any given window. A window may have any number of child windows, that could be the controls of a dialog box, and the children may have children themselves and so forth.
Try and mess around with Winspector a bit. Identify the various windows of the system (including those that are not visible). Inspect their properties, the process they belong to, their parent windows and so forth. Most, if not all, of the API tips & tricks posts will include references to windows, handles, processes and threads - so get used to them.
So, tell me, do you notice anything unusual in the picture below?
For a month or so I’ve used my computer with the Windows Start menu at the top. Am I crazy? Most likely. I started out doing it on my home computer (on all monitors), while keeping the start menu at the bottom at work. Honestly, it is feels quite weird and wrong in the beginning, and I was constantly throwing my mouse southwards just to realize that my work had been for nothing, as the Start menu was actually up north. I really couldn’t impose this waste of time upon my employers, that’s why I kept it down south there.
After a couple of weeks had passed, things started to shift. I was now starting to notice how wrong it was for the Start menu to be at the bottom at work - and how cumbersome it really is! So I moved it. And everybody laughed at me.
So why’d you want to move your Start menu to the top of the monitor?
See how all the menus are in the top? Usually - excluding gaming and other special applications - our mouse will be working inside a menu, dragging a window, using the Start menu, or in the main content area of a browser/application. Common to most of these are that they all happen at the top of the monitor. As the monitor gets larger, the distance between the top and the bottom becomes greater.
Having the Start menu at the top really saves a lot of mouse movement. The only negative side that I’ve become aware of is that you can’t just toss the mouse top-right like a maniac and click to close a window - that’ll now activate the system clock. When using multiple monitors, that really isn’t an issue as you wouldn’t be able to do that anyways since your mouse would enther the other monitor.
The greatest opponent of this efficiency improvement really is… Tradition. I shall not try to hide the fact that it takes a lot of getting used to. After having moved my mouse towards the bottom and hammering a fist in the table for the 100th time, I was almost about to give up. But hang in, for the sake of your carpal tunnel syndrome suffering hand, MOVE THAT START MENU!
Unfortunately it’s been quite silent around here for the last couple of months. I want to change that, so why not make a promise?
I’ve always been bullied by my wannabe developer friends for memorizing most of the Win32 (XP onwards) API. What they don’t realize is just how useful the API is - how powerful it is!
For the complete month of April 2007, I will post a new blog each day containing a Win32 API trick including demonstration code. Although my samples will be in C#, this being the Win32 API, it’s actually usable in more or less any language you want.
I look forward to my missionary work in the name of the holy Win32 API!