ShellView.xaml.cs 27 KB

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