Z-axis window value - windows

I can retrieve the position of window using GetWindowRect winapi function.
It should be a function also that defines the order of windows in z-axis (which window is above and which is under), but cannot find the appropriate function.
Point me to any one?

Well, seems like EnumDesktopWindows returns windows in the Z order from the top to the bottom. So no need in any special function then (which doesn't exist perhaps).

You don't get the z order directly. You are expected to call GetWindow()passing GW_HWNDNEXT or GW_HWNDPREV to walk the z order hierarchy.
Start at one of your windows and walk until you find either the other window or your walk terminates. This then tells you the relationship between the two windows.

Related

PTVISIBLE always returns true when relevant point obscured by another window

I am trying to ascertain whether the mouse cursor is over a specific window and whether there are any other windows obscuring that window at that specific point. The relevant point is obtained in screen coordinates by way of a mouse hook. I then use the ptVisible function to determine this. My code is:
DC := GetDC(wnd);
try
Result := PtVisible(DC, pt.X, pt.Y);
finally
ReleaseDC(wnd, DC);
end;
This always returns false even when there is nothing obscuring the window represented by the wnd handle.
I found very little on the web as to proper use of ptVisible. Can anyone advise if I am using it incorrectly?
You are not using it correctly. From the docs page, PtVisible() "determines whether the specified point is within the clipping region of a device context." This has nothing to do with mouse location or location of a pixel within a window. This has specific uses to check whether the point is within the clipping region of a graphics device context.
If you want to check whether the mouse is within a certain window, you might want to try checking if your mouse coordinate is within GetWindowRect(). And then to check whether or not any windows overlap, you'd want to EnumWindows() and then IntersectRect()

Z-index in winapi

I need the ability to set the window not only z-type (always top/always bottom/etc.), but also z-index (0..+inf.).
Windows with smaller z-index values ​​should be lower than windows with greater.
I know about SetWindowPos and it`s parameter hWndInsertAfter, using it I can achieve what I want, but this way seems too complicated.
Is there better solution ?
The windowing subsystem maintains the Z-Order, implemented as a list:
The system maintains the z-order in a single list.
You can move windows in this list (by calling SetWindowPos for example), passing the previous window as an index, or HWND_TOP to move a window to the front. There is no API that uses an ordinal as the index.
If you need to insert a window ahead of another window, call GetNextWindow(GW_HWNDPREV) first to be passed as the hWndInsertAfter. If there is no window ahead in the z-order, GetNextWindow returns NULL, which conveniently maps to HWND_TOP.

Programmatically find blink cursor position in windows c++?

How to find out blink cursor position in windows, from c++? In many cases I need send button click on the position of the blinking cursor, but I didn't find any important function which will take care of that.
OS win 7(64), c++
It is called "caret", cursor is the mouse pointer. You use GetCaretPos() to get its position. But the returned position is relative to the client area of the window that owns the caret. Which probably means that you need to find that window first, use GetForegroundWindow() for that. And don't send button click messages, they are posted so use PostMessage().
Avoid all of this by just using SendInput().
Note that UIPI (the user interface component of UAC) prevents you from poking stuff into a window owned by an elevated process.
GetGUIThreadInfo() is probably your best bet; pass it with idThread = 0 to get the info from the currently active thread, and then check the rcCaret member of the returned GUITHREADINFO structure. You'll then need to use ClientToScreen() with the hwndCaret value to convert client-relative coordinates to screen coordinates.
Note that this only works for apps that use the Win32 caret functions - specifically SetCaretPos(). If an app draws its own caret without using these, you may not get anything meaningful back. (Some apps, like Word, draw their own caret, but still call SetCaretPos so that accessibility aids that need to track the caret can use this technique.)
The rectangle you get back can sometimes be wider than the actual caret. When a bitmap is used for the caret, as is the case for Right-To-Left or Left-To-Right carets that have a little 'flag' attached to the top, you'll get back a rectangle that's a bit wider than the actual caret area, and may need to adjust or otherwise figure out where within this area the actual caret bar is - it may or may not be in the exact middle. Looks like for Notepad++ you should be fine, though.

How to get the full client rect?

The GetClientRect function, according to MSDN, is actually only good for determining the client width & height, since left & top are always zero. Is there a way to get the complete client coordinates, including left & top (either in screen space, or in window space)?
Call ClientToScreen on the top left and bottom right of the returned RECT. If you're using MFC, CWnd has a helper overload of CWnd::ClientToScreen that will do this transparently for you.
Maybe you are needing GetWindowRect.
You're looking for the GetWindowPlacement function. This function returns a WINDOWPLACEMENT struct which has an rcNormalPosition property which specifies the window's position when it is in the normal (rather than maximized or minimized) display state.
EDIT: itowilson's answer is actually cleaner because the WINDOWPLACEMENT structure also contains a bunch of data you don't need.

How do I detect which Window is obscuring another?

If I have the handles to two windows, how can I tell whether one is obscuring the other? Obviously I can easily do a collision test, but how do I test / find out their "z order"? The windows are from totally different apps.
I am probably missing something fairly obvious..
WindowFromPoint, (use a point bounded by one window, and see if you get back that window's handle, or the other one).
For partial obscuration, you can use the clipping system. I discuss this in more detail on my website here
This page talks about the Z ordering of windows. It doesn't mention a function to get the Z order directly, but it does point at GetNextWindow(), which given one window can return the next (or previous, don't let the name fool you) in the Z order. Using that, you should be able to figure it out.

Resources