ShellView.xaml.cs 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620
  1. using Prism.Regions;
  2. using System.Collections.Generic;
  3. using System.Windows;
  4. using Venus_Themes.CustomControls;
  5. using Venus_UI.Themes.Attach;
  6. using Venus_Unity;
  7. using System.Linq;
  8. using System;
  9. using Venus_MainPages.Views;
  10. using System.Windows.Controls;
  11. using System.Windows.Media;
  12. using Venus_Core;
  13. using System.Reflection;
  14. using Venus_MainPages.Unity;
  15. using MECF.Framework.Common.DataCenter;
  16. using MECF.Framework.Common.OperationCenter;
  17. using Venus_MainPages.ViewModels;
  18. using MECF.Framework.Common.CommonData;
  19. using System.Windows.Threading;
  20. using Venus_Themes.Unity;
  21. using MECF.Framework.Common.Equipment;
  22. using WinInterop = System.Windows.Interop;
  23. using System.Runtime.InteropServices;
  24. using Aitex.Core.RT.SCCore;
  25. using Venus_Themes.UserControls;
  26. using System.IO;
  27. using System.Windows.Media.Imaging;
  28. using System.Threading.Tasks;
  29. using Aitex.Core.UI.View.Frame;
  30. using System.Runtime.Serialization.Formatters.Binary;
  31. using System.CodeDom;
  32. using System.Windows.Media.Animation;
  33. namespace Venus_UI.Views
  34. {
  35. /// <summary>
  36. /// ShellView.xaml 的交互逻辑
  37. /// </summary>
  38. public partial class ShellView : Window
  39. {
  40. IRegionManager m_regionManager;
  41. IRegionNavigationService m_regionNavigationService;
  42. List<VenusMenu> VenusMenu;
  43. public List<TabControl> centerTabViews = new List<TabControl>();
  44. public List<AduRadioButtonIcon> buttonList = new List<AduRadioButtonIcon>();
  45. DispatcherTimer timer = new DispatcherTimer();
  46. //public DateTime Time
  47. //{
  48. //get { return DateTime.Now; }
  49. //}
  50. public static readonly DependencyProperty TimeProperty = DependencyProperty.Register(
  51. "Time", typeof(DateTime), typeof(ShellView));
  52. public DateTime Time
  53. {
  54. get { return (DateTime)this.GetValue(TimeProperty); }
  55. set { this.SetValue(TimeProperty, value); }
  56. }
  57. public ShellView(IRegionManager regionManager, IRegionNavigationService regionNavigationService)
  58. {
  59. InitializeComponent();
  60. m_regionManager = regionManager;
  61. m_regionNavigationService = regionNavigationService;
  62. m_regionManager.RegisterViewWithRegion("TopRegion", typeof(Venus_MainPages.Views.TopView));
  63. VenusGlobalEvents.SlotRightClickChangedEvent += Instance_SlotRightClickChangedEvent;
  64. VenusGlobalEvents.SlotWaferTransferEvent += Instance_SlotStartTransferEvent;
  65. timer.Tick += timer_Tick;
  66. timer.Interval = TimeSpan.FromSeconds(0.5);
  67. timer.Start();
  68. UIEvents.PMDoorRaiseChangedEvent += UIEvents_PMDoorRaiseChangedEvent;
  69. UIEvents.LLTDoorRaiseChangedEvent += UIEvents_LLTDoorRaiseChangedEvent;
  70. UIEvents.LLEDoorRaiseChangedEvent += UIEvents_LLEDoorRaiseChangedEvent;
  71. UIEvents.ChamberCreateDeleteWaferEvent += UIEvents_ChamberCreateDeleteWaferEvent;
  72. UIEvents.InitRaiseChangedEvent += UIEvents_InitRaiseChangedEvent;
  73. UIEvents.IncludeRaiseChangedEvent += UIEvents_IncludeRaiseChangedEvent;
  74. UIEvents.OnlineRaiseChangedEvent += UIEvents_OnlineRaiseChangedEvent;
  75. this.SourceInitialized += (o, e) =>
  76. {
  77. System.IntPtr handler = (new WinInterop.WindowInteropHelper(this)).Handle;
  78. WinInterop.HwndSource.FromHwnd(handler).AddHook(new WinInterop.HwndSourceHook(WindowProc));
  79. };
  80. this.MaxHeight = SystemParameters.WorkArea.Height;
  81. ResizeMode = ResizeMode.CanMinimize;
  82. this.WindowState = this.WindowState == WindowState.Maximized ? WindowState.Normal : WindowState.Maximized;
  83. }
  84. public ShellView()
  85. {
  86. }
  87. void timer_Tick(object sender, EventArgs e)
  88. {
  89. if (Anychange.needchange)
  90. {
  91. Anystationchange(Anychange.menuname, Anychange.args);
  92. Anychange.needchange = false;
  93. }
  94. Tag=DateTime.Now;
  95. }
  96. private void Instance_SlotRightClickChangedEvent(OpenSEMI.Ctrlib.Controls.Slot slot)
  97. {
  98. if (slot != null)
  99. {
  100. ContextMenu cm = ContextMenuManager.Instance.GetSlotMenus(slot);
  101. if (cm != null)
  102. {
  103. slot.ContextMenu = cm;
  104. }
  105. return;
  106. }
  107. }
  108. private void Instance_SlotStartTransferEvent(OpenSEMI.Ctrlib.Controls.DragDropEventArgs e)
  109. {
  110. string info = " from " + e.TranferFrom.ModuleID + " slot " + (e.TranferFrom.SlotID + 1).ToString() + " to " + e.TranferTo.ModuleID + " slot " + (e.TranferTo.SlotID + 1).ToString();
  111. string message = "Are you sure to transfer the wafer: \n" + info;
  112. WaferDialogViewModel vm = new WaferDialogViewModel();
  113. vm.ConfirmText = message;
  114. WaferDialogView dialog = new WaferDialogView()
  115. {
  116. Owner = Application.Current.MainWindow,
  117. };
  118. dialog.DataContext = vm;
  119. dialog.Height = 300;
  120. dialog.Width = 400;
  121. bool alignflag = false;
  122. bool coolingflag = false;
  123. double angel = 0;
  124. double coolingtime = 0;
  125. if (dialog.ShowDialog() == true)
  126. {
  127. alignflag = (bool)dialog.AlignFlag;
  128. coolingflag = (bool)dialog.CoolingFlag;
  129. if (alignflag && !string.IsNullOrEmpty(dialog.Angle))
  130. {
  131. angel = Convert.ToDouble(dialog.Angle);
  132. }
  133. if (coolingflag && !string.IsNullOrEmpty(dialog.CoolingTime))
  134. {
  135. coolingtime = Convert.ToDouble(dialog.CoolingTime);
  136. }
  137. //from robot to robot is illegal. Must be stop
  138. if (e.TranferFrom.ModuleID == e.TranferTo.ModuleID && (e.TranferTo.ModuleID == ModuleName.EfemRobot.ToString() || e.TranferTo.ModuleID == ModuleName.TMRobot.ToString()))
  139. {
  140. }
  141. else
  142. if(e.TranferTo.ModuleID == "VPA" || string.IsNullOrEmpty(e.TranferTo.ModuleID))
  143. InvokeClient.Instance.Service.DoOperation("System.MoveWafer",
  144. e.TranferFrom.ModuleID, e.TranferFrom.SlotID, "VPA", 0, true, 0, coolingflag, coolingtime, "");
  145. InvokeClient.Instance.Service.DoOperation("System.MoveWafer",
  146. e.TranferFrom.ModuleID, e.TranferFrom.SlotID, e.TranferTo.ModuleID, e.TranferTo.SlotID, alignflag, angel, coolingflag, coolingtime, "");
  147. }
  148. else
  149. {
  150. ModuleManager.OnFlashWafer(new FlashWaferInformation() { ModuleName = e.TranferFrom.ModuleID, SoltId = e.TranferFrom.SlotID });
  151. //ModuleManager.OnFlashWafer(new FlashWaferInformation() { ModuleName = e.TranferTo.ModuleID, SoltId = e.TranferTo.SlotID });
  152. }
  153. e.TranferFrom.ClearDragDropStatus();
  154. e.TranferTo.ClearDragDropStatus();
  155. }
  156. private void CustomWnd_Loaded(object sender, RoutedEventArgs e)
  157. {
  158. var h1 = SystemParameters.WorkArea.Height;
  159. var h2 = SystemParameters.PrimaryScreenHeight;
  160. //this.ResizeMode = ResizeMode.CanResize;
  161. //System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width / SystemParameters.PrimaryScreenWidth
  162. VenusMenu = SerializeHelper.Instance.ReadFromJsonFile<List<VenusMenu>>($"Config/UIMenu.json");
  163. int index = 0;
  164. for (int i = 0; i < VenusMenu.Count; i++)
  165. {
  166. if (VenusMenu[i].IsShow == false)
  167. {
  168. continue;
  169. }
  170. string[] allModules = QueryDataClient.Instance.Service.GetConfig($"System.InstalledModules").ToString().Split(',');
  171. if (VenusMenu[i].Id == "PMA" || VenusMenu[i].Id == "PMB" || VenusMenu[i].Id == "PMC" || VenusMenu[i].Id == "PMD" || VenusMenu[i].Id == "TM")
  172. {
  173. if (!allModules.Contains(VenusMenu[i].Id))
  174. {
  175. continue;
  176. }
  177. }
  178. //if (VenusMenu[i].Id == "SETM" && SC.GetStringValue("System.ChamberSelect") !="4" && SC.GetStringValue("System.ChamberSelect") != "5")
  179. //{
  180. // //不是SE DE
  181. // continue;
  182. //}
  183. AduRadioButtonIcon aduRadioButtonIcon = new AduRadioButtonIcon();
  184. Button button = new Button();
  185. if (i == 0)
  186. {
  187. aduRadioButtonIcon.IsChecked = true;
  188. }
  189. IconElement.SetPathData(aduRadioButtonIcon, (Geometry)aduRadioButtonIcon.FindResource($"Icon_{VenusMenu[i].Id}"));
  190. aduRadioButtonIcon.Content = VenusMenu[i].Name;
  191. aduRadioButtonIcon.Checked += AduRadioButtonIcon_Click;
  192. aduRadioButtonIcon.SelectBackground = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#0076C4"));
  193. aduRadioButtonIcon.SelectColor = new SolidColorBrush((Colors.White));
  194. //aduRadioButtonIcon.DefaultBackground = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#94BCD7"));
  195. //aduRadioButtonIcon.DefaultBackground = new SolidColorBrush(Colors.DarkGray);
  196. aduRadioButtonIcon.Width = 180;
  197. //aduRadioButtonIcon.Height = 40;
  198. //aduRadioButtonIcon.Foreground=Brushes.White;
  199. aduRadioButtonIcon.Tag = index;
  200. buttonList.Add(aduRadioButtonIcon);
  201. index += 1;
  202. Bottom_Frame.Children.Add(aduRadioButtonIcon);
  203. TabControl tabControl = new TabControl();
  204. for (int j = 0; j < VenusMenu[i].MenuItem.Count; j++)
  205. {
  206. if (VenusMenu[i].MenuItem[j].IsShow == false)
  207. {
  208. continue;
  209. }
  210. string className;
  211. if ((VenusMenu[i].Id == "PMA" || VenusMenu[i].Id == "PMB" || VenusMenu[i].Id == "PMC" || VenusMenu[i].Id == "PMD") && VenusMenu[i].MenuItem[j].Id == "Operation")
  212. {
  213. JetChamber jetChamber = (JetChamber)(Convert.ToInt32(QueryDataClient.Instance.Service.GetConfig($"{VenusMenu[i].Id}.ChamberType")));
  214. className = $"Venus_MainPages.Views.Over{jetChamber.ToString()}View";
  215. }
  216. else
  217. {
  218. className = $"Venus_MainPages.Views.{VenusMenu[i].MenuItem[j].View}";
  219. }
  220. Type t = Type.GetType($"{className},Venus_MainPages");
  221. var obj = System.Activator.CreateInstance(t);
  222. if (VenusMenu[i].Id == "PMA" || VenusMenu[i].Id == "PMB" || VenusMenu[i].Id == "PMC" || VenusMenu[i].Id == "PMD" || VenusMenu[i].Id == "TM" || VenusMenu[i].Id == "SETM")
  223. {
  224. MethodInfo methodInfo = t.GetMethod("Init", new Type[] { typeof(string) });
  225. methodInfo?.Invoke(obj, new object[] { VenusMenu[i].Id });
  226. }
  227. tabControl.Items.Add(new TabItem() { Header = VenusMenu[i].MenuItem[j].Name, Content = obj });
  228. }
  229. centerTabViews.Add(tabControl);
  230. }
  231. Main_Frame.Content = centerTabViews[0];
  232. ModuleManager.Initialize();
  233. }
  234. public void Anystationchange(string menuviewItem, WaferHistoryWafer queryFilter)
  235. {
  236. UserControl address = new ProcessHistoryView();
  237. ProcessHistoryViewModel vm = new ProcessHistoryViewModel() { };
  238. vm.searchlot(queryFilter.WaferGuid);
  239. //vm.OnDataGridSelectionChanged(vm.Recipes[0]);
  240. address.DataContext = vm;
  241. int s = 0;
  242. for (int i = 0; i < centerTabViews.Count; i++)
  243. {
  244. var item = centerTabViews[i];
  245. foreach (TabItem v in item.Items)
  246. {
  247. if (v.Header.ToString() == "Process History")
  248. {
  249. s = i;
  250. }
  251. }
  252. }
  253. if (s != 0)
  254. {
  255. centerTabViews[s].Items[2] = new TabItem() { Header = menuviewItem, Content = address };
  256. centerTabViews[s].SelectedIndex = 2;
  257. Main_Frame.Content = centerTabViews[s];
  258. }
  259. }
  260. private void AduRadioButtonIcon_Click(object sender, RoutedEventArgs e)
  261. {
  262. var currentButton = sender as AduRadioButtonIcon;
  263. Main_Frame.Content = centerTabViews[Convert.ToInt32(currentButton.Tag)];
  264. }
  265. private void CustomWnd_Closed(object sender, EventArgs e)
  266. {
  267. System.Diagnostics.Process.GetCurrentProcess().Kill();
  268. }
  269. private void UIEvents_ChamberCreateDeleteWaferEvent(WaferOperation obj)
  270. {
  271. if (obj.IsCreate == true)
  272. {
  273. InvokeClient.Instance.Service.DoOperation("CreateWafer", obj.ModuleName, 0);
  274. }
  275. else
  276. {
  277. InvokeClient.Instance.Service.DoOperation("DeleteWafer", obj.ModuleName, 0);
  278. }
  279. }
  280. private void UIEvents_PMDoorRaiseChangedEvent(DoorPara obj)
  281. {
  282. //var value = SC.GetValue<int>($"{obj?.ModuleName}.ChamberType");
  283. //var value=(JetChamber)Enum.Parse(typeof(JetChamber), QueryDataClient.Instance.Service.GetConfig($"{obj?.ModuleName}.ChamberType").ToString());
  284. JetChamber jetChamber = (JetChamber)Enum.Parse(typeof(JetChamber), QueryDataClient.Instance.Service.GetConfig($"{obj?.ModuleName}.ChamberType").ToString());
  285. if (jetChamber == JetChamber.Venus)
  286. {
  287. InvokeClient.Instance.Service.DoOperation($"{obj?.ModuleName}.SetSlitDoor", obj.IsOpen == "Open" ? true : false);
  288. }
  289. else
  290. {
  291. InvokeClient.Instance.Service.DoOperation($"TM.SetMFSlitDoor", obj.ModuleName, obj.IsOpen == "Open" ? true : false);
  292. }
  293. //InvokeClient.Instance.Service.DoOperation($"{obj?.ModuleName}.SlitDoor.{obj?.IsOpen}");
  294. }
  295. private void UIEvents_LLTDoorRaiseChangedEvent(DoorPara obj)
  296. {
  297. InvokeClient.Instance.Service.DoOperation($"TM.SetMFSlitDoor", obj.ModuleName, obj.IsOpen == "Open" ? true : false);
  298. }
  299. private void UIEvents_LLEDoorRaiseChangedEvent(DoorPara obj)
  300. {
  301. InvokeClient.Instance.Service.DoOperation($"TM.SetEFEMSlitDoor", obj.ModuleName, obj.IsOpen == "Open" ? true : false);
  302. }
  303. private void UIEvents_InitRaiseChangedEvent(string obj)
  304. {
  305. InvokeClient.Instance.Service.DoOperation($"{obj}.Home");
  306. }
  307. private void UIEvents_IncludeRaiseChangedEvent(IncludePara obj)
  308. {
  309. if (obj.IsInclude)
  310. {
  311. InvokeClient.Instance.Service.DoOperation($"{obj.ModuleName}.{RtOperation.Include}");
  312. }
  313. else
  314. {
  315. InvokeClient.Instance.Service.DoOperation($"{obj.ModuleName}.{RtOperation.Exclude}");
  316. }
  317. }
  318. private void UIEvents_OnlineRaiseChangedEvent(IncludePara obj)
  319. {
  320. if (obj.IsInclude)
  321. {
  322. InvokeClient.Instance.Service.DoOperation($"{obj.ModuleName}.{RtOperation.Online}");
  323. }
  324. else
  325. {
  326. InvokeClient.Instance.Service.DoOperation($"{obj.ModuleName}.{RtOperation.Offline}");
  327. }
  328. }
  329. #region 调用api功能部分
  330. void win_SourceInitialized(object sender, EventArgs e)
  331. {
  332. System.IntPtr handle = (new WinInterop.WindowInteropHelper(this)).Handle;
  333. WinInterop.HwndSource.FromHwnd(handle).AddHook(new WinInterop.HwndSourceHook(WindowProc));
  334. }
  335. private static System.IntPtr WindowProc(
  336. System.IntPtr hwnd,
  337. int msg,
  338. System.IntPtr wParam,
  339. System.IntPtr lParam,
  340. ref bool handled)
  341. {
  342. switch (msg)
  343. {
  344. case 0x0024:
  345. WmGetMinMaxInfo(hwnd, lParam);
  346. handled = true;
  347. break;
  348. }
  349. return (System.IntPtr)0;
  350. }
  351. private static void WmGetMinMaxInfo(System.IntPtr hwnd, System.IntPtr lParam)
  352. {
  353. MINMAXINFO mmi = (MINMAXINFO)Marshal.PtrToStructure(lParam, typeof(MINMAXINFO));
  354. // Adjust the maximized size and position to fit the work area of the correct monitor
  355. int MONITOR_DEFAULTTONEAREST = 0x00000002;
  356. System.IntPtr monitor = MonitorFromWindow(hwnd, MONITOR_DEFAULTTONEAREST);
  357. if (monitor != System.IntPtr.Zero)
  358. {
  359. MONITORINFO monitorInfo = new MONITORINFO();
  360. GetMonitorInfo(monitor, monitorInfo);
  361. RECT rcWorkArea = monitorInfo.rcWork;
  362. RECT rcMonitorArea = monitorInfo.rcMonitor;
  363. mmi.ptMaxPosition.x = Math.Abs(rcWorkArea.left - rcMonitorArea.left);
  364. mmi.ptMaxPosition.y = Math.Abs(rcWorkArea.top - rcMonitorArea.top);
  365. mmi.ptMaxSize.x = Math.Abs(rcWorkArea.right - rcWorkArea.left);
  366. mmi.ptMaxSize.y = Math.Abs(rcWorkArea.bottom - rcWorkArea.top);
  367. }
  368. Marshal.StructureToPtr(mmi, lParam, true);
  369. }
  370. /// <summary>
  371. /// POINT aka POINTAPI
  372. /// </summary>
  373. [StructLayout(LayoutKind.Sequential)]
  374. public struct POINT
  375. {
  376. /// <summary>
  377. /// x coordinate of point.
  378. /// </summary>
  379. public int x;
  380. /// <summary>
  381. /// y coordinate of point.
  382. /// </summary>
  383. public int y;
  384. /// <summary>
  385. /// Construct a point of coordinates (x,y).
  386. /// </summary>
  387. public POINT(int x, int y)
  388. {
  389. this.x = x;
  390. this.y = y;
  391. }
  392. }
  393. [StructLayout(LayoutKind.Sequential)]
  394. public struct MINMAXINFO
  395. {
  396. public POINT ptReserved;
  397. public POINT ptMaxSize;
  398. public POINT ptMaxPosition;
  399. public POINT ptMinTrackSize;
  400. public POINT ptMaxTrackSize;
  401. };
  402. /// <summary>
  403. /// </summary>
  404. [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
  405. public class MONITORINFO
  406. {
  407. /// <summary>
  408. /// </summary>
  409. public int cbSize = Marshal.SizeOf(typeof(MONITORINFO));
  410. /// <summary>
  411. /// </summary>
  412. public RECT rcMonitor = new RECT();
  413. /// <summary>
  414. /// </summary>
  415. public RECT rcWork = new RECT();
  416. /// <summary>
  417. /// </summary>
  418. public int dwFlags = 0;
  419. }
  420. /// <summary> Win32 </summary>
  421. [StructLayout(LayoutKind.Sequential, Pack = 0)]
  422. public struct RECT
  423. {
  424. /// <summary> Win32 </summary>
  425. public int left;
  426. /// <summary> Win32 </summary>
  427. public int top;
  428. /// <summary> Win32 </summary>
  429. public int right;
  430. /// <summary> Win32 </summary>
  431. public int bottom;
  432. /// <summary> Win32 </summary>
  433. public static readonly RECT Empty = new RECT();
  434. /// <summary> Win32 </summary>
  435. public int Width
  436. {
  437. get { return Math.Abs(right - left); } // Abs needed for BIDI OS
  438. }
  439. /// <summary> Win32 </summary>
  440. public int Height
  441. {
  442. get { return bottom - top; }
  443. }
  444. /// <summary> Win32 </summary>
  445. public RECT(int left, int top, int right, int bottom)
  446. {
  447. this.left = left;
  448. this.top = top;
  449. this.right = right;
  450. this.bottom = bottom;
  451. }
  452. /// <summary> Win32 </summary>
  453. public RECT(RECT rcSrc)
  454. {
  455. this.left = rcSrc.left;
  456. this.top = rcSrc.top;
  457. this.right = rcSrc.right;
  458. this.bottom = rcSrc.bottom;
  459. }
  460. /// <summary> Win32 </summary>
  461. public bool IsEmpty
  462. {
  463. get
  464. {
  465. // BUGBUG : On Bidi OS (hebrew arabic) left > right
  466. return left >= right || top >= bottom;
  467. }
  468. }
  469. /// <summary> Return a user friendly representation of this struct </summary>
  470. public override string ToString()
  471. {
  472. if (this == RECT.Empty) { return "RECT {Empty}"; }
  473. return "RECT { left : " + left + " / top : " + top + " / right : " + right + " / bottom : " + bottom + " }";
  474. }
  475. /// <summary> Determine if 2 RECT are equal (deep compare) </summary>
  476. public override bool Equals(object obj)
  477. {
  478. if (!(obj is Rect)) { return false; }
  479. return (this == (RECT)obj);
  480. }
  481. /// <summary>Return the HashCode for this struct (not garanteed to be unique)</summary>
  482. public override int GetHashCode()
  483. {
  484. return left.GetHashCode() + top.GetHashCode() + right.GetHashCode() + bottom.GetHashCode();
  485. }
  486. /// <summary> Determine if 2 RECT are equal (deep compare)</summary>
  487. public static bool operator ==(RECT rect1, RECT rect2)
  488. {
  489. return (rect1.left == rect2.left && rect1.top == rect2.top && rect1.right == rect2.right && rect1.bottom == rect2.bottom);
  490. }
  491. /// <summary> Determine if 2 RECT are different(deep compare)</summary>
  492. public static bool operator !=(RECT rect1, RECT rect2)
  493. {
  494. return !(rect1 == rect2);
  495. }
  496. }
  497. [DllImport("user32")]
  498. internal static extern bool GetMonitorInfo(IntPtr hMonitor, MONITORINFO lpmi);
  499. /// <summary>
  500. ///
  501. /// </summary>
  502. [DllImport("User32")]
  503. internal static extern IntPtr MonitorFromWindow(IntPtr handle, int flags);
  504. #endregion
  505. #region 截屏
  506. private void SaveWindowContent(Window source, string fileName)
  507. {
  508. //FrameworkElement elem = source.Content as FrameworkElement;
  509. RenderTargetBitmap targetBitmap = new RenderTargetBitmap(
  510. 1920,
  511. 1030,
  512. 96d,
  513. 96d,
  514. PixelFormats.Default);
  515. targetBitmap.Render(source);
  516. BmpBitmapEncoder encoder = new BmpBitmapEncoder();
  517. encoder.Frames.Add(BitmapFrame.Create(targetBitmap));
  518. // save file to disk
  519. using (FileStream fs = File.Open(fileName, FileMode.OpenOrCreate))
  520. {
  521. encoder.Save(fs);
  522. }
  523. }
  524. #endregion
  525. private void Window_MouseDoubleClick(object sender, System.Windows.Input.MouseButtonEventArgs e)
  526. {
  527. //this.buttonList[2].IsChecked = true;
  528. //await Task.Delay(5);
  529. //SaveWindowContent(this, "test.jpg");
  530. //this.buttonList[0].IsChecked = true;
  531. }
  532. }
  533. }