话不多说,直接上代码
bool IsWindowAbove(HWND hHwnd, HWND hHwndCurrent) {
// 判断 hHwnd 是否在 hHwndCurrent 之上
if(NULL == hHwnd || NULL == hHwndCurrent)
return false;
HWND hwndPrev = hHwndCurrent;
while (hwndPrev != NULL) {
hwndPrev = GetWindow(hwndPrev, GW_HWNDPREV);
if (hwndPrev == hHwnd) {
return true;
}
}
return false;
}
bool IsWindowBelow(HWND hHwnd, HWND hHwndCurrent) {
// 判断 hHwnd 是否在 hHwndCurrent 之下
if(NULL == hHwnd || NULL == hHwndCurrent)
return false;
HWND hwndNext = hHwndCurrent;
while (hwndNext != NULL) {
hwndNext = GetWindow(hwndNext , GW_HWNDNEXT);
if (hwndNext == hHwnd) {
return true;
}
}
return false;
}