private bool check(InputStock stockCode)
 {
     if (stockCode.Code != null && stockCode.Price != 0 && stockCode.Amount != 0 && stockCode.State != 0)
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
        /*******************************************************************************************/

        /*****************************************************
         * 函数功能:自动下单
         * 输入: InputStock:
         *          股票代码,价格,数量,交易方式
         * 输出: return 0 成功操作
         *        return 1 没找到button
         *        return 2 没有找到msg标题
         *        return 3 没找到button与text
         *        return 4 价格输入出错
         *        return 5 msg标题没有匹配的操作
         *        return 6 tv选择与操作不匹配
         *        return 7 输入stock错误
         *        return 8 没有找到相应窗体
         *        return 9 没有找到下单程序
         *        return 10 没有获取弹出窗口
         ******************************************************/
        public int AutoBuy(InputStock stockCode)
        {
            if (!check(stockCode))
            {
                return(7);
            }
            IntPtr hwnd = FindWindow("xiadan");

            if (hwnd != IntPtr.Zero)
            {
                SetForegroundWindow(hwnd);
                IntPtr frame    = FindWindowEx(hwnd, 0, "AfxMDIFrame42s", null);
                IntPtr dlg      = GetDlgItem(frame, 0x0000E901);
                IntPtr dlgTitle = GetDlgItem(dlg, 0x000005C6);

                if (dlgTitle != IntPtr.Zero)
                {
                    string s = getstring(dlgTitle);
                    if (s.IndexOf(stockCode.State.ToString()) == -1)
                    {
                        return(6);
                    }
                    IntPtr stcokCodeBox = GetDlgItem(dlg, 0x00000408);
                    IntPtr priceBox     = GetDlgItem(dlg, 0x00000409);
                    IntPtr numberBox    = GetDlgItem(dlg, 0x0000040A);
                    SendMessage(stcokCodeBox, WM_SETTEXT, 0, stockCode.Code);
                    SendMessage(priceBox, WM_SETTEXT, 0, stockCode.Price.ToString());
                    SendMessage(numberBox, WM_SETTEXT, 0, stockCode.Amount.ToString());
                    IntPtr dlgok = GetDlgItem(dlg, 0x000003EE);
                    if (dlgok != IntPtr.Zero)
                    {
                        PostMessage(dlgok, BM_CLICK, 0, 0);
                    }
                    else
                    {
                        return(1);
                    }
                    System.Threading.Thread.Sleep(500);
                    IntPtr msg = GetLastActivePopup(hwnd); //弹出窗口查找句柄
                    if (msg == IntPtr.Zero)
                    {
                        return(10);
                    }
                    IntPtr msgtitle = GetDlgItem(msg, 0x00000555);
                    if (msgtitle != IntPtr.Zero)
                    {
                        string ss = getstring(msgtitle);
                        if (ss.IndexOf("委托确认") != -1)
                        {
                            return(ControlqrMsg(msg, hwnd));
                        }
                        else if (ss.IndexOf("提示信息") != -1)
                        {
                            return(ControltsxxMsg(msg, hwnd));
                        }
                        else if (ss.IndexOf("提示") != -1)
                        {
                            return(ControltsMsg(msg, hwnd));
                        }
                        else
                        {
                            return(5);
                        }
                    }
                    else
                    {
                        return(2);
                    }
                }
                else
                {
                    return(8);
                }
            }
            else
            {
                return(9);
            }
        }