Tech Off Thread

17 posts

How to "pin" to desktop in Vista?

Back to Forum: Tech Off
  • User profile image
    mscrivo

    Hi everyone,

    I've been perplexed over this problem for the past week.  On previous version of windows (post-Win2k), you were able to employ the following C#  code to essentially pin your window to the desktop:

    this.SendToBack();
    IntPtr pWnd = UnsafeNativeMethods.FindWindow("Progman", null);
    IntPtr tWnd = this.Handle;
    UnsafeNativeMethods.SetParent(tWnd, pWnd);


    where FindWindow and SetParent are imported from User32.dll.  The window would essentially be part of the desktop background, no other window could hide behind it and when you click show desktop, it would still be on screen.  On Vista, this does not work when DWM is enabled.  The code does not throw any exceptions, it's just not visible.  Does anyone have any idea how to do this on Vista with DWM enabled?

    Thanks,
    Michael

  • User profile image
    AndyC

    mscrivo wrote:
    
    IntPtr pWnd = UnsafeNativeMethods.FindWindow("Progman", null);



    You are relying on an unsupported "feature" of Explorer that was included for backwards compatibility with Windows 3.1 (namely that there was a window called Progman). The correct way to get a Handle to the desktop is by calling GetDesktopWindow().

    However you really, really don't want to set that as your parent window. Doing so is dangerous as you can potentially disable all on screen windows and cause the system to lock up.

  • User profile image
    amotif

    There are ">http://blogs.msdn.com/oldnewthing+desktop+parent"> a number of reasons to beware of playing with the desktop.

  • User profile image
    PCBUILDERCH​RIS

    windows 3.1 is where the hearts at mainly because im 18 and started off on it i remember the high def colors my packard bell used to put out screaming packard bell navigator

  • User profile image
    mscrivo

    Thanks for the responses guys,

    I know that using the desktop window for arbitrary things, especially when not absolutely needed is not a good idea.  However, for the program I developed, it's sort of it's heart and soul.  Here is the program in question:
    http://fileforum.betanews.com/detail/Outlook_on_the_Desktop/1127842333/1

    The whole draw of it, is to be able to always have your outlook calendar accessible on the desktop, nothing can get behind it, and when you click show desktop, it's still visible, like it's fused to your desktop.

    The above hack works perfectly to achieve that on Windows 2000 and XP.  However, on Vista, as mentioned, the hack no longer works and neither does SetParent using GetDesktopWindow().   The closest I've been able to achieve is to use SetWindowPos to position it under all windows every time it's activated, but this only solves one of the problems, that is preventing other windows from going behind it.  The other problems are: when the user clicks show desktop, it disappears as well, and it shows up in the window list when pressing alt-tab which is also not desirable.

  • User profile image
    Yggdrasil

    I was hoping someone else would link this, but what the hell. Smiley

    http://channel9.msdn.com/ShowPost.aspx?PostID=278156#278156

  • User profile image
    AndyC

    You can't use HTML backgrounds in Vista though.

  • User profile image
    mscrivo

    AndyC,

    I don't use a transparent html background for my program.  I use a fully qualified window, with html hosted within it.  All dressings are removed from the window (titlebar, borders, etc) and the opacitiy is set and volia, it actually works very very well on Windows XP, even with multiple monitors.

  • User profile image
    CecleCW

    hi, Michael,

    would you mind telling me more about how you implement your application to pin to desktop in W2K?

    i'm looking for a solution on this


    thank you so much

  • User profile image
    Richard.Hein

    I have no idea how the DreamScene stuff is supposed to work, but could you tap into those APIs to get an active background?

    Update:  Forget it, I did a bit of checking and aside from the facts that it's only for Vista Ultimate, there is no documentation on the APIs, and wouldn't be what you want anyways, as far as I can tell.

  • User profile image
    Richard.Hein

    mscrivo wrote:
    AndyC,

    I don't use a transparent html background for my program.  I use a fully qualified window, with html hosted within it.  All dressings are removed from the window (titlebar, borders, etc) and the opacitiy is set and volia, it actually works very very well on Windows XP, even with multiple monitors.


    Isn't that what Gadgets are all about?

  • User profile image
    JChung2006

    Please don't pin your windows to the desktop.

    http://blogs.msdn.com/oldnewthing/archive/2004/02/24/79212.aspx

  • User profile image
    figuerres

    mscrivo wrote:
    Thanks for the responses guys,

    I know that using the desktop window for arbitrary things, especially when not absolutely needed is not a good idea.  However, for the program I developed, it's sort of it's heart and soul.  Here is the program in question:
    http://fileforum.betanews.com/detail/Outlook_on_the_Desktop/1127842333/1

    The whole draw of it, is to be able to always have your outlook calendar accessible on the desktop, nothing can get behind it, and when you click show desktop, it's still visible, like it's fused to your desktop.

    The above hack works perfectly to achieve that on Windows 2000 and XP.  However, on Vista, as mentioned, the hack no longer works and neither does SetParent using GetDesktopWindow().   The closest I've been able to achieve is to use SetWindowPos to position it under all windows every time it's activated, but this only solves one of the problems, that is preventing other windows from going behind it.  The other problems are: when the user clicks show desktop, it disappears as well, and it shows up in the window list when pressing alt-tab which is also not desirable.


    have you tested with the "classic" vista UI ??

    things that things come to mind:

    1)  dwm and compositing -- vista handles windows differently then xp / 2k did.  for example an app hang in xp could create the window trails effect, that can't happen in vista.

    2) as posted what about a gadget??  seems like a good UI for the vista users. and you can have a docked UI and a "full UI" for the gadget.

    3) what about a wpf app?  try a small toy wpf app and try the hack, what happens? same or different results?

    4)  debug, is your app running ?  does it crash?  are you logging any exceptions ??

    my bet is this hack was broke in #1 and you need a new way to do this on vista...

  • User profile image
    TampaJohn

    You have to go a little further to get this to work properly in vista...

    Basically Include the following DLLImports


    [DllImport("User32.dll")]
    static extern IntPtr FindWindow(String lpClassName, String lpWindowName);

    [DllImport("user32.dll", SetLastError = true)]
    static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow);

    [DllImport("user32.dll")]
    static extern int SetParent(IntPtr hWndChild, IntPtr hWndNewParent);


    Then instead of your original code, use the following:


    IntPtr pWnd = FindWindow("Progman"null);
    pWnd = FindWindowEx(pWnd, IntPtr.Zero, "SHELLDLL_DefVIew", null);
    pWnd = FindWindowEx(pWnd, IntPtr.Zero, "SysListView32", null);
    IntPtr tWnd = this.Handle;
    SetParent(tWnd, pWnd);


    In my application this works in both Vista and XP to get the effect I believe you desire.

    Do make a note that doing this does break TaskStripButtons ... if anyone has any suggestions for how to get these working, I would appreciate it.

  • User profile image
    mscrivo

    I tried that, it doesn't seem to be working for me.  It runs, but my window disappears completely.

  • User profile image
    evildictait​or

    Richard.Hein wrote:
    I have no idea how the DreamScene stuff is supposed to work, but could you tap into those APIs to get an active background?

    Update:  Forget it, I did a bit of checking and aside from the facts that it's only for Vista Ultimate, there is no documentation on the APIs, and wouldn't be what you want anyways, as far as I can tell.


    There are no dreamscene APIs - it's all managed by the Desktop Windows Manager, who paints the background from a buffer - if dreamscene is on, that buffer is the output of the mpeg decoding stream.

  • User profile image
    mscrivo

    I am using Vista 64 ... it works if I use SysListView64 instead of SysListView32, but using Spy++, I see that there doesn't appear to be a SysListView64 ... so I'm not quite sure what's going on. 

Comments closed

Comments have been closed since this content was published more than 30 days ago, but if you'd like to continue the conversation, please create a new thread in our Forums, or Contact Us and let us know.