ShellView.xaml.cs 27 KB

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