?
Solved

Click-through forms

Posted on 2001-08-03
4
Medium Priority
?
636 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 300 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Suggested Courses
Course of the Month10 days, 8 hours left to enroll

764 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