Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7519829
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T01:58:01+00:00 2026-05-30T01:58:01+00:00

In one of my programs, I need to test if the user is currently

  • 0

In one of my programs, I need to test if the user is currently focusing the desktop/shell window. Currently, I’m using GetShellWindow() from user32.dll and compare the result to GetForegroundWindow().

This approach is working until someone changes the desktop wallpaper, but as soon as the wallpaper is changed the handle from GetShellWindow() doesn’t match the one from GetForegroundWindow() anymore and I don’t quite get why that is. (OS: Windows 7 32bit)

Is there a better approach to check if the desktop is focused? Preferably one that won’t be broken if the user changes the wallpaper?

EDIT: I designed a workaround: I’m testing the handle to have a child of class SHELLDLL_DefView. If it has, the desktop is on focus. Whilst, it’s working at my PC that doesn’t mean it will work all the time.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T01:58:02+00:00Added an answer on May 30, 2026 at 1:58 am

    The thing changed a little bit since there are slideshows as wallpaper available in Windows 7.
    You are right with WorkerW, but this works only with wallpaper is set to slideshow effect.

    When there is set the wallpaper mode to slideshow, you have to search for a window of class WorkerW and check the children, whether there is a SHELLDLL_DefView.
    If there is no slideshow, you can use the good old GetShellWindow().

    I had the same problem some months ago and I wrote a function for getting the right window. Unfortunately I can’t find it. But the following should work. Only the Win32 Imports are missing:

    public enum DesktopWindow
    {
        ProgMan,
        SHELLDLL_DefViewParent,
        SHELLDLL_DefView,
        SysListView32
    }
    
    public static IntPtr GetDesktopWindow(DesktopWindow desktopWindow)
    {
        IntPtr _ProgMan = GetShellWindow();
        IntPtr _SHELLDLL_DefViewParent = _ProgMan;
        IntPtr _SHELLDLL_DefView = FindWindowEx(_ProgMan, IntPtr.Zero, "SHELLDLL_DefView", null);
        IntPtr _SysListView32 = FindWindowEx(_SHELLDLL_DefView, IntPtr.Zero, "SysListView32", "FolderView");
    
        if (_SHELLDLL_DefView == IntPtr.Zero)
        {
            EnumWindows((hwnd, lParam) =>
            {
                if (GetClassName(hwnd) == "WorkerW")
                {
                    IntPtr child = FindWindowEx(hwnd, IntPtr.Zero, "SHELLDLL_DefView", null);
                    if (child != IntPtr.Zero)
                    {
                        _SHELLDLL_DefViewParent = hwnd;
                        _SHELLDLL_DefView = child;
                        _SysListView32 = FindWindowEx(child, IntPtr.Zero, "SysListView32", "FolderView"); ;
                        return false;
                    }
                }
                return true;
            }, IntPtr.Zero);
        }
    
        switch (desktopWindow)
        {
            case DesktopWindow.ProgMan:
                return _ProgMan;
            case DesktopWindow.SHELLDLL_DefViewParent:
                return _SHELLDLL_DefViewParent;
            case DesktopWindow.SHELLDLL_DefView:
                return _SHELLDLL_DefView;
            case DesktopWindow.SysListView32:
                return _SysListView32;
            default:
                return IntPtr.Zero;
        }
    }
    

    In your case you would call GetDesktopWindow(DesktopWindow.SHELLDLL_DefViewParent); to get the top-level window for checking whether it is the foreground window.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say I have shell programs a,b,c, each one executing a command from the
The folder I need to delete is one that is created from my program.
I am trying to get input from the user and need to know a
While running one of my programs, I need to scan through a rather large
I have a C program and I need to test it using a file
I need to write one java program which monitors a folder containing excel sheets
I need to port one of my old program to Windows. The current version
I need to make the program which have one form that contains PNG image
I have two programs: one CLI program, and one GUI. The GUI is a
One of my programs seems to be changing the Display Properties > Appearance >

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.