Page 1 of 1

Screenshot email

Posted: Tue Apr 06, 2021 12:15 pm
by Otto
Hello,
I try to take a screenshot of an email msg file.
The problem is that the part with the email - body is missing in the screenshot.
Maybe someone has a solution.
Best regards,
Otto

Image

Code: Select all | Expand


function MSGToJpeg( cMSG )
   local cTitle   := ""
   local hWnd, hBmp, hBmp2, hDib, cBuf, nWait := 2
   local lRet := .f.
   local nWidth := GetSysMetrics( 0 )
   local nHeight := GetSysMetrics( 1 )
   local aClass := {}

   cTitle := msgGetTitle( cMSG )

   if nWidth > 1920
      nWidth :=  1920
   endif

   if File( cMSG )
      ShellExecute( 0, 'Open', cMSG )
      SysWait( 3 )

      do while nWait < 5 .and. Empty( hWnd :=  FindWnd( cTitle ) )
         SysWait( nWait )
         nWait    += 1
      enddo


      if ! Empty( hWnd )
         SetFocus( hWnd )
         SetForeGroundWindow( hWnd )
         SysRefresh()
         SysWait( 0.8 )
            // for a test
         EnumChildWindows( hWnd,;
            { | hWnd, nLParam | AADD( aClass,{ GetClassName( hWnd ), hWnd } ), .T. },; // .T. means continue
            0 )                                 // optional supplied value

         xbrowse( aClass )
            // for a test end

         hBmp  := WndBitmap( hWnd )

         SendMessage( hWnd, WM_CLOSE )
         hBmp2 := BmpTrim( hBmp )

         DeleteObject( hBmp )

         //    hBmp2 := CropImage( hBmp2, 150, 420, nHeight,nWidth-420 )
         hDib              := DibFromBitmap( hBmp2 )
         cBuf              := DibToStr( hDib )
         GlobalFree( hDib )

         DeleteObject( hBmp2 )

         lRet  := BmpBufToJpg( cFileSetExt( cMSG, "jpg" ), cBuf )
         cBuf  := nil


      endif
   endif

return lRet

//----------------------------------------------------------------------------//

function msgGetTitle( cFile )
 
   LOCAL oOutlook       := TOleAuto():New( "Outlook.Application" )
   local myOlExp        := oOutlook:ActiveExplorer
   local oMail

        oMail := oOutlook:CreateItemFromTemplate( Alltrim(  cFile ) )

return ( oMail:Subject )

//----------------------------------------------------------------------------//

 

Re: Screenshot email

Posted: Tue Apr 06, 2021 3:43 pm
by Otto
Hello,
I have found a workaround for me.
I installed a printer driver, which can print into a jpg-file.
Now I open msg file and then print it to the printer driver.
Best regards,
Otto

Re: Screenshot email

Posted: Tue Apr 13, 2021 4:53 am
by hua
Hi Otto,
Can I ask what does BmpTrim() and BmpBufToJpg() do and can you share their source?

TIA

Re: Screenshot email

Posted: Tue Apr 13, 2021 7:29 am
by Marc Venken
Otto,

I use Greenshot for this kind of things. I'ts free and, small and very usefull (copy,print,save,....) select part of windows...

Re: Screenshot email

Posted: Tue Apr 13, 2021 7:33 am
by Otto
Hello Hua,

These functions Mr. Rao showed in a session when we had the FIVEWIN meeting in Sillian.
Image

https://mybergland.com/fwforum/meeting.mp4


BmpTrim( hBmp ) is function to crop black borders of a bitmap, if any.

Code: Select all | Expand

static function BmpTrim( hBmp )  // Trim black sides on left and right

   local hOldBmp, hDC, hDCMem, hBmpTrim
   local nLeft := 0, nRight := 0
   local nHeight, nWidth, ny
   *----------------------------------------------------------

   nWidth   := nBmpWidth(  hBmp )
   nHeight  := nBmpHeight( hBmp )

   hDC      := GetDC( GetDeskTopWindow() )
   hDCMem   := CreateCompatibleDC( hDC )
   hOldBmp  := SelectObject( hDCMem, hBmp )

   ny       := Int( nHeight / 2 )
   do while nLeft < .4 * nWidth .and. GetPixel( hDCMem, nLeft, ny ) == 0
      nLeft++
   enddo
   nRight   := nWidth - 1
   do while nRight > .6 * nWidth .and. GetPixel( hDCMem, nRight, ny ) == 0
      nRight--
   enddo
   SelectObject( hDCMem, hOldBmp )
   DeleteDC( hDCMem )
   ReleaseDC( GetDesktopWindow(), hdc )

   hBmpTrim    := CropImage( hBmp, 0, nLeft, nHeight, nRight )

return hBmpTrim

//----------------------------------------------------------------------------//


BmpBufToJpg( cFileJpg, cBuf ) is also my very old function to save hBitmap as Jpg file, using Freeimage.dll.

Code: Select all | Expand


static function BmpBufToJpg( cJpeg, cBuf )

   local hMem, nFormat, hDib, hDib2, lRet := .f.
   local nQuality    := 0  // Default

   if LoadFreeImage() <= 32
      MsgAlert( "freeimage.dll not found" )
      return .f.
   endif

   hMem        := FI_OpenMemory( cBuf, Len( cBuf ) )
   nFormat     := FI_GetFileTypeFromMemory( hMem, 0 )
   hDib        := FI_LoadFromMemory( nFormat, hMem, 0 )
   cBuf        := nil  // to release memory
   FI_CloseMemory( hMem )
   hDib2       := FICnv24( hDib )
   FIUnload( hDib )
   lRet        := FISave( 2, hDib2, cJpeg, nQuality )
   FIUnload( hDib2 )



return lRet

//----------------------------------------------------------------------------//




This was before FWH implemented more advanced image functions, without the need for freeimage.dll.


It is now better to use the latest function:
FW_SaveImage( hBitmap, JpgFile, nJpgQuality )


Best regards,
Otto

Re: Screenshot email

Posted: Tue Apr 13, 2021 7:40 am
by Otto
Hello Mark,

Can you use Greenshot from command com?
If yes, would you be so kind as to show some code?

Best regards,
Otto

Re: Screenshot email

Posted: Tue Apr 13, 2021 7:50 am
by Marc Venken
Otto wrote:Hello Mark,

Can you use Greenshot from command com?
If yes, would you be so kind as to show some code?

Best regards,
Otto


I never used it, but it seems to be possible :

FAQ's :
Are there any command line options available for Greenshot?
Yes, a few are implemented. Find the actual list by running the executable on the command line with the parameter /help, e.g.: "C:\Program Files\Greenshot\Greenshot.exe" /help.

Re: Screenshot email

Posted: Tue Apr 13, 2021 7:54 am
by Marc Venken
Marc Venken wrote:
Otto wrote:Hello Mark,

Can you use Greenshot from command com?
If yes, would you be so kind as to show some code?

Best regards,
Otto


I never used it from command line, but it seems to be possible :

FAQ's :
Are there any command line options available for Greenshot?
Yes, a few are implemented. Find the actual list by running the executable on the command line with the parameter /help, e.g.: "C:\Program Files\Greenshot\Greenshot.exe" /help.

Re: Screenshot email

Posted: Tue Apr 13, 2021 9:02 am
by hua
Thank you very much for your time and reply Otto.

I did found a command line utility https://www.nirsoft.net/utils/nircmd.html during my research that supports screenshot but didn't experiment with it yet

Re: Screenshot email

Posted: Wed Apr 14, 2021 6:54 am
by nageswaragunupudi
hua wrote:Thank you very much for your time and reply Otto.

I did found a command line utility https://www.nirsoft.net/utils/nircmd.html during my research that supports screenshot but didn't experiment with it yet


Why do we have to look elsewhere when Wiindows 10 comes with a built-in snipping tool? The best of its kind.

What Mr. Otto is trying to do is to automate the entire process from inside a FWH application without using a 3rd party tool.

Re: Screenshot email

Posted: Thu Apr 15, 2021 3:47 pm
by Otto
Hello friends,
Yes I need jpg creation in my program to automate the process.

My program "EmailDeskTop" uses FIVEWIN and mod harbour.

As you see, a new preview is recreated after inserting some data into an email item.

Best regards,
Otto

Image