Пример #1
0
        public MacroForm()
        {
            Win32Locator.KickOffEnumWindows();
            InitializeComponent();
            this.TopMost = true;

            Field_Map.Add("<客户名称>", "Copy([Customer_Text])");
            Field_Map.Add("<油号>", "Set([Product_Code])");
            Field_Map.Add("<单价>", "Set([Product_Price])");
            Field_Map.Add("<总价>", "Set([Amount])");
            Field_Map.Add("<数量>", "Set([Product_Number])");
            Field_Map.Add("[点击]", "<Click>");
            foreach (String str in Field_Map.Keys)
            {
                cbContent.Items.Add(str);
            }

            main_wnd_rect.Bottom = main_wnd_rect.Left = main_wnd_rect.Top = main_wnd_rect.Right = 0;

            TbLogTrace log = new TbLogTrace(this);

            Trace.Listeners.Add(log);

            mouseHook.MouseMove += new MouseEventHandler(mouseHook_MouseMove);
            //mouseHook.MouseDown += new MouseEventHandler(mouseHook_MouseDown_RecFieldPos);
            //mouseHook.MouseUp += new MouseEventHandler(mouseHook_MouseUp);

            keyboardHook.KeyDown += new KeyEventHandler(keyboardHook_KeyDown);
            //keyboardHook.KeyUp += new KeyEventHandler(keyboardHook_KeyUp);

            read_config(cfg_file_name);
        }
Пример #2
0
        void keyboardHook_KeyDown(object sender, KeyEventArgs e)
        {
            if (capture_status == false)
            {
                this.recordStartButton.Enabled = true;
                return;
            }
            if (e.Control && e.KeyCode == Keys.F)
            {
                this.recordStartButton.Enabled = true;
                String position = String.Format("{0:d},{1:d}", cur_mouse_x, cur_mouse_y);
                this.lvFIelds.Items.Add(createListItem(cbContent.Text, position));
                capture_status = false;
                keyboardHook.Stop();
                mouseHook.Stop();
                Win32Locator.SetForeGWindow(this.Handle);
            }

            /*events.Add(
             *  new MacroEvent(
             *      MacroEventType.KeyDown,
             *      e,
             *      Environment.TickCount - lastTimeRecorded
             *  ));
             *
             * lastTimeRecorded = Environment.TickCount;*/
        }
 bool ShuiKongInterface.SendRecipt(CheRequest req)
 {
     if (anch_wnd_handle != IntPtr.Zero)
     {
         Win32Locator.SetForeGWindow(anch_wnd_handle);
         if (this.first_editor_wnd_str != null)
         {
             IntPtr f_e = Win32Locator.locateWindow(this.first_editor_wnd_str, GetWndClassPostFix());
             if (f_e != IntPtr.Zero)
             {
                 Win32Locator.SetForeGWindow(f_e);
                 //SetFocus(f_e); the method doesn't work
             }
             else
             {
                 Trace.WriteLineIf(Program.trace_sw.TraceError, "did not find the window");
             }
         }
         for (int i = 0; i < this.max_send_ops; i++)
         {
             String str = actions[i].getValue(req);
             SendKeys.Send(str);
         }
         return(true);
     }
     return(false);
 }
Пример #4
0
 private void btInfo_Click(object sender, EventArgs e)
 {
     tbLog.AppendText(CheDaoFactory.Dump() + Environment.NewLine);
     tbLog.AppendText(Win32Locator.Dump() + Environment.NewLine);
     tbLog.AppendText(Program.log.Dump() + Environment.NewLine);
     //tbLog.AppendText(ShuiKongFactory.Test() + Environment.NewLine);
 }
Пример #5
0
        public wndEnvCfg()
        {
            Win32Locator.KickOffEnumWindows();
            InitializeComponent();
            TbLogTrace log = new TbLogTrace(this);

            Trace.Listeners.Add(log);
            this.TopMost = true;
        }
        public bool DetectShuiKong()
        {
            IntPtr tmp = Win32Locator.locateWindow(anch_wnd_str, null);

            if (tmp != anch_wnd_handle)
            {
                anch_wnd_handle = tmp;
                AnchWndChangeEvt(tmp);
            }
            return(tmp != IntPtr.Zero);
        }
        bool ShuiKongInterface.DetectShuiKong()
        {
            IntPtr tmp = anch_wnd_handle;

            anch_wnd_handle = Win32Locator.locateWindow(anch_wnd_str, null);
            if (tmp != anch_wnd_handle)
            {
                Trace.WriteLineIf(Program.trace_sw.TraceVerbose, String.Format("locate {0:s} at {1:X00000}", anch_wnd_str, anch_wnd_handle));
                AnchWndChangeEvt(anch_wnd_handle);
            }
            //Trace.WriteLineIf(Program.trace_sw.TraceInfo, String.Format("locate {0:s} at {1:X00000}", anch_wnd_str, anch_wnd_handle));
            return(anch_wnd_handle != IntPtr.Zero);
        }
Пример #8
0
        private void btCapture_Click(object sender, EventArgs e)
        {
            Bitmap bp = Win32Locator.CaptureScreen();

            if (bp != null)
            {
                try
                {
                    bp.Save("shuikong-screen.jpg", ImageFormat.Jpeg);
                    MessageBox.Show("屏幕信息保存在 shuikong-screen.jpg, 请发送给技术部门分析");
                }
                catch (Exception ex) {
                    MessageBox.Show("保存失败 " + ex.Message);
                }
            }
        }
Пример #9
0
 private void cbMainWnd_Click(object sender, EventArgs e)
 {
     cbMainWnd.Items.Clear();
     if (cbMainWnd.Items.Count == 0)
     {
         List <String> wnds = Win32Locator.GetWindows();
         foreach (String str in wnds)
         {
             if (str.Trim() != "" && Win32Locator.HasChinese(str))
             {
                 cbMainWnd.Items.Add(str);
             }
         }
     }
     Win32Locator.KickOffEnumWindows();
 }
        public String TestLocationFunction()
        {
            String res = "Test:\n Detect " + anch_wnd_str + "\n";

            ((ShuiKongInterface)this).DetectShuiKong();
            res += Win32Locator.Dump() + Environment.NewLine;
            foreach (String wnd_str in mFieldMap.Keys)
            {
                String fix = GetWndClassPostFix() != null?GetWndClassPostFix() : "";

                res += "Find " + wnd_str + " with postfix " + fix + Environment.NewLine;
                Win32Locator.locateWindow(wnd_str, GetWndClassPostFix());
                res += Win32Locator.Dump();
            }
            return(res);
        }
        String ShuiKongInterface.TestLocationFunction()
        {
            String res = "Test:\n Detect " + anch_wnd_str + "\n";

            ((ShuiKongInterface)this).DetectShuiKong();
            res += Win32Locator.Dump() + Environment.NewLine;
            if (this.first_editor_wnd_str != null)
            {
                String fix = GetWndClassPostFix() != null?GetWndClassPostFix() : "";

                res += "find 1st Editor " + this.first_editor_wnd_str + "with postfix " + fix + Environment.NewLine;
                Win32Locator.locateWindow(this.first_editor_wnd_str, GetWndClassPostFix());
                res += Win32Locator.Dump();
            }
            return(res);
        }
        public bool SendRecipt(CheRequest req)
        {
            Boolean res = false;
            IntPtr  wnd_ptr;

            if (anch_wnd_handle != null)
            {
                Win32Locator.SetForeGWindow(anch_wnd_handle);
            }
            else
            {
                return(false);
            }
            foreach (String wnd_str in mFieldMap.Keys)
            {
                res = false;
                if (wnd_str != null)
                {
                    wnd_ptr = Win32Locator.locateWindow(wnd_str, GetWndClassPostFix());
                    if (wnd_ptr == null)
                    {
                        break;
                    }
                    String text = mFieldMap[wnd_str].GetValue(req, null).ToString();
                    try
                    {
                        SendMessage(wnd_ptr, WM_SETTEXT, IntPtr.Zero, text);
                        int r = Marshal.GetLastWin32Error();
                        if (r != 0)
                        {
                            Trace.WriteLineIf(Program.trace_sw.TraceError, String.Format("sendmessage with error code:{0:d}", res), "error");
                            break;
                        }
                    }
                    catch (Exception e)
                    {
                        Trace.WriteLineIf(Program.trace_sw.TraceError, "Send Text Failed with " + e.ToString(), "error");
                        break;
                    }
                }
                res = true;
            }
            return(res);
        }
Пример #13
0
 private void btLocateWnd_Click(object sender, EventArgs e)
 {
     if (cbMainWnd.Text.Trim().Length > 0)
     {
         IntPtr wnd = Win32Locator.locateWindow(String.Format("S({0:S})[0]", cbMainWnd.Text.Trim()), null);
         if (wnd == IntPtr.Zero)
         {
             main_wnd_str = null;
             MessageBox.Show(String.Format("定位窗口 {0:s} 失败", cbMainWnd.Text.Trim()));
             lbLayout.Text = "...";
             return;
         }
         main_wnd_str = cbMainWnd.Text.Trim();
         Win32Locator.SetForeGWindow(wnd);
         main_wnd_rect = Win32Locator.centerWindow(wnd);
         lbLayout.Text = String.Format("屏幕:{0:d}X{1:d},窗口({2:d},{3:d},{4:d},{5:d})", Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height,
                                       main_wnd_rect.Left, main_wnd_rect.Top, main_wnd_rect.Right, main_wnd_rect.Bottom);
         Trace.WriteLine(String.Format("Locate the Wnd at center"));
     }
 }
Пример #14
0
        private Boolean collectWndEnv(string v)
        {
            IntPtr wnd = Win32Locator.locateWindow(String.Format("S({0:S})[0]", v), null);

            if (wnd == IntPtr.Zero)
            {
                MessageBox.Show(String.Format("定位窗口 {0:s} 失败", v));
                return(false);
            }
            try
            {
                String fn = "shuikong-screen.jpg";
                Win32Locator.SetForeGWindow(wnd);
                Win32Locator.centerWindow(wnd);
                Bitmap       pic     = Win32Locator.CaptureScreen();
                MemoryStream mStream = new MemoryStream();
                pic.Save(mStream, ImageFormat.Jpeg);
                WebClient w_cli = new WebClient();
                String    url   = string.Format("{0:s}log?client_id={1:s}&name={2:d}", ConfigurationManager.AppSettings["service_url"], Program.mAppCode, fn);
                w_cli.UploadData(new Uri(url), mStream.ToArray());
                MessageBox.Show("上载文件成功,请联系技术支持生成配置文件");
            }
            catch (IOException e)
            {
                MessageBox.Show("写文件错误,请检查磁盘空间");
                return(false);
            }
            catch (WebException e)
            {
                MessageBox.Show("上载文件失败,请联系技术支持");
                return(false);
            }
            catch (Exception e) {
                MessageBox.Show("系统异常");
                return(false);
            }
            return(true);
        }