C++ Set window below (or above) the icons on the desktop - c++

I'm trying to place a window either above or below the icons on the desktop. I mostly just want it to stay attached to the desktop at all times. Similar to Rainmeter or Wallpaper engine. So far, everything I tried either disables interaction, or gets minimized when you use the "Show Desktop" button. Any ideas on how to achieve this? I'm using electron and a native module in node to do this.

It's an old subject, but I'll find out how to do it recently and answer it.
The method is to find the handle of SHELLDLL_DefView, the parent of the desktop window, and then make the SHELLDLL_DefView handle the parent of my window to fix it to the desktop.
The method is to find the handle of SHELLDLL_DefView, the owner of the desktop window, and then make the SHELLDLL_DefView handle the owner of my window to fix it to the desktop.
SHELLDLL_DefView is located under the Progma or WorkerW handle. This is a code to prevent ShowDesktop from being used in the Electget package created by ffi-napi to attach the Electron browserWindow to the desktop.
const GWLP_HWNDPARENT = -8;
// find SHELLDLL_DefView in Progma
const progman = user32.FindWindowExA(ref.NULL, ref.NULL, 'Progman', ref.NULL);
let defView = user32.FindWindowExA(progman, ref.NULL, 'SHELLDLL_DefView', ref.NULL );
// find SHELLDLL_DefView in WorkerW
if (!defView) {
const desktopHWnd = user32.GetDesktopWindow();
let workerW = 0;
do {
workerW = user32.FindWindowExA(desktopHWnd, workerW, 'WorkerW', ref.NULL);
defView = user32.FindWindowExA(workerW, ref.NULL, 'SHELLDLL_DefView', ref.NULL );
} while (!defView && workerW);
}
if (!defView) return false;
// make the SHELLDLL_DefView handle the parent of my window
user32.SetWindowLongPtrA(hWnd, GWLP_HWNDPARENT, defView);
This allows you to create a window where you can click and interact without being hidden by ShowDesktop.
2022-03-29
There was a wrong word, so I corrected it. According to doc, it is not a parent window, but an owner window. In the doc, it is strange that the GWLP_HWNDPARENT constant is related to the parent window. However, when tested with Spy++, the corresponding constant changes the owner window.

Related

How to detect if any app goes fullscreen or exiting fullscreen?

I need to disable notifications at my app when there is another app fullscreen like powerpoint or VLC to do not bother a user.
For now, I get to this code, but it always returns true. Whether there is some app fullscreen or not. I am not sure whether this should work only for app bars or also taskbar.
HWND hWnd;
hWnd = FindWindow(L"Shell_TrayWnd", nullptr);
if( hWnd )
{
APPBARDATA apd;
apd.cbSize = sizeof(APPBARDATA);
apd.hWnd = hWnd;
bool uState = bool(SHAppBarMessage(ABN_FULLSCREENAPP , &apd));
if(uState)
qDebug()<<"fullscreen";
else
qDebug()<<"not fullscreen";
}
ABN_FULLSCREENAPP is not a message you send to the shell, it's a message the shell sends to you when an application enters or leaves full screen mode. The message is sent to the owner of an app bar created with ABM_NEW.
Documentation is here.
My reading of the documentation is that you have to create an app bar to receive this message but you may be able to set it to zero height or width with ABM_SETPOS if you want to hide it.

How do I create a Window in App B so that App A may use it to render instead of using it's own Window

Folks, I apologize if this sounds like a newbie questions, but I am not very familiar with Windows development as a whole. So I was given App A, which does a lot of things and one particular function is to render a duck picture. Internally it created the Window with the title 'DrawingBoard' and later on when the program is ready to render it will try to find this "DrawingBoard" window. I was only told that this is how App A finds the window to render the duck:
static const TCHAR TITLE_NAME[] = "DrawingBoardParent";
static const TCHAR TITLE_CLASS_NAME[] = "DrawingBoard";
HWND parent = FindWindowExA(NULL, NULL, NULL, TITLE_NAME);
while (parent != NULL)
{
//find the child window by window title
window = findWindowRecursive(parent, TITLE_CLASS_NAME);
if (window != NULL)
{
break;
}
//no child by the given title name found, go down one level
parent = FindWindowExA(NULL, parent, NULL, TITLE_NAME);
}
Now I need to create App B and I want to create my own "DrawingBoard" window on App B. Because App A uses the above algorithm to find the rendering window, instead of using it's own App A "DrawingBoard" Window, it will use my App B "DrawingBoard" Window.
Questions:
1) Is this within the realm of possibility at all ?
2) Say if both App A & B have two windows with the same title "DrawingBoard". Which one does FindWindowEx(NULL, NULL, NULL, ""DrawingBoard"); return ?
3) If FindWindowEx always returns the handle for App A "DrawingBoard" window. How do I hack it so it will return App B "DrawingBoard" window.
Thanks for the help folks.
Say if both App A & B have two windows with the same title "DrawingBoard". Which one does FindWindowEx(NULL, NULL, NULL, ""DrawingBoard") return?
That is ill-defined. It will return one of them. You cannot influence which is returned.
If FindWindowEx always returns the handle for App A "DrawingBoard" window. How do I hack it so it will return App B "DrawingBoard" window.
You cannot. The other app is broken. Its search for a window that it created is broken, since it can yield the wrong window, a window from another process.
You can avoid getting caught out by this app by using a different name for your window. However you really ought to either fix or remove the defective program. That's the sane way forward.

c++ attaching to thread (taking focus)

So, (I rewrote this since a lot of people didn't understand me. I apologize.)
I'd like to bring the window of my qt application to the very front of ALL windows on screen.
I've heard you can do this by attaching to the thread of the foreground window and then "stealing focus" aka putting yourself where that foreground window was.
(I'm using OSX, so windows.h is no option for me.)
I hope you understand now.
To bring a window to the front, ensure the window is visible, then activate the window.
As the docs state: -
Sets the top-level widget containing this widget to be the active window.
And
If you want to ensure that the window is stacked on top as well you should also call raise().
So, assuming you have a window called pWindow, you can do something like this: -
pWindow->raise();
pWindow->show();
pWindow->activateWindow();
Also note that OS X can have multiple desktops (Spaces). If you also want the window to track the user's Space when they switch between them, you can add this function to your window class: -
void MyWindow::DisplayOnAllSpaces()
{
// ensure we stay on the active desktop
WId windowObject = this->winId();
objc_object* nsviewObject = reinterpret_cast<objc_object *>(windowObject);
objc_object* nsWindowObject = objc_msgSend(nsviewObject, sel_registerName("window"));
int NSWindowCollectionBehaviorCanJoinAllSpaces = 1 << 0;
objc_msgSend(nsWindowObject, sel_registerName("setCollectionBehavior:"), NSWindowCollectionBehaviorCanJoinAllSpaces);
}

How to determine if a window handle is the taskbar thumbnail view?

I have a code that gets the window handle that the mouse cursor is pointing at, and I am required to determine if the mouse cursor points at a window that is not a part of the task bar. My code is able to recognize if I'm pointing at the task bar, the start button and the show desktop button (on windows 7). But I am not able to recognize if I'm pointing on the thumbnails view of combined windows (see image below).
This is the code that I use to recognize the task bar:
m_hTaskBar = FindWindow("Shell_TrayWnd", "");
m_hTaskBar = GetAncestor(m_hTaskBar, GA_ROOT);
// This code is at a mouse move event:
POINT p;
GetCursorPos(&p);
HWND hWnd = GetAncestor(WindowFromPoint(p), GA_ROOT);
m_hSelectedWin = hWnd;
bool isTaskBar = m_hSelectedWin == m_hTaskBar || GetParent(m_hSelectedWin) == m_hTaskBar;
How can I check if the cursor points at the thumbnails view of combined windows? Thanks.
I have managed to find a solution:
FindWindow("TaskListThumbnailWnd", "");
I used Spy++ to find the class name of the taskbar thumbnails window.
Spy++ can be used from Visual Studio (Tools > Spy++).
You can also find it through Autohotkey Window Spy.

Getting ActiveX window handle

I have followed this link to get the window handle of a ActiveX control
Sample Code from microsoft's site
// The following code should return the actual parent window of the ActiveX control.
HWND CMyOleControl::GetActualParent()
{
HWND hwndParent = 0;
// Get the window associated with the in-place site object,
// which is connected to this ActiveX control.
if (m_pInPlaceSite != NULL)
m_pInPlaceSite->GetWindow(&hwndParent);
return hwndParent; // Return the in-place site window handle.
}
But in my case I keep finding that "m_pInPlaceSite" is always NULL. I'm trying to run this code in my controls FinalConstruct. Is there something else I need to implement for the m_pInPlaceSite to be given a value? Or do I need to Query to get the value.
Thanks
FinalConstruct is way too early. In FinalConstruct your class is just being created and is not yet initialized. There is no "in place" site, there is no yet site at all.
Your control will be called by its owner, it will be given its site, then activated - only then you will possibly have m_pInPlaceSite available.