예제 #1
0
 private bool EnumWindowsProc(IntPtr hwnd, int lParam)
 {
     try
     {
         if (!PNInterop.IsWindowVisible(hwnd))
         {
             return(true);
         }
         var count = PNInterop.GetWindowTextLength(hwnd);
         if (count <= 0)
         {
             return(true);
         }
         var sb = new StringBuilder(count + 1);
         PNInterop.GetWindowText(hwnd, sb, count + 1);
         var sbClass = new StringBuilder(1024);
         PNInterop.GetClassName(hwnd, sbClass, sbClass.Capacity);
         m_Windows.Add(new PinWindow {
             ClassWnd = sbClass.ToString(), TextWnd = sb.ToString()
         });
         return(true);
     }
     catch (Exception ex)
     {
         PNStatic.LogException(ex);
         return(false);
     }
 }
예제 #2
0
        private static bool enumAllWindowsProc(IntPtr hwnd, int msg)
        {
            try
            {
                var sb = new StringBuilder(256);

                PNInterop.GetWindowText(hwnd, sb, 256);
                if (sb.Length > 0 && sb.ToString() == "PNotes.NET Main Window")
                {
                    if (msg == PNInterop.WM_COPYDATA)
                    {
                        var cpdata = new PNInterop.COPYDATASTRUCT {
                            dwData = new IntPtr((int)_copyDataType)
                        };
                        var data = new StringBuilder();
                        switch (_copyDataType)
                        {
                        case CopyDataType.NewNote:
                            cpdata.cbData = Encoding.Default.GetBytes(_newNoteString).Count() +
                                            Encoding.Default.GetBytes(_newNoteName).Count() +
                                            Encoding.Default.GetBytes(_newNoteTags).Count() + 3;
                            data.Append(_newNoteString);
                            data.Append(PNStrings.DEL_CHAR);
                            data.Append(_newNoteName);
                            data.Append(PNStrings.DEL_CHAR);
                            data.Append(_newNoteTags);
                            break;

                        case CopyDataType.LoadNotes:
                            foreach (var f in _FilesToLoad)
                            {
                                cpdata.cbData += Encoding.Default.GetBytes(f).Count() + 1;
                                data.Append(f);
                                data.Append(PNStrings.DEL_CHAR);
                            }
                            if (data.Length > 0)
                            {
                                data = data.Remove(data.Length - 1, 1);
                            }
                            break;

                        case CopyDataType.ShowNoteById:
                            cpdata.cbData = Encoding.Default.GetBytes(_idToShow).Count();
                            data.Append(_idToShow);
                            break;
                        }
                        cpdata.lpData = data.ToString();
                        PNInterop.SendMessageCopyData(hwnd, (uint)msg, IntPtr.Zero, ref cpdata);
                    }
                    else
                    {
                        PNInterop.SendMessage(hwnd, (uint)msg, 0, 0);
                    }
                    _mainWindowExists = true;
                    return(false);
                }
                return(true);
            }
            catch (Exception ex)
            {
                PNStatic.LogException(ex);
                return(false);
            }
        }