-
Dec 28th, 2019, 12:38 PM
#1
Thread Starter
Fanatic Member
Getting the name of a file
I am using VB6 on WIn 10. I have my desktop background set to change once per day. I want to be able to get the name of the photo and display is on the screen. Displaying it is simple. But how do I get the name in code of the current desktop picture?
Thanks
-
Dec 28th, 2019, 01:16 PM
#2
Re: Getting the name of a file
Try calling this function:
Code:
Private Declare Function lstrlenW Lib "kernel32.dll" (ByVal lpString As Long) As Long
Private Declare Function SysReAllocStringLen Lib "oleaut32.dll" (ByVal pBSTR As Long, Optional ByVal pszStrPtr As Long, Optional ByVal Length As Long) As Long
Private Declare Function SystemParametersInfoW Lib "user32.dll" (ByVal uiAction As Long, ByVal uiParam As Long, ByRef pvParam As Any, ByVal fWinIni As Long) As Long
Public Function GetDesktopWallpaperPath() As String
Const MAX_PATH = 260&, SPI_GETDESKWALLPAPER = &H73&
Dim sBuffer As String
If SysReAllocStringLen(VarPtr(sBuffer), , MAX_PATH - 1&) Then
If SystemParametersInfoW(SPI_GETDESKWALLPAPER, MAX_PATH, ByVal StrPtr(sBuffer), 0&) Then
GetDesktopWallpaperPath = Left$(sBuffer, lstrlenW(StrPtr(sBuffer)))
End If
End If
End Function
-
Dec 28th, 2019, 01:47 PM
#3
Thread Starter
Fanatic Member
Re: Getting the name of a file
That code gives me a directory I cannot reach thru the file explorer. It addition it only gives a dir, not the file name.
-
Dec 28th, 2019, 02:03 PM
#4
Re: Getting the name of a file
Originally Posted by AccessShell
That code gives me a directory I cannot reach thru the file explorer.
What is the path that you're getting from that function? Please post it here.
Originally Posted by AccessShell
It addition it only gives a dir, not the file name.
According to the documentation of SPI_GETDESKWALLPAPER, it "retrieves the full path of the bitmap file for the desktop wallpaper." The full path should contain the filename of the wallpaper. It should be easy enough to extract the filename using a combination of VB6's String functions. Do you want an example?
-
Dec 28th, 2019, 02:07 PM
#5
Thread Starter
Fanatic Member
Re: Getting the name of a file
"C:\Users\Me.DESKTOP-BL62LB2\AppData\Roaming\Microsoft\Windows\Themes\TranscodedWallpaper
-
Dec 28th, 2019, 02:23 PM
#6
Re: Getting the name of a file
Hmm, that's weird. Is "Me.DESKTOP-BL62LB2" really your profile name? Also, did you forget to add the end quotation mark or is the string really truncated?
-
Dec 28th, 2019, 02:24 PM
#7
Thread Starter
Fanatic Member
Re: Getting the name of a file
Yes, I forgot the ". And no it is not Me, it is Shell
-
Dec 28th, 2019, 02:29 PM
#8
Re: Getting the name of a file
Originally Posted by AccessShell
And no it is not Me, it is Shell
What exactly do you mean by "it is Shell"?
-
Dec 28th, 2019, 02:41 PM
#9
Thread Starter
Fanatic Member
Re: Getting the name of a file
C:\Users\Shell.DESKTOP-BL62LB2\AppData\Roaming\Microsoft\Windows\Themes\TranscodedWallpaper
-
Dec 28th, 2019, 03:04 PM
#10
Re: Getting the name of a file
I asked you above what path you were getting and you wrote:
Originally Posted by AccessShell
"C:\Users\Me.DESKTOP-BL62LB2\AppData\Roaming\Microsoft\Windows\Themes\TranscodedWallpaper
But now you're telling me it's actually:
Originally Posted by AccessShell
C:\Users\Shell.DESKTOP-BL62LB2\AppData\Roaming\Microsoft\Windows\Themes\TranscodedWallpaper
I really don't have time to play any games with you. I'll try helping you one last time, so please cooperate!
Start a new Standard EXE project and paste my code above. Then add this code as well:
Code:
Private Sub Form_Load()
MsgBox """" & GetDesktopWallpaperPath & """", vbInformation
Unload Me
End Sub
Now, compile that project and run the resulting EXE. When the message box comes up, press CTRL+C to copy the message and paste it here.
If you still get the same result, then I'm out of ideas.
-
Dec 28th, 2019, 03:08 PM
#11
Thread Starter
Fanatic Member
Re: Getting the name of a file
Same result
C:\Users\Shell.DESKTOP-BL62LB2\AppData\Roaming\Microsoft\Windows\Themes\TranscodedWallpaper
-
Dec 28th, 2019, 03:14 PM
#12
Hyperactive Member
Re: Getting the name of a file
Code from post 2 works for me with exception. I'm on XP. If the wallpaper bitmap fills the entire screen then I get the correct path and file name but if the image only shows in the center of the screen then the path is always the same no matter which picture I select.
Examples:
I select from Display Properties--->Desktop--->Santa Fe Stucco (which covers the entire screen) then I get
C: \Windows\Santa Fe Stucco.bmp
but if I select from Display Properties--->Desktop--->Stonehenge(which only show a square picture centered in the screen) then I get
C: \Documents and Settings\Ordinary Guy\Local Settings\Application Data\Microsoft\Wallpaper1.bmp
I get the above path\filename no matter what the name of the image is that I select
Last edited by Ordinary Guy; Dec 28th, 2019 at 03:33 PM.
-
Dec 28th, 2019, 10:26 PM
#13
Thread Starter
Fanatic Member
Re: Getting the name of a file
I have discovered that "TranscodedWallpaper" is supposed to the file that represents the current background. By copying the file to another place and adding the suffix .jpg you can open with with any photo app. However the photo in "TranscodedWallpaper" is the blue default background, not the photo I have. I checked the CachedFiles subdir and found a file called "CachedImage_1920_1080_POS4.jpg. This is the default blue background.
-
Dec 28th, 2019, 10:57 PM
#14
Fanatic Member
Re: Getting the name of a file
This is what I get on Windows 7:
C:\Users\<MyUserIDHere>\AppData\Roaming\Microsoft\Windows\Themes\TranscodedWallpaper.jpg
-
Jan 24th, 2020, 11:05 PM
#15
Re: Getting the name of a file
Remembered this thread when I came across something today...
In a project with oleexp.tlb, this method gives you the actual image file:
Code:
Dim pAD As ActiveDesktop
Set pAD = New ActiveDesktop
Dim szwp As String
Dim hr As Long
szwp = String$(MAX_PATH, 0)
Const AD_GETWP_LAST_APPLIED = &H2
hr = pAD.GetWallpaper(szwp, MAX_PATH, AD_GETWP_LAST_APPLIED)
If hr = S_OK Then
Debug.Print Left$(szwp, InStr(szwp, vbNullChar) - 1)
Else
Debug.Print "Error 0x" & Hex$(hr)
End If
Worked on both Win7 and Win10.
Last edited by fafalone; Jan 24th, 2020 at 11:24 PM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|