Resolved Click through

Gloops

Well-known member
Joined
Jun 30, 2022
Messages
137
Programming Experience
10+
Hello everybody,

I intend to provide a (new version of a) form to show the state of the keyboard, when the Windows taskbar is not visible : caps lock, num lock, ins, scroll lock.

It will have an opacity adjustable with a slider.

When the user clicks on it, I should like the click to be transmitted to the element that is visible through the form (except, for instance, if the shift key is down). It can be either a web site or a document in a text editor. Perhaps the slider could be accessible to the click, and thus be an exception to the "click through" rule.

I saw some years ago that this exists, but I do not have a too precise idea of how to implement that.
 
Solution
Anyway, here's a quick simple way for you to play with the TransparencyKey, and see how it acts with a button on the form:
C#:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using System.Drawing;

namespace WinForms
{
    class MainForm : Form
    {
        MainForm()
        {
            Text = "Main";
            Size = new Size(800, 600);
            BackColor = Color.Green;
            TransparencyKey = Color.Green;

            var button = new Button() { Text = "Press me!", Dock = DockStyle.Left, BackColor = Color.Red };
            button.Click += (o, e) => MessageBox.Show("Got it.");
            Controls.Add(button);

            CenterToScreen();
        }

        [STAThread]...
Full screen means also covering the taskbar. Maximized means using up all off the working area. Set the window state to maximized if you want to not encroach on the taskbar area.
 
How is the best way to get the background color at a certain point?
Call the APIs?
Otherwise if I ask the form backcolor I do not really get it, as it is a transparency key.
Best way is to use P/Invoke and call GetPixel()
because you will only need to eventually move just a single DWORD value from unmanaged code space to managed code space.

The most common answers you'll find on the Internet involve taking a screen shot (either a full screen shot, or a 1x1 pixel screen shot), and then checking the pixel color from that screen shot. It's not very efficient due to the number of intermediate GDI objects that need to be created, the the corresponding managed wrappers around those GDI objects, as well as moving the bytes of data from unmanaged code space into managed code space.
 
OK. And as I understand, you first have to call EnumDisplayDevices and GetDisplayMonitorInfo, in order to get the HDC.
 
Full screen means also covering the taskbar. Maximized means using up all off the working area. Set the window state to maximized if you want to not encroach on the taskbar area.
OK, but the topic is not to avoid to cover the taskbar, but to know when it is done.
So I picked up a point down the screen, and I go on getting its module name. I presume if it is the taskbar it should be explorer. Of course I shall have to distinguish the case I have an explorer window displayed full screen.
The problem I have at the moment is that GetProcessIdOfThread(hwnd) returns 0, so it is difficult to find a module name with that.
 
And ... rereading the name of the function, I realize it waits for a handle to a thread, and I send it a handle to a window, so it is not extraordinary that it is not happy with that.
 
Just a reminder to start new threads for new topics. This topic on how to do a "click through form" seems resolved?
 
That is right. I was following ... the thread of the application😁
Just remarking that for what I was speaking about I forgot to try GetModuleFileName, and I am going to look where I should have clicked ...
 
Back
Top Bottom