using System.Runtime.InteropServices; using System.Windows; using System.Windows.Interop; using System.Windows.Media.Imaging; namespace WpfSketch { /// /// App.xaml 的交互逻辑 /// public partial class App : System.Windows.Application { /// /// Application_S the startup. /// /// The sender. /// The e. private void Application_Startup(object sender, StartupEventArgs e) { Window1 main = new Window1(); if (e.Args.Length > 0) { if (e.Args.Length>1 && e.Args[0].Equals("/e") && e.Args[1].Equals("/h")) { System.Windows.Forms.IDataObject data = System.Windows.Forms.Clipboard.GetDataObject(); if (data.GetDataPresent(typeof(Bitmap))) { Bitmap photo = (Bitmap)data.GetData(typeof(Bitmap)); BitmapSource returnImage = ImageWork.BitmapToBitmapImage(photo); main.DestImage = returnImage; main.ImageSaveEvent += (image) => { //Bitmap bmtEdited = ImageWork.BitmapToBitmapImage() System.Windows.Clipboard.SetImage(image); }; if (e.Args.Length > 2) { IntPtr pWindow = new IntPtr(Convert.ToInt64(e.Args[2])); if (IsWindow(pWindow)) { WindowInteropHelper helper = new WindowInteropHelper(main); helper.Owner = pWindow; } } } } else { main.ImageFile = e.Args[0]; } } main.Show(); } [DllImport("user32.dll", SetLastError = true)] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool IsWindow(IntPtr hWnd); } }