Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Click-through forms

Posted on 2001-08-03
4
Medium Priority
?
638 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses

609 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