>>Btw the handle GetDesktopWindow() returns is 0x10014, so it's different from the desktop handle I'm looking for<<
The handle returned by GetDesktopWindow is the handle of 'the' actual desktop - any other handle you have obtained will be a child window of 'the' desktop.
Any application you create with a main window has the desktop as its parent ie you normally specify NULL as the parent handle in the call to CreateWindow/CreateWindowEx (unless you deliberately specify a different parent).
For a control you could, for example
Code:
#include <windows.h>
#include <tchar.h>
int WINAPI WinMain(HINSTANCE,HINSTANCE,LPSTR,int)
{
HWND h=CreateWindowEx(0,_T("button"),_T("child of desktop"),WS_VISIBLE|WS_CHILD,
100,100,200,200,
GetDesktopWindow(),0,GetModuleHandle(0),0);
MSG msg;
while (GetMessage(&msg,0,0,0)>0)
{
if (msg.message==WM_LBUTTONDOWN)
{
DestroyWindow(h);
break;
}
DispatchMessage(&msg);
TranslateMessage(&msg);
}
return 0;
}
which makes that (button) control an explicit child of the desktop; the same should apply to user-defined window classes with the WS_CHILD style.
If all you are concerned about is the z-order, then use SetWindowPos, as Magos has already suggested.