0

I work in the automotive sector and part of the project task is to simulate a touch screen on the vehicle's Head Unit. I am displaying the simulated video output in a window on my PC's desktop.

I have created a windows form application using C# (Visual Studio 2015) that is transparent by design so it does not allow clicks through to the content beneath. The window is fixed at the size of the video output and is manually aligned so as to be on top of the the simulated video output. I can get the mouse co-ordinates and mouse button states as long as the mouse pointer is within the window. These values are written to the window's title bar and also to a small .ini file that is read by the CAN simulation which then assigns the values to the appropriate CAN signals.

This works fine on my PC at work and at home (they both have Visual Studio 2015) but copying the .exe file to other work colleagues' PCs gives different behaviour in that I can click through the window onto the desktop below and the mouse co-ordinates are not being written to the title bar or the .ini file.

I am at a loss to understand why the behaviour of the program is different between PC's that have the same version of .NET framework installed (4.61).

Can anyone offer any insights, please?

SteveOll
  • 79
  • 1
  • 4
  • The Click-Through behavious seems to be mysteriously tied to the `TranparencyKey` color. Using `Fuchsia` or just about any random other color makes all the difference.. But why it would different between machines I can't say.. – TaW Sep 09 '16 at 19:56
  • I have found that different colours work on my PC such as 'Red' 'Orange' or 'Blue' and they did not allow click through. That is the correct behaviour that I wanted. I tried 'Fuchsia' instead and it allowed click through to occur. Is there some other setting that I am missing for the Form? The problem is that why should the behaviour be different between different PC's? – SteveOll Sep 09 '16 at 20:07
  • I'm afraid it is more of a legacy bug than a feature in WinForms. I use Fuchsia for click-through and some not-named color (e.g.: Color.FromArgb(255, 147, 151, 162)) for non-click-through. – TaW Sep 09 '16 at 20:10
  • I don't understand `by design`, `TransparencyKey` allows you to click through it works like that. Why wouldn't it allow on your PC this should be the question. Shouldn't it? – Shaharyar Sep 09 '16 at 20:27
  • Do you need the entire client area of the window to be transparent? I don't know how much control you have over the native window creation, but if you can pass the [WS_EX_NOREDIRECTIONBITMAP](https://msdn.microsoft.com/en-us/library/windows/desktop/ff700543.aspx) extended window style along, you'll get exactly what you need. The window's client area receives all mouse input, but is fully transparent. No fiddling around with key colors required. – IInspectable Sep 09 '16 at 20:36
  • 1
    It is a bug in the DWM implementation (aka Aero). *Certain* transparency key values don't behave correctly and are opaque to the mouse. Like Red. This bug started to appear somewhere around Win7 SP1 or Win8, not exactly sure which version. So it in fact works like it should on your colleague's machine, probably because he has an older Windows version, what's transparent to your eye should also be transparent to the mouse. Relying on the bug is tricky of course but it is the kind of bug they can't fix anymore since it has been around too long. – Hans Passant Sep 09 '16 at 21:17

0 Answers0