Control is an illusion Elliot !

Hello again !

It’s been a while. Well today I wanna write about a small [useful at the time] program i made like, 7 years ago, using Visual Basic 6. I found it while I was looking through my old stuff in an old website.

Here’s a sneak peek of it (and a link to it):

WindowControl screenshot

So what does it do ? Simple : click on capture the window, and navigate with your mouse cursor on the screen, you’ll notice the “Name” and “Handle” text boxes, changing and reflecting the windows’ and objects’ names under your cursor. Now click on the window or object you wanna control. That way you’ll catch the object’s handle; after that, you’ll have the possibility to crawl through the siblings and children or parent of an object using the “Window Navigation” buttons. After you’ve settled on the desired object, you can select an action: whether you want to enable it, disable it, maximize, restore, flash, hide or show it…

Why would I go through this trouble ? Well, again, boredom, and just for fun. Also, remember those trial programs that used to give you a “Try” and “Buy” button ?  And the “Try” button would be disabled after the trial period have expired ? Well, I thought, may be there’s a way I can force that button to be enabled. So, I dived down into it, and I discovered all kinds of things I can do with the Win32 API, that also enabled me to do just that. It was a great fun exercise for me.

So the thing is, I found the exe, but I couldn’t find the source code, so again, for fun, I decided to rewrite the whole thing, using nothing but C, and Win32 API, from the ground up. Here is the link to the source code (it’s a VS2015 project), and here’s the exe link.

Now I’ll try to quickly scan the code and explain generally the logic and what each block does, but I’m not gonna go into specific details, if you want to know more about, I suggest you read follow this tutorial, it have been a great start for me: winprog.org/tutorial/.

The WinMain function is equivalent to the main()  function for console program; it is the entry point for GUI programs, and in it, we declare a window class, that hold and the properties of the window we’re going to create from cursor icon, to color, to the icon, and so on :

After that, we need to register the window, create it and then show it in the screen :

And finally, to finish off with the entry point, we start the message loop that’s gonna handle the message queue :

Before I continue to the next part, I should point out that in this “new” version, you no longer have to click the capture button and click the object, all you have to do, is maintain the click on the button, and drag the mouse to your desired object (it’s like you’re simulating a drag and drop gesture). To accomplish that, I had to install a hook, that’ll intercept the mouse movements and process the outputs accordingly. Usually, to install a hook, you need to make a separate DLL file just for the hook and then use from your exe, but I wanted the program to be portable. So, I wrote the hook in the exe, and I will create a second thread, that’ll call the hook and intercept the mouse movements, and it goes something like this; I create the hook :

And then, I setupt the hook in this function that will be called by the thread :

And to finish off with the hook, I create a thread that will set it up, in the WM_CREATE  event, which will be triggered upon the creation of our main window :

The function WndProc , is the window function, that processes the messages sent to our window.

The rest of the work is done by sending messages to the target window, like what the navigation buttons do, or the actions list does.

To finish off, this is the switch case block responsible for executing the actions in the listbox :

As I said, in this article, I didn’t get into details, I just wanted to explain the general idea of the program.

But if you have any questions, suggestions, comments, criticism or something you need to be clarified more, hit me in the comment section.

Btw, sorry, I couldn’t think of any funny movie references to go with this… may be next time.

See ya.

 

One thought on “Control is an illusion Elliot !

Leave a Reply

Your email address will not be published. Required fields are marked *

* Copy This Password *

* Type Or Paste Password Here *