drag and drop

drag and drop

Postby Silvio.Falconi » Mon Sep 30, 2013 6:57 pm

it is possible select an image from a folder and drag it into a image 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: 7056
Joined: Thu Oct 18, 2012 7:17 pm

Re: drag and drop

Postby MaxP » Tue Oct 01, 2013 6:24 am

you can try this

Code: Select all  Expand view

#include "FiveWin.ch"
#include "Image.ch"

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

function Main()
   LOCAL        oWnd, oImage


   DEFINE WINDOW oWnd FROM 0, 0 TO 22, 60 ;
      TITLE FWDESCRIPTION + " JPG,JIF,GIF,BMP,DIB,RLE,TGA,PCX support!"

   @ 0, 0 IMAGE oImage SIZE 300, 300 OF oWnd SCROLL ADJUST

   oImage:Progress( .f. )

   @ 2, 56 BUTTON "Select Image" SIZE 100,20 OF oWnd ACTION GetImage( oImage )

   @ 4, 56 BUTTON "Print" SIZE 100,20 OF oWnd ACTION PrintImage( oImage )

   @ 6, 56 BUTTON "Copy" SIZE 100, 20 OF oWnd ;
      ACTION oImage:CopyToClipboard()

   @ 8, 56 BUTTON "Paste" SIZE 100, 20 OF oWnd ;
      ACTION ( oImage:LoadFromClipboard(), oImage:Refresh() )

   @ 10, 56 BUTTON "Save" SIZE 100, 20 OF oWnd ;
      ACTION ( oImage:SaveImage( "SAVED.JPG", 2, 25 ), MsgInfo( "saved as saved.jpg" ) )

   @ 12, 56 BUTTON "Exit" SIZE 100, 20 OF oWnd ACTION oWnd:End()
   
   @ 20, 56 CHECKBOX oImage:lStretch PROMPT "Stretch" SIZE 100, 20 OF oWnd ;
      ON CHANGE ( oImage:ScrollAdjust(), oImage:Refresh() )

   ACTIVATE WINDOW oWnd  ON DROPFILES TakeDrop( aFiles, oImage )

return nil

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

STATIC FUNCTION TakeDrop( aFiles, oImage )
        LOCAL   nPos
       
        FOR nPos = 1 to Len( aFiles )
                IF UPPER( RIGHT( aFiles[ nPos ], 3 ) ) == "JPG" .OR. UPPER( RIGHT( aFiles[ nPos ], 3 ) ) == "BMP" // etc.
                        oImage:LoadBmp( aFiles[ nPos ] )
                        EXIT
                ENDIF
        NEXT nPos
RETURN NIL

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

function GetImage( oImage )

   local gcFile := cGetFile( "Bitmap (*.bmp)| *.bmp|" +         ;
                             "DIB   (*.dib)| *.dib|" +          ;
                             "PCX   (*.pcx)| *.pcx|"  +         ;
                             "JPEG  (*.jpg)| *.jpg|" +          ;
                             "GIF   (*.gif)| *.gif|"  +         ;
                             "TARGA (*.tga)| *.tga|" +          ;
                             "RLE   (*.rle)| *.rle|" +          ;
                             "All Files (*.*)| *.*"             ;
                            ,"Please select a image file", 4 )

   if ! Empty( gcFile ) .and. File( gcFile )
      oImage:LoadBmp( gcFile )
   endif

return nil

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

function PrintImage( oImage )

   local oPrn

   PRINT oPrn NAME "Image Printing" PREVIEW
      PAGE
         oPrn:SayImage( 0, 0, oImage )
      ENDPAGE
   ENDPRINT

return nil

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

procedure AppSys   // XBase++ requirement

return

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


Saluti
Massimo
User avatar
MaxP
 
Posts: 85
Joined: Thu Jul 12, 2007 2:02 pm

Re: drag and drop

Postby Silvio.Falconi » Tue Oct 01, 2013 9:28 am

only not run with TDIALOG
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: 7056
Joined: Thu Oct 18, 2012 7:17 pm

Re: drag and drop

Postby MaxP » Tue Oct 01, 2013 10:09 am

you can try this

Code: Select all  Expand view

#include "FiveWin.ch"
#include "Image.ch"



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

function Main()
   LOCAL        oDlg, oImage


   DEFINE DIALOG oDlg FROM 0, 0 TO 22, 60 ;
      TITLE FWDESCRIPTION + " JPG,JIF,GIF,BMP,DIB,RLE,TGA,PCX support!"

   @ 0, 0 IMAGE oImage SIZE 150, 150 OF oDlg SCROLL ADJUST

   oImage:Progress( .f. )

   @ 1, 28 BUTTON "Select Image" SIZE 50, 10 OF oDlg ACTION GetImage( oImage )

   @ 2, 28 BUTTON "Print" SIZE 50, 10 OF oDlg ACTION PrintImage( oImage )

   @ 3, 28 BUTTON "Copy" SIZE 50, 10 OF oDlg ;
      ACTION oImage:CopyToClipboard()

   @ 4, 28 BUTTON "Paste" SIZE 50, 10 OF oDlg ;
      ACTION ( oImage:LoadFromClipboard(), oImage:Refresh() )

   @ 5, 28 BUTTON "Save" SIZE 50, 10 OF oDlg ;
      ACTION ( oImage:SaveImage( "SAVED.JPG", 2, 25 ), MsgInfo( "saved as saved.jpg" ) )

   @ 6, 28 BUTTON "Exit" SIZE 50, 10 OF oDlg ACTION oDlg:End()
   
   @ 10, 28 CHECKBOX oImage:lStretch PROMPT "Stretch" SIZE 50, 10 OF oDlg ;
      ON CHANGE ( oImage:ScrollAdjust(), oImage:Refresh() )

     
   ACTIVATE DIALOG oDlg CENTER ON INIT SetDrop( oDlg, oImage )

return nil

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

STATIC FUNCTION SetDrop( oDlg, oImage )      
      DragAcceptFiles( oDlg:hWnd, .t. )
      oDlg:bDropFiles = { | nRow, nCol, aFiles | TakeDrop( nRow, nCol, aFiles, oImage ) }
RETURN NIL

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

STATIC FUNCTION TakeDrop( nRow, nCol, aFiles, oImage )
        LOCAL   nPos

        FOR nPos = 1 to Len( aFiles )
                IF UPPER( RIGHT( aFiles[ nPos ], 3 ) ) == "JPG" .OR. UPPER( RIGHT( aFiles[ nPos ], 3 ) ) == "BMP" // etc.
                        oImage:LoadBmp( aFiles[ nPos ] )
                        EXIT
                ENDIF
        NEXT nPos
RETURN NIL

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

function GetImage( oImage )

   local gcFile := cGetFile( "Bitmap (*.bmp)| *.bmp|" +         ;
                             "DIB   (*.dib)| *.dib|" +          ;
                             "PCX   (*.pcx)| *.pcx|"  +         ;
                             "JPEG  (*.jpg)| *.jpg|" +          ;
                             "GIF   (*.gif)| *.gif|"  +         ;
                             "TARGA (*.tga)| *.tga|" +          ;
                             "RLE   (*.rle)| *.rle|" +          ;
                             "All Files (*.*)| *.*"             ;
                            ,"Please select a image file", 4 )

   if ! Empty( gcFile ) .and. File( gcFile )
      oImage:LoadBmp( gcFile )
   endif

return nil

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

function PrintImage( oImage )

   local oPrn

   PRINT oPrn NAME "Image Printing" PREVIEW
      PAGE
         oPrn:SayImage( 0, 0, oImage )
      ENDPAGE
   ENDPRINT

return nil

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

procedure AppSys   // XBase++ requirement

return

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


ciao
Massimo
User avatar
MaxP
 
Posts: 85
Joined: Thu Jul 12, 2007 2:02 pm


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 85 guests