Re: How to Inherit a Keypress?

From: Bruce Roberts (ber_at_bounceitattcanada.xnet)
Date: 06/18/04


Date: Fri, 18 Jun 2004 10:18:33 -0400


"Alistair George" <noemailadds@xtra.co.nz> wrote in message
news:40d238a3@news.orcon.net.nz...
> In the following code, if the user presses the Right-Mouse down, the
> mousedown
> re-enters despite putting variable:MBdownmsg (which is not a very
> satisfactory
> method.)

I have some difficulty with the logic in the routine.

Using Application.ProcessMessages is not something one wants to do in a
message handler. It really isn't. The call is likely at the root of your
reentrancy problem.

I also wonder why the routine uses GetCursorPos instead of the
MouseHookStruct pointed to by lParam.

IMO, Exit is overused in the routine and contributes somewhat to its poor
construction. You might want to consider a construction similar to that
shown below. IMO it more clearly expresses what is supposed to happen. (I'm
reasonably sure that this alternate construction accurately reflects the
logic you posted but I won't swear to it.)

function Balloon_Mouse_HookProc . . .

    function doCommonCode : lResult;

    begin
    if Assigned (BalloonForm.OnClose)
    then BalloonForm.Close
    else BalloonForm.Release;
    if not BalloonForm.tmrExit.Enabled
    then begin
        if Assigned (zBalloonControl.OnClick) and
          (zBalloonControl.fShowMode = smDefault) and
          (BalloonForm.lblClickHere.Visible) and
          (PtInRect (BalloonForm.lblClickHere.BoundsRect,
BalloonForm.ScreenToClient (Mouse.CursorPos))
        then begin
            result := 0;
            zBalloonControl.OnClick (zBalloonControl);
            end
        else result := 1;
        end;
    end;
. . .
begin
result := 0;
case wParam of
    wm_RButtonDown : begin
        if not MBDownMsg
        then begin
            MBDownMsg := True;
            GetCursorPos (Pt); // why not lParam structure?
            zBalloon.zBalloonControl.MouseDown (mbLeft, Shift, Pt.x, Pt.y);
            end;
        end;
    wm_LButtonUp : begin
        if BalloonForm.tmrExit.Enabled
        then begin
            MBDownMsg := False;
            end
        else result := doCommonCode;
        end;
    wm_LButtonDblClk,
    wm_RButtonUp,
    wm_RButtonDblClk,
    wm_MButtonUp,
    wm_MButtonDown : begin
        result := doCommonCode;
        end;
    wm_MouseWheel,
    wm_MouseMove : begin
        if not BalloonForm.tmrExit.Enabled
        then result := doCommonCode
        else begin
            if not (zBalloonControl.fShowMode in [smMessage, smError,
smWorning {sic}])
            then result := CallNextHookEx (BalloonMouseHookHandle, Code,
wParam, lParam);
            end;
        end;
    else begin
        if (zBalloonControl.fShowMode in [smMessage, smError, smWorning
{sic}])
        then result := doCommonCode
        else result := CallNextHookEx (BalloonMouseHookHandle, Code, wParam,
lParam);
        end;
    end;
end;



Relevant Pages

  • Re: How to catch WM_PAINT use Hook in Dialog?
    ... return CallNextHookEx(m_hCallWndhook, nCode, wParam, lParam); ... rather than just putting you code into the OnPaint() routine? ...
    (microsoft.public.vc.mfc)
  • Re: Corresponding forms of new and delete
    ... > routine may not do what's right given that the memory was not ... primarily because of potential failure of the object construction while ... delete this passed pointer, so how can the functions know which operator ... you have to manually deallocate and delete the ...
    (comp.lang.cpp)
  • RE: I want to update a row if it exists and Insert if the row dont ex
    ... am creating application for construction of telecom sites. ... wanted update routine to check if the site exits else I ... > I am Using Left outer join to join the tables. ... The inner table may or may ...
    (microsoft.public.access.modulesdaovba)
  • ObjectConstruction Automatic Logs???
    ... I wrote a servicedComponent and set the constructionEnabledatribute ... constructroutine and started testing some errors. ... SQL Server does not exist or access denied. ... The following component is configured for Construction, ...
    (microsoft.public.dotnet.framework.component_services)
  • Re: ActiveX event and DoModal
    ... afx_msg void OnSysCommand(UINT nID, LPARAM lParam); ... afx_msg void OnPaint; ... // cannot call DoModal on a dialog already constructed as modeless ...
    (microsoft.public.vc.mfc)