<html>
<head>
<style>
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
FONT-SIZE: 10pt;
FONT-FAMILY:Tahoma
}
</style>
</head>
<body class='hmmessage'><div style="text-align: left;">Thats excellent Tim, I was just about to start digging around for information on how to get the data once it's dropped.<br><br>Thanks for your help<br>Alex<br><br></div><hr id="stopSpelling">&gt; Date: Fri, 25 Apr 2008 17:16:34 +0100<br>&gt; From: mail@timgolden.me.uk<br>&gt; CC: python-win32@python.org<br>&gt; Subject: Re: [python-win32] Creating python com objects<br>&gt; <br>&gt; Well, for those of you still watching this show (!) and<br>&gt; just in case anyone comes along in the future with the<br>&gt; same question, I attach below a small working example<br>&gt; which will accept one or more files dropped onto its<br>&gt; Window. It doesn't do anything with the files, bar pull<br>&gt; their names from the relevant data structure, but that's<br>&gt; up to the specific application.<br>&gt; <br>&gt; Many thanks to Roger for the critical info to get this<br>&gt; working and to Alex for asking the question which started<br>&gt; it off.<br>&gt; <br>&gt; TJG<br>&gt; <br>&gt; &lt;code&gt;<br>&gt; import os, sys<br>&gt; import win32gui<br>&gt; import win32con<br>&gt; import pythoncom<br>&gt; import win32com.server.policy<br>&gt; from win32com.shell import shell, shellcon<br>&gt; <br>&gt; # clsid generated by pythoncom.CreateGuid ()<br>&gt; CLSID = '{89DD545A-2C83-4103-AFE3-6CEB7FF5ECA4}'<br>&gt; PROGID = "Tim.DropTarget"<br>&gt; DESC = "Drop target handler for Tim"<br>&gt; <br>&gt; class DropTarget (win32com.server.policy.DesignatedWrapPolicy):<br>&gt;    _reg_clsid_ = CLSID<br>&gt;    _reg_progid_ = PROGID<br>&gt;    _reg_desc_ = DESC<br>&gt;    _public_methods_ = ['DragEnter', 'DragOver', 'DragLeave', 'Drop']<br>&gt;    _com_interfaces_ = [pythoncom.IID_IDropTarget]<br>&gt; <br>&gt;    def __init__ (self, hWnd):<br>&gt;      self._wrap_ (self)<br>&gt;      self.hWnd = hWnd<br>&gt; <br>&gt;    def DragEnter (self, data_object, key_state, point, effect):<br>&gt;      if data_object.QueryGetData ((15, None, 1, -1, 1)):<br>&gt;        return shellcon.DROPEFFECT_COPY<br>&gt;      else:<br>&gt;        return shellcon.DROPEFFECT_NONE<br>&gt;    def DragOver (self, key_state, point, effect):<br>&gt;      pass<br>&gt;    def DragLeave (self):<br>&gt;      pass<br>&gt;    def Drop (self, data_object, key_state, point, effect):<br>&gt;      data = data_object.GetData ((15, None, 1, -1, 1))<br>&gt;      n_files = shell.DragQueryFileW (data.data_handle, -1)<br>&gt;      filenames = [<br>&gt;        shell.DragQueryFileW (data.data_handle, n_file) \<br>&gt;          for n_file in range (n_files)<br>&gt;      ]<br>&gt; <br>&gt; def create_window ():<br>&gt;    def OnDestroy (hwnd, msg, wparam, lparam):<br>&gt;      win32gui.PostQuitMessage (0)<br>&gt; <br>&gt;    wc = win32gui.WNDCLASS ()<br>&gt;    hinst = win32gui.GetModuleHandle(None)<br>&gt;    wc.lpszClassName = "DragDrop"<br>&gt;    wc.style = win32con.CS_VREDRAW | win32con.CS_HREDRAW;<br>&gt;    wc.hCursor = win32gui.LoadCursor (0, win32con.IDC_ARROW)<br>&gt;    wc.hbrBackground = win32con.COLOR_WINDOW<br>&gt;    wc.lpfnWndProc = {win32con.WM_DESTROY : OnDestroy}<br>&gt;    classAtom = win32gui.RegisterClass (wc)<br>&gt;    style = win32con.WS_VISIBLE | win32con.WS_OVERLAPPED \<br>&gt;      | win32con.WS_SYSMENU<br>&gt;    return win32gui.CreateWindow (<br>&gt;      classAtom,<br>&gt;      "Drag &amp; Drop demo",<br>&gt;      style,<br>&gt;      0, 0, 100, 100,<br>&gt;      0, 0, hinst, None<br>&gt;    )<br>&gt; <br>&gt; if __name__ == '__main__':<br>&gt;    pythoncom.OleInitialize ()<br>&gt;    hWnd = create_window ()<br>&gt;    drop_target = DropTarget (hWnd)<br>&gt;    pythoncom.RegisterDragDrop (<br>&gt;      hWnd,<br>&gt;      pythoncom.WrapObject (<br>&gt;        drop_target,<br>&gt;        pythoncom.IID_IDropTarget,<br>&gt;        pythoncom.IID_IDropTarget<br>&gt;      )<br>&gt;    )<br>&gt;    win32gui.PumpMessages ()<br>&gt; <br>&gt; &lt;/code&gt;<br>&gt; _______________________________________________<br>&gt; python-win32 mailing list<br>&gt; python-win32@python.org<br>&gt; http://mail.python.org/mailman/listinfo/python-win32<br><br /><hr />Get fish-slapping on Messenger <a href='http://mobile.uk.msn.com/pc/messenger.aspx ' target='_new'>Play Now</a></body>
</html>