Guest User

ImageSearch

a guest
Jun 21st, 2012
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.89 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9. using System.Runtime.InteropServices;
  10.  
  11.  
  12. namespace ImageSearch
  13. {
  14. public partial class Form1 : Form
  15. {
  16.  
  17.  
  18. [DllImport("user32.dll",CharSet=CharSet.Auto, CallingConvention=CallingConvention.StdCall)]
  19. public static extern void mouse_event(long dwFlags, long dx, long dy, long cButtons, long dwExtraInfo);
  20.  
  21. private const int MOUSEEVENTF_leFTDOWN = 0x02;
  22. private const int MOUSEEVENTF_LEFTUP = 0x04;
  23.  
  24. public Form1()
  25. {
  26. InitializeComponent();
  27.  
  28. }
  29. public void DoMouseClick()
  30. {
  31. for (int i = 0; i < 200; i++)
  32. {
  33. System.Threading.Thread.Sleep(1000);
  34. //Call the imported function with the cursor's current position
  35.  
  36.  
  37. mouse_event(MOUSEEVENTF_leFTDOWN | MOUSEEVENTF_LEFTUP, 0, 0, 1280, 1024);
  38. }
  39.  
  40. }
  41.  
  42.  
  43.  
  44.  
  45. private void button1_Click_1(object sender, EventArgs e)
  46. {
  47.  
  48. int[] img = IMGSearch.FindImage(0, 0, 1280, 1024, "C:\\s.bmp");
  49. if (img[0] != 0)
  50. {
  51.  
  52.  
  53. label1.Text = "OK!";
  54.  
  55.  
  56. }
  57. }
  58.  
  59. private void label1_Click(object sender, EventArgs e)
  60. {
  61.  
  62.  
  63. }
  64. public static class IMGSearch
  65. {
  66. //[DllImport("ImageSearchDLL.dll", EntryPoint="ImageSearch")]
  67. [DllImport("Boxy")]
  68. public static extern string ImageSearch(int x1, int y1, int x2, int y2, string str);
  69. /// <summary>
  70. /// The main entry point for the application.
  71. /// </summary>
  72. [STAThread]
  73. static void Main2()
  74. {
  75. Application.EnableVisualStyles();
  76. Application.SetCompatibleTextRenderingDefault(false);
  77. Application.Run(new Form1());
  78. }
  79.  
  80. public static int[] FindImage(int L, int T, int R, int B, string F)
  81. {
  82. int[] aRTN = new int[5];
  83.  
  84. //MessageBox.Show(R.ToString());
  85. string rtn = ImageSearch(L, T, R, B, F);
  86.  
  87. //MessageBox.Show(rtn);
  88.  
  89. if (rtn == "0")
  90. {
  91. aRTN[0] = 0;
  92. return aRTN;
  93. }
  94. else
  95. {
  96. string[] coords = rtn.Split('|'); //split return value of imagesearch into array
  97. //int[] aRTN = new int[5]; //declare int array with enough elements
  98. aRTN[0] = int.Parse(coords[0]); //convert the string values into ints
  99. aRTN[1] = int.Parse(coords[1]);
  100. aRTN[2] = int.Parse(coords[2]);
  101. aRTN[3] = int.Parse(coords[3]);
  102. aRTN[4] = int.Parse(coords[4]);
  103. return aRTN;
  104.  
  105. }
  106. }
  107. }
  108.  
  109.  
  110.  
  111. private void Form1_Load(object sender, EventArgs e)
  112. {
  113.  
  114. }
  115. }
  116. }
Add Comment
Please, Sign In to add comment