/// <summary> /// 檢查是否為一般監視器 /// </summary> /// <param name="ResultArray"></param> /// <param name="AnswerDic"></param> public static void Display_Check(ref Dictionary <string, object> ResultArray, ref Dictionary <string, object> AnswerDic) { ResultArray[Parameters.Status] = "Pass"; FuncClass.ExtendMode(); Thread.Sleep(100); if (!ResultArray.ContainsKey("ID")) { ResultArray.Add("ID", new List <string> { }); } if (!ResultArray.ContainsKey("Screen")) { ResultArray.Add("Screen", new List <string> { }); } List <string> idl = new List <string>(); List <string> screenl = new List <string>(); var device = new Parameters.Windows.DISPLAY_DEVICE(); device.cb = Marshal.SizeOf(device); try { foreach (var screen in Screen.AllScreens) { for (uint id = 0; Parameters.Windows.EnumDisplayDevices(null, id, ref device, 0); id++) { device.cb = Marshal.SizeOf(device); Parameters.Windows.EnumDisplayDevices(device.DeviceName, 0, ref device, 0); device.cb = Marshal.SizeOf(device); if (device.DeviceName == null || device.DeviceName == "") { continue; } if (device.DeviceName.Contains(screen.DeviceName)) { if (screen.Primary) { idl.Add(FuncClass.StringCut(device.DeviceID)); screenl.Add("Primary"); } else { idl.Add(FuncClass.StringCut(device.DeviceID)); screenl.Add("Secondary"); } } } } ResultArray["ID"] = idl; ResultArray["Screen"] = screenl; string dutID = ""; string dutSc = ""; for (int i = 0; i < idl.Count(); i++) { // Primary screen id comparison if (idl[i] == (string)AnswerDic["DUTID"]) { dutID = (string)AnswerDic["DUTID"]; dutSc = screenl[i]; } } // Make sure is extend mode if (Screen.AllScreens.Length > 1) { if (!string.IsNullOrEmpty(dutID)) { if (dutSc == "Primary") { ResultArray[Parameters.Status] = "Pass"; } else { ResultArray[Parameters.Status] = "Fail"; ResultArray[Parameters.Remark] = "Dut monitor is not generic PnP monitor "; } } else { ResultArray[Parameters.Status] = "Fail"; ResultArray[Parameters.Remark] = "No Dut monitor detected."; } } else { ResultArray[Parameters.Status] = "Fail"; ResultArray[Parameters.Remark] = "No more than two monitors."; } } catch (Exception) { ResultArray[Parameters.Status] = "Fail"; ResultArray[Parameters.Remark] = "Display mode is not extend mode"; } }
/// <summary> /// 主螢幕檢查 /// </summary> /// <param name="ResultArray"></param> /// <param name="AnswerDic"></param> public static void PnP_Check(ref Dictionary <string, object> ResultArray, ref Dictionary <string, object> AnswerDic) { ResultArray[Parameters.Status] = "Pass"; FuncClass.ExtendMode(); Thread.Sleep(100); if (!ResultArray.ContainsKey("ID")) { ResultArray.Add("ID", new List <string> { }); } if (!ResultArray.ContainsKey("Type")) { ResultArray.Add("Type", new List <string> { }); } if (!ResultArray.ContainsKey("Screen")) { ResultArray.Add("Screen", new List <string> { }); } if (!ResultArray.ContainsKey("Resolution")) { ResultArray.Add("Resolution", new List <string> { }); } List <string> idl = new List <string>(); List <string> typel = new List <string>(); List <string> screenl = new List <string>(); List <string> resolutionl = new List <string>(); var device = new Parameters.Windows.DISPLAY_DEVICE(); device.cb = Marshal.SizeOf(device); try { foreach (var screen in Screen.AllScreens) { for (uint id = 0; Parameters.Windows.EnumDisplayDevices(null, id, ref device, 0); id++) { device.cb = Marshal.SizeOf(device); Parameters.Windows.EnumDisplayDevices(device.DeviceName, 0, ref device, 0); device.cb = Marshal.SizeOf(device); if (device.DeviceName == null || device.DeviceName == "") { continue; } if (screen.Primary && device.DeviceName.Contains(screen.DeviceName)) { idl.Add(FuncClass.StringCut(device.DeviceID)); typel.Add(device.DeviceString); //resolutionl.Add($"{Screen.PrimaryScreen.Bounds.Width}x{Screen.PrimaryScreen.Bounds.Height}"); resolutionl.Add($"{Resolution_.DESKTOP.Width}x{Resolution_.DESKTOP.Height}"); screenl.Add("Primary"); } else if (!screen.Primary && device.DeviceName.Contains(screen.DeviceName)) { idl.Add(FuncClass.StringCut(device.DeviceID)); typel.Add(device.DeviceString); resolutionl.Add($"{screen.Bounds.Width}x{screen.Bounds.Height}"); screenl.Add("Secondary"); } } } ResultArray["ID"] = idl; ResultArray["Type"] = typel; ResultArray["Screen"] = screenl; ResultArray["Resolution"] = resolutionl; string dutSc = ""; string dyttype = ""; Console.WriteLine(idl.Count().ToString()); for (int i = 0; i < idl.Count(); i++) { if (idl[i] == (string)AnswerDic["DUTID"]) { dutSc = (string)AnswerDic["DUTID"]; Console.WriteLine("1:" + dutSc); dyttype = typel[i]; } } if (!string.IsNullOrEmpty(dutSc)) { if (dyttype == "一般 PnP 監視器" || dyttype == "Generic PnP Monitor") { ResultArray[Parameters.Status] = "Pass"; } else { ResultArray[Parameters.Status] = "Fail"; ResultArray[Parameters.Remark] = "Dut monitor is not generic PnP monitor "; } } else { ResultArray[Parameters.Status] = "Fail"; ResultArray[Parameters.Remark] = "No Dut monitor detection."; } } catch (Exception) { ResultArray[Parameters.Status] = "Fail"; ResultArray[Parameters.Remark] = "No monitor has been detective."; } }