private void timerAutoClick_Tick(object sender, EventArgs e)
{
// セキュリティダイアログの座標を取得
IntPtr dialog = FindWindow("#32770", "Microsoft Office Outlook");
Rect dialogRect = new Rect();
GetWindowRect(dialog, ref dialogRect);
toolStripStatusLabel1.Text = "LEFT:" + dialogRect.Left + " TOP:" + dialogRect.Top + " RIGHT:"+dialogRect.Right + " BOTTOM:"+dialogRect.Bottom;
// 座標が0,0であれば、ダイアログは出ていないと考えられるので、処理を終了。
if (dialogRect.Right == 0 && dialogRect.Bottom == 0)
{
if (lblStatus.Text != messageKanshichu)
{
lblStatus.Text = messageKanshichu;
this.BackColor = Color.White;
}
return;
}
lblStatus.Text = "ダイアログ発見\r\nクリック中!";
this.BackColor = Color.Yellow;
// Outlookをアクティブにする
activateOutlook();
dialogLeft = dialogRect.Left;
dialogTop = dialogRect.Top;
timerDelayClick.Start();
}
void activateOutlook()
{
try
{
/*
// VisualBasic.dll
System.Diagnostics.Process[] ps = System.Diagnostics.Process.GetProcessesByName("Outlook");
if (0 < ps.Length)
{
Microsoft.VisualBasic.Interaction.AppActivate(ps[0].Id);
}
*/
//user32.dll
foreach (System.Diagnostics.Process p
in System.Diagnostics.Process.GetProcesses())
{
//"Outlook"がメインウィンドウのタイトルに含まれているか調べる
if (0 <= p.MainWindowTitle.IndexOf("Outlook"))
{
//ウィンドウをアクティブにする
SetForegroundWindow(p.MainWindowHandle);
break;
}
}
}
catch (Exception ex)
{
}
}
//クリックする処理
void doClick()
{
int MOUSEEVENTF_LEFTDOWN = 0x2;
int MOUSEEVENTF_LEFTUP = 0x4;
mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
}
//カーソルを移動させる処理
void setPoint(int newX, int newY)
{
System.Windows.Forms.Cursor.Position = new System.Drawing.Point(newX, newY);
}
private void timerDelayClick_Tick(object sender, EventArgs e)
{
setPoint(dialogLeft + 116, dialogTop + 156);
doClick();
doClick();
timerDelayClick.Stop();
}