ClocX did made me very curious about its click-through feature. The click-through effect looks very slick to me. That’s exactly what I had really wanted to be implemented on my BeeClock program years ago, but I had never successfully made it. Then I gave up and forgot about it. But, tonight ClocX raised my failed experience memory up again.
As usual, I started my search for answers adventure from Google. After playing around with appropriate search phrases, finally google took me to this page. The page shows me a clear solution, though the solution is originally written using VB.Net language. It’s even very easy actually as it just requires two simple API calls. I never thought it’s gonna be that easy! 😀
I wrote BeeClock using Delphi 5 on Windows 98. I wrote it on early 1999, when Windows 2000 had not been released by that time. And I never reopened its code on newer Windows releases. So, I never knew that click-through effect was already provided since Windows 2000. Obviously this effect is not supported by Windows 98. Unless, you got plenty of time to waste to implement this
not too important cosmetic effect without windows’ API. 😛
Well, now let’s talk about the real code. I’m now using Turbo Delphi Explorer. But Delphi 7 should be able to compile the code as well. Here’s step by step demo how to create click-through effect using Delphi:
- Create a new VCL form project. I assume the main form name is
- Write the code below at OnCreate event of Form1:
procedure TForm1.FormCreate(Sender: TObject); begin SetWindowLong(Self.Handle, GWL_EXSTYLE, WS_EX_TRANSPARENT or WS_EX_LAYERED); SetLayeredWindowAttributes(Self.Handle, 0, 255, LWA_ALPHA); end;
- Put a TTimer onto the main form. I assume the TTimer instance name is
- Go to Object Inspector and set the Interval property value of Timer1 to 1.
- Write the code below at OnTimer event of Timer1:
procedure TForm1.Timer1Timer(Sender: TObject); begin if (Mouse.CursorPos.X >= Left) and (Mouse.CursorPos.X <= Width+Left+1) and (Mouse.CursorPos.Y >= Top) and (Mouse.CursorPos.Y <= Height+Top+1) then SetLayeredWindowAttributes(Self.Handle, 0, 200, LWA_ALPHA) else SetLayeredWindowAttributes(Self.Handle, 0, 255, LWA_ALPHA); end;
- Run the program. You may hit the F9 key or click the Run icon.
Now, move your mouse pointer in and out of main form area to see the dynamic transparent alpha blend effect. And while your mouse is over the main form, try to click on the form. You should see the click-through effect in action. Pretty nice, eh? 😀 To close the application, you may use Alt+F4 combination keys (while the application is in focus) or right-click the application’s taskbar icon and click the Close item (if the application has lost its focus).
I suggest you to play around with the timer component. You should know the reason why I put the code in step 5 at OnTimer event of Timer1, instead of using OnMouseEnter and OnMouseLeave events of Form1. Also try to place the main form at various positions on the screen or over various objects of other window. You should see that the form visually shown but virtually invisible to the mouse.
Now I’m thinking of suitable application that able to take advantage of this cool effect. Any ideas? 😉