예제 #1
0
        //根据类名获取句柄
        public IntPtr GetWindowHandlebyClass(String Class)
        {
            bool      flg_success = false;
            string    tmp;
            AccessWin aw = new AccessWin();

            aw.windowsTree = aw.ListWindow((IntPtr)0);
            int i;

            for (i = 0; i < aw.windowsTree.WindowCount; i++)
            {
                tmp = "";
                if (aw.windowsTree.winfos[i].classname.Length >= Class.Length)
                {
                    tmp = aw.windowsTree.winfos[i].classname.Substring(0, Class.Length); //prevent string too short to be cut
                    if (Class == tmp)
                    {
                        break;
                    }
                }
            }
            if (i >= aw.windowsTree.WindowCount)   //can't find Top window
            {
                flg_success = false;
                if (flg_success == false)
                {
                    return(new IntPtr(-1));
                }
            }
            int    currWindowNO = i;
            IntPtr currWnd      = aw.windowsTree.winfos[currWindowNO].hwnd;

            return(currWnd);
        }
예제 #2
0
        private void btn_ClickPos_Click(object sender, EventArgs e)
        {
            AccessWin aw = new AccessWin();

            //0,0的话单击当前位置
            aw.ClickLocation(Convert.ToInt32(txt_posX.Text), Convert.ToInt32(txt_posY.Text));
        }
예제 #3
0
        private void btn_GetTXT_Click(object sender, EventArgs e)
        {
            AccessWin aw      = new AccessWin();
            IntPtr    vHandle = new IntPtr(Convert.ToInt32(txt_SelectedCell.Text, 16));

            txt_GetTXT.Text = aw.GetText(vHandle);
        }
예제 #4
0
        private void btn_GetHandleByChild_Click(object sender, EventArgs e)
        {
            AccessWin aw           = new AccessWin();
            IntPtr    pt           = new IntPtr(Convert.ToInt32(txt_SelectedCell.Text, 16));
            IntPtr    parentHandle = NativeMethods.GetParent(pt);

            txtParentHandle1.Text = parentHandle.ToString("X");
        }
예제 #5
0
        private void btn_KeyDown_Click(object sender, EventArgs e)
        {
            AccessWin aw      = new AccessWin();
            IntPtr    handle  = new IntPtr(Convert.ToInt32(txt_SelectedCell.Text, 16));
            int       keycode = Convert.ToInt32(txt_KeyDownCode.Text, 16);

            NativeMethods.SendMessageW(handle, NativeMethods.WM_KEYDOWN, (uint)keycode, 0x1c0001);
        }
예제 #6
0
        private void btn_GetGridContent_Click(object sender, EventArgs e)
        {
            AccessWin aw      = new AccessWin();
            IntPtr    vHandle = new IntPtr(Convert.ToInt32(txt_SelectedCell.Text, 16));
            DataTable dt      = aw.GetListViewContent(vHandle);

            dgv_Listview.DataSource = dt;
        }
예제 #7
0
        private void btn_SendSpace_Click(object sender, EventArgs e)
        {
            try
            {
                AccessWin aw     = new AccessWin();
                IntPtr    handle = new IntPtr(Convert.ToInt32(txt_SelectedCell.Text, 16));
                NativeMethods.SendMessageW(handle, NativeMethods.WM_KEYDOWN, 0x20, 0);
            }
            catch

            { }
        }
예제 #8
0
        private void btn_GetBrotherWindowTree_Click(object sender, EventArgs e)
        {
            AccessWin aw = new AccessWin();

            AccessWin.WindowsTree wt = new AccessWin.WindowsTree();
            IntPtr pt = new IntPtr(Convert.ToInt32(txt_SelectedCell.Text, 16));

            txt_handle.Text = pt.ToString("X");  //display the handle in textbox
            //IntPtr vHandle = new IntPtr(Convert.ToInt32(txt_ListHandle.Text, 16));

            dgv_child.DataSource = aw.ListBrotherWindow(pt).toDatatable();
        }
예제 #9
0
        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                AccessWin aw = new AccessWin();

                aw.ClickLocation(Convert.ToInt32(txt_posX.Text), Convert.ToInt32(txt_posY.Text));
                System.Windows.Forms.SendKeys.Send(txt_keytoPos.Text);
                System.Windows.Forms.SendKeys.Send("{ENTER}");
            }
            catch
            { }
        }
예제 #10
0
        private void btn_ClickPOSs_Click(object sender, EventArgs e)
        {
            DataTable dt_Pos = new DataTable("POS");

            dt_Pos.Columns.Add("X");
            dt_Pos.Columns.Add("Y");
            dt_Pos.Rows.Add(100, 100);
            dt_Pos.Rows.Add(100, 200);
            dt_Pos.Rows.Add(100, 300);
            AccessWin aw = new AccessWin();

            aw.ClickPOSList(dt_Pos, 100);
        }
예제 #11
0
        public bool CloseMessageBox(ref string message, IntPtr handle)
        {
            try {
                WindowsTree wt = ListWindow(handle);
                for (int i = 0; i < wt.WindowCount; i++)
                {
                    WindowInfo info = wt.winfos[i];
                    //记录提示信息
                    if (info.title == "提示")
                    {
                        if ((sw.ElapsedMilliseconds > 20000) || (ptr_LastClosedHWND != info.hwnd)) //据上次关闭大于3S,或者要关闭的窗体是新窗体 (3S钟内不重复关闭一个窗体)
                        {
                            sw.Reset();
                            sw.Restart();
                            ptr_LastClosedHWND = info.hwnd;
                            AccessWin   aw       = new AccessWin();
                            WindowsTree wtsub    = aw.ListWindow(info.hwnd);
                            WindowsTree wtfilter = wtsub.FiltedbyClassName("Static");
                            for (int j = 0; j < wtfilter.WindowCount; j++)
                            {
                                WindowInfo infosub = wtfilter.winfos[j];
                                message = message + infosub.title + " ";
                                message = message.Trim();
                            }

                            //关闭窗口
                            WindowsTree wtfilter2 = wtsub.FiltedbyClassName("Button");
                            ClickButton(wtfilter2.winfos[0].hwnd);
                            ClickButton(wtfilter2.winfos[0].hwnd);
                            return(true);
                        }
                        else
                        {
                            int iii = 0;
                            iii++;
                        }
                    }
                }
            }
            catch (Exception ee)
            {
                Console.Write(ee.StackTrace);
                return(false);
            }
            return(false);
        }
예제 #12
0
        private void btn_ListViewItem_Click(object sender, EventArgs e)
        {
            AccessWin aw      = new AccessWin();
            IntPtr    vHandle = new IntPtr(Convert.ToInt32(txt_SelectedCell.Text, 16));

            aw.CheckListViewItem(vHandle, dgv_Listview.SelectedCells[0].OwningRow.Index);
            IntPtr vHandle2 = new IntPtr(Convert.ToInt32(txt_handle.Text, 16));

            //NativeMethods.SetActiveWindow(vHandle);
            //ExternalCode.keybd_event(0x0d, 0x1c, 0, 0);
            //ExternalCode.keybd_event(0x0d, 0x1c, 2, 0);


            //IntPtr handle = new IntPtr(Convert.ToInt32(txt_SelectedCell.Text, 16));
            //int keycode = Convert.ToInt32(txt_KeyDownCode.Text, 16);
            //NativeMethods.SendMessageW(handle, NativeMethods.WM_KEYDOWN, (uint)keycode, 0x1c0001);
        }
예제 #13
0
        private void btn_CloseMessageBox_Click(object sender, EventArgs e)
        {
            IntPtr pt;

            try
            {
                pt = new IntPtr(Convert.ToInt32(txt_SelectedCell.Text, 16));
            }catch
            {
                pt = new IntPtr(0);
            }
            AccessWin aw = new AccessWin();
            string    s  = "";

            aw.CloseMessageBox(ref s, pt);
            txt_Message.Text = s;
        }
예제 #14
0
        private void btn_FilterHWND_Click(object sender, EventArgs e)
        {
            AccessWin aw = new AccessWin();

            AccessWin.WindowsTree wt = new AccessWin.WindowsTree();
            IntPtr pt = aw.GetWindowHandlebyTitle(txt_APPTitle.Text);

            txt_handle.Text = pt.ToString("X");  //display the handle in textbox
            //IntPtr vHandle = new IntPtr(Convert.ToInt32(txt_ListHandle.Text, 16));
            wt = aw.ListWindow(pt);
            try
            {
                dgv_list.DataSource = wt.FiltedbyHWND(Convert.ToInt32(txt_FilterHWND.Text, 16)).toDatatable();
            }
            catch
            { }
        }
예제 #15
0
        private void btn_GetWindowList_Click(object sender, EventArgs e)
        {
            AccessWin aw = new AccessWin();

            AccessWin.WindowsTree wt = new AccessWin.WindowsTree();

            IntPtr pt = aw.GetWindowHandlebyTitle(txt_APPTitle.Text);

            txt_handle.Text = pt.ToString("X");  //display the handle in textbox
            //IntPtr vHandle = new IntPtr(Convert.ToInt32(txt_hndle.Text, 16));
            if (aw != null)
            {
                DataTable dt = new DataTable();
                dt = aw.ListWindow(pt).toDatatable();
                //dgv_list.DataSource = dt;
                AccessWin.WindowsTree wt2 = new AccessWin.WindowsTree();
                wt2.GetfromDataTable(dt);
                DataTable dt2 = wt2.toDatatable();
                dgv_list.DataSource = dt2;
            }
        }
예제 #16
0
        public bool CloseSystemTreeBox(string title, ref string message, IntPtr handle)
        {
            try
            {
                WindowsTree wt = ListWindow(handle);
                for (int i = 0; i < wt.WindowCount; i++)
                {
                    WindowInfo info = wt.winfos[i];
                    //记录提示信息
                    if (info.title == title)
                    {
                        AccessWin   aw       = new AccessWin();
                        WindowsTree wtsub    = aw.ListWindow(info.hwnd);
                        WindowsTree wtfilter = wtsub.FiltedbyClassName("SysListView32");

                        DataTable dt = aw.GetListViewContent(wtfilter.winfos[0].hwnd);
                        for (int j = 0; j < dt.Rows.Count; j++)
                        {
                            for (int k = 0; k < dt.Columns.Count; k++)
                            {
                                message = message + dt.Rows[j][k].ToString() + "/";
                            }
                        }

                        //关闭窗口
                        WindowsTree wtfilter2 = wtsub.FiltedbyClassName("Button");
                        ClickButton(wtfilter2.winfos[0].hwnd);
                        ClickButton(wtfilter2.winfos[0].hwnd);
                        return(true);
                    }
                }
            }
            catch (Exception ee)
            {
                Console.Write(ee.StackTrace);
                return(false);
            }
            return(false);
        }
예제 #17
0
        private void btn_doubleclick_Click(object sender, EventArgs e)
        {
            AccessWin aw = new AccessWin();

            aw.DoubleClickButton(new IntPtr(Convert.ToInt32(txt_SelectedCell.Text, 16)));
        }
예제 #18
0
        private void btn_inputTXT_Click(object sender, EventArgs e)
        {
            AccessWin aw = new AccessWin();

            aw.SetText(new IntPtr(Convert.ToInt32(txt_SelectedCell.Text, 16)), txt_inputTXT.Text);
        }
예제 #19
0
        /// <summary>
        /// 获取指定句柄的listview内容
        /// </summary>
        /// <param name="handle"></param>
        /// <returns></returns>
        public DataTable GetListViewContent(IntPtr handle)
        {
            AccessWin aw = new AccessWin();
            int       vItemCount;
            int       ColumnCount;

            if (handle == IntPtr.Zero)
            {
                return(null);
            }
            vItemCount = NativeMethods.SendMessageW(handle, NativeMethods.LVM_GETITEMCOUNT, 0, 0);
            IntPtr handleHeader = new IntPtr(NativeMethods.SendMessageW(handle, NativeMethods.LVM_GETHEADER, 0, 0));

            ColumnCount = NativeMethods.SendMessageW(handleHeader, NativeMethods.HDM_GETITEMCOUNT, 0, 0);
            uint vProcessId;

            NativeMethods.GetWindowThreadProcessId(handle, out vProcessId);
            IntPtr    vProcess = NativeMethods.OpenProcess(NativeMethods.PROCESS_VM_OPERATION | NativeMethods.PROCESS_VM_READ | NativeMethods.PROCESS_VM_WRITE, false, vProcessId);
            IntPtr    vPointer = NativeMethods.VirtualAllocEx(vProcess, IntPtr.Zero, 4096, NativeMethods.MEM_RESERVE | NativeMethods.MEM_COMMIT, NativeMethods.PAGE_READWRITE);
            int       ttt      = Marshal.SizeOf(typeof(NativeMethods.NMHDR));
            DataTable dt       = new DataTable();

            try
            {
                for (int j = 0; j < ColumnCount; j++)
                {
                    byte[] vBuffer = new byte[256];
                    NativeMethods.LVHEADER[] vHeader = new NativeMethods.LVHEADER[1];
                    vHeader[0]            = new NativeMethods.LVHEADER();
                    vHeader[0].mask       = NativeMethods.LVCF_TEXT;
                    vHeader[0].cchTextMax = 256;
                    vHeader[0].iSubItem   = 0;
                    vHeader[0].pszText    = (IntPtr)((int)vPointer + Marshal.SizeOf(typeof(NativeMethods.LVHEADER)));
                    uint vNumberOfBytesRead = 0;
                    NativeMethods.WriteProcessMemory(vProcess, vPointer, Marshal.UnsafeAddrOfPinnedArrayElement(vHeader, 0), Marshal.SizeOf(typeof(NativeMethods.LVHEADER)), ref vNumberOfBytesRead);
                    NativeMethods.SendMessageW(handle, NativeMethods.LVM_GETCOLUMN, (uint)j, vPointer.ToInt32());
                    NativeMethods.ReadProcessMemory(vProcess, (IntPtr)((int)vPointer + Marshal.SizeOf(typeof(NativeMethods.LVHEADER))), Marshal.UnsafeAddrOfPinnedArrayElement(vBuffer, 0), vBuffer.Length, ref vNumberOfBytesRead);
                    string vText = Marshal.PtrToStringAnsi(Marshal.UnsafeAddrOfPinnedArrayElement(vBuffer, 0));
                    dt.Columns.Add(vText);
                }

                for (int j = 0; j < ColumnCount; j++)
                {
                }

                for (int i = 0; i < vItemCount; i++)
                {
                    DataRow dr = dt.NewRow();
                    for (int j = 0; j < ColumnCount; j++)
                    {
                        byte[] vBuffer = new byte[256];

                        NativeMethods.LVITEM[] vItem = new NativeMethods.LVITEM[1];
                        vItem[0]            = new NativeMethods.LVITEM();
                        vItem[0].mask       = NativeMethods.LVIF_TEXT;
                        vItem[0].iItem      = i;
                        vItem[0].iSubItem   = j;
                        vItem[0].cchTextMax = vBuffer.Length;
                        vItem[0].pszText    = (IntPtr)((int)vPointer + Marshal.SizeOf(typeof(NativeMethods.LVITEM)));
                        uint vNumberOfBytesRead = 0;
                        NativeMethods.WriteProcessMemory(vProcess, vPointer, Marshal.UnsafeAddrOfPinnedArrayElement(vItem, 0), Marshal.SizeOf(typeof(NativeMethods.LVITEM)), ref vNumberOfBytesRead);
                        NativeMethods.SendMessageW(handle, NativeMethods.LVM_GETITEMW, (uint)i, vPointer.ToInt32());
                        NativeMethods.ReadProcessMemory(vProcess, (IntPtr)((int)vPointer + Marshal.SizeOf(typeof(NativeMethods.LVITEM))), Marshal.UnsafeAddrOfPinnedArrayElement(vBuffer, 0), vBuffer.Length, ref vNumberOfBytesRead);
                        string vText = Marshal.PtrToStringUni(Marshal.UnsafeAddrOfPinnedArrayElement(vBuffer, 0));
                        dr[j] = vText;
                    }
                    dt.Rows.Add(dr);
                }
            }
            finally
            {
                NativeMethods.VirtualFreeEx(vProcess, vPointer, 0, NativeMethods.MEM_RELEASE);
                NativeMethods.CloseHandle(vProcess);
            }
            return(dt);
        }
예제 #20
0
        private void btn_changeselect_Click(object sender, EventArgs e)
        {
            AccessWin aw = new AccessWin();

            aw.SelectComboBoxIndex(new IntPtr(Convert.ToInt32(txt_SelectedCell.Text, 16)), Convert.ToInt16(txt_index.Text));
        }
예제 #21
0
        private void btn_sendKey_Click(object sender, EventArgs e)
        {
            AccessWin aw = new AccessWin();

            aw.SendKey(new IntPtr(Convert.ToInt32(txt_SelectedCell.Text, 16)), txt_KeyCode.Text);
        }
예제 #22
0
        private void btn_GetSel_Click(object sender, EventArgs e)
        {
            AccessWin aw = new AccessWin();

            txt_select.Text = Convert.ToString(aw.GetComboBox(new IntPtr(Convert.ToInt32(txt_handle.Text, 16))));
        }