Problem when clicking on transparent control.

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

Problem when clicking on transparent control.

Post by wetware05 » 16 Aug 2022, 19:13

Hi. :wave:

I'm doing a little mini-project. It is a visual URL collector. I know there are much better browser extensions. I do it just as a challenge and to entertain myself. In addition, a personal application and on the computer itself, you create it to your liking and it is totally under your control.

My goal is to use it for when there is a situation where the browser is being saturated with tabs. I copy part of them, quickly, with this utility, and I close them from the browser.

I have encountered the problem that I have put a pseudo-button in the GUI to delete the URLs, but having the transparent property, the routine programmed in the control below (URL/Thumbnail) is switched at the same time. I've been searching and haven't found the solution. At the moment I have left the button displaced so that it is almost outside the Thumbnail. It even looks elegant and gives it a style!

(For just 219 lines of code, that's not bad.)

Code: Select all

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory
#Include Lib\ViewHtml.ahk
;#include Lib\ImagePut.ahk
#include Lib\ImagePut (for v1).ahk
Menu, Tray, Icon, Resources\1609.ico
 

if FileExist("Data\Image_1.jpg")
Loop, Data\Image_Lite_*.jpg
ImgData:= A_Index

^F3::
NotifyTrayClick_207:
Gui, DroIt: Destroy
Settimer, RetriveText, 250

Gui, DroIt: -border -caption +toolwindow +LastFound +alwaysontop
hI := DllCall( "LoadLibrary", Str,"RichEd20.dll" ), Gui1 := WinExist(),  W:=500, H:=30
RE1 := RichE( Gui1, 15, 15, 50, 50, hI )
Gui, DroIt: Add, Pic, w50 h50 gRetriveText vDroIt GuiMove, Resources\ArrowDown.png
xSp:= A_ScreenWidth-180
ySp:= A_ScreenHeight-180
Gui, DroIt: Show, x%xSp% y%ySp% ; w800 h640
Return

RetriveText:
Gui +OwnDialogs
ControlGetText, RET1,, ahk_id %RE1%
If (RET1 !="")
 {
  Settimer, RetriveText, off
  ImgData++
  URLName:= "Data\URL_" ImgData ".txt"
  FileAppend, %RET1%, %URLName%
  
  IfNotInString, RET1, youtube
   {
   browserId := WinExist("ahk_exe chrome.exe")
   WinActivate, ahk_exe chrome.exe
   Sleep, 300
   ControlGetPos, x, y, w, h, Chrome_RenderWidgetHostHWND1, ahk_id %browserId%
   WinGetPos, wx, wy, ww, wh, ahk_id %browserId%
   XPos:= wx+ww-w-11
   YPos:= wy+wh-h-11
   Ww:=w-40
   Hh:=h-40
   ImagePutFile([XPos, YPos, Ww, Hh], "Image_" ImgData ".jpg")
   }

  GetTitle:= UrlDownloadToVar2(RET1)
  Document:= ComObjCreate("HTMLfile")
  Document.Write("<meta http-equiv=""X-UA-Compatible"" content=""IE=9"">")
  Document.DesignMode := "on"
  Gettitle:= RegExReplace(gettitle, "iframe","")
  Document.Write(gettitle)
  Result:= % document.title
		
  NameData:= "Data\Name_" ImgData ".txt"
  FileAppend, %Result%, %NameData%
  ImgName:= "Image_" ImgData ".jpg"
 
  IfInString, RET1, youtube
   {
   vVideoID := SubStr(RET1, InStr(RET1, "?v=")+3, 11)
   ImgVideo:="http://img.youtube.com/vi/" vVideoID "/maxresdefault.jpg"
   UrlDownloadToFile, %ImgVideo%, %ImgName%
   }
   
  Percent:="30%"
  LiteImg:= "Image_Lite_" ImgData ".jpg"
  RunWait, %A_WorkingDir%\Addons\magick.exe -quiet %ImgName% -bordercolor "#2d2d2d" -border 10x10 -resize %Percent% %LiteImg%,,hide
  FileMove, %ImgName%, %A_WorkingDir%\Data\%ImgName%
  FileMove, %LiteImg%, %A_WorkingDir%\Data\%LiteImg%
  
  TrayTip
  SoundPlay, Resources\Clipboard_Sound.mp3
  TrayTip, Clipboard Message, %Clipboard%,, 0x1, 0x10, 0x20
  SetTimer, HideTrayTip, -1500
  Gosub, NotifyTrayClick_207
 }
Return

HideTrayTip:
TrayTip
Return

^F6::
NotifyTrayClick_201:
gui,2: Destroy
Gui, ColletorIMG: Destroy
Gui, DroIt: Destroy
if FileExist("Data\Image_1.jpg")
Loop, Data\Image_Lite_*.jpg
ImgData:= A_Index

Gui, ColletorIMG: +alwaysontop +ToolWindow ; +0x400000 +hWndhMainWnd +Owner -Caption

CSV_Load("Table.csv","data")
Loop %ImgData%
  {
  XPos:=CSV_ReadCell("data",A_index,1)
  C_XPos:= XPos
  YPos:=CSV_ReadCell("data",A_index,2)
  C_YPos:= YPos
  Gui, ColletorIMG: Add, Pic, w313 h236 x%XPos% y%YPos% gGoURL vDateURL%A_Index%, Data\Image_Lite_%A_index%.jpg
  FileText:="Data\Name_" A_Index ".txt"
  Fileread, TempText, %FileText%
  YPos:=CSV_ReadCell("data",A_index,3)
  Gui, ColletorIMG: Font, S9 Bold, Verdana
  Gui, ColletorIMG: Add, Text, w313 h20 x%XPos% y%YPos% center +BackgroundTrans, %TempText%
  XPos:= C_XPos+295 ;278
  YPos:= C_YPos-12 ;+5
  Gui, ColletorIMG: Add, Pic, w28 h28 x%XPos% y%YPos% +BackgroundTrans gDeleteImg vDeleteURL%A_Index%, Resources\Close_Red.png
  }
Gui, ColletorIMG: Show, AutoSize, URL'S Collector
Gui, ColletorIMG: Add, Pic, x0 y0 w2400 , Resources\Abstracto_azul.jpg
Return

GoURL:
Gui, ColletorIMG: Submit
StringTrimLeft, URLCopy, a_guicontrol, 7
FileURL:="Data\URL_" URLCopy ".txt"
Fileread, TempURL, %FileURL%
Run, %TempURL%
Return

DeleteImg:
Gui, ColletorIMG: Submit
StringTrimLeft, DelImg, a_guicontrol, 9
MsgBox, 0x1034,, Do you want to delete the %DelImg%st entrance of the Colletor?
IfMsgBox Yes 
	{
	Gui, 4: Destroy
	Gui, ContextClip: Destroy
	FileDelete, Data\Image_%DelImg%.jpg
	FileDelete, Data\Image_Lite_%DelImg%.jpg
	FileDelete, Data\Name_%DelImg%.txt
	FileDelete, Data\URL_%DelImg%.txt
	Loop, %ImgData%
        if !FileExist("image_Lite_" A_Index ".jpg")
	   {
	   NumberFile := A_Index
           FileSup := NumberFile+1
           Sup := "Data\Image_" Filesup ".jpg"
           NumF:= "Data\Image_" NumberFile ".jpg"
           Filemove, %Sup%, %NumF%
	   Sup := "Data\Image_Lite_" Filesup ".jpg"
           NumF:= "Data\Image_Lite_" NumberFile ".jpg"
           Filemove, %Sup%, %NumF%
	   Sup := "Data\Name_" Filesup ".txt"
	   NumF:= "Data\Name_" NumberFile ".txt"
	   Filemove, %Sup%, %NumF%
	   Sup := "Data\URL_" Filesup ".txt"
           NumF:= "Data\URL_" NumberFile ".txt"
           Filemove, %Sup%, %NumF%
           }
	Gosub, NotifyTrayClick_201
	}
Else
Gosub, NotifyTrayClick_201
Return

;---------------------------

RichE( hW, X,Y,W,H, hI ) { ; Thanks corrupt www.autohotkey.com/forum/viewtopic.php?t=19421
Return DllCall( "CreateWindowEx", UInt,0x200, Str,"RichEdit20A", Str,Null, UInt,0x50000004
                           ,Int,X, Int,Y, Int,W, Int,H, UInt,hW, UInt,0, UInt,hI, UInt,0 )
}

;-----------------------------------------

GetTitleFromUrl(url) {
	http := ComObjCreate("WinHttp.WinHttpRequest.5.1")
	http.Open("GET", "https://www.youtube.com/oembed?url=" url "&format=json", true)
	http.Send()
	http.WaitForResponse()
	
	if (RegExMatch(http.ResponseText,"\x22title\x22:\x22([^\x22]+)",title)) { ;could use a json library but this should work just as well
		return title1
	}
	return ""
}

;-----------------------------------------
UrlDownloadToVar2(URL) {
WebRequest := ComObjCreate("WinHttp.WinHttpRequest.5.1")
try	WebRequest.Open("GET", url, false)
catch	error
	return error.Message
WebRequest.Send()
Return WebRequest.ResponseText
}
;-----------------------------------------

NotifyTrayClick(P*) {              ;  v0.41 by SKAN on D39E/D39N @ tiny.cc/notifytrayclick
Static Msg, Fun:="NotifyTrayClick", NM:=OnMessage(0x404,Func(Fun),-1),  Chk,T:=-250,Clk:=1
  If ( (NM := Format(Fun . "_{:03X}", Msg := P[2])) && P.Count()<4 )
     Return ( T := Max(-5000, 0-(P[1] ? Abs(P[1]) : 250)) )
  Critical
  If ( ( Msg<0x201 || Msg>0x209 ) || ( IsFunc(NM) || Islabel(NM) )=0 )
     Return
  Chk := (Fun . "_" . (Msg<=0x203 ? "203" : Msg<=0x206 ? "206" : Msg<=0x209 ? "209" : ""))
  SetTimer, %NM%,  %  (Msg==0x203        || Msg==0x206        || Msg==0x209)
    ? (-1, Clk:=2) : ( Clk=2 ? ("Off", Clk:=1) : ( IsFunc(Chk) || IsLabel(Chk) ? T : -1) )
Return True
}
;-----------------------------------------

uiMove:
PostMessage, 0xA1, 2,,, A 
Return

/*
Miniatura de baja calidad:

http://img.youtube.com/vi/<YouTube_Video_ID_HERE>/sddefault.jpg
Miniatura de calidad media:

http://img.youtube.com/vi/<YouTube_Video_ID_HERE>/mqdefault.jpg
Miniatura de alta calidad:

http://img.youtube.com/vi/<YouTube_Video_ID_HERE>/hqdefault.jpg
Miniatura de máxima calidad:

http://img.youtube.com/vi/<YouTube_Video_ID_HERE>/maxresdefault.jpg

https://img.youtube.com/vi/GNIzN32EruU/0.jpg

desde https://stackoverflow.com/questions/2068344/how-do-i-get-a-youtube-video-thumbnail-from-the-youtube-api
*/
Limitations. At the moment it only works with Chrome. At least capture non-YouTube pages. The captures of this social network are made by downloading the main image of the video. It doesn't work for other video networks (over time), it will treat them as normal pages. The captures are done by the ImagePut.ahk function https://github.com/iseahound/ImagePut. Conversions to smaller size are done by ImageMagick's magick.exe. I use it because it adds a black frame to the image. The capture creates two sizes, for now I leave the large size to give it other uses. The gui is not resizable. I have only found one application that resizes images: Quick-Picto-Viewer-master https://github.com/marius-sucan/Quick-Picto-Viewer, with about 80 thousand lines of code. I have been looking for how images can be resized with the GUI, it does not seem an easy task, it takes a lot of knowledge and a lot of time, and I do not have it.

Thanks to @descolada for the part of the code that captures the chrome client window viewtopic.php?p=477537#p477537.

Due to my limits of knowledge, I will put several tabs; that the gui can be seen at 3, 8, or 10 columns..., lowering the size of the Thumbnail, but I can do little else. I used the CSV.ahk function https://github.com/hi5/CSV to control the position of images by reading them from a .CSV file. There is quite a lot of ingenuity in all the processes.

Demo:

(I ran out of Camtasia license.)

Download file with all necessary components: https://mega.nz/file/9FJhWDYA#OiAMNfsTdkdLa0n9-Aw7ioWKBaugS8LpuDWODwBQ2j0

Sorry to the administrators, the post has been duplicated. Sometimes I duplicate the tab to search for information and it is that action that must make things wrong. Also tiredness


[Mod edit: Fixed the code tags, which allowed most of the post that was hidden within the code box (everything after the code box) to be displayed since there was no correct closing tag. The code goes between a pair of code tags like this: [code]code goes here[/code], not inside one of the tags.
Last edited by wetware05 on 17 Aug 2022, 09:05, edited 2 times in total.

BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

Re: Problem when clicking on transparent control.

Post by BoBo » 17 Aug 2022, 00:39

Code: Select all

 Loop, Data\Image_Lite_*.jpg
:wtf: That Loop expects a number, right? Right. :thumbup: …while you expect it to loop through a folder of files.

User avatar
Xtra
Posts: 2750
Joined: 02 Oct 2015, 12:15

Re: Problem when clicking on transparent control.

Post by Xtra » 17 Aug 2022, 00:53

@BoBo

It's depreciated but still valid:
Old Syntax
Loop, FilePattern [, IncludeFolders?, Recurse?]
Deprecated: This syntax is not recommended for use in new scripts. Use the new syntax instead.
New Syntax [v1.1.21+]
Loop, Files, FilePattern , Mode

BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

Re: Problem when clicking on transparent control.

Post by BoBo » 17 Aug 2022, 02:38

@Xtra - TBH, not talking about deprecated commands gives me that cozy feeling of progression :thumbup: ... besides that "This syntax is not recommended for use in new scripts. Use the new syntax instead." :thumbup:

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

Re: Problem when clicking on transparent control.

Post by wetware05 » 17 Aug 2022, 07:46

ok, there are people on the forum who just seem to be looking for free criticism (or non-constructive criticism). Each new image that is created must be referenced with respect to the existing ones. That kind of control is necessary. A number could be generated in each session and saved in an ini file, which would be read in each session. Who hasn't found an .ini file suddenly corrupted or deleted? Or when the computer freezes it has not been generated by a program (the typical case that happened before that if the computer crashed, the browsers lost the pages they had open). Reading file numbers is the fastest and safest way, especially in utilities as simple as this one. Regarding the "mode" parameter. There won't be your directories in that folder, and besides, the weird name and extension do their job.

I am not a programmer. I will never get to the point of wanting to understand dllcalls(), because it would require knowing deeper parts of programming. I make use of the simple capabilities of AutoHotkey for automations. I have already thanked those who create functions for free. They do know programming and make it easier for people like me to be able to do more complex things, based on such functions. Again: a thousand thanks to the programmers who make functions for AutoHotkey. Likewise, a thousand thanks to those who program the application itself. As I am in favor of open source, I share the few things and utilities that I can manage to do.

Can someone explain to me why something transparent lets the mouse click through? If there was an invisible man, a bullet would not go through him. (if we get into the philosophical field, an object, such as a man, should not be go through, since every living entity was born by its ability to create a cell membrane where to differentiate what is the other, and what is Likewise, a rape of a woman is first and foremost an ontological violation. :? Computer Ontology: https://en.wikipedia.org/wiki/Ontology_(information_science)). The default value should be that it remains an object not go through. Which is given by its width and height value. The added value should be to be go through. In any case, this state switching should be simple, with a simple command, or a property of the ability to be transparent. I don't know how it is in other computer languages ​​and therefore I speak without extensive knowledge of the subject. I understand that in graphism an object is transparent and can be drawn behind it. But not in programming, where such a graph should, in some cases, act like what is a button.

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

Re: Problem when clicking on transparent control.

Post by wetware05 » 17 Aug 2022, 08:41

Okay. I have done the following experiment:

Code: Select all

XPos:=CSV_ReadCell("data",A_index,1)
  C_XPos:= XPos
  YPos:=CSV_ReadCell("data",A_index,2)
  C_YPos:= YPos
  Gui, ColletorIMG: Add, Pic, w313 h236 x%XPos% y%YPos% gGoURL vDateURL%A_Index%, Data\Image_Lite_%A_index%.jpg
  FileText:="Data\Name_" A_Index ".txt"
  Fileread, TempText, %FileText%
  YPos:=CSV_ReadCell("data",A_index,3)
  Gui, ColletorIMG: Font, S9 Bold, Verdana
  Gui, ColletorIMG: Add, Text, w313 h20 x%XPos% y%YPos% center +BackgroundTrans, %TempText%
  XPos:= C_XPos+295 ;278
  YPos:= C_YPos-12 ;+5
  Gui, ColletorIMG: Add, Button, w28 h28 x%XPos% y%YPos% ;This button, which is not transparent, stays just below the image with transparency.
  Gui, ColletorIMG: Add, Pic, w28 h28 x%XPos% y%YPos% +BackgroundTrans gDeleteImg vDeleteURL%A_Index%, Resources\Close_Red.png
I've added a button below the transparent control with a closing X, and the script still behaves the same way. Clicking on that space executes the control routine of line 5, when what would be expected is that the added button should "stop" the click down. I hope you understand what I mean, and that my idea is well translated.

Post Reply

Return to “Ask for Help (v1)”