예제 #1
0
        //internal Window FindChildWindow(string v1)
        //{
        //    int iCount = 0;
        //    while (iCount < 100)
        //    {
        //        WinTree winTree = GetWindowTree();
        //        IntPtr hWnd  = winTree.Find(v1);
        //        if (hWnd != IntPtr.Zero)
        //        {
        //            Window findWindow = (Window)Activator.CreateInstance(typeof(Window), hWnd, v1);
        //            Log.INFO(string.Format("Finded chid Window:[{0},{1}], in process:[{2}]", findWindow._name, findWindow._hWnd.ToString("X8"), _process.Id));
        //            return findWindow;
        //        }

        //        iCount++;

        //        Thread.Sleep(200);
        //    }

        //    throw new ArgumentException(string.Format("can not find child window:[{0}], in process:[{1}]", v1, _process.Id));
        //}

        internal void FindChildWindow(string v1, Action <Window> actionNomarl, string v2, Action <Window> actionException)
        {
            int iCount = 0;

            while (iCount < 100)
            {
                WinTree winTree = GetWindowTree();
                IntPtr  hWnd    = winTree.Find(v2);
                if (hWnd != IntPtr.Zero && WinAPI.IsWindowEnabled(hWnd))
                {
                    Window findWindow = (Window)Activator.CreateInstance(typeof(Window), hWnd, v2);
                    Log.INFO(string.Format("Finded chid Window:[{0},{1}], in process:[{2}]", findWindow._name, findWindow._hWnd.ToString("X8"), _process.Id));

                    actionException(findWindow);
                    return;
                }

                hWnd = winTree.Find(v1);
                if (hWnd != IntPtr.Zero && WinAPI.IsWindowEnabled(hWnd))
                {
                    Window findWindow = (Window)Activator.CreateInstance(typeof(Window), hWnd, v1);
                    Log.INFO(string.Format("Finded chid Window:[{0},{1}], in process:[{2}]", findWindow._name, findWindow._hWnd.ToString("X8"), _process.Id));

                    actionNomarl(findWindow);
                    return;
                }

                iCount++;

                Thread.Sleep(200);
            }

            throw new ArgumentException(string.Format("can not find child window:[{0}], in process:[{1}]", v1 + "," + v2, _process.Id));
        }
예제 #2
0
        public void SetCheckFlag(bool isChecked)
        {
            while (!WinAPI.IsWindowEnabled(_hWnd))
            {
                Thread.Sleep(200);
            }

            Log.INFO(string.Format("Set Checkbox:[{0}], value{1}, hWnd[{2},{3}]", _Text, isChecked, _hWnd.ToString("X8"), _hWndWin.ToString("X8")));
            WinAPI.SetActiveWindow(_hWndWin);
            WinAPI.SetFocus(_hWnd);

            IntPtr lparam = IntPtr.Zero;

            if (isChecked)
            {
                lparam = (IntPtr)0;
            }
            else
            {
                lparam = (IntPtr)1;
            }

            WinAPI.PostMessage(_hWnd, (int)WinAPI.ButtonMessages.BM_SETCHECK, lparam, (IntPtr)0);

            Thread.Sleep(1000);
        }
예제 #3
0
파일: Button.cs 프로젝트: yxw027/AutoIECalc
        public void Click(int time = 1000)
        {
            while (!WinAPI.IsWindowEnabled(_hWnd))
            {
                Thread.Sleep(200);
            }

            Log.INFO(string.Format("Click Button:[{0}], hWnd[{1},{2}]", _Text, _hWnd.ToString("X8"), _hWndWin.ToString("X8")));
            WinAPI.SetActiveWindow(_hWndWin);
            WinAPI.SetFocus(_hWnd);

            //WinAPI.SendMessage(_hWnd, (int)WinAPI.ButtonMessages.BM_CLICK, (IntPtr)0, (IntPtr)0);

            WinAPI.PostMessage(_hWnd, (int)WinAPI.WMMessage.WM_LBUTTONDOWN, (IntPtr)1, (IntPtr)0);
            WinAPI.PostMessage(_hWnd, (int)WinAPI.WMMessage.WM_LBUTTONUP, (IntPtr)1, (IntPtr)0);


            Thread.Sleep(time);

            //WinAPI.PostMessage
        }