views:

406

answers:

4

How would I go about implementing the Ctrl+F6 Next Window action in the Windows menu for an MDI application in Delphi 7?

+1  A: 

I don't think you need to do anything - it is implicit in MDI apps (created with the new MDI app wizard in Delphi 2006 anyway).

It also "just works" in an app the was originally created in Delphi 6 as well.

Gerry
I realize it just works, but several of our customers are not aware of the Ctrl+Tab/Ctrl+F6 or Ctrl+Shift+Tab/Ctrl+Shift+F6 shortcuts. We just want to have it available in the Windows menu to help them learn the keyboard shortcuts.
Mike Howard
+1  A: 

Send the main form a wm_SysCommand message. Use sc_NextWindow or sc_PrevWindow for the wParam parameter.

Rob Kennedy
Unnecessary overkill, Rob. TCustomForm.Next and TCustomForm.Previous accomplish the same thing, and assigning them to menu item OnClick events (with whatever shortcuts you want) is child's play.
Ken White
Didn't know those methods existed. And I'm disappointed that the wm_SysCommand documentation doesn't mention the wm_MdiNext message, which is what TCustomForm.Next sends. There are several ways to skin this cat.
Rob Kennedy
Several ways is true, as always. TCustomForm has actually implemented Next/Previous since before there even *was* a TCustomForm (Delphi 1), where the base for forms was TForm. I'm suspecting the lack of documentation on wm_MdiNext is because MS has deprecated MDI since around the days of Delphi 2 and Win95.
Ken White
+1  A: 

Use the Next and Previous methods of the MDI parent window. You can do this from a menu event, and assign a shortcut like any other menu item. In the code below, the MDI parent form is TFormMDIParent, and it assumes you've created two menu items captioned "Next Child" and "Previous Child", leaving their names set to the default generated by the IDE. It also assumes that you've set the main form up correctly to be the MDI parent (FormStyle = fsMDIForm).

procedure TFormMDIParent.NextChild1Click(Sender: TObject);
begin
  Self.Next;
end;

procedure TFormMDIParent.PreviousChild1Click(Sender: TObject);
begin
  Self.Previous;
end;
Ken White
Ken you answer works, although the Next and Previous work in reverse order to what I think is the Next and Previous windows. If I open 4 windows and I am on the 3rd window that was opened and I perform the Self.Next, I would think that the next window would be the 4th window but it actually gives focus to the 2nd window. Works the same way with the built-in Ctrl+F6/Shift+Ctrl+F6 keys.
Mike Howard
Hmmm... I never noticed that, Mike, but I'll readily admit that I quit doing MDI applications back in the Delphi 2 days. They've been deprecated by MS since that time, and I never did like them much anyway. :-) I'd guess that the interpretation of Next/Previous are an MS thing, because the built-in hotkeys work that way as well (even in non-Delphi MDI apps). Actually, I think the behavior varies. Try focusing window 3, clicking with the mouse on win 1, click on win 2, and then try Next. Where do you end up?
Ken White
A: 

thank for all comment and answer

Ponghyper