Leaderboard
Popular Content
Showing content with the highest reputation on 06/23/2023 in all areas
-
MbTcp - Modbus TCP UDF
marcoauto reacted to kurtykurtyboy for a topic
Here is something that I have been wanting in AutoIt for years but sadly no one had created it yet. Well, I decided to hunker down and do something about it! I present to you, MbTCP - a Modbus TCP/IP UDF. What is Modbus? Modbus is a communications protocol commonly used to communicate with various types of PLC's, sensors, SCADA systems, and many other industrial applications. Modbus TCP is the ethernet variant (as opposed to Modbus RTU which uses a serial connection). This UDF takes care of all the behind-the-scenes legwork and makes it easy to get right to the data. No need to worry about which function codes to use or how to format the data. Modbus typically works on discrete coils and inputs (think BOOL) or 16-bit registers (think INT). However, some devices support 32-bit signed and unsigned integers and 32-bit floating point numbers. This is possible by reading or writing 2 consecutive 16-bit registers and formatting them on both ends. The UDF will take care of all that as well (although maybe not in the most sophisticated ways...😏 ). Because there is no standard for working with 32-bit numbers, it is necessary to have the option to enable or disable big-endianness. Similarly, not all devices start counting at register 1. Some of them actually start at register 0. The UDF allows you to define these parameters when creating the connection to the device. Available data types for input and holding registers are INT16, UINT16, INT32, UINT32, and FLOAT32. Function List: ; _MbTcp_Connect ......................: Open a connection to a remote device ; _MbTcp_ReadCoils ....................: Read 1 or more output coils (function code 1) ; _MbTcp_ReadDiscreteInputs ...........: Read 1 or more discrete inputs (function code 2) ; _MbTcp_ReadHoldingRegisters .........: Read 1 or more holding registers (function code 3) ; _MbTcp_ReadInputRegisters ...........: Read 1 or more input registers (function code 4) ; _MbTcp_WriteCoils ...................: Write 1 or more output coils (function code 5 and 15) ; _MbTcp_WriteRegisters ...............: Write 1 or more holding registers (function code 6 and 16) ; _MbTcp_Disconnect ...................: Close the connection to a device ; _MbTcp_DisconnectAll ................: Close the connection to all connected devices To get started, follow these easy steps: Create a new connection to the device using _MbTcp_Connect Call any of the available read or write functions That's it. The program will automatically clean up any connections that are left open on exit. You may also manually disconnect from any device if needed. The most basic example of use. Connect to a device and read one holding register starting at register 2. #include "MbTcp.au3" ;connect to device at IP 127.0.0.1 Local $iConnection1 = _MbTcp_Connect("127.0.0.1") If @error Then MsgBox(16, "Error", "Failed to connect to the Modbus device at 127.0.0.1." & @CRLF & "Error Code: " & @error) Exit Else ConsoleWrite("Successfully connected to device at 127.0.0.1" & @CRLF) EndIf ;read 1 holding register Local $iReadData = _MbTcp_ReadHoldingRegisters($iConnection1, 2, 1) If @error Then MsgBox(16, "Error", "Failed to read the Modbus value." & @CRLF & "Error Code: " & @error) Else ConsoleWrite("Value: " & $iReadData & @CRLF) EndIf The next example shows how we can format the data to return an unsigned integer instead of the default signed integer. In the following example, we connect to a device that uses big-endian word order and starts at register 0 instead of 1. Then we read and write a group of registers. I may add more examples here if needed. There are a number of Modbus simulators out there if you want to test locally on your computer. But I really like a tool named Mod_RSsim link. Let me know if you find any issues. I know I will probably end up needing to add a timeout option. MbTcp_20230620.zip1 point -
Did you look into wd_demo.au3 ? I can presume yes. Did you go through all the links mentioned here: https://www.autoitscript.com/wiki/WebDriver#References Especially : btw. Few hours ago I suplemented WiKi page with this link: https://github.com/mlipok/Au3WebDriver-testing Take a look there. Especially for just created/uploaded wd_testing_Example.au3.1 point
-
StringSplit() may fail if LF not CRLF is used for the end of line. StringRegExp() cover both cases.1 point
-
I was unable to duplicate your results. When compiled or run from SciTE, if I didn't have a default mail client selected, it prompted me for an action. When I selected a default mail client (hat tip @ioa747) , it opened a compose email window in outlook or more options in Firefox. Note that the MailTo class you referenced doesn't set the default mail client in Win8 or later. Microsoft migrated it to "HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\Shell\Associations\UrlAssociations\mailto" in more recent builds of Windows and it's hashed so you can't just edit it (see here). Which leads us to how to set that: I've used SetFTA (here) or via @Danyfirex's AutoIT only solution (here). You'll still have to determine which mail client is installed but after setting whatever that is, you can use ShellExecute to your hearts delight.1 point
-
2020/08/16 New Version CropTool.au3 I've made some changes and fixes to this function: I added the possibility to vary both the thickness of the selector and its color. to customize the appearance and behavior of the tool, you can change the values of some variables in the function listing. See comments on lines 140-170 You can also vary the look of the border by setting a custom dash/space length pattern. Thanks to @UEZ for that. See here for reference. Hope it is free of bugs. (i don't know how to test it to see if it is also DPI aware??) Suggestions for improvements and bug reports are welcome. How to use this demo of use: hit Ctrl+PrintScreen to activate the tool LeftClick and drag on the borders of the tool to resize the area you can also Leftclick and drag within the area to move it around RightClick within the area to shot a screenshot of only the delimited area to the clipboard. in short "how to use the function" outside this demo in your programs: including the following 4 standard udf #include <Windowsconstants.au3> #include <WinAPISys.au3> #include <Misc.au3> #include <GDIPlus.au3> and pasting the _Crop function in your listing is all what you need, then: call the _Crop() function; the 'selector' appears around the mouse hovering the mouse over any side or corner the cursor should change accordingly; LeftClick on the edges and drag to redim the area, also LeftClick within the area and drag to move the selection around. When you are done with the selection, RightClick within the area or also hit the ESC key, the 4 element 1D array is returned to the caller and the 'selector' disappears from the screen Thank you ... below original post ... A function that allows you to freely and visually select an area of the screen Yes I know, there are already some in the forum, however here is yet another cropping tool. I collected some snippets from the forum and merged in a simple and quick cropping tool implemented as a single standalone function. The _Crop() function simply returns a 4-element 1D array with the x-y coordinates of the upper left and the width and height of the selected area, respectively in the elements [0] [1] [2] [3]. So it's up to you to make good use of these parameters An example of use: Since Windows already has both a screenprint functionkey to copy the whole screen to the clipboard and the Alt-printscreen shortkut to copy only the active window to the clipboard, I'm goinmg to bind this _crop() function combined with the Control-printscreen hotkey to create a "partial" screenshot of the delimited area of the screen. The captured screenshot of that area is copied to the clipboard, so you can paste it wherever you want. How to use it: after running the script, use the Control+Printscreen keys to activate the crop tool that appears around the mouse position; then use the mouse to visually resize and move the area and when you have delimited the desired area click with the right mouse button inside the area to copy it to the clipboard. Suggestions, improvements and finally error reports are welcome Happy cropping #AutoIt3Wrapper_Res_HiDpi=y #include <Windowsconstants.au3> #include <WinAPISys.au3> #include <Misc.au3> #include <GDIPlus.au3> #include <Clipboard.au3> ; ---------------------- ; -- Demo start -------- ; ---------------------- #include <ScreenCapture.au3> ; needed only For this demo Global $user32 = DllOpen("user32.dll") While 1 ; hit Control+Printscreen to call the _Crop Function If _IsPressed("11", $user32) And _IsPressed("2C", $user32) Then _example() ; 11 CTRL key + 2C PRINTSCREEN key ; hit Control + c to exit this script (can be castomized with other keys) If _IsPressed("11", $user32) And _IsPressed("43", $user32) Then ExitLoop ; 11 CTRL key + 43 C key Sleep(150) WEnd DllClose($user32) TrayTip("Crop demo", "End of the 'TSR' crop demo", 3, 1) ; (1) = Info icon Sleep(3000) Exit Func _example() $aRect = _Crop() ; mark the area If Not @extended Then ; if the ESC key was pressed within the _Crop function the @extended is set to 1 _GDIPlus_Startup() Local $hGui = GUICreate("", $aRect[2], $aRect[3], $aRect[0] - 1, $aRect[1] - 1, $WS_POPUPWINDOW) Local $idPic = GUICtrlCreatePic('', 0, 0, $aRect[2], $aRect[3]) Local $hTimer = TimerInit() Local $hBmp = _ScreenCapture_Capture('', $aRect[0], $aRect[1], $aRect[0] + $aRect[2] - 1, $aRect[1] + $aRect[3] - 1, False) Local $hBitmap = _GDIPlus_BitmapCreateFromHBITMAP($hBmp) Local $iMidX = $aRect[0] + $aRect[2] / 2 Local $iMidY = $aRect[1] + $aRect[3] / 2 ; snippet by UEZ ; https://www.autoitscript.com/forum/topic/129333-screen-capture-to-clipboard/?do=findComment&comment=898287 Local $bResult = _ClipBoard_Open(0) + _ClipBoard_Empty() + Not _ClipBoard_SetDataEx($hBmp, $CF_BITMAP) _ClipBoard_Close() If $bResult = 2 Then ToolTip("the area was copied to the clipboard", $iMidX, $iMidY, 'Info', 1, 6) Else ToolTip("Something went wrong", $iMidX, $iMidY, 'Error', 3, 6) EndIf ; snippet by Malkey ; https://www.autoitscript.com/forum/topic/191425-capturing-image-without-saving/?do=findComment&comment=1373088 Local $STM_SETIMAGE = 0x0172 GUICtrlSendMsg($idPic, $STM_SETIMAGE, $IMAGE_BITMAP, $hBmp) _WinAPI_DeleteObject($hBmp) GUISetState() DllCall("User32.dll", "int", "AnimateWindow", "hwnd", $hGui, "int", 750, "long", "0x00050002") ; Right-Left GUIDelete($hGui) Sleep(250) ToolTip('') ; #ce ; GUIDelete($hGui) _WinAPI_DeleteObject($hBmp) _GDIPlus_BitmapDispose($hBitmap) _GDIPlus_Shutdown() EndIf EndFunc ;==>_example ; ---------------------- ; -- Demo end ---------- ; ---------------------- ; #FUNCTION# ==================================================================================================================== ; Name ..........: _Crop ; Description ...: A function that allows you to freely and visually select an area of the screen ; Syntax ........: _Crop([$i_X = Default[, $i_Y = Default[, $i_W = Default[, $i_H = Default[, $iMinW = -1[, $iMaxW = -1[, ; $iMinH = -1[, $iMaxH = -1]]]]]]]]) ; ; - To resize the area click the left mouse button and drag on any of the moving colored edges of the tool. ; You can also LeftClick within the selected area and drag to move the whole selection. ; ; - To terminate the selection operation RightClick within the selected area. ; ; You can alse terminate the selection operation by hitting the ESC key; ; in that case the @extended macro will be setted to true ; ; Parameters ....: All parameters are optional: ; $i_X - [optional] an integer value. Default is MouseGetPos(0) - 50. ; The upper left X coordinate where you want the cropping tool to appear ; ; $i_Y - [optional] an integer value. Default is MouseGetPos(1) - 50. ; The upper left Y coordinate where you want the cropping tool to appear ; ; $i_W - [optional] an integer value. Default is 100. ; The initial width of the selection area ; ; $i_H - [optional] an integer value. Default is 100. ; The initial height of the selection area ; ; $iMinW - [optional] an integer value. Default is 1 (minimum allowed is 1). ; The minimum selectable width ; ; $iMaxW - [optional] an integer value. Default is -1 (no limit). ; The maximum selectable width ; ; $iMinH - [optional] an integer value. Default is 1 (minimum allowed is 1). ; The minimum selectable height ; ; $iMaxH - [optional] an integer value. Default is -1 (no limit). ; The maximum selectable height ; ; Return values .: - A 4 element 1D array where: ; element [0] the upperLeft X coordinate of the selected area ; element [1] the upperLeft Y coordinate of the selected area ; element [2] the width of the selected area ; element [3] the height of the selected area ; ; @extended is set to True if you exit from the _crop() function by pressing the ESC key ; ; Author ........: Chimp (Gianni Addiego) ; Modified ......: ; Remarks .......: ; Related .......: ; Link ..........: ; Example .......: ; =============================================================================================================================== ; Func _Crop($i_X = MouseGetPos(0) - 50, $i_Y = MouseGetPos(1) - 50, $i_W = 100, $i_H = 100, $iMinW = -1, $iMaxW = -1, $iMinH = -1, $iMaxH = -1) Func _Crop($i_X = Default, $i_Y = Default, $i_W = Default, $i_H = Default, $iMinW = 1, $iMaxW = -1, $iMinH = 1, $iMaxH = -1) _GDIPlus_Startup() If ($i_X = '') Or ($i_X = Default) Then $i_X = MouseGetPos(0) - 50 If ($i_Y = '') Or ($i_Y = Default) Then $i_Y = MouseGetPos(1) - 50 If ($i_W = '') Or ($i_W = Default) Then $i_W = 100 If ($i_H = '') Or ($i_H = Default) Then $i_H = 100 If ($iMinW < 1) Or ($iMinW = Default) Then $iMinW = 1 If ($iMaxW < 1) Or ($iMaxW = Default) Then $iMaxW = 65535 If ($iMinH < 1) Or ($iMinH = Default) Then $iMinH = 1 If ($iMaxH < 1) Or ($iMaxH = Default) Then $iMaxH = 65535 ; used local variables Local $hGUI2, $hGUI3, $aWinPos2, $aPrevPos2[4], $aClientSize Local $iX, $iY, $iW, $iH Local Enum $x, $y Local $iOuterTolerance, $iBorder, $iInnerTolerance Local $hGraphic, $hPen, $AlphaKey = 0xFF000000, $RectColor, $RectBgColor Local $hDLL = DllOpen("user32.dll") Local $fOffset, $iDelay, $iTimerID = TimerInit() Local $iCursorID, $iBorderID, $aMousePointer, $iSide, $iTopBot, $iInner, $iRightEdge, $iBottomEdge, $iMouseOffsetX, $iMouseOffsetY Local $bEscape ; ================================================================================== ; Set the appearance and behaviour of the tool ; ================================================================================== $iBorder = 2 ; the width of the colored border (minimum 1) ; since with a very thin border it is difficult to click on it to drag it ; it is possible to set an external courtesy area authorized to click on the border ; even if the mouse is not exactly on it (it can also be set to 0 to disable it) $iOuterTolerance = 4 ; 'courtesy' external area allowed to click on the border ; same as above but for the inside of the edge $iInnerTolerance = 3 ; 'courtesy' internal area allowed to click on the border $RectColor = 0xFFFF0000 ; The color of the colored moving edge $RectBgColor = 0xFFFFFF00 ; The Background color of the colored moving edge $iDelay = 50 ; this value determines the rotation speed of the moving colored border. The lower it is, the faster it is ; here the pattern of the moving edge can be customized ; Thanks to @UEZ for this snippet. See Here for reference: https://www.autoitscript.com/forum/topic/185769-moving-dash-rectangle/?do=findComment&comment=1343856 Local $iCount = 4, $tArray = DllStructCreate("float;float;float;float") DllStructSetData($tArray, 1, 2) ; dash length DllStructSetData($tArray, 2, 4) ; space length DllStructSetData($tArray, 3, 2) ; dash length DllStructSetData($tArray, 4, 4) ; space length ; Important!: also set the below variable as the sum of all the above dash/space values ; ========== Local $iDotsDashesTotLen = 2 + 4 + 2 + 4 ; <--- adapt this variable to the above values ; ================================================================================== ; Create a transparent window where to draw the moving colored edge effect using the $iBorder variable ; X and Y coordinates refers to where will be placed the client crop area (not the draggable outer colored border) $hGUI2 = GUICreate('', $i_W + $iBorder * 2, $i_H + $iBorder * 2, $i_X - $iBorder, $i_Y - $iBorder, $WS_POPUP, BitOR($WS_EX_LAYERED, $WS_EX_TOPMOST)) ; make sure $AlphaKey color is different from both $RectColor and $RectBgColor While ($AlphaKey = $RectColor) Or ($AlphaKey = $RectBgColor) $AlphaKey += 1 WEnd GUISetBkColor($AlphaKey, $hGUI2) _WinAPI_SetLayeredWindowAttributes($hGUI2, $AlphaKey, 0, $LWA_COLORKEY) ; Create a transparent window wider than the main one to allow the custom mouse cursor to be displayed even beyond the colored border (Tolerance) ; also, since this window is not "passthrough", it prevents mouse clicks from passing underneath. $hGUI3 = GUICreate('', $i_W + $iBorder * 2 + $iOuterTolerance * 2, $i_H + $iBorder * 2 + $iOuterTolerance * 2, $i_X - $iBorder - $iOuterTolerance, $i_Y - $iBorder - $iOuterTolerance, $WS_POPUP, BitOR($WS_EX_LAYERED, $WS_EX_TOPMOST)) WinSetTrans($hGUI3, "", 1) WinSetOnTop($hGUI3, "", $WINDOWS_ONTOP) GUISetState(@SW_SHOW, $hGUI2) GUISetState(@SW_SHOW, $hGUI3) $hPen = _GDIPlus_PenCreate($RectColor, $iBorder * 2) ; why * 2 ?? _GDIPlus_PenSetColor($hPen, $RectColor) $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI2) Do $iSide = 0 $iTopBot = 0 $iInner = 0 $bEscape = False $aMousePointer = GUIGetCursorInfo($hGUI2) ; zero based $aWinPos2 = WinGetPos($hGUI2) $aClientSize = WinGetClientSize($hGUI2) ; ----------------------- ; check pointer position ; -------------------------------------------------------------------------------------------------------------------------------------------------------- If _ ; Pointer is on the left border (($aMousePointer[$x] >= -$iOuterTolerance) And ($aMousePointer[$x] < ($iBorder + $iInnerTolerance))) And _ (($aMousePointer[$y] >= -$iOuterTolerance) And ($aMousePointer[$y] < ($aClientSize[1] + $iOuterTolerance))) Then $iSide = 1 If _ ; Pointer is on the right border (($aMousePointer[$x] >= ($aClientSize[0] - $iBorder - $iInnerTolerance)) And ($aMousePointer[$x] < ($aClientSize[0] + $iOuterTolerance))) And _ (($aMousePointer[$y] >= -$iOuterTolerance) And ($aMousePointer[$y] < ($aClientSize[1] + $iOuterTolerance))) Then $iSide = 2 If _ ; Pointer is on the top border (($aMousePointer[$y] >= -$iOuterTolerance) And ($aMousePointer[$y] < ($iBorder + $iInnerTolerance))) And _ (($aMousePointer[$x] >= -$iOuterTolerance) And ($aMousePointer[$x] < ($aClientSize[0] + $iOuterTolerance))) Then $iTopBot = 3 If _ ; Pointer is on the bottom border (($aMousePointer[$y] >= ($aClientSize[1] - $iBorder - $iInnerTolerance)) And ($aMousePointer[$y] < $aClientSize[1] + $iOuterTolerance)) And _ (($aMousePointer[$x] >= -$iOuterTolerance) And ($aMousePointer[$x] < ($aClientSize[0] + $iOuterTolerance))) Then $iTopBot = 6 If _ ; Pointer is within the client area (($aMousePointer[$x] >= ($iBorder + $iInnerTolerance)) And $aMousePointer[$x] < ($aClientSize[0] - $iBorder - $iInnerTolerance)) And _ (($aMousePointer[$y] >= ($iBorder + $iInnerTolerance)) And $aMousePointer[$y] < ($aClientSize[1] - $iBorder - $iInnerTolerance)) Then $iInner = 9 ; -------------------------------------------------------------------------------------------------------------------------------------------------------- $iBorderID = $iSide + $iTopBot + $iInner ; ; SetCursor ; --------- $iCursorID = 0 Switch $iBorderID Case 0 $iCursorID = 2 ; ARROW Case 1, 2 ; 1 left ; 2 right $iCursorID = 13 ; SIZEWE Case 3, 6 ; 3 top ; 6 bottom $iCursorID = 11 ; SIZENS Case 5, 7 ; 5 TopRight ; 7 BottomLeft $iCursorID = 10 ; SIZENESW Case 4, 8 ; 4 TopLeft ; 8 BottomRight $iCursorID = 12 ; SIZENWSE Case 9 ; 9 Inside $iCursorID = 0 ; HAND - or SIZEALL (9) EndSwitch GUISetCursor($iCursorID, 1) ; ------------------------------------------------------- ; If LeftClick on the tool then Drag or redimm selector ; ------------------------------------------------------- If _IsPressed("1", $hDLL) And $iBorderID And (WinActive($hGUI2) Or WinActive($hGUI3)) Then ; Left clicked $aWinPos2 = WinGetPos($hGUI2) Switch $iBorderID Case 0 Case 1 ; Pointer is on the left border $iMouseOffsetX = $aWinPos2[0] - MouseGetPos(0) $iRightEdge = $aWinPos2[0] + WinGetClientSize($hGUI2)[0] Case 2 ; Pointer is on the right border $iMouseOffsetX = $aWinPos2[0] + $aWinPos2[2] - MouseGetPos(0) Case 3 ; Pointer is on the top border $iMouseOffsetY = $aWinPos2[1] - MouseGetPos(1) $iBottomEdge = $aWinPos2[1] + $aWinPos2[3] Case 4 ; Pointer is on the top-left corner $iMouseOffsetY = $aWinPos2[1] - MouseGetPos(1) $iMouseOffsetX = $aWinPos2[0] - MouseGetPos(0) $iRightEdge = $aWinPos2[0] + WinGetClientSize($hGUI2)[0] $iBottomEdge = $aWinPos2[1] + $aWinPos2[3] Case 5 ; Pointer is on the top-right corner $iMouseOffsetX = $aWinPos2[0] + $aWinPos2[2] - MouseGetPos(0) $iMouseOffsetY = $aWinPos2[1] - MouseGetPos(1) $iBottomEdge = $aWinPos2[1] + $aWinPos2[3] Case 6 ; Pointer is on the bottom border $iMouseOffsetY = $aWinPos2[1] + $aWinPos2[3] - MouseGetPos(1) Case 7 ; Pointer is on the bottom-left $iMouseOffsetY = $aWinPos2[1] + $aWinPos2[3] - MouseGetPos(1) $iMouseOffsetX = $aWinPos2[0] - MouseGetPos(0) $iRightEdge = $aWinPos2[0] + WinGetClientSize($hGUI2)[0] Case 8 ; Pointer is on the bottom-right $iMouseOffsetY = $aWinPos2[1] + $aWinPos2[3] - MouseGetPos(1) $iMouseOffsetX = $aWinPos2[0] + $aWinPos2[2] - MouseGetPos(0) Case 9 $iMouseOffsetY = $aWinPos2[1] - MouseGetPos(1) $iMouseOffsetX = $aWinPos2[0] - MouseGetPos(0) EndSwitch Do $iX = Default $iY = Default $iW = Default $iH = Default Switch $iBorderID Case 1 ; Pointer is on the left border $iX = MouseGetPos(0) + $iMouseOffsetX $iW = $iRightEdge - MouseGetPos(0) + -$iMouseOffsetX Case 2 ; Pointer is on the right border $iW = (MouseGetPos(0) - $aWinPos2[0]) + $iMouseOffsetX Case 3 ; Pointer is on the top border $iY = MouseGetPos(1) + $iMouseOffsetY $iH = $iBottomEdge - MouseGetPos(1) + -$iMouseOffsetY Case 4 ; Pointer is on the top-left corner $iX = MouseGetPos(0) + $iMouseOffsetX $iY = MouseGetPos(1) + $iMouseOffsetY $iW = $iRightEdge - MouseGetPos(0) + -$iMouseOffsetX $iH = $iBottomEdge - MouseGetPos(1) + -$iMouseOffsetY Case 5 ; Pointer is on the top-right corner $iY = MouseGetPos(1) + $iMouseOffsetY $iW = (MouseGetPos(0) - $aWinPos2[0]) + $iMouseOffsetX $iH = $iBottomEdge - MouseGetPos(1) + -$iMouseOffsetY Case 6 ; Pointer is on the bottom border $iH = (MouseGetPos(1) - $aWinPos2[1]) + $iMouseOffsetY Case 7 ; Pointer is on the bottom-left corner $iX = MouseGetPos(0) + $iMouseOffsetX $iW = $iRightEdge - MouseGetPos(0) + -$iMouseOffsetX $iH = (MouseGetPos(1) - $aWinPos2[1]) + $iMouseOffsetY Case 8 ; Pointer is on the bottom-right corner $iW = (MouseGetPos(0) - $aWinPos2[0]) + $iMouseOffsetX $iH = (MouseGetPos(1) - $aWinPos2[1]) + $iMouseOffsetY Case 9 ; Pointer is inside the client area $iX = MouseGetPos(0) + $iMouseOffsetX $iY = MouseGetPos(1) + $iMouseOffsetY EndSwitch If $iW > ($iMaxW + $iBorder * 2) Then $iW = $iMaxW + $iBorder * 2 $iX = Default EndIf If $iW < ($iMinW + $iBorder * 2) Then $iW = $iMinW + $iBorder * 2 $iX = Default EndIf If $iH > ($iMaxH + $iBorder * 2) Then $iH = $iMaxH + $iBorder * 2 $iY = Default EndIf If $iH < ($iMinH + $iBorder * 2) Then $iH = $iMinH + $iBorder * 2 $iY = Default EndIf WinMove($hGUI2, '', $iX, $iY, $iW, $iH) GUISetCursor($iCursorID, 1) $aWinPos2 = WinGetPos($hGUI2) $aClientSize = WinGetClientSize($hGUI2) ; If GUI2 moved or resized then redraw the colored border and reposition also GUI3 If $aPrevPos2[0] <> $aWinPos2[0] Or $aPrevPos2[1] <> $aWinPos2[1] Or $aPrevPos2[2] <> $aWinPos2[2] Or $aPrevPos2[3] <> $aWinPos2[3] Then ; store new position/size $aPrevPos2[0] = $aWinPos2[0] $aPrevPos2[1] = $aWinPos2[1] $aPrevPos2[2] = $aWinPos2[2] $aPrevPos2[3] = $aWinPos2[3] _GDIPlus_GraphicsDispose($hGraphic) WinMove($hGUI3, '', $aWinPos2[0] - $iOuterTolerance, $aWinPos2[1] - $iOuterTolerance, $aWinPos2[2] + $iOuterTolerance * 2, $aWinPos2[3] + $iOuterTolerance * 2) $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI2) _GDIPlus_GraphicsClear($hGraphic, $AlphaKey) ; erase rect _GDIPlus_PenSetDashStyle($hPen, $GDIP_DASHSTYLESOLID) _GDIPlus_PenSetColor($hPen, $RectBgColor) _GDIPlus_GraphicsDrawRect($hGraphic, 0, 0, $aWinPos2[2], $aWinPos2[3], $hPen) ; _GDIPlus_PenSetDashStyle($hPen, $GDIP_DASHSTYLEDOT) DllCall($__g_hGDIPDll, "int", "GdipSetPenDashArray", "handle", $hPen, "struct*", $tArray, "long", $iCount) _GDIPlus_PenSetColor($hPen, $RectColor) _GDIPlus_GraphicsDrawRect($hGraphic, 0, 0, $aWinPos2[2], $aWinPos2[3], $hPen) ; draw again rect EndIf If TimerDiff($iTimerID) > $iDelay Then $fOffset = Mod($fOffset + .5, $iDotsDashesTotLen) ; this is the key for the animated dotted line ;-) by UEZ ; https://www.autoitscript.com/forum/topic/185769-moving-dash-rectangle/?do=findComment&comment=1343851 DllCall($__g_hGDIPDll, "int", "GdipSetPenDashOffset", "handle", $hPen, "float", $fOffset) _GDIPlus_GraphicsClear($hGraphic, $AlphaKey) ; erase rect _GDIPlus_PenSetDashStyle($hPen, $GDIP_DASHSTYLESOLID) _GDIPlus_PenSetColor($hPen, $RectBgColor) _GDIPlus_GraphicsDrawRect($hGraphic, 0, 0, $aWinPos2[2], $aWinPos2[3], $hPen) ; _GDIPlus_PenSetDashStyle($hPen, $GDIP_DASHSTYLEDOT) DllCall($__g_hGDIPDll, "int", "GdipSetPenDashArray", "handle", $hPen, "struct*", $tArray, "long", $iCount) _GDIPlus_PenSetColor($hPen, $RectColor) _GDIPlus_GraphicsDrawRect($hGraphic, 0, 0, $aWinPos2[2], $aWinPos2[3], $hPen) ; draw again rect $iTimerID = TimerInit() EndIf Until Not _IsPressed("1", $hDLL) ; Right click released EndIf If TimerDiff($iTimerID) > $iDelay Then $fOffset = Mod($fOffset + .5, $iDotsDashesTotLen) DllCall($__g_hGDIPDll, "int", "GdipSetPenDashOffset", "handle", $hPen, "float", $fOffset) ; this is the key for the animated dotted line ;-) by UEZ _GDIPlus_GraphicsClear($hGraphic, $AlphaKey) ; erase rect _GDIPlus_PenSetDashStyle($hPen, $GDIP_DASHSTYLESOLID) _GDIPlus_PenSetColor($hPen, $RectBgColor) _GDIPlus_GraphicsDrawRect($hGraphic, 0, 0, $aWinPos2[2], $aWinPos2[3], $hPen) ; _GDIPlus_PenSetDashStyle($hPen, $GDIP_DASHSTYLEDOT) DllCall($__g_hGDIPDll, "int", "GdipSetPenDashArray", "handle", $hPen, "struct*", $tArray, "long", $iCount) _GDIPlus_PenSetColor($hPen, $RectColor) _GDIPlus_GraphicsDrawRect($hGraphic, 0, 0, $aWinPos2[2], $aWinPos2[3], $hPen) ; draw again rect $iTimerID = TimerInit() EndIf If _IsPressed('1B', $hDLL) Then $bEscape = True ; 1B ESC key Until ((_IsPressed('2', $hDLL) Or $bEscape) And (WinActive($hGUI2) Or WinActive($hGUI3))) ; RightClick means I'm done with selection Do ; neutralize the RightClick persistency Until Not _IsPressed('2', $hDLL) Local $aGotRect[4] = [ _ $aWinPos2[0] + $iBorder, _ ; ....... UpperLeft X of window's client area $aWinPos2[1] + $iBorder, _ ; ....... UpperLeft Y of window's client area $aWinPos2[2] - $iBorder * 2, _ ; ... Width of window's client area $aWinPos2[3] - $iBorder * 2 _ ; .... Height of window's client area ] _GDIPlus_PenDispose($hPen) _GDIPlus_GraphicsDispose($hGraphic) _GDIPlus_Shutdown() DllClose($hDLL) $tArray = 0 GUIDelete($hGUI3) GUIDelete($hGUI2) Return SetError(0, $bEscape, $aGotRect) EndFunc ;==>_Crop CropTool.au31 point
-
_Excel_RangeRead How to read all cells in a single column
ThomasBennett reacted to Danp2 for a topic
Why not use the recommended solution of workbook.activesheet.usedrange?1 point -
Something like this here? $hClipboard_Bitmap = _GDIPlus_BitmapCreateFromFile('C:\Users\s\Desktop\1.jpg') $hClipboard_BitmapGDI = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hClipboard_Bitmap) $hHBmp_Clipboard = _WinAPI_CopyImage($hClipboard_BitmapGDI, 0, 0, 0, BitOR($LR_COPYDELETEORG, $LR_COPYRETURNORG)) _WinAPI_Bitmap2Clipboard($hHBmp_Clipboard) Func _WinAPI_Bitmap2Clipboard($hHBitmap) If Not _ClipBoard_Open(0) Then Return 1 If Not _ClipBoard_Empty() Then Return 2 Local Const $hCP = _ClipBoard_SetDataEx($hHBitmap, $CF_BITMAP) If Not $hCP Or @error Then Return 3 _ClipBoard_Close() Return 0 EndFunc1 point
-
I haven't the zip file, but probably these three listings were in that zip: DragDropEvent.au3 ; =============================================================================================================================== ; File : DragDropEvent.au3 (2012/3/15) ; Purpose : Convert OLE drag-and-drop event to "Windows Message" that AutoIt3 can handle by GUIRegisterMsg ; Provide 4 message: $WM_DRAGENTER, $WM_DRAGOVER, $WM_DRAGLEAVE, and $WM_DROP ; Author : Ward ; =============================================================================================================================== #Include-once #Include <Memory.au3> #Include <SendMessage.au3> #Include <WindowsConstants.au3> ; =============================================================================================================================== ; Public Functions: ; ; DragDropEvent_Startup() ; DragDropEvent UDF startup. ; ; DragDropEvent_Register($hWnd, $hWndToReceiveMsg = $hWnd) ; Register a window or control that can be the target. $hWndToReceiveMsg is needed only when $hWnd is a control. ; ; DragDropEvent_Revoke($hWnd) ; Revokes the registration of the specified window or control. ; ; DragDropEvent_GetHWnd($wParam) ; Can invoke by all message handler, to get what window or control is the target. ; ; DragDropEvent_GetX($wParam) ; DragDropEvent_GetY($wParam) ; DragDropEvent_GetKeyState($wParam) ; Can invoke by all message handler except $WM_DRAGLEAVE, to get the modifier keys and mouse position. ; ; DragDropEvent_IsText($wParam) ; DragDropEvent_IsFile($wParam) ; Can invoke by $WM_DRAGENTER or $WM_DROP, to check what data is being dragged. ; ; DragDropEvent_GetText($wParam) ; DragDropEvent_GetFile($wParam) ; Can invoke by $WM_DRAGENTER or $WM_DROP, to get related data. Path of file is splited by "|". ; ; =============================================================================================================================== ; =============================================================================================================================== ; Internal Functions: ; ; IDropTarget_QueryInterface($pSelf, $pRIID, $pObj) ; IDropTarget_AddRef($pSelf) ; IDropTarget_Release($pSelf) ; IDropTarget_DragEnter($pSelf, $DataObj, $KeyState, $X, $Y, $pEffect) ; IDropTarget_DragLeave($pSelf) ; IDropTarget_DragOver($pSelf, $KeyState, $X, $Y, $pEffect) ; IDropTarget_Drop($pSelf, $DataObj, $KeyState, $X, $Y, $pEffect) ; IDropTarget_SetEffect($pEffect, $Value) ; Methods of IDropTarget interface. ; ; IDropTarget_SetHWnd($pSelf, $hWnd, $hWndToReceiveMsg) ; IDropTarget_GetHWnd($pSelf, ByRef $hWnd, ByRef $hWndToReceiveMsg) ; To set and get data store in IDropTarget interface. ; ; DataObject_QueryText($DataObj) ; DataObject_QueryFile($DataObj) ; DataObject_GetText($DataObj) ; DataObject_GetFile($DataObj) ; Functions to handle DataObject. ; ; DragDropEvent_InfoCreate($hWnd, $DataObj, $KeyState, $X, $Y) ; DragDropEvent_Get($wParam, $Name) ; Functions to handle infomation data for DragDropEvent. ; ; __CreateCOMInterface($sFunctionPrefix, $dtagInterface, $fNoUnknown = False, $ExtraSpace = 0) ; To create vtable of a COM interface. Modify from _AutoItObject_ObjectFromDtag. ; ; =============================================================================================================================== ; =============================================================================================================================== ; Global const and variables ; =============================================================================================================================== ; Define 4 kind of DragDropEvent: DragEnter, DragOver, DragLeave, and Drop Global Enum $WM_DRAGENTER = $WM_USER + 0x1001, $WM_DRAGOVER, $WM_DRAGLEAVE, $WM_DROP ; Message handler return one of these flags, which indicates what the result of the drop operation would be. Global Enum $DROPEFFECT_NONE = 0, $DROPEFFECT_COPY = 1, $DROPEFFECT_MOVE = 2, $DROPEFFECT_LINK = 4, $DROPEFFECT_SCROLL = 0x80000000 Global Const $IID_IDataObject = "{0000010e-0000-0000-C000-000000000046}" Global Const $dtagIDropTarget = "DragEnter hresult(ptr;uint;uint64;ptr);DragOver hresult(uint;uint64;ptr);DragLeave hresult();Drop hresult(ptr;uint;uint64;ptr);" Global Const $dtagIDataObject = "GetData hresult(struct*;struct*);GetDataHere hresult(struct*;struct*);QueryGetData hresult(struct*);GetCanonicalFormatEtc hresult(struct*;struct*);SetData hresult(struct*;struct*;int);EnumFormatEtc hresult(uint;ptr);DAdvise hresult(struct*;uint;ptr;ptr);DUnadvise hresult(uint);EnumDAdvise hresult(ptr);" Global Const $tagFORMATETC = "struct;uint Format;ptr ptd;uint Aspect;int lindex;uint tymed;endstruct" Global Const $tagSTGMEDIUM = "struct;uint tymed;ptr hGlobal;ptr UnkForRelease;endstruct" Global Const $tagDragDropEventInfo = "ptr hwnd;ptr DataObj;uint KeyState;uint x;uint y" Global Const $__KERNEL32_DLL = DllOpen("kernel32.dll") Global Const $__OLE32_DLL = DllOpen("ole32.dll") Global $__IDropTargetLen = 0 ; =============================================================================================================================== ; DragDropEvent startup and register functions ; =============================================================================================================================== Func DragDropEvent_Startup() ; If @AutoItVersion < "3.3.8.0" Then Exit MsgBox(16, "DragDropEvent Fail", "Require AutoIt Version 3.3.8.0 at least") DllCall($__OLE32_DLL, "int", "OleInitialize", "ptr", 0) EndFunc Func DragDropEvent_Register($hWnd, $hWndToReceiveMsg = Default) If IsKeyword($hWndToReceiveMsg) Then $hWndToReceiveMsg = $hWnd Local $IDropTarget = __CreateCOMInterface("IDropTarget_", $dtagIDropTarget, True, 2) ; add 2 extra space to store hWnd If $IDropTarget Then $__IDropTargetLen = @Extended IDropTarget_SetHWnd($IDropTarget, $hWnd, $hWndToReceiveMsg) DllCall($__OLE32_DLL, "int", "RegisterDragDrop", "hwnd", $hWnd, "ptr", $IDropTarget) EndIf EndFunc Func DragDropEvent_Revoke($hWnd) DllCall($__OLE32_DLL, "int", "RevokeDragDrop", "hwnd", $hWnd) EndFunc ; =============================================================================================================================== ; Methods of IDropTarget interface ; =============================================================================================================================== Func IDropTarget_QueryInterface($pSelf, $pRIID, $pObj) Return 0x80004002 ; E_NOINTERFACE EndFunc Func IDropTarget_AddRef($pSelf) EndFunc Func IDropTarget_Release($pSelf) DllCall($__OLE32_DLL, "none", "CoTaskMemFree", "ptr", $pSelf) EndFunc Func IDropTarget_DragEnter($pSelf, $DataObj, $KeyState, $Point, $pEffect) Local $hWnd, $hWndToReceiveMsg IDropTarget_GetHWnd($pSelf, $hWnd, $hWndToReceiveMsg) Local $X = BitAND($Point, 0xFFFFFFFF), $Y = Dec(StringTrimRight(Hex($Point), 8)) Local $Info = DragDropEvent_InfoCreate($hWnd, $DataObj, $KeyState, $X, $Y) Local $Ret = _SendMessage($hWndToReceiveMsg, $WM_DRAGENTER, DllStructGetPtr($Info), 0) DllStructSetData(DllStructCreate("dword", $pEffect), 1, $Ret) EndFunc Func IDropTarget_DragLeave($pSelf) Local $hWnd, $hWndToReceiveMsg IDropTarget_GetHWnd($pSelf, $hWnd, $hWndToReceiveMsg) Local $Info = DragDropEvent_InfoCreate($hWnd, 0, 0, 0, 0) _SendMessage($hWndToReceiveMsg, $WM_DRAGLEAVE, DllStructGetPtr($Info), 0) EndFunc Func IDropTarget_DragOver($pSelf, $KeyState, $Point, $pEffect) Local $hWnd, $hWndToReceiveMsg IDropTarget_GetHWnd($pSelf, $hWnd, $hWndToReceiveMsg) Local $X = BitAND($Point, 0xFFFFFFFF), $Y = Dec(StringTrimRight(Hex($Point), 8)) Local $Info = DragDropEvent_InfoCreate($hWnd, 0, $KeyState, $X, $Y) Local $Ret = _SendMessage($hWndToReceiveMsg, $WM_DRAGOVER, DllStructGetPtr($Info), 0) DllStructSetData(DllStructCreate("dword", $pEffect), 1, $Ret) EndFunc Func IDropTarget_Drop($pSelf, $DataObj, $KeyState, $Point, $pEffect) Local $hWnd, $hWndToReceiveMsg IDropTarget_GetHWnd($pSelf, $hWnd, $hWndToReceiveMsg) Local $X = BitAND($Point, 0xFFFFFFFF), $Y = Dec(StringTrimRight(Hex($Point), 8)) Local $Info = DragDropEvent_InfoCreate($hWnd, $DataObj, $KeyState, $X, $Y) Local $Ret = _SendMessage($hWndToReceiveMsg, $WM_DROP, DllStructGetPtr($Info), 0) DllStructSetData(DllStructCreate("dword", $pEffect), 1, $Ret) EndFunc Func IDropTarget_SetHWnd($pSelf, $hWnd, $hWndToReceiveMsg) Local $Buffer = DllStructCreate("ptr[" & ($__IDropTargetLen + 2) & "]", $pSelf) DllStructSetData($Buffer, 1, $hWnd, $__IDropTargetLen + 1) DllStructSetData($Buffer, 1, $hWndToReceiveMsg, $__IDropTargetLen + 2) EndFunc Func IDropTarget_GetHWnd($pSelf, ByRef $hWnd, ByRef $hWndToReceiveMsg) Local $Buffer = DllStructCreate("ptr[" & ($__IDropTargetLen + 2) & "]", $pSelf) $hWnd = DllStructGetData($Buffer, 1, $__IDropTargetLen + 1) $hWndToReceiveMsg = DllStructGetData($Buffer, 1, $__IDropTargetLen + 2) EndFunc ; =============================================================================================================================== ; Functions to handle DataObject ; =============================================================================================================================== Func DataObject_QueryText($DataObj) Local $IDataObj = ObjCreateInterface($DataObj, $IID_IDataObject, $dtagIDataObject) If Not IsObj($IDataObj) Then Return -1 $IDataObj.AddRef() Local $FORMATETC = DllStructCreate($tagFORMATETC) DllStructSetData($FORMATETC, "Format", 13) ; 13 = CF_UNICODETEXT DllStructSetData($FORMATETC, "Aspect", 1) DllStructSetData($FORMATETC, "lindex", -1) DllStructSetData($FORMATETC, "tymed", 1) ; 1 = TYMED_HGLOBAL Local $Ret = $IDataObj.QueryGetData($FORMATETC) If $Ret <> 0 Then DllStructSetData($FORMATETC, "Format", 1) ; 1 = CF_TEXT $Ret = $IDataObj.QueryGetData($FORMATETC) EndIf Return $Ret EndFunc Func DataObject_QueryFile($DataObj) Local $IDataObj = ObjCreateInterface($DataObj, $IID_IDataObject, $dtagIDataObject) If Not IsObj($IDataObj) Then Return -1 $IDataObj.AddRef() Local $FORMATETC = DllStructCreate($tagFORMATETC) DllStructSetData($FORMATETC, "Format", 15) ; 15 = CF_HDROP DllStructSetData($FORMATETC, "Aspect", 1) DllStructSetData($FORMATETC, "lindex", -1) DllStructSetData($FORMATETC, "tymed", 1) ; 1 = TYMED_HGLOBAL Return $IDataObj.QueryGetData($FORMATETC) EndFunc Func DataObject_GetText($DataObj) Local $IDataObj = ObjCreateInterface($DataObj, $IID_IDataObject, $dtagIDataObject) If Not IsObj($IDataObj) Then Return -1 $IDataObj.AddRef() Local $FORMATETC = DllStructCreate($tagFORMATETC) Local $STGMEDIUM = DllStructCreate($tagSTGMEDIUM) DllStructSetData($FORMATETC, "Format", 13) ; 13 = CF_UNICODETEXT DllStructSetData($FORMATETC, "Aspect", 1) DllStructSetData($FORMATETC, "lindex", -1) DllStructSetData($FORMATETC, "tymed", 1) ; 1 = TYMED_HGLOBAL Local $IsUnicode = True Local $Ret = $IDataObj.QueryGetData($FORMATETC) If $Ret <> 0 Then $IsUnicode = False DllStructSetData($FORMATETC, "Format", 1) ; 1 = CF_TEXT $Ret = $IDataObj.QueryGetData($FORMATETC) EndIf If $Ret <> 0 Then Return SetError(1, 0, "") Local $Error = 1, $Text = "" If $IDataObj.GetData($FORMATETC, $STGMEDIUM) = 0 Then If DllStructGetData($STGMEDIUM, "tymed") = 1 Then Local $Ptr = _MemGlobalLock(DllStructGetData($STGMEDIUM, "hGlobal")) Local $Tag If $IsUnicode Then $Tag = "wchar[" & (_MemGlobalSize($Ptr) / 2) & "]" Else $Tag = "char[" & _MemGlobalSize($Ptr) & "]" EndIf $Text = DllStructGetData(DllStructCreate($Tag, $Ptr), 1) _MemGlobalUnlock($Ptr) If DllStructGetData($STGMEDIUM, "UnkForRelease") = 0 Then _MemGlobalFree($Ptr) $Error = 0 EndIf EndIf Return SetError($Error, 0, $Text) EndFunc Func DataObject_GetFile($DataObj) Local $IDataObj = ObjCreateInterface($DataObj, $IID_IDataObject, $dtagIDataObject) If Not IsObj($IDataObj) Then Return -1 $IDataObj.AddRef() Local $FORMATETC = DllStructCreate($tagFORMATETC) Local $STGMEDIUM = DllStructCreate($tagSTGMEDIUM) DllStructSetData($FORMATETC, "Format", 15) ; 15 = CF_HDROP DllStructSetData($FORMATETC, "Aspect", 1) DllStructSetData($FORMATETC, "lindex", -1) DllStructSetData($FORMATETC, "tymed", 1) ; 1 = TYMED_HGLOBAL Local $Error = 1, $FileList = "" If $IDataObj.GetData($FORMATETC, $STGMEDIUM) = 0 Then If DllStructGetData($STGMEDIUM, "tymed") = 1 Then Local $Ptr = _MemGlobalLock(DllStructGetData($STGMEDIUM, "hGlobal")) Local $StrPtr = $Ptr + DllStructGetData(DllStructCreate("dword", $Ptr), 1) Do Local $Ret = DllCall($__KERNEL32_DLL, "uint", "lstrlenW", "ptr", $StrPtr) Local $StrLen = $Ret[0] If $StrLen Then Local $Str = DllStructGetData(DllStructCreate("wchar[" & $StrLen & "]", $StrPtr), 1) $FileList &= $Str & "|" $StrPtr += $StrLen * 2 + 2 EndIf Until $StrLen = 0 If StringRight($FileList, 1) = "|" Then $FileList = StringTrimRight($FileList, 1) _MemGlobalUnlock($Ptr) If DllStructGetData($STGMEDIUM, "UnkForRelease") = 0 Then _MemGlobalFree($Ptr) $Error = 0 EndIf EndIf Return SetError($Error, 0, $FileList) EndFunc ; =============================================================================================================================== ; Functions to handle infomation data for DragDropEvent ; =============================================================================================================================== Func DragDropEvent_InfoCreate($hWnd, $DataObj, $KeyState, $X, $Y) Local $Info = DllStructCreate($tagDragDropEventInfo) DllStructSetData($Info, "hwnd", $hWnd) DllStructSetData($Info, "DataObj", $DataObj) DllStructSetData($Info, "KeyState", $KeyState) DllStructSetData($Info, "x", $X) DllStructSetData($Info, "y", $Y) Return $Info EndFunc Func DragDropEvent_Get($wParam, $Name) If Not $wParam Then Return SetError(1, 0, 0) Local $Info = DllStructCreate($tagDragDropEventInfo, $wParam) Return DllStructGetData($Info, $Name) EndFunc Func DragDropEvent_GetHWnd($wParam) Local $Ret = DragDropEvent_Get($wParam, "hwnd") Return SetError(@Error, 0, $Ret) EndFunc Func DragDropEvent_GetX($wParam) Local $Ret = DragDropEvent_Get($wParam, "x") Return SetError(@Error, 0, $Ret) EndFunc Func DragDropEvent_GetY($wParam) Local $Ret = DragDropEvent_Get($wParam, "y") Return SetError(@Error, 0, $Ret) EndFunc Func DragDropEvent_GetKeyState($wParam) Local $Ret = DragDropEvent_Get($wParam, "KeyState") Return SetError(@Error, 0, $Ret) EndFunc Func DragDropEvent_IsText($wParam) Local $DataObj = DragDropEvent_Get($wParam, "DataObj") Return DataObject_QueryText($DataObj) = 0 EndFunc Func DragDropEvent_IsFile($wParam) Local $DataObj = DragDropEvent_Get($wParam, "DataObj") Return DataObject_QueryFile($DataObj) = 0 EndFunc Func DragDropEvent_GetText($wParam) Local $DataObj = DragDropEvent_Get($wParam, "DataObj") Return DataObject_GetText($DataObj) EndFunc Func DragDropEvent_GetFile($wParam) Local $DataObj = DragDropEvent_Get($wParam, "DataObj") Return DataObject_GetFile($DataObj) EndFunc ; =============================================================================================================================== ; Functions to create COM interface ; =============================================================================================================================== Func __CreateCOMInterface($sFunctionPrefix, $dtagInterface, $fNoUnknown = False, $ExtraSpace = 0) ; Original is _AutoItObject_ObjectFromDtag in AutoItObject.au3 by AutoItObject-Team ; Modify by Ward Local Const $__PtrSize = DllStructGetSize(DllStructCreate('ptr', 1)) Local Const $dtagIUnknown = "QueryInterface hresult(ptr;ptr*);AddRef dword();Release dword();" If $fNoUnknown Then $dtagInterface = $dtagIUnknown & $dtagInterface Local $sMethods = StringReplace(StringRegExpReplace($dtagInterface, "\h*(\w+)\h*(\w+\*?)\h*(\((.*?)\))\h*(;|;*\z)", "$1\|$2;$4" & @LF), ";" & @LF, @LF) If $sMethods = $dtagInterface Then $sMethods = StringReplace(StringRegExpReplace($dtagInterface, "\h*(\w+)\h*(;|;*\z)", "$1\|" & @LF), ";" & @LF, @LF) $sMethods = StringTrimRight($sMethods, 1) $sMethods = StringReplace(StringReplace(StringReplace(StringReplace($sMethods, "object", "idispatch"), "variant*", "ptr"), "hresult", "long"), "bstr", "ptr") Local $aMethods = StringSplit($sMethods, @LF, 3) Local $iUbound = UBound($aMethods) Local $sMethod, $aSplit, $sNamePart, $aTagPart, $sTagPart, $sRet, $sParams, $hCallback Local $AllocSize = $__PtrSize * ($iUbound + 1 + $ExtraSpace) Local $Ret = DllCall($__OLE32_DLL, "ptr", "CoTaskMemAlloc", "uint_ptr", $AllocSize) If @error Then Return SetError(1, 0, 0) Local $AllocPtr = $Ret[0] Local $tInterface = DllStructCreate("ptr[" & $iUbound + 1 & "]", $AllocPtr) If @error Then Return SetError(1, 0, 0) For $i = 0 To $iUbound - 1 $aSplit = StringSplit($aMethods[$i], "|", 2) If UBound($aSplit) <> 2 Then ReDim $aSplit[2] $sNamePart = $aSplit[0] $sTagPart = $aSplit[1] $sMethod = $sFunctionPrefix & $sNamePart $aTagPart = StringSplit($sTagPart, ";", 2) $sRet = $aTagPart[0] $sParams = StringReplace($sTagPart, $sRet, "", 1) $sParams = "ptr" & $sParams ; To avoid repeat allocate the same callback, a memory leakage $hCallback = Eval(":Callback:" & $sMethod) If Not $hCallback Then $hCallback = DllCallbackRegister($sMethod, $sRet, $sParams) Assign(":Callback:" & $sMethod, $hCallback, 2) EndIf DllStructSetData($tInterface, 1, DllCallbackGetPtr($hCallback), $i + 2) Next DllStructSetData($tInterface, 1, $AllocPtr + $__PtrSize) ; Interface method pointers are actually pointer size away Return SetExtended($iUbound + 1, $AllocPtr) ; Return interface size as @Extended for access extra space EndFunc DragDropEvent_Example_1.au3 ; =============================================================================================================================== ; File : DragDropEvent_Example_1.au3 (2012/3/9) ; Purpose : Demonstrate the usage of DragDropEvent UDF ; Author : Ward ; =============================================================================================================================== #Include <GUIConstantsEx.au3> #Include <WindowsConstants.au3> #Include "DragDropEvent.au3" Opt("MustDeclareVars", 1) DragDropEvent_Startup() Main() Exit Func Main() Local $MainWin = GUICreate("DragDropEvent Example", 380, 130, -1, -1, -1, $WS_EX_TOPMOST) GUISetFont(12, 900) GUICtrlCreateLabel("(Drop text or files on me)", 40, 40) DragDropEvent_Register($MainWin) GUIRegisterMsg($WM_DRAGENTER, "OnDragDrop") GUIRegisterMsg($WM_DRAGOVER, "OnDragDrop") GUIRegisterMsg($WM_DRAGLEAVE, "OnDragDrop") GUIRegisterMsg($WM_DROP, "OnDragDrop") GUISetState(@SW_SHOW) While GUIGetMsg() <> $GUI_EVENT_CLOSE WEnd GUIDelete() EndFunc Func OnDragDrop($hWnd, $Msg, $wParam, $lParam) Static $DropAccept Switch $Msg Case $WM_DRAGENTER, $WM_DROP ToolTip("") Select Case DragDropEvent_IsFile($wParam) If $Msg = $WM_DROP Then Local $FileList = DragDropEvent_GetFile($wParam) MsgBox(262144, "DragDropEvent", StringReplace($FileList, "|", @LF)) EndIf $DropAccept = $DROPEFFECT_COPY Case DragDropEvent_IsText($wParam) If $Msg = $WM_DROP Then MsgBox(262144, "DragDropEvent", DragDropEvent_GetText($wParam)) EndIf $DropAccept = $DROPEFFECT_COPY Case Else $DropAccept = $DROPEFFECT_NONE EndSelect Return $DropAccept Case $WM_DRAGOVER Local $X = DragDropEvent_GetX($wParam) Local $Y = DragDropEvent_GetY($wParam) ToolTip("(" & $X & "," & $Y & ")") Return $DropAccept Case $WM_DRAGLEAVE ToolTip("") EndSwitch EndFunc DragDropEvent_Example_2.au3 ; =============================================================================================================================== ; File : DragDropEvent_Example_2.au3 (2012/3/9) ; Purpose : Demonstrate the usage of DragDropEvent UDF ; Author : Ward ; =============================================================================================================================== #Include <GUIConstantsEx.au3> #Include <WindowsConstants.au3> #Include "DragDropEvent.au3" Opt("MustDeclareVars", 1) Global $Button1, $Button2, $Button3, $Button4 DragDropEvent_Startup() Main() Exit Func Main() Local $MainWin = GUICreate("DragDropEvent Example", 460, 400, -1, -1, -1, $WS_EX_TOPMOST) GUISetFont(12, 900) $Button1 = GUICtrlCreateButton("Drop Text", 20, 20, 200, 150) $Button2 = GUICtrlCreateButton("Drop Files", 240, 20, 200, 150) $Button3 = GUICtrlCreateButton("Drop Anything", 20, 190, 200, 150) $Button4 = GUICtrlCreateButton("Don't Drop", 240, 190, 200, 150) GUICtrlCreateLabel("(Click button to revoke the target)", 40, 350) DragDropEvent_Register(GUICtrlGetHandle($Button1), $MainWin) DragDropEvent_Register(GUICtrlGetHandle($Button2), $MainWin) DragDropEvent_Register(GUICtrlGetHandle($Button3), $MainWin) DragDropEvent_Register(GUICtrlGetHandle($Button4), $MainWin) GUIRegisterMsg($WM_DRAGENTER, "OnDragDrop") GUIRegisterMsg($WM_DRAGOVER, "OnDragDrop") GUIRegisterMsg($WM_DRAGLEAVE, "OnDragDrop") GUIRegisterMsg($WM_DROP, "OnDragDrop") GUISetState(@SW_SHOW) While 1 Local $Msg = GUIGetMsg() Switch $Msg Case $Button1, $Button2, $Button3, $Button4 DragDropEvent_Revoke(GUICtrlGetHandle($Msg)) Case $GUI_EVENT_CLOSE ExitLoop EndSwitch WEnd GUIDelete() EndFunc Func OnDragDrop($hWnd, $Msg, $wParam, $lParam) Static $DropAccept Switch $Msg Case $WM_DRAGENTER, $WM_DROP ToolTip("") Local $Target = DragDropEvent_GetHWnd($wParam) Select Case DragDropEvent_IsFile($wParam) If $Target = GUICtrlGetHandle($Button1) Or $Target = GUICtrlGetHandle($Button4) Then $DropAccept = $DROPEFFECT_NONE Else If $Msg = $WM_DROP Then Local $FileList = DragDropEvent_GetFile($wParam) MsgBox(262144, "DragDropEvent", StringReplace($FileList, "|", @LF)) EndIf $DropAccept = $DROPEFFECT_COPY EndIf Case DragDropEvent_IsText($wParam) If $Target = GUICtrlGetHandle($Button2) Or $Target = GUICtrlGetHandle($Button4) Then $DropAccept = $DROPEFFECT_NONE Else If $Msg = $WM_DROP Then MsgBox(262144, "DragDropEvent", DragDropEvent_GetText($wParam)) EndIf $DropAccept = $DROPEFFECT_COPY EndIf Case Else $DropAccept = $DROPEFFECT_NONE EndSelect Return $DropAccept Case $WM_DRAGOVER Local $X = DragDropEvent_GetX($wParam) Local $Y = DragDropEvent_GetY($wParam) Local $KeyState = DragDropEvent_GetKeyState($wParam) ToolTip("(" & $X & "," & $Y & "," & $KeyState & ")") Return $DropAccept Case $WM_DRAGLEAVE ToolTip("") EndSwitch EndFunc1 point
-
Redraw your desktop with GDI+
KeeperOfTheReaper reacted to InunoTaishou for a topic
Take a screenshot of your desktop (works even if the desktop is hidden), then redraws it row by row. Makes a neat little effect. An effect I remember seeing at the photo booth at Chuck E' Cheese. I mostly just wanted to mess with LockBits and PrintWindow and thought this was a decent way to figure it out, but I liked the outcome and thought I'd share lol #include <GDIPlus.au3> #include <WinApi.au3> #include <WindowsConstants.au3> _GDIPlus_Startup() Global $tDesktopMetrics = GetDesktopMetrics() Global $hHBitmapDesktop = CaptureWindow("", -1, -1, -1, -1, "Program Manager") Global $hBitmapDesktop = _GDIPlus_BitmapCreateFromHBITMAP($hHBitmapDesktop) _WinAPI_DeleteObject($hHBitmapDesktop) Global $iW = _GDIPlus_ImageGetWidth($hBitmapDesktop) Global $iH = _GDIPlus_ImageGetHeight($hBitmapDesktop) Global $tBitmapData = _GDIPlus_BitmapLockBits($hBitmapDesktop, 0, 0, $iW, $iH, $GDIP_ILMREAD, $GDIP_PXF32PARGB) Global $tPixelMap = DllStructCreate("int[" & $iW * $iH & "];", DllStructGetData($tBitmapData, "Scan0")) Global $hGui = GUICreate("Redraw", $iW, $iH, $tDesktopMetrics.x, $tDesktopMetrics.y, $WS_POPUP) Global $hGraphics = _GDIPlus_GraphicsCreateFromHWND($hGui) Global $hBitmap = _GDIPlus_BitmapCreateFromGraphics($iW, $iH, $hGraphics) Global $tBitmapData2 = _GDIPlus_BitmapLockBits($hBitmap, 0, 0, $iW, $iH, $GDIP_ILMWRITE, $GDIP_PXF32PARGB) Global $tPixelMap2 = DllStructCreate("int[" & $iW * $iH & "];", DllStructGetData($tBitmapData2, "Scan0")) GUISetState(@SW_SHOW, $hGui) _GDIPlus_GraphicsClear($hGraphics) For $iY = 0 To $iH - 1 Local $iRowOffset = $iY * $iW + 1 For $iX = 0 To $iW - 1 ;get each pixel in each line and row DllStructSetData($tPixelMap2, 1, DllStructGetData($tPixelMap, 1, $iRowOffset + $iX), $iRowOffset + $iX) Next If (Not Mod($iY, 5)) Then ; Every 5 rows draw the bitmap _GDIPlus_BitmapUnlockBits($hBitmap, $tBitmapData2) _GDIPlus_GraphicsDrawImage($hGraphics, $hBitmap, 0, 0) $tBitmapData2 = _GDIPlus_BitmapLockBits($hBitmap, 0, 0, $iW, $iH, $GDIP_ILMWRITE, $GDIP_PXF32PARGB) $tPixelMap2 = DllStructCreate("int[" & $iW * $iH & "];", DllStructGetData($tBitmapData2, "Scan0")) EndIf Next If (Mod($iY, 5)) Then ; Didn't end on an even row, clean up _GDIPlus_BitmapUnlockBits($hBitmap, $tBitmapData2) _GDIPlus_GraphicsDrawImage($hGraphics, $hBitmap, 0, 0) $tPixelMap2 = 0 $tBitmapData2 = 0 EndIf _GDIPlus_BitmapUnlockBits($hBitmapDesktop, $tBitmapData) _GDIPlus_BitmapDispose($hBitmapDesktop) _GDIPlus_BitmapDispose($hBitmap) _GDIPlus_GraphicsDispose($hGraphics) _GDIPlus_Shutdown() GUIDelete($hGui) Exit 0 Func CaptureWindow($sFileName = "", $iLeft = -1, $iTop = -1, $iWidth = -1, $iHeight = -1, $hWnd = WinGetHandle("[Active]"), $bClientArea = True) If (Not IsHWnd($hWnd)) Then $hWnd = WinGetHandle($hWnd) If (@error) Then Return SetError(1, 0, False) If (BitAND(WinGetState($hWnd), 16) = 16) Then Return SetError(2, 0, False) Local $iSrcWidth = 0 Local $iSrcHeight = 0 ConsoleWrite($iLeft & ', ' & $iTop & ", " & $iWidth & ', ' & $iHeight & @LF) If ($hWnd = _WinAPI_GetDesktopWindow() Or $hWnd = WinGetHandle("Program Manager")) Then Local $tDesktop = GetDesktopMetrics() If ($iWidth = -1 Or $iWidth = 0 Or $iWidth = Default Or $iWidth > DllStructGetData($tDesktop, 3)) Then $iWidth = DllStructGetData($tDesktop, 3) If ($iHeight = -1 Or $iHeight = 0 Or $iHeight = Default Or $iWidth > DllStructGetData($tDesktop, 4)) Then $iHeight = DllStructGetData($tDesktop, 4) $iSrcWidth = DllStructGetData($tDesktop, 3) $iSrcHeight = DllStructGetData($tDesktop, 4) Else Local $tRectWindow = _WinAPI_GetWindowRect($hWnd) ; Get the absolute width, using Abs on all of the memembers because the [1] index of the struct may be negative, supports multiple monitors Local $iAbsWidth = Abs(Abs(DllStructGetData($tRectWindow, 3)) - Abs(DllStructGetData($tRectWindow, 1))) ; Get the absolute height, using Abs on all of the memembers because the [1] index of the struct may be negative, supports multiple monitors ; Subtracts the caption bar if $bClientArea only Local $iAbsHeight = Abs(Abs(DllStructGetData($tRectWindow, 4)) - Abs(DllStructGetData($tRectWindow, 2))) - ($bClientArea ? _WinAPI_GetSystemMetrics($SM_CYCAPTION) : 0) If ($iWidth = -1 Or $iWidth = 0 Or $iWidth = Default Or $iWidth > $iAbsWidth) Then $iWidth = $iAbsWidth If ($iHeight = -1 Or $iHeight = 0 Or $iHeight = Default Or $iHeight > $iAbsHeight) Then $iHeight = $iAbsHeight $iSrcWidth = $iAbsWidth $iSrcHeight = $iAbsHeight EndIf If ($iLeft = -1 Or $iLeft = Default) Then $iLeft = 0 If ($iTop = -1 Or $iTop = Default) Then $iTop = 0 Local $hDC = _WinAPI_GetWindowDC($hWnd) Local $hDestDC = _WinAPI_CreateCompatibleDC($hDC) Local $hDestBitmap = _WinAPI_CreateCompatibleBitmap($hDC, $iWidth, $iHeight) Local $hDestSv = _WinAPI_SelectObject($hDestDC, $hDestBitmap) Local $hSrcDC = _WinAPI_CreateCompatibleDC($hDC) Local $hBmp = _WinAPI_CreateCompatibleBitmap($hDC, $iSrcWidth, $iSrcHeight) Local $hSrcSv = _WinAPI_SelectObject($hSrcDC, $hBmp) _WinAPI_PrintWindow($hWnd, $hSrcDC, True) _WinAPI_BitBlt($hDestDC, 0, 0, $iWidth, $iHeight, $hSrcDC, $iLeft, $iTop, $MERGECOPY) _WinAPI_SelectObject($hDestDC, $hDestSv) _WinAPI_SelectObject($hSrcDC, $hSrcSv) _WinAPI_ReleaseDC($hWnd, $hDC) _WinAPI_DeleteDC($hDestDC) _WinAPI_DeleteDC($hSrcDC) _WinAPI_DeleteObject($hBmp) $tPoint = 0 $tRectWindow = 0 $tDesktop = 0 If ($sFileName) Then _GDIPlus_Startup() Local $hBitmap = _GDIPlus_BitmapCreateFromHBITMAP($hDestBitmap) _GDIPlus_ImageSaveToFile($hBitmap, $sFileName) _GDIPlus_BitmapDispose($hBitmap) _GDIPlus_Shutdown() EndIf Return $hDestBitmap EndFunc ;==>CaptureWindow Func GetDesktopMetrics() Return _GDIPlus_RectFCreate(_WinAPI_GetSystemMetrics($SM_XVIRTUALSCREEN), _WinAPI_GetSystemMetrics($SM_YVIRTUALSCREEN), _ _WinAPI_GetSystemMetrics($SM_CXVIRTUALSCREEN), _WinAPI_GetSystemMetrics($SM_CYVIRTUALSCREEN)) EndFunc ;==>GetDesktopMetrics1 point -
Using "And" and "Or" statement help?
ThomasBennett reacted to PsaltyDS for a topic
Basic logic error, if it matches one, it doesn't match the other. You can select multiple matches in a single Case: $State = "Test1" Switch $State Case "Test1", "Test2" MsgBox(1024,$State,"var is Test1 or Test2") Case Else MsgBox(1024,$State,"var is something other than Test1 or Test2") EndIf Edit: Or just change your Boolean operation to And: If ($State <> "Test1") And ($State <> "Test2") Then The parens are not required, but good practice for readability.1 point