Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB 6 Visual Basic 6 > VB How-To
|
VB How-To Ask your "How do I do this with VB?" questions in this forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 25th, 2006, 04:05 PM
Registered User
 
Join Date: Sep 2006
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default VBA w/ Word 2000 - Make form on top of everything

Does anyone know of a way to make a form stay on top of all applications or even on top of all open Word documents? I want a form that stays on top even if I minimize its parent Window (the document from which it was launched). I want it to stay on top even if I click on another Word document. Is it possible?

I've used the SetWindowPos function, but as soon as I minimize the form's parent, the form minimizes as well. I've tried using the SetParent function and the GetDesktopWindow function to make the desktop the forms parent, but for some reason the GetDesktopWindow seemed to return the same handle as the form's parent Word document.

Any help would be greatly appreciated.


 
Old September 26th, 2006, 02:36 AM
Friend of Wrox
 
Join Date: Dec 2004
Posts: 221
Thanks: 0
Thanked 0 Times in 0 Posts
Default

check this link

http://www.geocities.com/raghavendra...os_EXAMPLE.zip

It is created in MS-Word 2002 (Office XP)

Hope this helps.


With Regards,
Raghavendra Mudugal
 
Old September 26th, 2006, 10:31 AM
Registered User
 
Join Date: Sep 2006
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for the quick response, I appreciate your help!

Thank you also for the sample code, but it isn't quite the effect I'm going for. In your sample code, when you click the button to bring the Form on top, it also brings the Form's parent on top of other open Word documents. I don't know if it's possible, but I'd like to make the form come to the top without it's parent.

Let me better explain what I'm trying to accomplish. What's going on in my app is the following. The user opens a Word document, presses a toolbar button that loads a Form. While interacting with the Form, other Word documents are opened (often blocking the view of the form). The real pain is trying to view the opened documents and the Form together: If you click on the opened documents, the Form goes behind them, and if you click on the Form, the Form's parent document pops up and covers the opened documents. Does that make sense?

One thing I did try was to set the Form's parent to one of the opened document. This put the Form nested inside the document's window - which make it hard to view them side by side. I would like to find a solution (if one exists) of the more general problem of making a Form stay on top of all windows no matter which window you click on or minimize/maximize.

Thanks
-mvick

 
Old September 26th, 2006, 11:32 PM
Friend of Wrox
 
Join Date: Dec 2004
Posts: 221
Thanks: 0
Thanked 0 Times in 0 Posts
Default

your line

"In your sample code, when you click the button to bring the Form on top, it also brings the Form's parent on top of other open Word documents. I don't know if it's possible, but I'd like to make the form come to the top without it's parent."

For me it working properly as you desired.
It brings only the form not the parent window. If the other documents are opened
only that form can is seen, not the parent window.

Well this was me. I got the horse to the pound, but I cant make it to drink.

Hope you will get your problems fixed soon.

With Regards,
Raghavendra Mudugal
 
Old September 27th, 2006, 12:14 PM
Registered User
 
Join Date: Sep 2006
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Pardon me. Computers are deterministic after all, and I misspoke. The form does work as you claim - "It brings only the form not the parent window. If the other documents are opened only that form can is seen, not the parent window."

It was not clicking the button that brought the form's parent to the top, it was clicking and dragging the form around that did it. I was hoping to find a solution where the form could be completely independent from other documents - in your solution, for example, if you minimize the parent window, the form disappears (read my first posting again).

I have tried the SetWindowPos function before (as mentioned in my first posting), but it didn't quite give the functionality I was looking for.

Thank you for you solution. I really appreciate your time. It appears to be the best so far. It still leaves me with undesired functionality, but I guess when all is said and done, my real question is: Can you sever the parent relationship a UserForm has with it's parent - can you make a UserForm act independently from its parent Word document? As far as I can tell the answer is no.

The only way I've been able to make a UserForm a child of something other than a Word document is to make the form a child of the shell window (using GetShellWindow() ). This, forces the form to be behind everything - not what I'm after.

Thanks again for you time. You are very kind. Maybe there is no way to make it do exactly what I want.

Have a good one,
-mvick

 
Old September 27th, 2006, 02:57 PM
Friend of Wrox
 
Join Date: Nov 2004
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts
Default

After you use GetShellWindow, can you set the z-order of the created form? that should be what you need.

You could try to find the current z-order of all the open windows, and add say 10 to that to guarantee to stay on top.
 
Old September 27th, 2006, 11:16 PM
Friend of Wrox
 
Join Date: Dec 2004
Posts: 221
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Okay, mvick..

do let me know when get this problem fixed. So I also get to learn.



With Regards,
Raghavendra Mudugal
 
Old September 28th, 2006, 09:37 AM
Registered User
 
Join Date: Sep 2006
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I hadn't tried your idea, Brian, and it looked like a good one.

For VBA 6 it seems like UserForms don't have a .ZOrder property, but if I understand correctly, the SetWindowPos( ) function sets the z order. I tried using that after setting my form as a child of the shell window, but it didn't bring it to the front. :(

Thanks for the help,
-msv6

 
Old September 28th, 2006, 09:50 AM
Registered User
 
Join Date: Sep 2006
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default

OK - I found the EXACT functionality I want to try to replicate. It must be possible because Word does it (somehow). I want to replicate the functionality of the Cross-reference dialog:

In Word (I know this works in 2000 and 20003):

 - From the Insert menu, select Reference and then Cross-reference
 - Open another Word document
 - Click on the older document, then the newer, then the dialog

Notice how the dialog stays on top of all Word documents, and doesn't bring its original parent to the front when you drag it around, and doesn't disappear when you minimize one of the documents.

I figure there's got to be a way to do this since it's built into Word!!

Any ideas? Thanks!

 
Old September 28th, 2006, 05:33 PM
Friend of Wrox
 
Join Date: Nov 2004
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts
Default

I would not say that this means that you can do what you are trying to do. There's nothing that says that the windows Word puts onto the screen for its own purposes have the same capability set that user forms do.

I had been suspicious that you would not be able to do this, since userforms are modal-only (implies stricter than normal use rules).

When you said that you were able to use GetShellWindow() I was surprised, and thought that therefore perhaps you would be able to affect the z-order. But now I'm back to my thinking that Word owns that window (the user-form) and will only let you do a select set of things to/with it.

Still, I'm lurking to see...





Similar Threads
Thread Thread Starter Forum Replies Last Post
Why TopMost make form at The top of all applicatio imaginator C# 1 March 7th, 2008 03:47 PM
Make Word Form Available for Use on Home Page aml Word VBA 0 March 6th, 2007 10:29 AM
Word 2000 VBA code John Stark Excel VBA 0 March 1st, 2006 06:02 AM
Word 2000 VBA AutoCorrect copying rjohnson VB How-To 0 August 30th, 2004 12:40 PM
Help with VBA (MS Word 2000) vb_programmer Beginning VB 6 0 May 22nd, 2004 12:26 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.