[Webinar] Streamline your web hosting managementRegister Today

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 260
  • Last Modified:

How to have Daisy Fuentes?

I've got this really cool and seductive picture of Daisy which I want to use for a wallpaper on my pc at work.  Unfortunately, people sometimes pop in to my cubicle, and they might not think my wallpaper is appropriate.  So...I want to write a little program /TSR for Win 95/NT.  The idea is that I could just quickly hit a hot key, say F12, and the wallpaper would change to something more acceptable (Although far more boring).  
     Can someone show me the code to change wallpapers, and how to get the program to run sort of like an NT service, but which would allow the quick hot key.  Maybe theres already a program to do this, so pointing me to that would be just as good.  I wish I could offer more points, but know that you will be helping many a man with this question!

:) dapperry
  • 5
  • 3
1 Solution
dapperryAuthor Commented:
Oh yeah, if anyone wants the picture just leave your email address.

:) dapperry
Here is Daisy!
Pressing F12 will toggle the wallpaper between the 2 images you setup in Form_Load.

Private Sub Form_Load()
    lHotkey = &HBF0F&
    'Setup your 2 images to swap here
    sWP1 = "c:\windows\Internet Explorer Wallpaper.bmp"
    sWP2 = "c:\windows\waves.bmp"
    'F12 is the hotkey to swap images
    Call RegisterHotKey(Me.hwnd, lHotkey, 0&, vbKeyF12)
    'Hook into the message stream to catch WM_HOTKEY message
    glPrevWndProc = fSubClass()
End Sub

Private Sub Form_Unload(Cancel As Integer)
    ' Stop intercepting messages.
    Call pUnSubClass
    Call UnregisterHotKey(Me.hwnd, lHotkey)
End Sub

Option Explicit

Public Const GWL_WNDPROC = (-4)
Declare Function SystemParametersInfo Lib "user32" Alias _
    "SystemParametersInfoA" (ByVal uAction As Long, ByVal uParam _
    As Long, ByVal lpvParam As Any, ByVal fuWinIni As Long) As Long
Declare Function RegisterHotKey Lib "user32" _
    (ByVal hwnd As Long, ByVal id As Long, _
    ByVal fsModifiers As Long, ByVal vk As Long) As Long
Declare Function UnregisterHotKey Lib "user32" _
    (ByVal hwnd As Long, ByVal id As Long) As Long

Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" _
    (ByVal hwnd As Long, ByVal nIndex As Long, _
    ByVal dwNewLong As Long) As Long
Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" _
    (ByVal lpPrevWndFunc As Long, ByVal hwnd As Long, _
    ByVal Msg As Long, ByVal wParam As Long, _
    ByVal lParam As Long) As Long
Public Const WM_HOTKEY = &H312

Public sWP1 As String
Public sWP2 As String
Public lHotkey As Long
Public glPrevWndProc As Long
Private bToggle As Boolean

Public Sub pUnSubClass()
' Stops the form from intercepting Window's messages
' by resetting the default procedures associated
' with the form.
Call SetWindowLong(Form1.hwnd, GWL_WNDPROC, glPrevWndProc)
End Sub

Public Function pMyWindowProc(ByVal hw As Long, ByVal uMsg As Long, _
    ByVal wParam As Long, ByVal lParam As Long) As Long
' This is the callback procedure used when a message is received
' by this form.  The desired message is processed and all others are
' passed back to the original procedure associated with the form.
If uMsg = WM_HOTKEY Then
    If wParam = lHotkey Then
        If Not bToggle Then
            Call SetWallpaper(sWP2)
            Call SetWallpaper(sWP1)
        End If
        bToggle = Not bToggle
    End If
End If

pMyWindowProc = CallWindowProc(glPrevWndProc, hw, uMsg, wParam, lParam)
End Function

Public Function fSubClass() As Long
' Subclass the form by replacing the "normal" procedures associated
' with the form with procedure "pMyWindowProc".
' NOTE: Comment all calls to fSubClass while in IDE.
fSubClass = SetWindowLong(Form1.hwnd, GWL_WNDPROC, AddressOf pMyWindowProc)
End Function

Public Sub SetWallpaper(ByVal FileName As String)
    Dim x As Long
    x = SystemParametersInfo(SPI_SETDESKWALLPAPER, _
End Sub
dapperryAuthor Commented:
I will try to implement this code this afternoon, and will get back to you soon on how it works out.  Thanks.

:) dapperry
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

dapperryAuthor Commented:
Ok, the code works great!  The only part of the question is how to make it work as a service, or hidden, or at least in the sys tray.  Let me know what the best thing to do here would be.  I think it would be great if it was hidden, but you could hit another hot key to bring up the form.  Then in the form you could choose the wallpapers to switch.  (In case I get any more sexy shots of Daisy!) Let me know, and thanks for your help thus far.

:) dapperry
The best option would be to make the program reside in the system tray.  You can have the program startup hidden or minimized in the tray.  To restore the program, use the tray icon.

Here is a MS article which shows how to put your program into the system tray:

dapperryAuthor Commented:
It works great.  Thanks a lot.  BTW, please check out my new question, or how to determine/remove a shortcut from the startup.

:) dapperry
dapperryAuthor Commented:
      Just an update.  I completed my program.  It seems to work fine on Win 95, but the hot keys seem to have no effect in Win NT 4.  Any idea why?

:) dapperry
Here's what MS says about RegisterHotkey:

Return Values
If the function succeeds, the return value is nonzero.
If the function fails, the return value is zero.

[check to make sure RegisterHotkey returns a nonzero number]

RegisterHotKey fails if the keystrokes specified for the hot key have already been registered by another hot key.

[make sure F12 is not already a reserved hotkey]

Featured Post

[Webinar] Improve your customer journey

A positive customer journey is important in attracting and retaining business. To improve this experience, you can use Google Maps APIs to increase checkout conversions, boost user engagement, and optimize order fulfillment. Learn how in this webinar presented by Dito.

  • 5
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now