[comp.windows.ms] Windows Hooks and Message Filters

ramspott@secola.Columbia.NCR.COM (John Ramspott) (07/26/89)

 I am having trouble using the SetWindowsHook() routine with the
WH_MSGFILTER option. I am interested in trapping when the user hits the
help button on a dialog box, which is always control id 3 in my app.
What I am expecting to see is a WM_COMMAND message with a wParam of 3.

I never get any WM_COMMAND messages, yet I know that my dialog box is
getting the message. The only thing I ever get are button up, button
down, and paint messages, and that is for the push button control, and not
the dialog box. Why is my filter function unable to get the other messages
that go to my dialog box? I currently hacked a way to figure out if the
help button has been hit by using the button up message, but this is very
schlocky...

The other complaint I have is an inaccuracy in the documentation. It claims
that the nCode your filter function will get is one of three values --
MSGF_DIALOGBOX, MSGF_MENU, and MSGF_MESSAGEBOX, and ONLY one of these
three. Not true. You can also get MSGF_SCROLLBAR if you have a list box,
as well as some nCodes for resizing.

And I get a lot more than just dialog box stuff with nCode = MSGF_DIALOGBOX.
This seems to be a catch-all for Microsoft, which uses it for mouse
movements and button activity in any window, not just a dialog box.

Finally, I often get two copies of a message for modeless dialog boxes sent
to my filter function. Any idea why?? I am currently recording the times
of messages and ignoring ones I get with no time elapsed.

The guy at Microsoft didn't have any clues, but said he will make a request
of Microsoft Online, but he gets low priority!! I have seen few if any signs
of intelligent life from either Microsoft help line, documentation, or their
"KnowledgeBase". Has anyone gotten a real, accurate, and timely response from
the Online group, or is this just another sham to get $500?

Thanx.  ---- John E. Ramspott--

These ideas are only my own. My employer will not acknowledge or understand
them.
-- 
John E. Ramspott, NCR, SE-Columbia.  Usenet: ramspott@columbia.NCR.COM
     "Amiga's so fine, there's no telling where the money went..."
Disclaimer: These ideas don't represent my company. In fact, they aren't
mine either. I just found them laying on the sidewalk.

kyler@pyr.gatech.EDU (J. Kyle Rogers) (07/27/89)

In article <385@secola.Columbia.NCR.COM> ramspott@secola.Columbia.NCR.COM (John Ramspott) writes:
>
> I am having trouble using the SetWindowsHook() routine with the
>WH_MSGFILTER option. I am interested in trapping when the user hits the
>help button on a dialog box, which is always control id 3 in my app.
>What I am expecting to see is a WM_COMMAND message with a wParam of 3.

Why can't you just trap the WM_COMMAND message within the dialog box
function?  If what you want is to trap events for the help button
before anything makes it to the dialog box function, why not just
subclass the help button?

> [...]
>The other complaint I have is an inaccuracy in the documentation. It claims
>that the nCode your filter function will get is one of three values --
>MSGF_DIALOGBOX, MSGF_MENU, and MSGF_MESSAGEBOX, and ONLY one of these
>three. Not true. You can also get MSGF_SCROLLBAR if you have a list box,
>as well as some nCodes for resizing.
> [...]

I agree.  The documentation is sketchy -- but then again, this stuff
is practically Windows internals.

>Finally, I often get two copies of a message for modeless dialog boxes sent
>to my filter function. Any idea why?? I am currently recording the times
>of messages and ignoring ones I get with no time elapsed.

Are you using the modified message loop for modeless dialog boxes
(suggested in lots of things I've seen)?
(i.e. something like this -- off the top of my head:
        while (GetMessage (...) ) {
            if (modeless dialog box present and !IsDialogMessage (...) ) {
                TranslateMessage (...)
                DispatchMessage (...)
            }
        }
)
Check the SDK Prog. Ref. Functions Overview or the Petzold book for more info.


>John E. Ramspott, NCR, SE-Columbia.  Usenet: ramspott@columbia.NCR.COM

|          krogers  --  J. Kyle Rogers  --  Technology Dynamics Inc.         |
|           145 15th Street N.E., Suite 624  --  Atlanta, GA 30361           |
|uucp: ...!{akgua,allegra,amd,hplabs,ihnp4,seismo,ut-ngp}!gatech!gitpyr!kyler|
|ARPA: kyler@pyr.gatech.edu                                                  |