Forum

C# Events in vvvv

Hiya!
I wanna do a node which outputs Drag and Drop information about a window selected by a handle. I searched for it and I found very simple solutions like this http://www.jonasjohn.de/snippets/csharp/drag-and-drop-example.htm which was planned to be used for listboxes.
currently i only want a simple bang when DragEnter, DragDrop and DragLeave happens on that window and maybe i would like to retrieve the string what is dragged. Anyway I’ve only came to a mess which produces nothing but an “Object reference not set to an instance of an object.” exception. I’m suspicious that i’ve used “this”

window.DragEnter += new DragEventHandler(this.window_DragEnter);

in a wrong way. however if i say

window.DragEnter += new DragEventHandler(VVVV.Nodes.WindowsDragAndDropNode.window_DragEnter);

instead of “this” the compiler says
“An object reference is required for non-static field, method or property ‘VVVV.Nodes.WindowsDragAndDropNode.window_DragEnter(object, System.Windows.Forms.DragEventArgs)’”
however in all examples the method called on the event doesn’t have those “object” and “DragEventArgs” arguments in the DragEventHandler() just in the declaration so I don’t really understand where those two come from in the examples as well.
Anybody could help with this?

this is what i’m talking about (19.5 kB)

the first line is good. but the window you are trying to cast to a form is null. i think you can only cast c# form windows like this.

the compiler tries to tell you that you have to provide a object method reference and not a static method reference.

if the window cast would work, the code could work like this:

code(lang=csharp):

  • region usings
    using System;
    using System.ComponentModel.Composition;
    using System.Windows.Forms;
    using System.Collections;

using VVVV.PluginInterfaces.V1;
using VVVV.PluginInterfaces.V2;
using VVVV.Utils.VColor;
using VVVV.Utils.VMath;

using VVVV.Core.Logging;

  • endregion usings

namespace VVVV.Nodes
{
#region PluginInfo
[PluginInfo(Name = “DragAndDrop”, Category = “Windows”, Help = “Basic template with one value in/out”, Tags = “”)](PluginInfo(Name = “DragAndDrop”, Category = “Windows”, Help = “Basic template with one value in/out”, Tags = “”))
#endregion PluginInfo
public class WindowsDragAndDropNode : IPluginEvaluate
{
#region fields & pins
[Input(“Window Handle”, DefaultValue = 0)](Input(“Window Handle”, DefaultValue = 0))
IDiffSpread FHandle;

  [Output("DragEnter")](Output("DragEnter"))
  ISpread<bool> FDragEnter;
  
  Control FWindow; //store the window so that it doesn't get garbage collected
  bool FDragEnterState;
  object FDragThreadLock = new object();

  [Import()](Import())
  ILogger FLogger;
  #endregion fields & pins

  //called when data for any output pin is requested
  public void Evaluate(int SpreadMax)
  {
  	FDragEnter.SliceCount = 1;
  	
  	if(FHandle.IsChanged)
  	{
  		IntPtr handle = new IntPtr(FHandle[0](0));
  		FWindow = (handle==IntPtr.Zero) ? null : Control.FromHandle(handle); //store window
  		
  		if(FWindow != null)
  		{
  			//do this only once
  			FWindow.DragEnter += new DragEventHandler(this.window_DragEnter);
  			FLogger.Log(LogType.Debug, "window is good");
  		}
  		else
  		{
  			FLogger.Log(LogType.Debug, "window of handle " + handle.ToInt64() + " is null, cast isn't working");
  		}
  	}
  	
  	lock(FDragThreadLock) //make sure that no other thread is changing the state while writing it
  	{
  		//write the state
  		FDragEnter[0](0) = FDragEnterState;
  		
  		//reset the state
  		FDragEnterState = false;
  	}

  }
  
  //this can happen at any time, so you have to store the state until the vvvv main loop can read it
  public void window_DragEnter(object sender, System.Windows.Forms.DragEventArgs e)
  {
  	lock(FDragThreadLock) //make sure vvvv is not writing the state while it gets changed
  	{
  		FDragEnterState = true;
  	}
  	
  	e.Effect = DragDropEffects.All;
  }

}
}

aah thanks! I see now! well that’s a bad news. do you know another way to get drag’n’drop data about that renderer?
i found this: http://msdn.microsoft.com/en-us/library/windows/desktop/bb774303(v=vs.85).aspx but retrieving the info about the dropped file with “DragQueryFile” requires some pointer story i’m not really sure about in managed environment.

i am sure you will find some answers here: http://stackoverflow.com/questions/2061167/how-to-receive-the-windows-messages-without-a-windows-form

or here:
http://www.codeproject.com/Articles/3946/Trapping-windows-messages

hmm that’s some kind of low-level network communication method it seems to have nothing to do with window messages

it was using the same terms, probably the same api, but check the new links. maybe they help…?

that message trapping seems useful. i’ve tried GetMessage with DLLImport from user32.dll but that freezed vvvv. I’ll give that a try!

edit: maaan this is a disaster. i’ll just create a separate form for dropping files:D