Want form on top of, but no in, non-.NET window

G

Guest

Hi;

I used the Win32:SetParent to set the parent of a Form to the Window of the
app it is in (Word). This forced the form to stay within the main window of
Word.

How can I set a Form so it is always above the Word window - but not
restricted to being within it?
 
J

Jeffrey Tan[MSFT]

Hi Dave,

Currently, I have met a little problem in the researching progress, I will
spend a little more time on this issue, and update you ASAP. Thanks

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
J

Jeffrey Tan[MSFT]

Hi Dave,

Sorry for letting you wait for so long.

What you after is the owner window behavior, which we should set our Form's
Owner form to Word document. For more information about owned window
feature, please refer to "Owned Windows" section in the link below:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui
/windowsuserinterface/windowing/windows/windowfeatures.asp

As you can see, owned window has:
1. An owned window is always above its owner in the z-order.
2. The system automatically destroys an owned window when its owner is
destroyed.
3. An owned window is hidden when its owner is minimized.

Normally, we can use SetWindowLong with GWL_HWNDPARENT to specify our
Form's owner. Like this:
[DllImport("user32.dll")]
static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong);
private void button1_Click(object sender, System.EventArgs e)
{
IntPtr hWord=FindWindowEx(IntPtr.Zero, IntPtr.Zero, "OpusApp", null);
SetWindowLong(this.Handle, -8, (int)hWord);
SetWindowPos(this.Handle, HWND_TOP, 0, 0, 0, 0,
SWP_NOSIZE|SWP_NOMOVE|SWP_SHOWWINDOW|SWP_FRAMECHANGED);
}
Note: I used SetWindowPos to flush the cached window style bits. Hope this
helps.
=========================================================================
Thank you for your patience and cooperation. If you have any questions or
concerns, please feel free to post it in the group. I am standing by to be
of assistance.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top