Solved

Key Events in an MDI Frame form

Posted on 2000-02-14
7
1,313 Views
Last Modified: 2008-03-17
We have an MDI Application.  We'd like to trap key presses in the application when there are no children forms displayed/created.  In other words, when only the MDI Frame form is displayed, we'd like to track the key press events to start a function.

I've added handlers to the Key* events (KeyPress, KeyDown and KeyUp) on the Frame form (FormStyle fsMDIForm).  However, it never gets the events.  I'm presuming that, by creating the form as a MDI frame, windows sends the key events to the active child form.

Is there a way to, when there is no active child form, to get these events sent to the frame window?  I've tried to watch the HandleMessage procedure, but I wasn't having much luck.

Thanks
0
Comment
Question by:EdHillmann
  • 3
  • 3
7 Comments
 
LVL 2

Accepted Solution

by:
hubdog earned 100 total points
ID: 2521403
you can process the application.onmessage event by yourself like this
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  RxHook, AppEvnts;

type
  TForm1 = class(TForm)
    ApplicationEvents1: TApplicationEvents;
    procedure ApplicationEvents1Message(var Msg: tagMSG;
      var Handled: Boolean);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}


procedure TForm1.ApplicationEvents1Message(var Msg: tagMSG;
  var Handled: Boolean);
begin
  if (Msg.message=wm_keydown) and (mdichildcount=0)  then
  begin
    showmessage('keydown');
    handled:=true;
  end;
end;

end.

good luck
hubdog
0
 
LVL 2

Author Comment

by:EdHillmann
ID: 2521448
Hubdog...

That did the trick.  Here's my successful test.  This is with a form whose style is fsMDIForm....


unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs;

type
  TForm1 = class(TForm)
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
    procedure MessageHandler(var Msg: TMsg; var Handled: Boolean);
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.MessageHandler(var Msg: TMsg; var Handled: Boolean);
begin
  if (Msg.message = wm_keydown) and (mdichildcount = 0)  then begin
    case Msg.wParam of
      VK_F2: begin
        ShowMessage('F2 Pressed!');
        Handled := true;
      end;
      VK_F3: begin
        ShowMessage('F3 Pressed!');
        Handled := true;
      end;
      VK_TAB: begin
        ShowMessage('Tab Pressed!');
        Handled := true;
      end;
    end;
  end;
end;

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

end.


Thanks!!
0
 

Expert Comment

by:sevenofnine
ID: 5540161
Did either of you ever get any problems using this?  Once I added it to my app, I started getting errors like 'A WIN32 API function failed'?  Any suggestions?
0
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 
LVL 2

Author Comment

by:EdHillmann
ID: 5540200
Weird.  I didn't get any errors like that.  I'll clarify that I'm using D5, although I don't think there's anything specific to D5 in that.

Maybe first comment out the ShowMessage calls to see if that causes it.  Just comment out the code and run, incrementally adding code back in to find the culprit?

Did you try this example, cause there's not much in it.  Might be easier to find the nasty line.
0
 

Expert Comment

by:sevenofnine
ID: 5540315
Yeah, I tried the code.  The problem is whenever I try to create more than one or two MDI child forms - it's like there's a memory leak?
0
 

Expert Comment

by:sevenofnine
ID: 5540379
Just rebooted my PC and the problem has mysteriously gone away.  Sorry to bother you!
0
 
LVL 2

Author Comment

by:EdHillmann
ID: 5579782
Aahh, Windows.  When all else fails, reboot!  Have fun!
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
ddeman not working in activex 3 103
oracle global variables 4 68
can i put an image from resource into image tag ? 6 24
Slow Restore if incremental backups using RDiff.exe 4 18
The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

776 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