Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Windows.Forms;
- using System.Runtime.InteropServices;
- namespace ImageSearch
- {
- public partial class Form1 : Form
- {
- [DllImport("user32.dll",CharSet=CharSet.Auto, CallingConvention=CallingConvention.StdCall)]
- public static extern void mouse_event(long dwFlags, long dx, long dy, long cButtons, long dwExtraInfo);
- private const int MOUSEEVENTF_leFTDOWN = 0x02;
- private const int MOUSEEVENTF_LEFTUP = 0x04;
- public Form1()
- {
- InitializeComponent();
- }
- public void DoMouseClick()
- {
- for (int i = 0; i < 200; i++)
- {
- System.Threading.Thread.Sleep(1000);
- //Call the imported function with the cursor's current position
- mouse_event(MOUSEEVENTF_leFTDOWN | MOUSEEVENTF_LEFTUP, 0, 0, 1280, 1024);
- }
- }
- private void button1_Click_1(object sender, EventArgs e)
- {
- int[] img = IMGSearch.FindImage(0, 0, 1280, 1024, "C:\\s.bmp");
- if (img[0] != 0)
- {
- label1.Text = "OK!";
- }
- }
- private void label1_Click(object sender, EventArgs e)
- {
- }
- public static class IMGSearch
- {
- //[DllImport("ImageSearchDLL.dll", EntryPoint="ImageSearch")]
- [DllImport("Boxy")]
- public static extern string ImageSearch(int x1, int y1, int x2, int y2, string str);
- /// <summary>
- /// The main entry point for the application.
- /// </summary>
- [STAThread]
- static void Main2()
- {
- Application.EnableVisualStyles();
- Application.SetCompatibleTextRenderingDefault(false);
- Application.Run(new Form1());
- }
- public static int[] FindImage(int L, int T, int R, int B, string F)
- {
- int[] aRTN = new int[5];
- //MessageBox.Show(R.ToString());
- string rtn = ImageSearch(L, T, R, B, F);
- //MessageBox.Show(rtn);
- if (rtn == "0")
- {
- aRTN[0] = 0;
- return aRTN;
- }
- else
- {
- string[] coords = rtn.Split('|'); //split return value of imagesearch into array
- //int[] aRTN = new int[5]; //declare int array with enough elements
- aRTN[0] = int.Parse(coords[0]); //convert the string values into ints
- aRTN[1] = int.Parse(coords[1]);
- aRTN[2] = int.Parse(coords[2]);
- aRTN[3] = int.Parse(coords[3]);
- aRTN[4] = int.Parse(coords[4]);
- return aRTN;
- }
- }
- }
- private void Form1_Load(object sender, EventArgs e)
- {
- }
- }
- }
Add Comment
Please, Sign In to add comment