Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

An elephant is a mouse with an operating system.


devel / comp.lang.xharbour / Re: Windows screenshot

SubjectAuthor
* Windows screenshotCV
`- Windows screenshotMichael Hagl

1
Re: Windows screenshot

<bd9bd608-b14f-4929-b074-90d09a5ca837n@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=10490&group=comp.lang.xharbour#10490

  copy link   Newsgroups: comp.lang.xharbour
X-Received: by 2002:a5d:6d8d:0:b0:1e3:3de4:e0e6 with SMTP id l13-20020a5d6d8d000000b001e33de4e0e6mr2449072wrs.159.1645106640874;
Thu, 17 Feb 2022 06:04:00 -0800 (PST)
X-Received: by 2002:a0c:e784:0:b0:424:5143:999d with SMTP id
x4-20020a0ce784000000b004245143999dmr2169473qvn.83.1645106640284; Thu, 17 Feb
2022 06:04:00 -0800 (PST)
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!proxad.net!feeder1-2.proxad.net!209.85.128.88.MISMATCH!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.xharbour
Date: Thu, 17 Feb 2022 06:04:00 -0800 (PST)
In-Reply-To: <jore30$aen$1@speranza.aioe.org>
Injection-Info: google-groups.googlegroups.com; posting-host=152.170.233.99; posting-account=PzJOtwoAAAB-nLPGTsEPjzvj-I7nsyBK
NNTP-Posting-Host: 152.170.233.99
References: <jog3ts$33t$1@news.albasani.net> <joggsq$pk9$1@speranza.aioe.org>
<joq90p$bqi$1@news.albasani.net> <jore30$aen$1@speranza.aioe.org>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <bd9bd608-b14f-4929-b074-90d09a5ca837n@googlegroups.com>
Subject: Re: Windows screenshot
From: cvosk...@gmail.com (CV)
Injection-Date: Thu, 17 Feb 2022 14:04:00 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
 by: CV - Thu, 17 Feb 2022 14:04 UTC

El lunes, 14 de mayo de 2012 a la(s) 14:06:43 UTC-3, Saulius escribió:
> 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

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

Re: Windows screenshot

<adad64c1-3a9a-42a5-9100-1f0720ff4c1fn@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=10496&group=comp.lang.xharbour#10496

  copy link   Newsgroups: comp.lang.xharbour
X-Received: by 2002:a5d:6d8e:0:b0:1ea:7987:d2c with SMTP id l14-20020a5d6d8e000000b001ea79870d2cmr3500702wrs.279.1645730392450;
Thu, 24 Feb 2022 11:19:52 -0800 (PST)
X-Received: by 2002:ac8:7fcc:0:b0:2de:6f5:3f5c with SMTP id
b12-20020ac87fcc000000b002de06f53f5cmr3823922qtk.214.1645730392069; Thu, 24
Feb 2022 11:19:52 -0800 (PST)
Path: i2pn2.org!i2pn.org!aioe.org!pasdenom.info!usenet-fr.net!fdn.fr!proxad.net!feeder1-2.proxad.net!209.85.128.87.MISMATCH!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.xharbour
Date: Thu, 24 Feb 2022 11:19:51 -0800 (PST)
In-Reply-To: <bd9bd608-b14f-4929-b074-90d09a5ca837n@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=80.151.237.2; posting-account=V7lAIgoAAAC3DUcIU4p9S6DraPJfG7Az
NNTP-Posting-Host: 80.151.237.2
References: <jog3ts$33t$1@news.albasani.net> <joggsq$pk9$1@speranza.aioe.org>
<joq90p$bqi$1@news.albasani.net> <jore30$aen$1@speranza.aioe.org> <bd9bd608-b14f-4929-b074-90d09a5ca837n@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <adad64c1-3a9a-42a5-9100-1f0720ff4c1fn@googlegroups.com>
Subject: Re: Windows screenshot
From: inf...@hagl.de (Michael Hagl)
Injection-Date: Thu, 24 Feb 2022 19:19:52 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
 by: Michael Hagl - Thu, 24 Feb 2022 19:19 UTC

CV schrieb am Donnerstag, 17. Februar 2022 um 15:04:02 UTC+1:
> El lunes, 14 de mayo de 2012 a la(s) 14:06:43 UTC-3, Saulius escribió:
> > 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
> 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
Thank you Claudio!
Michael Hagl

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor