Application.WindowBeforeDoubleClick passes in a Selection in the main document when double clicking in a header
-
Thursday, May 03, 2012 10:27 PM
How can I determine that the double click was to switch the mode to the header?
thanks - dave
Who will win The International Collegiate Programming Championships?
All Replies
-
Friday, May 04, 2012 3:26 AMModerator
Hi Dave,
Thanks for posting in the MSDN Forum.
What's mean of "mode to the header" ? Would you please show your scenario more detailed?
Have a good day,
Tom
Tom Xu [MSFT]
MSDN Community Support | Feedback to us
-
Friday, May 04, 2012 6:09 AMModerator
Hi David / Tom
@Tom: David wants to know when double-clicking has activated the Header/Footer editing mode, instead of selecting text.
@David: If your solution has a Ribbon customization, I'd try using CommandBars.GetEnabledMso or GetVisibleMso in the event to find out if a Header/Footer specific command is available in the UI. This seems to work in a quick test:
commandBars.GetEnabledMso("HeaderFooterClose")
Cindy Meister, VSTO/Word MVP
-
Monday, May 07, 2012 5:34 PM
This post is wrong (see following post):
That half works - it tells us if we're in the header/footer. However, once in the header/footer we do want to handle a double click on one of our tags. So is there any way to know if the double click was to enter the header?
thanks - dave
Who will win The International Collegiate Programming Championships?
- Edited by DavidThi808 Monday, May 07, 2012 6:02 PM
-
Monday, May 07, 2012 6:01 PM
Update: (I had it wrong - that also returns the mode you're leaving, not the mode being switched to.)
The commandBars.GetEnabledMso("HeaderFooterClose") returns the state before the mode switch. I think this makes sense because the event can cancel the double click. But the selection passed is a problem.
Is there a way to use the mouse position to determine if it is in the header or main story?
thanks - dave
Who will win The International Collegiate Programming Championships?
-
Thursday, May 10, 2012 5:12 PMModeratorIn your Application.SelectionChange event handler you can test for Word.Selection.HeaderFooter.IsHeader which rethrns a bool - True if you're in the header, False if not.
Please remember to mark the replies as answer if they help and unmark them if the provide no help. and click "Vote as Helpful" this and other helpful posts, so other users will see your thread as useful. Chris Jensen
-
Thursday, May 10, 2012 5:48 PM
Hi Chris;
Unfortunately that returns where you are, not where you will be. I think that logically makes sense as the event is can the double clicked be passed on to Word, not the double click has been processed.
But that leaves the problem of how do I know when it is a double clcik inside th main story vs a double click that is about to transition to the header?
thanks - dave
Who will win The International Collegiate Programming Championships?
-
Thursday, May 10, 2012 10:25 PM
Ok, this is the best I could come up with to do this (yuck):
// if going between mainstory & header - we don't do anything. // note sel is the Selection object Point pt = NativeMethods.GetMessageMousePos(); Window wnd = sel.Document.ActiveWindow; Range rngCaret = wnd.RangeFromPoint(pt.X, pt.Y) as Range; if (rngCaret != null) { if ((rngCaret.StoryType == WdStoryType.wdMainTextStory) && (sel.HeaderFooter != null) && sel.HeaderFooter.IsHeader) return; if ((rngCaret.StoryType != WdStoryType.wdMainTextStory) && ((sel.HeaderFooter == null) || (!sel.HeaderFooter.IsHeader))) return; }thanks - dave
Who will win The International Collegiate Programming Championships?
- Marked As Answer by DavidThi808 Thursday, May 10, 2012 10:26 PM
-
Friday, May 11, 2012 9:41 AMModerator
Hi Dave
As you say, "Yuck". But at least you've found a way - and thanks for sharing :-)
Cindy Meister, VSTO/Word MVP

