using System; using Arp.Prova.PlayLib; using System.IO; using System.Windows.Forms; // ↓今回作成した画像比較ライブラリをロードします using Arp.Prova.ImageLibrary; // ↓Point型で使用します using System.Drawing; // CodeClass public class CodeClass { // exeと同じ階層に「Image」フォルダーを配置し、そのパスを「ButtonImagePath1」「ButtonImagePath2」に格納 static string ButtonImagePath1 = Path.Combine(Path.GetDirectoryName(Application.StartupPath)) + @"\Image\MaximizeButton.PNG"; static string ButtonImagePath2 = Path.Combine(Path.GetDirectoryName(Application.StartupPath)) + @"\Image\Close.PNG"; public static int CodeStart() { // メモ帳を開く PlayLib.ProcessStart("notepad.exe"); // 1秒待機 PlayLib.Sleep(1000); // ↓開いたメモ帳の最大化ボタンの座標をPoint型で取得します。 Point pt; //bool ret1 = ImageLibrary.GetPoint(String.Empty, ButtonImagePath1, 1, ImageLibrary.SearchArea.ALL, 0.6, out pt); bool ret1 = ImageLibrary.GetPoint(String.Empty, ButtonImagePath1, out pt); PlayLib.TestLog(ret1); PlayLib.CheckValue(ret1, true, true); //取得した座標をクリックしてメモ帳を最大化します。 //Window名に"Program Manager"を指定することでディスプレイ全体を見たときの座標をクリックします。 PlayLib.Window("Program Manager").Click(pt.X, pt.Y); // 1秒待機 PlayLib.Sleep(1000); // 画面全体(デスクトップ全体)からメモ帳の閉じるボタンを検索します。 bool ret2 = ImageLibrary.Search(String.Empty, ButtonImagePath2, 1, ImageLibrary.SearchArea.ALL, 0.6); PlayLib.CheckValue(ret2, true, true); // 1秒待機 PlayLib.Sleep(1000); // ↓閉じるボタンクリックで開いたメモ帳を閉じます。 bool ret3 = ImageLibrary.Click(String.Empty, ButtonImagePath2, 1, ImageLibrary.SearchArea.ALL, 0.6); PlayLib.CheckValue(ret3, true, true); // 1秒待機 PlayLib.Sleep(1000); return 0; } }