Leaderboard
Popular Content
Showing content with the highest reputation on 11/12/2021 in all areas
-
ProcessExists() documentation question
TheDcoder and one other reacted to JockoDundee for a topic
This topic discussed to the fullest extent of the law here:2 points -
C# PointersOne difference between C# and VB.NET is that C# offers more advanced and specialized functionality. In C# it's possible to use pointers to further speed up the code. This isn't possible in VB.NET. This post is about performance optimizing C# code using pointers. C# pointers in this thread are interesting because the IntPtr technique makes it possible to copy even very large amounts of data very fast. Therefore, it's also interesting with very fast code to process these large amounts of data. C# and VB.NET code perform pretty much as well as C/C++ code. C# code based on pointers performs as well as C/C++ code based on pointers. Unsafe codeThe part of C# code that uses pointers must be marked as unsafe code. When compiling the code, use the /unsafe compiler option. In DotNetAll.au3, DotNet_LoadCScode() is used to load and compile C# code: DotNet_LoadCScode( $sCode, $sReferences = "", $oAppDomain = 0, $sFileName = "", $sCompilerOptions = "" ) The function is used this way to load and compile C# code with pointers: Local $oNetCode = DotNet_LoadCScode( FileRead( "Example01.cs" ), "System.dll", 0, "", "/unsafe" ) Simple exampleExample01.au3 and Example01.cs in \Examples\4) C# Pointers\ is a simple example that demonstrates the use of pointers: #AutoIt3Wrapper_Au3Check_Parameters=-d -w- 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7 #AutoIt3Wrapper_UseX64=Y Opt( "MustDeclareVars", 1 ) #include "..\..\Includes\DotNetAll.au3" Example() Func Example() Local $oNetCode = DotNet_LoadCScode( FileRead( "Example01.cs" ), "System.dll", 0, "", "/unsafe" ) Local $oTestClass = DotNet_CreateObject( $oNetCode, "TestClass" ) $oTestClass.Test() EndFunc using System; class TestClass { public void Test() { int i; // Integer variable i. unsafe { // Unsafe code block with pointers. int *p = &i; // Integer type pointer p is initialized with the memory address of i. *p = 123; // The memory address to which pointer p refers is set to the value 123. } // Since pointer p refers to the memory address of i, the value of i is Console.WriteLine(i); // actually set to 123. } } Image exampleThe other examples are translations of the image manipulation example at the end of first post. The example is translated from VB.NET code to first C# code without pointers and then C# code with pointers. Example02.au3 and Example02.vb is the original example with VB.NET code: Imports System Imports System.Drawing Imports System.Drawing.Imaging Imports System.Runtime.InteropServices Class TestClass Public Function Test() As IntPtr 'Create bitmap Dim bmp As New Bitmap( "Test.bmp" ) 'Lock the bits in the bitmap Dim rect As New Rectangle( 0, 0, bmp.Width, bmp.Height ) Dim bmpData As BitmapData = bmp.LockBits( rect, ImageLockMode.ReadWrite, bmp.PixelFormat ) 'Get the address of the first line Dim ptr As IntPtr = bmpData.Scan0 'Declare an array to hold the bytes of the bitmap 'This code is specific to a bitmap with 24 bits per pixel (bpp) Dim iBytes As Integer = Math.Abs( bmpData.Stride ) * bmp.Height Dim aRGBValues(iBytes-1) As Byte 'Copy the RGB values into the array Marshal.Copy( ptr, aRGBValues, 0, iBytes ) 'Set every third value to 255, a 24bpp image will look red For i As Integer = 2 To aRGBValues.Length - 1 Step 3 aRGBValues(i) = 255 Next 'Copy the RGB values back to the bitmap Marshal.Copy( aRGBValues, 0, ptr, iBytes ) 'Unlock the bits bmp.UnlockBits( bmpData ) 'Create GDI bitmap Dim hBitmap As IntPtr = bmp.GetHbitmap() 'Return GDI bitmap Return hBitmap End Function End Class Example03.au3 and Example03.cs is a translation of the VB.NET code into C# code: using System; using System.Drawing; using System.Drawing.Imaging; using System.Runtime.InteropServices; class TestClass { public IntPtr Test() { // Create bitmap Bitmap bmp = new Bitmap( "Test.bmp" ); // Lock the bits in the bitmap Rectangle rect = new Rectangle( 0, 0, bmp.Width, bmp.Height ); BitmapData bmpData = bmp.LockBits( rect, ImageLockMode.ReadWrite, bmp.PixelFormat ); // Get the address of the first line IntPtr ptr = bmpData.Scan0; // Declare an array to hold the bytes of the bitmap // This code is specific to a bitmap with 24 bits per pixel (bpp) int iBytes = Math.Abs( bmpData.Stride ) * bmp.Height; byte[] aRGBValues = new byte[iBytes]; // Copy the RGB values into the array Marshal.Copy( ptr, aRGBValues, 0, iBytes ); // Set every third value to 255, a 24bpp image will look red for ( int i = 2; i < aRGBValues.Length; i += 3 ) aRGBValues[i] = 255; // Copy the RGB values back to the bitmap Marshal.Copy( aRGBValues, 0, ptr, iBytes ); // Unlock the bits bmp.UnlockBits( bmpData ); // Create GDI bitmap IntPtr hBitmap = bmp.GetHbitmap(); // Return GDI bitmap return hBitmap; } } Example04.au3 and Example04.cs is an implementation of the C# code using pointers: using System; using System.Drawing; using System.Drawing.Imaging; using System.Runtime.InteropServices; class TestClass { public unsafe IntPtr Test() { // Unsafe function // Create bitmap Bitmap bmp = new Bitmap( "Test.bmp" ); // Lock the bits in the bitmap Rectangle rect = new Rectangle( 0, 0, bmp.Width, bmp.Height ); BitmapData bmpData = bmp.LockBits( rect, ImageLockMode.ReadWrite, bmp.PixelFormat ); // Get the address of the first line byte* ptr = (byte*)bmpData.Scan0.ToPointer(); // Declare an array to hold the bytes of the bitmap // This code is specific to a bitmap with 24 bits per pixel (bpp) int iBytes = Math.Abs( bmpData.Stride ) * bmp.Height; byte[] aRGBValues = new byte[iBytes]; // Normal pointer to an object // Copy the RGB values into the array Marshal.Copy( (IntPtr)ptr, aRGBValues, 0, iBytes ); // Set every third value to 255, a 24bpp image will look red // Must pin object on heap so that it doesn't move while using pointers fixed ( byte* p = &aRGBValues[2] ) { // aRGBValues[2] = First red color value // p is pinned as well as object, so create another pointer to increment it for ( byte* p2 = p; p2 < p + aRGBValues.Length; p2 += 3 ) *p2 = 255; } // Copy the RGB values back to the bitmap Marshal.Copy( aRGBValues, 0, (IntPtr)ptr, iBytes ); // Unlock the bits bmp.UnlockBits( bmpData ); // Create GDI bitmap IntPtr hBitmap = bmp.GetHbitmap(); // Return GDI bitmap return hBitmap; } } PerformanceIt makes no sense to performance test the three examples above because the test image is a small image and the image manipulation is simple and can be performed in a very tight fast loop. They'll pretty much all three be equally fast. 7z-fileNew 7z-file at bottom of first post.2 points
-
CodeCrypter enables you to encrypt scripts without placing the key inside the script. This is because this key is extracted from the user environment at runtime by, for example: password user query any macro (e.g., @username) any AutoIt function call any UDF call some permanent environment variable on a specific machine (and not created by your script) a server response a device response anything else you can think of, as long as it's not stored in the script any combination of the above You need several scripts to get this to work, and they are scattered over several threads, so here's a single bundle that contains them all (including a patched version of Ward's AES.au3; with many thanks to Ward for allowing me to include this script here): Latest version: 3.4 (3 Dec 2021): please follow this link. Note: if you experience issues under Win8/8.1 (as some users have reported), please upgrade to Win10 (or use Win7) if you can; as far as I can tell, the scripts in the bundle all work under Win7 & Win10 (and XP). Moreover, I have no access to a Win8 box, so these issues will not be fixed, at least not by yours truly. How the bits and pieces fit together: CodeCrypter is a front-end for the MCF UDF library (you need version 1.3 or later). Its thread is here: '?do=embed' frameborder='0' data-embedContent>> The MCF package (also contained in the CodeScannerCrypter bundle) contains MCF.au3 (the library itself) plus a little include file called MCFinclude.au3. The latter you have to include in any script you wish to encrypt. Any code preceding it will not be encrypted, any code following it will be encrypted. You define the dynamic key inside MCFinclude.au3, in the UDF: _MCFCC_Init(). From the same post you can download an MCF Tutorial which I heartily recommend, because encrypting a script requires a number of steps in the right order, namely: In MCFinclude.au3, define and/or choose your dynamic key(s) (skip this step = use default setting) include MCFinclude.au3 in your target script Run CodeScanner (version 2.3+) on your target script, with setting WriteMetaCode=True (see '?do=embed' frameborder='0' data-embedContent>>), then close CodeScanner. Start CodeCrypter press the Source button to load your target file enable Write MCF0 (tick the first option in Main Settings) Enable "Encrypt" (last option in the Main Settings) Go to the Tab Encrypt and set up the encryption the way you want (skip this = use default settings) Return to Main Tab and press "Run" if all goes well, a new script called MCF0test.au3 is created in the same directory as your target. It has no includes and no redundant parts. Please check that it works as normal. (see Remarks if not) It all sounds far more complicated than it is, really. Not convinced? Check out: a simple HowTo Guide: HowToCodeCrypt.pdf an updated and extended Q & A pdf (FAQ, also included in the bundle) to help you get started:CodeCrypterFAQ.pdf For additional explanations/examples in response to specific questions by forum members (how it works, what it can/cannot do), see elsewhere in this thread, notably: Simple analogy of how it works: post #53, second part General Explanation and HowTo: post #9, 51, 75, 185/187, 196, 207, 270, 280 (this gets a bit repetitive) BackTranslation: post #179 Obfuscation: post #36 (general), 49 (selective obfuscation) Specific features and fixes: post #3 (security), 84 (redefining the expected runtime response), 169 (Curl Enum fix), 185/187 (using license keys), 194 (replacing Ward's AES UDF with different encryption/decryption calls), 251 (AV detection issue), 262 (extract key contents to USB on different target machine prior to encryption) Limitations: post #26 (@error/@extended), 149 (FileInstall), 191 (AES.au3 on x64) Not recommended: post #46/249 (static encryption), 102 (programme logic error), 237 (parsing password via cmdline) Technical notes: BackTranslation is a test to check that the MetaCode translation worked. Skip it at your peril. It also turns your multi-include composite script into a single portable file without redundant parts (you can opt to leave the redundant parts in, if you want). CodeCrypter can also obfuscate (vars and UDF names) and replace strings, variable names and UDF names with anything else you provide, for example, for language translation). After CodeScanner separates your target's structure from its contents, CodeCrypter (actually MCF, under the hood) can change any part, and then generate a new script from whichever pieces you define. See the MCF Tutorial for more explanation and examples. Encryption currently relies on Ward's excellent AES UDF and TheXman's sophisticated CryptoNG bundle. You can replace these with any other algorithm you like (but this is not trivial to do: edit MCFinclude.au3 UDF _MCFCC(), and MCF.au3 UDF _EncryptEntry(), see post #194 in this thread). AES by Ward, and CryptoNG by TheXman are also included in the bundle (with many thanks to Ward and TheXman for graciously allowing me to republish their outstanding work). Going to lie down now... RT1 point
-
GuiFlatButton UDF : Change Colors of Regular Buttons
mumpel reacted to kurtykurtyboy for a topic
GuiFlatButton is a UDF to easily create regular buttons with different colors for background, foreground, border, hover, focus, etc.. This started as an effort to change the background color of a button and eventually grew into a full UDF. If you've looked around forums for changing button background colors, you have probably noticed that each proposed workaround has its own set of issues/side-effects. The answers usually circle back to 'use ownerdrawn buttons' and 'not worth it'. Well, now it is possible for anyone to easily create ownerdrawn buttons - totally worth it! Some issues with other workarounds such as drawing with GDI+ or using a colored label as a 'button': Not 'real' buttons so you lose built-in functionality that windows gives to buttons Messy / inefficient code in the main while loop to check for mouse position Slow to respond to click, paint, etc... Having to deal with GUIRegisterMsg messages Not straight-forward to implement GuiFlatButton is not a workaround; it is a technique to respond to Windows' built-in owner-drawn button events. With minimal effort, we can now create true simple colored buttons. The idea is to create an owner-drawn button using GUICtrlCreateButton then subclass the GUI and controls to handle the button-specific events to paint it however we want. This UDF magically does all of this for us! No need to worry about event handling or main while loop logic. How to use It couldn't be any easier! Simply create a new button using the familiar syntax. This creates an ownerdrawn button with default colors. $mybutton1 = GuiFlatButton_Create("Button 1", 78, 20, 120, 40) If you want to change the background and text colors: GuiFlatButton_SetBkColor(-1, 0x5555FF) GuiFlatButton_SetColor(-1, 0xFFFFFF) Advanced Usage Set background/text/border all at once GuiFlatButton_SetColors(-1, 0x0000FF, 0xFFFFFF, 0x9999FF) Set ALL colors for ALL button states! (normal, focus, hover, selected) Local $aColorsEx = [0x0000FF, 0xFFFFFF, -2, 0x4444FF, 0xFFFFFF, 0xAAAAFF, 0x6666FF, 0xFFFFFF, 0xCCCCFF, 0x0000EE, 0xFFFFFF, 0x7777EE] GuiFlatButton_SetColorsEx(-1, $aColorsEx) Set default colors to apply to any future buttons ;set colors GuiFlatButton_SetDefaultColors(0x0000FF, 0xFFFFFF, 0x9999FF) ;create buttons $mybutton1 = GuiFlatButton_Create("Button 1", 12, 20, 120, 40) $mybutton2 = GuiFlatButton_Create("Button 2", 143, 20, 120, 40) Set ALL color defaults ;set colors Local $aColorsEx = [0x0000FF, 0xFFFFFF, -2, 0x4444FF, 0xFFFFFF, 0xAAAAFF, 0x6666FF, 0xFFFFFF, 0xCCCCFF, 0x0000EE, 0xFFFFFF, 0x7777EE] GuiFlatButton_SetDefaultColorsEx($aColorsEx) ;create buttons $mybutton1 = GuiFlatButton_Create("Button 1", 12, 20, 120, 40) $mybutton2 = GuiFlatButton_Create("Button 2", 143, 20, 120, 40) Available Functions Simple Example #include <GUIConstantsEx.au3> #include <MsgBoxConstants.au3> #include "GuiFlatButton.au3" Example() ;GUI with one button Func Example() Local $hGUI, $mybutton1 $hGUI = GUICreate("GuiFlatButton Ex0", 275, 120) GUISetBkColor(0x333333) Local $idLabel = GUICtrlCreateLabel("Click the button", 10, 100, 150, 30) GUICtrlSetColor(-1, 0xFFFFFF) ;create new button then set the background and foreground colors $mybutton1 = GuiFlatButton_Create("Button 1" & @CRLF & "Line 2", 78, 20, 120, 40, $BS_MULTILINE) GuiFlatButton_SetBkColor(-1, 0x5555FF) GuiFlatButton_SetColor(-1, 0xFFFFFF) GUISetState(@SW_SHOW, $hGUI) Local $i = 0 Local $iMsg While 1 $iMsg = GUIGetMsg() Switch $iMsg Case $GUI_EVENT_CLOSE ExitLoop Case $mybutton1 $i += 1 GUICtrlSetData($idLabel, $i) ConsoleWrite($i & @CRLF) EndSwitch Sleep(10) WEnd GUIDelete() EndFunc ;==>Example Menu/Toolbar Example #include <GUIConstantsEx.au3> #include <MsgBoxConstants.au3> #include "GuiFlatButton.au3" Example() ;Example GUI with toolbar Func Example() Local $hGUI, $idLabel, $aButtons, $iTbSize $hGUI = GUICreate("GuiFlatButton Ex2", 300, 200) GUISetBkColor(0x444444) $idLabel = GUICtrlCreateLabel("Click a button", 10, 180, 150, 30) GUICtrlSetColor(-1, 0xFFFFFF) $aButtons = createToolbar() $iTbSize = UBound($aButtons) GUISetState(@SW_SHOW, $hGUI) Local $i = 0 Local $iMsg While 1 $iMsg = GUIGetMsg() Switch $iMsg Case $GUI_EVENT_CLOSE ExitLoop Case $aButtons[0] To $aButtons[$iTbSize - 1] ConsoleWrite("1") GUICtrlSetData($idLabel, GuiFlatButton_Read($iMsg)) EndSwitch Sleep(10) WEnd GUIDelete() EndFunc ;==>Example Func createToolbar() Local $aButtons[6] Local $bkColor = 0x777777 Local $textColor = 0xFFFFFF Local $borderColor = 0x999999 Local $aBtnClrs[12] = [0x777777, 0xFFFFFF, $GUI_BKCOLOR_TRANSPARENT, 0x888888, 0xFFFFFF, $GUI_BKCOLOR_TRANSPARENT, 0x999999, 0xFFFFFF, $GUI_BKCOLOR_TRANSPARENT, 0x666666, 0xFFFFFF, $GUI_BKCOLOR_TRANSPARENT] For $i = 0 To UBound($aButtons) - 1 $aButtons[$i] = GuiFlatButton_Create("B" & $i, $i * 50, 0, 50, 17) GuiFlatButton_SetColorsEx($aButtons[$i], $aBtnClrs) Next Return $aButtons EndFunc ;==>createToolbar Icon Example You can even easily add icons to your buttons -- just create a new button and send it an icon! #include <GDIPlus.au3> #include "GuiFlatButton.au3" Example() ;buttons with Icon images Func Example() ;get images for demonstration _GDIPlus_Startup() ;initialize GDI+ Local $hIcon = _WinAPI_ShellExtractIcon(@SystemDir & '\shell32.dll', 258, 24, 24) ;extract the 'Save' icon Local $hBitmap = _GDIPlus_BitmapCreateFromHICON($hIcon) ;Create Bitmap from Icon (for demonstration) Local $hHBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap) ;Create HBitmap from Bitmap _GDIPlus_BitmapDispose($hBitmap) ;dispose the bitmap _GDIPlus_Shutdown() ;done with GDI+ Local $hGUI = GUICreate("GuiFlatButton Ex5", 255, 400) GUISetBkColor(0xEEEEEE) ;set default colors of future buttons Local $aColorsEx = _ [0xE2E5E8, 0X000000, 0x888888, _ ; normal : Background, Text, Border 0xE2E5E8, 0X000000, 0x333333, _ ; focus : Background, Text, Border 0xE8E8E8, 0X000000, 0x666666, _ ; hover : Background, Text, Border 0xDDDDDD, 0X000000, 0xAAAAAA] ; selected : Background, Text, Border GuiFlatButton_SetDefaultColorsEx($aColorsEx) ;normal button with icon $label1 = GUICtrlCreateLabel( "$BS_TOOLBUTTON -->", 5, 10) GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT) Local $mybutton1 = GuiFlatButton_Create("Save", 130, 5, 50, 48, $BS_TOOLBUTTON) _WinAPI_DeleteObject(_SendMessage(GUICtrlGetHandle($mybutton1), $BM_SETIMAGE, $IMAGE_ICON, $hIcon)) ;align top Local $mybuttonT = GuiFlatButton_Create("Top", 5, 65, 120, 55, $BS_TOP) _WinAPI_DeleteObject(_SendMessage(GUICtrlGetHandle($mybuttonT), $BM_SETIMAGE, $IMAGE_ICON, $hIcon)) ;align top-left Local $mybuttonTL = GuiFlatButton_Create("Top-Left", 5, 125, 120, 55, BITOR($BS_TOP, $BS_LEFT)) _WinAPI_DeleteObject(_SendMessage(GUICtrlGetHandle($mybuttonTL), $BM_SETIMAGE, $IMAGE_ICON, $hIcon)) ;align top-right Local $mybuttonTR = GuiFlatButton_Create("Top-Right", 5, 185, 120, 55, BITOR($BS_TOP, $BS_RIGHT)) _WinAPI_DeleteObject(_SendMessage(GUICtrlGetHandle($mybuttonTR), $BM_SETIMAGE, $IMAGE_ICON, $hIcon)) ;align left Local $mybuttonL = GuiFlatButton_Create("Left", 5, 245, 120, 55, $BS_LEFT) _WinAPI_DeleteObject(_SendMessage(GUICtrlGetHandle($mybuttonL), $BM_SETIMAGE, $IMAGE_ICON, $hIcon)) ;align bottom Local $mybuttonB = GuiFlatButton_Create("Bottom", 130, 65, 120, 55, $BS_BOTTOM) _WinAPI_DeleteObject(_SendMessage(GUICtrlGetHandle($mybuttonB), $BM_SETIMAGE, $IMAGE_ICON, $hIcon)) ;align bottom-left Local $mybuttonBL = GuiFlatButton_Create("Bottom-Left", 130, 125, 120, 55, BITOR($BS_BOTTOM, $BS_LEFT)) _WinAPI_DeleteObject(_SendMessage(GUICtrlGetHandle($mybuttonBL), $BM_SETIMAGE, $IMAGE_ICON, $hIcon)) ;align bottom-right Local $mybuttonBR = GuiFlatButton_Create("Bottom-Right", 130, 185, 120, 55, BITOR($BS_BOTTOM, $BS_RIGHT)) _WinAPI_DeleteObject(_SendMessage(GUICtrlGetHandle($mybuttonBR), $BM_SETIMAGE, $IMAGE_ICON, $hIcon)) ;align right Local $mybuttonR = GuiFlatButton_Create("Right", 130, 245, 120, 55, $BS_RIGHT) _WinAPI_DeleteObject(_SendMessage(GUICtrlGetHandle($mybuttonR), $BM_SETIMAGE, $IMAGE_ICON, $hIcon)) GuiFlatButton_SetState($mybuttonR, $GUI_DISABLE ) ;disabled Local $mybuttonDisable = GuiFlatButton_Create("Disabled", 130, 310, 120, 55, $BS_TOOLBUTTON) _WinAPI_DeleteObject(_SendMessage(GUICtrlGetHandle($mybuttonDisable), $BM_SETIMAGE, $IMAGE_BITMAP, $hHBitmap)) GuiFlatButton_SetState($mybuttonDisable, $GUI_DISABLE ) ;clean up! _WinAPI_DestroyIcon( $hIcon ) _WinAPI_DeleteObject( $hHBitmap ) GUISetState(@SW_SHOW, $hGUI) Local $iMsg While 1 $iMsg = GUIGetMsg() Switch $iMsg Case $GUI_EVENT_CLOSE ExitLoop EndSwitch Sleep(10) WEnd GUIDelete() EndFunc ;==>Example I'm sure there are some use-cases I've forgotten, so feedback is welcome! Download the latest UDF and several more examples: GuiFlatButton_20220919.zip (1,121) Update 2022-09-19 Added update from 05/25 back in after it was accidentally removed Update 2022-09-01 Added $BS_MULTILINE button style Added ellipses when text is longer than the button Fixed compatibility with Opt("MustDeclareVars", 1) Update 2022-05-25 Fixed issue, buttons disappear when a GUI containing a child window with WS_EX_MDICHILD extended style is moved Update 2022-05-24 Fixed issue releasing subclassing when GUI is deleted but program is not closed Fixed occasional white background flicker Added function GuiFlatButton_GetPos Update 2021-01-02 Fixed bug, not drawing correctly after deleting GUI with GUIDelete() Fixed bug, changing default colors changed all buttons, even previously created buttons Made some internal functions more efficient Update 2019-04-14 Fixed bug, not showing pressed down state when clicking rapidly Added Icon/Bitmap support! Added function GuiFlatButton_SetPos to change the position and/or size of a button Update 2019-02-09 Added 2 new functions to set the button colors globally for all future buttons. GuiFlatButton_SetDefaultColors GuiFlatButton_SetDefaultColorsEx Credits to: Melba23 (UDF template) LarsJ (general subclassing code) 4ggr35510n (TrackMouseEvent example) binhnx (disable dragging with $WS_EX_CONTROLPARENT) GUIRegisterMsg in AutoIt Help (owner-draw button example) funkey (_WinAPI_DrawState example)1 point -
Hi all, Just wanted to verify something from the documentation for ProcessExists(). It notes that The process is polled approximately every 250 milliseconds. Does this mean it can take up to 250ms for the function to realize a process exists or no longer exists? If so, does this limitation affect ProcessList() as well? EDIT: In terms of how often the process list it checks against is updated, not the function execution time Thanks in advance!1 point
-
... and one year later the mirage line still exists in the helpfile1 point
-
The documentation is obviously incorrect. It is only polled once per statement. You can find out for yourself how long it takes by writing a simple test script. On my PC it is 7ms regardless of whether notepad is active or not. $start = TimerInit() For $i = 1 To 1000 $x = ProcessExists("notepad.exe") Next ConsoleWrite("Per iteration = " & TimerDiff($start) / 1000 & " ms")1 point
-
Couple of ways you could just create a shortcut and pin it to the taskbar, you can use different profiles to load a seperate instance for example, this would use the default profile: Note: if you want a different icon (for example I used Google icon) you'll have to download it and place it in a common area. FileCreateShortcut(@ProgramFilesDir & "\Microsoft\Edge\Application\msedge.exe", @DesktopDir & "\Google Shortcut.lnk", @ProgramFilesDir & "\Microsoft\Edge\Application", "--profile-directory=Default http://www.google.com", "", @ScriptDir & "\favicon.ico") Alternatively you coud just create a script using Run to open Edge and create your own custom icon. Run('"' & @ProgramFilesDir & '\Microsoft\Edge\Application\msedge.exe" --profile-directory=Default http://www.google.com')1 point
-
Hi, Give you some solution for tab control from me. FlatTab.au3 #include-once #include <GDIPlus.au3> #include <Array.au3> #include "GUICtrlOnHover.au3" Global $FlatUIColor = DllStructCreate("struct;float back;float fore;float frame;endstruct;") $FlatUIColor.back = 0x3C4649 $FlatUIColor.fore = 0x23A86D ;0x3498db $FlatUIColor.frame = 0x2D2F31 Global Const $tObjTabEx = "hwnd hwnd;byte ctrl;byte ctab;" & _ "byte count;byte current;int next;" & _ "int width;int x;int y;" Global Const $tObjTabBtnEx = "byte ctrl;byte ctab;byte idtab;" & _ "wchar text[255];" Global $____aTabList[1] = [0] Global $____aTabBtnList[1] = [0] Func FlatTab_Create($hWnd, $Left, $Top, $Width, $Height) GUISwitch($hWnd) Local $oObj = DllStructCreate($tObjTabEx) _ArrayAdd($____aTabList, $oObj) $____aTabList[0] += 1 $oObj.hwnd = $hWnd $oObj.ctrl = GUICtrlCreatePic("", $Left, $Top+25, $Width, $Height-50) GUICtrlSetResizing($oObj.ctrl, 802) GUICtrlSetState($oObj.ctrl, 128) $oObj.ctab = GUICtrlCreateTab(-99, -99, 1, 1) GUICtrlSetState($oObj.ctab, 128) Local $aBmp = _GDIPlus_BitmapCreateFromScan0($Width, $Height-50) Local $hGfx = _GDIPlus_ImageGetGraphicsContext($aBmp) Local $hPen = _GDIPlus_PenCreate($FlatUIColor.frame+0xFF000000, 4) Local $hBrush = _GDIPlus_BrushCreateSolid($FlatUIColor.frame+0xFF000000) _GDIPlus_GraphicsDrawRect($hGfx, 0, 0, $Width, $Height-50, $hPen) _GDIPlus_GraphicsFillRect($hGfx, 0, 0, $Width, $Height-50, $hBrush) _GDIPlus_GraphicsClear($hGfx, $FlatUIColor.frame+0xFF000000) Local $hBmp = _GDIPlus_BitmapCreateDIBFromBitmap($aBmp) _GDIPlus_BitmapDispose($aBmp) _GDIPlus_GraphicsDispose($hGfx) _GDIPlus_PenDispose($hPen) _WinAPI_DeleteObject(GUICtrlSendMsg($oObj.ctrl, 0x0172, 0, $hBmp)) _WinAPI_DeleteObject($hBmp) $oObj.width = $Width $oObj.x = $Left $oObj.y = $Top $oObj.current = "" $oObj.count = 0 $oObj.next = $Left Return $oObj EndFunc Func FlatTab_AddTab($Ctrl, $Text) GUISwitch($Ctrl.hwnd) GUICtrlCreateTabItem("") Local $oObj = DllStructCreate($tObjTabBtnEx) _ArrayAdd($____aTabBtnList, $oObj) $____aTabBtnList[0] += 1 $oObj.ctrl = GUICtrlCreatePic("", $Ctrl.next, $Ctrl.y, 80, 25) GUICtrlSetResizing($oObj.ctrl, 802) _GUICtrl_OnHoverRegister($oObj.ctrl, 'FlatTab_EventHover', 'FlatTab_EventHover', 'FlatTab_EventClick', 'FlatTab_EventClick') $oObj.count +=1 $oObj.idtab = GUICtrlCreateTabItem($oObj.count) $oObj.text = $Text If $Ctrl.current <> "" Then Local $Prev = FlatTab_GetObjTabBtnFromCtrl($Ctrl.current) FlatTab_Draw($Prev.ctrl, $Prev.text, 0xFFFFFFFF, $FlatUIColor.fore+0xFF000000) EndIf FlatTab_Draw($oObj.ctrl, $Text, 0xFFFFFFFF, $FlatUIColor.frame+0xFF000000) $Ctrl.current = $oObj.ctrl $oObj.ctab = $Ctrl.ctab $Ctrl.next += 80 GUICtrlSetState($oObj.idtab, 16) Return $oObj.idtab EndFunc Func FlatTab_EventHover($Ctrl, $Mode) Local $Obj1 = FlatTab_GetObjTabFromCtrl($Ctrl) If $Obj1.current = $Ctrl Then Return Local $Obj2 = FlatTab_GetObjTabBtnFromCtrl($Ctrl) Switch $Mode Case 1 FlatTab_Draw($Ctrl, $Obj2.text, 0xFFFFFFFF, $FlatUIColor.fore+0xFF151515) Case 2 FlatTab_Draw($Ctrl, $Obj2.text, 0xFFFFFFFF, $FlatUIColor.fore+0xFF000000) EndSwitch EndFunc Func FlatTab_EventClick($Ctrl, $Mode) If $Mode = 2 Then Local $Obj1 = FlatTab_GetObjTabFromCtrl($Ctrl) If $Obj1.current = $Ctrl Then Return Local $Obj2 = FlatTab_GetObjTabBtnFromCtrl($Ctrl) Local $Obj3 = FlatTab_GetObjTabBtnFromCtrl($Obj1.current) FlatTab_Draw($Ctrl, $Obj2.text, 0xFFFFFFFF, $FlatUIColor.frame+0xFF000000) FlatTab_Draw($Obj3.ctrl, $Obj3.text, 0xFFFFFFFF, $FlatUIColor.fore+0xFF000000) GUICtrlSetState($Obj2.idtab, 16) $Obj1.current = $Ctrl EndIf EndFunc Func FlatTab_GetObjTabFromCtrl($Ctrl) Local $Obj2, $Index Local $Obj = FlatTab_GetObjTabBtnFromCtrl($Ctrl) If $____aTabList[0] = 0 Then Return False For $Index = $____aTabList[0] To 1 Step -1 $Obj2 = $____aTabList[$Index] If $Obj2.ctab == $Obj.ctab Then Return $____aTabList[$Index] Next Return False EndFunc Func FlatTab_GetObjTabBtnFromCtrl($Ctrl) Local $Obj, $Index If $____aTabBtnList[0] = 0 Then Return False For $Index = $____aTabBtnList[0] To 1 Step -1 $Obj = $____aTabBtnList[$Index] If $Obj.ctrl == $Ctrl Then Return $____aTabBtnList[$Index] Next Return False EndFunc Func FlatTab_Draw($iCtrl, $Text, $Color = 0xFFFFFFFF, $BgColor = 0x00FFFFFF) Local $hWnd = _WinAPI_GetParent(GUICtrlGetHandle($iCtrl)) Local $aPos = ControlGetPos($hWnd, "", $iCtrl) Local $hFormat = _GDIPlus_StringFormatCreate() Local $hFamily = _GDIPlus_FontFamilyCreate("Segoe UI Semibold") Local $hFont = _GDIPlus_FontCreate($hFamily, 10, 0) Local $tLayout = _GDIPlus_RectFCreate(0, 0, $aPos[2], $aPos[3]) _GDIPlus_StringFormatSetAlign($hFormat, 1) _GDIPlus_StringFormatSetLineAlign($hFormat, 1) Local $aBitmaps = _GDIPlus_BitmapCreateFromScan0($aPos[2], $aPos[3]) Local $aGfxCtxt = _GDIPlus_ImageGetGraphicsContext($aBitmaps) _GDIPlus_GraphicsSetSmoothingMode($aGfxCtxt, 2) _GDIPlus_GraphicsSetTextRenderingHint($aGfxCtxt, 5) _GDIPlus_GraphicsClear($aGfxCtxt, $BgColor) Local $hBrushColor = _GDIPlus_BrushCreateSolid($Color) _GDIPlus_GraphicsDrawStringEx($aGfxCtxt, $Text, $hFont, $tLayout, $hFormat, $hBrushColor) Local $aHBitmaps = _GDIPlus_BitmapCreateDIBFromBitmap($aBitmaps) _GDIPlus_BrushDispose($hBrushColor) _GDIPlus_FontDispose($hFont) _GDIPlus_BitmapDispose($aBitmaps) _GDIPlus_GraphicsDispose($aGfxCtxt) _GDIPlus_FontFamilyDispose($hFamily) _GDIPlus_StringFormatDispose($hFormat) _WinAPI_DeleteObject(GUICtrlSendMsg($iCtrl, 0x0172, 0, $aHBitmaps)) _WinAPI_DeleteObject($aHBitmaps) EndFunc FlatTab_Example.au3 #include "FlatTabEx.au3" #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> _GDIPlus_Startup(); Global $hGUI = GUICreate("FlatTab Example", 450, 290); GUISetBkColor(0x3C4649, $hGUI); GUISetFont(10, 400, 0, "Segoe UI", $hGUI, 5); Global $Tab = FlatTab_Create($hGUI, 10, 10, 430, 290); ;================================================= FlatTab_AddTab($Tab, "Tab 1"); GUICtrlCreateLabel("This is Tab 1", 30, 50); GUICtrlSetColor(-1, 0xFFFFFF); GUICtrlCreateButton("Button 1", 30, 100, 75, 25); GUICtrlCreateButton("Button 2", 120, 100, 75, 25); ;================================================= FlatTab_AddTab($Tab, "Tab 2"); GUICtrlCreateLabel("This is Tab 2", 30, 50); GUICtrlSetColor(-1, 0xFFFFFF); GUICtrlCreateButton("Button 3", 210, 100, 75, 25); GUICtrlCreateButton("Button 4", 30, 150, 75, 25); ;================================================= FlatTab_AddTab($Tab, "Tab 3"); GUICtrlCreateLabel("This is Tab 3", 30, 50); GUICtrlSetColor(-1, 0xFFFFFF); GUICtrlCreateButton("Button 5", 120, 150, 75, 25); GUICtrlCreateButton("Button 6", 210, 150, 75, 25); ;================================================= GUICtrlCreateTabItem(""); GUISetState(); Do Sleep(10); Until GUIGetMsg() = -3;1 point
-
Skysnake, You need to remove the $WS_HSCROLL style from the control styles - the $ES_AUTOHSCROLL merely allows the control to automatically scroll as you type. This is why the final snippet works and the others do not, as you only remove the correct style in that final one - in the first 2 the edit control is created with the $WS_HSCROLL as a default style as explained in the Help file. This works for me: #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <EditConstants.au3> $hGUI = GUICreate("Test", 500, 500) ; Create edit without the $WS_HSCROLL style $cEdit = GUICtrlCreateEdit("", 10, 10, 200, 200, Bitor($ES_WANTRETURN, $WS_VSCROLL, $ES_AUTOVSCROLL)) GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd M231 point
-
To fix the Title issue I went ahead and made this change to script... MetroGUI_UDF.au3 Under This: If $AllowResize Then DllCall("uxtheme.dll", "none", "SetThemeAppProperties", "int", 0) ;Adds compatibility for Windows 7 Basic theme $GUI_Return = GUICreate($Title, $Width, $Height, $Left, $Top, BitOR($WS_SIZEBOX, $WS_MINIMIZEBOX, $WS_MAXIMIZEBOX), -1, $ParentGUI) _Metro_SetGUIOption($GUI_Return, True, True, $Width, $Height) DllCall("uxtheme.dll", "none", "SetThemeAppProperties", "int", BitOR(1, 2, 4)) Else DllCall("uxtheme.dll", "none", "SetThemeAppProperties", "int", 0) ;Adds compatibility for Windows 7 Basic theme $GUI_Return = GUICreate($Title, $Width, $Height, $Left, $Top, -1, -1, $ParentGUI) _Metro_SetGUIOption($GUI_Return, False, False, $Width, $Height) DllCall("uxtheme.dll", "none", "SetThemeAppProperties", "int", BitOR(1, 2, 4)) EndIf Add this: GUICtrlCreateLabel($Title, 54, 7) GUICtrlSetColor(-1, $FontThemeColor) GUICtrlSetFont(-1, 8.5, 400, 0, "Arial", 5) Hope this helps someone until the UDF is updated with something better.1 point
-
A UDF with Extended Functions for Window Management Notes: Fixes WinGetClassList's barbaric returning of a @LF separated string instead of an array. Potential Uses: Automating applications that change their controls' handles/classes on each launch (e.g. half of Cisco's programs) Functions: _WinGetClassList _WinGetClassNNList _WindowGetHandleList _WindowGetHandleListFromPos Download: WindowEx.zip (v0.4) Changelog: 10/04/2016 (v0.4): _WinGetClassNNList Fixed : Not Returning an Index when using $2D_ARRAY _WinGetClassNNList Fixed : Not Properly returning $aArray[x][1] on Classes with instances > 9 when using $2D_ARRAY 10/03/2016 (v0.3): _WinGetClassList Added : Exactly the same as WinGetClassList but returns a more civilized Array _WinGetClassNNList Added : Returns Classes and their instances in either a 1D or 2D array depending on Flags _WindowGetHandleList Renamed: _WinGetHandleList SCRIPT BREAKING! _WindowGetHandleListFromPos Renamed: _WinGetHandleListFromPos SCRIPT BREAKING! 10/01/2016 (v0.2): WindowsExConstants.au3 Added : Flags in _WindowGetHandleListFromPos _WindowGetHandleListFromPos Removed: ConsoleWrite left in during debug _WindowGetHandleListFromPos Added : Flag for if part of a Control is at $X, $Y return it as well. 10/01/2016 (v0.1): _WindowGetHandleList Added : Retrieves the handles of classes from a window. _WindowGetHandleListFromPos Added : Retrieves the handles of classes at a specific position from a window. Known and Reported Bugs: None reported To Do: To Be Decided. Opinions welcome! Upcoming Changes: To Be Decided.1 point
-
ManneMoses, Sure: #include <GUIConstantsEx.au3> #include <MsgBoxConstants.au3> $iState = 1 $hGUI = GUICreate("Test", 500, 500) $cButton = GUICtrlCreateButton("Press Me!", 10, 10, 80, 30) GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $cButton Switch $iState Case 1 MsgBox($MB_SYSTEMMODAL, "Pressed", "State = 1") $iState = 2 Case Else MsgBox($MB_SYSTEMMODAL, "Pressed", "State = 2") $iState = 1 EndSwitch EndSwitch WEndM23 P.S. When you reply, please use the "Reply to this topic" button at the top of the thread or the "Reply to this topic" editor at the bottom rather than the "Quote" button - I know what I wrote and it just pads the thread unnecessarily.1 point
-
ManneMoses, One way of doing it: #include <GUIConstantsEx.au3> #include <MsgBoxConstants.au3> $hGUI = GUICreate("Test", 500, 500) $cButton = GUICtrlCreateButton("State 1", 10, 10, 80, 30) GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $cButton Switch GUICtrlRead($cButton) Case "State 1" MsgBox($MB_SYSTEMMODAL, "Pressed", "State = 1") GUICtrlSetData($cButton, "State 2") Case Else MsgBox($MB_SYSTEMMODAL, "Pressed", "State = 2") GUICtrlSetData($cButton, "State 1") EndSwitch EndSwitch WEndPlease ask if you have any questions. M231 point
-
$b1 = StringToBinary('JScript') $b2 = StringToBinary(' - Joao Carlos.') $b3 = $b1 + $b2 ConsoleWrite($b1 & @CR) ConsoleWrite($b2 & @CR) ConsoleWrite($b3 & @CR) ConsoleWrite(BinaryToString($b3) & @CR)1 point