I have developed a dll which is loaded from a thirdparty application.
The application does not provide me any events like WM_SIZE, WM_MOVE etc.
My dll displays a window (dialog) which is child of the main application.
I want that my window should move whenever main application is resized or moved.
How can I achieve this? As I said, the main application does not provide any WM_SIZE or WM_MOVE events.
Is there a way to subscribe to events of the application using the application handle?
OR can a child window know when main application is moved or resized without these events?
If a window has a style WS_CHILD it never receives a WM_MOVE or WM_SIZE message when the parent moves!
Why should it? Its position (relative to the parent) and its size doesn't change. Also the OS Windows takes care about any repainting that has to occur by uncovering sections of the window.
So when you are saying that the window should move with the parent and it doesn't than the window isn't a child of the parent. (Style WS_CHILD). Recheck this with Spy++. Or maybe you have only an owned window. (Your question isn't detailed enough).
If you have a non WS_CHILD window and you want it to move with another window, you can use a timer to recheck if the other window moved. Or if the window is in the same process you can subclass the window and post your own message to your window when the parent receives WM_SIZE/WM_MOVE.
Related
here is the situation
my WPF Main window is always visible and several small windows should be floating on the Main Window.
So these small windows are children of Main Window and their z-index should be always one greater than Main Window even if the focus is on the main window rather than children but smaller z-index than other applications (e.g. file browser or chrome etc.)
I've tried Window's TopMost property but it makes really top most than everything else even more than application's MessageBox.
any good idea for making these children windows are just floating in front of only parent window?
thanks in advance
it should automatically open above the owner window. Or set the child to be topmost
I'm trying to overlay child window of some application with a form.
I have handle to that window so I successfully used GetWindowRect()
to get coordinates and correctly place my winform on the screen.
However I have problem with order of application's windows and my winform.
With TopMost parameter set to true my form overlays menu drop lists of the main window of the application and generally doesn't look very elegant. With this paramter set to false, my form hides below all windows and is invisible.
Is it possible to place my winform above only one, specific window (to which I have the handle) and maintain order of all other windows (keep it below them)?
To illustrate it. Now I have this order of visibillity(?):
My form (on top)
Application main window
Application child window
I want:
Application main window
My form
Application child window
Please keep in mind, that this another application is 3rd part product. Everything I have is the handle to the window which I want to overlay.
In a WPF app of mine, I have to let the user choose a certificate. I do this via the X509Certificate2UI.SelectFromCollection-method. For proper dialog handling, the SelectFromCollection-method needs an IntPtr of the parents Hwnd. I have found the following code to provide this:
HwndSource source = (HwndSource)HwndSource.FromVisual(Window.GetWindow(this));
var certificates= X509Certificate2UI.SelectFromCollection(...,source.Handle);
So far, this works fine. My question is, because I have no big knowledge of Win32 or interop, if I have to do some cleanup code after this, or if there are some pitfalls in using the HwndSource-class like I did above?
I have seen that HwndSource implements IDisposable, but disposing the object after use closes the parent window. Therefore this seems not to be the intended usage.
WPF window is made up of two parts:
Window area which is made up of Operating System Window
Non - Window area which is inside a WPF window
Now, a WPF window being a ContentControl holds everything as its Content. So you can say every pixel of the Content inside the Window class is held by the Outside window. Every Visual of WPF does not have its own HANDLE associated with it, rather it is a content for the outside window element.
For detail refer to this - http://www.abhisheksur.com/2010/12/win32-handle-hwnd-wpf-objects-note.html
So, when you are disposing that handle, you are actually disposing your main window handler which results in close of complete application.
Hence, you are here only fetching your window handler and not creating anything which you might need to dispose..!!
I am using C# and WinForms to create UI of my application.
I have main window and dialog, which is shown modal to the main window. Dialog window is not shown in task bar. I go to another application and return back by clicking at the main window task bat icon. I can see locked main window but cannot see dialog unless I select it in Alt-Tab. This is confusing for an application user.
How can I ensure showing modal window in this situation? I can see similar but unfortunately unsolved question ALT+TAB in Vista activates main window instead of previously active child window which regards to Vista (and I have Windows 7).
This is probably because you don't use the ShowDialog(owner) overload. You should fret a little bit about the exact reason that ShowDialog() cannot find an owner by itself and picked the desktop window instead. It isn't healthy. I cannot guess why from your post. See what explicitly setting the owner buys you.
Oh, this will happen when the dialog runs on its own thread. In which case ShowDialog(owner) is going to bomb.
It sounds like your dialog is not properly owned by the main window. Make sure you have assigned the main window to the dialog object's Owner property before showing the modal dialog.
I would like to display a status window in my C# Windows Forms application that informs the user when the application is waiting to acquire a lock. This is an application-defined thing, however, the window should be visible and always remain on top of all other windows of my application, even when the user clicks on another window (like for example the larger main window behind it).
It must not be modal (so ShowDialog() cannot be used) because the app needs to keep trying in the background and close the window automatically if the lock could eventually be acquired, and it really should not be top-most for the entire window station (i.e. all applications running in that terminal session).
I know the Form.TopMost property, but it can only bring and keep a single window above all others, even those from other applications. This is clearly not what I'm looking for.
I know that this is possible, I've seen it many times before in other applications. I just don't know how it can be done.
If you pass your main form into the Show method of the status form, it will stay on top of the main form, but not on top of other applications. So, in the main form you can have code like so:
StatusForm statusForm = new StatusForm();
statusForm.Show(this);
However, this will only point out one single window of your application as the owner.
You have to set the Owner property of the child form to the parent form, and use Show to show the child form.