Mega Code Archive

 
Categories / Delphi / Examples
 

Copyscreentoword

COPY SCREEN TO WORD Ralph, I found a solution from Delphi3000.com for your reference. Gordon procedure SimulateKeystroke(Key : byte; extra : DWORD); begin keybd_event(Key, extra, 0, 0); keybd_event(Key, extra, KEYEVENTF_KEYUP, 0); end; procedure TForm1.Button2Click(Sender: TObject); begin {Capture the entire screen to the clipboard} {by simulating pressing the PrintScreen key} SimulateKeystroke(VK_SNAPSHOT, 0); end; procedure TForm1.Button3Click(Sender: TObject); begin {Capture the active window to the clipboard} {by simulating pressing the PrintScreen key} SimulateKeystroke(VK_SNAPSHOT, 1); end; -----Original Message----- From: Ralph Friedman [mailto:ralphfriedman@email.com] Sent: Tuesday, December 26, 2000 6:26 PM To: delphi@elists.org Subject: Re: How to copy/past Active form to Word ? Gordon, yet cleaner: var formImage: TBitmap; begin formImage := GetFormImage; try Clipboard.Assign(formImage); finally formImage.Free; end; end; Regards Ralph _______________________________________________ Delphi mailing list -> Delphi@elists.org http://www.elists.org/mailman/listinfo/delphi _______________________________________________ Delphi mailing list -> Delphi@elists.org http://www.elists.org/mailman/listinfo/delphi ********************************************************************* > Thanks ! But I want it from a button/menuitem of the active form !!!! > The following will get you the client area (everything except the caption bar): procedure TForm1.Button1Click(Sender: TObject); var data: cardinal; format: Word; palette: HPALETTE; begin GetFormImage.SaveToClipboardFormat(format, data, palette); Clipboard.SetAsHandle(format, data); end; ******************************************************************************** Actually, Ctrl+Print Screen isn't defined by Windows (not mine, anyway). For the whole screen, it's just plain Print Screen. A number of graphics packages will set up functions for other Print Screen combinations. As for copying the form, I guess we're assuming a graphical image. The keyboard solution given would work, but I don't think it's appropriate for a programmatic method. Maybe it's just me, but I don't like solutions that rely on emulating user input through the *_event functions--for one thing, they imply certain keyboard shortcuts exist and certain window focus conditions. My method would use the wm_Print message. Something like this: Bmp := Graphics.TBitmap.Create; Bmp.Height := SourceForm.Height; Bmp.Width := SourceForm.Width; SendMessage(SourceForm.Handle, wm_Print, Bmp.Canvas.Handle, prf_Children or prf_Client or prf_NonClient); At this point, you should have a bitmap image of the form. To place it on the clipboard, use Clipboad.Assign(Bmp). I'm a little wary of using the clipboard to actually _transfer_ information between programs automatically. Unless the menu command is "Copy to clipoard and paste in Word," I'd use something else. For example, if the text is more like, "Send image to Word," then the clipboard should not be used at all. The clipboard is for the user's data, not the program's. Program information can be sent via automation. If the menu command really does make it clear that the clipboard will be used, then I would ask why you're limiting it to Word. Thousands of applications can take bitmap information from the clipboard, including WordPerfect, Wordpad, and StarOffice, so a command aimed only at Word isn't a great design. --Rob *****************************************************************************************