Thanks very much for the code view.
I was very close to what you have there.
Using your registry code line I can now update that value.
The Sendmessage line is still not co-opperating with me.
Here is a clean version of the current code I am now using.
Running in debug mode in VS.net 2005.
Emulating PocketPc WM 5.0
At time of error on the "Sendmessage" line, varible values are;
strKeyName = "HKEY_CURRENT_USER\ControlPanel\Home"
strValueName = BgImage
strWallpaperImageIs = "\\windows\\Guava bubbles.tsk"
HWND_BROADCAST = 65535
SPIF_SENDWININICHANGE = 2
SPI_SETDESKTOPWALLPAPER = 20
Registry Key values:
[Microsoft.Win32.Registry.CurrentUser.OpenSubKey("ControlPanel").OpenSubKey("Home").GetValue("BgImage")]
Using
[objRegistryKey.OpenSubKey("ControlPanel").OpenSubKey("Home").GetValue("BgImage")]
to view it value.
Before: "\\windows\\Guava bubbles_Before.tsk"
After: "\\windows\\Guava bubbles.tsk"
Error Msg on executing the Sendmessage line: NotSupportedException
#Region " Area: Imports"
Imports System.IO 'To read the windows folder for .tsk files
Imports System.Runtime.InteropServices 'For the wallpaper changing API
interface
#End Region
Public Class WPMaster_PPC
#Region " Area: Application wide variables "
'Wallpaper changing API
Public Shared SPI_SETDESKTOPWALLPAPER As Integer = 20
Public Shared SPIF_SENDWININICHANGE As Integer = 2
Public Shared HWND_BROADCAST As IntPtr = IntPtr.op_Explicit(&HFFFF)
#End Region
'<DllImport("coredll.dll")>
Private Declare Function SendMessage Lib "coredll.dll" Alias
"SendMessage" (ByVal hWnd As IntPtr, ByVal Msg As System.Int32, ByVal
wParam
As System.Int32, ByVal lParam As System.Int32)
Private Sub WPMaster_PPC_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim strWhoAmI As String = msApplication & "." & msVersion & "."
&
msFormOn & ".WPMaster_PPC_Load"
Try
initThemeListBox(strWhoAmI)
SetTheWallpaper(strWhoAmI)
Catch ex As Exception
End Try
End Sub
#Region " Area: Sub Procedures "
Private Sub initThemeListBox(ByVal strWhoCalledMe As String)
Dim strWhoAmI As String = msApplication & "." & msVersion & "."
&
msFormOn & ".initThemeListBox"
Try
Dim intFilesInFolder As Integer =
Directory.GetFiles("\Windows\", "*.tsk").Length
Dim intIndex As Integer = 0
While (intIndex < intFilesInFolder)
Dim strFileName As String =
Directory.GetFiles("\Windows\",
"*.tsk").GetValue(intIndex)
strFileName = StrReverse(strFileName)
strFileName = strFileName.Substring(0,
(strFileName.IndexOf("\")))
strFileName = StrReverse(strFileName)
Dim objTheme As New ListViewItem
With objTheme
.Text = strFileName
End With
With lstBoxThemes
.Items.Add(objTheme.Text)
End With
intIndex += 1
End While
Catch ex As Exception
End Try
End Sub
Private Sub SetTheWallpaper(ByVal strWhoCalledMe As String)
Dim strWhoAmI As String = msApplication & "." & msVersion & "."
&
msFormOn & ".SetTheWallpaper"
Dim strKeyName As String = "HKEY_CURRENT_USER\ControlPanel\Home"
Dim strValueName As String = "BgImage" ' "Wallpaper" 'Skin
Dim objRegistryKey As Microsoft.Win32.RegistryKey
Dim strWallpaperImageIs As String = "\\windows\\Guava
bubbles.tsk"
Try
objRegistryKey.SetValue(strKeyName, strValueName,
strWallpaperImageIs)
SendMessage(HWND_BROADCAST, SPIF_SENDWININICHANGE,
SPI_SETDESKTOPWALLPAPER, 0)
Catch ex As Exception
End Try
End Sub
#End Region
End Class
--
Deasun
Home Site:
www.tirnaog.com
Check out: The Code Vault in my forums section.
:
Hi Deasun,
A majority of the generalizable C# code I write for Windows Mobile has
been open sourced at SourceForge in a project called Roam (http://
www.sourceforge.net/projects/roam). The code to programatically switch
wallpaper is found in the DesktopUtils.cs file. Here is a direct link:
http://roam.svn.sourceforge.net/vie...Utils/DesktopUtils.cs?revision=73&view=markup
You can download the entire Roam project via SVN. The license is BSD
so feel free to incorporate any of the code in your project
Jon
---
http://csharponphone.blogspot.com
Hello there,
Would you mind showing the code to do the wallpaper changing?
I have been try to do this for some time now but I am not finding
much
docs
on it.
Its driving me nuts.
{VB/C# .NET code would be best, but I will take anything at this
point
}
Thanks
--
Deasun
Home Site:
www.tirnaog.com
Check out: The Code Vault in my forums section.
:
Yep. My current approach is to:
1. Wait until device goes idle for N minutes
2. Wake up device
3. Set a new background
4. Invalidate the desktop (the entire today screen) and force it
to
update. I was doing this by trying to minimize any open
applications
but this was a hack.
5. Put the device back into idle state
An awful lot of work just to change the desktop wallpaper. Does
anyone
have any sense as to why it takes so long?
j
On May 8, 10:04 am, "Paul G. Tobey [eMVP]" <p space tobey no spam
AT
no instrument no spam DOT com> wrote:
I suppose that you could get the top-level window of the today
screen
application, mark its entire content area as invalid
(InvalidateRect()), and
then force it to update, UpdateWindow(). You'd have to P/Invoke
those, of
course.
Paul T.
Paul,
I have run into this issue as well. I believe what Sunil meant
is
*not* that the redraw is problematic (i.e., of course drawing
an
image
behind the today screen is painless and fast) but rather when
the
INI
change message is received, the new image is *not* applied
until
the
desktop is visible. In other words, broadcasting the INI
message
is
fast (and not the cause of overhead I don't believe)--it's
that
the
actual change in desktop wallpaper does not happen until the
desktop
becomes visible (which could be N minutes after the INI
message
was
sent). This can cause some interesting UI issues. For example,
I
end a
phone call, the phone app minimizes, the desktop becomes top
level and
suddenly I lose control of my phone for 15-30 seconds while
the
background changes. Very disconcerting indeed! Alternatively,
forcing
a background change while the device is idle and the desktop
is
or is
not visible would be preferred.
You can check the "changing wallpaper" overhead for yourself.
Open
Settings->Homescreen->Background Image. Note that the
background
image
is *not* set until the desktop becomes visible for the first
time.
Jon
On May 7, 9:06 am, "Paul G. Tobey [eMVP]" <p space tobey no
spam
AT no
instrument no spam DOT com> wrote:
The wallpaper *is* what is drawn behind the Today screen. It
has no
meaning
that would cause it to be redrawn when some other window is
in
front of
the
today screen.
As far as limiting the effect of the change itself, you could
just send
the
INI change message to the desktop window, I guess. That's
probably the
only
application that cares about it.
Paul T.
I am trying to change the wallpaper of the home screen by
1. resetting the value of BgImage in
HKEY_CURRENT_USER\ControlPanel
\Home to the location of the new wallpaper file
2. Win32Window.SendMessage((IntPtr)HWND_BROADCAST,
WM_WININICHANGE,
SPI_SETDESKWALLPAPER, 0);
It seems that this succeeds, but the desktop is not redrawn
until all
applications are minimized (e.g., the desktop is displayed
as
the top
level application) and the device is not idle. This is not
ideal
behavior, however, as Windows takes control of the device
while
refreshing the wallpaper, making the phone unusable for a
few
seconds.
I want to change the wallpaper without interrupting the
user
of the
phone (e.g., while the device is idle and regardless of
whether or not
the desktop is the top level application), yet it does not
seem like
this is feasible. Any ideas on how to trigger the redraw so
that the
user will never be forced to wait for the change to
complete?
Thanks.