Determine TopMost Window on the Desktop
Hi All,
I have a tricky one (well, tricky for me) that I am having trouble finding a solution for.
Here is the problem;
I have a Form that is open and a Notify Icon. I want to be able to click the icon and have one of two things occur depending on the current state of the form.
If the form is the Top Most (i.e. on top of all other normalised or maximised Windows) I want to hide the form.
If the form is NOT the Top Most (i.e. behind another form) then I want to bring the form to the top.
You can determine the topmost form for the desktop using a couple of Windows API's as follows;
'GetForegroundWindow will get the handle of the Forground Window... 'GetTopWindow returns a handle to the currently active child window of a window. The problem as I see it is that because you have clicked the notify icon to kick off this logic, these API's will return the wrong Handle. Regards, Grant.
PublicDeclareFunction GetForegroundWindowLib"user32" ()As IntPtr
'GetDesktopWindow will get the handle for the Desktop...
PublicDeclareFunction GetDesktopWindowLib"user32" ()As IntPtr
'The active child window is the one that has the focus, and it is usually at the
'top of all the other children in the Z-order. This function works even if the parent
'window is not active. If an error occurs or the window has no children, the Function
'instead returns 0.
PublicDeclareFunction GetTopWindowLib"user32" (ByVal hwndAs IntPtr)As IntPtr
Does anyone have any idea how to determine that the form is currently on top of all other windows, even though it is not active?

