Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Windows screenshot

322 views
Skip to first unread message

Michael Hagl

unread,
May 10, 2012, 6:04:45 AM5/10/12
to
Hi,

how can I do a Windows screenshot of the active windows whithin xharbour ?

Michael Hagl



Saulius

unread,
May 10, 2012, 9:47:01 AM5/10/12
to
Hi,

> how can I do a Windows screenshot of the active windows whithin xharbour ?

Is it console window?

Saulius


dlzc

unread,
May 10, 2012, 10:13:16 AM5/10/12
to
Dear Michael Hagl:

On Thursday, May 10, 2012 3:04:45 AM UTC-7, Michael Hagl wrote:
> Hi,
>
> how can I do a Windows screenshot of the active
> windows whithin xharbour ?

http://msdn.microsoft.com/en-us/library/dd183402%28v=vs.85%29.aspx
... does not look pleasant, don't know if we've implemented in WinAPI.

David A. Smith

dlzc

unread,
May 10, 2012, 5:39:32 PM5/10/12
to
Dear Michael Hagl:

On Thursday, May 10, 2012 3:04:45 AM UTC-7, Michael Hagl wrote:
> Hi,
>
> how can I do a Windows screenshot of the active
> windows whithin xharbour ?

May be able to bend one of these to your needs:
http://sourceforge.net/directory/os:windows/freshness:recently-updated/?q=screen%20shot%20c

Presumably you are not running console mode so savescreen / restscreen will not work for you...? Because you could write those screen-containing memory variables out to a file, or memo field.

David A. Smith

fatfat

unread,
May 11, 2012, 12:07:05 PM5/11/12
to
minigui got one of the routine that do windows screend capture : - )

"Michael Hagl" 在郵件張貼內容主旨 jog3ts$33t$1...@news.albasani.net 中撰寫...

Michael Hagl

unread,
May 14, 2012, 2:32:57 AM5/14/12
to
Sorry for delay,

yes it is console window.

Michael


"Saulius" <lab...@gmail.com> schrieb im Newsbeitrag
news:joggsq$pk9$1...@speranza.aioe.org...

Michael Hagl

unread,
May 14, 2012, 2:34:40 AM5/14/12
to
Hi,

I`m using xHarbour.com version. I think I can not use minigui.

Michael


"fatfat" <fat...@fatfat.com> schrieb im Newsbeitrag
news:jojdfg$a8u$1...@dont-email.me...

cul...@gmail.com

unread,
May 14, 2012, 8:32:27 AM5/14/12
to
On 14 maio, 03:34, "Michael Hagl" <hag...@hagl.de> wrote:
> Hi,
>
> I`m using xHarbour.com version. I think I can not use minigui.
>
> Michael
>
> "fatfat" <fat...@fatfat.com> schrieb im Newsbeitragnews:jojdfg$a8u$1...@dont-email.me...
>
>
Hi

What you need from the screen shoot?

Regards
Luiz


>
>
>
>
> > minigui got one of the routine that do windows screend capture : - )
>
> > "Michael Hagl"  ¦b¶l¥ó±i¶K¤º®e¥D¦® jog3ts$33...@news.albasani.net ¤¤¼¶¼g...

x...@y.local

unread,
May 14, 2012, 1:00:25 PM5/14/12
to
Hi,

In article <joq90p$bqi$1...@news.albasani.net>, hag...@hagl.de says...
[...]
> > Hi,
> >
> >> how can I do a Windows screenshot of the active windows whithin xharbour
> >> ?
[...]

For an example you can se at

http://groups.google.com/group/comp.lang.xharbour/browse_frm/thread/1864
b0ceb9ace059/2e85dbec43c8805e?tvc=1&q=Copy+screen#2e85dbec43c8805e
--> articel number 4

Dusan

Saulius

unread,
May 14, 2012, 1:06:43 PM5/14/12
to
Try this code:

proc main()
Win2Bmp(,, 'SCR_S.bmp') // Full Screen
Win2Bmp(, .t., 'SCR_W.bmp') // Full window w/ border, title, ...
Win2Bmp(, .f., 'SCR_C.bmp') // Windows' client area
return

#pragma BEGINDUMP
#include <windows.h>
#include "hbapi.h"

/*
* Win2Bmp( [nWnd], [lFullWindow] [,cBmFile] ) --> nBitMap
*
* hWnd : window handle - if NIL then GetForegroundWindow()
* lFullWindow : .T. = Window, .F. = Client, Nil = Screen
* cBmFile : FileName for .bmp file
*/
HB_FUNC( WIN2BMP )
{
HWND hWnd = ISNUM( 1 ) ? (HWND) hb_parnl( 1 ) :
ISPOINTER( 1 ) ? (HWND) hb_parptr( 1 ) : GetForegroundWindow();
UINT iWhat = ISLOG( 2 ) ? ( hb_parl( 2 ) ? 1 : 2 ) : 0;
const char *pszBmF = ISCHAR( 3 ) && hb_parclen( 3 ) ? hb_parc( 3 ) : NULL;
HDC hdcWin, hdcMem;
HBITMAP hbmWin;
RECT rc;

if( iWhat == 1 )
{
hdcWin = GetWindowDC( hWnd );
GetWindowRect( hWnd, &rc );
}
else if( iWhat == 2 )
{
hdcWin = GetDC( hWnd );
GetClientRect( hWnd, &rc );
}
else
{
hdcWin = GetDC( NULL );
rc.left = rc.top = 0;
rc.right = GetSystemMetrics( SM_CXSCREEN );
rc.bottom = GetSystemMetrics( SM_CYSCREEN );
}

hdcMem = CreateCompatibleDC( hdcWin );
hbmWin = CreateCompatibleBitmap( hdcWin, rc.right - rc.left, rc.bottom - rc.top );
SelectObject( hdcMem, hbmWin );
BitBlt( hdcMem, 0, 0, rc.right - rc.left, rc.bottom - rc.top, hdcWin, 0, 0, SRCCOPY );

if( pszBmF ) // Save bmp to .bmp file ?
{
BITMAP bmWin;
BITMAPFILEHEADER bmfHdr;
BITMAPINFOHEADER bmiHdr;
LPBITMAPINFOHEADER lpbmi;
DWORD dwBmSize, dwByWritten = 0;
HANDLE hBmF;

// Get the BITMAP from the HBITMAP
GetObject( hbmWin, sizeof( BITMAP ), &bmWin );

// Fill in BITMAPINFOHEADER structure
memset( (void *) &bmiHdr, 0, sizeof( BITMAPINFOHEADER ) );
bmiHdr.biSize = sizeof( BITMAPINFOHEADER );
bmiHdr.biWidth = bmWin.bmWidth;
bmiHdr.biHeight = bmWin.bmHeight;
bmiHdr.biPlanes = 1; // Should always be 1
bmiHdr.biBitCount = 32; // color resolution (in bits per pixel)
bmiHdr.biCompression = BI_RGB;
//bmiHdr.biSizeImage =
//bmiHdr.biXPelsPerMeter =
//bmiHdr.biYPelsPerMeter =
//bmiHdr.biClrUsed =
//bmiHdr.biClrImportant = 0;

dwBmSize = ( ( bmiHdr.biWidth * bmiHdr.biBitCount + 31 ) / 32 ) * 4 * bmiHdr.biHeight;

lpbmi = (LPBITMAPINFOHEADER) hb_xgrab( sizeof( BITMAPINFOHEADER ) + dwBmSize );
*lpbmi = bmiHdr;

GetDIBits( hdcWin, hbmWin, 0, (UINT) bmWin.bmHeight, lpbmi, (BITMAPINFO *) lpbmi, DIB_RGB_COLORS );

// Fill in BITMAPFILEHEADER structure
memset( (void *) &bmfHdr, 0, sizeof( BITMAPFILEHEADER ) );
bmfHdr.bfType = 0x4D42; //= "BM"
bmfHdr.bfSize = sizeof( BITMAPFILEHEADER ) + sizeof( BITMAPINFOHEADER ) + dwBmSize;
bmfHdr.bfOffBits = (DWORD) sizeof( BITMAPFILEHEADER ) + (DWORD) sizeof( BITMAPINFOHEADER );

// Create and Write .bmp file and Close it
hBmF = CreateFile( pszBmF, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL );
WriteFile( hBmF, (LPSTR) &bmfHdr, sizeof( BITMAPFILEHEADER ), &dwByWritten, NULL );
WriteFile( hBmF, (LPSTR) &bmiHdr, sizeof( BITMAPINFOHEADER ), &dwByWritten, NULL );
WriteFile( hBmF, (LPSTR) lpbmi, dwBmSize, &dwByWritten, NULL );
CloseHandle( hBmF );

hb_xfree( lpbmi );
}
DeleteDC( hdcMem );
ReleaseDC( hWnd, hdcWin );

hb_retnl( (LONG) hbmWin );
}
#pragma ENDDUMP

Best regards,
Saulius


Michael Hagl

unread,
May 18, 2012, 7:03:40 AM5/18/12
to
Hi Saulius,

this code works great with my xharbour. Now I have a really good
PrintScreen() function.

Thank you very much !!

Michael



"Saulius" <lab...@gmail.com> schrieb im Newsbeitrag
news:jore30$aen$1...@speranza.aioe.org...

Michael Hagl

unread,
May 18, 2012, 7:06:14 AM5/18/12
to
Hi Dusan

this code don't compile.

I think it is almost the same code as from Saulius. But the the line:

CHAR * pszBmF = ISCHAR( 3 ) && hb_parclen( 3 ) ? hb_parc( 3 ) : NULL;

is replaced with

const CHAR * pszBmF = ISCHAR( 3 ) && hb_parclen( 3 ) ? hb_parc( 3 ) : NULL;

Thank you

Michael



<x...@y.local> schrieb im Newsbeitrag
news:MPG.2a1b5897...@news.siol.net...

Michael Hagl

unread,
May 18, 2012, 7:07:09 AM5/18/12
to
Hi Luiz,

the code from Saulius workes very great !

Michael


<cul...@gmail.com> schrieb im Newsbeitrag
news:807834a0-d5e9-4a37...@v24g2000vbx.googlegroups.com...
On 14 maio, 03:34, "Michael Hagl" <hag...@hagl.de> wrote:
> Hi,
>
> I`m using xHarbour.com version. I think I can not use minigui.
>
> Michael
>
> "fatfat" <fat...@fatfat.com> schrieb im
> Newsbeitragnews:jojdfg$a8u$1...@dont-email.me...
>
>
Hi

What you need from the screen shoot?

Regards
Luiz


>
>
>
>
> > minigui got one of the routine that do windows screend capture : - )
>
> > "Michael Hagl" �b�l��i�K���e�D�� jog3ts$33...@news.albasani.net

FabioNery

unread,
May 18, 2012, 8:46:22 AM5/18/12
to
Hi, Saulius.

Thank You Very Much!

FabioNery

"Saulius" <lab...@gmail.com> escreveu na mensagem
news:jore30$aen$1...@speranza.aioe.org...

x...@y.local

unread,
May 19, 2012, 11:32:21 PM5/19/12
to
Hi Michael,

In article <jp5ah9$ccv$1...@news.albasani.net>, hag...@hagl.de says...
[...]
> I think it is almost the same code as from Saulius. But the the line:
[...]
Te code from Saulius IS my 'reworked' code ... ;)

Dusan

cher...@gmail.com

unread,
May 24, 2012, 4:44:05 PM5/24/12
to
Saulius
It works great.
One step further, how can the BMP be converted to JPG or any other more compressed format ?
Thanks
Claudio H

dlzc

unread,
May 24, 2012, 10:16:50 PM5/24/12
to
Dear Claudio:

On Thursday, May 24, 2012 1:44:05 PM UTC-7, cher...@gmail.com wrote:
> Saulius
> It works great.
> One step further, how can the BMP be converted
> to JPG or any other more compressed format ?

You could open it with Paint, and save it out as a JPEG.

David A. Smith

Saulius

unread,
May 25, 2012, 5:12:40 AM5/25/12
to
Hi,

>
> You could open it with Paint, and save it out as a JPEG.
>
> David A. Smith

I propose to use ImageMagick open source from command line:
convert file1.bmp file2.jpg
There are over 100 image formats and many more, plus coding possibility

Best regards,
Saulius


CV

unread,
Feb 17, 2022, 9:04:02 AM2/17/22
to
Hi! sorry for jumping over an old message.

This routine works perfectly BUT has a drawback: generates memory leaks.
If used repeatedly over a day (calling it every 5'), then the computer lost about 1.5 gb of ram. Closing the application and starting again solves the problem.

My solution to avoid this involves modifying a couple of lines, as seen below.

From:
...
CloseHandle( hBmF );
hb_xfree( lpbmi );
}
DeleteDC( hdcMem );
ReleaseDC( hWnd, hdcWin );

hb_retnl( (LONG) hbmWin );
}
#pragma ENDDUMP

To:
...
CloseHandle( hBmF );
hb_xfree( lpbmi );
}
hb_retnl( (LONG) hbmWin ); // RELOCATED

DeleteObject(hbmWin); // ADDED
DeleteObject( hdcMem ); // MODIFIED
ReleaseDC( hWnd, hdcWin );
}
#pragma ENDDUMP

It solved the problem I was facing.

Best regards!
---
Claudio Voskian
Buenos Aires - Argentina

Michael Hagl

unread,
Feb 24, 2022, 2:19:53 PM2/24/22
to
Thank you Claudio!
Michael Hagl
0 new messages