Results 1 to 13 of 13

Thread: [RESOLVED] Stick an app to the desktop background

  1. #1

    Thread Starter
    Pro Grammar chris128's Avatar
    Join Date
    Jun 2007
    Location
    England
    Posts
    7,604

    Resolved [RESOLVED] Stick an app to the desktop background

    Bit of a strange request and I don't think it is possible to do what I want but just thought I would check and see if anyone had any suggestions.

    I would like to have my application basically appear as if it was part of the desktop background, I've removed the form border etc and made the background colour of the form the same as our standard company background so it all blends in nicely. I have also made it so the app does not appear in the toolbar and it is set to launch on startup so it appears as soon as the user logs in - so all works fine and looks fine because any new apps that the user opens will open on top of my app. The only problem is that if they press the Show Desktop button (or use Windows Key + D) to minimize all apps, mine gets minimized as well and disappears. Its easy enough to get the user to make it appear again as it has a system tray icon that they can interact with, but it would be better if it just didn't vanish when they did this.

    Now I know the best thing for this on Windows 7 would be a Gadget but the problem is that Gadget's annoyingly have to be HTML/javascript and a) I'm not great with web coding and b) I don't think it is even possible to do what my app does from a HTML/javascript page... oh and c) I can't find any way to deploy gadgets in a business network (there is no way we are installing it manually on all 300 of our PCs), so the gadget idea is not looking very promising.

    Any thoughts? I'm wondering if there is some window message I can capture and ignore in the WndProc event handler but so far google hasn't helped much...

    Cheers
    Chris
    My free .NET Windows API library (Version 2.2 Released 12/06/2011)

    Blog: cjwdev.wordpress.com
    Web: www.cjwdev.co.uk


  2. #2

    Thread Starter
    Pro Grammar chris128's Avatar
    Join Date
    Jun 2007
    Location
    England
    Posts
    7,604

    Re: Stick an app to the desktop background

    I found you can use the SetParent API to set your form's parent to the desktop window (which has a title of Program Manager), however this doesn't seem to work on Windows 7 or Vista
    EDIT: and from this thread it looks like it might not be possible at all http://social.msdn.microsoft.com/For...b-1ae1d780990a
    Last edited by chris128; Jan 7th, 2011 at 11:12 AM.
    My free .NET Windows API library (Version 2.2 Released 12/06/2011)

    Blog: cjwdev.wordpress.com
    Web: www.cjwdev.co.uk


  3. #3
    Fanatic Member stlaural's Avatar
    Join Date
    Sep 2007
    Location
    Quebec, Canada
    Posts
    683

    Re: Stick an app to the desktop background

    As you said it doesn't seem possible to do that. What you could try to do though, and this is just a suggestion I throw like that, I didn't try it or anything, but you could have a background worker that checks once in while, whatever interval suits your need, if the application is not minimized, if its windows is in the boundaries of the screen etc... If it is minimized or out of boundaries then you show it. I think that could be a work around.
    Alex
    .NET developer
    "No. Not even in the face of Armageddon. Never compromise." (Walter Kovacs/Rorschach)

    Things to consider before posting.
    Don't forget to rate the posts if they helped and mark thread as resolved when they are.


    .Net Regex Syntax (Scripting) | .Net Regex Language Element | .Net Regex Class | DateTime format | Framework 4.0: what's new
    My fresh new blog : writingthecode, even if I don't post much.

    System: Intel i7 920, Kingston SSDNow V100 64gig, HDD WD Caviar Black 1TB, External WD "My Book" 500GB, XFX Radeon 4890 XT 1GB, 12 GBs Tri-Channel RAM, 1x27" and 1x23" LCDs, Windows 10 x64, ]VS2015, Framework 3.5 and 4.0

  4. #4
    Fanatic Member BlindSniper's Avatar
    Join Date
    Jan 2011
    Location
    South Africa
    Posts
    865

    Re: Stick an app to the desktop background

    I think it can be done albeit with complicated windows api(well for me anyway)
    You can Use SetWindowsHookEx with the first parameter as WH_CALLWNDPROC (4) and then in your callback function you can check for a minimize message to your program if the message is a minimize message remove the message from the queue else let it go

    have a look at these
    http://msdn.microsoft.com/en-us/libr...(v=vs.85).aspx
    http://msdn.microsoft.com/en-us/libr...(v=vs.85).aspx

    I'm not really good with win API so i'm in no position to provide examples im not even sure if it is possible with this api but its worth having a look at

    Useful CodeBank Entries of mine
    Expand Function
    Code Compiler
    Sudoku Solver
    HotKeyHandler Class

    Read this to get Effective help on VBForums
    Hitchhiker's Guide to Getting Help at VBF

  5. #5

    Thread Starter
    Pro Grammar chris128's Avatar
    Join Date
    Jun 2007
    Location
    England
    Posts
    7,604

    Re: Stick an app to the desktop background

    Quote Originally Posted by stlaural View Post
    As you said it doesn't seem possible to do that. What you could try to do though, and this is just a suggestion I throw like that, I didn't try it or anything, but you could have a background worker that checks once in while, whatever interval suits your need, if the application is not minimized, if its windows is in the boundaries of the screen etc... If it is minimized or out of boundaries then you show it. I think that could be a work around.
    Well yeah I could just use a timer (no need to use a background worker) but that seems like a fairly bad way of doing it and I'd rather avoid that if possible. Plus there would then be a small delay between the user showing the desktop and the app appearing (along with the animation of the window being restored).
    My free .NET Windows API library (Version 2.2 Released 12/06/2011)

    Blog: cjwdev.wordpress.com
    Web: www.cjwdev.co.uk


  6. #6

    Thread Starter
    Pro Grammar chris128's Avatar
    Join Date
    Jun 2007
    Location
    England
    Posts
    7,604

    Re: Stick an app to the desktop background

    Quote Originally Posted by BlindSniper View Post
    I think it can be done albeit with complicated windows api(well for me anyway)
    You can Use SetWindowsHookEx with the first parameter as WH_CALLWNDPROC (4) and then in your callback function you can check for a minimize message to your program if the message is a minimize message remove the message from the queue else let it go

    have a look at these
    http://msdn.microsoft.com/en-us/libr...(v=vs.85).aspx
    http://msdn.microsoft.com/en-us/libr...(v=vs.85).aspx

    I'm not really good with win API so i'm in no position to provide examples im not even sure if it is possible with this api but its worth having a look at
    Thanks for the suggestion but I don't think using SetWindowHookEx is required to do what you mentioned as it seems to me that you are just using that to intercept all windows messages that are sent to the window yeah? You can do that by just overriding the WndProc event of a form, no APIs necessary and I had considered doing that and looking for the minimize message but from some quick research into how the show desktop function works it looks like that won't work. I might try it anyway though as I've nothing to loose...
    My free .NET Windows API library (Version 2.2 Released 12/06/2011)

    Blog: cjwdev.wordpress.com
    Web: www.cjwdev.co.uk


  7. #7
    Fanatic Member BlindSniper's Avatar
    Join Date
    Jan 2011
    Location
    South Africa
    Posts
    865

    Re: Stick an app to the desktop background

    OFFtopic : how do you override wndProc event of a form ?
    topic: anyway i was about to try my code that looked promising then got a power outage and lost everything so maybe later i will tell you if i was successful

    Useful CodeBank Entries of mine
    Expand Function
    Code Compiler
    Sudoku Solver
    HotKeyHandler Class

    Read this to get Effective help on VBForums
    Hitchhiker's Guide to Getting Help at VBF

  8. #8

    Thread Starter
    Pro Grammar chris128's Avatar
    Join Date
    Jun 2007
    Location
    England
    Posts
    7,604

    Re: Stick an app to the desktop background

    lol no worries, if you do get chance to try again it would be much appreciated

    As for overriding the WndProc event, just go to any empty line in your form code that is outside of a Sub/Function/Property etc (but within your form class) and type Overrides WndProc then press enter and VS will fill in the full signature for you and put the call to MyBase.WndProc in that you need to call to pass on any messages that you want the window to process to the real window message processing system. So basically if you wanted to ignore a certain type of message you would just inspect the various properties of the argument that is passed in to WndProc (which contains details of the windows message such as wparam, lparam, message ID etc) and if it matches the message you want to ignore you don't call MyBase.WndProc - if it doesn't match then you do call it so that the message gets processed as normal.
    My free .NET Windows API library (Version 2.2 Released 12/06/2011)

    Blog: cjwdev.wordpress.com
    Web: www.cjwdev.co.uk


  9. #9
    Fanatic Member BlindSniper's Avatar
    Join Date
    Jan 2011
    Location
    South Africa
    Posts
    865

    Re: Stick an app to the desktop background

    Unfortunately my attempts didn't work out , but i did learn a few things out of trying :
    No.1 I suck at Windows Api
    No.2 It looks like minimizing, maximizing, moving, resizing ect. is handled by windows. The messages your program gets is just a heads up that the user is resizing ect. (correct me if i'm wrong)
    No.3 WndProc is really handy

    With that being said you just need to make your own sort of API that can add exceptions to the Windows minimize operation.lol
    something in this line
    Code:
    SetWindowsProgramException(WM_MINIMIZE, MyProgramHandle)
    or just modify windows a bit
    and If this post seems crazy, I ate some funny food a while back.lol
    Last edited by BlindSniper; Jan 7th, 2011 at 01:40 PM.

    Useful CodeBank Entries of mine
    Expand Function
    Code Compiler
    Sudoku Solver
    HotKeyHandler Class

    Read this to get Effective help on VBForums
    Hitchhiker's Guide to Getting Help at VBF

  10. #10

    Thread Starter
    Pro Grammar chris128's Avatar
    Join Date
    Jun 2007
    Location
    England
    Posts
    7,604

    Re: Stick an app to the desktop background

    The messages that a window receives are actually what does the moving/maximize etc normally (EDIT: Looks like moving might be an exception, as it seems that like you said you just get told that the window has moved and ignoring the move message doesn't stop the window from moving...). I'm sure a lot of messages are actually what causes the action to happen though, for example I think you can use that WndProc overrride to ignore the maximize message then your app will not maximize. You can use WndProc to get some useful effects, such as making it so that when the user clicks and drags anywhere on your form it acts as if they clicked the title bar and moves the window around (useful for borderless forms, as they don't have a title bar for the user to drag so they have no way of moving the form). I can't remember exactly which messages are involved for that but I think it basically involves checking to see if the current message being passed to WndProc is the MouseDown message and if it is then you change one of the message parameters to indicate that the user clicked the title bar rather than the form client area, then you pass the modified message to MyBase.WndProc.

    Having said all that, from some of the stuff I found on google it looks like the Show Desktop feature does not make the windows minimize and instead it does something with the Z order of the windows and basically just places everything behind the background window... I don't think this involves any windows messages being sent to each window so there's no easy way I can know when this happens. I might be wrong and I'm going to have a play around later to try and prove this.
    Last edited by chris128; Jan 7th, 2011 at 02:44 PM.
    My free .NET Windows API library (Version 2.2 Released 12/06/2011)

    Blog: cjwdev.wordpress.com
    Web: www.cjwdev.co.uk


  11. #11

    Thread Starter
    Pro Grammar chris128's Avatar
    Join Date
    Jun 2007
    Location
    England
    Posts
    7,604

    Re: Stick an app to the desktop background

    Aha! I was playing around in a new test project and found that it worked fine if I just set the parent of my window to the desktop window (which is what I had already tried on my proper app but it didnt work) so I went through all of the properties on the form in my proper app and set them the same on my test app until it stopped working. Turns out it was the Opacity property that was causing it to stop working - it seems that if you set the Opacity to anything other than 100% then the window becomes completely invisible when you set its parent to the desktop window. No idea why but it looks like I'll just have to have it 100% opaque (not really a big issue, I only had it at 85% just to make it blend in with the background a bit better).

    So for anyone else interested, to get a form to 'stick' to the background and stay there you just need to use the SetParent API to set your form's parent to the desktop window (which is named Program Manager and has a class name of ProgMan). Here's an example of how to do that by using my Windows API library if you don't want to define and use the windows APIs directly yourself (download link for my API library is in my sig) :
    vb Code:
    1. Dim CurrentWindow = Cjwdev.WindowsApi.NativeWindow.FromHandle(Me.Handle)
    2. Dim DesktopWindow = Cjwdev.WindowsApi.NativeWindow.GetWindowFromTitle("Program Manager")
    3. Cjwdev.WindowsApi.NativeWindow.SetParentWindow(CurrentWindow, DesktopWindow)
    although in this particular case it would be more efficient to use the API definitions directly as my NativeWindow classes gather information about the windows that we don't need in this scenario (title, icon, class name, handle, owning process etc). You can still save yourself the time and effort of declaring the APIs correctly yourself by using my API library though, as you can just use my ApiDefinitions class like so:
    vb Code:
    1. Cjwdev.WindowsApi.ApiDefinitions.SetParent(Me.Handle, Cjwdev.WindowsApi.ApiDefinitions.FindWindowW("ProgMan", Nothing))
    Last edited by chris128; Jan 9th, 2011 at 06:24 PM.
    My free .NET Windows API library (Version 2.2 Released 12/06/2011)

    Blog: cjwdev.wordpress.com
    Web: www.cjwdev.co.uk


  12. #12
    Fanatic Member BlindSniper's Avatar
    Join Date
    Jan 2011
    Location
    South Africa
    Posts
    865

    Re: [RESOLVED] Stick an app to the desktop background

    Chris, if you are using border-less forms I might have some helpful code for you
    lets call it digital camouflage

    Code:
    Sub camo()
            BackgroundImageLayout = ImageLayout.Center
            Dim b As New Bitmap(Me.Width, Me.Height, Drawing.Imaging.PixelFormat.Format24bppRgb)
            Dim g As Graphics = Graphics.FromImage(b)
            Dim p As Point = Me.Location
            Dim s As Size = Me.Size
            Me.WindowState = FormWindowState.Minimized
            g.CopyFromScreen(p, New Point(0, 0), s)
            Me.WindowState = FormWindowState.Normal
            Me.BackgroundImage = b
        End Sub
    call this whenever you like its quite cool
    Last edited by BlindSniper; Jan 7th, 2011 at 06:08 PM.

    Useful CodeBank Entries of mine
    Expand Function
    Code Compiler
    Sudoku Solver
    HotKeyHandler Class

    Read this to get Effective help on VBForums
    Hitchhiker's Guide to Getting Help at VBF

  13. #13

    Thread Starter
    Pro Grammar chris128's Avatar
    Join Date
    Jun 2007
    Location
    England
    Posts
    7,604

    Re: [RESOLVED] Stick an app to the desktop background

    That's a cool little trick! Thanks
    My free .NET Windows API library (Version 2.2 Released 12/06/2011)

    Blog: cjwdev.wordpress.com
    Web: www.cjwdev.co.uk


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width