Articles   Members Online:
-Article/Tip Search
-News Group Search over 21 Million news group articles.
-Delphi/Pascal
-CBuilder/C++
-C#Builder/C#
-JBuilder/Java
-Kylix
Member Area
-Home
-Account Center
-Top 10 NEW!!
-Submit Article/Tip
-Forums Upgraded!!
-My Articles
-Edit Information
-Login/Logout
-Become a Member
-Why sign up!
-Newsletter
-Chat Online!
-Indexes NEW!!
Employment
-Build your resume
-Find a job
-Post a job
-Resume Search
Contacts
-Contacts
-Feedbacks
-Link to us
-Privacy/Disclaimer
Embarcadero
Visit Embarcadero
Embarcadero Community
JEDI
Links
How to pass a [CTRL] [TAB] to a TPageControl on a MDI child form Turn on/off line numbers in source code. Switch to Orginial background IDE or DSP color Comment or reply to this aritlce/tip for discussion. Bookmark this article to my favorite article(s). Print this article
21-Oct-02
Category
VCL-General
Language
Delphi 2.x
Views
62
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			Author: Jonas Bilinkevicius

I have a TabControl inserted into a MDI child form. When one press the Ctrl+Tab or 
Ctrl+Shift+Tab keys, the application selects the next (previous) MDIChildForm 
instead of changing the active page of TabControl. How can I force the MDIChild 
pass the Ctrl+Tab to the TabControl?

Answer:

This is in fact a conflict on the API level. In a MDI application the message loop 
will call IsMDIMsg on every key message fetched form the message loop, and this 
function calls the API TranslateMDISysAccel function. This in turn handles the 
Ctrl-Tab, so the child form never even sees the key event.

To get around this one needs to intervene before IsMDIMsg is even called. There is 
only one opportunity to do this: the Application.OnMessage event. So add a handler 
for the main form OnCreate event, and add a private method to the form called 
AppMessage:
1   
2   procedure TMainForm.FormCreate(Sender: TObject);
3   begin
4     Application.OnMessage := AppMessage;
5   end;
6   
7   procedure TMainform.Appmessage(var Msg: TMsg; var Handled: Boolean);
8   var
9     message: TWMKey;
10  begin
11    if (msg.message = WM_KEYDOWN) and (LoWord(msg.wparam) = VK_TAB) and
12      (GetKeyState(VK_CONTROL) < 0) and Assigned(ActiveMDIChild) then
13    begin
14      Move(msg.message, message.msg, 3 * sizeof(Cardinal));
15      message.result := 0;
16      Handled := ActiveMDIChild.IsShortcut(message);
17    end;
18  end;


This will redirect Ctrl+Tab (and Ctrl+Shift+Tab) to the active MDI childs 
IsShortcut function. This fires the OnShortcut event, so we can use that event on 
the child form to further handle the key event:
19  
20  function IsOnTabsheet(aControl: TWinControl; var pc: TPageControl): Boolean;
21  begin
22    while Assigned(aControl) and not (aControl is TTabsheet) do
23      aControl := aControl.Parent;
24    Result := Assigned(aControl);
25    if result then
26      pc := TTabSheet(aControl).Pagecontrol;
27  end;
28  
29  procedure TMDIChild.FormShortCut(var Msg: TWMKey; var Handled: Boolean);
30  var
31    pc: TPageControl;
32  begin
33    if (msg.CharCode = VK_TAB) and (GetKeyState(VK_CONTROL) < 0) then
34    begin
35      if IsOnTabsheet(ActiveControl, pc) then
36      begin
37        pc.Perform(CM_DIALOGKEY, msg.CharCode, 0);
38        Handled := true;
39      end;
40    end;
41  end;


That seems to do the trick.

			
Vote: How useful do you find this Article/Tip?
Bad Excellent
1 2 3 4 5 6 7 8 9 10

 

Advertisement
Share this page
Advertisement
Download from Google

Copyright © Mendozi Enterprises LLC