Jump to content

Blaxxun

Active Members
  • Posts

    94
  • Joined

  • Last visited

Everything posted by Blaxxun

  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.
  16. Hello Forum, Since my next problem seems to be related to the previous PNG Clipboard Problem i will continue here. Everything works nice so far. The PNG is created from the Base64String and placed properly into the clipboard thanks to @UEZ But for some unknown reason the pasting into word gives me a crash here: $oWord.Selection.PasteSpecial(Default, False, Default, False, $iDataType, Default, Default) ; <<<<< $oWord.Selection^ ERROR When i comment out the Clipboard PNG Logo generation herem then it does not throw an error and the image gets pasted correctly into word: LogoToClipboard() ; <<<<<<<< When PNG ALREADY in Clipboard COMMENT OUT and Run again = No error and Image gets pasted as expected... Here is the minimalized code of the whole script: #include <Word.au3> #include "WordConstants.au3" #include <GDIPlus.au3> #include <Clipboard.au3> Global $oWord = _Word_Create() ; Start Word > Word.Application object Global $oDoc = _Word_DocAdd($oWord) ; Create Document > document object Global $oSel, $oRange, $oShape, $oInlineShape Global $iDataType = 15 ; PNG Global Const $wdAlignParagraphCenter = 1 ; Align Center LogoToClipboard() ; <<<<<<<< When PNG ALREADY in Clipboard COMMENT OUT and Run again = No error and Image gets pasted as expected... $oWord.ActiveDocument.Range.Select $oWord.Selection.Collapse($wdCollapseStart) $oWord.Selection.PasteSpecial(Default, False, Default, False, $iDataType, Default, Default) ; <<<<< $oWord.Selection^ ERROR $oWord.Selection.ParagraphFormat.Alignment = $wdAlignParagraphCenter 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 the clipboard and prevents other applications from modifying the clipboard (0 = current task) _ClipBoard_Empty() ; Empties the clipboard and frees handles to data in the 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) ; Locks a global memory object and returns a pointer to the first byte of the object's memory block 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 the lock count associated with a memory object that was allocated with GMEM_MOVEABLE _ClipBoard_SetDataEx($hMemory, $iFormat_PNG) ; Places data on the clipboard in a specified clipboard format _MemGlobalFree($hMemory) ; Frees the specified global memory object and invalidates its handle _GDIPlus_ImageDispose($hBitmapGDI) ; Release an image object _GDIPlus_Shutdown() ; Clean up resources used by Microsoft Windows GDI+ EndFunc ;==>LogoToClipboard Func _GDIPlus_StreamImage2BinaryString($hBitmap, $sFormat = "PNG", $iQuality = 80) ; Coded by UEZ 2013 build 2014-01-25 Local $sImgCLSID, $tGUID, $tParams Switch $sFormat Case "JPG" $sImgCLSID = _GDIPlus_EncodersGetCLSID($sFormat) $tGUID = _WinAPI_GUIDFromString($sImgCLSID) Local $tData = DllStructCreate("int Quality") DllStructSetData($tData, "Quality", $iQuality) ;quality 0-100 Local $pData = DllStructGetPtr($tData) $tParams = _GDIPlus_ParamInit(1) _GDIPlus_ParamAdd($tParams, $GDIP_EPGQUALITY, 1, $GDIP_EPTLONG, $pData) Case "PNG", "BMP", "GIF", "TIF" $sImgCLSID = _GDIPlus_EncodersGetCLSID($sFormat) $tGUID = _WinAPI_GUIDFromString($sImgCLSID) Case Else Return SetError(1, 0, 0) EndSwitch Local $hStream = _WinAPI_CreateStreamOnHGlobal() ;http://msdn.microsoft.com/en-us/library/ms864401.aspx If @error Then Return SetError(2, 0, 0) _GDIPlus_ImageSaveToStream($hBitmap, $hStream, DllStructGetPtr($tGUID), DllStructGetPtr($tParams)) If @error Then Return SetError(3, 0, 0) Local $hMemory = _WinAPI_GetHGlobalFromStream($hStream) ;http://msdn.microsoft.com/en-us/library/aa911736.aspx If @error Then Return SetError(4, 0, 0) Local $iMemSize = _MemGlobalSize($hMemory) If Not $iMemSize Then Return SetError(5, 0, 0) Local $pMem = _MemGlobalLock($hMemory) $tData = DllStructCreate("byte[" & $iMemSize & "]", $pMem) Local $bData = DllStructGetData($tData, 1) _WinAPI_ReleaseStream($hStream) ;http://msdn.microsoft.com/en-us/library/windows/desktop/ms221473(v=vs.85).aspx _MemGlobalFree($hMemory) Return $bData EndFunc ;==>_GDIPlus_StreamImage2BinaryString Func _Base64String($bSaveBinary = False, $sSavePath = @ScriptDir) Local $Base64String $Base64String &= 'm7MAiVBORw0KGgoAAAAADUlIRFIlAHBkARgIBgAocOIElVQAGAlwSFlzEAAACxIBDAHS3QB+/AAAA3RJRABBVHgB7ZsxbwDTUBSFDWKq1ACVSmwMwNof0ACNhQXGDsxIlQC6UcHGPwC1WwAlpM79AbCwsADxA7oCAxsSWQCROnM+iFOSWgCJRJN3bsq50gBVHDt59/g79gDzs/PSdYkQCAKBQgJ1JnCjvPgAvcMhidta+UAAeUe5Of7AT70Afld+Vp6N13UA3duDyeI6LKwAiyEbgvlU+UQA+VDJ+3lxro0AH5XvlKdK3g8ARzHD/IYMnwEAPbzbWnip3FcALjKh/87sK2YAHCtfK0ezG6sAnUE3Lwmss+IAuaR8U75Q/qsAGewN36UN2qIAzdJR0RDOCroAGi4eVzFiFjwAbdEmbVOjZFQAM4SL9Sfl4xUA0qJtalCrXFQAMgRAH5T3GlAAoga1yplS5aIAThfCUdvCDJUAmcRXLe0oR5MANf2CafRV5QwAORGH1maAnpoA1C4TFQxh5LMAymvGItjULjMA+mrfZU3fd9AAVTEcXeZoapEAAUPbz7XyrvIAouv6T7ssbvoA3GZgEBrQYg8AZ5cFhH07gQsAAWhBkzWchvBAbMoO4C/6BAagALBa2DU5DeGpAG21sGtyGcIdAHKl7qo/MNBkAL17dxnCj0tVAOO+U5jLEH7pAKsaVm0uQzarCLohXQECCvvhlQDmMoQJCVXDqgDNZQizQ6qGVQCbyxCm6lSNLwBOYS5DzrTTPABhrRZoQpstXACGsMPMm6oWdgBNTkOY/VEt7ACanIbMn1HY3gAquis0WcNpCAAAjq17P10cLQBosobTEHac6QCddghjDWixxwCt5gqmf6sedQB7h6+kgRmFzgBAw8gpoK/tPgBD0HGkfN8LMgC8UhsNJaKCIQCAeKZk0lrroAAmtctE+y5reADX6S52lUzv3AAa/sjS1/5QiwC7+jtCia6q3wC7' $Base64String &= 'KmcIerhDfgCkbHGmUINa1gC7ctW/FJUMQQAcgHaUq7ym0AA2NcqZIU1dNQBD0EQXwuyPAwDlMofEtEWbtABdqpuSnklUNACkF8fIh+mdbwCUVzGG79IGbQCVGU1Jy2C0nwDbOyhjzso/cwCBN/QJJrFxdABf6z99VhllzQBx5PcmjvKTcQCyYlt5Lf8WzSDOJUIgBLkA/AQAfgGdGnQnr6IELMkA5QBJRU5EAK5CYII=' $Base64String = _WinAPI_Base64Decode($Base64String) If @error Then Return SetError(1, 0, 0) Local $tSource = DllStructCreate('byte[' & BinaryLen($Base64String) & ']') DllStructSetData($tSource, 1, $Base64String) Local $tDecompress _WinAPI_LZNTDecompress($tSource, $tDecompress, 962) If @error Then Return SetError(3, 0, 0) $tSource = 0 Local Const $bString = Binary(DllStructGetData($tDecompress, 1)) If $bSaveBinary Then Local Const $hFile = FileOpen($sSavePath & "\Test.png", 18) If @error Then Return SetError(2, 0, $bString) FileWrite($hFile, $bString) FileClose($hFile) EndIf Return $bString EndFunc ;==>_Base64String Func _WinAPI_Base64Decode($sB64String) Local $aCrypt = DllCall("Crypt32.dll", "bool", "CryptStringToBinaryA", "str", $sB64String, "dword", 0, "dword", 1, "ptr", 0, "dword*", 0, "ptr", 0, "ptr", 0) If @error Or Not $aCrypt[0] Then Return SetError(1, 0, "") Local $bBuffer = DllStructCreate("byte[" & $aCrypt[5] & "]") $aCrypt = DllCall("Crypt32.dll", "bool", "CryptStringToBinaryA", "str", $sB64String, "dword", 0, "dword", 1, "struct*", $bBuffer, "dword*", $aCrypt[5], "ptr", 0, "ptr", 0) If @error Or Not $aCrypt[0] Then Return SetError(2, 0, "") Return DllStructGetData($bBuffer, 1) EndFunc ;==>_WinAPI_Base64Decode Func _WinAPI_LZNTDecompress(ByRef $tInput, ByRef $tOutput, $iBufferSize) $tOutput = DllStructCreate("byte[" & $iBufferSize & "]") If @error Then Return SetError(1, 0, 0) Local $aRet = DllCall("ntdll.dll", "uint", "RtlDecompressBuffer", "ushort", 0x0002, "struct*", $tOutput, "ulong", $iBufferSize, "struct*", $tInput, "ulong", DllStructGetSize($tInput), "ulong*", 0) If @error Then Return SetError(2, 0, 0) If $aRet[0] Then Return SetError(3, $aRet[0], 0) Return $aRet[6] EndFunc ;==>_WinAPI_LZNTDecompress The .PasteSpecial command works. But not directly after the Clipboard is generated. I also added a Sleep(5000) already because i thought it was a timing problem. Still Error...
  17. @UEZ Okay, WoW! This does work now! But i did not expect that it is this complicated / complex. Thank you very much! I could not have done this alone. 😳 I was testing yesterday and i used a little program called "freeclipviewer". I was not aware of how much stuff is created in the clipboard when you do a simple image copy. Word for example creates a whole list of image formats in the clipboard. And the application you paste it into, selects the best format to paste from this list.
  18. Hello Forum, I have a PNG with Alpha channel and i converted it into an Base64 string. Goal is to have a Logo for a Word document but not a File.png on HDD. When i paste the image from the clipboard (manually for now) then the Alpha channel is black and not transparent. How can i achieve a transparent background? I tested in MS Paint, Krita and Word. All black background. Thanks! The code: #include <Word.au3> #include "WordConstants.au3" #include <GDIPlus.au3> #include <Clipboard.au3> _GDIPlus_Startup() Global $hBitmapGDI = _GDIPlus_BitmapCreateFromMemory(_Base64String(), True) ; False = bitmap(GDI+), True = hbitmap(GDI) will be created ;Global $hBitmapInfo = _GDIPlus_BitmapCreateDIBFromBitmap($hBitmapGDI) Global $hClipboard_Bitmap = _WinAPI_CopyImage($hBitmapGDI, 0, 0, 0, $LR_DEFAULTCOLOR) _ClipBoard_Open(0) _ClipBoard_Empty() ; Must empty or previous image stays _ClipBoard_SetDataEx($hClipboard_Bitmap, $CF_BITMAP) _ClipBoard_Close() _WinAPI_DeleteObject($hBitmapGDI) _WinAPI_DeleteObject($hClipboard_Bitmap) _GDIPlus_Shutdown() Exit The image: Func _Base64String($bSaveBinary = False, $sSavePath = @ScriptDir) Local $Base64String $Base64String &= 'm7MAiVBORw0KGgoAAAAADUlIRFIlAHBkARgIBgAocOIElVQAGAlwSFlzEAAACxIBDAHS3QB+/AAAA3RJRABBVHgB7ZsxbwDTUBSFDWKq1ACVSmwMwNof0ACNhQXGDsxIlQC6UcHGPwC1WwAlpM79AbCwsADxA7oCAxsSWQCROnM+iFOSWgCJRJN3bsq50gBVHDt59/g79gDzs/PSdYkQCAKBQgJ1JnCjvPgAvcMhidta+UAAeUe5Of7AT70Afld+Vp6N13UA3duDyeI6LKwAiyEbgvlU+UQA+VDJ+3lxro0AH5XvlKdK3g8ARzHD/IYMnwEAPbzbWnip3FcALjKh/87sK2YAHCtfK0ezG6sAnUE3Lwmss+IAuaR8U75Q/qsAGewN36UN2qIAzdJR0RDOCroAGi4eVzFiFjwAbdEmbVOjZFQAM4SL9Sfl4xUA0qJtalCrXFQAMgRAH5T3GlAAoga1yplS5aIAThfCUdvCDJUAmcRXLe0oR5MANf2CafRV5QwAORGH1maAnpoA1C4TFQxh5LMAymvGItjULjMA+mrfZU3fd9AAVTEcXeZoapEAAUPbz7XyrvIAouv6T7ssbvoA3GZgEBrQYg8AZ5cFhH07gQsAAWhBkzWchvBAbMoO4C/6BAagALBa2DU5DeGpAG21sGtyGcIdAHKl7qo/MNBkAL17dxnCj0tVAOO+U5jLEH7pAKsaVm0uQzarCLohXQECCvvhlQDmMoQJCVXDqgDNZQizQ6qGVQCbyxCm6lSNLwBOYS5DzrTTPABhrRZoQpstXACGsMPMm6oWdgBNTkOY/VEt7ACanIbMn1HY3gAquis0WcNpCAAAjq17P10cLQBosobTEHac6QCddghjDWixxwCt5gqmf6sedQB7h6+kgRmFzgBAw8gpoK/tPgBD0HGkfN8LMgC8UhsNJaKCIQCAeKZk0lrroAAmtctE+y5reADX6S52lUzv3AAa/sjS1/5QiwC7+jtCia6q3wC7' $Base64String &= 'KmcIerhDfgCkbHGmUINa1gC7ctW/FJUMQQAcgHaUq7ym0AA2NcqZIU1dNQBD0EQXwuyPAwDlMofEtEWbtABdqpuSnklUNACkF8fIh+mdbwCUVzGG79IGbQCVGU1Jy2C0nwDbOyhjzso/cwCBN/QJJrFxdABf6z99VhllzQBx5PcmjvKTcQCyYlt5Lf8WzSDOJUIgBLkA/AQAfgGdGnQnr6IELMkA5QBJRU5EAK5CYII=' $Base64String = _WinAPI_Base64Decode($Base64String) If @error Then Return SetError(1, 0, 0) Local $tSource = DllStructCreate('byte[' & BinaryLen($Base64String) & ']') DllStructSetData($tSource, 1, $Base64String) Local $tDecompress _WinAPI_LZNTDecompress($tSource, $tDecompress, 962) If @error Then Return SetError(3, 0, 0) $tSource = 0 Local Const $bString = Binary(DllStructGetData($tDecompress, 1)) If $bSaveBinary Then Local Const $hFile = FileOpen($sSavePath & "\Test.png", 18) If @error Then Return SetError(2, 0, $bString) FileWrite($hFile, $bString) FileClose($hFile) EndIf Return $bString EndFunc ;==>_Base64String Func _WinAPI_Base64Decode($sB64String) Local $aCrypt = DllCall("Crypt32.dll", "bool", "CryptStringToBinaryA", "str", $sB64String, "dword", 0, "dword", 1, "ptr", 0, "dword*", 0, "ptr", 0, "ptr", 0) If @error Or Not $aCrypt[0] Then Return SetError(1, 0, "") Local $bBuffer = DllStructCreate("byte[" & $aCrypt[5] & "]") $aCrypt = DllCall("Crypt32.dll", "bool", "CryptStringToBinaryA", "str", $sB64String, "dword", 0, "dword", 1, "struct*", $bBuffer, "dword*", $aCrypt[5], "ptr", 0, "ptr", 0) If @error Or Not $aCrypt[0] Then Return SetError(2, 0, "") Return DllStructGetData($bBuffer, 1) EndFunc ;==>_WinAPI_Base64Decode Func _WinAPI_LZNTDecompress(ByRef $tInput, ByRef $tOutput, $iBufferSize) $tOutput = DllStructCreate("byte[" & $iBufferSize & "]") If @error Then Return SetError(1, 0, 0) Local $aRet = DllCall("ntdll.dll", "uint", "RtlDecompressBuffer", "ushort", 0x0002, "struct*", $tOutput, "ulong", $iBufferSize, "struct*", $tInput, "ulong", DllStructGetSize($tInput), "ulong*", 0) If @error Then Return SetError(2, 0, 0) If $aRet[0] Then Return SetError(3, $aRet[0], 0) Return $aRet[6] EndFunc ;==>_WinAPI_LZNTDecompress
  19. Okay, looks like i was able to solve it myself 😆 #include <Word.au3> #include "WordConstants.au3" Global Const $wdAlignParagraphCenter = 1 ; Align Center Global Const $wdAlignParagraphLeft = 0 ; Align Left Global Const $wdWrapMergeFront = 4 ; In front of Text Global Const $wdMove = 0 ; Move to Global $sPic = @ScriptDir & "\Logo.png" Global $oWord = _Word_Create() ; Start Word Global $oDoc = _Word_DocAdd($oWord) ; Create Document Global $oRange Global $oSel = $oWord.Selection Global $oInlineShape = $oDoc.InlineShapes.AddPicture($sPic, False, True) $oInlineShape.LockAspectRatio = True $oInlineShape.width = CentimetersToPoints(9.58) $oSel.ParagraphFormat.Alignment = $wdAlignParagraphCenter ; Align Center Global $oShape = $oInlineShape.ConvertToShape ; Convert InlineShape to Shape $oShape.WrapFormat.Type = $wdWrapMergeFront ; Set wrapping type to "Top and Bottom" $oSel.ParagraphFormat.Alignment = $wdAlignParagraphLeft ; Align Left $oSel.ParagraphFormat.SpaceAfter = 10 $oSel.EndKey($wdLine, $wdMove) $oSel.TypeParagraph .Selection.EndKey was not working because i used it wrong. $oWord.Selection.EndKey($wdLine,$wdMove) is correct.
  20. Hello Forum! I have a Word VBA Macro that inserts an image. I rebuilt the same behavior in AutoIt. Everything works the same except of one tiny difference. In VBA the image does NOT move down when i manually press <ENTER> after the Macro was running. In Autoit the image DOES move down when i press <ENTER> after the Script was running. Adding the image is just the beginning of the script. More Text will be added after. When i press <END> and then <ENTER> the behavior is the same again as in VBA. I tryd already several things but i do not want to hack in a Send("{END}") VBA: ' LOGO ---------------------------------------------------------------------------------------------------------------------- Dim Img As String Dim inlineShape As inlineShape Dim shape As shape Img = "C:\Logo.png" Set inlineShape = Selection.InlineShapes.AddPicture(FileName:=Img, LinkToFile:=False, SaveWithDocument:=True) inlineShape.LockAspectRatio = msoTrue inlineShape.width = CentimetersToPoints(9.58) Selection.ParagraphFormat.Alignment = wdAlignParagraphCenter Set shape = inlineShape.ConvertToShape shape.WrapFormat.Type = wdWrapMergeFront ' Set wrapping type to "Top and Bottom" < This is not wrong! ' Texts ------------------------------------------------------------------------------------------------------------------------ Selection.ParagraphFormat.Alignment = wdAlignParagraphLeft Selection.ParagraphFormat.SpaceAfter = 10 'Selection.TypeParagraph AutoIt: #include <Word.au3> #include "WordConstants.au3" Global $oRange Global Const $wdAlignParagraphCenter = 1 ; Align Center Global Const $wdAlignParagraphLeft = 0 ; Align Left Global Const $wdWrapMergeFront = 4 ; In front of Text Global $Bild = @ScriptDir & "\Logo.png" Global $oWordApp = _Word_Create(); Start Word Global $oDoc = _Word_DocAdd($oWordApp); Create Document Global $oInlineShape = $oDoc.InlineShapes.AddPicture($Bild, False, True) $oInlineShape.LockAspectRatio = True $oInlineShape.width = CentimetersToPoints(9.58) $oRange = $oInlineShape.Range $oRange.ParagraphFormat.Alignment = $wdAlignParagraphCenter ; Center Global $oShape = $oInlineShape.ConvertToShape ; Convert InlineShape to Shape $oShape.WrapFormat.Type = $wdWrapMergeFront ; Set wrapping type to "Top and Bottom" < "MergeFront" selects "Top and Bottom" in Word $oRange = _Word_DocRangeSet($oDoc, 0) $oRange.ParagraphFormat.Alignment = $wdAlignParagraphLeft ; Align Left $oRange.ParagraphFormat.SpaceAfter = 10 ;$oWordApp.Selection.TypeParagraph ;$oRange.InsertAfter("Inserted text after range.") ;$oRange.EndKey($wdLine,0) ;$oRange.Text = @CRLF ;$oRange.Collapse($wdCollapseEnd)
  21. I was able to shave off a little more time by using the DLL call directly. ; Comboboxen Dropdown List fill _______________________________________________________________________________________________________________ Local $iLen = UBound($aINI_KeyList) Local $hDll = DllOpen("user32.dll") For $x = 0 To UBound($hCombo) - 1 _GUICtrlComboBox_BeginUpdate($hCombo[$x]) For $i = 0 To $iLen - 1 ; INI Keys durchgehen ; _GUICtrlComboBox_AddString = _SendMessage DllCall($hDll, "lresult", "SendMessageW", "hwnd", $hCombo[$x], "uint", 0x143, "wparam", 0, "wstr", $aINI_KeyList[$i]) ; = _SendMessage Next _GUICtrlComboBox_EndUpdate($hCombo[$x]) Next DllClose($hDll)
  22. @Danp2 Hello, and thanks for the tip. Unfortunately _GUICtrlComboBox_InitStorage did not speedup the process. @mikell Hello, thanks a lot. I could swear that I tested this with beginupdate / endupdate and it did not make a difference. BUT now with _GUICtrlComboBox_BeginUpdate it shaved off 1.5 seconds of 2.8 seconds. Great, thank you guys! 👍
  23. @Danp2 Yes, this stops the GUI from updating. Thanks for that. Unfortunately, it does not speed up the creation of the comboboxes. I thought if I provided a delimited string @ creation, it would generate faster than when I use _GUICtrlComboBox_AddString one by one. Turns out they are both the same slow speed.
  24. Hello forum! Merry Christmas! I have this little loop here and I want to stop the GUI update until the comboboxes are populated. I want to do this because it takes around 3 seconds to draw 10 comboboxes. They all hold the same $sText (1200 items). But for some reason i can still see how they get created. ; Comboboxes create _______________________________________________________________________________________________________________ GUISetState(@SW_DISABLE, $hGUI) For $i = 1 To $iCoCo $hCombo[$i - 1] = _GUICtrlComboBox_Create($hGUI, $sKeys, $aPosX[$i], 37, $aColWI[$i] - 1, 500, BitOR($CBS_DROPDOWNLIST, $WS_VSCROLL)) $iCombo[$i - 1] = _WinAPI_GetDlgCtrlID($hCombo[$i - 1]) Next GUISetState(@SW_ENABLE, $hGUI) Thanks!!
×
×
  • Create New...