I'm trying to simulate a lighting effect when the mouse goes over a button. I'm open to all possibilities. I've looked a lot, but I haven't found a way to do it.
The following script is a hybrid of two scripts and one feature. The main simulates a state change when passing through a control or exiting: (viewtopic.php?t=30932). The second is from "teadrinker" and is found in this post (viewtopic.php?f=76&t=69559&p=420401#p420401) and the function is to be able to add icons or images found here (viewtopic.php?t=1985)
I have separated the three controls of interest, on lines 16 to 18.
The problem is that it was started with an empty space in the gui, by the control of line 17, which is created by means of a "SendMessage," but which is nested within the behaviors of "OnThe Leave" and "The Move."
I fixed it with a "patch," adding line 18 that makes an image equal to the control of line 16 (linked with the function of displaying a .png on a button).
Code: Select all
pngFile := "AbajoDchaF.png"
BS_ICON := 0x40
BS_BITMAP := 0x80
IMAGE_BITMAP := 0
IMAGE_ICON := 1
BM_SETIMAGE := 0xF7
^F4::
Gui, OptionMenu: new
Gui, OptionMenu: -Caption +alwaysontop +ToolWindow
Gui, OptionMenu: Add, Picture, x0 y0 w600 h167, Clipboard Utility_p.png
Gui, OptionMenu: Add, Picture, x553 y0 w48 h35 gExitCopy, ArribaDcha.png
Gui, OptionMenu: Add, Text, x0 y0 w552 h35 GuiMove, `&& Drag
Gui, OptionMenu: Add, Picture, x0 y0 w552 h35, ArribaIzq.png
Gui, OptionMenu: Add, Button, x16 y36 w141 h115 hwndIcon10 gPrintPDF vPrint
Gui, OptionMenu: Add, Button, x16 y36 w141 h115 %BS_BITMAP% hwndIcon11 hwndhImageButton ; Válido
Gui, OptionMenu: Add, Picture, x16 y36 w141 h115, AbajoDcha.png
;Gui, OptionMenu: Add, Picture, x158 y36 w141 h115, AbajoDcha2.png
;Gui, OptionMenu: Add, Picture, x444 y36 w141 h115, AbajoDcha4.png
GuiButtonIcon(Icon10, "AbajoDcha.png", 1, "w213 h174")
MouseGetPos, xpos2, ypos2
VarSetCapacity(tme,16,0)
NumPut(16,tme,0), NumPut(2,tme,4), NumPut(hwnd,tme,8)
OnMessage(0x2A3,"OnMouseLeave")
OnMessage(0x200,"OnMouseMove")
Gui, OptionMenu: Show, x%xpos2% y%ypos2% W600 h167
Return
OnMouseMove( wParam, lParam, Msg,hwnd ) {
global status_Print ,tme
DllCall( "TrackMouseEvent","uint",&tme )
Status_Print:=""
if instr(a_guicontrol,"Print")
{
status_Print:=a_guicontrol
SetTimer, Printalert, -20
}
}
OnMouseLeave(){
global
status_print_old:=""
}
Printalert:
if (status_Print=status_print_old)
return
/*
if !hBitmap := LoadPicture(pngFile, "w213 h174", IMAGE_BITMAP)
MsgBox, Can't load image
if !(hBitmap)
ExitApp
*/
hBitmap := LoadPicture(pngFile, "w213 h174", IMAGE_BITMAP)
SendMessage, BM_SETIMAGE, IMAGE_BITMAP, hBitmap,, ahk_id %hImageButton%
;status_print_old:=status_print
Return
RefreshGUI:
WinSet Redraw
Gui, show
Return
ExitCopy:
Gui, OptionMenu:Hide
Return
uiMove:
PostMessage, 0xA1, 2,,, A
Return
PrintPDF:
Return
GuiButtonIcon(Handle, File, Index := 1, Options := "")
{
RegExMatch(Options, "i)w\K\d+", W), (W="") ? W := 16 :
RegExMatch(Options, "i)h\K\d+", H), (H="") ? H := 16 :
RegExMatch(Options, "i)s\K\d+", S), S ? W := H := S :
RegExMatch(Options, "i)l\K\d+", L), (L="") ? L := 0 :
RegExMatch(Options, "i)t\K\d+", T), (T="") ? T := 0 :
RegExMatch(Options, "i)r\K\d+", R), (R="") ? R := 0 :
RegExMatch(Options, "i)b\K\d+", B), (B="") ? B := 0 :
RegExMatch(Options, "i)a\K\d+", A), (A="") ? A := 4 :
Psz := A_PtrSize = "" ? 4 : A_PtrSize, DW := "UInt", Ptr := A_PtrSize = "" ? DW : "Ptr"
VarSetCapacity( button_il, 20 + Psz, 0 )
NumPut( normal_il := DllCall( "ImageList_Create", DW, W, DW, H, DW, 0x21, DW, 1, DW, 1 ), button_il, 0, Ptr ) ; Width & Height
NumPut( L, button_il, 0 + Psz, DW ) ; Left Margin
NumPut( T, button_il, 4 + Psz, DW ) ; Top Margin
NumPut( R, button_il, 8 + Psz, DW ) ; Right Margin
NumPut( B, button_il, 12 + Psz, DW ) ; Bottom Margin
NumPut( A, button_il, 16 + Psz, DW ) ; Alignment
SendMessage, BCM_SETIMAGELIST := 5634, 0, &button_il,, AHK_ID %Handle%
return IL_Add( normal_il, File, Index )
}
It also has a small failure: sometimes it does not do well the change of control or takes time to make the effect (it switches between the two controls of line 16 and 17 (control 18 only emerges at the beginning, being an image stops operating).
I would have preferred to do the same with images and not with buttons, because the button leaves a halo that shaves the interface. Is there the possibility of doing the same with images and not with buttons. If you don't. How to fix this little "Frankenstein." check if a file exists
If the position of the three controls is changed, it does not work ... crazy!
Images needed: https://mega.nz/file/xdAE3ZoC#vnwrJkXjI2CF9GUP528c7L3KzQ6HrPIBWX_w6V_P9YI
Explanatory video and how "works" and the script fails: