|
Subject:
|
VBA w/ Word 2000 - Make form on top of everything
|
|
Posted By:
|
mvick
|
Post Date:
|
9/25/2006 4:05:12 PM
|
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.
|
|
Reply By:
|
Raghavendra_Mudugal
|
Reply Date:
|
9/26/2006 2:36:44 AM
|
check this link
http://www.geocities.com/raghavendra_mudugal/VBA_SetWindowPos_EXAMPLE.zip
It is created in MS-Word 2002 (Office XP)
Hope this helps.
With Regards, Raghavendra Mudugal
|
|
Reply By:
|
mvick
|
Reply Date:
|
9/26/2006 10:31:42 AM
|
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
|
|
Reply By:
|
Raghavendra_Mudugal
|
Reply Date:
|
9/26/2006 11:32:51 PM
|
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
|
|
Reply By:
|
mvick
|
Reply Date:
|
9/27/2006 12:14:26 PM
|
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
|
|
Reply By:
|
BrianWren
|
Reply Date:
|
9/27/2006 2:57:21 PM
|
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.
|
|
Reply By:
|
Raghavendra_Mudugal
|
Reply Date:
|
9/27/2006 11:16:38 PM
|
Okay, mvick..
do let me know when get this problem fixed. So I also get to learn.
With Regards, Raghavendra Mudugal
|
|
Reply By:
|
mvick
|
Reply Date:
|
9/28/2006 9:37:53 AM
|
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
|
|
Reply By:
|
mvick
|
Reply Date:
|
9/28/2006 9:50:47 AM
|
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!
|
|
Reply By:
|
BrianWren
|
Reply Date:
|
9/28/2006 5:33:09 PM
|
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...
|
|
Reply By:
|
mvick
|
Reply Date:
|
10/2/2006 9:28:54 AM
|
Good point. Thanks for your help Brian. I'll keep digging around also, and will certainly post any interesting findings.
|