How to determine which window to apply a semi-transparent effect to?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
wetware05
Posts: 750
Joined: 04 Dec 2020, 16:09

How to determine which window to apply a semi-transparent effect to?

Post by wetware05 » 18 Oct 2021, 05:06

Hi.

In the following script a menu-like window with the clipboards appears. I'd like it to be semi-transparent, but I haven't got anything. In some tests it becomes invisible (100% tranasparent), in other tests it only becomes semi-transparent when closed and remains as a watermark on the screen.
It is a menu generated through the PUM.ahk library.

Image

(In the image is the menu on the left)

Code: Select all

; https://www.autohotkey.com/board/topic/73599-ahk-l-pum-owner-drawn-object-based-popup-menu/ - capitalH
#NoEnv
;#Include  %A_ScriptDir%
#Include PUM.ahk
#Include PUM_API.ahk
#singleinstance force
SetWorkingDir %A_ScriptDir% 
CoordMode, Mouse, Screen
;MaxCount:=0

StartTicks:=A_TickCount
ClipBoardHistory:=Object()
ClipBoardEnabled=1
previousClip=%clipboard%

if FileExist("TempClip\Clip1.clip")
{
Loop, TempClip\Clip*.clip
NumberClip := A_Index
;MsgBox, %NumberClip%
Loop, %NumberClip%
{
ReadClip:= "TempClip\Clip" A_Index ".clip"
FileRead, ClipHsy, %ReadClip%
FileDelete, %ReadClip%
ClipSave(ClipBoardHistory, ClipHsy, A_Index)
}
}
; parameters of the PUM object, the manager of the menus
pumParams := { "SelMethod" : "fill"            ;item selection method, may be frame,fill
                ,"selTColor" : 0xFFFFFF        ;selection text color
                ,"selBGColor" :  0x036FC5         ;selection background color, -1 means invert current color
                ,"oninit"      : "PUM_out"      ;function which will be called when any of this events happen, se it below
                ,"onuninit"    : "PUM_out"
                ,"onselect"    : "PUM_out"
                ,"onrbutton"   : "PUM_out"
                ,"onmbutton"   : "PUM_out"
                ,"onrun"       : "PUM_out" }
                
;PUM_Menu parameters
menuParams1 := { "bgcolor" : 0xFFFFF4   ;background color of the menu R
            , "iconssize" : 0          ;size of icons in the menu
            , "tcolor" : 0x036FC5 ; text color of the menu items
	    , "hFont"  : Segoe UI 50}

;create an instance of PUM object, it is best to have only one of such in the program
pm := new PUM( pumParams )

PUM_out( msg, obj )
{
;  if ( msg = "onselect" )
;    tooltip %  obj.tooltip 
;  if ( msg = "oninit" )
;    tooltip % "menu init: " obj.handle
;  if ( msg = "onuninit" )
;    tooltip % "menu uninit: " obj.handle
;  if ( msg = "onrbutton" )
;    tooltip % "Right clicked: " obj.name
;  if ( msg = "onmbutton" )
;    tooltip % "Middle clicked: " obj.name
;  if ( msg = "onrun" )
;    tooltip % "Item runned: " obj.name
}

^!v::
;^ñ::
menu := pm.CreateMenu( menuParams1 )
index:=ClipBoardHistory.maxIndex()
if index=
	return

while Index>=ClipBoardHistory.minIndex()
{
	Description:=ClipBoardHistory[Index]["plain"]
	FullDescription:=Description
	;if(StrLen(Description)>35)
	if(StrLen(Description)>80)
	{ 
		;toCut:=StrLen(Description)-18 
		toCut:=StrLen(Description)-50
		StringMid, itemTemp1, Description, 1, 12 
		StringTrimLeft, itemTemp2, Description, %toCut% 
		Description=%itemTemp1%...%itemTemp2% 
	} 
	if index<10
	MenuString:="&" . (ClipBoardHistory.maxindex()-Index+1) . ".  " . Description
	else
	MenuString:= (ClipBoardHistory.maxindex()-Index+1) . ".  " . Description
  menu.Add( { "name" : MenuString
            , "bold" : 1
			, "index" : Index
			, "tooltip" : ClipBoardHistory[Index]["plain"]})
			
	index--
}


WinGet, ActiveWindow , ID, A
MouseGetPos, xpos2, ypos2
; item := menu.Show( A_ScreenWidth/3, A_ScreenHeight/3 ) 
item := menu.Show( xpos2, ypos2 )
WinGet, MenuClip, ID, A
;MsgBox, %MenuClip%
WinSet, Transparent, 150, ahk_Class AutohotkeyGui
WinSet, Redraw,, ahk_Class AutohotkeyGui
tooltip
WinActivate , ahk_id %ActiveWindow%
WinWaitActive, ahk_id %ActiveWindow%
hwnd := WinExist()
if item
{
ClipBoardEnabled=0
test:=item.index

tempClip:=clipboard
clipboard:=ClipBoardHistory[test]["plain"]
send, ^v
clipboard:=tempClip
ClipBoardEnabled=1
}
return

Menu.destroy()
WinSet, Transparent, 255, ahk_Class AutohotkeyGui
WinSet, Transparent, off, ahk_Class AutohotkeyGui
return

HideTrayTip:
TrayTip
Return

OnClipboardChange:
	if (ClipBoardEnabled=1) and ((A_TickCount-StartTicks)>1)
	{
	currentClip=%clipboard% 
	;currentClipAll=%clipboardall% 
	If (A_EventInfo=1) and (currentClip <> previousClip)
	{
		previousClip=%clipboard%
		;TrayTip,, %currentClip%
		;SoundPlay, Close Window.mp3
		;SetTimer, HideTrayTip, -1500
		ClipSave(ClipBoardHistory,currentclip, 5)	
	}
	}
Return

ClipSave(ClipBoardHistory,clip,maxclips=5)
{
	ClipBoardHistory.insert(Object())
	index:=ClipBoardHistory.MaxIndex()
	ClipBoardHistory[index]["plain"]:=clip
	;ClipBoardHistory[index]["All"]:=clipall
	ClipTemp:= "TempClip\Clip" index ".clip"
	If Index<=5 
		{
		FileAppend, %Clip%, %ClipTemp%
		}
	if (index>maxclips)
		{
		ClipBoardHistory.Remove(ClipBoardHistory.MinIndex())
		FileDelete, TempClip\Clip1.clip
		Loop 5
		if !FileExist("TempClip\Clip" A_Index ".clip")
			{
			NumberFile := A_Index
		        FileSup := NumberFile+1
			Sup := "TempClip\Clip" Filesup ".clip"
			NumF:= "TempClip\Clip" NumberFile ".clip"
			Filemove, %Sup%, %NumF%
			}
			FileAppend, %Clip%, TempClip\Clip5.clip
			}
}

wetware05
Posts: 750
Joined: 04 Dec 2020, 16:09

Re: How to determine which window to apply a semi-transparent effect to?

Post by wetware05 » 19 Oct 2021, 16:00

I'm going to answer myself.

The menu is pop up. This resource is controlled by the system (windows), it is always of type ahk_class #32768.

I haven't found any script that makes the menus transparent that works well. There has to be a way.

The Moo0 transparent menu utility (free: https://spa.moo0.com/) does that function, but it requires administrator privileges, maybe that's why it's so complicated to make the menus transparent. I don't know.

I want this effect:
Image

For those who know how to work with several programming languages, I found this page for transparencies in C++:https://www.codeproject.com/Articles/2080/Transparent-Menu

Someone must have created a code to make the menu transparency work with autohotkeys, but I haven't found any good or stable development.

wetware05
Posts: 750
Joined: 04 Dec 2020, 16:09

Re: How to determine which window to apply a semi-transparent effect to?

Post by wetware05 » 20 Oct 2021, 15:13

In the end the solution was very simple.

The PUP library has programmed what its menus do when it is started, when the mouse passes over it..., when it is closed. It occurred to me to put in its startup (lines 177-180) to become transparent and so it did. I've been trying to figure it out for weeks and in the end it was almost the easy way out.

Code: Select all

; https://www.autohotkey.com/board/topic/73599-ahk-l-pum-owner-drawn-object-based-popup-menu/ - capitalH
#NoEnv
;#Include  %A_ScriptDir%
#Include PUM_API.ahk
#Include PUM.ahk
#singleinstance force
DetectHiddenWindows, On
SetWorkingDir %A_ScriptDir% 
CoordMode, Mouse, Screen
;MaxCount:=0

Style := 0

;IniWrite, 20, Reg.ini, Cache Option, MaxClip
;IniRead, MaxClip, Reg.ini, Cache Option, MaxClip


StartTicks:=A_TickCount
ClipBoardHistory:=Object()
ClipBoardEnabled=1
previousClip=%clipboard%

if FileExist("TempClip\Clip1.clip")
{
Loop, TempClip\Clip*.clip
NumberClip := A_Index
;MsgBox, %NumberClip%
Loop, %NumberClip%
{
ReadClip:= "TempClip\Clip" A_Index ".clip"
FileRead, ClipHsy, %ReadClip%
FileDelete, %ReadClip%
ClipSave(ClipBoardHistory, ClipHsy, A_Index)
}
}


If Style=0
{
; parameters of the PUM object, the manager of the menus
pumParams := { "SelMethod" : "fill"            ;item selection method, may be frame,fill
                ,"selTColor" : 0xFFFFFF        ;selection text color
                ,"selBGColor" :  0x036FC5         ;selection background color, -1 means invert current color
                ,"oninit"      : "PUM_out"      ;function which will be called when any of this events happen, se it below
                ,"onuninit"    : "PUM_out"
                ,"onselect"    : "PUM_out"
                ,"onrbutton"   : "PUM_out"
                ,"onmbutton"   : "PUM_out"
                ,"onrun"       : "PUM_out" }
                
;PUM_Menu parameters
menuParams1 := { "bgcolor" : 0xFFFFF4   ;background color of the menu R
            , "iconssize" : 0          ;size of icons in the menu
            , "tcolor" : 0x064D85} ; text color of the menu items 036FC5 1A86DB 054C84 064D85 02192C 043053
}
If Style=1
{
pumParams := { "SelMethod" : "fill"            ;item selection method, may be frame,fill
                ,"selTColor" : 0x363E69        ;selection text color 0x02192C 0xFFFFFF
                ,"selBGColor" :  0xFFFFA9        ;selection background color, -1 means invert current color 0x036FC5 
                ,"oninit"      : "PUM_out"      ;function which will be called when any of this events happen, se it below
                ,"onuninit"    : "PUM_out"
                ,"onselect"    : "PUM_out"
                ,"onrbutton"   : "PUM_out"
                ,"onmbutton"   : "PUM_out"
                ,"onrun"       : "PUM_out" }

;PUM_Menu parameters
menuParams1 := { "bgcolor" : 0x363E69   ;background color of the menu R
            , "iconssize" : 32          ;size of icons in the menu
            , "tcolor" : 0xFFFF33} ; text color of the menu items 036FC5 1A86DB 054C84 064D85 02192C 043053
}

;create an instance of PUM object, it is best to have only one of such in the program
pm := new PUM( pumParams ), hwndGuiHwnd


;^!v::
;^ñ::
^Up::
^MButton::
;WinGet, ActiveWindow , ID, A
MouseGetPos, mx, my, WinUMID

menu := pm.CreateMenu( menuParams1 )
If Style=1
{
menu.Add( { "name" : "     ClipBoard Utility"
            , "bold" : 1
	    , "icon" : "Resources\Clipboard Utility.ico" } )
}
;menu := pm.CreateMenu( menuParams1 )
index:=ClipBoardHistory.maxIndex()
if index=
	return

MaxClip:=(ClipBoardHistory.maxindex())
;Loop, %MaxClip%
while Index>=ClipBoardHistory.minIndex()
{
	Description1:=ClipBoardHistory[Index]["plain"]
	Description:=ClipBoardHistory[Index]["plain"]
	FullDescription:=Description
	;if(StrLen(Description)>35)
	if(StrLen(Description)>80)
	{ 
		toCut:=StrLen(Description)-25
		;toCut:=StrLen(Description)-50
		;StringMid, itemTemp1, Description, 1, 12
		StringMid, itemTemp1, Description, 1, 50
		StringTrimLeft, itemTemp2, Description, %toCut% 
		Description=%itemTemp1%...%itemTemp2% 
	} 
	;MsgBox, %MaxClip%
	if Index<10
	{
	MenuString:="&" . (ClipBoardHistory.maxindex()-Index+1) . ".  " . Description
	}
	else
	{
	MenuString:= (ClipBoardHistory.maxindex()-Index+1) . ".  " . Description
	}
  menu.Add( { "name" : MenuString
            , "bold" : 1
			, "index" : Index
			, "tooltip" : ClipBoardHistory[Index]["plain"]})
			
	index--
}


MouseGetPos, xpos2, ypos2,winid,ctrl
xpos2 := xpos2-150
ypos2 := ypos2-50
; item := menu.Show( A_ScreenWidth/3, A_ScreenHeight/3 ) 
item := menu.Show( xpos2, ypos2 ), Prueba ;*************************************<<<<< MENU

if item
{
ClipBoardEnabled=0
test:=item.Index
clipboard:=ClipBoardHistory[test]["plain"]

WinActivate, ahk_id %WinUMID%
WinWaitActive, ahk_id %WinUMID%
send, ^v
}

Menu.destroy()
ClipBoardEnabled=1
return

HideTrayTip:
TrayTip
Return

PUM_out( msg, obj )
{
;   if ( msg = "onselect" )
;  {
;    rect := obj.GetRECT()
;    CoordMode, ToolTip, Screen
;    tooltip,% "Selected: " obj.name,% rect.right,% rect.top
;  }
;   if ( msg ~= "oninit|onuninit|onshow|onclose" )
;    tooltip % "menu " msg ": " obj.handle
;  if ( msg = "onrbutton" )
;    tooltip % "Right clicked: " obj.name
;  if ( msg = "onmbutton" )
;    {
;    ;MsgBox, HOLA
;    ;test:=item.index
;    clipboard:=obj.name
;    ;clipboard:=ClipBoardHistory[test]["plain"]
;    ;tooltip % "Middle clicked: " obj.name
;    }
  if ( msg ~= "oninit" )
      {
      WinSet, Transparent, 200, ahk_class #32768
      }
;  if ( msg = "onrun" )
;     {
;     test:=item.index
;     clipboard:=ClipBoardHistory[test]["plain"]
;     clipboard:=obj.name
;     clipboard:=ClipBoardHistory[A_Index]["plain"]
;     clipboard:=obj.ID
;     MsgBox, 1. %Index% 2. %A_Index% 3. %clipboard% 4. %WinUMID%
;     WinActivate, ahk_id %WinUMID%
;     WinWaitActive, ahk_id %ActiveWindow%
;     clipboard:=obj.name
;     Sleep 300
;     Send, ^v
;     Gosub, PasteClip
;     }
;    tooltip % "Item runned: " obj.name
}

PasteClip:
WinActivate, ahk_id %WinUMID%
WinWaitActive, ahk_id %WinUMID%
;clipboard:=obj.name
Send, ^v
Sleep 300
ClipBoardEnabled=1
Return

OnClipboardChange:
	if (ClipBoardEnabled=1) and ((A_TickCount-StartTicks)>1)
	{
	currentClip=%clipboard% 
	;currentClipAll=%clipboardall% 
	If (A_EventInfo=1) and (currentClip <> previousClip)
	{
		previousClip=%clipboard%
		;TrayTip,, %currentClip%
		;SoundPlay, Close Window.mp3
		;SetTimer, HideTrayTip, -1500
		ClipSave(ClipBoardHistory,currentclip, 15)	
	}
	}
Return

ClipSave(ClipBoardHistory,clip,maxclips=15)
{
	ClipBoardHistory.insert(Object())
	index:=ClipBoardHistory.MaxIndex()
	ClipBoardHistory[index]["plain"]:=clip
	;ClipBoardHistory[index]["All"]:=clipall
	ClipTemp:= "TempClip\Clip" index ".clip"
	If Index<=15 
		{
		FileAppend, %Clip%, %ClipTemp%
		}
	if (index>maxclips)
		{
		ClipBoardHistory.Remove(ClipBoardHistory.MinIndex())
		FileDelete, TempClip\Clip1.clip
		Loop 15
		if !FileExist("TempClip\Clip" A_Index ".clip")
			{
			NumberFile := A_Index
		        FileSup := NumberFile+1
			Sup := "TempClip\Clip" Filesup ".clip"
			NumF:= "TempClip\Clip" NumberFile ".clip"
			Filemove, %Sup%, %NumF%
			}
			FileAppend, %Clip%, TempClip\Clip15.clip
			}
}

^F3::
Reload
Return

wetware05
Posts: 750
Joined: 04 Dec 2020, 16:09

Re: How to determine which window to apply a semi-transparent effect to?

Post by wetware05 » 21 Oct 2021, 13:56

Horror!!! :o

I made the program "Moo0 Transparent Menu Utility" was not resident and again the transparency in the script became erratic. That is, that only remain stable if Moo0 Transparent is resident (even if it is deactivated). There have to be some solution to this!

At the moment it is not good to incorporate it into a script (or only for own use and making Moo0 Transparent start with the system).

wetware05
Posts: 750
Joined: 04 Dec 2020, 16:09

Re: How to determine which window to apply a semi-transparent effect to?

Post by wetware05 » 21 Oct 2021, 18:20

I've found out that if you make a quick press -of the assigned keyboard shortcut- it gives errors (the transparencies -upper left- and the menu square appear uncoupled), but if you hold it for a few tenths of a second it works fine.

I have this script to simulate holding down the keys, for those who are interested and want to try it.

Code: Select all

+v::
Send {Shift down}
Send {V Down}
Sleep 300
Send {Shift Up}
Send {V Up}

wetware05
Posts: 750
Joined: 04 Dec 2020, 16:09

Re: How to determine which window to apply a semi-transparent effect to?

Post by wetware05 » 21 Oct 2021, 19:21

what nonsense, it's not even to keep it pressed for a while, but to delay a little its appearance with a sleep, 300, after the keyboard shortcut.

Code: Select all

^Up::

^MButton::
sleep, 300
MouseGetPos,,, WinUMID

menu := pm.CreateMenu( menuParams1 )
If Style=1
....
....
....

Post Reply

Return to “Ask for Help (v1)”