Jump to content

Blaxxun

Active Members
  • Posts

    94
  • Joined

  • Last visited

About Blaxxun

  • Birthday 02/18/1975

Profile Information

  • Location
    Austria
  • WWW
    www.c3d.at
  • Interests
    AutoIt, 3D Artist Stuff, AI, Programming, Microcontrollers & ANSI-C, C# , C++, VBA, VBS, WinCC, Softimage, Redshift3D, Blender..

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

Blaxxun's Achievements

  1. @Werty Yes, you are right. I will add even more. Like: Move whole rectangle after selection and adjusting each side of the rectangle. But until now my focus was to get rid of the click-through problem. @ioa747 Thanks for pointing this out!
  2. Okay, here is the final solution. Two windows. One window to draw on. Another window to block the mouse. 100% blocking mouse interactions with any underlying window. #include <GDIPlus.au3> #include <WindowsConstants.au3> HotKeySet("{ESC}", "End") ; DPI awareness Win10 & Win11 If @OSVersion = 'WIN_10' Or @OSVersion = 'WIN_11' Then DllCall("User32.dll", "bool", "SetProcessDpiAwarenessContext", "hwnd", -2) EndIf _GDIPlus_Startup() Local $hGUI = GUICreate("", @DesktopWidth, @DesktopHeight, 0, 0, $WS_POPUP, BitOR($WS_EX_TOPMOST, $WS_EX_LAYERED)) ; Main GUI Local $hBLK = GUICreate("", @DesktopWidth, @DesktopHeight, 0, 0, $WS_POPUP, BitOR($WS_EX_TOPMOST, $WS_EX_TOOLWINDOW)) ; Mouse Block GUI WinSetTrans($hBLK, "", 1) ; 0 = clicktrough | > 0 = Non clickthrough Local $hGDC = _WinAPI_GetDC($hGUI) Local $hMDC = _WinAPI_CreateCompatibleDC($hGDC) Local $hBit = _WinAPI_CreateCompatibleBitmap($hGDC, @DesktopWidth, @DesktopHeight) Local $hOld = _WinAPI_SelectObject($hMDC, $hBit) Local $hGFX = _GDIPlus_GraphicsCreateFromHDC($hMDC) Local $hPen = _GDIPlus_PenCreate(0xFF00FF00, 2) _GDIPlus_GraphicsSetSmoothingMode($hGFX, $GDIP_SMOOTHINGMODE_HIGHQUALITY) GUISetState(@SW_SHOW, $hBLK) GUISetState(@SW_SHOW, $hGUI) ; Pre-create structs outside the function if they do not change Global $tSize = DllStructCreate("int;int") Global $tPSrc = DllStructCreate("int;int") Global $tPDst = DllStructCreate("int;int") Global $tBlnd = DllStructCreate("byte;byte;byte;byte") ; Initialize constant values in the structs DllStructSetData($tSize, 1, @DesktopWidth) DllStructSetData($tSize, 2, @DesktopHeight) DllStructSetData($tBlnd, 3, 255) ; Alpha value 0-255 DllStructSetData($tBlnd, 4, 1) ; AC_SRC_ALPHA | Has Alpha = 1 | Has No Alpha = 0 While 1 StartMouseTracking($hGUI, $hGDC, $hMDC, $hGFX, $hPen) WEnd Func StartMouseTracking($hGUI, $hGDC, $hMDC, $hGFX, $hPen) Local $topLeft[2], $bottomRight[2], $aCall Local $isDragging = False While 1 $aCall = DllCall("user32.dll", "short", "GetAsyncKeyState", "int", 0x01) If BitAND($aCall[0], 0x8000) <> 0 Then ; Left mouse button is pressed down If Not $isDragging Then $topLeft[0] = MouseGetPos(0) $topLeft[1] = MouseGetPos(1) $isDragging = True Else ; Mouse is dragging Local $currentX = MouseGetPos(0) Local $currentY = MouseGetPos(1) If $currentX <> $bottomRight[0] Or $currentY <> $bottomRight[1] Then $bottomRight[0] = $currentX $bottomRight[1] = $currentY DrawRectangle($topLeft[0], $topLeft[1], $bottomRight[0], $bottomRight[1], $hGUI, $hGDC, $hMDC, $hGFX, $hPen) EndIf EndIf ElseIf $isDragging Then ; Left mouse button is released $isDragging = False ConsoleWrite($topLeft[0] & " " & $topLeft[1] & " " & $bottomRight[0] & " " & $bottomRight[1] & @LF) ExitLoop EndIf WEnd EndFunc ;==>StartMouseTracking Func DrawRectangle(ByRef $x1, ByRef $y1, ByRef $x2, ByRef $y2, ByRef $hGUI, ByRef $hGDC, ByRef $hMDC, ByRef $hGFX, ByRef $hPen) _GDIPlus_GraphicsClear($hGFX, 0x00000000) ; Clear with transparent background _GDIPlus_GraphicsDrawRect($hGFX, $x1, $y1, $x2 - $x1, $y2 - $y1, $hPen) DllCall("user32.dll", "bool", "UpdateLayeredWindow", "hwnd", $hGUI, "handle", $hGDC, "struct*", $tPDst, "struct*", $tSize, "handle", $hMDC, "struct*", $tPSrc, "dword", 0, "struct*", $tBlnd, "dword", 0x02) ; FAST _WinAPI_UpdateLayeredWindow $ULW_ALPHA = 0x02 EndFunc ;==>DrawRectangle Func End() _GDIPlus_PenDispose($hPen) ; Cleanup pen _GDIPlus_GraphicsDispose($hGFX) ; Cleanup graphics object _WinAPI_ReleaseDC($hGUI, $hGDC) ; Release device context _WinAPI_SelectObject($hMDC, $hOld) ; Restore the old object _WinAPI_DeleteObject($hBit) ; Delete the bitmap _WinAPI_DeleteDC($hMDC) ; Delete the memory device context _GDIPlus_Shutdown() ; Shutdown GDI+ GUIDelete($hGUI) ; Delete overlay window Exit EndFunc ;==>End @ioa747 Thanks man for the inspiration!
  3. I just noticed 2 things. 1. I put the solution on my post instead of @ioa747 and i don't know how to change that. 2. The solution is not really a 100% solution because the first mouse click still strikes through although the dragging of the mouse does not. So... Im still working on it.
  4. @ioa747 Hello, thanks for the links! I experimented a bit more and found that if i use my own version of WinActivate() then the refresh is MUCH faster. DllCall("user32.dll", "int", "SetForegroundWindow", "hwnd", $hGUI) ; FAST WinActivate() Thank you!
  5. @ioa747 Man, this actually works. Although its a dirty hack, lol. Framerate drops to 1/10th, lol. BUT it works! 😅
  6. @ioa747 Hi and thanks for your reply! Before I started this thread I was also experimenting with: $hGUI = GUICreate("", 100, 100, -1, -1, $WS_POPUP, BitOR($WS_EX_TOOLWINDOW, $WS_EX_TOPMOST)) WinSetTrans($hGUI, "", 1) In "WinSetTrans()" I found that if you use 0 then it becomes click-through. But everything from 1-255 becomes non click-through. Also, I was unable to draw opaque GFX elements on that "$WS_EX_TOOLWINDOW" because they get the same transparency as the window. So when I look at the code of your "NewCapture()" function. Do you suggest that I should use 2 transparent windows? One to Draw on and one to block the mouse from the background? Thank you!
  7. Hello fellow friends, I have a working code for a simple mouse selection rectangle on a transparent window. Works fine for the first click, hold, drag, and release. A green rectangle is drawn. But at the second attempt of dragging the rectangle the GUI suddenly becomes click-through and the code/text in the underlying Skite IDE gets selected while dragging. I guess it is because something changes after the _WinAPI_UpdateLayeredWindow() command. Not sure what exactly it is... #include <Misc.au3> #include <GDIPlus.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <WinAPI.au3> ; DPI awareness Win10 & Win11 If @OSVersion = 'WIN_10' Or @OSVersion = 'WIN_11' Then DllCall("User32.dll", "bool", "SetProcessDpiAwarenessContext", "hwnd", -2) EndIf HotKeySet("{ESC}", "End") _GDIPlus_Startup() Local $hGUI = GUICreate("", @DesktopWidth, @DesktopHeight, 0, 0, $WS_POPUP, BitOR($WS_EX_TOPMOST, $WS_EX_LAYERED)) Local $hGDC = _WinAPI_GetDC($hGUI) Local $hMDC = _WinAPI_CreateCompatibleDC($hGDC) Local $hBit = _WinAPI_CreateCompatibleBitmap($hGDC, @DesktopWidth, @DesktopHeight) Local $hOld = _WinAPI_SelectObject($hMDC, $hBit) Local $hGFX = _GDIPlus_GraphicsCreateFromHDC($hMDC) Local $hPen = _GDIPlus_PenCreate(0xFF00FF00, 2) _GDIPlus_GraphicsSetSmoothingMode($hGFX, $GDIP_SMOOTHINGMODE_HIGHQUALITY) GUISetState(@SW_SHOW, $hGUI) While 1 StartMouseTracking($hGUI, $hGDC, $hMDC, $hGFX, $hPen) WEnd Func StartMouseTracking($hGUI, $hGDC, $hMDC, $hGFX, $hPen) Local $topLeft[2], $bottomRight[2] Local $isDragging = False While 1 If _IsPressed("01") Then ; Left mouse button is pressed down If Not $isDragging Then $topLeft[0] = MouseGetPos(0) $topLeft[1] = MouseGetPos(1) $isDragging = True Else ; Mouse dragging Local $currentX = MouseGetPos(0) Local $currentY = MouseGetPos(1) If $currentX <> $bottomRight[0] Or $currentY <> $bottomRight[1] Then $bottomRight[0] = $currentX $bottomRight[1] = $currentY DrawRectangle($topLeft[0], $topLeft[1], $bottomRight[0], $bottomRight[1], $hGUI, $hGDC, $hMDC, $hGFX, $hPen) EndIf EndIf ElseIf $isDragging Then ; Left mouse button is released $isDragging = False ConsoleWrite($topLeft[0] & " " & $topLeft[1] & " " & $bottomRight[0] & " " & $bottomRight[1] & @LF) ExitLoop EndIf WEnd EndFunc Func DrawRectangle($x1, $y1, $x2, $y2, $hGUI, $hGDC, $hMDC, $hGFX, $hPen) _GDIPlus_GraphicsClear($hGFX, 0x00000000) ; Clear with transparent background _GDIPlus_GraphicsDrawRect($hGFX, $x1, $y1, $x2 - $x1, $y2 - $y1, $hPen) Local $tSize = DllStructCreate("int;int") Local $tPointSource = DllStructCreate("int;int") Local $tPointDest = DllStructCreate("int;int") Local $tBlend = DllStructCreate("byte;byte;byte;byte") DllStructSetData($tSize, 1, @DesktopWidth) DllStructSetData($tSize, 2, @DesktopHeight) DllStructSetData($tBlend, 1, 0) ; AC_SRC_OVER DllStructSetData($tBlend, 2, 0) ; 0 DllStructSetData($tBlend, 3, 255) ; Alpha value 0-255 DllStructSetData($tBlend, 4, 1) ; AC_SRC_ALPHA | Has Alpha = 1 | Has No Alpha = 0 _WinAPI_UpdateLayeredWindow($hGUI, $hGDC, $tPointDest, $tSize, $hMDC, $tPointSource, 0, $tBlend, $ULW_ALPHA) EndFunc Func End() _GDIPlus_PenDispose($hPen) ; Cleanup pen _GDIPlus_GraphicsDispose($hGFX) ; Cleanup graphics object _WinAPI_ReleaseDC($hGUI, $hGDC) ; Release device context _WinAPI_SelectObject($hMDC, $hOld) ; Restore the old object _WinAPI_DeleteObject($hBit) ; Delete the bitmap _WinAPI_DeleteDC($hMDC) ; Delete the memory device context _GDIPlus_Shutdown() ; Shutdown GDI+ GUIDelete($hGUI) ; Delete overlay window Exit EndFunc Thanks!
  8. IMPORTANT: You are not allowed to sell this code or just parts of it in a commercial project @UEZ Really? Would need this in a project for my employer... WinCC 7.5 Visu. Just wanna add a backdrop shadow to the existing picture. So.. 1. Screenshot of the given zone (Done) 2. Remove the background color and make it transparent. (Done) 3. Make everything that is left black. 4. Directional blur or just Gaussian blur and offset picture afterward to sim light direction. 5. Set global transparency to 10% 6. Save to png. (Done)
  9. Yes. This is what I thought too. Screenshot just takes the pixels as they are on screen in RGB values. This is why the Alpha is calculated after the screenshot is taken. In my/this case the color white.
  10. @UEZ Hello, thanks for your help. No, I did not check if the captured image has an Alpha channel. I guess that _ScreenCapture_Capture() is not able to capture an Alpha channel. The docs don't say anything about this and I did not look into the function. But i think i know what you mean. Because it could also be RGBA or other combinations. I assumed it will only be RGB and that the Alpha is created in the next step. @paw Thank you! Yes, it also works on my end. It is also WAY faster this way instead of iterating through every single pixel... I don't know how this works yet because I have to look into _GDIPlus_ImageAttributesCreate first. Thank you! 🙂
  11. Hello ladys and gents, hello forum. How to: 1. Take a screenshot of an area/fullscreen 2. Make a color or color range transparent. 3. Save to *.png with alpha channel. Yeah... thats actually it. But im unable to figure it out for unknown reasons... lol. My NOT working code... DllCall("User32.dll", "bool", "SetProcessDPIAware") ; Get Real Screen Resolution because 4k #include <GDIPlus.au3> #include <ScreenCapture.au3> #include <WinAPI.au3> _GDIPlus_Startup() WinActivate("[CLASS:MozillaWindowClass]") ; Just Firefox with a white website Sleep(500) ; Adjust the sleep time as necessary Local $hGDIBmap = _ScreenCapture_Capture("", 0, 0, 500, 500) ; Create a GDI bitmap Local $hGDIPlusBmp = _GDIPlus_BitmapCreateFromHBITMAP($hGDIBmap) ; Convert GDI bitmap to GDI+ bitmap _WinAPI_DeleteObject($hGDIBmap) ; Release GDI bitmap resource ; Get image dimensions $iWidth = _GDIPlus_ImageGetWidth($hGDIPlusBmp) $iHeight = _GDIPlus_ImageGetHeight($hGDIPlusBmp) ; Create a new GDI+ bitmap with alpha channel support $hGDIPlusBmpNew = _GDIPlus_BitmapCreateFromScan0($iWidth, $iHeight) ; Create Graphics from the new bitmap $hGraphics = _GDIPlus_ImageGetGraphicsContext($hGDIPlusBmpNew) ; Draw the original bitmap onto the new one, so we keep the original content _GDIPlus_GraphicsDrawImageRect($hGraphics, $hGDIPlusBmp, 0, 0, $iWidth, $iHeight) ; Now, modify the new bitmap to set white pixels to transparent For $y = 0 To $iHeight - 1 For $x = 0 To $iWidth - 1 ; Get the current pixel's color from the original image $iARGB = _GDIPlus_BitmapGetPixel($hGDIPlusBmp, $x, $y) ; Check if the pixel is pure white (0xFFFFFFFF) If $iARGB = 0xFFFFFFFF Then ; Set the pixel to transparent in the new bitmap _GDIPlus_BitmapSetPixel($hGDIPlusBmpNew, $x, $y, 0x00000000) EndIf Next Next ; Save the modified image as PNG with transparency _GDIPlus_ImageSaveToFile($hGDIPlusBmpNew, @ScriptDir & "\modified_screenshot.png") ; Release resources _GDIPlus_GraphicsDispose($hGraphics) _GDIPlus_ImageDispose($hGDIPlusBmp) _GDIPlus_ImageDispose($hGDIPlusBmpNew) _GDIPlus_Shutdown() It actually works, but there is no alpha in the saved image for some reason.. Thanks!!
  12. @Nine @Andreik Thank you very much for the solution. It works fine now! Thanks! 🙂
  13. Hello Forum, I have a little Script here that generates a Directory Tree View of a given path. It works fine so far. Only thing that i cant figure out is: It prints the name of the previously selected Item and not of the current selected Item. Why is that? Thank you! #include <File.au3> #include <WindowsConstants.au3> #include <GUIConstantsEx.au3> #include <GuiTreeView.au3> Global $sPath = @DesktopDir Global $hGui = GUICreate('TreeView-Example', 400, 600) Global $iStyle = BitOR($TVS_EDITLABELS, $TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS) Global $hTreeView = _GUICtrlTreeView_Create($hGui, 10, 10, 380, 580, $iStyle, $WS_EX_CLIENTEDGE) Opt("GUIOnEventMode", 1) GUISetOnEvent($GUI_EVENT_CLOSE, "SpecialEvents") GUISetOnEvent($GUI_EVENT_MINIMIZE, "SpecialEvents") GUISetOnEvent($GUI_EVENT_RESTORE, "SpecialEvents") GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") CreateTVItems($hTreeView, 0, $sPath) GUISetState(@SW_SHOW) While 1 Sleep(10) WEnd Func CreateTVItems($hWnd, $hParent, $sPath) Local $aFolder, $aFiles, $hItem If StringRight($sPath, 1) <> '\' Then $sPath &= '\' $aFolder = _FileListToArray($sPath, '*', $FLTA_FOLDERS) If Not @error Then For $i = 1 To $aFolder[0] $hItem = _GUICtrlTreeView_AddChild($hWnd, $hParent, $aFolder[$i]) CreateTVItems($hWnd, $hItem, $sPath & $aFolder[$i]) ; Recursive call for subfolders Next EndIf $aFiles = _FileListToArray($sPath, '*', $FLTA_FILES) If @error Then Return For $i = 1 To $aFiles[0] $hItem = _GUICtrlTreeView_AddChild($hWnd, $hParent, $aFiles[$i]) Next EndFunc ;==>CreateTVItems Func SpecialEvents() Select Case @GUI_CtrlId = $GUI_EVENT_CLOSE ConsoleWrite("Window Close Pressed > ID = " & @GUI_CtrlId & " WinHandle = " & @GUI_WinHandle & @LF) GUIDelete() Exit Case @GUI_CtrlId = $GUI_EVENT_MINIMIZE ConsoleWrite("Window Minimized > ID = " & @GUI_CtrlId & " WinHandle = " & @GUI_WinHandle & @LF) Case @GUI_CtrlId = $GUI_EVENT_RESTORE ConsoleWrite("Window Restored > ID = " & @GUI_CtrlId & " WinHandle = " & @GUI_WinHandle & @LF) EndSelect EndFunc ;==>SpecialEvents Func WM_NOTIFY($hWnd, $Msg, $wParam, $lParam) $tNMHDR = DllStructCreate($tagNMHDR, $lParam) $hWndFrom = DllStructGetData($tNMHDR, "hWndFrom") $iIDFrom = DllStructGetData($tNMHDR, "IDFrom") $iCode = DllStructGetData($tNMHDR, "Code") Switch $hWndFrom Case $hTreeView Switch $iCode Case $NM_CLICK Local $hTVItemSel = _GUICtrlTreeView_GetSelection($hTreeView) Local $sText = _GUICtrlTreeView_GetText($hTreeView, $hTVItemSel) ConsoleWrite("Item: " & $hTVItemSel & " " & $sText & @LF) EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_NOTIFY
  14. OK! I have found the issue... _ClipBoard_Close() Was missing 😆 Corrected version: Func LogoToClipboard() _GDIPlus_Startup() ; Initialize Microsoft Windows GDI+ Local $hBitmapGDI = _GDIPlus_BitmapCreateFromMemory(_Base64String()) ; _Base64String Local $bPNG = _GDIPlus_StreamImage2BinaryString($hBitmapGDI) ; Binary String Local $iFormat_PNG = _ClipBoard_RegisterFormat("PNG") ; Registers a new clipboard format _ClipBoard_Open(0) ; Opens clipboard, prevent apps modifying clipboard _ClipBoard_Empty() ; Empties clipboard & frees handles to data in clipboard Local $iSize = BinaryLen($bPNG) ; Returns the number of bytes in a binary variant Local $hMemory = _MemGlobalAlloc($iSize, $GHND) ; Allocates the specified number of bytes from the heap Local $hLock = _MemGlobalLock($hMemory) ; Lock global mem obj,return ptr to 1st byte of obj memblock Local $tData = DllStructCreate("byte png[" & $iSize & "]", $hLock) ; Creates a C/C++ style structure to be used in DllCall $tData.png = Binary($bPNG) ; Returns the binary representation of an expression _MemGlobalUnlock($hMemory) ; Decrements lock count associated with memory object _ClipBoard_SetDataEx($hMemory, $iFormat_PNG) ; Place data on clipboard in specified clipboard format _ClipBoard_Close() ; <<<<<< This was missing _MemGlobalFree($hMemory) ; Free the specified global mem obj & invalidate handle _GDIPlus_ImageDispose($hBitmapGDI) ; Release an image object _GDIPlus_Shutdown() ; Clean up resources used by Microsoft Windows GDI+ EndFunc ;==>LogoToClipboard
  15. I think that the transfer is not yet finished to the clipboard but the program moves on already. If i use Sleep() then the transfer also stops. So i guess i need a way to find out if the clipboard transfer is finished before moving on.
×
×
  • Create New...