Leaderboard
Popular Content
Showing content with the highest reputation on 04/13/2022 in all areas
-
[NEW VERSION] - 13 Apr 22 Changed: If completely emptying and reloading a ListView with user colour enabled, the WM_NOTIFY handler must be unregistered before the process is started and reregistered once it is over. To this end the parameters of _GUIListViewEx_MsgRegister now take one of 3 possible values: True = Register handler False = Unregister handler Default = Do nothing This permits any of the handlers to be un/reregistered without affecting the state of the others. The most obvious use is the un/reregistering of WM_NOTIFY as described above, but other scenarios could be envisaged. New UDF in the first post. M231 point
-
Hi all. I have seen a number of requests for something like this in the Help and Support section so I thought I would post it. All the credit goes to SmOke_N - I just touched it up. This script was created when trying to get a ControlHandle that has next to no information displayed in the AutoIT Info Tool. ; =============================================================================== ;~ This script gets the control under the mouse pointer (active or inactive) ;~ The information then can be used with in conjunction with control functions. ;~ Requires AutoIt v3.3.6.0 or later to run and to view apps maximized. ;~ Big thanks to SmOke_N and Valik their help in creating it. ; =============================================================================== #include <WinAPI.au3> #include <Array.au3> #include <WindowsConstants.au3> AutoItSetOption("MustDeclareVars", 1) AutoItSetOption("MouseCoordMode", 1) AdlibRegister("_Mouse_Control_GetInfoAdlib", 10) HotKeySet("^!x", "MyExit") ; Press Ctrl+Alt+x to stop the script ;~ #AutoIt3Wrapper_run_debug_mode=Y Global $pos1 = MouseGetPos() Global $pos2 = MouseGetPos() ; must be initialized Global $appHandle = 0 While 1 Sleep(0xFFFFFFF) WEnd ; =============================================================================== ;~ Retrieves the information of a Control located under the mouse and displayes it in a tool tip next to the mouse. ;~ Function uesd ;~ _Mouse_Control_GetInfo() ;~ GetDlgCtrlID ; =============================================================================== Func _Mouse_Control_GetInfoAdlib() $pos1 = MouseGetPos() If $pos1[0] <> $pos2[0] Or $pos1[1] <> $pos2[1] Then ; has the mouse moved? Local $a_info = _Mouse_Control_GetInfo() Local $aDLL = DllCall('User32.dll', 'int', 'GetDlgCtrlID', 'hwnd', $a_info[0]) ; get the ID of the control If @error Then Return ToolTip("Handle = " & $a_info[0] & @CRLF & _ "Class = " & $a_info[1] & @CRLF & _ "ID = " & $aDLL[0] & @CRLF & _ "Mouse X Pos = " & $a_info[2] & @CRLF & _ "Mouse Y Pos = " & $a_info[3] & @CRLF & _ "ClassNN = " & $a_info[4] & @CRLF & _ ; optional "Parent Hwd = " & _WinAPI_GetAncestor($appHandle, $GA_ROOT)) $pos2 = MouseGetPos() EndIf EndFunc ;==>_Mouse_Control_GetInfoAdlib ; =============================================================================== ;~ Retrieves the information of a Control located under the mouse. ;~ Uses Windows functions WindowFromPoint and GetClassName to retrieve the information. ;~ Functions used ;~ _GetHoveredHwnd() ;~ _ControlGetClassnameNN() ;~ Returns ;~ [0] = Control Handle of the control ;~ [1] = The Class Name of the control ;~ [2] = Mouse X Pos (converted to Screen Coord) ;~ [3] = Mouse Y Pos (converted to Screen Coord) ;~ [4] = ClassNN ; =============================================================================== Func _Mouse_Control_GetInfo() Local $client_mpos = $pos1 ; gets client coords because of "MouseCoordMode" = 2 Local $a_mpos ;~ Call to removed due to offset issue $a_mpos = _ClientToScreen($appHandle, $client_mpos[0], $client_mpos[1]) ; $a_mpos now screen coords $a_mpos = $client_mpos $appHandle = GetHoveredHwnd($client_mpos[0], $client_mpos[1]) ; Uses the mouse to do the equivalent of WinGetHandle() If @error Then Return SetError(1, 0, 0) Local $a_wfp = DllCall("user32.dll", "hwnd", "WindowFromPoint", "long", $a_mpos[0], "long", $a_mpos[1]) ; gets the control handle If @error Then Return SetError(2, 0, 0) Local $t_class = DllStructCreate("char[260]") DllCall("User32.dll", "int", "GetClassName", "hwnd", $a_wfp[0], "ptr", DllStructGetPtr($t_class), "int", 260) Local $a_ret[5] = [$a_wfp[0], DllStructGetData($t_class, 1), $a_mpos[0], $a_mpos[1], "none"] Local $sClassNN = _ControlGetClassnameNN($a_ret[0]) ; optional, will run faster without it $a_ret[4] = $sClassNN Return $a_ret EndFunc ;==>_Mouse_Control_GetInfo ; =============================================================================== ; Retrieves the Handle of GUI/Application the mouse is over. ; Similar to WinGetHandle except it used the current mouse position ; Taken from http://www.autoitscript.com/forum/index.php?showtopic=444962 ; Changed to take params to allow only one set of coords to be used. ; Params ;~ $i_xpos - x position of the mouse - usually from MouseGetPos(0) ;~ $i_ypos - x position of the mouse - usually from MouseGetPos(1) ; =============================================================================== Func GetHoveredHwnd($i_xpos, $i_ypos) Local $iRet = DllCall("user32.dll", "int", "WindowFromPoint", "long", $i_xpos, "long", $i_ypos) If IsArray($iRet) Then $appHandle = $iRet[0] Return HWnd($iRet[0]) Else Return SetError(1, 0, 0) EndIf EndFunc ;==>GetHoveredHwnd ; =============================================================================== ;~ Gets the ClassNN of a control (Classname and Instance Count). This is checked with ControlGetHandle ;~ The instance is really a way to uniquely identify classes with the same name ;~ Big thanks to Valik for writing the function, taken from - http://www.autoitscript.com/forum/index.php?showtopic=97662 ;~ Param ;~ $hControl - the control handle from which you want the ClassNN ;~ Returns ;~ the ClassNN of the given control ; =============================================================================== Func _ControlGetClassnameNN($hControl) If Not IsHWnd($hControl) Then Return SetError(1, 0, "") Local Const $hParent = _WinAPI_GetAncestor($appHandle, $GA_ROOT) ; get the Window handle, this is set in GetHoveredHwnd() If Not $hParent Then Return SetError(2, 0, "") Local Const $sList = WinGetClassList($hParent) ; list of every class in the Window Local $aList = StringSplit(StringTrimRight($sList, 1), @LF, 2) _ArraySort($aList) ; improves speed Local $nInstance, $sLastClass, $sComposite For $i = 0 To UBound($aList) - 1 If $sLastClass <> $aList[$i] Then ; set up the first occurrence of a unique classname $sLastClass = $aList[$i] $nInstance = 1 EndIf $sComposite = $sLastClass & $nInstance ;build the ClassNN for testing with ControlGetHandle. ClassNN = Class & ClassCount ;if ControlGetHandle(ClassNN) matches the given control return else look at the next instance of the classname If ControlGetHandle($hParent, "", $sComposite) = $hControl Then Return $sComposite EndIf $nInstance += 1 ; count the number of times the class name appears in the list Next Return SetError(3, 0, "") EndFunc ;==>_ControlGetClassnameNN Func MyExit() ; stops the script ConsoleWrite("Script Stoppted By User" & @CR) Exit EndFunc ;==>MyExit Edit: Sept 09 Enhancement by corgano Added ControlID Added ClassNN and now requires AutoIt v3.3.0.0 or later to run Removed _WinAPI_GetParent and added global $appHandle 06 Apr 10 Removed ClientToScreenCall Made _ControlGetClassnameNN apart of the script General Updates1 point
-
You made some mistakes. Try this: #include <GDIplus.au3> #include <GUIConstantsEx.au3> #include <ButtonConstants.au3> _GDIPlus_Startup() Global $myImage = "https://www.autoitscript.com/forum/uploads/profile/photo-thumb-29844.png" Global $hBMPMem = _GDIPlus_BitmapCreateFromMemory(InetRead($myImage)) ;use GDI+ bitmap format!!! Global $hAttribute_Transparent_BMP = _GDIPlus_AttributeCreateTransparentBitmap($hBMPMem, 0.66666) Global $hGDIBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hAttribute_Transparent_BMP, 0xFFFFFFFF) Global $hGUI = GUICreate("", 300, 300, -1, -1) GUICtrlCreateTab(0,0,300,300) GUICtrlCreateTabItem("Test") Global $iPic = GUICtrlCreatePic("", 50, 50) _WinAPI_DeleteObject(GUICtrlSendMsg($iPic, 0x0172, 0, $hGDIBitmap)) ; $STM_SETIMAGE ;~ _WinAPI_DeleteObject(GUICtrlSendMsg($iPic, 0x0172, 0, $hBMPMem)) ; $STM_SETIMAGE GUICtrlCreateTabItem(""); end tabitem definition GUICtrlCreateTabItem("Test2") GUICtrlCreateTabItem(""); end tabitem definition GUISetState() Do Switch GUIGetMsg() Case $GUI_EVENT_CLOSE _GDIPlus_ImageDispose($hBMPMem) _GDIPlus_ImageDispose($hAttribute_Transparent_BMP) _WinAPI_DeleteObject($hGDIBitmap) _GDIPlus_Shutdown() GUIDelete() Exit EndSwitch Until False Func _GDIPlus_AttributeCreateTransparentBitmap($hImage, $fTransparency = 0.25) Local Const $hAttribute_Alpha = _GDIPlus_ImageAttributesCreate() ;~ $fTransparency = $fTransparency > 1 ? 1 : $fTransparency < 0 ? 0 : $fTransparency Local $tColorMatrix = _GDIPlus_ColorMatrixCreateTranslate(0, 0, 0, $fTransparency * -1) Local Const $pColorMatrix = DllStructGetPtr($tColorMatrix) _GDIPlus_ImageAttributesSetColorMatrix($hAttribute_Alpha, 0, True, $pColorMatrix) Local $aDim = _GDIPlus_ImageGetDimension($hImage) Local Const $aBitmap = _GDIPlus_BitmapCreateFromScan0($aDim[0], $aDim[1]) Local Const $hGfx = _GDIPlus_ImageGetGraphicsContext($aBitmap) _GDIPlus_GraphicsDrawImageRectRect($hGfx, $hImage, 0, 0, $aDim[0], $aDim[1], 0, 0, $aDim[0], $aDim[1], $hAttribute_Alpha) _GDIPlus_GraphicsDispose($hGfx) _GDIPlus_ImageAttributesDispose($hAttribute_Alpha) Return $aBitmap EndFunc1 point
-
I don't know whether it is possible to combine buttons with GDI+ so that the buttons are semi transparent with GDI+ elements! You can use a backround pic and draw semi transparent lines over it! #include <ButtonConstants.au3> #include <GdiPlus.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> _GDIPlus_Startup() Global $hGUI=GUICreate("Alpha test",400,400) GUISetBkColor(0) $ContextMenu=GUICtrlCreateContextMenu() $SavePicture=GUICtrlCreateMenuItem("Save picture",$ContextMenu) $button=GUICtrlCreateButton("A test button- I thought this should ""show through"" anything with less than full alpha",50,100,300,40,$BS_MULTILINE) GUICtrlSetState(-1, $GUI_DISABLE) GUISetState() $hGraphic=_GDIPlus_GraphicsCreateFromHWND($hGUI) $hBMP=_GDIPlus_BitmapCreateFromGraphics(400,400,$hGraphic) $hImage=_GDIPlus_ImageGetGraphicsContext($hBMP) For $i=1 To 15 $hPen=_GDIPlus_PenCreate(BitOR(0x80000000-((0x80000000/15)*$i),0x800000),1) _GDIPlus_GraphicsDrawLine($hImage,0,200-$i,400,200-$i,$hPen) _GDIPlus_GraphicsDrawLine($hImage,0,199+$i,400,199+$i,$hPen) _GDIPlus_PenDispose($hPen) Next For $i=1 To 15 $hPen=_GDIPlus_PenCreate(BitOR(0x80000000-((0x80000000/15)*$i),0x0000FF),1) _GDIPlus_GraphicsDrawLine($hImage,200-$i,0,200-$i,400,$hPen) _GDIPlus_GraphicsDrawLine($hImage,199+$i,0,199+$i,400,$hPen) _GDIPlus_PenDispose($hPen) Next _GDIPlus_GraphicsDispose($hImage) _GDIPlus_GraphicsDrawImageRect($hGraphic,$hBMP,0,0,400,400) Do $msg=GUIGetMsg() If $msg<0 Then ContinueLoop If $msg=$SavePicture Then $SaveFile=FileSaveDialog("Save image as...","","png image (*.png)|jpg image (*.jpg)|gif image (*.gif)",18,"Output.png") If NOT @error Then _GDIPlus_ImageSaveToFile($hBMP, $SaveFile) EndIf sleep(15) Until $msg = -3 UEZ1 point