Link to home
Start Free TrialLog in
Avatar of dudup
dudup

asked on

Changing default event problem

Hi,

I want to change a default event WindowProc of TWebBrowser.

I do like this :

// Pass any key press to the main form onKeyDown event
procedure TMainForm.BrowserWndProc(var Message: TMessage);
begin
  case Message.Msg - CN_BASE of
    WM_KEYFIRST..WM_KEYLAST: // redirect all keyboard messages to self
      Perform(Message.Msg - CN_BASE, Message.WParam, Message.LParam);
    else // pass all other messages back to webbrowser
      FOldWndProc(Message);
  end;
end;

{    
    FOldWndProc: TWndMethod;
    procedure BrowserWndProc(var Message: TMessage);
}

procedure TMainForm.CreateBrowser(URL: string; InPanel: TPanel);
var
  AWeb: TWebBrowser;
begin
    AWeb := TWebBrowser.Create(InPanel);      // attach it to Panel1
    TWinControl(AWeb).Name := 'NewWeb';
    TWinControl(AWeb).Parent := InPanel;
    AWeb.Align := alClient;
    AWeb.Navigate(URL);
    FOldWndProc := AWeb.WindowProc;
    AWeb.WindowProc := BrowserWndProc;
end;

As you can see, I use the FOldWndProc to save the default event handler.

This works fine, however ...
My problem is, how to make this work for "multiple TWebBrowsers" object?
Because the application will have multiple panel and each panel will have a TWebBrowser.

In my understanding each TWebBrowser object should have its own FOldWndProc, but how to do this ?

Thanks for any help.
ASKER CERTIFIED SOLUTION
Avatar of 2266180
2266180
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial