Click-through Delphi form

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:

  1. Create a new VCL form project. I assume the main form name is Form1.
  2. Write the code below at OnCreate event of Form1:
    procedure TForm1.FormCreate(Sender: TObject);
      SetWindowLong(Self.Handle, GWL_EXSTYLE, WS_EX_TRANSPARENT or WS_EX_LAYERED);
      SetLayeredWindowAttributes(Self.Handle, 0, 255, LWA_ALPHA);
  3. Put a TTimer onto the main form. I assume the TTimer instance name is Timer1.
  4. Go to Object Inspector and set the Interval property value of Timer1 to 1.
  5. Write the code below at OnTimer event of Timer1:
    procedure TForm1.Timer1Timer(Sender: TObject);
      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)
        SetLayeredWindowAttributes(Self.Handle, 0, 255, LWA_ALPHA);
  6. 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? 😉

5 Responses to Click-through Delphi form

  1. WishKnew says:

    Kepotong tuh codenya…

  2. bee says:

    Nggak kok, bro. Itu cuman kepotong di tampilannya doang (efek CSS), teks HTML sebenarnya lengkap. Coba kamu blok, copy, trus paste, kodenya masih lengkap kok. 😉

  3. yuan says:

    Ideku : bikin program untuk menutupi seluruh layar dengan warna transparan. Lebih bagus lagi kalo bisa nampilin gambar desktop dibelakangnya dengan dikasih beberapa efek, misalnya : warnanya di invert.

  4. Pribadi Pamungkas says:

    Ini yg udah lama aku cari-cari di internet.
    Akhirnya dapet juga, barusan udah aku cobain, sukses! persis seperti yg aku butuhkan.
    Makasih banyak sekali lagi….\:D/

  5. Bob says:

    Great tip! Thanx!

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: