Jump to content

Leaderboard

Popular Content

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

  1. Newer systems have nicer looking "Browse for folder" UI than older does. AutoIt internally calls older version. Since some time AutoIt can natively access, by definition early bound objects, using special technique of late binding. Function that does this is ObjCreateInterface(). Considering most of the Windows is COM based the advantages are big, you just have to learn how to take them. This small example (attached FileSelectFolder.au3) shows how to create object of IFileDialog interface and by calling its methods customize and invoke "select folder" dialog. In case of older systems where IFileDialog isn't available the function will call internal AutoIt's FileSelectFolder(), so it should be safe to use in any environment. Example of usage is from the help file for normal dialog: #include "FileSelectFolder.au3" Local Const $sMessage = "Select a folder" ; Display an open dialog to select a folder. Local $sFileSelectFolder = FileSelectFolder2($sMessage, "") If @error Then MsgBox(4096, "", "No folder was selected.") Else MsgBox(4096, "", "You chose the following folder:" & @CRLF & $sFileSelectFolder) EndIf ...And the UDF: FileSelectFolder.au3
    1 point
  2. Instead of poluting other people's threads with my opinions I decided to start one of my own. • Using magic numbers fine tunes your application to squeeze the most out of the system by reducing memory usage and by avoiding the need for extra processing. • Using magic numbers avoids the problems assiociated with global variable inconsistancies. • Using magic numbers enables you to easily determine which bits are set and this helps to avoid introducing redundancy into your code. • Using magic numbers side steps obfuscated and meaningless constant names created by non professionals, and this in turn prevents the associated confusion these names cause. • Using magic numbers reduces bloat. • Using magic numbers is fast and convenient.
    1 point
  3. Here something you can play with: ;needs GDIPlus.au3 at least from AutoIt version 3.3.9.23 #include <GUIConstantsEx.au3> #include <GDIPlus.au3> _GDIPlus_Startup() Global Const $STM_SETIMAGE = 0x0172 Global Const $hGUI = GUICreate("GDI+ Test", 200, 100) GUISetBkColor(0x505050) Global Const $iPicBtn = GUICtrlCreatePic("", 60, 38, 80, 24) Global $aButtons = _GDIPlus_CreateTextButton("install", 80, 24) _WinAPI_DeleteObject(GUICtrlSendMsg($iPicBtn, $STM_SETIMAGE, $IMAGE_BITMAP, $aButtons[0])) GUISetState() Global $aMouseInfo, $bShow = False, $bHide = False Do If WinActive($hGUI) Then $aMouseInfo = GUIGetCursorInfo($hGUI) ;hover simulation Switch $aMouseInfo[4] Case $iPicBtn _WinAPI_DeleteObject(GUICtrlSendMsg($iPicBtn, $STM_SETIMAGE, $IMAGE_BITMAP, $aButtons[1])) $bShow = True $bHide = False Case Else _WinAPI_DeleteObject(GUICtrlSendMsg($iPicBtn, $STM_SETIMAGE, $IMAGE_BITMAP, $aButtons[0])) $bHide = True $bShow = False EndSwitch EndIf Switch GUIGetMsg() Case $GUI_EVENT_CLOSE _WinAPI_DeleteObject($aButtons[0]) _WinAPI_DeleteObject($aButtons[1]) _GDIPlus_Shutdown() Exit Case $iPicBtn MsgBox(0, "Information", "Button pressed") EndSwitch Until False ; #FUNCTION# ==================================================================================================================== ; Name ..........: _GDIPlus_CreateTextButton ; Description ...: Draws via GDI+ a Windows 8 style button with text ; Syntax ........: _GDIPlus_CreateTextButton($sString, $iWidth, $iHeight[, $iBgColor = 0xFF1BA0E1[, $iFontSize = 16[, $sFont = "Times New Roman"[, ; $iHoverColor = 0xFFC9388C[, $iFrameSize = 2[, $iFontFrameColor = 0x408AD5EA[, $iFontColor = 0xFFFFFFFF]]]]]]) ; Parameters ....: $sString - A string value. ; $iWidth - An integer value. ; $iHeight - An integer value. ; $iBgColor - [optional] An integer value. Default is 0xFF1BA0E1. ; $iFontSize - [optional] An integer value. Default is 16. ; $sFont - [optional] A string value. Default is "Times New Roman". ; $iHoverColor - [optional] An integer value. Default is 0xFFC9388C. ; $iFrameSize - [optional] An integer value. Default is 2. ; $iFontFrameColor - [optional] An integer value. Default is 0x408AD5EA. ; $iFontColor - [optional] An integer value. Default is 0xFFFFFFFF. ; Return values .: an array with 2 GDI bitmap handles -> [0]: default button, [1]: hover button ; Author ........: UEZ ; Version .......: 0.85 build 2014-05-08 ; Modified ......: ; Remarks .......: Dispose returned GDI bitmap handles when done ; Example .......: Yes ; =============================================================================================================================== Func _GDIPlus_CreateTextButton($sString, $iWidth, $iHeight, $iBgColor = 0xFF1BA0E1, $iFontSize = 16, $sFont = "Times New Roman", $iHoverColor = 0xFFFFFFFF, $iFrameSize = 2, $iFontFrameColor = 0x408AD5EA, $iFontColor = 0xFFFFFFFF) ;some checks If $sString = "" Then Return SetError(1, 0, 0) If Int($iWidth) < $iFrameSize * 2 Then Return SetError(2, 0, 0) If Int($iHeight) < $iFrameSize * 2 Then Return SetError(3, 0, 0) ;create font objects Local Const $hFormat = _GDIPlus_StringFormatCreate() Local Const $hFamily = _GDIPlus_FontFamilyCreate($sFont) Local $tLayout = _GDIPlus_RectFCreate(0, 0, $iWidth, $iHeight) _GDIPlus_StringFormatSetAlign($hFormat, 1) ;center string on X axis _GDIPlus_StringFormatSetLineAlign($hFormat, 1) ;center string on Y axis ;create bitmap and graphics context handles Local Const $aBitmaps[2] = [_GDIPlus_BitmapCreateFromScan0($iWidth, $iHeight), _GDIPlus_BitmapCreateFromScan0($iWidth, $iHeight)] Local Const $aGfxCtxt[2] = [_GDIPlus_ImageGetGraphicsContext($aBitmaps[0]), _GDIPlus_ImageGetGraphicsContext($aBitmaps[1])] ;set drawing quality _GDIPlus_GraphicsSetSmoothingMode($aGfxCtxt[0], $GDIP_SMOOTHINGMODE_HIGHQUALITY) _GDIPlus_GraphicsSetTextRenderingHint($aGfxCtxt[0], $GDIP_TEXTRENDERINGHINT_ANTIALIASGRIDFIT) ;define brush and pen objects Local Const $hBrushFontColor = _GDIPlus_BrushCreateSolid($iFontColor) Local Const $hPenFontFrameColor = _GDIPlus_PenCreate($iFontFrameColor, 1), $hPenHoverColor = _GDIPlus_PenCreate($iHoverColor, $iFrameSize) ;create path object Local Const $hPath = _GDIPlus_PathCreate() ;create cloned path object for string measurement Local Const $hPath_Dummy = _GDIPlus_PathClone($hPath) _GDIPlus_PathAddString($hPath_Dummy, $sString, $tLayout, $hFamily, 0, $iFontSize, $hFormat) ;~ Local Const $aInfo = _GDIPlus_PathGetWorldBounds($hPath_Dummy) ;~ $tLayout.Y = ($iHeight - $aInfo[3]) / 2 - Ceiling($aInfo[1]) ;center string on Y axis ;add string to path _GDIPlus_PathAddString($hPath, $sString, $tLayout, $hFamily, 1, $iFontSize, $hFormat) ;clear bitmap and draw string _GDIPlus_GraphicsClear($aGfxCtxt[0], $iBgColor) _GDIPlus_GraphicsFillPath($aGfxCtxt[0], $hPath, $hBrushFontColor) _GDIPlus_GraphicsDrawPath($aGfxCtxt[0], $hPath, $hPenFontFrameColor) ;draw rectangle on cloned bitmap for hover effect _GDIPlus_GraphicsDrawImageRect($aGfxCtxt[1], $aBitmaps[0], 0, 0, $iWidth, $iHeight) _GDIPlus_GraphicsDrawRect($aGfxCtxt[1], $iFrameSize / 2, $iFrameSize / 2, $iWidth - $iFrameSize, $iHeight - $iFrameSize, $hPenHoverColor) ;dispose object resources _GDIPlus_FontFamilyDispose($hFamily) _GDIPlus_StringFormatDispose($hFormat) _GDIPlus_PathDispose($hPath) _GDIPlus_PathDispose($hPath_Dummy) _GDIPlus_GraphicsDispose($aGfxCtxt[0]) _GDIPlus_GraphicsDispose($aGfxCtxt[1]) _GDIPlus_BrushDispose($hBrushFontColor) _GDIPlus_PenDispose($hPenFontFrameColor) _GDIPlus_PenDispose($hPenHoverColor) ;create GDI bitmap for later usage Local $aHBitmaps[2] = [_GDIPlus_BitmapCreateHBITMAPFromBitmap($aBitmaps[0]), _GDIPlus_BitmapCreateHBITMAPFromBitmap($aBitmaps[1])] ;dispose GDI+ bitmaps _GDIPlus_BitmapDispose($aBitmaps[0]) _GDIPlus_BitmapDispose($aBitmaps[1]) Return $aHBitmaps EndFunc Br,UEZ
    1 point
  4. guinness, I have read Valik's comment and discussed on teh forum it many times - I did not and still do not agree with it. While I see the logic of doing what he suggested when using a language which does have that sort of scoping, this is absolutely not the case in AutoIt and I firmly believe that declaring main script variables as Local when they are in fact treated as Global could well cause huge problems to someone who does not grasp the subtlety of the original argument. AutoIt is designed first and foremost for those who are not experienced coders - in my opinion some of those who are sometimes lose sight of this simple fact. End of transmission. M23
    1 point
  5. But it's not used anywhere else and thus is "Local to the scope" not Global. Valik was the one (when I started on the help file) who drilled this into me. For example I started to change examples like the one below to Global, but he made a point about this to me in the MVP section that it's actually Local and not Global. Local $sString = 'Some string' $sString = StringToBinary($sString) ConsoleWrite($sString & @CRLF) Read this >>
    1 point
  6. ab = a * b, not a + b.
    1 point
  7. Taskkill will run on a remote computer, your code will not, it will run wherever the script is being executed from, as I told you in your other thread.
    1 point
  8. markyrocks

    Having troubles

    I'd say if you don't want to click that much don't play the game.
    1 point
  9. No way. ...that's magic number too, but the value should be 2.
    1 point
×
×
  • Create New...