Solved

Click-through forms

Posted on 2001-08-03
4
628 Views
Last Modified: 2010-05-18
Delphi 6 now provides the ability to create an alpha-blended (i.e. translucent) form. What I would like to do is create a form like this, with FormStyle = fsStayOnTop, as a sort of 'watermark' that always shows as a light overlay in front of whatever's on the screen. The problem, of course, is that with my form in front of whatever else is on the system, mouse clicks go to my form, not to things behind my form. So my question is, how can a Delphi form be made 'transparent' to mouse clicks - i.e. make sure all mouse clicks are routed to the window in the second-topmost position at the pixel that was clicked. Bonus points if you write the code for me. :-)
0
Comment
Question by:ghjm
  • 2
4 Comments
 
LVL 21

Expert Comment

by:gemarti
ID: 6351070
This works, but may not be what your looking for. I'm just guessing since D6 is new to me:

Create a new application.
Place a Button and a edit control on the first form (Form1)
procedure TForm1.Button1Click(Sender: TObject);
begin
  Form2.Show;
end;

Create a second form (form2)

Set AlphaBlend := true;
AlphaBlendValue := 100 (or any value from 0..255 where 255 is the least transparent)
Set TransParentColor := true;
Set TransParentColorValue := clBtnFace (or whatever color works for you)

Add these lines of code:
procedure TForm2.FormActivate(Sender: TObject);
begin
  Form1.Button1.Parent := Form2;
  Form1.Edit1.Parent := Form2;
  Form2.AlphaBlendValue := 200; //if you leave at 100 you can't see the components very well.
  Form1.Button1.GetParentComponent;
end;

procedure TForm2.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  Form1.Button1.Parent := Form1;
  Form1.Edit1.Parent := Form1;
  Form2.AlphaBlendValue := 100;
end;
0
 
LVL 9

Accepted Solution

by:
ITugay earned 100 total points
ID: 6351234
Hi ghjm,

may be this code would be usefull for you.

procedure TForm1.MouseRedirect(Sender: TObject; Action: Integer; X,Y: Integer);
var
  C: TPoint;
  H: HRgn;
  L: HRgn;
begin
  C.X := X;
  C.Y := Y;
  C := TControl(Sender).ClientToScreen(C);

  // create empty region and assign it to the form to make form
  // transparent for mouse clicks
  H := CreateRectRgn(0, 0, 0, 0);
  GetWindowRgn(Handle, L);
  SetWindowRgn(Handle, H, False);
  DeleteObject(L);

  mouse_event(Action, X, Y, 0 ,0);

  // restore form region
  GetWindowRgn(Handle, L);
  SetWindowRgn(Handle, 0, False);
  DeleteObject(L);

end;

procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
  if Button = mbLeft then
    MouseRedirect(Self, MOUSEEVENTF_LEFTDOWN, X, Y)
  else
    MouseRedirect(Self, MOUSEEVENTF_RIGHTDOWN, X, Y);
end;

procedure TForm1.FormMouseUp(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
  if Button = mbLeft then
    MouseRedirect(Self, MOUSEEVENTF_LEFTUP, X, Y)
  else
    MouseRedirect(Self, MOUSEEVENTF_RIGHTUP, X, Y);
end;


Set OnMouseDown and OnMouseUp for rest of control that should be transparent for mouse clicks to the same handles (TForm1.OnMouseDown, OnMouseUp).

-----
Igor
0
 
LVL 1

Author Comment

by:ghjm
ID: 6351874
Well, I understand what you're trying to do, but I haven't been able to make it work. I'm still trying, but...I sure wish a Win32 API call existed to set the _mouse_ region without also setting the _display_ region.
0
 
LVL 1

Author Comment

by:ghjm
ID: 6351890
Okay, well I have it working, sort of. The remaining problem is that whenever a click event goes through, the transparent form disappears and reappears - even though bRedraw is set to FALSE. Any suggestions how to avoid this?
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

759 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now