private void CaptureEvent(object sender, EventArgs e) //타이머 이벤트 { logger.Info("Cpature Macro Start"); Bitmap capturedImg = captureBoxForm.CaptureImg(); logger.Info("Image Captured"); BitmapStatus status = ProofBitmap(prevBmap, capturedImg); if (status == BitmapStatus.Defalt || status == BitmapStatus.Normal) { //string fileName = DateTime.Now.ToString("yyyyMMddHHmmssffffff") + ".jpg"; //capturedImg.Save(TxtSaveFolder.Text + @"\" + fileName, ImageFormat.Jpeg); //logger.Info("Image File Name : " + fileName); //logger.Info("Image Complete"); MemoryStream stream = new MemoryStream(); capturedImg.Save(stream, ImageFormat.Bmp); pdfMaker.AddPdfPage(stream.ToArray()); logger.Info("A page add to pdf file"); PbCapturedImg.Image = capturedImg; logger.Info("Set a Thumbnail"); timerCount++; TxtRepeatCnt.Text = timerCount.ToString(); logger.Info("Page Count : " + timerCount.ToString()); PgbMacro.PerformStep(); prevBmap = capturedImg; } else if (status == BitmapStatus.Duplicate || status == BitmapStatus.Empty || status == BitmapStatus.CurImgVacant) // 중복이거나 내용이 없을 경우, 캡쳐한 이미지가 null 일경우 건너뜀 { logger.Warn("Capture Process Skiped / Skiped by : " + status.ToString()); logger.Info("Retry to capture / try to act macro"); ProcessSwiching.Swiching(targetWindowHandle); logger.Info("ProcessSwiching Complete"); SystemFunction.VKeyPress(TxtKeyValue.Text); logger.Info("Macro Key Pressed"); return; } else { logger.Error("Image Capture Macro Error / Bitmap Status : " + status.ToString()); MacroTimerStop(); } if (timerCount >= Int32.Parse(TxtRepeatTime.Text)) // 정해진 카운트를 채웠을 경우 종료 { MacroTimerStop(); logger.Info("Timer Event End"); } else { ProcessSwiching.Swiching(targetWindowHandle); logger.Info("ProcessSwiching Complete"); SystemFunction.VKeyPress(TxtKeyValue.Text); logger.Info("Macro Key Pressed"); } }
public void MacroTimerStart() { //if (captureTargetSet == true && TxtRepeatTime.Text != null && TxtSaveFolder.Text != null && TxtCaptureProgram != null && Int32.Parse(targetWindowPID) > 0) if (captureTargetSet == true && TxtRepeatTime.Text != String.Empty && TxtSaveFolder.Text != String.Empty && TxtDelayTime.Text != String.Empty && TxtKeyValue.Text != String.Empty && TxtCaptureProgram.Text != String.Empty) { captureBoxForm = new CaptureBoxForm(); captureBoxForm.Show(); captureBoxForm.Left = captureTarget.Left; captureBoxForm.Top = captureTarget.Top; captureBoxForm.Size = captureTarget.Size; captureBoxForm.FormBorderStyle = FormBorderStyle.None; captureBoxForm.BackColor = Color.Red; captureBoxForm.TransparencyKey = Color.Violet; Panel formCaptureBox = captureBoxForm.GetCaptureBox(); formCaptureBox.BackColor = captureBoxForm.TransparencyKey; formCaptureBox.Location = new Point(1, 1); formCaptureBox.Size = new Size(captureBoxForm.Width - 2, captureBoxForm.Height - 2); formCaptureBox.Visible = true; macroTimer = new System.Windows.Forms.Timer(); macroTimer.Interval = Int32.Parse(TxtDelayTime.Text); macroTimer.Tick += new EventHandler(CaptureEvent); BtnStart.BackColor = Color.Aquamarine; pdfMaker = new PdfMaker(TxtSaveFolder.Text); ProcessSwiching.Swiching(targetWindowHandle); logger.Info("ProcessSwiching Complete"); captureMacroStart = true; PgbMacro.Value = 0; PgbMacro.Maximum = Int32.Parse(TxtRepeatTime.Text); macroTimer.Start(); } else { if (captureTargetSet == false) { MessageBox.Show("지정된 영역이 없습니다.", "정보부족", MessageBoxButtons.OK, MessageBoxIcon.Error); } else if (TxtSaveFolder.Text == String.Empty) { MessageBox.Show("폴더가 지정되지 않았습니다.", "정보부족", MessageBoxButtons.OK, MessageBoxIcon.Error); } else if (TxtDelayTime.Text == String.Empty) { MessageBox.Show("지연시간이 정의되지 않았습니다.", "정보부족", MessageBoxButtons.OK, MessageBoxIcon.Error); } else if (TxtRepeatTime.Text == String.Empty) { MessageBox.Show("반복횟수가 정의되지 않았습니다.", "정보부족", MessageBoxButtons.OK, MessageBoxIcon.Error); } else if (TxtKeyValue.Text == String.Empty) { MessageBox.Show("매크로 키가 정의되지 않았습니다.", "정보부족", MessageBoxButtons.OK, MessageBoxIcon.Error); } else if (TxtCaptureProgram.Text == String.Empty) { MessageBox.Show("캡처대상 윈도우가 선택되지 않았습니다.", "정보부족", MessageBoxButtons.OK, MessageBoxIcon.Error); } //if (Int32.Parse(targetWindowPID) <= 0) //{ // MessageBox.Show("캡처대상 윈도우가 선택되지 않았습니다.", "정보부족", MessageBoxButtons.OK, MessageBoxIcon.Error); //} else { MessageBox.Show("매크로를 실행할 수 없습니다.", "실행불가", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }