Main.cs 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. using Kbg.NppPluginNET.PluginInfrastructure;
  2. using System;
  3. using System.Runtime.InteropServices;
  4. using System.Windows.Forms;
  5. using HelloNppPluginDockWindow;
  6. // ReSharper disable once CheckNamespace
  7. public class Main
  8. {
  9. public const string PluginName = nameof(HelloNppPluginDockWindow);
  10. public static void CommandMenuInit()
  11. {
  12. PluginBase.SetCommand(0, "Show hello form", ShowHi);
  13. PluginBase.SetCommand(0, "Show hello form (dockable)", ShowHiDockable);
  14. }
  15. public static void SetToolBarIcon()
  16. {
  17. }
  18. public static void PluginCleanUp()
  19. {
  20. }
  21. public static void OnNotification(ScNotification notification)
  22. {
  23. }
  24. private static void ShowHi()
  25. {
  26. var sayHiForm = new SayHiForm { StartPosition = FormStartPosition.CenterParent };
  27. sayHiForm.Show(new Win32Window(PluginBase.nppData._nppHandle));
  28. }
  29. private static void ShowHiDockable()
  30. {
  31. var sayHiForm = new SayHiForm();
  32. sayHiForm.Text += " (dockable)";
  33. sayHiForm.label1.Text += " (dockable)";
  34. // dlgID: the dlgDlg should be the index of funcItem where the current function pointer is in
  35. // this case is 15.. so the initial value of funcItem[15]._cmdID - not the updated internal one !
  36. // uMask: define the default docking behaviour
  37. var nppTbData = new NppTbData
  38. {
  39. pszModuleName = PluginName,
  40. hClient = sayHiForm.Handle,
  41. pszName = sayHiForm.Text,
  42. hIconTab = (uint)sayHiForm.Icon.Handle,
  43. uMask = NppTbMsg.DWS_DF_CONT_RIGHT | NppTbMsg.DWS_ICONTAB | NppTbMsg.DWS_ICONBAR,
  44. //dlgID = 15,
  45. };
  46. var ptrNppTbData = Marshal.AllocHGlobal(Marshal.SizeOf(nppTbData));
  47. Marshal.StructureToPtr(nppTbData, ptrNppTbData, false);
  48. Win32.SendMessage(PluginBase.nppData._nppHandle, (uint)NppMsg.NPPM_DMMREGASDCKDLG, IntPtr.Zero, ptrNppTbData);
  49. }
  50. }