Page 1 of 1

multiple monitors and random wallpapers

Posted: Tue Oct 28, 2003 1:50 am
by blueznl
Code updated For 5.20+

want to change your wallpapers? here's something small

i'll polish it a little the coming days, it shows some unexpected behaviour in combination with ultramon profiles i've been told, looks like ultramon replaces whatever background with its own... hmm...

Code: Select all

; twowalls v1 28.10.2003
;
; manage (well, sort of) wallpapers for dual monitor setups
;
; what does it do?
;
; - read all images in current subdir
; - read a 'preselection' list
; - generate combo bitmap
; - tile and refresh
;
; how to install
;
; - put all images )bmp and / or jpg) in a folder
; - add twowall.exe to the mix
; - edit the _combolist.txt if you want (format: <filename1> , <filename2> <cr>)
; - doubleclick twowall.exe and voila, different backgrounds
; - add twowall.exe to startup to change the paper on every reboot
; - add a parameter if you don't want the refresh now (twowall.exe /no)
;
; notes on filenames:
;
; - images that start with the same two letters are often combined
; - images that start with du_ are treated differently (dual screen images)
;
; path.s="c:\software\backgnds\"
path.s=""
;
UseJPEGImageDecoder()
;
NewList namelist.s()
;
; retrieve screen size
;
screen_w = GetSystemMetrics_(#SM_CXSCREEN)
screen_h = GetSystemMetrics_(#SM_CYSCREEN)
;
; set desktop wallpaper tiling on using the registry
;
topkey = #HKEY_CURRENT_USER
subkey.s = "Control Panel\Desktop"
handle = 0
RegOpenKeyEx_(topkey,subkey,0,#KEY_ALL_ACCESS,@handle)
value.s = "TileWallPaper"
buffer.s = "1"
buffer_l = Len(buffer)
RegSetValueEx_(handle,@value,0,#REG_SZ,buffer,buffer_l)
RegCloseKey_(handle)
;
variation = Random(5)               ; decide how to combine two images
;
If variation = 0                    ; use something from the preselect list
  If FileSize(path+"_combolist.txt")>0
    OpenFile(1,path+"_combolist.txt")
    Repeat
      name.s = LCase(Trim(ReadString(1)))
      If FindString(name,",",1)>0
        AddElement(namelist())
        namelist() = name
      EndIf
    Until Eof(1)
    CloseFile(1)
    pick = Random(CountList(namelist())-1)
    SelectElement(namelist(),pick)
    file1.s = Trim(Left(namelist(),FindString(namelist(),",",1)-1))
    file2.s = Trim(Mid(namelist(),FindString(namelist(),",",1)+1,255))
  EndIf
Else
  ;                                 ; okay, so not from the preselect list
  ;
  If ExamineDirectory(1,path,"*.*")
    Repeat
      type = NextDirectoryEntry(1)
      If type = 1
        name.s = LCase(DirectoryEntryName(1))
        If Left(name,1) <> "_"
          If Right(name,4) = ".bmp" Or Right(name,4) = ".jpg"
            AddElement(namelist())
            namelist() = name
          EndIf
        EndIf
      EndIf   
    Until type = 0
  EndIf
  namelist_n = CountList(namelist())
  ;
  pick1 = Random(namelist_n-1)
  SelectElement(namelist(),pick1)
  file1.s = namelist()
  Repeat                              ; no dual screen images for monitor 2
    pick2 = Random(namelist_n-1)
    SelectElement(namelist(),pick2)
    file2.s = namelist()
  Until Left(file2,2)<>"du"
  ;
  Select variation
    Case 1                            ; both screens random
    Case 2                            ; 1 = random , 2 = old screen 1
      file2 = "_single.bmp"
    Case 3                            ; both screens identical
      file2 = file1
    Default                           ; (4 and 5) pick 2 starting with the same 2 chars
      n = 0
      Repeat
        pick2 = Random(namelist_n-1)
        SelectElement(namelist(),pick2)
        file2.s = namelist()
      Until Left(file2,2) = Left(file1,2) Or n = 25         
  EndSelect
EndIf
;
; almost done, now cover dual screen images
;
If Left(file1,2)="DU"
  If LoadImage(1,path+file1)<>0
    ResizeImage(1,screen_w*2,screen_h)
    SaveImage(1,path+"_combo.bmp")
    FreeImage(1)
  EndIf
Else
  If LoadImage(1,path+file1)<>0
    If LoadImage(2,path+file2)<>0
      ResizeImage(1,screen_w,screen_h)
      ResizeImage(2,screen_w,screen_h)
      CreateImage(3,screen_w*2,screen_h)
      StartDrawing(ImageOutput(3))
      DrawImage(ImageID(1),0,0)
      DrawImage(ImageID(2),screen_w,0)
      StopDrawing()
      SaveImage(1,path+"_single.bmp")
      SaveImage(3,path+"_combo.bmp")
      FreeImage(1)
      FreeImage(2)
      FreeImage(3)
    EndIf
  EndIf
EndIf
;
; change the wallpaper and tell windows to refresh the desktop
;
file.s = path+"_combo.bmp"
;
If ProgramParameter()=""
  SystemParametersInfo_(#SPI_SETDESKWALLPAPER,0,@file,#SPIF_SENDWININICHANGE)
EndIf



Posted: Fri Jan 23, 2004 11:20 am
by DriakTravo
RegOpenKeyEx_(topkey,subkey,0,#KEY_ALL_ACCESS,@handle)
(Line 43)
It says to me that this is not a function, array, or linked list. They may of changed it in a current version of PB?

Posted: Fri Jan 23, 2004 1:12 pm
by blueznl
you're using a registered version?

Posted: Fri Jan 23, 2004 1:13 pm
by blueznl
works fine on my machine (3.81)

Code: Select all

; purebasic survival guide
; registry - 10.11.2003 ejn (blueznl)
; http://www.xs4all.nl/~bluez/datatalk/pure1.htm
;
; - read from and write to registry
;
;
;
; *** create a new key
;
topkey.l = #HKEY_CURRENT_USER
subkey.s = "Control Panel\Desktop2"
handle.l = 0
result.l = 0
If RegCreateKeyEx_(topkey,@subkey,0,0,#REG_OPTION_NON_VOLATILE,#KEY_ALL_ACCESS,0,@handle,@result)=0
  Debug "creation okay"
  RegCloseKey_(handle)
EndIf
;
; *** delete a key
;
If RegDeleteKey_(topkey,@subkey)=0
  Debug "deletion okay"
Else
  Debug "error deleting"
EndIf
;
; *** open key
;
topkey.l = #HKEY_CURRENT_USER
subkey.s = "Control Panel\Desktop"
handle.l = 0
If RegOpenkeyEx_(topkey,@subkey,0,#KEY_ALL_ACCESS,@handle)=0
  ;
  ; *** set or create a value
  ;
  name.s = "TileWallPaper"
  buffer.s = "1"
  buffer_l.l = Len(buffer)
  RegSetValueEx_(handle,@name,0,#REG_SZ,buffer,buffer_l)
  ;
  Debug "value set"
  Debug buffer
  ;
  ; *** read a value
  ;
  buffer_l.l = 255                                                    ; length of buffer
  buffer.s = Space(valuebuffer_l)                                     ; buffer for returned data
  type.l = 0                                                          ; type of data in buffer
  If RegQueryValueEx_(handle,@name,0,@type,@buffer,@buffer_l)=0      
    ;
    ; data found, could be different things, see win32.hlp for all possibilities
    ;
    Select type
      Case #REG_DWORD
        value.l = PeekL(@buffer)
      Case #REG_SZ
        value.l = Val(Left(buffer,buffer_l))
    EndSelect
    ;
    Debug "value read"
    Debug value
  EndIf
  ;
  ; *** free handle
  ;
  RegCloseKey_(handle)
EndIf
;