Code Tạo Hiệu Ứng Đẹp Cho Desktop

Trang ChínhLatest imagesTìm kiếmĐăng kýĐăng Nhập


Welcome to Forums Haku
Chào mừng các bạn đến với diễn đàn
Chúc các bạn có những giờ phút thư giãn thoải mái tại diễn đàn
Chúc các bạn luôn thành công trong cuộc sống

<--Code by Admin Haku -->

Share|
Tiêu đề

Code Tạo Hiệu Ứng Đẹp Cho Desktop

Xem chủ đề cũ hơn Xem chủ đề mới hơn Go down
Tác giảThông điệp

Admin
Member
Admin

Tổng bài gửi : 1074
Được Cảm Ơn : 538
Đến từ : Hà Ná»™i
Tài năng của Admin
Hạng: Member
Level:1074
Tài năng:/300


Tài Sản
Huân Chương: PhotobucketPhotobucketPhotobucketPhotobucketPhotobucketPhotobucketPhotobucketPhotobucketPhotobucket

Bài gửiTiêu đề: Code Tạo Hiệu Ứng Đẹp Cho Desktop Code Tạo Hiệu Ứng Đẹp Cho Desktop 3e45c23a204Tue Jul 09, 2013 4:55 pm

Code Tạo Hiệu Ứng Đẹp Cho Desktop

Demo:
Code Tạo Hiệu Ứng Đẹp Cho Desktop Untitled_zpsbed55490

WindowDarken
Code:
#NoTrayIcon
#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_icon=WindowDarken.ico
#AutoIt3Wrapper_Compression=4
#AutoIt3Wrapper_Res_Description=WindowDarken Background Dimmer
#AutoIt3Wrapper_Res_Fileversion=2.2.0.18
#AutoIt3Wrapper_Res_Fileversion_AutoIncrement=y
#AutoIt3Wrapper_Res_LegalCopyright=Crash Daemonicus
#AutoIt3Wrapper_Res_Language=1033
#AutoIt3Wrapper_Res_requestedExecutionLevel=requireAdministrator
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#Include <Misc.au3>
#include <WindowsConstants.au3>
#include <VarData.au3>


#cs
Haku.4rumer.com
Copyright (C) Haku.4rumer.Com

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
version 2 or later as published by the Free Software Foundation.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
#ce



;2.2 - Changed: savefile is much smaller (requires VarData update)
;2.1 - Fixed: changing fade opacities didn't recalculate fade step amounts (too long/short fades)
;2.0 -
;   Added: background color setting
;   Added: checking for Only One instance (per-user)
;1.1 - Start menu window (not the task bar) is considered an active window now and doesn't brighten everything.
;   Fixed: FadeIn checking FadeOutStep instead of FadeInStep (for UDEF condition)
;   Note: bug(?) found: disabling FadeIn won't disable while faded-out. (nonissue, not fixed)

;disable the DoFade_ options to disable switch-fading (the fade between window selection)

Global Const $Ver=2.2
Global Const $UDEF=1.1/0;  Double 1.#INF - this is just used in conditionals (please confirm correctness in conditionals)
Global $sSaveFile=@ScriptDir&'\WindowDarken.dat'
Global $sIconPath=@ScriptDir&'\WindowDarken.ico'
Global $sHighlightExclusionRegex='(?i)(^gimp|^logonui.exe$|^netropa|^OSD)'; these exclusions will brighten the entire screen like system windows do (reliant on bDoHighlightExclusions)
If @Compiled Then $sIconPath=@ScriptFullPath


Global $uVariables=10
Global $aVariables[$uVariables]=['@WorkingDir','sImageBackground','bDoHighlightExclusions','iBackColor','iDarkenTrans','iLightenTrans','iFadeStepDelay','iFadeSteps','bDoFadeOut','bDoFadeIn']
;Saved Settings - settings file is backwards-compatible as long as new settings are *appended* to the above array
Global $iBackColor=0
Global $iDarkenTrans=0.50*255
Global $iLightenTrans=1
Global $iFadeStepDelay=10
Global $iFadeSteps=5
Global $bDoFadeOut=True
Global $bDoFadeIn=True
Global $bDoHighlightExclusions=False; no menu option yet
Global $sImageBackground=''
FileChangeDir(@ScriptDir)
_Load()

Global $iFadeInStep=($iDarkenTrans-$iLightenTrans)/$iFadeSteps
Global $iFadeOutStep=($iDarkenTrans-$iLightenTrans)/$iFadeSteps
Global $bFaded=True
Global $bFadeState=true
Global $bRunning=True
Global $bBreakSleep=False
;Global $hStart=WinGetHandle('[TITLE:Start Menu; CLASS:DV2ControlHost]'); Q: why is this not used? A: highlighting the start menu is kind of neat.
Global $hTaskbar=WinGetHandle('[CLASS:Shell_TrayWnd]')
Global $hDesktop=WinGetHandle('[CLASS:Progman]')
Global $hActive=-1
Global $bActiveOnTop=false
Global $bActiveNoHighlight=false

If _Singleton('WindowDarken-D169F7',1)=0 Then
   MsgBox(16,'WindowDarken Warning','WindowDarken is already running. Please close it before trying to run another instance.')
   Exit
EndIf


Opt('GUIOnEventMode',1)
Local $iWidth=@DesktopWidth, $iHeight=@DesktopHeight
Global $hDarken=GUICreate('WindowDarken',$iWidth,$iHeight,0,0,$WS_POPUP,BitOr($WS_EX_TOOLWINDOW,$WS_EX_TRANSPARENT))
Global $cDarken=GUICtrlCreateLabel('',0,0,$iWidth,$iHeight)
Global $cImage=GUICtrlCreatePic('',0,0,$iWidth,$iHeight)
GUICtrlSetBkColor($cDarken,$iBackColor)
If StringLen($sImageBackground) Then
   GUICtrlSetImage($cImage,$sImageBackground)
   ControlMove ($hDarken,'', $cImage, 0, 0, $iWidth,$iHeight)
EndIf
GUICtrlSetOnEvent($cDarken,'_ClickEvent')
D_WinSetTrans($hDarken,'',1)
WinActivate($hActive)

Opt('TrayOnEventMode',1)
Opt('TrayMenuMode',3)
TrayCreateItem("&WindowDarken v"&$Ver)
TrayCreateItem("")
Local $settings=TrayCreateMenu("&Settings")
   TrayEventItem("+ &Default mode (Fade all, 5 steps)",'T_MDefault',$settings)
   TrayEventItem("+ &Quick-switch mode (No window-change fading)",'T_MQuick',$settings)
   TrayEventItem("+ Darken &only (No fading)",'T_MNoFades',$settings)
   TrayCreateItem("",$settings)
   TrayEventItem("Set background &color ...",'T_PBackColor',$settings)
   TrayEventItem("Set background &image ...",'T_PBackImage',$settings)
   TrayEventItem("&Set minimum fade opacity ...",'T_PFadeMin',$settings)
   TrayEventItem("Set &maximum fade opacity (Darkness) ...",'T_PFadeMax',$settings)
   TrayEventItem("Set &number of fade steps ...",'T_PFadeSteps',$settings)
   TrayEventItem("Set &fade steps delay ...",'T_PFadeDelay',$settings)
   TrayCreateItem("",$settings)
   Local $settings_fadeIn=TrayCreateItem("Fade &while Darkening*",$settings)
   TrayItemSetOnEvent(-1,'T_CFadeIn')
   Local $settings_fadeOut=TrayCreateItem("Fade while &Brightening*",$settings)
   TrayItemSetOnEvent(-1,'T_CFadeOut')
   TrayItemSetState(TrayCreateItem("* Window-change setting only",$settings),128)
TrayCreateItem("")
TrayEventItem("&About", "T_About" )
TrayCreateItem("")
TrayEventItem("E&xit", "T_Quit" )
T__ResetChecks()
TraySetState()
TraySetIcon($sIconPath)
TraySetToolTip('WindowDarken v'&$Ver)

_WinAPI_ShowWindow($hDarken, @SW_SHOWNOACTIVATE)
If (Not $bDoFadeIn) Then _FadeIn(1)
While $bRunning
   Local $tmp=WinGetHandle('[ACTIVE]')
   Local $stateX=_CheckState($tmp)
   If $bRunning And $tmp<>$hActive And IsHWnd($tmp) And $stateX Then
      $bActiveNoHighlight=false
      Local $class=_WinAPI_GetClassName($tmp)
      Local $title=WinGetTitle($tmp)
      ConsoleWrite('  '&$tmp&' - CLASS:'&$class&' TITLE:'&$title&@CRLF)
      If StringRegExp($class,'^\#\d+$') And $title=='' Then $bActiveNoHighlight=True
      If $bDoHighlightExclusions Then
         Local $proc=_ProcessGetName(WinGetProcess($tmp))
         If StringRegExp($proc,$sHighlightExclusionRegex) Then $bActiveNoHighlight=True
         ConsoleWrite('  - PROC:'&$proc&@CRLF)
      EndIf

      If $tmp=$hDarken Then
         If Not $bFaded Then _FadeOut(1)
         _ResetCurrentWindow()
         $hActive=$tmp
         WinActivate($hTaskbar)
         ConsoleWrite('    System Brightened (from WD)'&@CRLF)
      Else
         If $tmp=$hTaskbar Or $tmp=$hDesktop Or $bActiveNoHighlight  Then
            If Not $bFaded Then _FadeOut(1)
            _ResetCurrentWindow()
            $hActive=$tmp
            ConsoleWrite('    System Brightened'&@CRLF)
         Else
            If Not $bFaded Then _FadeOut()
            _ResetCurrentWindow()
            WinSetOnTop($hDarken,'',1);TopMost - and Top of all windows (inc topmost)
            $hActive=$tmp
            WinSetOnTop($hActive,'',1);TopMost - and Top of all windows (inc topmost{hDarken})
            $bActiveOnTop=true
            ConsoleWrite('    Window Brightened'&@CRLF)
            If $bFaded Then _FadeIn($bFadeState)
         EndIf
      EndIf
   EndIf
   _SleepCheck($bBreakSleep,100,25); sleep for 100ms in steps of 25ms with checks for Break in between
WEnd
Exit





Func _Save()
   Local $vd=''
   For $i=0 To $uVariables-1
      $vd&=BinaryToString(_VarData_EvalFromVar($aVariables[$i],False))
   Next
   Local $fh=FileOpen($sSaveFile,2+16)
   If $fh=-1 Then Return MsgBox(16,'WindowDarken','The Settings file could not be opened for writing.')
   If FileWrite($fh,$vd)=0 Then MsgBox(16,'WindowDarken','The Settings file could not be written to or is read-only.')
   FileClose($fh)
EndFunc
Func _Load()
   Local $f=@ScriptDir&'\WindowDarken.dat'
   If FileExists($f)=0 Then Return
   Local $fh=FileOpen($sSaveFile,0+16)
   If $fh=-1 Then Return MsgBox(16,'WindowDarken','The Settings file could not be opened for reading.')
   Local $vd=FileRead($fh)
   If @error<>0 and @error<>-1 Then MsgBox(16,'WindowDarken','The Settings file could not read from.')
   FileClose($fh)
   _VarData_AssignFromData($vd,$aVariables)
EndFunc


Func T_About()
   _ForceRelease()
   MsgBox(0,'Haku.4rumer.Com','Code By: Admin.haku'&@CRLF&'Web: Haku.4rumer.Com'&@CRLF&'Yh: mactoingaodu2001')
   _ForceCapture()
EndFunc
Func T_MDefault()
   T__FadeSteps(5)
   $bDoFadeOut=True
   $bDoFadeIn=True
   T__ResetChecks()
EndFunc
Func T_MQuick()
   T__FadeSteps(5)
   $bDoFadeOut=False
   $bDoFadeIn=False
   T__ResetChecks()
EndFunc
Func T_MNoFades()
   T__FadeSteps(0)
   $bDoFadeOut=False
   $bDoFadeIn=False
   T__ResetChecks()
EndFunc
Func T_PFadeMin()
   _ForceRelease()
   Local $m=InputBox('WindowDarken - Minimum Opacity','Please enter an opacity value in percents(%).'&@CRLF&'0% is invisible, 100% is black.',(($iLightenTrans/255)*100)&'%')
   _ForceCapture()
   If @error<>0 Then Return
   $m=Number($m)
   If $m<0 Then $m=0
   If $m>100 Then $m=100
   $iLightenTrans=($m/100)*255
   T__FadeSteps()
   If $bFadeState Then D_WinSetTrans($hDarken,'',$iLightenTrans)
EndFunc
Func T_PFadeMax()
   _ForceRelease()
   Local $m=InputBox('WindowDarken - Maximum Opacity','Please enter an opacity value in percents(%).'&@CRLF&'0% is invisible, 100% is black.',(($iDarkenTrans/255)*100)&'%')
   _ForceCapture()
   If @error<>0 Then Return
   $m=Number($m)
   If $m<0 Then $m=0
   If $m>100 Then $m=100
   $iDarkenTrans=($m/100)*255
   T__FadeSteps()
   If $bFadeState=false Then D_WinSetTrans($hDarken,'',$iDarkenTrans)
EndFunc
Func T_PFadeSteps()
   _ForceRelease()
   Local $m=InputBox('WindowDarken - Fade Steps','Please enter the number of steps to taken when fading in or out.',$iFadeSteps)
   _ForceCapture()
   If @error<>0 Then Return
   T__FadeSteps(Number($m))
EndFunc
Func T_PFadeDelay()
   _ForceRelease()
   Local $m=InputBox('WindowDarken - Fade Delay','Please enter the number of miliseconds to delay during each Fade Step.',$iFadeStepDelay)
   _ForceCapture()
   If @error<>0 Then Return
   $iFadeStepDelay=Number($m)
EndFunc
Func T_PBackColor()
   _ForceRelease()
   Local $color=_ChooseColor(0, switchRGB($iBackColor), 0)
   _ForceCapture()
   If $color=-1 Then Return
   $sImageBackground=''
   GUICtrlSetImage($cImage,$sImageBackground)
   ControlMove ($hDarken,'', $cImage, 0, 0, $iWidth,$iHeight)
   $iBackColor=switchRGB($color)
   GUICtrlSetBkColor($cDarken,$iBackColor)
EndFunc

Func T_PBackImage()
   _ForceRelease()
   Local $file=FileOpenDialog('Select Background Image',@WorkingDir,'Images (*.bmp;*.jpg;*.jpeg;*.gif;*.png)|All (*.*)',1)
   Local $error=@error
   _ForceCapture()
   If $error<>0 Then Return
   $sImageBackground=$file
   GUICtrlSetImage($cImage,$sImageBackground)
   ControlMove ($hDarken,'', $cImage, 0, 0, $iWidth,$iHeight)
EndFunc

Func T_CFadeIn()
   $bDoFadeIn=Not $bDoFadeIn
   T__ResetChecks()
EndFunc
Func T_CFadeOut()
   $bDoFadeOut=Not $bDoFadeOut
   T__ResetChecks()
EndFunc
Func T__ResetChecks()
   T__SetChecked($settings_fadeIn,$bDoFadeIn)
   T__SetChecked($settings_fadeOut,$bDoFadeOut)
EndFunc
Func T__FadeSteps($i=Default)
   If Not ($i=Default) Then $iFadeSteps=$i
   $iFadeInStep=($iDarkenTrans-$iLightenTrans)/$iFadeSteps
   $iFadeOutStep=($iDarkenTrans-$iLightenTrans)/$iFadeSteps
EndFunc
Func T__SetChecked($c,$bCheck)
   If $bCheck Then Return TrayItemSetState ($c,1)
   Return TrayItemSetState ($c,4)
EndFunc


Func _ClickEvent()
   ; this click event will just break the Sleep immediately and hasten the response to hDarken being activated.
   $bBreakSleep=True
EndFunc

Func _SleepCheck(ByRef $bCondition,$iMS,$iStepMS=25)
   For $i=0 To $iMS Step $iStepMS
      If $bCondition Then ExitLoop
      Sleep($iStepMS)
   Next
   $bCondition=False
EndFunc

Func _ResetCurrentWindow()
   If $bActiveOnTop Then
      WinSetOnTop($hActive,'',0);;;;Top of all non-Topmost windows (lower than topmost, still above normal{hDarken})
      $bActiveOnTop=false
      ConsoleWrite('    Brightened Window unlocked'&@CRLF)
   EndIf
EndFunc

Func _ForceRelease()
   If Not $bFaded Then _FadeOut(1)
   _ResetCurrentWindow()
EndFunc
Func _ForceCapture()
   $hActive=-1
   $bBreakSleep=True
EndFunc


Func T_Quit()
   $bBreakSleep=True
   $bRunning=False
   _ForceRelease()
   GUIDelete($hDarken)
   _Save()
   Exit
EndFunc

Func _CheckState(ByRef $hWnd)
   Local $state=WinGetState ($hWnd)
   Local $st_exs=BitAND($state,1)
   Local $st_vsb=BitAND($state,2)
   Local $st_enb=BitAND($state,4)
   Local $st_act=BitAND($state,8)
   Local $st_min=BitAND($state,16)
   Local $st_max=BitAND($state,32)
   ; Enabled and Maximized states are inconsequential.
   If $st_min Then
      $hWnd=$hDesktop
      Return true
   EndIf
   If $st_exs And $st_vsb And $st_act Then Return true
   Return 0
EndFunc

Func TrayEventItem($tx, $evt='', $parent=-1)
   Return TrayItemSetOnEvent(TrayCreateItem($tx,$parent),$evt)
EndFunc


Func _FadeOut($force=false)
   $bFaded=True
   If (Not $bDoFadeOut) And (Not $force) Then Return
   ;ConsoleWrite($force&@CRLF)
   $bFadeState=true
   If $iFadeOutStep>0 And $iFadeOutStep<255 And $iFadeOutStep<>$UDEF Then
      For $i=$iDarkenTrans To $iLightenTrans Step -$iFadeOutStep
         If $i<$iLightenTrans Then ExitLoop
         D_WinSetTrans($hDarken,'',$i)
         Sleep($iFadeStepDelay)
      Next
   EndIf
   D_WinSetTrans($hDarken,'',$iLightenTrans)
EndFunc

Func _FadeIn($force=false)
   $bFaded=False
   If (Not $bDoFadeIn) And (Not $force) Then Return
   $bFadeState=false
   If $iFadeInStep>0 And $iFadeInStep<255 And $iFadeInStep<>$UDEF Then
      For $i=$iLightenTrans To $iDarkenTrans Step $iFadeInStep
         If $i>$iDarkenTrans Then ExitLoop
         D_WinSetTrans($hDarken,'',$i)
         Sleep($iFadeStepDelay)
      Next
   EndIf
   D_WinSetTrans($hDarken,'',$iDarkenTrans)
EndFunc
Func switchRGB($color)
   Return BitShift($color,16)+BitAnd($color,65280)+BitShift(BitAnd($color,255),-16)
EndFunc

Func D_WinSetTrans($h,$ti,$ia)
   WinSetTrans($h,$ti,$ia)
   ;ConsoleWrite($ia&@CRLF)
EndFunc


;Included manually::

; Name...........: _WinAPI_ShowWindow
; Author ........: Paul Campbell (PaulIA)
Func _WinAPI_ShowWindow($hWnd, $iCmdShow = 5)
   Local $aResult = DllCall("user32.dll", "bool", "ShowWindow", "hwnd", $hWnd, "int", $iCmdShow)
   If @error Then Return SetError(@error, @extended, False)
   Return $aResult[0]
EndFunc  ;==>_WinAPI_ShowWindow

; Name...........: _WinAPI_GetClassName
; Author ........: Paul Campbell (PaulIA)
; Modified.......: jpm
Func _WinAPI_GetClassName($hWnd)
   If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd)
   Local $aResult = DllCall("user32.dll", "int", "GetClassNameW", "hwnd", $hWnd, "wstr", "", "int", 4096)
   If @error Then Return SetError(@error, @extended, False)
   Return SetExtended($aResult[0], $aResult[2])
EndFunc  ;==>_WinAPI_GetClassName

; Name...........: _ProcessGetName
; Author ........: Erifash <erifash [at] gmail [dot] com>, Wouter van Kesteren.
Func _ProcessGetName($i_PID)
   If Not ProcessExists($i_PID) Then Return SetError(1, 0, '')
   If Not @error Then
      Local $a_Processes = ProcessList()
      For $i = 1 To $a_Processes[0][0]
         If $a_Processes[$i][1] = $i_PID Then Return $a_Processes[$i][0]
      Next
   EndIf
   Return SetError(1, 0, '')
EndFunc  ;==>_ProcessGetName




VarData
Code:
#cs
VarData - Supplies methods for transfering variables to and from data/files while maintaining datatypes. (mostly to aide debugging, possibly to further settings capabilities)
Copyright (C) Crash Daemonicus (crashenator -at- gmail.com)

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
version 2 or later as published by the Free Software Foundation.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
#ce

;Note: this does some hackish stuff to permit array support and type conversions

Global Const $_VarData_tagHeader = 'align 1;byte Type; ushort NameLen; UINT ValueLen'
Global Const $_VarData_tagHeaderFormat = '; byte Name[%u]; byte Value[%u]'
Global $_VarData_VarTypes[12]=['Bool','Int32','Int64','Float','Double','String','Binary','Keyword','Array','Ptr','Object','DllStruct']

Func _VarData_AssignFromData($Data, $aNames=Default)
   If IsBinary($Data)=0 Then $Data=StringToBinary($Data); might not be a string, but nothing that needs handling otherwise.
   Local $i=0
   Local $fArray=IsArray($aNames)
   Local $uArray=UBound($aNames)
   Do
      Local $n,$v,$l
      $l=_VarData_DataToVar($Data, $n,$v)
      If $fArray And $i<$uArray Then $n=$aNames[$i]
      If StringLen($n) Then
         Switch $n
            Case '@ComSpec'
               EnvSet('comspec',$v)
            Case '@WorkingDir'
               FileChangeDir($v)
            Case '@error'
               SetError($v)
            Case '@extended'
               SetExtended($v)
            Case Else
               Assign($n,$v,2)
         EndSwitch
      EndIf
      $Data=BinaryMid($Data,$l+1)
      $i+=1
   Until BinaryLen($Data)<1
EndFunc
Func _VarData_EvalFromVar($VarName,$fSaveName=True)
   Local $VarValue
   Switch StringLeft($VarName,1)
      Case '$'
         $VarName=StringTrimLeft($VarName,1)
         $VarValue=Eval($VarName)
      Case '@'
         $VarValue=Execute($VarName)
      Case Else
         $VarValue=Eval($VarName)
   EndSwitch
   If $fSaveName=False Then $VarName=''
   Return _VarData_VarToData($VarName,$VarValue)
EndFunc

Func _VarData_VarToData($VarName,$VarValue,$o=0); Returns a Binary Type
   Local $typeValue=_VarData_GetType($VarValue)
   Local $lenName=StringLen($VarName)
   Local $binValue
   Local $lenValue
   _VarData_ValueToBinary($typeValue,$VarValue,$binValue,$lenValue)
   If $o Then ConsoleWrite($typeValue&'|'& _
      $lenName&'|'& _
      $lenValue&'|'& _
      $VarName&'|'& _
      $binValue&@CRLF)


   Local $lenName_disp=$lenName
   If $lenName<1 Then $lenName=1
   Local $lenValue_disp=$lenValue
   If $lenValue<1 Then $lenValue=1


   Local $stcVar=DllStructCreate($_VarData_tagHeader&StringFormat($_VarData_tagHeaderFormat,$lenName,$lenValue))
   DllStructSetData($stcVar,1,$typeValue)
   DllStructSetData($stcVar,2,$lenName_disp)
   DllStructSetData($stcVar,3,$lenValue_disp)
   DllStructSetData($stcVar,4,StringToBinary($VarName))
   DllStructSetData($stcVar,5,$binValue)

   Return _VarData__StructToBinaryDEL($stcVar)
EndFunc

Func _VarData_DataToVar(ByRef $Data, Byref $VarName_out, ByRef $VarValue_out,$o=0)
   Local $stcBytes=DllStructCreate('byte['&BinaryLen($Data)&']')
   DllStructSetData($stcBytes,1,$Data)

   Local $stcVarPreview=DllStructCreate($_VarData_tagHeader,DllStructGetPtr($stcBytes))
   Local $typeValue=DllStructGetData($stcVarPreview,1)
   Local $lenName_disp=DllStructGetData($stcVarPreview,2)
   Local $lenValue_disp=DllStructGetData($stcVarPreview,3)
   Local $lenName=$lenName_disp
   If $lenName<1 Then $lenName=1
   Local $lenValue=$lenValue_disp
   If $lenValue<1 Then $lenValue=1



   Local $stcVar=DllStructCreate($_VarData_tagHeader&StringFormat($_VarData_tagHeaderFormat,$lenName,$lenValue),DllStructGetPtr($stcBytes))
   $VarName_out = BinaryToString(BinaryMid(DllStructGetData($stcVar,4),1,$lenName_disp))
   Local $binValue =BinaryMid(DllStructGetData($stcVar,5),1,$lenValue_disp)
   If $o Then ConsoleWrite($typeValue&'|'& _
      $lenName&'|'& _
      $lenValue&'|'& _
      $VarName_out&'|'& _
      $binValue&@CRLF)

   _VarData_BinaryToValue($binValue,$typeValue,$lenValue,$VarValue_out)


   Return DllStructGetSize($stcVar)
EndFunc

Func _VarData_GetType(ByRef $VarValue)
   Local $VarType=VarGetType($VarValue)
   For $i=0 To UBound($_VarData_VarTypes)-1
      If $VarType==$_VarData_VarTypes[$i] Then Return $i
   Next
   Return 6; default to Binary.
EndFunc
Func _VarData_ValueToBinary($typeValue,ByRef $VarValue,ByRef $newValue_out,ByRef $lenNewValue_out)
   Switch $typeValue
      Case 0
         $newValue_out=0
         If $VarValue Then $newValue_out=1
         $lenNewValue_out=1
      Case 1
         _VarData__ConvertStruct($VarValue,'int','byte[%u]',$newValue_out,$lenNewValue_out)
      Case 2
         _VarData__ConvertStruct($VarValue,'INT64','byte[%u]',$newValue_out,$lenNewValue_out)
      Case 3,4,9
         _VarData__ConvertStruct($VarValue,StringLower($_VarData_VarTypes[$typeValue]),'byte[%u]',$newValue_out,$lenNewValue_out)
      Case 5
         $newValue_out=StringToBinary($VarValue)
         $lenNewValue_out=BinaryLen($newValue_out)
      Case 6
         $newValue_out=$VarValue
         $lenNewValue_out=BinaryLen($VarValue)
      Case 7
         $newValue_out=0
         If $VarValue=Default Then $newValue_out=1
         $lenNewValue_out=1
      Case 8;Array
         $newValue_out=_VarData__ArrayToBinary($VarValue)
         $lenNewValue_out=BinaryLen($newValue_out)
      Case Else
         $newValue_out=''
         $lenNewValue_out=1
   EndSwitch
EndFunc


Func _VarData_BinaryToValue(ByRef $binValue,$typeValue,$lenValue,ByRef $VarValue_out)
   Local $tagBytes='byte['&$lenValue&']'
   Switch $typeValue
      Case 0
         $VarValue_out=(Int($binValue)<>0)
      Case 1
         _VarData__ConvertStruct($binValue,$tagBytes,'int',$VarValue_out,$lenValue)
      Case 2
         _VarData__ConvertStruct($binValue,$tagBytes,'INT64',$VarValue_out,$lenValue)
      Case 3,4,9
         _VarData__ConvertStruct($binValue,$tagBytes,StringLower($_VarData_VarTypes[$typeValue]),$VarValue_out,$lenValue)
         If $typeValue=9 Then $VarValue_out=Ptr($VarValue_out)
      Case 5
         $VarValue_out=BinaryToString($binValue)
      Case 6
         $VarValue_out=$binValue
      Case 7
         $VarValue_out=''
         If (Int($binValue)<>0) Then $VarValue_out=Default; there's only one Keyword value at this time, anyway.
      Case 8;Array
         $VarValue_out=_VarData__BinaryToArray($binValue)
      Case Else
         $VarValue_out=''
   EndSwitch
EndFunc

Func _VarData__BinaryToArray(ByRef $Binary)
   ;note: this function sucks because there is no built-in way to
   ; declare an array with a dynamic amount of subscripts.
   ; Only a static number of subscripts are supported.
   ; So, I only handle 1-4, they must be handled individually. Yes, this looks like bad coding.
   Local $stcBytes,$stcSubscripts
   _VarData__BinaryToStruct($Binary,'UINT ElLength; byte Subscripts',$stcBytes,$stcSubscripts)
   Local $elLen=DllStructGetData($stcSubscripts,1)
   Local $uSubscripts=DllStructGetData($stcSubscripts,2)
   If $uSubscripts<1 Or $uSubscripts>4 Then Return ''
   Local $stcArray=DllStructCreate('UINT ElLength; byte Subscripts; UINT Dimensions['&$uSubscripts&']; byte['&$elLen&']',DllStructGetPtr($stcBytes))

   Local $aDimensions[$uSubscripts]
   Local $aDimCur[$uSubscripts]
   For $i=0 To $uSubscripts-1
      $aDimensions[$i]=DllStructGetData($stcArray,3,$i+1)
      $aDimCur[$i]=0
   Next

   ;And now, the ugly part!
   Switch $uSubscripts
      Case 1
         Dim $ArrTmp[$aDimensions[0]]
      Case 2
         Dim $ArrTmp[$aDimensions[0]][$aDimensions[1]]
      Case 3
         Dim $ArrTmp[$aDimensions[0]][$aDimensions[1]][$aDimensions[2]]
      Case 4
         Dim $ArrTmp[$aDimensions[0]][$aDimensions[1]][$aDimensions[2]][$aDimensions[3]]
   EndSwitch
   ;End ugly part.

   Local $elBytes=DllStructGetData($stcArray,4)
   Do
      Local $tmpVarName, $tmpVarValue
      Local $tmpLen=_VarData_DataToVar($elBytes, $tmpVarName, $tmpVarValue)
      ; this \/ only exists to allow dynamic assigning of values to array elements (where the array has a dynamic amount of subscripts)
      Execute('_VarData__Byref_Set($ArrTmp'&_VarData__ArrayDimCur_Output($aDimCur,$uSubscripts)&',$tmpVarValue)')
      $elBytes=BinaryMid($elBytes,$tmpLen+1)
   Until (Not _VarData__ArrayDimCur_Increase($aDimCur,$aDimensions)) Or (BinaryLen($elBytes)<1)
   Return $ArrTmp
EndFunc

Func _VarData__ArrayToBinary(ByRef $Array)
   ;[subs][dim1][dim2][dim3]....[dimN][ ... elements ... ]
   Local $uSubscripts=UBound($Array,0)
   Local $aDimensions[$uSubscripts]
   Local $aDimCur[$uSubscripts]
   For $i=0 To $uSubscripts-1
      $aDimensions[$i]=UBound($Array,$i+1)
      $aDimCur[$i]=0
   Next

   Local $elBytes=''
   Local $tmpName=''
   Do
      Local $subscript=_VarData__ArrayDimCur_Output($aDimCur,$uSubscripts)
      ;$tmpName=_VarData__ArrayDimCur_Output($aDimCur,$uSubscripts)
      Local $tmpValue=Execute('$Array'&$subscript)
      $elBytes&=BinaryToString(_VarData_VarToData($tmpName,$tmpValue))
   Until Not _VarData__ArrayDimCur_Increase($aDimCur,$aDimensions)

   Local $elLen=BinaryLen($elBytes)
   Local $stcArr=DllStructCreate('UINT ElLength; byte Subscripts; UINT Dimensions['&$uSubscripts&']; byte['&$elLen&']')
   DllStructSetData($stcArr,1,$elLen)
   DllStructSetData($stcArr,2,$uSubscripts)
   For $i=0 To $uSubscripts-1
      DllStructSetData($stcArr,3,$aDimensions[$i],$i+1)
   Next
   DllStructSetData($stcArr,4,StringToBinary($elBytes))

   Return _VarData__StructToBinaryDEL($stcArr)
EndFunc

Func _VarData__Byref_Set(ByRef $Var,ByRef $Val)
   ; this only exists to allow dynamic assigning of values to array elements (where the array has a dynamic amount of subscripts)
   ; see: _VarData__BinaryToArray
   $Var=$Val
EndFunc

Func _VarData__ArrayDimCur_Increase(ByRef $aDimCur,Byref $aDimensions)
   For $i=UBound($aDimCur)-1 To 0 Step -1
      If $aDimCur[$i]<($aDimensions[$i]-1) Then
         $aDimCur[$i]+=1
         Return True
      Else
         $aDimCur[$i]=0
      EndIf
   Next
   Return False
EndFunc
Func _VarData__ArrayDimCur_Output(ByRef $aDimCur,ByRef $uSubscripts)
   Local $dim=''
   For $i=0 To $uSubscripts-1
      $dim&='['&$aDimCur[$i]&']'
   Next
   Return $dim
EndFunc


Func _VarData__ConvertStruct(ByRef $Value,$strTypeA,$strTypeB,ByRef $Value_out,ByRef $Len_out)
   Local $stcA=DllStructCreate($strTypeA)
   DllStructSetData($stcA,1,$Value)
   Local $lenA=DllStructGetSize($stcA)
   Local $stcB=DllStructCreate(StringFormat($strTypeB,$lenA),DllStructGetPtr($stcA))
   $Value_out=DllStructGetData($stcB,1)
   $Len_out=$lenA
   $stcA=0
   $stcB=0
EndFunc
Func _VarData__BinaryToStruct(ByRef $Binary,$tagStc,ByRef $stcBytes_tmp,Byref $stcOut)
   $stcBytes_tmp=DllStructCreate('byte['&BinaryLen($Binary)&']')
   DllStructSetData($stcBytes_tmp,1,$Binary)
   $stcOut=DllStructCreate($tagStc,DLLStructGetPtr($stcBytes_tmp))
EndFunc
Func _VarData__StructToBinary(ByRef $stcA,ByRef $stc_tmp)
   Local $lenA=DllStructGetSize($stcA)
   $stc_tmp=DllStructCreate('byte['&$lenA&']',DllStructGetPtr($stcA))
   Return DllStructGetData($stc_tmp,1)
EndFunc
Func _VarData__StructToBinaryDEL(ByRef $stcA)
   ;both structures are released (really only stcB is, but it will release stcA's memory inadvertantly)
   Local $lenA=DllStructGetSize($stcA)
   Local $stcB=DllStructCreate('byte['&$lenA&']',DllStructGetPtr($stcA))
   Return DllStructGetData($stcB,1)
EndFunc

Hãy cám ơn bài viết của Admin bằng cáh bấm vào "" nhe!!!

Về Đầu Trang Go down

https://haku.forumvi.net

Tiêu đề

Code Tạo Hiệu Ứng Đẹp Cho Desktop

Xem chủ đề cũ hơn Xem chủ đề mới hơn Về Đầu Trang
Trang 1 trong tổng số 1 trang
::.
Permissions in this forum:Bạn không có quyền trả lời bài viết
Forum Häkü Cộng Đồng Chém Gió :: CONG NGHE THONG TIN :: Thủ thuật-