Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 12/25/2012 in all areas

  1. Lakes

    Xmas Animation

    Zip file for this is here #include <WindowsConstants.au3> #include <GUIConstantsEx.au3> #include <GDIPlus.au3> #include <String.au3> Opt("GUIOnEventMode", 1) $Wid = 960 $Hgt = 720 Global $StringX, $StringY Global $flakes = 25, $Min = 5, $Max = 20 Global $particles[$flakes][5] Global $santaX = $wid, $santaY = 100 Global $sc_hBrush, $sc_hFormat, $sc_hFamily, $sc_hFont, $sc_text_color, $text_scroller, $sc_tLayout, $sc_pen, $sc_brush Global $letter_distance, $x, $y, $lenght, $end, $scroller_length, $sc_k Global $shadowBrush, $shadowFormat, $shadowFamily, $shadowFont, $shadowFamily, $shadowLayout Global $tshadow, $shadowtext ,$shadowtLayout, $shadowColor = 0xFFABA9BA Global $sc_text = "*** Merry Christmas and Happy New Year to all Autoit Users! ***" Global $sc_font_size = 48, $Font = "Times New Roman", $Fontoffset = 3 Global $bassdll = DllOpen(@ScriptDir & "\BASSMOD.dll"), $Play, $Pause, $stop Global $Titlestart = " " Global $Title = $Titlestart &" *** Merry Christmas! *** " $hGUI = GUICreate($Title, $Wid, $Hgt, -1, -1); -1, BitOR($WS_EX_TOOLWINDOW, $WS_EX_WINDOWEDGE)) $menu = GUICtrlCreateMenu("Music") $Play = GUICtrlCreateMenuItem("Play", $menu) GUICtrlSetState(-1, $GUI_CHECKED) $Pause = GUICtrlCreateMenuItem("Pause", $menu) GUICtrlSetState(-1, $GUI_UNCHECKED) $Exit = GUICtrlCreateMenuItem("Exit", $menu) GUICtrlSetState(-1, $GUI_UNCHECKED) If @OSBuild < 7600 Then WinSetTrans($hGUI,"", 0xFF) ; only use this if solid background GUISetState(@SW_SHOW) GUISetOnEvent(-3, "close") GUIRegisterMsg($WM_COMMAND, "WM_COMMAND") ; =========================================== _GDIPlus_Startup() ;Window BckBuffer $graphics = _GDIPlus_GraphicsCreateFromHWND($hGUI) $bitmap = _GDIPlus_BitmapCreateFromGraphics($Wid, $Hgt, $graphics) $backbuffer = _GDIPlus_ImageGetGraphicsContext($bitmap) ; BackBuffer for static image $bitmap1 = _GDIPlus_BitmapCreateFromGraphics($Wid, $Hgt, $graphics) $backbuffer1 = _GDIPlus_ImageGetGraphicsContext($bitmap1) $Background = _GDIPlus_ImageLoadFromFile("SnowScene.png") #Region Load Images $santa = _GDIPlus_ImageLoadFromFile("Santa.png") $santaW = _GDIPlus_ImageGetWidth($santa) $santaH = _GDIPlus_ImageGetHeight($santa) $Flake1 = _GDIPlus_ImageLoadFromFile("Flake1.png") $Flake1W = _GDIPlus_ImageGetWidth($Flake1)/4 $Flake1H = _GDIPlus_ImageGetHeight($Flake1)/4 $F1eX = $Flake1W/2 $F1eY = $Flake1H/2 $Flake2 = _GDIPlus_ImageLoadFromFile("Flake2.png") $Flake2W = _GDIPlus_ImageGetWidth($Flake2)/4 $Flake2H = _GDIPlus_ImageGetHeight($Flake2)/4 $F2eX = $Flake2W/2 $F2eY = $Flake2H/2 $Flake3 = _GDIPlus_ImageLoadFromFile("Flake3.png") $Flake3W = _GDIPlus_ImageGetWidth($Flake3)/4 $Flake3H = _GDIPlus_ImageGetHeight($Flake3)/4 $F3eX = $Flake3W/2 $F3eY = $Flake3H/2 #endregion #Region Setup Scroll Font $sc_text_color = 0xFFffffff $sc_htextBrush = _GDIPlus_BrushCreateSolid($sc_text_color) $sc_hFormat = _GDIPlus_StringFormatCreate() $sc_hFamily = _GDIPlus_FontFamilyCreate($Font) $sc_hFont = _GDIPlus_FontCreate($sc_hFamily, $sc_font_size, 2) $sc_pen = _GDIPlus_PenCreate(0) $sc_brush = _GDIPlus_BrushCreateSolid(0) $tLayout = _GDIPlus_RectFCreate(0, 0) ;shadow ;$T_Fontoffset = 5 $ShadowBrush = _GDIPlus_BrushCreateSolid($shadowColor) $ShadowFormat = _GDIPlus_StringFormatCreate() $ShadowFamily = _GDIPlus_FontFamilyCreate($Font) $ShadowFont = _GDIPlus_FontCreate($shadowFamily, $sc_font_size, 2) $ShadowLayout = _GDIPlus_RectFCreate(0, 0) ;Text Ini $sc_letter_distance = $sc_font_size $sc_length = $sc_font_size * 1.666 * 0.36 $sc_k = $wid $end = 0 $scroller_length = StringLen($sc_text) * $sc_length $sc_FontY = $Hgt - $Hgt/4 + 40 #endregion For $i = 0 To UBound($particles) - 1 $particles[$i][0] = Random(0, $wid, 1) ;X pos $particles[$i][1] = Random(0, $hgt, 1) ;Y pos $particles[$i][2] = 0 $particles[$i][3] = Random($min, $max) $particles[$i][4] = Random($min, $max, 1) ;size Next Play_Audio() Do _GDIPlus_GraphicsClear($backbuffer, 0x00FFFFFF) _GDIPlus_GraphicsDrawImageRect($backbuffer1, $Background, 0, 0, $Wid, $Hgt) ;Static Image _Draw() ScrollText() _GDIPlus_GraphicsDrawImageRect($backbuffer1, $bitmap, 0, 0, $Wid, $Hgt) _GDIPlus_GraphicsDrawImageRect($graphics, $bitmap1, 0, 0, $Wid, $Hgt) Sleep(20) Until 0 Func _Draw() _GDIPlus_GraphicsDrawImageRect($backbuffer1, $santa, $santaX, $santaY, $santaW, $santaH) For $i = 0 To UBound($particles) - 1 If $particles[$i][1] > $hgt Then $particles[$i][0] = Random(-50, $wid+50, 1) ; X pos $particles[$i][1] = 0 ; y Pos $particles[$i][2] = 0 $particles[$i][3] = Random($min, $max) ;min, max, [int] $particles[$i][4] = Random($min, $max, 1) ; size EndIf $particles[$i][0] += $particles[$i][2] $particles[$i][1] += $particles[$i][3] ; X y width Height _GDIPlus_GraphicsDrawImageRect($backbuffer1, $Flake1, $particles[$i][0], $particles[$i][1], $Flake1W +$particles[$i][4], $Flake1H + $particles[$i][4]) _GDIPlus_GraphicsDrawImageRect($backbuffer1, $Flake2, $particles[$i][0] + 50 , $particles[$i][1] + 50, $Flake1W +$particles[$i][4], $Flake1H + $particles[$i][4]) _GDIPlus_GraphicsDrawImageRect($backbuffer1, $Flake3, $particles[$i][0] - 25 , $particles[$i][1] - 25, $Flake1W +$particles[$i][4], $Flake1H + $particles[$i][4]) Next $santaX -= 8 If -$SantaW >= $santaX Then $santaX = $Wid EndIf EndFunc ; ========= Handle WM_COMMAND messages ======================= Func WM_COMMAND($hWnd, $iMsg, $iwParam, $ilParam) Switch $iwParam Case $Play Play() Case $Pause Pause() Case $Exit Close() EndSwitch EndFunc ;==>WM_COMMAND ;============================================================= ; ================ SCROLL TEXT ==================== Func ScrollText() $sc_FontX = $sc_k + $sc_letter_distance DllStructSetData($tLayout, "x", $sc_FontX) DllStructSetData($tLayout, "y", $sc_FontY) _GDIPlus_GraphicsDrawStringEx($BackBuffer, $sc_text, $sc_hFont, $tLayout, $sc_hFormat, $sc_htextBrush) ;Shadow DllStructSetData($ShadowLayout, "X", $sc_FontX + $FontOffset) DllStructSetData($ShadowLayout, "Y", $sc_FontY + $FontOffset) _GDIPlus_GraphicsDrawStringEx($Backbuffer1, $sc_text, $shadowFont, $shadowLayout, $shadowFormat, $shadowBrush) ;Text DllStructSetData($tLayout, "X", $sc_FontX) DllStructSetData($tLayout, "Y", $sc_FontY) _GDIPlus_GraphicsDrawStringEx($Backbuffer1, $sc_text, $sc_hFont, $tLayout, $sc_hFormat, $sc_htextBrush) $sc_k -= 5 If -$scroller_length >= $sc_k Then $sc_k = $Wid EndFunc Func Play_Audio() $Init = DllCall($bassdll, "int", "BASSMOD_Init", "int", -1, "int", 44100, "int", 0) $string= DllStructCreate("char[255]") DllStructSetData($string, 1, @ScriptDir & "\christmas_silence.xm") $load = DllCall($bassdll, "int", "BASSMOD_MusicLoad", _ "int", 0, _ "ptr", DllStructGetPtr($string), _ "int", 0, _ "int", 0, _ "int", 4 + 1024) $VolLevel = 100 $Volume = DllCall($bassdll, "int", "BASSMOD_SetVolume", "int", $VolLevel) DllCall($bassdll, "int", "BASSMOD_MusicPlay") EndFunc Func Play() ;consolewrite("You selected Play" &@CRLF) GUICtrlSetState($Play, $GUI_CHECKED) DllCall($bassdll, "int", "BASSMOD_MusicPlay") GUICtrlSetState($Pause, $GUI_UNCHECKED) GUICtrlSetState($Stop, $GUI_UNCHECKED) EndFunc Func Pause() ;consolewrite("You selected Pause" &@CRLF) GUICtrlSetState($Pause, $GUI_CHECKED) DllCall($bassdll, "int", "BASSMOD_MusicPause") GUICtrlSetState($Play, $GUI_UNCHECKED) GUICtrlSetState($Stop, $GUI_UNCHECKED) EndFunc Func close() _GDIPlus_FontDispose($SC_hFont) _GDIPlus_FontFamilyDispose($SC_hFamily) _GDIPlus_StringFormatDispose($SC_hFormat) _GDIPlus_GraphicsDispose($graphics) _GDIPlus_BrushDispose($sc_hBrush) _GDIPlus_FontFamilyDispose($shadowFamily) _GDIPlus_StringFormatDispose($shadowFormat) _GDIPlus_BrushDispose($shadowBrush) _WinAPI_DeleteObject($bitmap) _WinAPI_DeleteObject($bitmap1) _GDIPlus_GraphicsDispose($backbuffer) _GDIPlus_GraphicsDispose($backbuffer1) _GDIPlus_Shutdown() Exit EndFunc ;==>close ; Happy Holidays!
    1 point
  2. kylomas

    Eval control ID variable

    Ryhono, If you want to use "dynamic" variable names it could be done like this. #include <GUIConstantsEx.au3> #AutoIt3Wrapper_Add_Constants=n local $msg local $gui010 = guicreate('Checkbox Controls Using an Array for the Control ID') for $1 = 1 to 15 guictrlcreatelabel('CheckBox #' & stringformat('%02i',$1),10, $1 * 25,90,20) assign('checkbox' & $1,GUICtrlCreateCheckbox('',95, $1 * 25,20,15)) Next guisetstate() while 1 $msg = guigetmsg() switch $msg case $gui_event_close Exit case eval('checkbox' & 1) to eval('checkbox' & 15) for $1 = 1 to 15 if guictrlread(eval('checkbox' & $1)) = $gui_checked then ConsoleWrite('Checkbox #' & stringformat('%02i',$1) & ' checked' & @LF) else ConsoleWrite('Checkbox #' & stringformat('%02i',$1) & ' unchecked' & @LF) endif next EndSwitch wend However, this makes reading and debugging the code more difficult than it need be. You will generally find multiple checkboxes implemented using an array like this. #include <GUIConstantsEx.au3> #AutoIt3Wrapper_Add_Constants=n local $ckb_cntrls[16], $msg ConsoleWrite(ubound($ckb_cntrls) - 1 & @LF) local $gui010 = guicreate('Checkbox Controls Using an Array for the Control ID') for $1 = 1 to 15 guictrlcreatelabel('CheckBox #' & stringformat('%02i',$1),10, $1 * 25,90,20) $ckb_cntrls[$1] = GUICtrlCreateCheckbox('',95, $1 * 25,20,15) Next guisetstate() while 1 $msg = guigetmsg() switch $msg case $gui_event_close Exit case $ckb_cntrls[1] to $ckb_cntrls[ubound($ckb_cntrls) - 1] for $1 = 1 to ubound($ckb_cntrls) - 1 if guictrlread($ckb_cntrls[$1]) = $gui_checked then ConsoleWrite('Checkbox #' & stringformat('%02i',$1) & ' checked' & @LF) else ConsoleWrite('Checkbox #' & stringformat('%02i',$1) & ' unchecked' & @LF) endif next EndSwitch wend Both of these examples list the state of all checkboxes when any checkbox is actioned. kylomas
    1 point
  3. Here one way to do it. ;coded by UEZ 2012 #include <GUIConstantsEx.au3> #include <GDIPlus.au3> #include <WinAPI.au3> #include <WindowsConstants.au3> Opt("MustDeclareVars", 1) _GDIPlus_Startup() Global Const $STM_SETIMAGE = 0x0172 Global $sPathKey = "HKLM64\SOFTWARE\AutoIt v3\AutoIt\" If @OSArch = "x64" Then $sPathKey = "HKLM\SOFTWARE\Wow6432Node\AutoIt v3\AutoIt\" Global $sImage1 = RegRead($sPathKey, "InstallDir") & "\Examples\GUI\msoobe.jpg" Global $sImage2 = RegRead($sPathKey, "InstallDir") & "\Examples\GUI\Torus.png" Global $hGUI = GUICreate("Test", 300, 100) Global $iInput = GUICtrlCreateInput($sImage1, 20, 20, 200, 20) Global $iInput2 = GUICtrlCreateInput($sImage2, 20, 60, 200, 20) Global $iBtn = GUICtrlCreateButton("Exit", 240, 26, 50, 50) Global $hGui_PreviewSize = 200, $iBGColor = 0xF0F0F0 Global $hGui_Preview = GUICreate("", $hGui_PreviewSize, $hGui_PreviewSize + 58, -1, -1, $WS_POPUP + $WS_BORDER, $WS_EX_TOPMOST, $hGUI) Global $idPic = GUICtrlCreatePic("", 0, 0, $hGui_PreviewSize, $hGui_PreviewSize) Global $idLabel_Info = GUICtrlCreateLabel("", 0, $hGui_PreviewSize + 8, $hGui_PreviewSize * 2, 50) GUICtrlSetFont(-1, 9, 400, 0, "Arial", 5) GUICtrlSetColor(-1, $iBGColor) GUICtrlSetBkColor(-1, 0x222222) GUISetState(@SW_HIDE, $hGui_Preview) GUISetState(@SW_SHOW, $hGUI) ControlFocus($hGUI, "", $iBtn) Global $aMouseInfo, $aPosCtrl, $aPosWin, $hBmp_Tmp, $sFile, $bShow = False, $bHide = False Do Switch GUIGetMsg() Case $GUI_EVENT_CLOSE, $iBtn If $hBmp_Tmp Then _WinAPI_DeleteObject($hBmp_Tmp) _GDIPlus_Shutdown() GUIDelete($hGui_Preview) GUIDelete($hGUI) Exit EndSwitch If WinActive($hGUI) Then $aMouseInfo = GUIGetCursorInfo($hGUI) Switch $aMouseInfo[4] Case $iInput $sFile = GUICtrlRead($iInput) If FileExists($sFile) And Not $bShow Then ShowPreview($sFile, $iInput) $bShow = True $bHide = False EndIf Case $iInput2 $sFile = GUICtrlRead($iInput2) If FileExists($sFile) And Not $bShow Then ShowPreview($sFile, $iInput2) $bShow = True $bHide = False EndIf Case Else If Not $bHide Then GUISetState(@SW_HIDE, $hGui_Preview) $bHide = True EndIf $bShow = False EndSwitch EndIf Until False Func ShowPreview($sFile, $iCtrl) $aPosWin = WinGetPos($hGUI) $aPosCtrl = ControlGetPos($hGUI, "", $iCtrl) WinMove($hGui_Preview, "", $aPosWin[0] + $aPosCtrl[0] + $aPosCtrl[2], $aPosWin[1] + $aPosCtrl[1] + $aPosCtrl[3]) $hBmp_Tmp = _GetImage($sFile, $hGui_PreviewSize, $iBGColor) _hBmpToPicControl($idPic, $hBmp_Tmp, 1) GUISetState(@SW_SHOWNOACTIVATE, $hGui_Preview) EndFunc ;==>ShowPreview Func _GetImage($sFile, $iWH, $iBkClr = 0xFFFFFF) Local $hBmp1, $hBitmap, $hGraphic, $hImage, $iW, $iH, $aGS, $hBmp2, $aFTS $aFTS = FileGetTime($sFile) If @error Then Return SetError(1, 0, 0) $hBmp1 = _WinAPI_CreateBitmap($iWH, $iWH, 1, 32) $hBitmap = _GDIPlus_BitmapCreateFromHBITMAP($hBmp1) $hGraphic = _GDIPlus_ImageGetGraphicsContext($hBitmap) _WinAPI_DeleteObject($hBmp1) _GDIPlus_GraphicsClear($hGraphic, BitOR(0xFF000000, $iBkClr)) $hImage = _GDIPlus_ImageLoadFromFile($sFile) $iW = _GDIPlus_ImageGetWidth($hImage) $iH = _GDIPlus_ImageGetHeight($hImage) GUICtrlSetData($idLabel_Info, StringRegExpReplace($sFile, ".*\\(.*)", "$1") & @LF & Round(FileGetSize($sFile) / 1024, 0) & " kb (" & $iW & " x " & $iH & ")" & @LF & $aFTS[0] & "/" & $aFTS[1] & "/" & $aFTS[2] & " " & $aFTS[3] & ":" & $aFTS[4] & ":" & $aFTS[5]) $aGS = _GetScale($iW, $iH, $iWH) _GDIPlus_GraphicsDrawImageRect($hGraphic, $hImage, $aGS[0], $aGS[1], $aGS[2], $aGS[3]) _GDIPlus_ImageDispose($hImage) _GDIPlus_GraphicsDispose($hGraphic) $hBmp2 = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap) _GDIPlus_BitmapDispose($hBitmap) Return $hBmp2 EndFunc ;==>_GetImage Func _GetScale($iW, $iH, $iWH) Local $aRet[4] If $iW <= $iWH And $iH <= $iWH Then $aRet[2] = $iW $aRet[3] = $iH $aRet[0] = ($iWH - $aRet[2]) / 2 $aRet[1] = ($iWH - $aRet[3]) / 2 ElseIf $iW > $iH Then $aRet[2] = $iWH $aRet[3] = $iH / ($iW / $iWH) $aRet[0] = 0 $aRet[1] = ($iWH - $aRet[3]) / 2 ElseIf $iW < $iH Then $aRet[2] = $iW / ($iH / $iWH) $aRet[3] = $iWH $aRet[0] = ($iWH - $aRet[2]) / 2 $aRet[1] = 0 ElseIf $iW = $iH Then $aRet[2] = $iWH $aRet[3] = $iWH $aRet[0] = 0 $aRet[1] = 0 EndIf Return $aRet EndFunc ;==>_GetScale Func _hBmpToPicControl($iCID, ByRef $hBmp, $iFlag = 0) Local Const $STM_SETIMAGE = 0x0172 Local Const $IMAGE_BITMAP = 0 Local $hOldBmp $hOldBmp = GUICtrlSendMsg($iCID, $STM_SETIMAGE, $IMAGE_BITMAP, $hBmp) If $hOldBmp Then _WinAPI_DeleteObject($hOldBmp) If $iFlag Then _WinAPI_DeleteObject($hBmp) EndFunc ;==>_hBmpToPicControl Edit: added @SW_SHOWNOACTIVATE as suggested by PhoenixXL - it's smoother now. Edit2: added WinActive() check to display preview only when window is active (good catch michaelslamet) Br, UEZ
    1 point
  4. stormbreaker

    GUI Button states

    Checkbox is a better option, but you can make it look like a button: #include <GUIConstantsEx.au3> Example() Func Example() Local $msg GUICreate("My Example") ; will create a dialog box that when displayed is centered GUICtrlCreateCheckbox("My Button", 10, 10, 120, 20, 0x1000) GUISetState() ; will display an dialog box with 1 checkbox ; Run the GUI until the dialog is closed While 1 $msg = GUIGetMsg() If $msg = $GUI_EVENT_CLOSE Then ExitLoop WEnd EndFunc ;==>Example
    1 point
×
×
  • Create New...