public static string GenerateDlgBaseName(SUIDialog suiDlg) { string Name = "NoTitleDialog"; if (!suiDlg.WindowText.Equals(string.Empty)) { Name = suiDlg.WindowText.Replace(" ", "") + "_Dialog"; } return Name; }
public static string GenerateDlgGUID(SUIDialog sui) { string DlgGUID = "NoItem"; SUIWindow firstChild = null; IntPtr ptr = SUIWinAPIs.GetWindow(sui.WindowHandle, 5); if (IntPtr.Zero.Equals(ptr)) return DlgGUID; firstChild = new SUIWindow(ptr); if (firstChild != null) { DlgGUID = firstChild.ClassName.Trim() + (uint)firstChild.WindowID + (firstChild.Width - firstChild.X); } return DlgGUID; }
public void Add(SUIDialog dialog) { this.InnerList.Add(dialog); }
public bool CompareWindowImage(SUIWindow window, SUIBitmap baseImage) { SUIBitmap windowImage = SUIImage.GetImageFromWindow(window); windowImage.Path = baseImage.Path; //2007 5-24 fhu add this line. if (baseImage.IsNullBitmap) { if (!windowImage.IsNullBitmap) { windowImage.Path = baseImage.Path; windowImage.Save(); windowImage.ReleaseMem(); return true; } } //Here's the Vista specific image comparison. // Both dialog and winform need to apply this algorithm. if ((SUIUtil.IsCurrentOSVista || SUIUtil.IsCurrentOSXP) && (window.IsDialog || window.IsWinForm)) { SUIDialog dialog = new SUIDialog(window); SUIButton defaultButton = dialog.DefaultPushButton; if (defaultButton == null) return SUIComparer.GetComparer(ComparerType.Image).Compare(baseImage,windowImage); else { Bitmap bmBase = baseImage.Bitmap; Bitmap bmTest = windowImage.Bitmap; int base_width = bmBase.Width; int base_height = bmBase.Height; int test_width = bmTest.Width; int test_height = bmTest.Height; //First of all, compare the size of images. if ((base_width != test_width) || (base_height != test_height)) { windowImage.Path = baseImage.Path.Replace(".bmp", "_error.bmp"); windowImage.Save(); windowImage.ReleaseMem(); return false; } //Retrieve button area. Rectangle defaultButtonRectangle = new Rectangle(); defaultButtonRectangle.X = defaultButton.X - dialog.X; defaultButtonRectangle.Y = defaultButton.Y - dialog.Y; defaultButtonRectangle.Width = defaultButton.Width - defaultButton.X; defaultButtonRectangle.Height = defaultButton.Height - defaultButton.Y; // Ignor the comparison of a 4-pixel width border so that we could // get rid of the side effect of dash-line rectangle on the button. Rectangle defaultButtonRectangleEx = new Rectangle(); defaultButtonRectangleEx.X = defaultButtonRectangle.X + 4; defaultButtonRectangleEx.Y = defaultButtonRectangle.Y + 4; defaultButtonRectangleEx.Width = defaultButtonRectangle.Width - 8; defaultButtonRectangleEx.Height = defaultButtonRectangle.Height - 8; //Ignor the effect of flatness under vista Rectangle flatnessRectangle1 = new Rectangle(); flatnessRectangle1.X = 0; flatnessRectangle1.Y = 0; flatnessRectangle1.Width = 6; flatnessRectangle1.Height = 6; Rectangle flatnessRectangle2 = new Rectangle(); flatnessRectangle2.X = dialog.Width - dialog.X - 6; flatnessRectangle2.Y = 0; flatnessRectangle2.Width = 6; flatnessRectangle2.Height = 6; Rectangle[] FlatnessAreas = new Rectangle[2]; FlatnessAreas[0] = flatnessRectangle1; FlatnessAreas[1] = flatnessRectangle2; Bitmap difference = new Bitmap(base_width, base_height); bool bChange = false; int i, j; Color pixBase; Color pixTest; for (i = 0; i < base_width; i++) { for (j = 0; j < base_height; j++) { pixBase = bmBase.GetPixel(i, j); pixTest = bmTest.GetPixel(i, j); Point temp = new Point(i, j); if (IsContainsPoint(FlatnessAreas,temp)) { //difference.SetPixel(i, j, Color.White); continue; } if (!defaultButtonRectangle.Contains(temp)) { if (!colorComparer.Compare(pixBase, pixTest)) { bChange = true; difference.SetPixel(i, j, Color.Black); } else difference.SetPixel(i, j, Color.White); } else if (!defaultButtonRectangleEx.Contains(temp)) { // Ignor the pixels in this border. //difference.SetPixel(i, j, Color.Orange); } else //Process the pixels in OK button rectangle { if (!colorComparer.Compare(pixBase, pixTest)) { int defaultBuffer = SUIColorComparer.buffer; //Temproraly set buffer to 150 since in this special area we need a larger buffer. SUIColorComparer.buffer = 150; if (colorComparer.Compare(pixBase, SystemColors.ControlText) || colorComparer.Compare(pixTest, SystemColors.ControlText)) { bChange = true; difference.SetPixel(i, j, Color.Black); } //else // difference.SetPixel(i, j, Color.Blue); // Set the default buffer back. SUIColorComparer.buffer = defaultBuffer; } //else // difference.SetPixel(i, j, Color.Red); } } } if (bChange) { windowImage.Path = baseImage.Path.Replace(".bmp", "_error.bmp"); windowImage.Save(); windowImage.ReleaseMem(); baseImage.ReleaseMem(); string path = baseImage.Path.Replace(".bmp", "_error_difference.bmp"); difference.Save(path); difference.Dispose(); return false; } else { windowImage.ReleaseMem(); baseImage.ReleaseMem(); difference.Dispose(); return true; } } } else return SUIComparer.GetComparer(ComparerType.Image).Compare(baseImage, windowImage); }