Announcement

Collapse
No announcement yet.

Windows Explorer - Right-Click->Copy - in PB?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Windows Explorer - Right-Click->Copy - in PB?

    Not really knowing much of the ins and outs of Windows Explorer - would it be possible to execute the same operation that Right-Click->Copy performs on a file/folder, so that other programs can have that same information pasted into it? Such as a CD Authoring application? (non WinXP, or 3rd Party on WinXP)
    Adam Drake
    PowerBASIC

  • #2
    HKCR\*\shell\My Copy\command\<default value> "c:\pb\pbwin80\samples\clay's copy program.exe" %1

    The above will create a menu-extension type of entry in the Windows Explorer Files menu. This is not a true context-menu extension thingy, though - the program being invoked (above, that would be "clay's copy program.exe") will receive the selected file name in COMMAND$. If you want to do the same for folders, in above replace "*" with "Directory". HUGE warning: your program will be invoked once for every file/folder the user has selected. The effects of this, if, for example, the user selects all the files in the System32 folder and then clicks on your program's entry in the Windows Explorer File menu, will be horrific.

    Comment


    • #3
      Clay,

      Thanks for the reply, although I don't think I communicated what I was looking for clearly. What I'm wanting to do is execute the same operation that happens when you right click a file in Windows Explorer and select copy.

      For example, I would love for this to make c:\adamtemp.txt available for pasting either in Windows Explorer or in something such as a 3rd party cd authoring app:

      Code:
      #COMPILE EXE
      #DIM ALL
      
      FUNCTION PBMAIN () AS LONG
      
          CALL ExplorerLikeCopy("C:\ADAMTEMP.TXT")
      
      END FUNCTION
      
      SUB ExplorerLikeCopy(FileName AS STRING)
          
          ' Insert Code here
          
      END SUB
      Adam Drake
      PowerBASIC

      Comment


      • #4
        For example, I would love for this to make c:\adamtemp.txt available for pasting either
        in Windows Explorer or in something such as a 3rd party cd authoring app:
        Your explanation is still too vague.

        What I'm wanting to do is execute the same operation that happens when you right click
        a file in Windows Explorer and select copy.
        In the land of OLE, the code required for this is the same as that for a drag-and-drop operation.
        Windows Explorer places the following formats on the clipboard:

        Shell IDList Array
        CF_HDROP
        Preferred DropEffect
        Shell Object Offsets
        Filename
        FilenameW

        The clipboard format of most interest to you is CF_HDROP. Or maybe it is Shell IDList Array?
        If your app is going to act only as a client, then you can get away with using the SDK wrappers
        around the clipboard(IsClipboardFormatAvailable, OpenClipboard etc.). If your app is also going
        to act as a server, you can still get away with just the SDK wrappers. But if you want things
        you copy to be available to Windows Explorer, you will need to use OLE.
        Welcome to the land of the IDataObject.
        Last edited by Dominic Mitchell; 20 Dec 2007, 07:19 AM.
        Dominic Mitchell
        Phoenix Visual Designer
        http://www.phnxthunder.com

        Comment


        • #5
          VB Code here http://www.vbcode.com/Asp/showsn.asp?theID=404 looks promising
          Rgds, Dave

          Comment


          • #6
            Windows-Explorer context menu demo.
            Add right-click context menu option in "Windows Explorer"
            for drives, folder, files and .exe-files.

            Windows-Explorer context menu

            Comment


            • #7
              Thanks to all for the replies.

              Really wasn't trying to be vague, but I think I definitely succeeded. I found samples a lot like Daves in many places, and they were all quite similar. It would seem this is what I need to be able to paste into Windows Explorer (or other apps):

              Code:
              #COMPILE EXE
              #DIM ALL
              
              #INCLUDE "WIN32API.INC"
              
              FUNCTION PBMAIN () AS LONG
              
                  CALL WriteToClipboard("C:\TEST.TXT" + $NUL + "C:\ADAMTMP.TXT")
              
              END FUNCTION
              
              SUB WriteToClipboard(inBuf AS STRING)
              
                  LOCAL df        AS DROPFILES
                  LOCAL tmp       AS STRING * 20
                  LOCAL buf       AS STRING
                  LOCAL nLen      AS LONG
                  LOCAL nGblLen   AS LONG
                  LOCAL hGbl      AS LONG
                  LOCAL tmpInBuf  AS STRING
                  LOCAL lpGlobal  AS LONG
                  LOCAL szPtr     AS ASCIIZ PTR
              
                  tmpInBuf = inBuf + $NUL + $NUL
              
                  df.pFiles = 20
                  df.fWide = 0
              
                  nLen = LEN(tmpInBuf)
                  nGblLen = SIZEOF(df) + nLen
                  hGbl = GlobalAlloc(%GHND, nGblLen)
                  lpGlobal = GlobalLock(hGbl)
                  CopyMemory lpGlobal, VARPTR(df), SIZEOF(df)
                  CopyMemory lpGlobal + 20, BYVAL STRPTR(tmpInBuf), BYVAL LEN(tmpInBuf)
                  GlobalUnLock hGbl
                  IF OpenClipboard(0) THEN
                      EmptyClipboard()
                      SetClipboardData %CF_HDROP, hGbl
                      CloseClipboard()
                  END IF
                  GlobalFree hGbl 
              
              END SUB
              Just out of curiosity - does anyone see any ill effects of using this using ANSI Strings instead of Unicode (ie: df.fWide=0) in any versions of Windows?
              Adam Drake
              PowerBASIC

              Comment

              Working...
              X