a***@gmail.com
2005-08-08 16:10:37 UTC
Hi group!
I have a very strange problem; I try to set a transparent child window
to always be ontop of its parent. I already have a parent window, then
I create a layered child window which I want to put one step on top of
the parent window. This does not work all the time, sometimes
everything is OK and the layered window is always visible over the
parent window. I have a second thread in the layered window which
checks every second if the layered child window is the previous window
in the z-order with regards to the parent window. Sometimes it is not
and sometimes it is...
Any help with this would be grealy appreciated.
The code below is how I create the layerd child window:
wnd is the parent window.
hudWnd = CreateWindowEx(WS_EX_TRANSPARENT | WS_EX_TOOLWINDOW,
"OverlayCls", "", WS_POPUP, 0,0,800,500, wnd, NULL,
(HINSTANCE)dllHandle, NULL);
//set the window attributes
SetWindowLong(hudWnd,
GWL_EXSTYLE, GetWindowLong(hudWnd, GWL_EXSTYLE) | WS_EX_LAYERED);
SetWindowLong(hudWnd,
GWL_STYLE, GetWindowLong(hudWnd, GWL_STYLE) | WS_POPUP |
WS_VISIBLE );
The code below is how I try to set the z-order:
wnd is the parent window.
SetWindowPos(hudWnd, HWND_TOPMOST, 0, 0, 0, 0,
SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_NOREDRAW );
SetWindowPos(hudWnd, GetParent(hudWnd), 0, 0, 0, 0,
SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_NOREDRAW );
The code below is executed in a separate thread which should move the
layerd window if the parent is moved.
//get parent windows coords.
RECT tableRect;
GetWindowRect(wnd, &tableRect);
//check which window is the previous to the parent
zWnd = GetNextWindow(wnd, GW_HWNDPREV);
//if all is well the layered child window should be the previous to the
parent window
//if so only update the layered windows x and y pos.
if(zWnd == hudWnd){
::SetWindowPos(hudWnd, // handle of window
zWnd , // placement-order handle
tableRect.left+3, // horizontal position
tableRect.top+29, // vertical position
0, // width
0, // height SWP_NOSIZE|SWP_NOZORDER|SWP_NOACTIVATE );
}
//if the z-order is incorrect try to set it again
//this is what happens sometimes the z.order is not correct
//sometimes the code below will fix it, sometime the frist try
sometimes the 10th or 20th and some time never....!
else{
SetWindowPos(hudWnd, HWND_TOPMOST, 0, 0, 0, 0,
SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_NOREDRAW );
SetWindowPos(hudWnd, GetParent(hudWnd), 0, 0, 0, 0,
SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_NOREDRAW );
}
If someone know what I am doing wrong or konw a better way of doing
this please let me know.
Best Regards
AET
I have a very strange problem; I try to set a transparent child window
to always be ontop of its parent. I already have a parent window, then
I create a layered child window which I want to put one step on top of
the parent window. This does not work all the time, sometimes
everything is OK and the layered window is always visible over the
parent window. I have a second thread in the layered window which
checks every second if the layered child window is the previous window
in the z-order with regards to the parent window. Sometimes it is not
and sometimes it is...
Any help with this would be grealy appreciated.
The code below is how I create the layerd child window:
wnd is the parent window.
hudWnd = CreateWindowEx(WS_EX_TRANSPARENT | WS_EX_TOOLWINDOW,
"OverlayCls", "", WS_POPUP, 0,0,800,500, wnd, NULL,
(HINSTANCE)dllHandle, NULL);
//set the window attributes
SetWindowLong(hudWnd,
GWL_EXSTYLE, GetWindowLong(hudWnd, GWL_EXSTYLE) | WS_EX_LAYERED);
SetWindowLong(hudWnd,
GWL_STYLE, GetWindowLong(hudWnd, GWL_STYLE) | WS_POPUP |
WS_VISIBLE );
The code below is how I try to set the z-order:
wnd is the parent window.
SetWindowPos(hudWnd, HWND_TOPMOST, 0, 0, 0, 0,
SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_NOREDRAW );
SetWindowPos(hudWnd, GetParent(hudWnd), 0, 0, 0, 0,
SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_NOREDRAW );
The code below is executed in a separate thread which should move the
layerd window if the parent is moved.
//get parent windows coords.
RECT tableRect;
GetWindowRect(wnd, &tableRect);
//check which window is the previous to the parent
zWnd = GetNextWindow(wnd, GW_HWNDPREV);
//if all is well the layered child window should be the previous to the
parent window
//if so only update the layered windows x and y pos.
if(zWnd == hudWnd){
::SetWindowPos(hudWnd, // handle of window
zWnd , // placement-order handle
tableRect.left+3, // horizontal position
tableRect.top+29, // vertical position
0, // width
0, // height SWP_NOSIZE|SWP_NOZORDER|SWP_NOACTIVATE );
}
//if the z-order is incorrect try to set it again
//this is what happens sometimes the z.order is not correct
//sometimes the code below will fix it, sometime the frist try
sometimes the 10th or 20th and some time never....!
else{
SetWindowPos(hudWnd, HWND_TOPMOST, 0, 0, 0, 0,
SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_NOREDRAW );
SetWindowPos(hudWnd, GetParent(hudWnd), 0, 0, 0, 0,
SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_NOREDRAW );
}
If someone know what I am doing wrong or konw a better way of doing
this please let me know.
Best Regards
AET