How do I detect which Window is obscuring another? - winapi

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.

Related

For WM_GETMINMAXINFO, if I'm not modifying ptMax­Size, do I still need to use MonitorFromWindow() to fix up unusual situations?

I'm probably misunderstanding something but:
I don't want the user to be able to resize my window smaller than the minimum size that its children can be visible in with a given layout. So I could do this with WM_GETMINMAXINFO, modifying ptMinTrackSize.
Now, these articles talk about compensating for multiple monitors on the ptMax­Size field of the MINMAXINFO structure, in the case where the desired window size doesn't fit on one dimension of the monitor but does on the other, using MonitorFromWindow().
My confusion is: do I need to do this adjustment always, or only if I actually put something custom in ptMax­Size? If the latter, then I will assume either DefWindowProc() or the window manager handles it for me.
Thanks.

NSWindow keep in back of all windows/apps

So not really sure how to even google search this question... But, I'd like to make an NSWindow, reside in the back of all other windows/apps & I want it to be displayed on every Mission Control space (still in the back).
I've seen other applications that do this, so I know it's possible, just don't know how.
(I'm referring to Lion's function called Mission Control where you can switch through different spaces.)
Found the answer, there's a method/enum to make it so that the window will appear in all "spaces" (mission control).
[self.window setCollectionBehavior:NSWindowCollectionBehaviorCanJoinAllSpaces];
And a method to keep the window to the farthest back possible.
[self.window setLevel:kCGDesktopIconWindowLevelKey - 1];
All you have to do is use these two methods, and it'll do exactly what I requested. However, I wish there was a way to keep it from animating when coming down from Mission control (there is non to my knowledge).
You want to set the NSWindow's level and collectionBehavior properties.
The window level you'll want to use will depend on what behavior you're after from your window. You can find constants for the available window levels in CoreGraphics/CGWindowLevel.h. I'd suggest trying CGWindowLevelForKey(kCGDesktopIconWindowLevelKey) ± 1.
Which collection behavior you specify will also depend on what behavior you're after. The brief description in your question suggests that NSWindowCollectionBehaviorStationary | NSWindowCollectionBehaviorCanJoinAllSpaces may be a good starting point.

Drag and Drop in Windows Phone 7.1

Windows Phone 7.1 (Mang), SL4, VS 2010/Expression Blend.
I have a UI element (an ellipse) that I've added the behavior MouseDragElementBehavior to so now I can drag my ellipse all over my other elements. Great. What I can't figure out is how to determine where (what other UI element, specifically in this case a canvas) it was dropped on. Imagine a game board where you click and drag a piece from one square to another.
How can I determine if it's been "dropped" on another element?
The VisualTreeHelper class contains a method FindElementsInHostCoordinates to which you can pass the Point or Rect location of your Ellipse and then get all the Controls that exist in that location and act accordingly.
You might find the remarks section in FindElementsInHostCoordinates useful.
I think you can use that method no problem in basic scenarios. I used it for a while in one of my application's then I decided to use a manual method where I just loop over the controls and checking whether an intersection (or Point containment) occurs. Then just get the first control that is hit.
Please tell me if you have reached a better solution because I'm looking for ideas better than what I have already done! Thanks.

What's the overhead of TPanel over TBevel

I'm working on a project where they essentially used TPanel for the only purpose of displaying a bevel (And maybe the design time convenience Panel have over Bevels).
Ok, I know TPanel is heavier than TBevel. Amongs other things, each TPanel create a user objects, which is a limited resource.
What I would like to know, beyond user objects, what's the overhead of TPanel? Is it next to non-existent (Especially on modern day machines).
If you were working on such a system, would you suggest :
Going back and changing all TPanel to TBevel.
Say "Ok it was bad. Lets not do it again in the future"
or
it's too small a concern and the design time convenience is well
worth it.
I wouldn't know if this design is intentional but, there's a slight navigational behavior difference when controls are grouped together in a window. If the focus is changed by arrow keys, after the one having the last tab order the first control will be focused (down/right), or vice-versa (up/left). IOW the focus will be wrapped in the parent. That's of course if any of the controls do not need the arrow keys.
Regarding the question, as it is already stated in the comments, apart from using up a count in an object pool, there're other resources associated with a window. It will also waste a few CPU cycles. There'll be one more level in the clipping chain or the messaging or keeping one more z-order list etc.. MSDN puts it as (I guess navigational aspect is being referred rather than visual partitioning):
For best performance, an application that needs to logically divide its main window should do so in the window procedure of the main window rather than by using child windows.
Nevertheless, as again already stated in the comments, most probably, no one will be able to tell the performance or resource difference caused by a few panels..
The correct answer is choice #3, so if that's the project's design approach, don't change it.

MATLAB: Prevent figures from being made active

I have a rather large routine which will can run for a couple of hours. Here and there it creates a figure, plots something to it and saves that Figure.
As I have only one PC, I would like to continue to work with that machine. The problem is that whenever a new figure is made, MATLAB becomes the active application again.
Is there any way to tell MATLAB or Windows that MATLAB should not be allowed to set itself to active?
I saw that one possibility is to run a MATLAB script totally in the background (like that). But that is a little bit too unsupervised, as I would like to be able to switch to the MATLAB window and check the output to the command window.
Any ideas? If there is a general solution for Windows that prevents that other Applications to become active would also be cool!
You can overload the figure function as following in order to prevent figure poping up:
a = figure('visible','off');
I hate to state the obvious, but you could always store the data you want to plot until the end.
Now, you're going to tell me that some of that data is subroutines and doesn't get passed back to the main routine. OK. So, the solution to that would be to write a "Store_Plot_Data" class with a method that would write into memory the data, the #plot_function_name (for 3D, scatter, etc.), the axis label strings, etc. Then you would create one instance of this class in your main routine and to ensure visibility of this one instance to all subroutines you could do any of the following:
use a global variable as your single instance ... OK, not so elegant,
implement the Singleton pattern, or
pass all subroutines the handle to that one instance of the "Store_Plot_Data" class.
If there is a general solution for Windows that prevents that other
Applications to become active would also be cool!
In Windows 7, this worked for me:
http://pcsupport.about.com/od/windowsxp/ht/stealingfocus02.htm
Set "HKEY_CURRENT_USER\Control Panel\Desktop\ForegroundLockTimeout" to 30d40 (hex).
If you want all figures to not show.
set(0,'defaultFigureVisible','off');
In the beginning of your script do:
set(0, 'DefaultFigureVisible', 'off');
set(0, 'DefaultFigureWindowStyle', 'docked');
Dock the Matlab figure window and maximize any other application (Excel, Word etc.) you are working with in front of Matlab.
Then you can continue to work without being interrupted by figures blinking on your face.

Resources