Sign in to follow this  
Followers 0
svatvn

Install fonts / change wallpapers

4 posts in this topic

#1 ·  Posted (edited)

Hey guys,

I have two questions:

#1

this code installs all font files in C:\MyFonts. But it doesnt install from subfolders in the same dir. Only files in the main dir will be installed.

So how can I make it to install all fonts from all subfolders...?

InstallFont("C:\MyFonts\*.*")
 
Func InstallFont($sSourceFile, $sFontDescript="", $sFontsPath="")
    Local Const $HWND_BROADCAST = 0xFFFF
    Local Const $WM_FONTCHANGE = 0x1D
    
    If $sFontsPath = "" Then $sFontsPath = @WindowsDir & "\fonts"
    
    Local $sFontName = StringRegExpReplace($sSourceFile, "^.*\\", "")
    If Not FileCopy($sSourceFile, $sFontsPath & "\" & $sFontName, 1) Then Return SetError(1, 0, 0)
    
    Local $hSearch = FileFindFirstFile($sSourceFile)
    Local $iFontIsWildcard = StringRegExp($sFontName, "\*|\?")
    Local $aRet, $hGdi32_DllOpen = DllOpen("gdi32.dll")
    
    If $hSearch = -1 Then Return SetError(2, 0, 0)
    If $hGdi32_DllOpen = -1 Then Return SetError(3, 0, 0)
    
    While 1
        $sFontName = FileFindNextFile($hSearch)
        If @error Then ExitLoop
        
        If $iFontIsWildcard Then $sFontDescript = StringRegExpReplace($sFontName, "\.[^\.]*$", "")
        
        $aRet = DllCall($hGdi32_DllOpen, "Int", "AddFontResource", "str", $sFontsPath & "\" & $sFontName)
        If IsArray($aRet) And $aRet[0] > 0 Then
            RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts", _
                $sFontDescript, "REG_SZ", $sFontsPath & "\" & $sFontName)
        EndIf
    WEnd
    
    DllClose($hGdi32_DllOpen)
    DllCall("user32.dll", "Int", "SendMessage", "hwnd", $HWND_BROADCAST, "int", $WM_FONTCHANGE, "int", 0, "int", 0)
    Return 1
EndFunc

#2

this code changes the current wallpaper with jpg-files in C:\MyWallpapers. But it uses all JPG files from all subfolders.

How can I make it to use the jpg files from the main directory only and not from subfolders?

Global $aWallpapers, $iRand
 
$aWallpapers = _GetFilesFolder_Rekursiv ("C:\MyWallpapers", "jpg", 0, 0)
$iRand = Random(1, UBound($aWallpapers) - 1, 1)
RegWrite("HKEY_CURRENT_USER\Control Panel\Desktop", "TileWallPaper", "REG_SZ", 0)
RegWrite("HKEY_CURRENT_USER\Control Panel\Desktop", "WallpaperStyle", "REG_SZ", -1)
RegWrite("HKEY_CURRENT_USER\Control Panel\Desktop", "Wallpaper", "REG_SZ", $aWallpapers[$iRand])
DllCall("user32.dll", "int", "SystemParametersInfo", "int", 20, "int", 0, "str", $aWallpapers[$iRand], "int", BitOR(1, 2))
Func _GetFilesFolder_Rekursiv($sPath, $sExt='*', $iDir=-1, $iRetType=0, $sDelim='0')
    Global $oFSO = ObjCreate('Scripting.FileSystemObject')
    Global $strFiles = ''
    Switch $sDelim
        Case '1'
            $sDelim = @CR
        Case '2'
            $sDelim = @LF
        Case '3'
            $sDelim = ';'
        Case '4'
            $sDelim = '|'
        Case Else
            $sDelim = @CRLF
    EndSwitch
    If ($iRetType < 0) Or ($iRetType > 1) Then $iRetType = 0
    If $sExt = -1 Then $sExt = '*'
    If ($iDir < -1) Or ($iDir > 1) Then $iDir = -1
    _ShowSubFolders($oFSO.GetFolder($sPath),$sExt,$iDir,$sDelim)
    If $iRetType = 0 Then
        Local $aOut
        $aOut = StringSplit(StringTrimRight($strFiles, StringLen($sDelim)), $sDelim, 1)
        If $aOut[1] = '' Then
            ReDim $aOut[1]
            $aOut[0] = 0
        EndIf
        Return $aOut
    Else
        Return StringTrimRight($strFiles, StringLen($sDelim))
    EndIf
EndFunc
Func _ShowSubFolders($Folder, $Ext='*', $Dir=-1, $Delim=@CRLF)
    If Not IsDeclared("strFiles") Then Global $strFiles = ''
    If ($Dir = -1) Or ($Dir = 0) Then
        For $file In $Folder.Files
            If $Ext <> '*' Then
                If StringRight($file.Name, StringLen($Ext)) = $Ext Then _
                    $strFiles &= $file.Path & $Delim
            Else
                $strFiles &= $file.Path & $Delim
            EndIf
        Next
    EndIf
    For $Subfolder In $Folder.SubFolders
        If ($Dir = -1) Or ($Dir = 1) Then $strFiles &= $Subfolder.Path & '\' & $Delim
        _ShowSubFolders($Subfolder, $Ext, $Dir, $Delim)
    Next
EndFunc
Edited by svatvn

Share this post


Link to post
Share on other sites



no one?

Share this post


Link to post
Share on other sites

svatvn,

Re-read your questions and look at your examples...the answer to each of your questions is in the other question...

Kylomas


Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

hi,

i havent written both codes. i found them on google.

I tried to figure out the trick to use and not to use subfolders, but I'm not a programmer.

both codes seems to be too complicated to me....

could you show me which part is important?

Edited by svatvn

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0