using System; using System.Drawing; using Arp.Prova.ImageLibrary; using Arp.Prova.CsvLib; using Arp.Prova.PlayLib; // CodeClass public class CodeClass { public static int CodeStart() { //---------------------------------プリンターとスキャナーの設定サンプル--------------------------------- //こちらのサンプルは、「デバイス」設定の「プリンターとスキャナー」画面にて既定のプリンターの設定を行います。 //設定値などは、設定したい内容に変更の上お試しください。 //--------------------設定開始-------------------- //■「プリンターとスキャナー」画面を表示 PlayLib.ProcessStart("ms-settings:printers"); //■「設定」画面が開くまで待つ if(PlayLib.WaitWindow("設定", true, 10)) { PlayLib.Window("設定").Activate(); //「設定」画面を前面に表示 PlayLib.Sleep(1000); //画面内の描画は終わるまで少し待つ //操作しやすいよう設定画面を最大化する if(PlayLib.Window("設定").WaitUIControl("UIButton", "設定 を最大化する", true, 2)) { PlayLib.Window("設定").UIButton("設定 を最大化する").Click(); PlayLib.Sleep(1000); } //■「Windows で通常使うプリンターを管理する」:オフ for(int i = 1; i < 5; i++) { if(PlayLib.Window("設定").UICheckBox("*&" + i).Text == "Windows で通常使うプリンターを管理する") { //「従量制課金接続でのダウンロード」:オンだった場合、オフにする PlayLib.Window("設定").UICheckBox("*&" + i).Uncheck(); PlayLib.Sleep(1000); break; } } //「Microsoft Print to PDF 既定」が存在しているか確認する if((bool)PlayLib.Window("設定").UIListBox("プリンターとスキャナー").GetItemProperty("exists", "Microsoft Print to PDF 既定") == true) { //存在していた場合 PlayLib.TestLog("「Microsoft Print to PDF」はすでに既定のプリンターとして設定されています"); return -1; } //「Microsoft Print to PDF」が存在しているか確認する if((bool)PlayLib.Window("設定").UIListBox("プリンターとスキャナー").GetItemProperty("exists", "Microsoft Print to PDF") == false) { //存在していなかった場合 PlayLib.TestLogError("「Microsoft Print to PDF」が存在していません"); return -1; } //「Microsoft Print to PDF」を選択する PlayLib.Window("設定").UIListBox("プリンターとスキャナー").Select("Microsoft Print to PDF"); PlayLib.Sleep(1000); //「管理」ボタンをクリックする PlayLib.Window("設定").UIButton("管理").Click(); PlayLib.Sleep(1000); for(int i = 1; i < 10; i++) { //「アイドル」を含んだ文字列を探す //(プリンターのインク残量によってはプリンターの状態が「アイドル」→「アイドル, トナー/インク残量: 少」になる) if(PlayLib.Window("設定").UIStatic("UIStatic&" + i).Text.Contains("アイドル") == true) { //「既定として設定する」をクリックする PlayLib.Window("設定").UIButton("既定として設定する").Click(); PlayLib.Sleep(1000); //「既定」を含んだ文字列に変更されたか確認する if(PlayLib.Window("設定").UIStatic("UIStatic&" + i).Text.Contains("既定") == false) { PlayLib.TestLogError("「Microsoft Print to PDF」を既定のプリンターとして設定できませんでした"); return -1; } break; } } //■「設定」画面を閉じる PlayLib.Window("設定").Close(); } else //「プリンターとスキャナー」画面が開かなかった場合 { PlayLib.TestLogError("「プリンターとスキャナー」画面が開きませんでした"); return -1; } return 0; } }