Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to intercept Control-N in CDHtmlDialog ?

136 views
Skip to first unread message

Jim Howard

unread,
Jan 15, 2004, 1:02:27 PM1/15/04
to
I'm intercepting all the alt keys in my CDHtmlDialog derived dialog
application, but I can't seem to intercept the control-N "new browser" key
combination. Unlike CHtmlView, CDHtmlDialog doesn't have an OnNewWindow2
event handler.

I'm using C++ in Visual Studio .Net 2003.

I should know how to do this, but I don't.

Hints or pointers to a fax are very welcome.

Thanks,

Jim Howard

Ed Dore [MSFT]

unread,
Jan 19, 2004, 6:09:49 PM1/19/04
to
Hi Jim,

You could try intercepting the message before it's routed to the dialog.
Just override your CWinApp::PreTranslateMessage.

Sincerely,
Ed Dore [MSFT]

This post is "AS IS" with no warranties, and confers no rightsl

Jim Howard

unread,
Jan 20, 2004, 1:55:27 PM1/20/04
to
That doesn't seem to work. I'm intercepting most of the internet explorer
shortcuts that way, but it appears that the browser is eating control-N
before it gets to pretranslate.

I'm having the same problem that MS Media player has. When you use media
player to view the media guide and press control-N, you get an instance of
internet explorer with the same html rendered.

What I'd really like to do is get the newwindow2 browser event, I think this
would be a much more robust way to solve the problem rather than futzing
with intercepting keystrokes.

In the code for CHtmlDialog ( see dlgdhtml.cpp in the MFC source
files) there is an event sink map for three browser events as follows:

///////////

BEGIN_EVENTSINK_MAP(CDHtmlDialog, CDialog)

ON_EVENT(CDHtmlDialog, AFX_IDC_BROWSER, 252 /* NavigateComplete2 */,
_OnNavigateComplete2, VTS_DISPATCH VTS_PVARIANT)

ON_EVENT(CDHtmlDialog, AFX_IDC_BROWSER, 250 /* BeforeNavigate2 */,
_OnBeforeNavigate2, VTS_DISPATCH VTS_PVARIANT VTS_PVARIANT
VTS_PVARIANT VTS_PVARIANT VTS_PVARIANT VTS_PBOOL)

ON_EVENT(CDHtmlDialog, AFX_IDC_BROWSER, 259 /* DocumentComplete */,
_OnDocumentComplete, VTS_DISPATCH VTS_PVARIANT)

END_EVENTSINK_MAP()/////////// If you look at the event sink map for
CHtmlView (located in
viewhtml.cpp) you'll see that they have event handlers not only for
OnNewWindow2, but for many other browser events beyond the three
supported by CHtmlDialog.

How do I add similar browser event handlers to my CHtmlDialog derived
class to handle the OnNewWindow2 and other similar browser events?

I tried adding this to my CDHtmlDialog derived class:
///////////////

BEGIN_EVENTSINK_MAP(CMyHtmlDlg, CDHtmlDialog)

ON_EVENT(CMyHtmlDlg, AFX_IDC_BROWSER, 251 /*DISPID_NEWWINDOW2*/,
OnNewWindow2, VTS_PDISPATCH VTS_PBOOL)

END_EVENTSINK_MAP()

/////////////////////

This compiles, but doesn't catch the new window event.

I must be missing something pretty simple.

Thanks,

Jim

""Ed Dore [MSFT]"" <ed...@online.microsoft.com> wrote in message
news:8EeUOFu3...@cpmsftngxa07.phx.gbl...

Ed Dore [MSFT]

unread,
Feb 9, 2004, 6:49:04 PM2/9/04
to
Hi Jim,

I'm not sure why your handler isn't getting called. I see the same problem.
I also tried sinking the DocumentComplete event, and that does seem to get
called, so I'm pretty sure we've got the event handler wired up correctly.
I have some email out the IE programability team, I'll let you as soon as I
hear back.

Sincerely,
Ed Dore [MSFT\

This post is "AS IS" with no warranties, and confers no rights.

Ed Dore [MSFT]

unread,
Feb 9, 2004, 8:38:39 PM2/9/04
to
Hi Jim,

I take that back. I do know why it's not getting called. The CDHtmlDialog
class sinks DWebBrowserEvents, not DWebBrowserEvents2. The DownloadComplete
method I was using as a baseline is actually present in both event
interfaces, wherease the NewWindow2 is only implemented by the latter.

I did some digging around the MFC sources, and it looks like the only way
to do this is to create a new sink object. None of the virtual methods on
the CDHtmlDialog or the CDhtmlEventSink class it derives from will allow
you to receive the events from that other interface.

For ideas on how to sink the DWebBrowserEvents2 interface, you might want
to review the following KB article:

HOWTO: Create a Sink INterface in MFC-Based COM Client
http://support.microsoft.com/?id=181845

Jim Howard

unread,
Feb 25, 2004, 12:05:19 PM2/25/04
to
Ed,

Thanks for you insight into this issue. I'll give making my own sink object
a try.

What really saved me on this was the fact that on my development machine I
can generate a new browser instance on control-N with MS Media Player when
the "Media guide" tab is selected. When I showed this to my boss he decided
that if it's acceptable to MS, its acceptable to us also.

My development machine seems to be the only copy of media player that I've
tried that exhibits this control-n behavior, so I got lucky there.

In any case I really appreciate your helping me understand what is
happening.

Jim Howard


""Ed Dore [MSFT]"" <ed...@online.microsoft.com> wrote in message

news:VuSNda37...@cpmsftngxa07.phx.gbl...

0 new messages