1

I'm trying to make a transparent screensaver in C++ and WinAPI.

It works fine so far on Windows XP, but on WES7 I have the following problem: By making my screen transparent, I can't recieve any WM_MOUSMOVE messages.

SetWindowLongPtr( hWnd,
           GWL_EXSTYLE,
           GetWindowLongPtr(hWnd, GWL_EXSTYLE) | WS_EX_LAYERED | WS_EX_TOOLWINDOW );
double TransparencyPercentage = 50.0;
double fAlpha = TransparencyPercentage * ( 255.0 /100 );
BYTE byAlpha = static_cast<BYTE>( fAlpha );
SetLayeredWindowAttributes( hWnd, 0, byAlpha, LWA_ALPHA );

I already got the information, that byAlpha has to be bigger than 0, because I won't recieve any mouse messages otherwise, but I still recieve keyboard messages, as well as mouseclicks.

Hope you can help me with this.

Robert Harvey
  • 178,213
  • 47
  • 333
  • 501
user2618639
  • 21
  • 2
  • 4
  • I scavenged a quick test just creating a layered window and looking for `WM_MOUSEMOVE` and it worked fine. Does [this code](http://pastebin.com/Gpy2K60B) work properly? – chris Aug 14 '13 at 11:26
  • actually im working on WES 7, but i guess that WES 7 is based on Windows 7 and so its basics should be just the same, shouldnt they? – user2618639 Aug 14 '13 at 11:28
  • Yes chris, your code is working – user2618639 Aug 14 '13 at 11:45
  • `WM_MOUSEMOVE` messages are only generated if the message queue is empty. If you are posting lots of messages you may never fully deplete the message queue to have a `WM_MOUSEMOVE` message generated the next time you call `GetMessage`. – IInspectable Aug 14 '13 at 12:15
  • Transparent windows are transparent to the user's eyes and to the mouse. Mouse messages go where the user thinks they'll go. You can't change that. What's different in Win7 is Aero, it does layered windows differently. – Hans Passant Aug 14 '13 at 14:11

1 Answers1

0

Since this is a screen saver, I assume you need the WM_MOUSEMOVE to know when to quit. You can use SetCapture to have all mouse input sent to your window regardless of where it actually points.

Adrian McCarthy
  • 45,555
  • 16
  • 123
  • 175