Re: What does an Active X control mean by Accelerator?

From: DavidB (davidb3_at_Ihatespam.hurkle.com)
Date: 08/17/04


Date: Tue, 17 Aug 2004 11:09:49 +1000

Yes, we've studied that code pretty carefully. It was the one that gave us
the clue about handling accelerators, but it depends on hooking into the
event loop, which we really don't want to do.

Incidentally, a chunk of code out of this sample seems to have turned up in
ATL 7. Now I wonder, did the guys get advance code from MS, or did someone
at MS think: great idea, we can use that!

What still surprises me is just how little code there is to do this stuff.
Most jobs, you can find dozens of samples on the Web. not this one.

DavidB

"Alexander Nickolov" <agnickolov@mvps.org> wrote in message
news:e0JCyx6gEHA.2916@TK2MSFTNGP12.phx.gbl...
> Check out an artivcle by Chris Sells and Dharma Shukla in
> Dec'99 issue of MCJ, titled something about extending ATL
> for real world containers. You may enjoy it... :)
>
> --
> =====================================
> Alexander Nickolov
> Microsoft MVP [VC], MCSD
> email: agnickolov@mvps.org
> MVP VC FAQ: http://www.mvps.org/vcfaq
> =====================================
>
> "DavidB" <davidb3@Ihatespam.hurkle.com> wrote in message
> news:31hTc.56712$K53.32251@news-server.bigpond.net.au...
> > Yes, sorry, that came out a bit snotty.
> >
> > Our challenge is to host a wide variety of other people's ActiveX
> controls,
> > most of which have probably been designed to work with VB, and get
correct
> > behaviour without hacking the event loop (which VB almost certainly
does).
> >
> > The solution we came up with is to use an AtlAxWindow to host the
control,
> > and after creating the control to subclass the child window using a
> CWindow.
> > We can then intercept the WM_KEYxxx messages, send them first to the
> > IOleInplaceActiveObject::TranslateAccelerator, and if not translated,
hand
> > them back to the WndProc. It seems to work nicely.
> >
> > The final solution seems to be simple and clean, it just isn't at all
> > obvious!
> >
> > The bottom line seems to be that although this is a lovely piece of
> > functionality provided in ATL, there are gaps and gotchas, and not many
> > people writing about it or posting code. Could be an opportunity here!
> >
> > DavidB
> >
> > "Alexander Nickolov" <agnickolov@mvps.org> wrote in message
> > news:%23Ijq2aOgEHA.3632@TK2MSFTNGP09.phx.gbl...
> > > Ok, ok, it is hard to judge the poster's level of experience
> > > from the initial post and I make mistakes...
> > >
> > > The intended behavior is for the control to translate its
> > > own accelerators within, anything else it feeds to the site.
> > > It is not strictly mandatory to use ::TranslateAccelerator,
> > > especially windowless controls can't do it for obvious
> > > reasons. The important point is to preserve the semantics.
> > >
> > > Ah, and ATL's control support is quite limited, so don't
> > > be surprised...
> > >
> > > --
> > > =====================================
> > > Alexander Nickolov
> > > Microsoft MVP [VC], MCSD
> > > email: agnickolov@mvps.org
> > > MVP VC FAQ: http://www.mvps.org/vcfaq
> > > =====================================
> > > "DavidB" <davidb3@Ihatespam.hurkle.com> wrote in message
> > > news:411c1424$0$27219$61ce578d@news.syd.swiftdsl.com.au...
> > > > This may come as a surprise, but I've been programming Windows for
> > over12
> > > > years. I read the first edition of Petzold cover to cover -- the
later
> > > > editions are less useful. I know precisely what an accelerator is in
> > > > Windows
> > > > terminology, including data structures, functions, etc, etc. I know
> that
> > > > to
> > > > translate an accelerator means to convert it into a WM_COMMAND or
> > > > WM_SYSCOMMAND, with wParam high order=1, sent to the same window.
> > > >
> > > > I also know that meanings shift over time. They broaden, narrow,
blur,
> > > > etc.
> > > > IT people don't always do their history lessons.
> > > >
> > > > A superficial study of some common ActiveX controls:
> > > > Calendar -- translates accelerators, as defined (generates
> WM_COMMAND).
> > > > Rich text -- acts on arrow keys sent to WndProc, but doesn't
translate
> > any
> > > > accelerators.
> > > > FlexGrid -- ignores arrow keys sent to WndProc; acts on arrow keys
> sent
> > to
> > > > IOleInplaceActiveObject::TranslateAccelerator but does not translate
> > > > accelerators (no WM_COMMAND).
> > > >
> > > > IMHO this last control bends the meaning of "translate accelerator"
to
> > > > breaking point. I don't write controls, so I'm trying to understand
> the
> > > > mindset of those who do. My guess is nobody cares much about the
finer
> > > > points, as long as it works with VB.
> > > >
> > > > ATL seems to provide very limited (and undocumented) support for
> > controls
> > > > like this. Which is why I hoped I might get some comments from
someone
> > who
> > > > had worked with this stuff to help us on our way.
> > > >
> > > > DavidB
> > > >
> > > > "Alexander Nickolov" <agnickolov@mvps.org> wrote in message
> > > > news:upvOIBJgEHA.632@TK2MSFTNGP12.phx.gbl...
> > > >> I guess an Win32 introductory book is in order here:
> > > >>
> > > >> "Programming Windows", fifth edition, by Charles Petzold
> > > >>
> > > >> Accelerators are a classic Windows concept, you are simply
> > > >> looking at the mechanism OLE employs for comminucating
> > > >> them to ActiveX Controls. Have a look at TranslateAccelerator,
> > > >> the Win32 API function, too. And, yes, accelerators keys are
> > > >> not dispatched to the window that currently has the focus.
> > > >> They are instead converted into other Windows messages,
> > > >> namely WM_COMMAND and WM_SYSCOMMAND.
> > > >>
> > > >> --
> > > >> =====================================
> > > >> Alexander Nickolov
> > > >> Microsoft MVP [VC], MCSD
> > > >> email: agnickolov@mvps.org
> > > >> MVP VC FAQ: http://www.mvps.org/vcfaq
> > > >> =====================================
> > > >>
> > > >> "DavidB" <davidb3@Ihatespam.hurkle.com> wrote in message
> > > >> news:DaMSc.53547$K53.26234@news-server.bigpond.net.au...
> > > >> > Is an accelerator intended to imply any keyboard input which
isn't
> a
> > > > data
> > > >> > key?
> > > >> >
> > > >> > Take the Rich Text control. What you type is what you see. Data
> keys.
> > > >> >
> > > >> > Take the Calendar control. The arrow keys move around. Are arrow
> keys
> > > >> > accelerators?
> > > >> >
> > > >> > If so, am I right in assuming that when an ActiveX control is
> > UIActive
> > > > and
> > > >> > gets the focus, it can happily process a whole range of windows
> > > >> > messages
> > > >> > (including keyboard messages for data keys), but not keyboard
> > messages
> > > > for
> > > >> > accelerators?
> > > >> >
> > > >> > That it is necessary to filter out the accelerators and feed them
> in
> > > >> > the
> > > >> > back door, using IOleControlSite::TranslateAccelerator()?
> > > >> >
> > > >> > That this either means contaminating the event loop, or
subclassing
> > the
> > > >> > ActiveX control window?
> > > >> >
> > > >> > It seems strange, but if that's what it takes...
> > > >> >
> > > >> > DavidB
> > > >> >
> > > >> >
> > > >>
> > > >>
> > > >
> > > >
> > >
> > >
> >
> >
>
>



Relevant Pages

  • Re: CWindowImpl-derived classes in dialog boxes
    ... Now I remember what was the principle problem with ATL ... for User Controls - its startup windowproc does not allocate ... the actual class instance is not even allocated); ...
    (microsoft.public.vc.atl)
  • Re: Quest: Creating an ActiveX panel control...
    ... I think you need to start from the basics on creating ActiveX controls. ... always prefer using ATL rather than MFC, ...
    (microsoft.public.vc.mfc)
  • Re: ocx creation
    ... There are two options - ATL and MFC. ... framework and it offers extensive support for writing ActiveX ... Controls. ...
    (microsoft.public.win32.programmer.ole)
  • Re: Controls
    ... If you want to use MFC, why bother with ATL in the first place? ... for Windows and Common Controls. ... Microsoft MVP, MCSD ...
    (microsoft.public.vc.atl)
  • Re: Tab Control Shortcut Keys Don Work
    ... Dim ctl As Control ... to use the keyboard rather than the mouse, and have requested shortcut keys ... for all button controls and tab controls. ...
    (microsoft.public.access.modulesdaovba)