Leaderboard
Popular Content
Showing content with the highest reputation on 03/25/2023 in all areas
-
Maybe this ? #include <GDIPlus.au3> #include <Clipboard.au3> _GDIPlus_Startup() Local $hImage = _GDIPlus_ImageLoadFromFile("torus.jpg") Local $hBitmap1 = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage) _GDIPlus_ImageDispose($hImage) Local $hBitmap2 = _WinAPI_CopyImage($hBitmap1, $IMAGE_BITMAP, 0, 0, $LR_COPYDELETEORG+$LR_COPYRETURNORG) _WinAPI_DeleteObject($hBitmap1) _GDIPlus_Shutdown() _ClipBoard_Open(0) _ClipBoard_Empty() _ClipBoard_SetDataEx( $hBitmap2, $CF_BITMAP) _ClipBoard_Close() _WinAPI_DeleteObject($hBitmap2)3 points
-
I had already created my GUI and had the basic flow working minus the INI section read. However thanks for your suggestion. I am working on the INI piece now so you response insightful. It gave me a different prospective. Think I will grind some code and see if I get struck. If I do I will definitely ask you guys for feedback. Thx2 points
-
Yes, the name I used for the byte array was "bytes" and the name for the word array was "words". I can see how that may have been a little hard to decipher at first. It does look like some sort of internal function when using dot-notation instead of DllStructSetData() with member names.2 points
-
I am an idiot...I totally missed the part that the data is explicitly assigned to `bytes` by: $tENDPOINT.bytes(1) = 127 ;127.0.0.1 $tENDPOINT.bytes(2) = 0 $tENDPOINT.bytes(3) = 0 $tENDPOINT.bytes(4) = 1 I thought it was some sort of internal function call...1 point
-
Thanks again for the explanation. I wasn't paying attention to the type of the item in the struct, one uses `byte` (an 8bit) and another is `word` (16bit)1 point
-
After @Dan_555 suggestion ; https://www.autoitscript.com/forum/topic/209945-interview-style-gui-creation-moved/?do=findComment&comment=1515664 #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> Global $sMyIni = @ScriptDir & "\Quest.ini" Global $Radio[3] = [2, 1, 2] Global $Choose[3] = [2, 1, 2] CheckMyIni() GUICreate("Quest", 400, 170, -1, -1) Global $lQuest = GUICtrlCreateLabel("Label1", 40, 10, 390, 22) GUICtrlSetFont(-1, 11, 400, 0, "Tahoma") GUICtrlCreateGroup("Choose", 30, 40, 311, 81) GUICtrlSetFont(-1, 8, 400, 0, "Tahoma") $Radio[1] = GUICtrlCreateRadio("Radio1", 40, 60, 97, 17) GUICtrlSetFont(-1, 10, 400, 0, "Tahoma") $Radio[2] = GUICtrlCreateRadio("Radio2", 40, 90, 97, 17) GUICtrlSetFont(-1, 10, 400, 0, "Tahoma") GUICtrlCreateGroup("", -99, -99, 1, 1) Global $ButtonNext = GUICtrlCreateButton("Nex", 150, 130, 100, 25) GUICtrlSetFont(-1, 10, 400, 0, "Tahoma") GUICtrlSetState(-1, $GUI_DISABLE) SetDataFromSection("Are you a Dog or a Cat") GUISetState(@SW_SHOW) ;*************************************************** While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $ButtonNext If GUICtrlRead($ButtonNext) = "Close" Then Exit If BitAND(GUICtrlRead($Radio[1]), $GUI_CHECKED) = $GUI_CHECKED Then SetDataFromSection($Choose[1]) ElseIf BitAND(GUICtrlRead($Radio[2]), $GUI_CHECKED) = $GUI_CHECKED Then SetDataFromSection($Choose[2]) EndIf GUICtrlSetState($Radio[1], $GUI_UNCHECKED) GUICtrlSetState($Radio[2], $GUI_UNCHECKED) Case $Radio[1], $Radio[2] GUICtrlSetState($ButtonNext, $GUI_ENABLE) EndSwitch WEnd ;*************************************************** Exit ;---------------------------------------------------------------------------------------- Func SetDataFromSection($Section) GUICtrlSetData($lQuest, $Section) Local $aArray = IniReadSection($sMyIni, $Section) ;$aArray[1][0] = 1st Key ;$aArray[1][1] = 1st Value If Not @error Then For $i = 1 To $aArray[0][0] If $aArray[$i][1] Then GUICtrlSetData($Radio[$i], $aArray[$i][0]) $Choose[$i] = $aArray[$i][1] Else GUICtrlSetState($Radio[$i], $GUI_HIDE) GUICtrlSetData($ButtonNext, "Close") EndIf Next EndIf EndFunc ;==>SetDataFromSection ;---------------------------------------------------------------------------------------- Func CheckMyIni() ; Read the INI section names. This will return a 1 dimensional array. Local $aSection = IniReadSectionNames($sMyIni) Local $sMsg ; Check if an error occurred. If Not @error Then ; Enumerate through the array displaying the section names. For $i = 1 To $aSection[0] ;ConsoleWrite("Section: " & $aSection[$i] & @CRLF) Next EndIf For $x = 1 To $aSection[0] For $z = 1 To $aSection[0] If $aSection[$x] = $aSection[$z] Then If $x <> $z Then $sMsg = $aSection[$z] & @CRLF & @CRLF $sMsg &= "collide sections " & $x & ", " & $z & @CRLF & @CRLF $sMsg &= "Please fix it to avoid complications" MsgBox(4144, "Dublicate Section found", $sMsg) ShellExecute($sMyIni) Exit EndIf EndIf Next Next EndFunc ;==>CheckMyIni1 point
-
I was playing this (in my thoughts) through, and came to the conclusion that you should check if an answer (ini section) already exists before adding something new. if you simply add, you may overwrite the old answer with a new question and the sequential logic may break at some time. edit: Ini file is just fine. If you go with the ini, you can easily spot the mistakes. when you are 100% sure that there are no mistakes, then you can convert it to the sql (if you think that the ini file is limiting in some way). If you manage to set the reading/editing/writing the data into functions, then you only need to rewrite the functions and to point them to the sql instead of the ini.1 point
-
I played with it a bit #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> Global $sMyIni = @ScriptDir & "\Quest.ini" Global $Radio[3] = [2, 1, 2] Global $Choose[3] = [2, 1, 2] GUICreate("Quest", 400, 170, -1, -1) Global $lQuest = GUICtrlCreateLabel("Label1", 40, 10, 390, 22) GUICtrlSetFont(-1, 11, 400, 0, "Tahoma") GUICtrlCreateGroup("Choose", 30, 40, 311, 81) GUICtrlSetFont(-1, 8, 400, 0, "Tahoma") $Radio[1] = GUICtrlCreateRadio("Radio1", 40, 60, 97, 17) GUICtrlSetFont(-1, 10, 400, 0, "Tahoma") $Radio[2] = GUICtrlCreateRadio("Radio2", 40, 90, 97, 17) GUICtrlSetFont(-1, 10, 400, 0, "Tahoma") GUICtrlCreateGroup("", -99, -99, 1, 1) Global $ButtonNext = GUICtrlCreateButton("Nex", 150, 130, 100, 25) GUICtrlSetFont(-1, 10, 400, 0, "Tahoma") GUICtrlSetState(-1, $GUI_DISABLE) SetDataFromSection("Are you a Dog or a Cat") GUISetState(@SW_SHOW) ;*************************************************** While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $ButtonNext If GUICtrlRead($ButtonNext) = "Close" Then Exit If BitAND(GUICtrlRead($Radio[1]), $GUI_CHECKED) = $GUI_CHECKED Then SetDataFromSection($Choose[1]) ElseIf BitAND(GUICtrlRead($Radio[2]), $GUI_CHECKED) = $GUI_CHECKED Then SetDataFromSection($Choose[2]) EndIf GUICtrlSetState($Radio[1], $GUI_UNCHECKED) GUICtrlSetState($Radio[2], $GUI_UNCHECKED) Case $Radio[1], $Radio[2] GUICtrlSetState($ButtonNext, $GUI_ENABLE) EndSwitch WEnd ;*************************************************** Exit ;---------------------------------------------------------------------------------------- Func SetDataFromSection($Section) GUICtrlSetData($lQuest, $Section) Local $aArray = IniReadSection($sMyIni, $Section) ;$aArray[1][0] = 1st Key ;$aArray[1][1] = 1st Value If Not @error Then For $i = 1 To $aArray[0][0] If $aArray[$i][1] Then GUICtrlSetData($Radio[$i], $aArray[$i][0]) $Choose[$i] = $aArray[$i][1] Else GUICtrlSetState($Radio[$i], $GUI_HIDE) GUICtrlSetData($ButtonNext, "Close") EndIf Next EndIf EndFunc ;==>SetDataFromSection ;---------------------------------------------------------------------------------------- the Quest.ini [Are you a Dog or a Cat] Dog=Is you dog a puppy Cat=Is you cat a calico [Is you dog a puppy] Yes=what do you like more No=Is you dog a shepherd [Is you cat a calico] Yes=what do you like more No=Is you cat a Siam [Is you dog a shepherd] Yes=what do you like more No=Is you dog a guardian [Is you dog a guardian] Yes=what do you like more No=what do you like more [Is you cat a Siam] Yes=what do you like more No=Is you cat a Persian [Is you cat a Persian] Yes=what do you like more No=what do you like more [what do you like more] Play=your Play is over ride=your ride is over [your ride is over] 1= 2= [your Play is over] 1= 2=1 point
-
You're welcome! The size of the $tagRASTUNNELENDPOINT struct is 20 bytes. As I showed in the example, the RASTUNNELENDPOINT struct is defined as: typedef struct RASTUNNELENDPOINT { DWORD dwType; union { RASIPV4ADDR ipv4; RASIPV6ADDR ipv6; }; }; That's a DWORD (4 bytes) followed by a union containing 2 members, a RASIPV4ADDR struct and a RASIPV6ADDR struct. The RASIPV4ADDR struct is 4 bytes and the RASIPV6ADDR struct is 16 bytes (8 WORDs). The size of a union in memory is the size of the largest member within the union. Therefore, the size of the RASTUNNELENDPOINT struct is: DWORD (4 btyes) + the size of the largest member within the union (16 bytes). So the total size is 20 bytes. If you need a high-level explanation of C Unions, the provided link is a good start. The RASCONNSTATUS and RASTUNNELENDPOINT structs can be defined in AutoIt in multiple ways that can produce the same result. Since AutoIt does not have an intrinsic data type similar to a C union, I choose to define unions by defining the physical (memory) representation and also the logical representations. The physical representations are used to read/write the whole struct to/from memory. The logical representations are used to correctly get and set members within a union. That is why you see in my example: $tagRASTUNNELENDPOINT (the physical representation; how the data is stored in memory) $tagRASTUNNELENDPOINT_UNION_IPV4 (logical definition of an IPV4 endpoint struct) $tagRASTUNNELENDPOINT_UNION_IPV6 (logical definition of an IPV6 endpoint struct) If you look at my previous example, the logical structs are used to set the values. Basically, the pointer of the logical struct is set to the physical memory location of the endpoint struct that I want to set. In memory, the endpoint's IP address takes up 16 bytes whether it is IPV4 or IPV6, The logical structs define how I reference the memory location, which can be as an IPV4 endpoint (4 bytes) or an IPV6 endpoint (8, 2-byte WORDs; 16 bytes).1 point
-
As to your question about the Enums, by default, Enums are 32-bit integers. To know for sure, you would need to look at how they are defined in their source files. I don't have any RAS VPNs defined on my PC so I can't test the structs with the actual APIs. However, I think my translation is correct. Below is an example of how I would probably define the RASCONNSTATUS & RASTUNNELENDPOINT structures and how I would use them. The RASIPV4ADDR struct is an alias for in_addr. The RASIPV6ADDR struct is an alias for in6_addr. I only gave an example of setting values, in order for you to see the struct with data in it. Reading values would pretty much be the same, except you would be getting the values instead of setting them. Example: #include <Constants.au3> #include <WinAPIDiag.au3> Const $RAS_MaxDeviceType = 16, _ $RAS_MaxDeviceName = 128, _ $RAS_MaxPhoneNumber = 128 Enum $RASTUNNELENDPOINT_UNKNOWN, _ ;0 $RASTUNNELENDPOINT_IPV4, _ ;1 $RASTUNNELENDPOINT_IPV6 ;2 #cs typedef struct RASTUNNELENDPOINT { DWORD dwType; union { RASIPV4ADDR ipv4; RASIPV6ADDR ipv6; }; }; #ce Global $tagRASTUNNELENDPOINT = _ "struct;" & _ "dword dwType;" & _ "byte bytes[16];" & _ "endstruct;" Global $tagRASTUNNELENDPOINT_UNION_IPV4 = _ "struct;" & _ "dword dwType;" & _ "byte bytes[4];" & _ "endstruct;" Global $tagRASTUNNELENDPOINT_UNION_IPV6 = _ "struct;" & _ "dword dwType;" & _ "word words[8];" & _ "endstruct;" #cs typedef struct RASCONNSTATUS { DWORD dwSize; RASCONNSTATE rasconnstate; DWORD dwError; TCHAR szDeviceType[RAS_MaxDeviceType + 1]; TCHAR szDeviceName[RAS_MaxDeviceName + 1]; TCHAR szPhoneNumber[RAS_MaxPhoneNumber + 1]; RASTUNNELENDPOINT localEndPoint; RASTUNNELENDPOINT remoteEndPoint; RASCONNSUBSTATE rasconnsubstate; } RASCONNSTATUS; #ce Global $tagRASCONNSTATUS = _ "struct;" & _ "dword dwSize;" & _ "int rasconnstate;" & _ "dword dwError;" & _ "wchar szDeviceType[" & $RAS_MaxDeviceType + 1 & "];" & _ "wchar szDeviceName[" & $RAS_MaxDeviceName + 1 & "];" & _ "wchar szPhoneNumber[" & $RAS_MaxPhoneNumber + 1 & "];" & _ $tagRASTUNNELENDPOINT & _ ;local endpoint $tagRASTUNNELENDPOINT & _ ;remote endpoint "int rasconnsubstate;" & _ "endstruct;" example() Func example() Local $tRASCONNSTATUS, _ $tENDPOINT ;Create RASCONNSTATUS structure $tRASCONNSTATUS = DllStructCreate($tagRASCONNSTATUS) ;Set RASCONNSTATUS dwSize field $tRASCONNSTATUS.dwSize = DllStructGetSize($tRASCONNSTATUS) $tRASCONNSTATUS.szDeviceType = "Some device type" $tRASCONNSTATUS.szDeviceName = "Some device name" $tRASCONNSTATUS.szPhoneNumber = "8005551212" ;Set local ipv4 tunnel endpoint $tENDPOINT = DllStructCreate($tagRASTUNNELENDPOINT_UNION_IPV4, DllStructGetPtr($tRASCONNSTATUS, 7)) $tENDPOINT.dwType = $RASTUNNELENDPOINT_IPV4 $tENDPOINT.bytes(1) = 127 ;127.0.0.1 $tENDPOINT.bytes(2) = 0 $tENDPOINT.bytes(3) = 0 $tENDPOINT.bytes(4) = 1 ;Set remote ipv6 tunnel endpoint $tENDPOINT = DllStructCreate($tagRASTUNNELENDPOINT_UNION_IPV6, DllStructGetPtr($tRASCONNSTATUS, 9)) $tENDPOINT.dwType = $RASTUNNELENDPOINT_IPV6 $tENDPOINT.words(1) = Binary("0x2001") ;2001:0db8:85a3:0000:0000:8a2e:0370:7334 $tENDPOINT.words(2) = Binary("0x0db8") $tENDPOINT.words(3) = Binary("0x85a3") $tENDPOINT.words(4) = Binary("0x0000") $tENDPOINT.words(5) = Binary("0x0000") $tENDPOINT.words(6) = Binary("0x8a2e") $tENDPOINT.words(7) = Binary("0x0370") $tENDPOINT.words(8) = Binary("0x7334") ;Display example struct _WinAPI_DisplayStruct($tRASCONNSTATUS, $tagRASCONNSTATUS, "RASCONNSTATUS") EndFunc1 point
-
The following code draws a picture from the clipboard to a gui window. The original code hasn't displayed the picture from the clipboard, and after a lot of trial and errors i found the solution which does work (i'm using windows 10). You have to have a screenshot or a picture in the clipboard for this to work (this script is sending a printscreen key if the clipboard content is not bitmap). Resizing reloads the picture from the clipboard. ;modified code from https://www.autoitscript.com/forum/topic/57053-updating-a-picture-control-without-a-file/?do=findComment&comment=514735 #include <ScreenCapture.au3> #include <Clipboard.au3> #include <GDIPlus.au3> #include <GUIConstantsEx.au3> #include <WinAPIHObj.au3> #include <WindowsConstants.au3> Global $hGUI = GUICreate("Draw Image from Clipboard ", 400, 300, -1, -1, BitOR($GUI_SS_DEFAULT_GUI, $WS_SIZEBOX)) GUISetState() If Not _ClipBoard_IsFormatAvailable($CF_BITMAP) Then Send("{printscreen}") EndIf ClipDrawBitmap() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $GUI_EVENT_RESIZED ClipDrawBitmap() EndSwitch WEnd Func ClipDrawBitmap() Local $WPos, $hBitmap, $hImage, $hGraphics $WPos = WinGetPos($hGUI) _ClipBoard_Open($hGUI) $hBitmap = _ClipBoard_GetDataEx($CF_BITMAP) _ClipBoard_Close() If $hBitmap > 0 Then _GDIPlus_Startup() $hImage = _GDIPlus_BitmapCreateFromHBITMAP($hBitmap) $hGraphics = _GDIPlus_GraphicsCreateFromHWND($hGUI) _GDIPlus_DrawImagePoints($hGraphics, $hImage, 0, 0, $WPos[2], 0, 0, $WPos[3]) _GDIPlus_ImageDispose($hImage) _WinAPI_DeleteObject($hBitmap) _GDIPlus_GraphicsDispose($hGraphics) _GDIPlus_Shutdown() EndIf EndFunc ;==>ClipDrawBitmap1 point
-
Regular Expression to escape characters
pixelsearch reacted to jchd for a topic
You can use a lookbehind assertion like this: $s = "/slash/, esc-slash\/, text#inside, esc\#untouched and esc\, is fine" Local $t = StringRegExpReplace($s, "(?<!\\)([/#,])", "\\$1") ConsoleWrite($s & @LF & $t & @LF)1 point