ShellView.xaml.cs 25 KB

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