Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Inactivate CTRL+Tab in MDI apps

Status
Not open for further replies.

Nordlund

Programmer
Jul 17, 2001
458
SE
Hi...
I would like to inactivate the use of CTRL+Tab in a MDI application...

...any ideas?

KungTure-RX.jpg

//Nordlund
 
...The actual problem is that I want to disable the use of shifting windows in an MDI application by use of CTRL+Tab

KungTure-RX.jpg

//Nordlund
 
I've found a way to do this, but I think this way will slow down the application really much due to the "GetKeyboardState" procedure... Give me comments!

Start with a project with 3 forms.
Form1 = fsMDIForm
Form2 = fsMDIChild
Form3 = fsMDIChild

Add a TApplicationEvents component om the main form (Form1).
Write the following code in the OnMessage event:
Code:
procedure TForm1.ApplicationEvents1Message(var Msg: tagMSG; var Handled: Boolean);
var
  S: TKeyboardState;
begin
  case Msg.message of
    WM_KEYDOWN:
      begin
        GetKeyboardState(S);
        if (S[VK_CONTROL] and $80 <> 0) and (S[9] and $80 <> 0) then
          Handled := true;
      end;
  end;
end;

KungTure-RX.jpg

//Nordlund
 
with appevents, this is the quickest method I think :

Code:
//define ctrl as global var somewhere and set it to false

procedure TMainForm.ApplicationEvents1Message(var Msg: tagMSG; var Handled: Boolean);
begin
  case Msg.message of
    WM_KEYDOWN:
      begin
       if Ctrl then
        Handled:=Msg.Wparam = VK_TAB
       else
        Ctrl:=Msg.Wparam = VK_CONTROL;
      end;
  end;
end;

I'm also investigating for a method without the use off appevents...

--------------------------------------
What You See Is What You Get
 
without applicationevents object :
Code:
procedure TMainForm.FormCreate(Sender: TObject);
begin
 Application.OnMessage:=ApplicationEvents1Message;
end;

procedure TMainForm.ApplicationMessage(var Msg: tagMSG; var Handled: Boolean);
begin
 if Msg.message = WM_KEYDOWN then
  begin
   if Ctrl then
    Handled:=Msg.Wparam = VK_TAB
   else
    Ctrl:=Msg.Wparam = VK_CONTROL;
  end;
end;

--------------------------------------
What You See Is What You Get
 
small typo :

change 'application.onmessage' line to

Application.OnMessage:=ApplicationMessage;

--------------------------------------
What You See Is What You Get
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top