Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

HTA ondrop event 1

Status
Not open for further replies.

bn2hunt

MIS
May 15, 2003
203
US
Does anybody have any idea on how to code and ondrop event in a vbscript. I want to be able to have a user drag a file into the hta and then I want to pull the file name and location to populate an array and a listbox.

I have been googling this for about a day and half and I'm not getting anywhere. Is this even possible with vbscript?

Thanks for any help

Dan

bn2hunt

"Born to hunt forced to work
 
Why would you think it's a question of whether VBScript can do it? This is about the host, not the scripting language.

In any case, try looking at the documentation: ondrop Event. There are a number of caveats and requirements.

The issues are the same whether VBScript, JScript, Perl, or whatever other language you have a script engine for.
 
I have looked at that web page several times, and I can't get the ondrop event to fire. The HTA that I created won't even accept input to be dropped into it. When I try to drag a file into the hta I get the circle with a slash in it indicating to me that this is not allowed.

As for why I asked if it was even possible in vbscript is becuase the only examples I have seen are in Javascript.

Code:
<html>

<head>

<title>Append PDF files</title>

<HTA:APPLICATION
     ID="appendpdf"
     APPLICATIONNAME="appendpdf"
     SCROLL="no"
     SINGLEINSTANCE="yes"
     WINDOWSTATE="maximize"
>
</head>

<style>
BODY
{
   background-color: buttonface;
   font-family: Helvetica;
   font-size: 8pt;
   margin-top: 10px;
   margin-left: 20px;
   margin-right: 20px;
   margin-bottom: 10px;
}
.button
{
   font-family: Helvetica;
   font-size: 8pt;
   width: 130px;
}
textarea
{
   font-family: arial;
   font-size: 8pt;
}
select
{
   font-family: arial;
   font-size: 8pt;
   width: 800px;
   margin-left: 0px;
}
td
{
   font-family: arial;
   font-size: 10pt;
}

.dropBox{
		width:190px;
		border:1px solid #000;
		background-color:#E2EBED;
		height:200px;
		overflow:auto;
		margin-bottom:10px;
		padding:3px;
		}

</style>

<body>

&nbsp;<br>


<SCRIPT LANGUAGE="VBScript">
	Set ws = CreateObject("WScript.Shell")
   	Set fs = CreateObject("Scripting.FileSystemObject")
	Set WshSysEnv = WS.Environment("Process")
	
	
	
Sub window_onload()
	h = 300
	w = 400
	sxTop = window.screen.height/2 -(h/2)
	sxLeft = window.screen.width/2  -(w/2)

	self.MoveTo sxLeft, sxTop
	self.ResizeTo w, h
	
	Availablefiles.ondrop = GetRef("ondrop_event")	
	
	
End Sub
Sub ondrop_event
	MsgBox "ondrop"
End Sub

</SCRIPT>
<body>
	<table>
		<tr>	
			<td colspan=3><TEXTAREA rows = '10' width:350 name='Availablefiles' readonly></textarea></td>
			
		</tr>
		<TR>
			<td><input type="button" onclick="browse" value=".."></input></td>
			<TD><INPUT TYPE=BUTTON NAME="APPEND" Value = "Append PDF Documents" ONCLICK="appendsub"></INPUT></TD>
			<td><input type=button name="close" value = "Close" onclick="window.close()"></input></td>
		</TR>
   </table>


</body>
</html>

bn2hunt

"Born to hunt forced to work
 
I see what you're after now. Sadly, I doubt it can be done. I don't think MSHTA or IE support dragdrop for the files/filelists that Explorer lets you dragdrop. As far as I know you only have the option to get Text or URLs.

An ActiveX control might work as such a drop target though.

Here's your example cleaned up a bit to work with text dragged from an IE window:
Code:
<html>
  <head>
    <title>Append PDF files</title>
    <HTA:APPLICATION
      ID="appendpdf"
      APPLICATIONNAME="appendpdf"
      SCROLL="no"
      SINGLEINSTANCE="yes"
      WINDOWSTATE="maximize"
    >
  <script language="VBScript">
    Option Explicit

    Sub Availablefiles_ondragenter()
      window.event.returnValue = False
    End Sub

    Sub Availablefiles_ondragover()
      window.event.returnValue = False
    End Sub

    Sub Availablefiles_ondrop()
      Availablefiles.value = _
          Availablefiles.value _
        & window.event.dataTransfer.getData("Text") _
        & vbNewLine
    End Sub

    Sub Close_onclick()
	window.close
    End Sub
    
    Sub window_onload()
      Dim h, w, sxTop, sxLeft

      h = 300
      w = 400
      sxTop = window.screen.height/2 -(h/2)
      sxLeft = window.screen.width/2  -(w/2)

      self.ResizeTo w, h
      self.MoveTo sxLeft, sxTop
    End Sub
  </script>
</head>
<body>
  <table>
    <tr>    
      <td colspan=3>
        <textarea rows=10 style="width: 350" id=Availablefiles
          readonly></textarea>
      </td>
    </tr>
    <tr>
      <td><input type=button value=".."></td>
      <td><input type=button id=Append
            value="Append PDF Documents"></td>
      <td><input type=button id=Close value=Close></td>
    </tr>
  </table>
</html>
 
Thanks Dilettante, that gets me alot closer than I was before. And also tells me that what I want may not be possible. I will post here agian if I figure it out.

If I am reading your code correct, I need to have the 3 subs ondragenter, ondragover and ondrop to have the drag and drop functionality available. Is that correct?

And thanks again for your help.

Dan

bn2hunt

"Born to hunt forced to work
 
Yes, as it says in the documentation page I linked to above you have to cancel the first two events of the dragdrop operation.

You might also note how much cleaner VBScript event binding can be than the JavaScript binding you were using. Also consider that when scripting HTML elements the [tt]id[/tt] attribute is used, not the [tt]name[/tt]. You can get lucky most of the time, because when it can MSHTA/IE will implicitly set the id to the name if not specified - but it doesn't always work. The [tt]name[/tt] is for form submission via HTTP, not for scripting!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top