Preview of a file

Re: Preview of a file

Postby Silvio.Falconi » Thu Jul 16, 2015 7:44 pm

Manuel,
it is possibile insert this preview into a Image control ?
I explain do you remmeber the first app I made this week ( bmpfromico) ?
I wish when the user select a file it can see the preview
or converte it into an image to show on image control


GenHPreview( cFile, oDlg )

do you tried odlg as oImage control ?
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
User avatar
Silvio.Falconi
 
Posts: 7053
Joined: Thu Oct 18, 2012 7:17 pm

Re: Preview of a file

Postby mastintin » Thu Jul 16, 2015 7:54 pm

would have to look
and insert 2 controls in the panel ?
timage y Opreview , and you change hide / show depending on which charge ?
User avatar
mastintin
 
Posts: 1516
Joined: Thu May 27, 2010 2:06 pm

Re: Preview of a file

Postby Silvio.Falconi » Thu Jul 16, 2015 10:05 pm

yes I draw how I wish create it

Image

the pdf is dropped into listview control and show on Image control ( it is into a tpanel control)
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
User avatar
Silvio.Falconi
 
Posts: 7053
Joined: Thu Oct 18, 2012 7:17 pm

Re: Preview of a file

Postby mastintin » Fri Jul 17, 2015 7:53 am

Silvio, This is a example developed as an idea, now need you as you develop more ...
Code: Select all  Expand view



// Our first DialogBox sample

#include "FiveWin.ch"
#include "constant.ch"
#include "FiveWin.ch"

#define  HKEY_CLASSES_ROOT       2147483648        // 0x80000000

Function Main ()
local ownd
local oimage
local oPreview


 DEFINE WINDOW oWnd TITLE "Testing hicon to bmp " FROM 5,5 TO 400, 600 PIXEL
 
    @ 20,2 button "crear" size 40,20 pixel Action GetFiletoview( oImage )  //imagenfromico( oimage )
    @ 20 ,130 Button "salir" Action ownd:end() size 40,20 pixel
     
   @ 13, 200 IMAGE oimage FILE "" size 256,256 of oWnd pixel
     
   
   ACTIVATE WINDOW oWnd

Return (nil)

Function GetFiletoview( oImage )
local oPreview
local cFile:= cGetfile("coge","*.*")
local cExt:= cFileExt( cfile)
   
    if cExt == "pdf"
       oImage:Hide()
       oPreview := TPreviewControl():New(13,200,oImage:oWnd, 255,255)
      // oPreview:AcceptDropFile()
       oImage:oWnd():refresh()
       oPreview:SetFile( cfile )
     
    else
       if !Empty(oPreview)
         oPreview:hide()
         oPreview:clear()  
         oPreview:destroy()
         oPreview:end()
         oPreview:= nil
       endif
       oImage:show()
        oImage:oWnd():refresh()
      imagenfromico( oImage, cfile )
    endif

Return nil


Function imagenfromico( oImage, cfile )
//local cFile:= cGetfile("coge","*.*")
local ico
    ico := ICON_EXEREAD( cFile, 4  )
      //  msginfo(ico)
        gdiBmpFromHIcon( ico, oImage , oImage:Super:nWidth(), oImage:Super:nHeight() )
        DestroyIcon( ico )
Return nil

 Function GDIBmpFromHIcon( hIcon , oImage , nWidth, nHeight )
//local hBmp := BmpFromIcon( hIcon )
local oGBmp := GdiBmp():new()
      oGBmp:hBmp:=  GDIPLUSIMAGEFROMICO( hIcon )
      DeleteObject( oImage:hBitmap )
      oGbmp:Resize( nWidth, nHeight )
     //  DeleteObject( hBmp )
      oImage:hBitmap:= oGBmp:GetGDIHbitmap()
      oImage:HasAlpha()
      oImage:Refresh()  
      oGBmp:end()
Return nil


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

CLASS TPreviewControl FROM TControl
   CLASSDATA lRegistered AS LOGICAL
   DATA pPreview INIT 0
   DATA pStream INIT 0
   DATA cID
   DATA cFile

   METHOD New( nRow, nCol, oWnd, nWidth, nHeight ) CONSTRUCTOR
   METHOD Destroy()
   METHOD SetFile(cFile)
   METHOD AcceptDropFile()
   METHOD Clear()
   METHOD UnloadPreview INLINE UnloadPreviewC ( ::pPreview )
   METHOD SeekCLSString( cFile )
   METHOD CreatehPreview() INLINE  ( ::pPreview := CreatehPreviewC( ::cID ) )
   METHOD AddPreview()     INLINE  AddPreviewC( ::cFile , ::pPreview  )  
   METHOD Show()
   METHOD DropFiles( hDrop )
   METHOD Resize()
   METHOD Prev_DoPreview() INLINE PrevDoPreview( ::pPreview )
   METHOD Prev_SetWindow() INLINE PrevSetWindow( ::hWnd, GetClientRect( ::hWnd ), ::pPreview  )
   
   METHOD Display() INLINE ::BeginPaint(), ::Paint(), ::EndPaint(), 0
   
ENDCLASS

METHOD New( nRow, nCol, oWnd, nWidth, nHeight ) CLASS TPreviewControl
   DEFAULT nRow := 10, nCol := 10, oWnd := GetWndDefault(), nWidth := 64, nHeight := 64
    CoInitialize()
   ::oWnd     := oWnd
   ::nId      := ::GetNewId()
   ::nStyle   := nOR( WS_CHILD, WS_VISIBLE, WS_TABSTOP, WS_CLIPCHILDREN )
   ::nTop     := nRow
   ::nLeft    := nCol
   ::nBottom  := ::nTop + nHeight - 1
   ::nRight   := ::nLeft + nWidth  
   
   ::Register( nOR( CS_VREDRAW, CS_HREDRAW ) )
   ::Create()
   oWnd:AddControl( Self )  
   
return Self

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

METHOD Destroy() CLASS TPreviewControl
   ::Clear()
return ::Super:Destroy()  

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

METHOD Show() CLASS TPreviewControl

   ::AddPreview()
   ::Prev_SetWindow()
   ::Prev_DoPreview()
     
     
Return nil

//-------------------------------------------------------
 
METHOD Clear() CLASS TPreviewControl
   if valtype(::pPreview) == "O"
       ::UnloadPreview()  
   endif
   if Valtype(::pStream) == "P"
     // DestroyStream(::pStream)
   endif
   ::pPreview := 0
   ::pStream := 0
return nil
*/

METHOD SetFile( cFile ) CLASS TPreviewControl

   ::Clear()
   ::cFile := cFile
   ::SeekCLSString( cFile )
   ::CreatehPreview()
   ::show()
     
return self

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

METHOD SeekCLSString( cFile ) CLASS TPreviewControl
local cExtension
local cKey := ""
local oReg
local cShellExe := "\ShellEx\{8895b1c6-b41f-4c1c-a562-0d564250836f}"
local cValue

if !Empty( cFile )
    cExtension := cFileExt( cFile )  
    if Empty( cExtension )
       MsgInfo( "not Extension File" )
       Return nil
    endif
    cExtension := "."+ cExtension
    cKey := cExtension + cShellExe
   //  msginfo(cKey)
    oReg := TReg32():New( HKEY_CLASSES_ROOT, ckey )
    cValue := oReg:Get()
       
    if Empty( cValue )
       oreg:Close()
     //   msginfo(cKey)
       oReg := TReg32():New( HKEY_CLASSES_ROOT, cExtension )
       cValue := oReg:Get()
       if Empty( cValue )
          oReg:Close()
          MsgInfo( "Clave no encontrada" )
          Return nil
       endif
       cKey := cValue + cShellExe
    //   msginfo(cKey)
       oReg := TReg32():New( HKEY_CLASSES_ROOT, cKey )
       cValue := oReg:Get()  
       if Empty( cValue )
          MsgInfo( "Clave no encontrada" )
          Return nil
       endIf      
    endif
endif

::cID := cValue

Return nil


METHOD Resize()
    SETRECTPREVIEWC(  ::pPreview , GetClientRect( ::hWnd ) )
    ::refresh()
return self

METHOD AcceptDropFile() CLASS TPreviewControl
   DragAcceptFiles( ::hWnd, .T. )
return Self

METHOD DropFiles( hDrop ) CLASS TPreviewControl
   LOCAL files
   files = DragQueryFiles( hDrop )
   ::SetFile( files[1])
return Self


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

#pragma BEGINDUMP

#define CINTERFACE
#define COBJMACROS

#if ( __BORLANDC__ <= 0x582 )
    #include <Shextra.h>
#endif
   
#include <windows.h>
#include <hbapi.h>
#include <CommCtrl.h>
#include <ShObjIdl.h>
//#include <Shlwapi.h>
//#include <ShlGuid.h>


LPWSTR UTF8toUTF16( LPCSTR utf8 );
LPWSTR AnsiToWide( LPSTR cAnsi );

const IID IID_IPreviewHandler = {0x8895b1c6, 0xb41f, 0x4c1c, {0xa5, 0x62,
0x0d, 0x56, 0x42, 0x50, 0x83, 0x6f}};

EXTERN_C const IID IID_IInitializeWithFile = {0xb7d14566, 0x0509, 0x4cce, {0xa7,
0x1f, 0x0a, 0x55, 0x42, 0x33, 0xbd, 0x9b}};
 
EXTERN_C const IID  IID_IInitializeWithStream =
    { 0xB824B49D, 0x22AC, 0x4161, { 0xAC, 0x8A, 0x99, 0x16, 0xE8, 0xFA, 0x3F, 0x7F } };  

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

HB_FUNC( CREATEHPREVIEWC )  // clsStr
{
 CLSID cls;
 IPreviewHandler* pRet=0;
 
 CLSIDFromString( AnsiToWide(( char * ) hb_parc( 1 )),&cls);
 
 if( CoCreateInstance( &cls, 0,  CLSCTX_INPROC_SERVER |CLSCTX_LOCAL_SERVER, &IID_IPreviewHandler, ( void ** ) &pRet ) ==S_OK )
   {
    hb_retptr(pRet);
    return ;
   }
   
 //  MessageBoxW(0,cKey,cExtension,MB_OK);
   hb_retptr( 0 );
   return ;
  }


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

HB_FUNC( ADDPREVIEWC ) // cFileName,pPreview
{
   IPreviewHandler* pPreview = ( IPreviewHandler* )hb_parptr(2);
 
   LPWSTR cFileName = AnsiToWide(( char * ) hb_parc( 1 ));
   LPCWSTR cExtension = wcsrchr(cFileName,L'.');
   IInitializeWithFile* pFile;
   IInitializeWithStream* pIStream;
   
   if(pPreview==0)
   {
      MessageBoxW(0,L"no pPreview",cExtension,MB_OK);
      hb_retptr( pPreview );
      return;
   }

   IPreviewHandler_QueryInterface(pPreview, &IID_IInitializeWithFile,(void**)&pFile );
   IPreviewHandler_QueryInterface(pPreview, &IID_IInitializeWithStream,(void**)&pIStream );
   
   if(pFile==0 && pIStream==0)
   {
      MessageBoxW(0,L"no pfile no pStream",cExtension,MB_OK);
      IPreviewHandler_Unload(pPreview);
      pPreview = 0;
      hb_retptr( pPreview );
      return;
   }
   if(pFile!=0)
   {
      IInitializeWithFile_Initialize(pFile, cFileName, STGM_READ);
   } else
   { //pIStream!=0
      HANDLE hFile = CreateFileW(cFileName,FILE_READ_DATA,FILE_SHARE_READ,NULL,OPEN_EXISTING,0,NULL );
     if( INVALID_HANDLE_VALUE != hFile )
     {
         DWORD dwSize = GetFileSize( hFile, NULL );
         HGLOBAL hGlobal= GlobalAlloc(GPTR, dwSize );
         BYTE * pByte = (BYTE *)GlobalLock(hGlobal);

         if( pByte )
         {
            LPSTREAM pStream;
            ReadFile(hFile,pByte,dwSize,&dwSize,NULL);  
            GlobalUnlock(hGlobal);

             CreateStreamOnHGlobal(hGlobal, TRUE, &pStream);    
             IInitializeWithStream_Initialize(pIStream, pStream, STGM_READ);
         }

         CloseHandle( hFile );
     }
   }
   
   hb_xfree( cFileName );
   hb_retptr( pPreview );
   return;
 }

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

HB_FUNC( PREVSETWINDOW ) //pPreview
{
   IPreviewHandler* pPreview = ( IPreviewHandler* )hb_parptr(3);
   
   
#ifndef _WIN64
   HWND hWnd = ( HWND ) hb_parnl( 1 );      
#else  
   HWND hWnd = ( HWND ) hb_parnll( 1 );  
#endif
   
   RECT rectPreview;
   if( pPreview )
   {
    rectPreview.top    = hb_parvni(2,1);
    rectPreview.left   = hb_parvni(2,2);
    rectPreview.bottom = hb_parvni(2,3);
    rectPreview.right  = hb_parvni(2,4);
     
    IPreviewHandler_SetWindow( pPreview, hWnd, &rectPreview );
     
   }
}

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

HB_FUNC( PREVDOPREVIEW ) //pPreview
{

 IPreviewHandler* pPreview = ( IPreviewHandler* )hb_parptr(1);
 if( pPreview )
 {
    IPreviewHandler_DoPreview( pPreview );
  }
}

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

HB_FUNC( UNLOADPREVIEWC ) //pPreview
{
   IPreviewHandler* pPreview = ( IPreviewHandler* )hb_parptr(1);
   if( pPreview )
   {
      IPreviewHandler_Unload(pPreview);
   }
}

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


HB_FUNC( SETRECTPREVIEWC ) //pPreview
{
   IPreviewHandler* pPreview = ( IPreviewHandler* )hb_parptr(1);
   
   RECT rectPreview;
   if( pPreview )
   {
    rectPreview.top    = hb_parvni(2,1);
    rectPreview.left   = hb_parvni(2,2);
    rectPreview.bottom = hb_parvni(2,3);
    rectPreview.right  = hb_parvni(2,4);
     
    IPreviewHandler_SetRect(  pPreview , &rectPreview );
     
   }
   
   
}


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

HB_FUNC( GETSTREAM ) // cFileName
{
   wchar_t* cFileName = UTF8toUTF16(hb_parc(1));
   HANDLE hFile = CreateFileW(cFileName,FILE_READ_DATA,FILE_SHARE_READ,NULL,OPEN_EXISTING,0,NULL );
   DWORD dwSize = GetFileSize( hFile, NULL );
   HGLOBAL hGlobal= GlobalAlloc(GPTR, dwSize );
   BYTE * pByte = (BYTE *)GlobalLock(hGlobal);
   LPSTREAM pStream;
   ReadFile(hFile,pByte,dwSize,&dwSize,NULL);  
   GlobalUnlock(hGlobal);
   CloseHandle( hFile );

   CreateStreamOnHGlobal(hGlobal, TRUE, &pStream);  
   hb_xfree( (void*) cFileName);
   hb_retptr(pStream);
}


HB_FUNC( DESTROYSTREAM ) // stream
{
   LPSTREAM pStream = hb_parptr(1);
   HGLOBAL  hGlobal;
   if( pStream )
   {
      GetHGlobalFromStream(pStream,&hGlobal);
      if(hGlobal)
         GlobalFree(hGlobal);
      IUnknown_Release(pStream);
   }
   hb_ret();
}

#pragma ENDDUMP



 
User avatar
mastintin
 
Posts: 1516
Joined: Thu May 27, 2010 2:06 pm

Re: Preview of a file

Postby nageswaragunupudi » Sat Jul 18, 2015 5:33 pm

Mr Manuel

I tried your code.
Sadly there is no improvement in my case.
As I said earlier, I tried IPreview earlier. I could preview docx,xlsx and pptx. My code is almost similar to your code regarding Ipreview. I did not try your extended search of Registry.

With your code too I am not able to view pdf. Like earlier, I see the controls of pdf but not the text.

Also I can not view .txt and other extensions.

I shall contact you personally over email about this and a few other gdi+ problems.
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10631
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: Preview of a file

Postby AntoninoP » Mon Jul 20, 2015 7:34 am

The CloseHandle( hFile ); in HB_FUNC( ADDPREVIEWC ) does not allow to pdf previewer to read the file.
It is because you don't view the pdf preview.
AntoninoP
 
Posts: 375
Joined: Tue Feb 10, 2015 9:48 am
Location: Albenga, Italy

Re: Preview of a file

Postby nageswaragunupudi » Mon Jul 20, 2015 8:31 am

AntoninoP wrote:The CloseHandle( hFile ); in HB_FUNC( ADDPREVIEWC ) does not allow to pdf previewer to read the file.
It is because you don't view the pdf preview.

In case of pdf, the preview is created from the stream not the file. In that case, why would the previewer require the file to be open?
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10631
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: Preview of a file

Postby AntoninoP » Mon Jul 20, 2015 9:39 am

:oops: I looked it too fast. The file handle is no more necessary.

so, i don't know why you see only the controls of pdf.
My mistake interfere,

Anyway, the Manuel program does not free the memory allocated to preview a pdf.
AntoninoP
 
Posts: 375
Joined: Tue Feb 10, 2015 9:48 am
Location: Albenga, Italy

Re: Preview of a file

Postby mastintin » Mon Jul 20, 2015 10:20 am

AntoninoP wrote::oops: I looked it too fast. The file handle is no more necessary.

Anyway, the Manuel program does not free the memory allocated to preview a pdf.

Yes AntoninoP , he's right. :-)

"Silvio, This is a example developed as an idea, now need you as you develop more ..."

Still much development for use.
I do not understand is because it no work. I tried it on several computers and all are ok. ¿?

Nages .You can send the exe does not work to my mail to see if it works here?
User avatar
mastintin
 
Posts: 1516
Joined: Thu May 27, 2010 2:06 pm

Re: Preview of a file

Postby Silvio.Falconi » Wed Jul 22, 2015 9:19 am

Friends
Sorry I not had time to see your messages ( my mother)
I can publich my test complete ( with listview, image ) but I have some problem because I use a class of Paco to show buttons at bottom , how I can change this class into a fwh class .. then You can try it ?
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
User avatar
Silvio.Falconi
 
Posts: 7053
Joined: Thu Oct 18, 2012 7:17 pm

Re: Preview of a file

Postby horacio » Fri Jul 24, 2015 9:00 pm

Manuel, podrías postear el archivo shextra.h ? . Muchas gracias

Saludos
horacio
 
Posts: 1363
Joined: Wed Jun 21, 2006 12:39 am
Location: Capital Federal Argentina

Re: Preview of a file

Postby mastintin » Sat Jul 25, 2015 8:42 am

horacio wrote:Manuel, podrías postear el archivo shextra.h ? . Muchas gracias

Saludos

Horacio esta unos mensajes mas arriba ... viewtopic.php?f=3&t=30904&start=15#p179276
Es el primero de los códigos que aparecen copia todo y grabalo como shextra.h y colocado con los demás includes de bcc582
User avatar
mastintin
 
Posts: 1516
Joined: Thu May 27, 2010 2:06 pm

Re: Preview of a file

Postby horacio » Sat Jul 25, 2015 1:56 pm

Gracias Manuel, no lo había visto.

Saludos
horacio
 
Posts: 1363
Joined: Wed Jun 21, 2006 12:39 am
Location: Capital Federal Argentina

Re: Preview of a file

Postby nageswaragunupudi » Fri Feb 19, 2021 11:45 am

I am reviving this old topic.

In 2015, I was able to preview docx,xlsx,pptx but not pdf (using Windows 10). When I shared this program with another user, he was able to view PDF also on his Windows 7 PC.

But now, I am not able to view even docx,xlsx,pptx also. The difference is that I installed MSOffice on my previous computer but now I am using Office 360 with a subscription. I am unable to view even jpg. :(

I seek help and guidance from our great experts Mr. Manuel and Mr. AntonioP and other experts.

May I know if you made any further improvements to this application? Can you please share your latest code?

Can we make a preview application for all extensions? Thank you in advance.
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10631
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Previous

Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 62 guests