Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 12/16/2014 in all areas

  1. trancexx

    MailSlot

    This way of communication between processes very much resemble to the communication we do with our mail accounts. I would guess (smartly, no doubt) that was the key factor used for naming the functions when they were created. Information about mailslots can be found on microsoft's site, link. Summary could be that datagrams are used for communication and it's one-way and asynchronous. Attached zip file contains MailSlot.au3, AutoIt's implementation of these functions. Also there would be two scripts in there MailSlot_Sender.au3 and MailSlot_Reciever.au3. Both scripts are demos of the mailslot mechanism. Start both and use former to send mails to latter. Examples are basic and should show what's this about. MailSlot.zip Available functions are alphabetically: _MailSlotCheckForNextMessage_MailSlotClose_MailSlotCreate_MailSlotGetMessageCount_MailSlotGetTimeout_MailSlotSetTimeout_MailSlotRead_MailSlotWriteedit: New attachment. _MailSlotGetTimeout() function added to MailSlot.au3.
    1 point
  2. mesale0077 asked me whether I could code some CSS loading animations from different web sites. These are the results using GDI+ (AutoIt v3.3.12.0+ required!): _GDIPlus_MonochromaticBlinker.au3 / _GDIPlus_RotatingBokeh.au3 _GDIPlus_SpinningCandy.au3 / _GDIPlus_SteamPunkLoading.au3 _GDIPlus_IncreasingBalls.au3 / _GDIPlus_PacmanProgressbar.au3 _GDIPlus_StripProgressbar.au3 / _GDIPlus_RingProgressbar.au3 _GDIPlus_LineProgressbar.au3 / _GDIPlus_SimpleLoadingAnim.au3 _GDIPlus_TextFillingWithWater.au3 / _GDIPlus_MultiColorLoader.au3 _GDIPlus_LoadingSpinner.au3 / _GDIPlus_SpinningAndPulsing.au3 _GDIPlus_TogglingSphere.au3 / _GDIPlus_CloudySpiral.au3 _GDIPlus_GlowingText.au3 (thanks to Eukalyptus) / _GDIPlus_HypnoticLoader.au3 _GDIPlus_RotatingRectangles.au3 / _GDIPlus_TRONSpinner.au3 _GDIPlus_RotatingBars.au3 / _GDIPlus_AnotherText.au3 (thanks to Eukalyptus) _GDIPlus_CogWheels.au3 (thanks to Eukalyptus) / _GDIPlus_DrawingText.au3 (thanks to Eukalyptus) _GDIPlus_GearsAnim.au3 / _GDIPlus_LEDAnim.au3 _GDIPlus_LoadingTextAnim.au3 / _GDIPlus_MovingRectangles.au3 _GDIPlus_SpinningAndGlowing.au3 (thanks to Eukalyptus) / _GDIPlus_YetAnotherLoadingAnim.au3 _GDIPlus_AnimatedTypeLoader.au3 / _GDIPlus_Carousel.au3 Each animation function has a built-in example how it can be used. AiO download: GDI+ Animated Wait Loading Screens.7z (previous downloads: 1757) Big thanks to Eukalyptus for providing several examples. Maybe useful for some of you Br, UEZ PS: I don't understand CSS - everything is made out of my mind, so it might be different from original CSS examples
    1 point
  3. Zedna

    Resources UDF

    Link to pages with general resources description MSDN - Resources OverView & Reference You can embed any binary data into your AutoIt compiled EXE files in it's resources at compile time. As opposite to FileInstall() with resources you can use your embedded data directly without any temporary files on disk. If you wish you can save resources to disk with _ResourceSaveToFile() however. Adding data to resources can be done simply by AutoIt3Wrapper directive: #AutoIt3Wrapper_Res_File_Add=FileName, ResType, ResName As data can be used for example images,cursors,texts,sounds,videos,binary files etc. For loading/using data from resources at run time I made this tiny helper Resources UDF. Functions inside UDF: _ResourceGet($ResName, $ResType = $RT_RCDATA, $ResLang = 0, $DLL = -1) _ResourceGetAsString($ResName, $ResType = $RT_RCDATA, $ResLang = 0, $DLL = -1) _ResourceGetAsStringW($ResName, $ResType = $RT_RCDATA, $ResLang = 0, $DLL = -1) _ResourceGetAsBytes($ResName, $ResType = $RT_RCDATA, $ResLang = 0, $DLL = -1) _ResourceGetAsImage($ResName, $ResType = $RT_RCDATA, $DLL = -1) _ResourceGetAsBitmap($ResName, $ResType = $RT_RCDATA, $DLL = -1) _ResourceSaveToFile($FileName, $ResName, $ResType = $RT_RCDATA, $ResLang = 0, $CreatePath = 0, $DLL = -1) _ResourceSetImageToCtrl($CtrlId, $ResName, $ResType = $RT_RCDATA, $DLL = -1) _SetBitmapToCtrl($CtrlId, $hBitmap) _ResourcePlaySound($ResName, $Flag = 0, $DLL = -1) Notes: * to compile all script examples you must have installed Scite4AutoIt3 --> you must compile script by F7 from full Scite * for using #AutoIt3Wrapper_Res_File_Add directive you must have AutoIt3Wrapper at least version 2.0.1.22 (it's part of latest Scite4AutoIt3) * to compile all script examples must be apropriate resource data files in script directory (from resource_data.zip) * _ResourceGet() always returns pointer to data (for RT_BITMAP returns hBitmap), returning other types can be done by additional wrapper functions like _ResourceGetAsString() or _ResourceGetAsBytes() * _ResourceGetAsStringW() is for Unicode strings (Widechar) * you can use also #number instead of resource name, see examples * general supported resource types are listed in UDF as constants ($RT_BITMAP, $RT_RCDATA, ...) * information about playing video files (AVI) from resources is here thanks matrixnz * information/examples about using animated GIFs from resources is here and here thanks smashly/ProgAndy * information about running EXE files/DLL functions directly from resources is here thanks trancexx/Ward Known problems/limitations: * _ResourceGet() returns resource size (in bytes) in @extended macro but not for resource type RT_BITMAP * _ResourceSetImageToCtrl() works with "static/button" type of controls (picture,label,icon,button,checkbox,radiobutton,groupbox) * _ResourcePlaySound() plays only WAV files (not MP3 files) * _ResourceGetAsBytes() doesn't work for RT_BITMAP type because _ResourceGet() returns hBitmap instead of memory pointer in this case there could be used _ResourceGetAsImage() as workaround * _ResourceGet() has potential memory leak releasing of resources UnlockResource,FreeResource (opposite of LoadResource,LockResource) is not done because it must be done after using of resources at the end and not inside UDF * _GDIPlus_Startup() is called once at start of whole include --> no _GDIPlus_Shutdown() is called History: 2011-06-20 - fixed x64 compatibility (type: int->ptr) - internal change: FindResourceA -> FindResourceW (& type: str->wstr) - _SetBitmapToCtrl() --> $CtrlId parameter now supports also -1 (thanks guinness) - _WinAPI_LoadLibraryEx($DLL, $LOAD_LIBRARY_AS_DATAFILE) instead of _WinAPI_LoadLibrary($DLL) (thanks arcker) - added au3.user.calltips.api, au3.userudfs.properties (thanks guinness) - merged resource_au3.zip + resource_data.zip to one file resources.zip 2010-02-12 - all examples now use fixed #AutoIt3Wrapper_Res_File_Add directive from latest Scite4Autoit3 (no need for ResHacker.exe) - added support for buttons (also checkboxes,radiobuttons,groupboxes) in _ResourceSetImageToCtrl()/_SetBitmapToCtrl() thanks Melba 2009-08-25 - fixed corrupted topic (appeared after forum upgrade) - removed some AU3 tags from topic, note: all AU3 code is untouched inside attached ZIP 2008-11-27 - added _ResourceGetAsStringW() --> for Unicode strings (Widechar) 2008-11-10 - added two very simple examples 2008-08-14 - change: _GDIPlus_Startup() is called once at start of whole include--> no _GDIPlus_Shutdown() is called - fixed support for animated GIFs in _ResourceGetAsImage() --> removed_MemGlobalFree($hData) - used simpler UDF syntax (from WinAPI) instead of DllCall() where possible - added new example for animated GIF image 2008-07-08 - just corrected some typos in this topic (no code changes) 2008-06-25 - big thanks to ProgAndy for ideas,improvements! - added _ResourceGetAsImage(), _ResourceGetAsBitmap() - added optional $DLL parameter to all functions - for loading resources from external EXE,DLL files - fixed previous limitation in _ResourceSaveToFile() - now supports also RT_BITMAP type - new examples in resource_test.au3 2008-05-02 - added new RT,SND constants - fixed bad order of parameters ResName x ResType in FindResourceExA (thanks SmOke_N) - added DeleteObject of oldBmp from STM_SETIMAGE in _SetBitmapToCtrl (thanks ProgAndy) - added settinng SS_BITMAP style to control before STM_SETIMAGE in_SetBitmapToCtrl (support for labels) 2008-04-24 - added support for JPG,GIF,PNG in _ResourceSetImageToCtrl() using GDI+ - thanks ProgAndy - reverted all examples back from #AutoIt3Wrapper_Res_File_Add= to#AutoIt3Wrapper_run_after=ResHacker.exe -add - updated both ZIP archives 2007-10-16 - added _ResourcePlaySound() - thanks Larry - corrected local declaration of $struxt - was problem when Opt("MustDeclareVars",1) - updated resource_test.au3 and resource.au3 in resource_au3.zip 2007-09-14 - added optional parameter $CreatePath in _ResourceSaveToFile() - updated resource_test.au3 and resource.au3 in resource_au3.zip 2007-09-11 - in examples used new AutoIt3Wrapper directive#AutoIt3Wrapper_Res_File_Add from latest Scite4AutoIt3 (instead of #AutoIt3Wrapper_run_after=ResHacker.exe -add ...) - updated resource_test.au3 and resource_test_ie.au3 in resource_au3.zip 2007-09-05 - in #AutoIt3Wrapper_run_after=ResHacker.exe -add ... directive can be resource type in text form -->rcdata instead of 10, bitmap instead of 2 and so on (note: but for htmlmust be used 23 still) - updated only resource_test.au3 in resource_au3.zip 2007-09-04 - added description at top of this topic - added _ResourceSaveToFile() - source is also example for using _ResourceGetAsBytes() - more error checking in UDF and error codes are now differrent todistinguish possible problem - default ResType = 10 ($RT_RCDATA) in all functions - updated both ZIP archives 2007-08-29 - added TODO list - removed not used local variables in _ResourceSetImageToCtrl() - ziparchive not updated yet - revisited WWW links and TODO list and added list of functions 2007-08-10 - first version resource_test_min1.au3 - very simple example script of using UDF #AutoIt3Wrapper_Res_File_Add=image3.jpg, rt_rcdata, TEST_JPG_1 #include "resources.au3" $gui = GUICreate("Data from resources simple example 1",400,150) $pic1 = GUICtrlCreatePic("",0,0,400,150) _ResourceSetImageToCtrl($pic1, "TEST_JPG_1") ; set JPG image to picture control from resource GUISetState(@SW_SHOW) While 1 If GUIGetMsg() = -3 Then Exit WEnd resource_test.au3 - complex example script of using UDF #AutoIt3Wrapper_Res_File_Add=test_1.txt, rt_rcdata, TEST_TXT_1 #AutoIt3Wrapper_Res_File_Add=image1.bmp, rt_bitmap, TEST_BMP_1 #AutoIt3Wrapper_Res_File_Add=image2.bmp, rt_bitmap, TEST_BMP_2 #AutoIt3Wrapper_Res_File_Add=image3.jpg, rt_rcdata, TEST_JPG_3 #AutoIt3Wrapper_Res_File_Add=binary1.dat, rt_rcdata, TEST_BIN_1 #AutoIt3Wrapper_Res_File_Add=C:\WINDOWS\Media\tada.wav, sound, TEST_WAV_1 #include "resources.au3" $gui = GUICreate("Data from resources example",820,400) $pic1 = GUICtrlCreatePic("",0,0,400,300) $pic2 = GUICtrlCreatePic("",400,0,400,150) $pic3 = GUICtrlCreatePic("",400,150,400,150) $pic4 = GUICtrlCreatePic("",600,320,400,100) $label1 = GUICtrlCreateLabel("",20,320,380,100) $label2 = GUICtrlCreateLabel("",400,320,200,100) GUISetState(@SW_SHOW) ; get string from resource $string = _ResourceGetAsString("TEST_TXT_1") GUICtrlSetData($label1, $string) ; set BMP image to picture control from resource bitmap _ResourceSetImageToCtrl($pic1, "TEST_BMP_1", $RT_BITMAP) ; get bitmap from resource (as pointer) $hBmp = _ResourceGet("TEST_BMP_2", $RT_BITMAP) ; and use it for whatever you like _SetBitmapToCtrl($pic2, $hBmp) ; set JPG image to picture control from resource _ResourceSetImageToCtrl($pic3, "TEST_JPG_3") ; set image to picture control from external DLL resource _ResourceSetImageToCtrl($pic4, "#14355", $RT_BITMAP, @SystemDir & "\shell32.dll") ; get/use picture from resources as hImage type $size1 = _ResourceGetImageSize("TEST_BMP_1", $RT_BITMAP) $size2 = _ResourceGetImageSize("TEST_JPG_3") GUICtrlSetData($label2, $size1 & @CRLF & $size2) ; save binary data or another type (image) from resource to file and get its size in bytes $size1 = _ResourceSaveToFile(@ScriptDir & "\binary_data1.dat", "TEST_BIN_1") $size2 = _ResourceSaveToFile(@ScriptDir & "\binary_data2.bmp", "TEST_BMP_1", $RT_BITMAP) ; save binary data from resource to file (create not existing directory) _ResourceSaveToFile("C:\Dir1\SubDir2\binary_data1.dat", "TEST_BIN_1", $RT_RCDATA, 0, 1) _ResourceSaveToFile("C:\Dir1\SubDir2\binary_data2.bmp", "TEST_BMP_1", $RT_BITMAP, 0, 1) ; play WAV from resource (sync/async) _ResourcePlaySound("TEST_WAV_1") _ResourcePlaySound("TEST_WAV_1", $SND_ASYNC) While 1 If GUIGetMsg() = -3 Then Exit WEnd Func _ResourceGetImageSize($ResName, $ResType = 10) ; $RT_RCDATA = 10 ; get/use picture from resources as hImage type $hImage = _ResourceGetAsImage($ResName, $ResType) $width = _GDIPlus_ImageGetWidth ($hImage) $height = _GDIPlus_ImageGetHeight($hImage) Return "Size of " & $ResName & " is: " & $width & "x" & $height EndFunc resources.zip - UDF + examples + sample resource data for examples Previous downloads: 7195 resources.zip
    1 point
  4. Hi- In response to Kilgores question about having to enter twice with Windows 8, where do you turn off "ENABLE_LINE_INPUT"? I'm using the Valiks code example to read the input from the console and doing simple validation on the return. #AutoIt3Wrapper_Change2CUI=y #include <WinAPI.au3> #include <StringConstants.au3> #include <console.au3> _GetServiceInfoCMD() Func _ConsoleInput($sPrompt) If Not @Compiled Then Return SetError(1, 0, 0) ; Not compiled ConsoleWrite($sPrompt) Local $tBuffer = DllStructCreate("char"), $nRead, $sRet = "" Local $hFile = _WinAPI_CreateFile("CON", 2, 2) While 1 _WinAPI_ReadFile($hFile, DllStructGetPtr($tBuffer), 1, $nRead) If DllStructGetData($tBuffer, 1) = @CR Then ExitLoop If $nRead > 0 Then $sRet &= DllStructGetData($tBuffer, 1) WEnd _WinAPI_CloseHandle($hFile) Return $sRet EndFunc Func _GetServiceInfoCMD() Local $sCustomerID = _ConsoleInput("Please enter your Customer ID: ") Local $iDcount = StringLen($sCustomerID) Local $iIsNumber = StringIsDigit($sCustomerID) While $iIsNumber <> 1 ConsoleWrite( $sCustomerID & " is not a valid entry, numbers are only allowed." & @CRLF) $sCustomerID = _ConsoleInput("Please enter again: ") $iIsNumber = StringIsDigit($sCustomerID) ConsoleWrite("IsNumber: " & $iIsNumber & @CRLF) WEnd While $iDcount <> 7 ConsoleWrite("Incorrect amount of numbers, only 7 are allowed." & @CRLF) $sCustomerID = _ConsoleInput("Please enter again: ") $iDcount = StringLen($sCustomerID) ConsoleWrite("Count: " & $iDcount & @CRLF) WEnd EndFunc
    1 point
  5. Watch out for Drivers with Jpegs, They are a bugger to get out, if you don't stay clear and get hooked. P.S. Sorry, I couldn't resist. A sense of humor ... me ... you must be joking.
    1 point
  6. Don't! We all learn differently and at different paces. It's what we are here for.
    1 point
  7. AndrewClim, The easiest way to do this would be to use a temporary ini file to store the return value - but you must use RunWait on the compiled file to give it a chance to write the file before the second script tries to read it. Otherwise you are into "inter process communication" - there are lots of ways to do this if you search, but they are all considerably more trouble to code than a simple ini file. M23
    1 point
  8. It will work fine with no monitor connected, only a working video card is necessary. Even function such as get pixel color will work without a monitor. As mLipok says your problem is that a user is not logged on to the PC or the PC is locked. For a script that relies on mouse clicks and therefore widows being active, you will have to turn off screen saver and automatic PC locking after a certain period.
    1 point
  9. Do not log of from Windows and do not lock win terminal session. Session must be active.
    1 point
  10. funkey

    InputBox RTL Prompt Text

    #include <WinAPI.au3> #include <Constants.au3> #include <WindowsConstants.au3> Opt("MustDeclareVars", 1) Global $hHookInputBox InputBox("Standard InputBox", "Please enter some text") _InputBox("RTL InputBox", "Please enter some text") Func _InputBox($title, $prompt, $default = Default, $passwordchar = Default, $width = Default, $height = Default, $left = Default, $top = Default, $timeout = Default, $hwnd = Default) Local $hProcInputBox = DllCallbackRegister("CbtHookProcInputBox", "int", "int;int;int") Local $TIDInputBox = _WinAPI_GetCurrentThreadId() $hHookInputBox = _WinAPI_SetWindowsHookEx($WH_CBT, DllCallbackGetPtr($hProcInputBox), 0, $TIDInputBox) Local $iRet = InputBox($title, $prompt, $default, $passwordchar, $width, $height, $left, $top, $timeout, $hwnd) Local $ierror = @error _WinAPI_UnhookWindowsHookEx($hHookInputBox) DllCallbackFree($hProcInputBox) Return SetError($ierror, "", $iRet) EndFunc ;==>_InputBox Func CbtHookProcInputBox($nCode, $wParam, $lParam, $hHookInputBox) Local $RET = 0, $idText, $idInput If $nCode < 0 Then $RET = _WinAPI_CallNextHookEx($hHookInputBox, $nCode, $wParam, $lParam) Return $RET EndIf Switch $nCode Case 5 ;5=HCBT_ACTIVATE $idText = _WinAPI_GetDlgItem($wParam, 1002) $idInput = _WinAPI_GetDlgItem($wParam, 1001) _WinAPI_SetWindowLong($wParam, $GWL_EXSTYLE, BitOR(_WinAPI_GetWindowLong($wParam, $GWL_EXSTYLE), $WS_EX_LAYOUTRTL)) _WinAPI_SetWindowLong($idText, $GWL_EXSTYLE, BitOR(_WinAPI_GetWindowLong($idText, $GWL_EXSTYLE), $WS_EX_LAYOUTRTL)) _WinAPI_SetWindowLong($idInput, $GWL_EXSTYLE, BitOR(_WinAPI_GetWindowLong($idInput, $GWL_EXSTYLE), $WS_EX_LAYOUTRTL)) EndSwitch Return EndFunc ;==>CbtHookProcInputBox
    1 point
  11. Please stop with the Bold Print when you post on here. Bold is meant to emphasize something specific. Looks like you have 3 options. 1. Compile your script to 32 bit only. 2. Use 64 bit functions. 3. Convert this mystery "memory" functions to accept 64bit integers. Here's the question you should really ask yourself. Why do I need my executable to be 64bit and NOT 32bit.
    1 point
  12. Indeed... that was a "give a dog a bone" type moment.
    1 point
  13. All that aside. What happened to expecting effort and teaching someone to fish? Must be getting close to Christmas.
    1 point
  14. Language is obviously a barrier, but in looking at context, I don't think I've ever known anyone to ask for .jpg files embedded inside drivers. It isn't that far a leap...
    1 point
  15. That worked; didn't even require "runas".. It did!
    1 point
  16. I know this isn't what you are looking for but I got the second one to work with this: Func _Method2() Local $oIE = _IECreate("https://hide.me/en/proxy") Local $pURL = _IEGetObjByName($oIE, "u") Local $pButton = _IEGetObjById($oIE, "hide_register_save") _IEPropertySet($pURL, "innertext", "http://whatismyipaddress.com/") Sleep(5000) For $i = 1 TO 19 Send("{TAB}") Sleep(100) Next Send("http://whatismyipaddress.com/{ENTER}") EndFunc Even WinWait doesn't work on that page. The developers must not like automation. The first one works for me. I get a new proxy for the ie session.
    1 point
  17. This is a converter for a VBScript (5.6) to AutoIt (3.1.1) converter. i hope it is useful. There are many thinks to add at the moment. To test it you need all attach files. Comments are welcome. Version 0.4 - Fixing error message in GUI - Workaround for wscript.echo - Better handling of parenthesis for sub's - Implement ReDim - Set default destination file name in gui - Added some new commands in VATable.txt - Improvements for select constructs Version 0.3 - Added command line switch (vaconvert VBSCRIPTFILE) - Added Gui to select source and destination file (tahnks to gafrost) - Better handlung for prodedure calls - Fixing other errors (e.g. endless loop) Version 0.2 - Add some simple replace commands (VATable.txt) - Improve Select case - Find variables without Dim - Find Constants - Add List of VBCommands (VACommands.txt) Version 0.1 - Better function handling - Added most VBScript functions - Include handling Version 0.01 - First public release Added v0.4 10.06.2005 Added v0.3 08.06.2005 Added v0.2 06.06.2005 Added v0.1 05.06.2005 Added v0.01 04.06.2005 VAConvert.04.zip
    1 point
  18. guinness

    Transparent GUIs ?

    This is because WinSetTrans is never called since the loop is in the way. Try this >> #include <GUIConstants.au3> Example() Func Example() Local $hGUI = GUICreate("Transparent GUI", 300, 300) GUISetState(@SW_SHOW, $hGUI) WinSetTrans($hGUI, "", 170) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop EndSwitch WEnd GUIDelete($hGUI) EndFunc ;==>Example
    1 point
  19. Converter - Dec - Hex - Bin For all of those who need to convert Dec - Hex - Bin and visa versa. #include <Color.au3> #include <GUIConstantsEX.au3> #include <String.au3> Global Const $HX_REF="0123456789ABCDEF" Global Const $color1 = 0x99A8AC Global Const $color2 = 0xFFFFFF $Gui = GUICreate("Converter @ Dec - Bin - Hex"& _StringRepeat(" ",125) & " by ptrex" , 833, 247, 161, 166) GUISetIcon (@windowsdir & "system32Calc.exe",-1,$Gui) $Size = WinGetClientSize($Gui) $radio1 = GUICtrlCreateRadio ("Dec", 100, 10, 60, 20) GUICtrlSetBkColor(-1,0xA1AFB2) $radio2 = GUICtrlCreateRadio ("Hex", 160, 10, 60, 20) GUICtrlSetBkColor(-1,0xA1AFB2) $radio3 = GUICtrlCreateRadio ("Bin", 220, 10, 60, 20) GUICtrlSetBkColor(-1,0xA1AFB2) ;GUICtrlSetState ($radio1, $GUI_CHECKED) $label = GUICtrlCreateLabel("Input", 10, 15, 50, 15) GUICtrlSetBkColor(-1,0xA1AFB2) $labelout = GUICtrlCreateLabel("Result", 10, 45, 50, 15) GUICtrlSetBkColor(-1,0xAEBABD) $Input1 = GUICtrlCreateInput("", 100, 40, 650, 21) $Label1 = GUICtrlCreateLabel("Hexadecimal", 10, 80, 70, 15) GUICtrlSetBkColor(-1,0xBAC4C7) $Label1out = GUICtrlCreateLabel("0", 100, 80, 600, 15) GUICtrlSetBkColor(-1,0xBAC4C7) $Label2 = GUICtrlCreateLabel("Binary", 10, 115, 50, 15) GUICtrlSetBkColor(-1,0xCBD3D5) $Label2out = GUICtrlCreateLabel("0", 100, 115, 600, 15) GUICtrlSetBkColor(-1,0xCBD3D5) _GUICtrlCreateGradient($color1, $color2, 0, 0, $size[0]*1.5, $size[1]) GUISetState(@SW_SHOW) While 1 $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE ExitLoop Case $msg = $radio1 And BitAND(GUICtrlRead($radio1), $GUI_CHECKED) = $GUI_CHECKED GUICtrlSetData($Label1out,_DecimalToHex(int(StringStripWS(GUICtrlRead($Input1,1),8)))) GUICtrlSetData($Label1,"Hexadecimal") GUICtrlSetData($Label2out,_DecToBinary(StringStripWS(GUICtrlRead($Input1,1),8))) GUICtrlSetData($Label2,"Binary") ;ConsoleWrite("_DecimalToHex " & _DecimalToHex(Int(GUICtrlRead($Input1,1))) & @LF) ;ConsoleWrite("_DecToBinary " & _DecToBinary(GUICtrlRead($Input1,1)) & @CRLF) Case $msg = $radio2 And BitAND(GUICtrlRead($radio2), $GUI_CHECKED) = $GUI_CHECKED GUICtrlSetData($Label1out,_HexToDecimal(StringStripWS(GUICtrlRead($Input1,1),8))) GUICtrlSetData($Label1,"Decimal") GUICtrlSetData($Label2out,_HexToBinaryString(StringStripWS(GUICtrlRead($Input1,1),8))) GUICtrlSetData($Label2,"Binary") ;ConsoleWrite("_HexToDecimal " & _HexToDecimal(GUICtrlRead($Input1,1)) & @LF) ;ConsoleWrite("_HexToBinaryString " & _HexToBinaryString(GUICtrlRead($Input1,1)) & @LF) Case $msg = $radio3 And BitAND(GUICtrlRead($radio3), $GUI_CHECKED) = $GUI_CHECKED GUICtrlSetData($Label1out,_BinaryToHexString(StringStripWS(GUICtrlRead($Input1,1),8))) GUICtrlSetData($Label1,"Hexadecimal") GUICtrlSetData($Label2out,_BinaryToDec(StringStripWS(GUICtrlRead($Input1,1),8))) GUICtrlSetData($Label2,"Decimal") ;ConsoleWrite("_BinaryToHexString " & _BinaryToDec(GUICtrlRead($Input1,1)) & @LF) ;ConsoleWrite("_HexToBinaryString " & _HexToBinaryString(GUICtrlRead($Input1,1)) & @LF) EndSelect WEnd ; Conversion Code - Chart ; DECIMAL 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 ; HEX 0 1 2 3 4 5 6 7 8 9 A B C D E F 10 ; BINARY 0000 0001 0010 0011 0100 0101 0110 0111 1000 1001 1010 1011 1100 1101 1110 1111 10000 ; --------------------- Functions ----------------------------- ; Binary to Decimal Func _BinaryToDec($strBin) Local $Return Local $lngResult Local $intIndex If StringRegExp($strBin,'[0-1]') then $lngResult = 0 For $intIndex = StringLen($strBin) to 1 step -1 $strDigit = StringMid($strBin, $intIndex, 1) Select case $strDigit="0" ; do nothing case $strDigit="1" $lngResult = $lngResult + (2 ^ (StringLen($strBin)-$intIndex)) case else ; invalid binary digit, so the whole thing is invalid $lngResult = 0 $intIndex = 0 ; stop the loop EndSelect Next $Return = $lngResult Return $Return Else MsgBox(0,"Error","Wrong input, try again ...") Return EndIf EndFunc ; Decimal To Binary Func _DecToBinary($iDec) Local $i, $sBinChar = "" If StringRegExp($iDec,'[[:digit:]]') then $i = 1 Do $x = 16^$i $i +=1 ; Determine the Octets Until $iDec < $x For $n = 4*($i-1) To 1 Step -1 If BitAND(2 ^ ($n-1), $iDec) Then $sBinChar &= "1" Else $sBinChar &= "0" EndIf Next Return $sBinChar Else MsgBox(0,"Error","Wrong input, try again ...") Return EndIf EndFunc ; #FUNCTION# ============================================================== ; Function Name..: _HexToDec ( "expression" ) ; Description ...: Returns decimal expression of a hexadecimal string. ; Parameters ....: expression - String representation of a hexadecimal expression to be converted to decimal. ; Return values .: Success - Returns decimal expression of a hexadecimal string. ; Failure - Returns "" (blank string) and sets @error to 1 if string is not hexadecimal type. ; Author ........: jennico (jennicoattminusonlinedotde) ; Remarks .......: working input format: "FFFF" or "0xFFFF" (string format), do NOT pass 0xFFFF without quotation marks (number format). ; current AutoIt Dec() limitation: 0x7FFFFFFF (2147483647). ; Related .......: Hex(), Dec(), _DecToHex() ; ======================================================================= Func _HexToDecimal($hx_hex) If StringLeft($hx_hex, 2) = "0x" Then $hx_hex = StringMid($hx_hex, 3) If StringIsXDigit($hx_hex) = 0 Then SetError(1) MsgBox(0,"Error","Wrong input, try again ...") Return "" EndIf Local $ret="", $hx_count=0, $hx_array = StringSplit($hx_hex, ""), $Ii, $hx_tmp For $Ii = $hx_array[0] To 1 Step -1 $hx_tmp = StringInStr($HX_REF, $hx_array[$Ii]) - 1 $ret += $hx_tmp * 16 ^ $hx_count $hx_count += 1 Next Return $ret EndFunc ;==>_HexToDec() ; #FUNCTION# ============================================================== ; Function Name..: _DecToHex ( expression [, length] ) ; Description ...: Returns a string representation of an integer converted to hexadecimal. ; Parameters ....: expression - The integer to be converted to hexadecimal. ; - [optional] Number of characters to be returned (no limit). ; If no length specified, leading zeros will be stripped from result. ; Return values .: Success - Returns a string of length characters representing a hexadecimal expression, zero-padded if necessary. ; Failure - Returns "" (blank string) and sets @error to 1 if expression is not an integer. ; Author ........: jennico (jennicoattminusonlinedotde) ; Remarks .......: Output format "FFFF". ; The function will also set @error to 1 if requested length is not sufficient - the returned string will be left truncated. ; Be free to modify the function to be working with binary type input - I did not try it though. ; current AutoIt Hex() limitation: 0xFFFFFFFF (4294967295). ; Related .......: Hex(), Dec(), _HexToDec() ; ======================================================================= Func _DecimalToHex($hx_dec, $hx_length = 21) If IsInt($hx_dec) = 0 Then SetError(1) MsgBox(0,"Error","Wrong input, try again ...") Return "" EndIf Local $ret = "", $Ii, $hx_tmp, $hx_max If $hx_dec < 4294967296 Then If $hx_length < 9 Then Return Hex($hx_dec, $hx_length) If $hx_length = 21 Then $ret = Hex($hx_dec) While StringLeft($ret, 1) = "0" $ret = StringMid($ret, 2) WEnd Return $ret EndIf EndIf For $Ii = $hx_length - 1 To 0 Step -1 $hx_max = 16 ^ $Ii - 1 If $ret = "" And $hx_length = 21 And $hx_max > $hx_dec Then ContinueLoop $hx_tmp = Int($hx_dec/($hx_max+1)) If $ret = "" And $hx_length = 21 And $Ii > 0 And $hx_tmp = 0 Then ContinueLoop $ret &= StringMid($HX_REF, $hx_tmp+1, 1) $hx_dec -= $hx_tmp * ($hx_max + 1) Next $ret=String($ret) If $hx_length < 21 And StringLen($ret) < $hx_length Then SetError(1) Return $ret EndFunc ;==>_DecToHex() ; ---------------------------------------------------------------- ; Hex to Decimal Conversion ; Correct till Decimal 65789 ?! Func _HexToDecimal_NotCorrect($Input) Local $Temp, $i, $Pos, $Ret, $Output If StringRegExp($input,'[[:xdigit:]]') then $Temp = StringSplit($Input,"") For $i = 1 to $Temp[0] $Pos = $Temp[0] - $i $Ret = Dec (Hex ("0x" & $temp[$i] )) * 16 ^ $Pos $Output &= $Ret Next return $Output Else MsgBox(0,"Error","Wrong input, try again ...") Return EndIf EndFunc ; Decimal To Hex Conversion Func _DecimalToHex_NotCorrect($Input) local $Output, $Ret If StringRegExp($input,'[[:digit:]]') then Do $Ret = Int(mod($Input,16)) $Input = $Input/16 $Output = $Output & StringRight(Hex($Ret),1) Until Int(mod($Ret,16))= 0 Return StringMid(_StringReverse($Output),2) Else MsgBox(0,"Error","Wrong input, try again ...") Return EndIf EndFunc ;------------------------------------------------------------------- ; Binary To Hex Func _BinaryToHexString($BinaryValue) Local $test, $Result = '',$numbytes,$nb If StringRegExp($BinaryValue,'[0-1]') then if $BinaryValue = '' Then SetError(-2) Return endif Local $bits = "0000|0001|0010|0011|0100|0101|0110|0111|1000|1001|1010|1011|1100|1101|1110|1111" $bits = stringsplit($bits,'|') #region check string is binary $test = stringreplace($BinaryValue,'1','') $test = stringreplace($test,'0','') if $test <> '' Then SetError(-1);non binary character detected Return endif #endregion check string is binary #region make binary string an integral multiple of 4 characters While 1 $nb = Mod(StringLen($BinaryValue),4) if $nb = 0 then exitloop $BinaryValue = '0' & $BinaryValue WEnd #endregion make binary string an integral multiple of 4 characters $numbytes = Int(StringLen($BinaryValue)/4);the number of bytes Dim $bytes[$numbytes],$Deci[$numbytes] For $j = 0 to $numbytes - 1;for each byte ;extract the next byte $bytes[$j] = StringMid($BinaryValue,1+4*$j,4) ;find what the dec value of the byte is for $k = 0 to 15;for all the 16 possible hex values if $bytes[$j] = $bits[$k+1] Then $Deci[$j] = $k ExitLoop EndIf next Next ;now we have the decimal value for each byte, so stitch the string together again $Result = '' for $l = 0 to $numbytes - 1 $Result &= Hex($Deci[$l],1) Next return $Result Else MsgBox(0,"Error","Wrong input, try again ...") Return EndIf EndFunc ; Hex To Binary Func _HexToBinaryString($HexValue) Local $Allowed = '0123456789ABCDEF' Local $Test,$n Local $Result = '' if $hexValue = '' then SetError(-2) Return EndIf $hexvalue = StringSplit($hexvalue,'') for $n = 1 to $hexValue[0] if not StringInStr($Allowed,$hexvalue[$n]) Then SetError(-1) return 0 EndIf Next Local $bits = "0000|0001|0010|0011|0100|0101|0110|0111|1000|1001|1010|1011|1100|1101|1110|1111" $bits = stringsplit($bits,'|') for $n = 1 to $hexvalue[0] $Result &= $bits[Dec($hexvalue[$n])+1] Next Return $Result EndFunc Func _GUICtrlCreateGradient($nStartColor, $nEndColor, $nX, $nY, $nWidth, $nHeight) Local $color1R = _ColorGetRed($nStartColor) Local $color1G = _ColorGetGreen($nStartColor) Local $color1B = _ColorGetBlue($nStartColor) Local $nStepR = (_ColorGetRed($nEndColor) - $color1R) / $nHeight Local $nStepG = (_ColorGetGreen($nEndColor) - $color1G) / $nHeight Local $nStepB = (_ColorGetBlue($nEndColor) - $color1B) / $nHeight GuiCtrlCreateGraphic($nX, $nY, $nWidth, $nHeight) For $i = 0 To $nHeight - $nY $sColor = "0x" & StringFormat("%02X%02X%02X", $color1R+$nStepR*$i, $color1G+$nStepG*$i, $color1B+$nStepB*$i) GUICtrlSetGraphic(-1, $GUI_GR_COLOR, $sColor, 0xffffff) GUICtrlSetGraphic(-1, $GUI_GR_MOVE, 0, $i) GUICtrlSetGraphic(-1, $GUI_GR_LINE, $nWidth, $i) Next EndFunc Some of the functions i borrowed from someone -- some of them are mine. Can't really tell what's what. Anyhow, I hope it is fool proof. It wasn' t fool proof, therefore I followed "jennico" advise and used his DecHex and HexDec functions. Enjoy !! regards ptrex
    1 point
×
×
  • Create New...