Page 1 of 1 1
Topic Options
#195121 - 2009-07-30 07:20 AM Dual monitors using UDF
xempa Offline
Fresh Scripter

Registered: 2006-08-12
Posts: 37
Hi

I'm not sure how to query a second monitor with this UDF. Any help here would be appreciated cheers. I see there is a reference to "DesktopMonitor2" but not sure how to use it in this context ?

 Code:
$Bitmap1 = '\\server\netlogon\Kix2EXE\Wall800.bmp'
$Bitmap2 = '\\server\netlogon\Kix2EXE\Wall1024.bmp'
$Bitmap3 = '\\server\netlogon\Kix2EXE\Wall1280.bmp'

FUNCTION DoWall($HKCU)
? "Setting HKCU Wallpaper to " + $HKCU + "..." ?
 $=WriteValue("HKCU\Control Panel\Desktop","Wallpaper","",REG_SZ)
 $WallpaperMode = "1"
 $=WriteValue("HKCU\Control Panel\Desktop","Wallpaper","$HKCU",REG_SZ)
 $=WriteValue("HKCU\Control Panel\Desktop","WallpaperStyle","2",REG_SZ)
 $=WriteValue("HKCU\Control Panel\Desktop","TileWallpaper","0",REG_SZ)
 $=SetWallpaper($HKCU, $WallpaperMode)
 ENDFUNCTION


$wmiColl = GetObject("WinMgmts:root/cimv2").ExecQuery("Select * FROM Win32_DesktopMonitor")
For Each $wmiObj In $wmiColl
	Select
		Case $wmiObj.DeviceID = "DesktopMonitor1"
			$screenres1 = CSTR($wmiObj.ScreenWidth) + "x" + CSTR($wmiObj.ScreenHeight)
                        Case $wmiObj.DeviceID = "DesktopMonitor2"
			$screenres2 = CSTR($wmiObj.ScreenWidth) + "x" + CSTR($wmiObj.ScreenHeight)
	EndSelect
        Next

 
select
 
case $screenres1 = "800x600"
       DoWall ($Bitmap1)


 case $screenres1 = "1024x768"
     DoWall ($Bitmap2 )
 
 case $screenres1 = "1280x800"
    DoWall ($Bitmap3)
  
case 1
 ? "No standard screen resolution detected defaulting to none..................................."  
   DoWall ($Bitmap2 )
    ; Must be using some other resolution
 endselect


Edited by Mart (2009-07-31 09:03 PM)
Edit Reason: Added code tags.

Top
#195143 - 2009-07-30 02:38 PM Re: Dual monitors using UDF [Re: xempa]
Gargoyle Offline
MM club member
*****

Registered: 2004-03-09
Posts: 1597
Loc: Valley of the Sun (Arizona, US...
From a casual glance of your script,
If you are actually getting a value for $screenres2, you are not doing anything with it.
Change you Select to something like this...
 Code:
select

case $screenres1 = "800x600" or $screenres2 = "800x600"
DoWall ($Bitmap1)


case $screenres1 = "1024x768" or $screenres2 = "1024x768"
DoWall ($Bitmap2 )

case $screenres1 = "1280x800" or $screenres2 = "1280x800"
DoWall ($Bitmap3)

case 1
? "No standard screen resolution detected defaulting to none..................................." 
DoWall ($Bitmap2 )
; Must be using some other resolution
endselect 


I do not see any code for what $HKCU is, and how you are selecting which screen you are actually changing in the DoWall() function.
_________________________
Today is the tomorrow you worried about yesterday.

Top
#195145 - 2009-07-30 05:44 PM Re: Dual monitors using UDF [Re: Gargoyle]
Radimus Moderator Offline
Moderator
*****

Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
firstly this is probably the most efficient method:
 Code:
$wmiColl = GetObject("WinMgmts:root/cimv2").ExecQuery("Select * FROM Win32_DesktopMonitor")
For Each $wmiObj In $wmiColl
	if $wmiObj.PNPDeviceID > ' '
		$res = CSTR($wmiObj.ScreenWidth)
		$nul = setwallpaper('\\server\netlogon\Kix2EXE\Wall'+$res+'.bmp',$WallpaperMode)
	endif
Next


Second, it will work because:
you cannot set a different wallpaper per monitor
people can have monitors with different resolutions
_________________________
How to ask questions the smart way <-----------> Before you ask

Top
#195186 - 2009-07-31 05:44 PM Re: Dual monitors using UDF [Re: Radimus]
xempa Offline
Fresh Scripter

Registered: 2006-08-12
Posts: 37
Hi Radimus yes that does makes sense using $res to get the width size and applying it to the name of the bitmap is certainly cleaner and faster. But how do you tell this script to use a default wallpaper in the event the wallpaper doesn't exist ?

Many thanks

I've tried to use a an if statement as below

 Code:
$Bitmap = '\\Server\netlogon\Kix2EXE\Wall'



FUNCTION DoWall($HKCU)

? "Setting HKCU Wallpaper to " + $HKCU + "..." ?

 $=WriteValue("HKCU\Control Panel\Desktop","Wallpaper","",REG_SZ)

 $WallpaperMode = "1"

 $=WriteValue("HKCU\Control Panel\Desktop","Wallpaper","$HKCU",REG_SZ)

 $=WriteValue("HKCU\Control Panel\Desktop","WallpaperStyle","2",REG_SZ)

 $=WriteValue("HKCU\Control Panel\Desktop","TileWallpaper","0",REG_SZ)

 $=SetWallpaper($HKCU, $WallpaperMode)

 ENDFUNCTION





 $wmiColl = GetObject("WinMgmts:root/cimv2").ExecQuery("Select * FROM      Win32_DesktopMonitor")

  For Each $wmiObj In $wmiColl

  $res = CSTR($wmiObj.ScreenWidth) 

  DoWall('$BitMap'+$res+'.bmp')

  Next


e.g I've tried the following but cannot capture the value of $res at this point

 Code:
  $wmiColl = GetObject("WinMgmts:root/cimv2").ExecQuery("Select * FROM Win32_DesktopMonitor")

  if not exits ('$BitMap'+$res+'.bmp')
  DoWall($BitMap"Default.bmp")

  Else

  For Each $wmiObj In $wmiColl

  $res = CSTR($wmiObj.ScreenWidth)

  DoWall('$BitMap'+$res+'.bmp')

  Next

  Endif


Edited by Mart (2009-07-31 09:01 PM)
Edit Reason: Added code tags.

Top
#195202 - 2009-07-31 09:02 PM Re: Dual monitors using UDF [Re: xempa]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4669
Loc: The Netherlands
Please use the code tags when posting code in future posts. I added them for you this time.
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#195215 - 2009-08-01 11:56 PM Re: Dual monitors using UDF [Re: Mart]
xempa Offline
Fresh Scripter

Registered: 2006-08-12
Posts: 37
Hi many thanks to all particuarly Radimus. The solution that works for me is as follows.

Apologies Mart, if this code is not in the code tag area,I can't see any option to choose this with a response





$wmiColl = GetObject("WinMgmts:root/cimv2").ExecQuery("Select * FROM Win32_DesktopMonitor")
For Each $wmiObj In $wmiColl
if $wmiObj.PNPDeviceID > ' '
$res = CSTR($wmiObj.ScreenWidth)
DoWall($Bitmap1)
Endif
$res = CSTR($wmiObj.ScreenWidth)
if exist('$BitMap'+$res+'.bmp')
DoWall('$BitMap'+$res+'.bmp')
Else
DoWall($Bitmap1)
Endif
Next

Top
#195216 - 2009-08-02 12:29 AM Re: Dual monitors using UDF [Re: xempa]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4367
Loc: New Jersey
Choose the "reply" link from the bottom of the posting instead of using the "Quick Reply" window. That will provide the formatting menu. The Quick Reply window assumes you're familiar with entering UBB tags manually. You can simply type "[ code ]" at the start of your script and "[ /code ]" at the end, but without the spaces.

Edit your post your self and add the code tags so you see what we mean. Once you know how, it's easy. ;\)

Google "UBB Tags" to see what they are - similar to HTML, but used in these types of BBS systems so the message format is differentiated from HTML.

Glenn
_________________________
Actually I am a Rocket Scientist! \:D

Top
Page 1 of 1 1


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 318 anonymous users online.
Newest Members
Kelly001, MichaelK72, Janneman, standardbruker, maikoenig2001
17773 Registered Users

Generated in 0.034 seconds in which 0.013 seconds were spent on a total of 13 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org