unit uMainWindows;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Menus, ComCtrls, StdCtrls, ExtCtrls, ToolWin, Buttons, ImgList, shlobj;
const
WM_MDIWINDOWCREATE = WM_USER + 1;
WM_MDIWINDOWDELETE = WM_USER + 2;
WM_MDIWINDOWACTIVE = WM_USER + 3;
WM_MDIWINDOWTEXT = WM_USER + 4;
type
TMainForm = class(TForm)
MainMenu1: TMainMenu;
N1: TMenuItem;
N2: TMenuItem;
N3: TMenuItem;
N4: TMenuItem;
N5: TMenuItem;
N6: TMenuItem;
ToolBar1: TToolBar;
ToolButton1: TToolButton;
ToolButton2: TToolButton;
ToolButton3: TToolButton;
ToolButton4: TToolButton;
ToolButton5: TToolButton;
ToolButton6: TToolButton;
ToolButton7: TToolButton;
ToolButton8: TToolButton;
ToolButton9: TToolButton;
ToolButton10: TToolButton;
ToolButton11: TToolButton;
Panel1: TPanel;
TabMDIControl: TTabControl;
StatusBar1: TStatusBar;
ControlBar1: TControlBar;
ComboBoxEx1: TComboBoxEx;
SpeedButton1: TSpeedButton;
ToolBar2: TToolBar;
ImageList1: TImageList;
PopupMenu1: TPopupMenu;
PopupMenu2: TPopupMenu;
N7: TMenuItem;
mnuClearFavorites: TMenuItem;
N8: TMenuItem;
PopupMenu3: TPopupMenu;
N9: TMenuItem;
procedure SpeedButton1Click(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure mnuClearFavoritesClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure TabMDIControlChange(Sender: TObject);
procedure N9Click(Sender: TObject);
private
{ Private declarations }
procedure MenuItem_FaClick(Sender: TObject);
public
{ Public declarations }
procedure CreateChild(sUrl: string);
procedure MsgMdiCreate(var message: TMessage); message WM_MDIWINDOWCREATE;
procedure MsgMdiActive(var message: TMessage); message WM_MDIWINDOWACTIVE;
procedure MsgMdiDelete(var message: TMessage); message WM_MDIWINDOWDELETE;
procedure MsgMdiTEXT(var message: TMessage); message WM_MDIWINDOWTEXT;
end;
var
MainForm: TMainForm;
implementation
uses uChildWindows, uFavorites;
{$R *.dfm}
procedure TMainForm.CreateChild(sUrl: string);
var
Form: TFrmBrowser;
begin
lockWindowupdate(application.MainForm.Handle);
Form := TFrmBrowser.Create(self);
Form.OpenAddress(sUrl);
lockwindowupdate(0);
end;
procedure TMainForm.MsgMdiActive(var message: TMessage);
var
fChild: TFrmBrowser;
index: integer;
begin
fChild := TFrmBrowser(message.WParam);
index := TabMDIControl.Tabs.IndexOfObject(fChild);
if index >= 0 then TabMDIControl.TabIndex := index;
end;
procedure TMainForm.MsgMdiCreate(var message: TMessage);
var
fChild: TFrmBrowser;
begin
if TabMDIControl.Tabs.Count = 0 then TabMDIControl.Visible := true;
fChild := TFrmBrowser(message.WParam);
TabMDIControl.Tabs.AddObject(fChild.Caption, fChild);
end;
procedure TMainForm.MsgMdiDelete(var message: TMessage);
var
fChild: TFrmBrowser;
index: integer;
begin
fChild := TFrmBrowser(message.WParam);
index := TabMDIControl.Tabs.IndexOfObject(fChild);
if index >= 0 then TabMDIControl.Tabs.Delete(index);
end;
procedure TMainForm.SpeedButton1Click(Sender: TObject);
begin
CreateChild('http://www.sina.com.cn');
end;
procedure TMainForm.FormDestroy(Sender: TObject);
var
i: integer;
begin
for i := 0 to TabMDIControl.Tabs.Count - 1 do
begin
(TFrmBrowser(TabMDIControl.Tabs.Objects)).Free;
end;
end;
procedure TMainForm.mnuClearFavoritesClick(Sender: TObject);
begin
ClearUpFavorites(application.Handle); ;
end;
procedure TMainForm.FormCreate(Sender: TObject);
var
pidl: PItemIDList;
FavPath: array[0..MAX_PATH] of char;
begin
SHGetSpecialFolderLocation(Handle, CSIDL_FAVORITES, pidl);
SHGetPathFromIDList(pidl, favpath);
CreateFavoritesMenu(favpath, N4, MenuItem_FaClick);
end;
procedure TMainForm.MenuItem_FaClick(Sender: TObject);
var
sUrl: string;
begin
sUrl := (Sender as TMenuItem).hint;
CreateChild(sUrl);
end;
procedure TMainForm.TabMDIControlChange(Sender: TObject);
var
index: integer;
begin
index := TabMDIControl.TabIndex;
(TFrmBrowser(TabMDIControl.Tabs.Objects[index])).Show;
end;
procedure TMainForm.MsgMdiTEXT(var message: TMessage);
const
intmax = 120;
var
fChild: TFrmBrowser;
index: integer;
S1, s2: string;
Fit: integer;
sz:Size;
begin
fChild := TFrmBrowser(message.WParam);
index := TabMDIControl.Tabs.IndexOfObject(fChild);
s1 := fChild.Caption;
if (GetTextExtentExPoint(self.Canvas.Handle,Pchar(s1),length(s1),intmax,@Fit,(nil),sz)) then
begin
TabMDIControl.Tabs.Strings[index] :=copy(s1,0,Fit);
end;
end;
procedure TMainForm.N9Click(Sender: TObject);
var
index: integer;
begin
index := TabMDIControl.TabIndex;
(TFrmBrowser(TabMDIControl.Tabs.Objects[index])).Free;
TabMDiControl.Tabs.Delete(index);
if TabMDiControl.Tabs.Count <= 0 then
TabMdiControl.Visible := false;
end;
end.