2012-07-30 129 views
1

桌面背景更新,我已經有一個鏈接http://cam.sheratonamsterdamairportview.com/view_live1.jpg。 此鏈接鏈接到史基浦機場的相機,每20秒拍攝一張照片。通過鏈接

我真的想要得到這張照片,每20秒更新我的desktopbackground。那可能嗎?

我需要做一個程序或可我一招鏈接呢?我正在運行Windows 7 btw。

+0

對於一個完整的程序解決方案看對方的回答,對於一招,這將很好地工作,只需要一個小程序來更新圖像,只需使用標準的幻燈片放映功能在Windows後臺再看看我的答案。 – 2012-07-30 10:15:04

+0

@喬恩·泰勒 - >有什麼好處時,戴維希望有從相機不斷更新隨機圖片幻燈片? – mnmnc 2012-07-30 10:18:03

+0

@mnmnc我猜你還沒有仔細閱讀我的答案。隨機圖片更新只是爲了讓Windows更新圖片。實際上只有目錄中的一張照片纔會完全不隨機。每次從服務器輪詢時,都會覆蓋目錄中唯一的照片。 – 2012-07-30 10:20:39

回答

1

那麼做是創建一個程序,它覆蓋目錄中的單張照片的一個相當簡單的方法。然後讓Windows(在後臺設置中)進行幻燈片放映,並從該目錄中每隔20秒選擇一張隨機照片。

+0

OP想要從相機不斷更新,那麼隨機幀會有什麼好處?一個月之後,他將有非常小的機會實際看到當前的圖片。 – mnmnc 2012-07-30 10:14:32

+1

爲什麼?這樣可以很好地工作,並且你總是會有一張更新的照片,最多它會出現的時間是19秒,而且無論如何這都會隨着時間的推移而自行改正。避免這種情況的唯一方法是更頻繁地進行輪詢,或者在更新映像時從服務器進行某種回調。由於服務器不會提供任何形式的回調,因此確保其完全按時更新的唯一可能方式是更頻繁地進行輪詢。無論你使用完整的程序來實現這一點還是我提到的方式,這個輪詢頻率將成爲決定性因素 – 2012-07-30 10:18:23

2

如果您使用的是Windows XP,你可以簡單地在桌面上添加活動內容。 >屬性 - - >桌面選項卡 - > 自定義桌面 - > Web選項卡 - 在桌面上

鼠標右鍵>新建 - >位置 「WWW」

設置您的網址和激活的內容。你將在桌面上看到一個小型的窗口,裏面有來自相機的圖片。如果它不會自動刷新,那麼創建一個簡單的頁面,其中包含20秒內的元刷新,以及帶鏈接的src屬性設置的img標籤。

林不知道,如果上述工作爲Vista/7。


否則

這將可能對你有用:

'Set the wallpaper 
strComputer = "." 
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2") 
Set colItems = objWMIService.ExecQuery("Select * from Win32_VideoController",,48) 
Set WshShell = WScript.CreateObject("WScript.Shell") 
Set WshSysEnv = WshShell.Environment("Process") 
Set objFSO = CreateObject("Scripting.FileSystemObject") 
    WinPath = WshSysEnv("SystemRoot") & "\YourWallpaper.bmp" 

If Not objFSO.FileExists(winpath) then 
'If the file does not exist then copy it 
    For Each objItem in colItems 
     sourcePath = "\\path\here\" 
     rightSize = "NameHere" & objItem.CurrentHorizontalResolution & "x" & objItem.CurrentVerticalResolution & ".bmp" 
     objFSO.CopyFile sourcePath & rightSize, WSHShell.ExpandEnvironmentStrings ("%SystemRoot%") & "\NameYourWallpaper.bmp", overwrite = True 
    Next 
End If 
'************************************************************************************************************************************************ 
'Set Wallpaper Bitmap to Default 
Set WshShell = CreateObject("WScript.Shell") 
Set objFSO = CreateObject("Scripting.FileSystemObject") 

sWinDir = objFSO.GetSpecialFolder(0) 
sWallPaper = sWinDir & "\NameYourWallpaper.bmp" 

' update in registry 
WshShell.RegWrite "HKCU\Control Panel\Desktop\Wallpaper", sWallPaper 
WshShell.Regwrite "HKCU\Software\Microsoft\Internet Explorer\Desktop\General\Wallpaper", sWallPaper 
WshShell.Regwrite "HKCU\Software\Microsoft\Internet Explorer\Desktop\General\BackupWallpaper", sWallPaper 
' let the system know about the change 
WshShell.Run "%windir%\System32\RUNDLL32.EXE user32.dll,UpdatePerUserSystemParameters", 1, True 

這是VBscript的,這將改變桌面背景和事後重新加載您的個人資料,讓你看到的變化。

或者,如果你想要更多的東西這裏是你應該看看代碼:

這個例子演示了許多有用的技術,包括: 從隨機列表選取一個文件。 設置桌面壁紙。 設置桌面牆紙風格(居中,平鋪或拉伸)。 寫入註冊表項。 將文件移入廢紙簍。 使用系統的默認編輯器編輯文件。 程序啓動時(以及您單擊「應用」按鈕時),程序會調用ReadFiles。該例程讀取指定目錄中文件的名稱,並保存以BMP,GIF,JPG和JPEG格式結尾的文件。加載所有文件名後,例程調用RandomizeNames來隨機化列表。

Sub ReadFiles() 
Dim file As String 
Dim ext As String 

    ' Create the new file name collection. 
    Set FileNames = New Collection 

    ' Get the file names. 
    file = Dir(DirName & "\*.*") 
    Do While file <> "" 
     If LCase$(file) <> "temp.bmp" Then 
      ext = UCase$(Right$(file, 4)) 
      If ext = ".BMP" Or ext = ".GIF" Or _ 
       ext = ".JPG" Or ext = "JPEG" _ 
       Then _ 
        FileNames.Add file 
     End If 
     file = Dir() 
    Loop 

    NumNames = FileNames.Count 
    RandomizeNames 
End Sub 

子程序RandomizeNames使得指數與文件名集合中的一個條目每個名字的數組。對於i = 1到NumNames - 1,例程選擇一個隨機索引並將其交換到位置i。

Private Sub RandomizeNames() 
Dim idx As Integer 
Dim tmp As Integer 
Dim i As Integer 

    ReDim Indexes(1 To NumNames) 
    For i = 1 To NumNames 
     Indexes(i) = i 
    Next i 

    ' Randomize them. 
    For i = 1 To NumNames - 1 
     idx = Int((NumNames - i + 1) * Rnd + i) 
     tmp = Indexes(i) 
     Indexes(i) = Indexes(idx) 
     Indexes(idx) = tmp 
    Next i 

    ' Point to the index to display. 
    NextIndex = 1 
End Sub 

當定時器觸發時,程序調用演出文件顯示在列表中隨機下一個文件。

Private Sub SwitchTimer_Timer() 
Dim secs As Long 
Dim pic As Integer 

    ' See if it's time yet. 
    secs = DateDiff("s", Now, NextTime) 
    If secs <= 1 Then 
     If FileNames.Count > 1 Then 
      pic = Indexes(NextIndex) 
      NextIndex = NextIndex + 1 
      If NextIndex > NumNames Then RandomizeNames 

      ShowFile FileNames(pic) 
     End If 
     NextTime = DateAdd("s", Pause, Now) 
     secs = Pause 
    End If 

    If secs <= 60 Then 
     SwitchTimer.Interval = secs * 1000 
    Else 
     SwitchTimer.Interval = 60000 
    End If 
    SwitchTimer.Enabled = True 
End Sub 

子例程ShowFile檢查Style組合框並設置註冊表項以使桌面圖像居中,平鋪或拉伸。 接下來,如果該文件是一個位圖文件,程序只是調用SystemParametersInfo API函數來設置桌面背景圖片。

如果文件不是位圖文件,程序加載到一個隱藏的圖片框,然後保存圖像爲位圖文件。然後它調用SystemParametersInfo。

Private Sub ShowFile(ByVal file_name As String) 
Const STYLE_CENTERED As String = "0" 
Const STYLE_TILED As String = "1" 
Const STYLE_STRETCHED As String = "2" 
Const TILE_NO As String = "0" 
Const TILE_YES As String = "1" 

Dim had_error As Boolean 

    ' Set the display style. 
    had_error = False 
    Select Case cboStyle.Text 
     Case "Centered" 
      If SetRegistryValue(HKEY_CURRENT_USER, _ 
       "Control Panel\Desktop", "TileWallpaper", _ 
        TILE_NO) _ 
        Then had_error = True 
      If SetRegistryValue(HKEY_CURRENT_USER, _ 
       "Control Panel\Desktop", "WallpaperStyle", _ 
        STYLE_CENTERED) _ 
        Then had_error = True 
     Case "Tiled" 
      If SetRegistryValue(HKEY_CURRENT_USER, _ 
       "Control Panel\Desktop", "TileWallpaper", _ 
        TILE_YES) _ 
        Then had_error = True 
      If SetRegistryValue(HKEY_CURRENT_USER, _ 
       "Control Panel\Desktop", "WallpaperStyle", _ 
        STYLE_TILED) _ 
        Then had_error = True 
     Case "Stretched" 
      If SetRegistryValue(HKEY_CURRENT_USER, _ 
       "Control Panel\Desktop", "TileWallpaper", _ 
        TILE_NO) _ 
        Then had_error = True 
      If SetRegistryValue(HKEY_CURRENT_USER, _ 
       "Control Panel\Desktop", "WallpaperStyle", _ 
        STYLE_STRETCHED) _ 
        Then had_error = True 
    End Select 
    If had_error Then 
     MsgBox "Error saving desktop style to registry.", _ 
      vbOKOnly, "Registry Error" 
    End If 

    ' Display the file. 
    FileLabel.Caption = file_name 
    m_CurrentFile = DirName & "\" & file_name 
    If UCase$(Right$(file_name, 4)) = ".BMP" Then 
     SystemParametersInfo SPI_SETDESKWALLPAPER, _ 
      0, m_CurrentFile, SPIF_UPDATEINIFILE 
    Else 
     HiddenPict.Picture = LoadPicture(m_CurrentFile) 
     SavePicture HiddenPict.Picture, DirName & _ 
      "\temp.bmp" 
     SystemParametersInfo SPI_SETDESKWALLPAPER, _ 
      0, DirName & "\temp.bmp", _ 
      SPIF_UPDATEINIFILE 
    End If 
End Sub 

當您單擊編輯按鈕時,該程序使用ShellExecute API函數編輯當前圖片文件。

Private Sub cmdEdit_Click() 
    ShellExecute ByVal 0&, "edit", m_CurrentFile, _ 
     vbNullString, vbNullString, SW_SHOWMAXIMIZED 
End Sub 

當您單擊刪除按鈕,程序調用子程序的DeleteFile將文件移動到廢紙簍。然後顯示下一張照片。

Private Sub cmdDelete_Click() 
    ' Delete the file. 
    DeleteFile m_CurrentFile, False 

    ' Display the next file. 
    cmdNext_Click 
End Sub 

子程序DeleteFile使用SHFileOperation API函數將文件移動到垃圾箱,可選地要求用戶確認。

Public Sub DeleteFile(ByVal file_name As String, ByVal _ 
    user_confirm As Boolean) 
Dim op As SHFILEOPSTRUCT 

    With op 
     .wFunc = FO_DELETE 
     .pFrom = file_name 
     If user_confirm Then 
      ' Make the user confirm. 
      .fFlags = FOF_ALLOWUNDO 
     Else 
      ' Do not make the user confirm. 
      .fFlags = FOF_ALLOWUNDO Or FOF_NOCONFIRMATION 
     End If 
    End With 
    SHFileOperation op 
End Sub 

here

+0

我認爲這是他想要做的事情的頂部。 – 2012-07-30 10:07:04

+0

你可能是對的。儘管我已經用VBscript解決方案更新了我的答案。 – mnmnc 2012-07-30 10:10:44

0

採取什麼樣的東西就是這樣,需要約30秒敲了一個WinForms應用程序。 不是最好的解決方案,而是一個快速而骯髒的起點。

1)製作的文件夾例如C:/wallpaper並告訴Windows使用該文件夾爲您的背景使用幻燈片。

2)快速.NET腳本下載最新的圖像

public bool running = true; 
while(running){ 
string local= @"C:\wallpaper\localFile.jpg"; 
using(WebClient client = new WebClient()) 
{ 
    client.DownloadFile("http://cam.sheratonamsterdamairportview.com/view_live1.jpg", 
    System.Threading.Thread.Sleep(20000); //Wait 20 seconds. 
} 

} 

然後有,當你要退出,使得運行虛假的按鈕。 Windows將永遠看這裏,當圖像變化都會改變 - 或者如果你有使用該文件夾上的幻燈片它應該做的。 (幻燈片放映是一種在無需載入代碼的情況下快速解決緩存問題的快速方法) - 此外,即使您沒有對計算機的管理權限,也可以使用這種方式。

+0

如果這是一個項目,顯然不是最好的方法,但如果只是爲了個人使用,它應該沒問題。緩存*不應該是一個問題,但如果是這樣,只保存最後使用的文件名,使用迭代器或其他名稱在最後用隨機數命名新的文件名,然後刪除舊文件。 – JustAnotherDeveloper 2012-07-30 10:39:35