Tag Archives: Google Desktop

Google Desktop plugin (Google Gadgets) & C# – moving the gadget

As I specified in last post, and you probably figured out by now, the gadget cannot be moved onto window, by dragging it with the mouse, like it works for other gadgets.
In order to be able to drag it over the screen, add the following code in mouse down event handler (either in the plugin, or various other .net controls over the plugin interface) :

private void xxxx_MouseDown(object sender,
   MouseEventArgs e)
{
  if (e.Button == MouseButtons.Right)
  {
    IntPtr handle = FindWindow("ATL:051D0C28", "");
    if (handle != null)
    {
      MainPanel.RECT rect;
      MainPanel.GetWindowRect(handle, out rect);
      MainPanel.ReleaseCapture();
      MainPanel.SendMessage(handle, WM_NCLBUTTONDOWN,
        HT_CAPTION, 0);
    }
    else
    {
      MessageBox.Show("Window not found!!");
    }
  }
}

and also add the following definitions to the class:

[DllImport("user32.dll", SetLastError = true)]
public static extern IntPtr FindWindow(string lpClassName,
  string lpWindowName);

public const int WM_NCLBUTTONDOWN = 0xA1;
public const int HT_CAPTION = 0x2;

where the window with class ATL:051D0C28 is the window which hosts our plugin control.
This will tell the window to handle button down as it were clicked onto window title bar.

Happy dragging.