Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Getting keys to work in WebBrowser

Posted on 2003-03-01
7
Medium Priority
?
179 Views
Last Modified: 2010-04-04
Hi there,

I'm making a little program for playing flash games without a internet connection, it's ment for my coworkers when they want to play a little game when they have nothing to do, without having to go on internet.

The games are flashgames (like pacman andso), which i download from internet.

I use the WebBrowser component to navigate to the <filename>.swf file, and that works okay.

But then, after you click <PLAY>, the game starts, pacman (in this example) starts eating his way, but you can't send him in any direction...bummer...

I tried to made the WebBrowser component the active one the form, but no luck.
Even when I first click in the browser component, no luck.

In IE6 it's works fine with just the <filename>.swf file, but as soon as mine program starts, it doesn't work in my program.

It's very simpel for now, just a form, a menu bar with a start option and a webbrowser component. But before i go making the program be able to play more games, update itself etc., i first want to get this problem fixed.

For the moment i'm talking about the cursor keys, but ofcourse al keys have to go directly to the webbrowser component.

What am i doing wrong ?
0
Comment
Question by:WMPeters
  • 4
  • 3
7 Comments
 
LVL 6

Expert Comment

by:DaFox
ID: 8047590
Hi.

Add this to your unit:

initialization
  CoInitialize(nil);

finalization
  CoUninitialize;

Markus
0
 

Author Comment

by:WMPeters
ID: 8047664
Markus, i get the following error :

[Error] Unit1.pas(46): Undeclared identifier: 'CoInitialize'
[Error] Unit1.pas(49): Undeclared identifier: 'CoUnitialize'

Some unit i forgot ?
0
 
LVL 6

Expert Comment

by:DaFox
ID: 8047729
> Some unit i forgot ?

Yep, my fault, sorry.
You have to include ActiveX -> uses ActiveX ;-)

Markus
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

by:WMPeters
ID: 8047739
Yep, i found that unit, but still doesn't work.

The code now looks like this: (still dirty)
Any ideas?

---

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, Menus, OleCtrls, SHDocVw, ComCtrls, activex;

type
  TForm1 = class(TForm)
    MainMenu1: TMainMenu;
    File1: TMenuItem;
    Close1: TMenuItem;
    StatusBar1: TStatusBar;
    wb1: TWebBrowser;
    Pacman1: TMenuItem;
    procedure Close1Click(Sender: TObject);
    procedure Pacman1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}


procedure TForm1.Close1Click(Sender: TObject);
begin
application.Terminate;
end;

procedure TForm1.Pacman1Click(Sender: TObject);
begin
  wb1.navigate('file:///c:/PacMan.Swf');
end;

Initialization
 CoInitialize(nil);


Finalization
 CoUninitialize;

end.
0
 
LVL 6

Accepted Solution

by:
DaFox earned 300 total points
ID: 8047799
Okaydokay...

Now we got 2 possibilities:

1. We set up our own message handler:
...
  private
    FOleInPlaceActiveObject: IOleInPlaceActiveObject;
    procedure MyMessageHandler(var Msg: TMsg; var Handled: Boolean);

...

procedure TForm1.MyMessageHandler(var Msg: TMsg; var Handled: Boolean);
var
  iOIPAO: IOleInPlaceActiveObject;
  Dispatch: IDispatch;
begin
  // exit if we don't get back a webbrowser object
  if (WebBrowser1 = nil) then
  begin
    Handled := false;
    exit;
  end;

  Handled := (IsDialogMessage(WebBrowser1.Handle, Msg) = True);

  if (Handled) and (not WebBrowser1.Busy) then
  begin
    if FOleInPlaceActiveObject = nil then
    begin
      Dispatch := WebBrowser1.Application;
      if Dispatch <> nil then
      begin
        Dispatch.QueryInterface(IOleInPlaceActiveObject, iOIPAO);
        if iOIPAO <> nil then FOleInPlaceActiveObject := iOIPAO;
      end;
    end;
    if FOleInPlaceActiveObject <> nil then
    begin
      if ((Msg.message = WM_KEYDOWN) or (Msg.message = WM_KEYUP)) and ((Msg.wParam = VK_BACK) or (Msg.wParam = VK_LEFT) or (Msg.wParam = VK_RIGHT)) then
        //nothing - do not pass on Backspace, Left or Right arrows
      else
         FOleInPlaceActiveObject.TranslateAccelerator(Msg);
    end;
  end;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  Application.OnMessage := MyMessageHandler;
end;

2. -> http://community.borland.com/article/0,1410,6302,00.html (if we don't succeed using possibility 1 ;-)

Markus
0
 

Author Comment

by:WMPeters
ID: 8047814
Yep, i found that unit, but still doesn't work.

The code now looks like this: (still dirty)
Any ideas?

---

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, Menus, OleCtrls, SHDocVw, ComCtrls, activex;

type
  TForm1 = class(TForm)
    MainMenu1: TMainMenu;
    File1: TMenuItem;
    Close1: TMenuItem;
    StatusBar1: TStatusBar;
    wb1: TWebBrowser;
    Pacman1: TMenuItem;
    procedure Close1Click(Sender: TObject);
    procedure Pacman1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}


procedure TForm1.Close1Click(Sender: TObject);
begin
application.Terminate;
end;

procedure TForm1.Pacman1Click(Sender: TObject);
begin
  wb1.navigate('file:///c:/PacMan.Swf');
end;

Initialization
 CoInitialize(nil);


Finalization
 CoUninitialize;

end.
0
 

Author Comment

by:WMPeters
ID: 8047825
Works fine, now hopefully i can get other keys to work for other games.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Suggested Courses

578 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question