30
Sep
2009
Să numărăm ferestrele …
By DarkByte. Posted in De-ale vietii, Delphi, IT thingies | 4 Comments »
There are (a little) more that 11 years since, for the first time, I found Windows. I have had decided, after some ferm assurances that I would be helped if necessary, to try for the computer department in highschool, although I haven’t had seen a computer in my life before (this doesn’t count movies … and there they look good
)
Before the entrance exams in the summer of 1998 I was taken by my mother to her job where, at some offices, there were some computers, and the boss daughter used to play there often. Obviously, I went to see how a real computer looks like. Of course that, bright as I knew I was, I imagined that in two weeks I would learn everything that was possible about computers (I don’t really watch a lot of movies since that disillusionment
).. Ştefania, the aforementioned girl, was a year older than me (already in highschool, computer department too) wasn’t born to be a teacher, so she pushed the power button, some white on black lines started to move on the screen, and I was staring at it. When the lines got tired of moving around, Ştefania wrote three letters, w, i, n and then pushed Enter (Enter … meaning a big key near the center of the keyboard).
Windows. Versiune: 3.11. Everything became bright, mostly white. Some windows. Then little colorful drawings, in each ocean of white. I immediately noticed that she dived into an ocean full of games and kept on swimming until she found Solitaire. It has been interesting, but … I mean, I don’t let the playing cards home down to play cards on a computer.
It’s been a long time since (from my point of view), but I sticked with Windows. This is another way of saying that it’s still raining windows. To be honest, it’s been good years since Linux got windows, too…
Until recently, I had forgotten how much did the Windows’ windows fascinated me in high school (especially after the Olympiad in Informatics from the 9th grade … I was told to copy my source files onto a diskette, using Windows … very penitently, I had to explain to Mrs. Teacher that I had no clue how to do that). So much that, in my 11th grade, I made a program, in Delphi, that would list all the windows from the system, including the hidden ones … and, even more, to allow me to play with’em
Put them always on top, hide them, move them … good days ![]()
Assuming you had patience up until now, in the next paragraphs I will present this little program, explaining some pieces of the code and, as before, to offer it as open-source.
The first function I needed was EnumWindows, an API function that retrieves the full list of the system’s windows, requiring two parameters: a callback function and programmer-defined value to be passed to this function. To be perfectly honest, I couldn’t quite get what that freaking callback is and why, in this case, it would need a parameter for a handle of a single window and my parameter. I mean, in a system there are hundreds of windows … how would it get them all in a single handle?
I solved this problem quickly by displaying that “unique” handle (as I was expecting) in a ShowMessage. Do I still need to say that after the 20th ShowMessage I went back in Delphi and hit Ctrl + F2 (program reset) ? The callback function was called for every main window found by EnumWindows, giving me it’s handle.
Oh goody … the list of windows is done. I have a list of handles to windows which, honestly, looks smashing. Hammer smashing. I wanted something flashy, eye-candy, something that would show, to whoever would watch, that the program is super-mega-ultra-blah-blah. Hmm … the title of the window (usually, it’s caption-bar) would go well …
I went to finding the window’s name, something that was generously offered by GetWindowText, if you bribe it with the window’s handle and a little room to spill the characters.
Yeah, it’s already looking better. Still, there are a lot of weird names around here. CiceroUIWndFrame, curtain, AXWIN Frame Window, DDE Server Window, SysFader … WTF ? Microsoft sucks! What the hell is with this windows ? We need to see them ![]()
ShowWindow to the rescue. A very attractive and funny function. Give a handle, say SW_SHOW and voila … the window got out from the mist. Say SW_HIDE and … you’ll never knew it’s been there. It also knows some other stuff, but if you’re interested, all you need to do is to RTFM on the above specified link.
This was a real big moment. I realized that, considering the Get / Set function pairs, there had to be a SetWindowText. Lucky bet. I rapidly implemented the functionality and I was very proud of myself when the Windows Explorer window was calling itself as “Bond. James Bond”. I’m kidding, obviously. It was calling itself “Pop. Victor Pop”.
No matter the name, the function SetWindowPos takes care the Z-window placement, setting the top-level windows, not to mention the obvious fact that it can move / resize the window. It has been a pleasure to use this function to set a randomly picked window to be Always On Top or Always … not.
The rest of the code should be clear enough, but if you have any problems with it, let me know. I’ll try to play the good Samaritan, once in my life ![]()
Download:
Sursa : [download id="2"]
Executabil : [download id="1"]
Screenshot
DarkByte is
Email this author | All posts by DarkByte | Subscribe to Entries (RSS)


October 1st, 2009 at 8:21 PM
M-am distrat copios citind articolul
, acum pot sa invat mai usor la biologie :-#
.
Sti, acum, din cauza ta, evident, o sa ma apuc si eu curand de Delphi, dar intai trebuie sa ma mai zbengui in c++, in matricele si vectorii doamnei profesoare, care a reusit sa ma ameteasca total.
Keep up the good work, DarkByte !
October 1st, 2009 at 8:26 PM
Mi-a povestit si mie intamplarea.
October 16th, 2009 at 3:34 PM
îmi aduc şi eu aminte de olimpiada aia..la Goldiş s-a ţinut….ce habarnistă eram de Pascal, mai ţii minte?
October 18th, 2009 at 11:19 AM
Hello there
Nu mă aşteptam să mă găseşti aici, dar e o surpriză plăcută.
Nu-mi amintesc prea multe de cât erai tu de habarnistă, abia ne cunoşteam. Îmi amintesc, în schimb, ce habarnist eram eu
Ce-mi amintesc de atunci e că, parcă, ai ieşit înaintea mea şi m-ai aşteptat fiindcă nu aveai tren.
Trebuie să ne întâlnim şi să depănăm amintiri o dată …