StrokesPlus.net
Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Options
Go to last post Go to first unread
soooulp  
#1 Posted : Sunday, February 20, 2022 11:17:16 PM(UTC)
soooulp

Rank: Advanced Member

Reputation:

Groups: Moderators, Approved
Joined: 4/23/2020(UTC)
Posts: 161
China

Thanks: 46 times
Was thanked: 23 time(s) in 17 post(s)
Refer to this program See Through Windows, which uses hotkey to make the foreground Window transparency.

And it also can let the mouse "Click-Through and keep the Window on top of all other Windows", which is interesting.

Based on this post, I improve Window Transparency with the Click-Through function.

It will do the same thing as the program, but the Window is where the mouse is, also it will recover the Window and the mouse when doing the action again.

The insufficiency is that it can only set one Window transparency to 50% with the mouse Click Trough once and then recover it.

It has been rewritten by Rob in 2#

Put the first code into Global Actions-Load/Unload

Code:
if(!NativeModules.User32)
{
    var IntPtrT = host.typeOf(clr.System.IntPtr);
    var Int32T = host.typeOf(clr.System.Int32);
	
    var user32TB = sp.NativeModule().DefineType("User32", "Class,Public,SequentialLayout,Serializable");

    user32TB.DefinePInvokeMethod("GetWindowLong",
								 "user32.dll",
								 [IntPtrT,Int32T], 
								 Int32T, 
								 "PreserveSig");

    user32TB.DefinePInvokeMethod("SetWindowLong",
								 "user32.dll",
								 [IntPtrT,Int32T,Int32T], 
								 Int32T, 
								 "PreserveSig");

	user32TB.Create();
}



Action script

Code:
var WS_EX_LAYERED = 0x80000;
var WS_EX_TRANSPARENT = 0x20;
var GWL_EXSTYLE = (-20);

if(sp.GetStoredObject('WinTrans').Alpha == 128){
    var hWnds = sp.GetStoredObject('WinTrans').HWnd;
    sp.GetStoredObject('WinTrans').Alpha = 255;  //Remove transparency
    sp.GetStoredObject('WinTrans').TopMost = false;
    //Which will disable the Preview Pciture Window activate
    /*if(sp.GetStoredObject('WinTrans').ClassName != 'WindowsForms10.Window.8.app.0.13965fa_r6_ad1') {
        sp.GetStoredObject('WinTrans').Activate();
    }*/
    NativeModules.User32.SetWindowLong(hWnds ,GWL_EXSTYLE, NativeModules.User32.GetWindowLong(hWnds, GWL_EXSTYLE) & (~WS_EX_TRANSPARENT));
    sp.DeleteStoredObject('WinTrans');
} else {
    var wnd =  sp.WindowFromPoint(sp.GetCurrentMousePoint(), true);
    var hWnd = wnd.HWnd;
    wnd.Alpha = 128;  //Make 50% transparent
    wnd.TopMost = true;
    sp.StoreObject('WinTrans', wnd);
    NativeModules.User32.GetWindowLong(hWnd, GWL_EXSTYLE);
    NativeModules.User32.SetWindowLong(hWnd, GWL_EXSTYLE, WS_EX_TRANSPARENT | WS_EX_LAYERED);
}

Edited by user Sunday, March 6, 2022 7:25:47 AM(UTC)  | Reason: Not specified

Rob  
#2 Posted : Monday, February 21, 2022 6:28:03 PM(UTC)
Rob

Rank: Administration

Reputation:

Groups: Translators, Members, Administrators
Joined: 1/11/2018(UTC)
Posts: 1,349
United States
Location: Tampa, FL

Thanks: 28 times
Was thanked: 416 time(s) in 354 post(s)
Nice work!

I thought I brought in the window style flags, but I guess I didn't - I added them in 0.5.6.4.

So this would be the equivalent without the need for API imports.

Note that you don't need to add the WS_EX_LAYERED style when using the .Alpha property, since it is added when .Alpha is set from script.
Code:
if(sp.GetStoredObject('WinTrans').Alpha == 128){
    var transWnd = sp.GetStoredObject('WinTrans');
    //StrokesPlus.Console.Log(transWnd.ExtendedStyle);
    transWnd.Alpha = 255;  //Remove transparency
    transWnd.TopMost = false;

    // Can't seem to find a way to negate a flag using the 
    // ClearScript host.flags call directly, so casting the values to uint, 
    // performing bitwise operation, then casting back to enum type
    transWnd.ExtendedStyle = host.cast(WindowExStyleFlags, 
                                        host.cast(System.UInt32, 
                                                  transWnd.ExtendedStyle)
                                       & 
                                        ~host.cast(System.UInt32, 
                                                   WindowExStyleFlags.TRANSPARENT)
                                      );
    //StrokesPlus.Console.Log(transWnd.ExtendedStyle);
    sp.DeleteStoredObject('WinTrans');
} else {
    var mouseWnd = sp.WindowFromPoint(sp.GetCurrentMousePoint(), true);
    //StrokesPlus.Console.Log(mouseWnd.ExtendedStyle);
    mouseWnd.Alpha = 128;  //Make 50% transparent
    mouseWnd.TopMost = true;
    mouseWnd.ExtendedStyle = host.flags(mouseWnd.ExtendedStyle, 
                                        WindowExStyleFlags.TRANSPARENT);
    //StrokesPlus.Console.Log(mouseWnd.ExtendedStyle);
    sp.StoreObject('WinTrans', mouseWnd);
}

Edited by user Monday, February 21, 2022 6:40:02 PM(UTC)  | Reason: Not specified

thanks 1 user thanked Rob for this useful post.
soooulp on 2/21/2022(UTC)
Rob  
#3 Posted : Monday, February 21, 2022 8:48:28 PM(UTC)
Rob

Rank: Administration

Reputation:

Groups: Translators, Members, Administrators
Joined: 1/11/2018(UTC)
Posts: 1,349
United States
Location: Tampa, FL

Thanks: 28 times
Was thanked: 416 time(s) in 354 post(s)
Quote:
The insufficiency is that it can only set one Window transparency to 50% with the mouse Click Trough once and then recover it.

You could add handles to a list, then use a popup menu or input box to list them to restore to normal by selecting the window you want.
thanks 1 user thanked Rob for this useful post.
soooulp on 2/21/2022(UTC)
soooulp  
#4 Posted : Monday, February 21, 2022 9:05:53 PM(UTC)
soooulp

Rank: Advanced Member

Reputation:

Groups: Moderators, Approved
Joined: 4/23/2020(UTC)
Posts: 161
China

Thanks: 46 times
Was thanked: 23 time(s) in 17 post(s)
Aha, Never mind it.

I just think if it can get the handle of the semi-transparent Windows where the mouse is, and then can be free to use it on the sp.DisplayImage from the snip screen, but it is easy like this if without the Click-through function.

I find it is impossible after some effort, but it is useful for the preview picture which only shows a single one.

As for me, rarely use screenshots to show on the desktop, so don't need it.

Edited by user Sunday, March 6, 2022 7:30:38 AM(UTC)  | Reason: Not specified

Users browsing this topic
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.