MCPcopy Create free account
hub / github.com/bumptop/BumpTop / IsWindowTopMost

Method IsWindowTopMost

trunk/win/Source/BT_WindowsOS.cpp:4922–4980  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4920
4921
4922bool WindowsSystem::IsWindowTopMost()
4923{
4924 // workaround since top most window is not always a top-level window
4925 // we will check all the windows above bumptop and if we find another top-level
4926 // above ours, then we will bring bumptop to the front
4927 bool isTopMost = true;
4928
4929 HWND windowHwnd = NULL;
4930 if (winOS->GetWindowState() == WorkArea)
4931 {
4932 windowHwnd = GetAncestor(GetAncestor(winOS->GetWindowsHandle(), GA_PARENT), GA_PARENT);
4933 }
4934 else
4935 {
4936 windowHwnd = winOS->GetWindowsHandle();
4937 }
4938
4939 // NOTE: GetWindowRect sometimes pads the values it returns, so take
4940 // the intersection of that rect with the working area of the monitor
4941 // that we are currently on
4942 RECT btr;
4943 GetWindowRect(windowHwnd, &btr);
4944 HMONITOR btrMon = MonitorFromRect(&btr, MONITOR_DEFAULTTONEAREST);
4945 MONITORINFOEX mi;
4946 mi.cbSize = sizeof(MONITORINFOEX);
4947 GetMonitorInfo(btrMon, &mi);
4948 IntersectRect(&btr, &btr, &mi.rcWork);
4949
4950 HWND prevWnd = GetNextWindow(windowHwnd, GW_HWNDPREV);
4951 while (prevWnd && isTopMost)
4952 {
4953 // we allow top most floating windows (such as winamp or DUmeter) to sit above bumptop
4954 // so don't do the intersection test with these windows
4955 bool isTopMostWindow = (GetWindowLong(prevWnd, GWL_EXSTYLE) & WS_EX_TOPMOST);
4956 bool isWindowFramed = (GetWindowLong(prevWnd, GWL_STYLE) & WS_THICKFRAME);
4957 if (IsWindowVisible(prevWnd) && isWindowFramed && !isTopMostWindow)
4958 {
4959 TCHAR className[MAX_PATH];
4960 GetClassName(prevWnd, className, MAX_PATH);
4961
4962 // the task bar will always be above ours, so don't do the intersection test
4963 // with the task bar window
4964 if (lstrcmpi(className, _T("Shell_TrayWnd")) != 0)
4965 {
4966 // otherwise, check if the window rects intersect
4967 RECT wr, finalIntersect;
4968 GetWindowRect(prevWnd, &wr);
4969
4970 // ensure window intersections
4971 if (TRUE == IntersectRect(&finalIntersect, &btr, &wr)) {
4972 isTopMost = false;
4973 }
4974 }
4975 }
4976 prevWnd = GetNextWindow(prevWnd, GW_HWNDPREV);
4977 }
4978
4979 return isTopMost;

Callers 3

InitNxFunction · 0.80
HandleDoubleClickFunction · 0.80
InitMethod · 0.80

Calls 3

GetWindowStateMethod · 0.80
GetWindowsHandleMethod · 0.80
GetClassNameFunction · 0.50

Tested by

no test coverage detected