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

Notification

Icon
Error

Options
Go to last post Go to first unread
liuxilu  
#1 Posted : Tuesday, May 5, 2020 12:10:05 AM(UTC)
liuxilu

Rank: Advanced Member

Reputation:

Groups: Moderators, Approved
Joined: 4/5/2020(UTC)
Posts: 67
China

Was thanked: 15 time(s) in 15 post(s)
Read this first. Then add this after that.
Code:
var WindowAlpha = (function(){
var RtnT = clr.System.Type.GetType("System.Boolean");

GLWA = MethodFromNativeDll("user32.dll", "GetLayeredWindowAttributes", RtnT,
    GetParmT(["System.IntPtr", "System.Int32&", "System.Byte&", "System.Int32&"]));
SLWA = MethodFromNativeDll("user32.dll", "SetLayeredWindowAttributes", RtnT,
    GetParmT(["System.IntPtr", "System.Int32", "System.Byte", "System.Int32"]));

return {Get : function GetAlpha(hwnd) {
    var a = GetParm([action.Window.HWnd, 0, host.newVar(clr.System.Byte), 0]);
    GLWA.Invoke(null, a);
    return a[2];
},
Set : function SetAlpha(hwnd, alpha) {
    return SLWA.Invoke(null, GetParm([hwnd, 0, host.newVar(clr.System.Byte, alpha), 2]));
}};
})();

Example:
Code:
// Set window to layered, or it can't be transparent.
action.Window.ExtendedStyle = clr.System.Enum.Parse(
    action.Window.ExtendedStyle.GetType(),
    action.Window.ExtendedStyle.ToString() + ', LAYERED'
)
if (WindowAlpha['Get'](action.Window.HWnd) == 128) {
    WindowAlpha['Set'](action.Window.HWnd, 255);
} else {
    WindowAlpha['Set'](action.Window.HWnd, 128);
}
thanks 1 user thanked liuxilu for this useful post.
Rob on 5/8/2020(UTC)
sunnyabcd  
#2 Posted : Tuesday, May 12, 2020 12:34:34 AM(UTC)
sunnyabcd

Rank: Member

Reputation:

Groups: Approved
Joined: 4/9/2020(UTC)
Posts: 19

Thanks: 7 times
dear liuxilu#,when loading scripts, it gives following errors:

ReferenceError: GetParmT is not defined
at LoadScripts:37:72 -> GLWA = MethodFromNativeDll("user32.dll", "GetLayeredWindowAttributes", RtnT,
at LoadScripts:50:3

liuxilu  
#3 Posted : Tuesday, May 12, 2020 6:19:26 AM(UTC)
liuxilu

Rank: Advanced Member

Reputation:

Groups: Moderators, Approved
Joined: 4/5/2020(UTC)
Posts: 67
China

Was thanked: 15 time(s) in 15 post(s)
Code:
function GetParmT (StrArr) {
    var ParmT = host.newArr(clr.System.Type, StrArr.length);
    for (var i = 0; i < StrArr.length; i++) {
        ParmT[i] = clr.System.Type.GetType(StrArr[i]);
    }
    return ParmT;
}
function GetParm (Arr) {
    var Parm = host.newArr(clr.System.Object, Arr.length);
    for (var i = 0; i < Arr.length; i++) {
        Parm[i] = Arr[i];
    }
    return Parm;
}
thanks 1 user thanked liuxilu for this useful post.
sunnyabcd on 5/13/2020(UTC)
sunnyabcd  
#4 Posted : Wednesday, May 13, 2020 7:19:37 PM(UTC)
sunnyabcd

Rank: Member

Reputation:

Groups: Approved
Joined: 4/9/2020(UTC)
Posts: 19

Thanks: 7 times
Originally Posted by: liuxilu# Go to Quoted Post
Code:
function GetParmT (StrArr) {
    var ParmT = host.newArr(clr.System.Type, StrArr.length);
    for (var i = 0; i < StrArr.length; i++) {
        ParmT[i] = clr.System.Type.GetType(StrArr[i]);
    }
    return ParmT;
}
function GetParm (Arr) {
    var Parm = host.newArr(clr.System.Object, Arr.length);
    for (var i = 0; i < Arr.length; i++) {
        Parm[i] = Arr[i];
    }
    return Parm;
}


thanks, it works well!
Rob  
#5 Posted : Thursday, May 14, 2020 8:32:09 AM(UTC)
Rob

Rank: Administration

Reputation:

Groups: Translators, Members, Administrators
Joined: 1/11/2018(UTC)
Posts: 636
United States

Thanks: 11 times
Was thanked: 143 time(s) in 125 post(s)
FYI, I've added .Alpha property to SystemWindow in 0.3.8.7, value range is 0 - 255.

Code:
//Toggles between opaque and 50% transparent
if(action.Window.Alpha == 128){
    action.Window.Alpha = 255;  //Remove transparency
} else {
    action.Window.Alpha = 128;  //Make 50% transparent
}

It checks the windows extended styles and adds layered if it's not present.
liuxilu  
#6 Posted : Thursday, May 14, 2020 10:27:10 AM(UTC)
liuxilu

Rank: Advanced Member

Reputation:

Groups: Moderators, Approved
Joined: 4/5/2020(UTC)
Posts: 67
China

Was thanked: 15 time(s) in 15 post(s)
Thank you for add this. And transparent color please by the way.
Set alpha may not be expacted to change EX_STYLE. Or you should just write a tip reminding users to check EX_STYLE before setting alpha in Script Help...?

Test for Editing.

Edited by user Friday, May 22, 2020 3:39:19 AM(UTC)  | Reason: Not specified

Rob  
#7 Posted : Thursday, May 14, 2020 10:59:21 AM(UTC)
Rob

Rank: Administration

Reputation:

Groups: Translators, Members, Administrators
Joined: 1/11/2018(UTC)
Posts: 636
United States

Thanks: 11 times
Was thanked: 143 time(s) in 125 post(s)
Quote:
Set alpha may not be expacted to change EX_STYLE


What do you mean by this?

Yeah, I was up late at night and was tired, I added ColorKey but something was off in the window styles as it led to the whole window being unclickable. I have it on my list to figure out and include that.
Rob  
#8 Posted : Thursday, May 14, 2020 12:03:31 PM(UTC)
Rob

Rank: Administration

Reputation:

Groups: Translators, Members, Administrators
Joined: 1/11/2018(UTC)
Posts: 636
United States

Thanks: 11 times
Was thanked: 143 time(s) in 125 post(s)
So it seems to depend on the application. Some apps accept the color key and behave as you'd expect (Firefox, WordPad), while others cause the window to become unclickable (Notepad, Notepad++).

I'll still add it with this disclaimer unless I figure out what the difference is and how to correct it.
Rob  
#9 Posted : Thursday, May 14, 2020 12:17:42 PM(UTC)
Rob

Rank: Administration

Reputation:

Groups: Translators, Members, Administrators
Joined: 1/11/2018(UTC)
Posts: 636
United States

Thanks: 11 times
Was thanked: 143 time(s) in 125 post(s)
Actually, that issue only seems to occur when using white as the color key.
liuxilu  
#10 Posted : Thursday, May 14, 2020 7:51:00 PM(UTC)
liuxilu

Rank: Advanced Member

Reputation:

Groups: Moderators, Approved
Joined: 4/5/2020(UTC)
Posts: 67
China

Was thanked: 15 time(s) in 15 post(s)
Originally Posted by: Rob Go to Quoted Post
It checks the windows extended styles and adds layered if it's not present.

I mean, this seems not a set alpha should do, it should just set alpha.
Rob  
#11 Posted : Thursday, May 14, 2020 9:30:46 PM(UTC)
Rob

Rank: Administration

Reputation:

Groups: Translators, Members, Administrators
Joined: 1/11/2018(UTC)
Posts: 636
United States

Thanks: 11 times
Was thanked: 143 time(s) in 125 post(s)
Which makes sense from a purist perspective, but alpha doesn't work for a non-layered window - so for the average user it seems it would simply add complexity...unless there's something I'm missing.
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.