Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / Visual J# / May 2004

Tip: Looking for answers? Try searching our database.

How to capture the screen in J#?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
tomato - 23 Apr 2004 00:31 GMT
I would like to do a screen capture from J#

Tried using Robot, but since that is 1.3, it is not supported
Any .NET classes that do this
If not, how would I access WINAPI from J#

Thank you.
Lars-Inge T?nnessen - 23 Apr 2004 15:24 GMT
Here is an example in C#. (It uses a huge amount of memory:)
http://www.codeproject.com/csharp/csCaptureScreen1.asp

Let us know if you can't convert it into J#.

Lars-Inge T?nnessen
www.larsinge.com
RAHUL YADAV - 23 Apr 2004 16:40 GMT
Hi,

.NET provides Platform Invocation Services, or PInvoke, that enables J# to
access WinAPI.

Thanks,
Rahul
VJ# Team



--------------------
>Thread-Topic: How to capture the screen in J#?
>thread-index: AcQoweA1jMfPKFHGQUaBpZMbiJbanA==
[quoted text clipped - 20 lines]
>
>I would like to do a screen capture from J#.

Tried using Robot, but since that is 1.3, it is not supported.
Any .NET classes that do this?
If not, how would I access WINAPI from J#?

Thank you.
George Birbilis [MVP J#] [9880] - 28 May 2004 09:08 GMT
the program below is a command-line utility authored in Delphi (Object
Pascal) to grab a screen part (or all of it) and put it on the clipboard.
You can easily convert it to C if you wish and add code to save to a Windows
Bitmap, then call the command-line utility from J# as you wish (using the
appropriate "System" or "Runtime" class static methods you can execute an
external application). At the Delphi code I don't use {$APPTYPE CONSOLE} at
the start of the code so that it doesn't show a black command-line window
when it's executed from Java or other environment

I have a similar Screen2Printer utility if anyone needs such (to print a
screen part or the whole from Java/J# etc.)
Beware that parts of a window that are out of the screen will be shown as
black (not sure why, something related to the clip region probably, maybe
should update
it first to include the part of the "virtual" desktop to be grabbed, then
grab it)

cheers,
George

//Screen2Clipboard - (C)2001 George Birbilis <birbilis@kagi.com>
//
//This program is FREEWARE!
//Feel free to modify and distribute as long as you give due credit and also
//distribute together with your modified source the original source
unmodified.
//Source parts are from ClipCopy utility used in the "Gaia" educational
software
//
//Version: 5Sep2001

program Screen2Clipboard;
uses Windows,SysUtils;

resourcestring msgSyntax='Syntax: Screen2Clipboard [x1 y1 x2 y2]';
resourcestring msgSyntaxError='Syntax error!';
resourcestring msgNotNumber='x1, y1, x2, y2 must all be numbers!';

function CopyScreenToBitmap(x1,y1, x2,y2:integer):HBITMAP;
var screenDC, memDC : HDC;
   bitmap, oldBitmap : HBITMAP;
   nWidth, nHeight : integer;
begin
//screenDC := CreateDC('DISPLAY'#0, nil, nil, nil); //the 'DISPLAY' string
must be null-terminated, that's why #0 is appended to it

screenDC := GetWindowDC(0);
memDC := CreateCompatibleDC(screenDC);

nWidth := x2-x1+1;
nHeight := y2-y1+1;

bitmap := CreateCompatibleBitmap(screenDC, nWidth, nHeight);
oldBitmap := HBITMAP(SelectObject(memDC, bitmap));

BitBlt(memDC, 0, 0, nWidth, nHeight, screenDC, x1, y1, SRCCOPY);

bitmap := HBITMAP(SelectObject(memDC, oldBitmap));

DeleteDC(screenDC);
DeleteDC(memDC);

result:=bitmap;
end;

function copyBitmapToClipboard(bitmap:HBITMAP):boolean;
begin
result:=OpenClipboard(0{hwndGaia});
if(result) then
 begin
 EmptyClipboard();
 SetClipboardData(CF_BITMAP, bitmap);
 CloseClipboard();
 end;
end;

var x1,y1, x2,y2:integer;
   screenDC:HDC;
begin

if paramCount=0 then
 begin
 screenDC:=GetWindowDC(0);
 x1:=0;
 y1:=0;
 x2:=GetDeviceCaps(screenDC,HORZRES)-1;
 y2:=GetDeviceCaps(screenDC,VERTRES)-1;
 end
else if paramCount=4 then
 try
  x1:=StrToInt(paramStr(1));
  y1:=StrToInt(paramStr(2));
  x2:=StrToInt(paramStr(3));
  y2:=StrToInt(paramStr(4));
 except
  on EConvertError do
   begin
   MessageBox(0,pchar(msgNotNumber),pchar(msgSyntaxError),MB_ICONERROR);
   halt(2);
   exit; //add this here to avoid warning about x1,y1,x2,y2 possibility of
not being initialized
   end;
 end
else
 begin
 MessageBox(0,pchar(msgSyntax),pchar(msgSyntaxError),MB_ICONERROR);
 halt(1);
 exit; //add this here to avoid warning about x1,y1,x2,y2 possibility of
not being initialized
 end;

if CopyBitmapToClipboard(CopyScreenToBitmap(x1,y1,x2,y2))
 then halt(0)
 else halt(3);

end.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
George Birbilis <birbilis@kagi.com>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ QuickTime VCL and ActiveX controls (for PowerPoint/VB/Delphi etc.)
+ Plugs VCL and ActiveX controls (InterProcess/Internet communication)
+ TransFormations, VB6 forms to ASP.net WebForms convertion
http://www.kagi.com/birbilis
+ Robotics
http://www.mech.upatras.gr/~robgroup
........................................................................

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.