Note that this example was debugged in Delphi7.0
////////////////////////////////////////////////// ////////////////////////
(I) Establish a project
new Items-->PRojects-->MDI application
(2) Redesign the MDI subform - ChildWin to realize the captured image being displayed in ChildWin.
Remove the original Memo1 control in the ChildWin child form and add the Image control, Image1.Align=alClient.
Image1.AutoSize=ture means the original size is displayed, and Strech=false means that it is not displayed according to the object box.
(III) Main interface modification
1) Remove items related to paste and new in menu,toolbar,ActionList
2) Add PrinterSetupDialog1 and SaveDialog control to MainForm.
Add menu item file/print, the attribute name is filePrintItem;
Add menu item file/print settings, property enabled=false, name is filePrintSet;
Add menu item edit/Draw, its property enabled=false;
Add menu item edit/Preferences and set it to create Submenu;
Add menu items edit/Preferences/Configuration;
Add menu item edit/Preferences/ToolBar, its checked=true,name=toolbarItem;
Add menu Image;
Add menu item Image/Capture Desktop;
Add menu item Image/Capture Area;
Add menu items Image/Capture Windows or Controls;
Add menu item Image/Capture Icon
Add four toolbar buttons to the toolbar, corresponding to the four menu items under the Image menu.
Add four Actions to ActionList: cptDestop, cptArea, cptWindows, cptIcon;
The action attributes of the four menu items under the Image menu correspond to the above four Actions respectively;
The action attributes of the four newly added toolbar buttons correspond to the above four Actions respectively.
3) Move implementation uses CHILDWIN into interface uses in the Main unit.
Add ScrnCpt to the interface's uses;
Add definition in TMainForm's public:
Child: TMDIChild;
CaptureNum:integer;
FileName:String;
DefaultDirectory:string;
4) Add private function in TMainForm: procedure Delay(msecs:integer)
procedure TMainForm.Delay(msecs:integer); //Implement delay
var FirstTickCount:Longint;
Begin
FirstTickCount:=GetTickCount; //The time from windows to the current startup (Hao seconds)
repeat
Begin
Application.ProcessMessages; //Interrupt the program to enable Windows to respond to events that occur
end;
until ((GetTickCount-FirstTickCount)>=Longint(msecs));
end;
5) Modify the [TMainForm.CreateMDIChild] process:
Remove variable var Child: TMDIChild, add parameter newFile
procedure TMainForm.CreateMDIChild(const Name: string;newFile:boolean);
Begin
Child := TMDIChild.Create(Application); { create a new MDI child window }
Child.Caption := Name;
if (not newFile)and(Name<>'') then begin
Child.Image1.Picture.Bitmap.LoadFromFile(Name);
Child.HorzScrollBar.Range := Child.Image1.Picture.Width;
Child.VertScrollBar.Range := Child.Image1.Picture.Height;
end;
end;