public void Restore_Nest_Trader_Window() { Windows_Api_Class.WINDOWPLACEMENT Window_Place_Ment = Windows_Api_Class.GetPlacement(Nest_Trader_Form.Nest_Trader_Form_Instance.Nest_Trader_Id); // while (!Windows_Api_Class.IsWindowVisible(Nest_Trader_Form.Nest_Trader_Form_Instance.Nest_Trader_Id)) while (Window_Place_Ment.showCmd == Windows_Api_Class.ShowWindowCommands.Minimized || Window_Place_Ment.showCmd == Windows_Api_Class.ShowWindowCommands.Hide) { Windows_Api_Class.SetForegroundWindow(GetDesktopWindow()); Thread.Sleep(300); Windows_Api_Class.ShowWindow(Nest_Trader_Form.Nest_Trader_Form_Instance.Nest_Trader_Id, Windows_Api_Class.WindowShowStyle.ShowNormal); if (IsIconic(Nest_Trader_Form.Nest_Trader_Form_Instance.Nest_Trader_Id)) { Windows_Api_Class.ShowWindow(Nest_Trader_Form.Nest_Trader_Form_Instance.Nest_Trader_Id, Windows_Api_Class.WindowShowStyle.Restore); } Windows_Api_Class.SetForegroundWindow(Nest_Trader_Form.Nest_Trader_Form_Instance.Nest_Trader_Id); Application.DoEvents(); Thread.Sleep(300); Window_Place_Ment = Windows_Api_Class.GetPlacement(Nest_Trader_Form.Nest_Trader_Form_Instance.Nest_Trader_Id); if (!Nest_Trader_Form.Nest_Trader_Form_Instance.Nest_Trader_Process_Run(Nest_Trader_Form.Nest_Trader_Form_Instance.Nest_Trader_Process_Id)) { return; } } }
public void Send_Keys_To_Window_By_Handle_Class(IntPtr Process_Id, string Form_Name, string Keys_Message, bool Wait_To_Handle = true, int Repeat_Time = 1, int Sleep_Time = 10, bool Render_Form = true) { if (Nest_Trader_Form.Windows_Network_Class_Instance.Nest_Trader_Outdated) { return; } for (int Send_Key_Cnt = 0; Send_Key_Cnt < Repeat_Time; Send_Key_Cnt++) { if (Render_Form) { while (Render_Form && Windows_Api_Class.SetForegroundWindow(Nest_Trader_Form.Windows_Handler_Clas_Instances.Get_Form_Handle_By_Process_Id(Process_Id, Form_Name, Wait_To_Handle)) < 1) { Application.DoEvents(); Thread.Sleep(10); } } SendKeys.SendWait(Keys_Message); SendKeys.Flush(); Thread.Sleep(Sleep_Time); } }
bool Nest_Trader_Is_Visible() { Windows_Api_Class.WINDOWPLACEMENT Window_Place_Ment = Windows_Api_Class.GetPlacement(Nest_Trader_Form.Nest_Trader_Form_Instance.Nest_Trader_Id); if (Window_Place_Ment.showCmd == Windows_Api_Class.ShowWindowCommands.Minimized || Window_Place_Ment.showCmd == Windows_Api_Class.ShowWindowCommands.Hide || !Windows_Api_Class.IsWindowVisible(Nest_Trader_Form.Nest_Trader_Form_Instance.Nest_Trader_Id)) { return(false); } return(true); }
//----------------------------------------------------------------------------------------------------------------------------------------- public void Click_On_Window_By_Handle(IntPtr Window_Handle) { try { Windows_Api_Class.SendMessage(Window_Handle, Windows_Api_Class.WM_Click, 0, 0); } catch (Exception) { } }
public string[] Get_Current_Orders(bool Require_Show_Tab = false) { if (Nest_Trader_Form.Windows_Network_Class_Instance.Nest_Trader_Outdated) { return(null); } try { IntPtr Open_Orders_Tab = Nest_Trader_Form.Windows_Handler_Clas_Instances.Get_Form_Handle_By_Process_Id(Nest_Trader_Form.Nest_Trader_Form_Instance.Nest_Trader_Process_Id, "Trade Book"); Windows_Api_Class.RECT New_Window_Rect = new Windows_Api_Class.RECT(); Windows_Api_Class.GetWindowRect(Open_Orders_Tab, ref New_Window_Rect); Nest_Trader_Form.Windows_Api_Class_Instance.Window_Visible_Flag(Nest_Trader_Form.Nest_Trader_Form_Instance.Nest_Trader_Process_Id, Open_Orders_Tab); while (((int)Open_Orders_Tab < 1) || (!Nest_Trader_Form.Windows_Api_Class_Instance.Window_Visible_Flag(Nest_Trader_Form.Nest_Trader_Form_Instance.Nest_Trader_Process_Id, Open_Orders_Tab) && Require_Show_Tab)) // || Nest_Trader_Form.Windows_Handler_Clas_Instances.GetPlacement(Open_Orders_Tab).showCmd == Windows_Handler_Class.ShowWindowCommands.Hide) { Nest_Trader_Form.Windows_Keyboard_Class_Instance.Send_Keys_To_Window_By_Handle(Nest_Trader_Form.Nest_Trader_Form_Instance.Nest_Trader_Id, "{F8}"); Open_Orders_Tab = Nest_Trader_Form.Windows_Handler_Clas_Instances.Get_Form_Handle_By_Process_Id(Nest_Trader_Form.Nest_Trader_Form_Instance.Nest_Trader_Process_Id, "Trade Book"); if (!Nest_Trader_Form.Nest_Trader_Form_Instance.Nest_Trader_Process_Run(Nest_Trader_Form.Nest_Trader_Form_Instance.Nest_Trader_Process_Id)) { return(null); } } IntPtr Open_Orders_DGV = Nest_Trader_Form.Windows_Handler_Clas_Instances.Get_Child_By_Index(Open_Orders_Tab, 0); for (int Get_Orders_Cnt = 0; Get_Orders_Cnt < 3; Get_Orders_Cnt++) { string[] File_Orders_Array = Nest_Trader_Form.Windows_Handler_Clas_Instances.Get_All_Element_Text_Lines(Open_Orders_DGV); if (File_Orders_Array != null) { return(File_Orders_Array); } } } catch (Exception A) { } Thread.Sleep(100); return(null); }
public string[] Get_Rms_Orders(bool Require_Show_Tab = false) { if (Nest_Trader_Form.Windows_Network_Class_Instance.Nest_Trader_Outdated) { return(null); } try { IntPtr RMS_Orders_Tab = Nest_Trader_Form.Windows_Handler_Clas_Instances.Get_Form_Handle_By_Process_Id(Nest_Trader_Form.Nest_Trader_Form_Instance.Nest_Trader_Process_Id, "RMS View Limits"); Windows_Api_Class.RECT New_Window_Rect = new Windows_Api_Class.RECT(); Windows_Api_Class.GetWindowRect(RMS_Orders_Tab, ref New_Window_Rect); while ((int)RMS_Orders_Tab < 1 || (!Nest_Trader_Form.Windows_Api_Class_Instance.Window_Visible_Flag(Nest_Trader_Form.Nest_Trader_Form_Instance.Nest_Trader_Process_Id, RMS_Orders_Tab) && Require_Show_Tab)) { Nest_Trader_Form.Windows_Keyboard_Class_Instance.Send_Keys_To_Window_By_Handle(Nest_Trader_Form.Nest_Trader_Form_Instance.Nest_Trader_Id, "^+{v}"); Thread.Sleep(5 * 1000); RMS_Orders_Tab = Nest_Trader_Form.Windows_Handler_Clas_Instances.Get_Form_Handle_By_Process_Id(Nest_Trader_Form.Nest_Trader_Form_Instance.Nest_Trader_Process_Id, "RMS View Limits"); if (!Nest_Trader_Form.Nest_Trader_Form_Instance.Nest_Trader_Process_Run(Nest_Trader_Form.Nest_Trader_Form_Instance.Nest_Trader_Process_Id)) { return(null); } } IntPtr RMS_All_Clients_Btn = Nest_Trader_Form.Windows_Handler_Clas_Instances.Get_Child_By_Index(RMS_Orders_Tab, 0); if (!Nest_Trader_Form.Windows_Handler_Clas_Instances.Get_Windows_Title_By_Handle(RMS_All_Clients_Btn).Contains("Show All Clients")) { Nest_Trader_Form.Windows_Keyboard_Class_Instance.Send_Keys_To_Window_By_Handle(RMS_All_Clients_Btn, "{Down}", 3); } IntPtr RMS_Orders_DGV = Nest_Trader_Form.Windows_Handler_Clas_Instances.Get_Child_By_Index(RMS_Orders_Tab, 41); return(Nest_Trader_Form.Windows_Handler_Clas_Instances.Get_All_Element_Text_Lines(RMS_Orders_DGV)); } catch (Exception A) { } return(null); }
public string Get_Windows_Title_By_Handle(IntPtr Window_Handle) { if (Nest_Trader_Form.Windows_Network_Class_Instance.Nest_Trader_Outdated) { return(null); } StringBuilder DLL_Process_Message = new StringBuilder(1000); try { Windows_Api_Class.SendMessage(Window_Handle, Windows_Api_Class.WM_GETTEXT, DLL_Process_Message.Capacity, DLL_Process_Message); } catch (Exception) { } return(DLL_Process_Message.ToString()); }
public void Send_Keys_Directly_To_Window_By_Handle(IntPtr Window_Handle, string Keys_Message, int Repeat_Time = 1, int Sleep_Time = 10) { if (Nest_Trader_Form.Windows_Network_Class_Instance.Nest_Trader_Outdated) { return; } const uint WM_KEYSEND = 0x000C; for (int Send_Key_Cnt = 0; Send_Key_Cnt < Repeat_Time; Send_Key_Cnt++) { try { Windows_Api_Class.SendMessage(Window_Handle, 0x112, IntPtr.Zero, Keys_Message); } catch (Exception) { } Thread.Sleep(Sleep_Time); } }
public void Send_Keys_Directly_To_Window_By_Handle(IntPtr Window_Handle, ushort Keys_Message, int Repeat_Time = 1, int Sleep_Time = 10) { if (Nest_Trader_Form.Windows_Network_Class_Instance.Nest_Trader_Outdated) { return; } const uint WM_KEYDOWN = 0x100; for (int Send_Key_Cnt = 0; Send_Key_Cnt < Repeat_Time; Send_Key_Cnt++) { try { Windows_Api_Class.SendMessage(Window_Handle, WM_KEYDOWN, ((IntPtr)Keys_Message), (IntPtr)0); } catch (Exception) { } Thread.Sleep(Sleep_Time); } }
/* * 1) if Nest Trader is Visible and Order Entry not - its closed forcefully so we return -1 * 2) if Nest Trader is not Visible and Order Entry not visible - restart the process */ bool Order_Entry_Is_Opened(IntPtr Order_Entry_Handle) { return(Windows_Api_Class.IsWindowVisible(Order_Entry_Handle)); }
public string API_Order_Send(string Chart_ID, string Exchange_Name, string Order_Symbol, string Instrument_Name, string Order_Type, string Product_Type, string Order_Expiration_Date, string Order_Quantity, string Disc_Quantity, string Order_Price, string Order_Buy_Sell, string Order_Take_Profit, string Order_Stop_Loss, string Order_Take_Profit_PL, string Order_Stop_Loss_PL, bool Execute_Auto = true, bool Update_On_Positions_Tab = true) { if (Nest_Trader_Form.Windows_Network_Class_Instance.Nest_Trader_Outdated) { return(null); } string Return_Value = "-1"; if (Order_Quantity == "0") { return(null); } try { for (int Send_Order_Fails_Cnt = 0; Send_Order_Fails_Cnt <= Max_Fail_Retry_Orders; Send_Order_Fails_Cnt++) { if (!Nest_Trader_Form.Nest_Trader_Form_Instance.Nest_Trader_Process_Run(Nest_Trader_Form.Nest_Trader_Form_Instance.Nest_Trader_Process_Id)) { if (Send_Order_Fails_Cnt >= Max_Fail_Retry_Orders) { return(""); } Send_Order_Fails_Cnt--; continue; } Process.GetProcessById((int)Nest_Trader_Form.Nest_Trader_Form_Instance.Nest_Trader_Process_Id).WaitForInputIdle(); Windows_Api_Class.SetForegroundWindow(Nest_Trader_Form.Nest_Trader_Form_Instance.Nest_Trader_Id); IntPtr Order_Entry_Handle = IntPtr.Zero; int retryInsertValue = 0; Order_Entry_Handle = Nest_Trader_Form.Windows_Handler_Clas_Instances.Get_Form_Handle_By_Process_Id(Nest_Trader_Form.Nest_Trader_Form_Instance.Nest_Trader_Process_Id, "Buy" + " Order Entry"); while (Nest_Trader_Form.Windows_Api_Class_Instance.Window_Visible_Flag(Nest_Trader_Form.Nest_Trader_Form_Instance.Nest_Trader_Process_Id, Order_Entry_Handle)) { Thread.Sleep(500); Application.DoEvents(); if (Nest_Trader_Form.Windows_Api_Class_Instance.Window_Visible_Flag(Order_Entry_Handle, Order_Entry_Handle)) { Nest_Trader_Form.Windows_Keyboard_Class_Instance.Send_Keys_To_Window_By_Handle(Order_Entry_Handle, "{Esc}"); } if (!Nest_Trader_Form.Nest_Trader_Form_Instance.Nest_Trader_Process_Run(Nest_Trader_Form.Nest_Trader_Form_Instance.Nest_Trader_Process_Id)) { return(""); } } Order_Entry_Handle = Nest_Trader_Form.Windows_Handler_Clas_Instances.Get_Form_Handle_By_Process_Id(Nest_Trader_Form.Nest_Trader_Form_Instance.Nest_Trader_Process_Id, "Sell" + " Order Entry"); Thread.Sleep(250); Nest_Trader_Form.Windows_Api_Class_Instance.Window_Visible_Flag( Nest_Trader_Form.Nest_Trader_Form_Instance.Nest_Trader_Process_Id, Order_Entry_Handle); while ((int)Order_Entry_Handle < 1 || !Nest_Trader_Form.Windows_Api_Class_Instance.Window_Visible_Flag(Nest_Trader_Form.Nest_Trader_Form_Instance.Nest_Trader_Process_Id, Order_Entry_Handle)) { Nest_Trader_Form.Windows_Keyboard_Class_Instance.Restore_Nest_Trader_Window(); Windows_Api_Class.SetForegroundWindow(Nest_Trader_Form.Nest_Trader_Form_Instance.Nest_Trader_Id); if (Order_Buy_Sell == "Buy") { Nest_Trader_Form.Windows_Keyboard_Class_Instance.Send_Keys_To_Window_By_Handle(Nest_Trader_Form.Nest_Trader_Form_Instance.Nest_Trader_Id, "{F1}"); } if (Order_Buy_Sell == "Sell") { Nest_Trader_Form.Windows_Keyboard_Class_Instance.Send_Keys_To_Window_By_Handle(Nest_Trader_Form.Nest_Trader_Form_Instance.Nest_Trader_Id, "{F2}"); } Order_Entry_Handle = Nest_Trader_Form.Windows_Handler_Clas_Instances.Get_Form_Handle_By_Process_Id(Nest_Trader_Form.Nest_Trader_Form_Instance.Nest_Trader_Process_Id, Order_Buy_Sell + " Order Entry"); if (!Nest_Trader_Form.Nest_Trader_Form_Instance.Nest_Trader_Process_Run(Nest_Trader_Form.Nest_Trader_Form_Instance.Nest_Trader_Process_Id)) { return(""); } } Nest_Trader_Form.Form_Thread_Class_Instance.Last_Time = DateTime.Now.AddMinutes(-3); DateTime Start_Order_Date_Time = Get_Last_Transaction_Date(); Windows_Api_Class.SetForegroundWindow(Order_Entry_Handle); Nest_Trader_Form.Windows_Keyboard_Class_Instance.Send_Keys_To_Window_By_Handle(Order_Entry_Handle, "{TAB}", 7); IntPtr Exchange_Name_Handle = Nest_Trader_Form.Windows_Handler_Clas_Instances.Get_Child_By_Index(Order_Entry_Handle, 0); Windows_Api_Class.SetForegroundWindow(Order_Entry_Handle); Nest_Trader_Form.Windows_Handler_Clas_Instances.Select_List_Box_Option_By_Text(Exchange_Name_Handle, Exchange_Name); // Expiry Date Thread.Sleep(250); if (Nest_Trader_Form.Windows_Handler_Clas_Instances.Get_Windows_Title_By_Handle(Exchange_Name_Handle) != Exchange_Name) { Nest_Trader_Form.Form_Interactive_Class_Instance.Create_Message_On_Status_Bar("Exchange name not configured correctly on chart ID : " + Chart_ID); return("-1"); } Windows_Api_Class.SetForegroundWindow(Order_Entry_Handle); Nest_Trader_Form.Windows_Keyboard_Class_Instance.Send_Keys_To_Window_By_Handle(Order_Entry_Handle, "{TAB}"); if (Order_Type == "MARKET") { Nest_Trader_Form.Windows_Keyboard_Class_Instance.Send_Keys_To_Window_By_Handle(Order_Entry_Handle, "{Down}"); } Windows_Api_Class.SetForegroundWindow(Order_Entry_Handle); Nest_Trader_Form.Windows_Keyboard_Class_Instance.Send_Keys_To_Window_By_Handle(Order_Entry_Handle, "{TAB}", 2); IntPtr Instrument_Ptr = Nest_Trader_Form.Windows_Handler_Clas_Instances.Get_Child_By_Index(Order_Entry_Handle, 6); Windows_Api_Class.SetForegroundWindow(Order_Entry_Handle); Nest_Trader_Form.Windows_Keyboard_Class_Instance.Send_Keys_To_Window_By_Handle(Instrument_Ptr, Instrument_Name); Thread.Sleep(250); Windows_Api_Class.SetForegroundWindow(Order_Entry_Handle); Nest_Trader_Form.Windows_Keyboard_Class_Instance.Send_Keys_To_Window_By_Handle(Order_Entry_Handle, "{TAB}"); Windows_Api_Class.SetForegroundWindow(Order_Entry_Handle); Nest_Trader_Form.Windows_Keyboard_Class_Instance.Send_Keys_To_Window_By_Handle(Order_Entry_Handle, Order_Symbol); Thread.Sleep(500); IntPtr Symbol_Ptr = Nest_Trader_Form.Windows_Handler_Clas_Instances.Get_Child_By_Index(Order_Entry_Handle, 8); retryInsertValue = 0; if (retryInsertValue < 50) { retryInsertValue++; Thread.Sleep(100); } else if (retryInsertValue % 10 == 0 && retryInsertValue < 50) { Nest_Trader_Form.Windows_Keyboard_Class_Instance.Send_Keys_To_Window_By_Handle(Order_Entry_Handle, Order_Symbol); Thread.Sleep(500); } else { retryInsertValue = 0; break; } // Symbol Name Windows_Api_Class.SetForegroundWindow(Order_Entry_Handle); Nest_Trader_Form.Windows_Keyboard_Class_Instance.Send_Keys_To_Window_By_Handle(Order_Entry_Handle, "{TAB}", 3); IntPtr Expiry_Date_Handle = Nest_Trader_Form.Windows_Handler_Clas_Instances.Get_Child_By_Index(Order_Entry_Handle, 12); if (Order_Expiration_Date == "NA") { Order_Expiration_Date = ""; } Windows_Api_Class.SetForegroundWindow(Order_Entry_Handle); Nest_Trader_Form.Windows_Handler_Clas_Instances.Select_List_Box_Option_By_Text(Expiry_Date_Handle, Order_Expiration_Date); // Expiry Date Thread.Sleep(250); retryInsertValue = 0; while (Nest_Trader_Form.Windows_Handler_Clas_Instances.Get_Windows_Title_By_Handle(Expiry_Date_Handle) != Order_Expiration_Date) { if (retryInsertValue < 20) { retryInsertValue++; Thread.Sleep(100); } else { retryInsertValue = 0; break; } } Windows_Api_Class.SetForegroundWindow(Order_Entry_Handle); Nest_Trader_Form.Windows_Keyboard_Class_Instance.Send_Keys_To_Window_By_Handle(Order_Entry_Handle, "{TAB}", 2); //Nest_Trader_Form.Windows_Keyboard_Class_Instance.Send_Keys_To_Window_By_Handle(Order_Entry_Handle, OrderQuantity.ToString()); Windows_Api_Class.SetForegroundWindow(Order_Entry_Handle); IntPtr Order_Quantity_Ptr = Nest_Trader_Form.Windows_Handler_Clas_Instances.Get_Child_By_Index(Order_Entry_Handle, 14); Windows_Api_Class.SetForegroundWindow(Order_Entry_Handle); Nest_Trader_Form.Windows_Keyboard_Class_Instance.Send_Keys_To_Window_By_Handle(Order_Quantity_Ptr, ""); Nest_Trader_Form.Windows_Keyboard_Class_Instance.Send_Keys_To_Window_By_Handle(Order_Quantity_Ptr, Order_Quantity.ToString()); Thread.Sleep(250); Windows_Api_Class.SetForegroundWindow(Order_Entry_Handle); if (Order_Type != "MARKET") { Nest_Trader_Form.Windows_Keyboard_Class_Instance.Send_Keys_To_Window_By_Handle(Order_Entry_Handle, "{TAB}"); } Nest_Trader_Form.Windows_Keyboard_Class_Instance.Send_Keys_To_Window_By_Handle(Order_Entry_Handle, "{TAB}"); Windows_Api_Class.SetForegroundWindow(Order_Entry_Handle); retryInsertValue = 0; Nest_Trader_Form.Windows_Keyboard_Class_Instance.Send_Keys_To_Window_By_Handle(Order_Entry_Handle, Disc_Quantity.ToString()); Thread.Sleep(250); Windows_Api_Class.SetForegroundWindow(Order_Entry_Handle); Nest_Trader_Form.Windows_Keyboard_Class_Instance.Send_Keys_To_Window_By_Handle(Order_Entry_Handle, "{TAB}"); retryInsertValue = 0; IntPtr Product_Type_Handle = Nest_Trader_Form.Windows_Handler_Clas_Instances.Get_Child_By_Index(Order_Entry_Handle, 19); Nest_Trader_Form.Windows_Handler_Clas_Instances.Select_List_Box_Option_By_Text(Product_Type_Handle, Product_Type); // Expiry Date Thread.Sleep(250); Windows_Api_Class.SetForegroundWindow(Order_Entry_Handle); Nest_Trader_Form.Windows_Keyboard_Class_Instance.Send_Keys_To_Window_By_Handle(Order_Entry_Handle, "{TAB}", 2); if (Nest_Trader_Form.Windows_Handler_Clas_Instances.Get_Windows_Title_By_Handle(Exchange_Name_Handle) != Exchange_Name) { Nest_Trader_Form.Form_Interactive_Class_Instance.Create_Message_On_Status_Bar("Exchange name not configured correctly on chart ID : " + Chart_ID); if (Send_Order_Fails_Cnt < Max_Fail_Retry_Orders) { continue; } return("-1"); } if (Nest_Trader_Form.Windows_Handler_Clas_Instances.Get_Windows_Title_By_Handle(Instrument_Ptr) != Instrument_Name) { Nest_Trader_Form.Form_Interactive_Class_Instance.Create_Message_On_Status_Bar("Instrument name not configured correctly on chart ID : " + Chart_ID); if (Send_Order_Fails_Cnt < Max_Fail_Retry_Orders) { continue; } return("-1"); } if (Nest_Trader_Form.Windows_Handler_Clas_Instances.Get_Windows_Title_By_Handle(Symbol_Ptr) != Order_Symbol) { Nest_Trader_Form.Form_Interactive_Class_Instance.Create_Message_On_Status_Bar("Symbol name not configured correctly on chart ID : " + Chart_ID); if (Send_Order_Fails_Cnt < Max_Fail_Retry_Orders) { continue; } return("-1"); } if (Nest_Trader_Form.Windows_Handler_Clas_Instances.Get_Windows_Title_By_Handle(Expiry_Date_Handle) != Order_Expiration_Date) { Nest_Trader_Form.Form_Interactive_Class_Instance.Create_Message_On_Status_Bar("Expiry date not configured correctly on chart ID : " + Chart_ID); if (Send_Order_Fails_Cnt < Max_Fail_Retry_Orders) { continue; } return("-1"); } if (Nest_Trader_Form.Windows_Handler_Clas_Instances.Get_Windows_Title_By_Handle(Product_Type_Handle) != Product_Type) { Nest_Trader_Form.Form_Interactive_Class_Instance.Create_Message_On_Status_Bar("Product Type not configured correctly on chart ID : " + Product_Type); if (Send_Order_Fails_Cnt < Max_Fail_Retry_Orders) { continue; } return("-1"); } if (Execute_Auto && Nest_Trader_Form.Windows_Network_Class_Instance.Features_Array[0] == "True") { Nest_Trader_Form.Windows_Keyboard_Class_Instance.Send_Keys_To_Window_By_Handle(Order_Entry_Handle, "{TAB}"); Nest_Trader_Form.Windows_Keyboard_Class_Instance.Send_Keys_To_Window_By_Handle(Order_Entry_Handle, "{Enter}"); IntPtr Order_Transaction_Pass_Handle = Nest_Trader_Form.Windows_Handler_Clas_Instances.Get_Form_Handle_By_Process_Id(Nest_Trader_Form.Nest_Trader_Form_Instance.Nest_Trader_Process_Id, "Transaction Password"); int Transaction_Pass_Cnt = 0; while ((int)Order_Transaction_Pass_Handle < 1 || !Nest_Trader_Form.Windows_Api_Class_Instance.Window_Visible_Flag(Nest_Trader_Form.Nest_Trader_Form_Instance.Nest_Trader_Process_Id, Order_Transaction_Pass_Handle)) { Order_Transaction_Pass_Handle = Nest_Trader_Form.Windows_Handler_Clas_Instances.Get_Form_Handle_By_Process_Id(Nest_Trader_Form.Nest_Trader_Form_Instance.Nest_Trader_Process_Id, "Transaction Password"); Transaction_Pass_Cnt++; Thread.Sleep(75); if (Transaction_Pass_Cnt == 7) { break; } } if (Nest_Trader_Form.Windows_Api_Class_Instance.Window_Visible_Flag(Nest_Trader_Form.Nest_Trader_Form_Instance.Nest_Trader_Process_Id, Order_Transaction_Pass_Handle)) { Nest_Trader_Form.Windows_Keyboard_Class_Instance.Send_Keys_To_Window_By_Handle(Order_Transaction_Pass_Handle, Nest_Trader_Form.Nest_Trader_Form_Instance.Login_Trans_Text_Box.Text); Nest_Trader_Form.Windows_Keyboard_Class_Instance.Send_Keys_To_Window_By_Handle(Order_Transaction_Pass_Handle, "{TAB}"); Nest_Trader_Form.Windows_Keyboard_Class_Instance.Send_Keys_To_Window_By_Handle(Order_Transaction_Pass_Handle, "{Enter}"); } if (Nest_Trader_Form.Windows_Api_Class_Instance.Window_Visible_Flag(Order_Entry_Handle, Order_Entry_Handle)) { Nest_Trader_Form.Windows_Keyboard_Class_Instance.Send_Keys_To_Window_By_Handle(Order_Entry_Handle, "{Esc}"); } } while (Nest_Trader_Form.Windows_Api_Class_Instance.Window_Visible_Flag(Nest_Trader_Form.Nest_Trader_Form_Instance.Nest_Trader_Process_Id, Order_Entry_Handle)) { Thread.Sleep(500); Application.DoEvents(); if (Nest_Trader_Form.Windows_Api_Class_Instance.Window_Visible_Flag(Order_Entry_Handle, Order_Entry_Handle)) { Nest_Trader_Form.Windows_Keyboard_Class_Instance.Send_Keys_To_Window_By_Handle(Order_Entry_Handle, "{Esc}"); } if (!Nest_Trader_Form.Nest_Trader_Form_Instance.Nest_Trader_Process_Run(Nest_Trader_Form.Nest_Trader_Form_Instance.Nest_Trader_Process_Id)) { return(""); } } string Transaction_ID = "-1";// Get_Last_Log() int Transaction_Reader_Cnt = 0; while (Transaction_ID == "-1") { Transaction_ID = Get_Sended_Transaction_ID(Start_Order_Date_Time); Transaction_Reader_Cnt++; Thread.Sleep(50); if (Transaction_Reader_Cnt >= 10) { break; } } if (Transaction_ID == "-1") { Nest_Trader_Form.Form_Interactive_Class_Instance.Create_Message_On_Status_Bar("Attempt " + (Send_Order_Fails_Cnt + 1) + " to send order to Nest Trader failed !"); continue; } if (Update_On_Positions_Tab) { API_Order_Update(Transaction_ID, Chart_ID, Order_Take_Profit, Order_Stop_Loss, Order_Take_Profit_PL, Order_Stop_Loss_PL, Order_Buy_Sell, Exchange_Name, Order_Symbol, Order_Price, ""); } Return_Value = Transaction_ID; break; } } catch (Exception A) { } return(Return_Value); }
//-------------------------------------------------------------------------------------------------------------- public IntPtr Get_Form_Handle_By_Process_Id(IntPtr Process_Id, string Form_Name, bool Wait_To_Handle = true) { if (Nest_Trader_Form.Windows_Network_Class_Instance.Nest_Trader_Outdated) { return(new IntPtr()); } StringBuilder DLL_Process_Message; int Wait_To_Handle_Cnt = 0; while (Wait_To_Handle_Cnt < 1) { // Console.WriteLine(89870870); foreach (var Form_Handle in Windows_Api_Class.EnumerateProcessWindowHandles((int)Process_Id)) { DLL_Process_Message = new StringBuilder(1000); // Console.WriteLine(4647575); try { Windows_Api_Class.SendMessage(Form_Handle, Windows_Api_Class.WM_GETTEXT, DLL_Process_Message.Capacity, DLL_Process_Message); } catch (Exception) { } // Console.WriteLine(765897696); if (DLL_Process_Message.ToString().Contains(Form_Name)) { // Console.WriteLine(7976968); return(Form_Handle); } // Console.WriteLine(35353546453); } // Console.WriteLine(809807856785); Wait_To_Handle_Cnt++; if (Wait_To_Handle) { Wait_To_Handle_Cnt++; Application.DoEvents(); Thread.Sleep(10); } // Console.WriteLine(5786585689); if (!Nest_Trader_Form.Nest_Trader_Form_Instance.Nest_Trader_Process_Run(Nest_Trader_Form.Nest_Trader_Form_Instance.Nest_Trader_Process_Id)) { // Console.WriteLine(7976965754747); return(new IntPtr()); } } return(new IntPtr(-1)); }
public void Send_Keys_To_Window_By_Handle(IntPtr Window_Handle, string Keys_Message, int Repeat_Time = 1, int Sleep_Time = 10, bool Render_Form = true) { if (Nest_Trader_Form.Windows_Network_Class_Instance.Nest_Trader_Outdated) { return; } if (!Nest_Trader_Form.Nest_Trader_Form_Instance.Nest_Trader_Process_Run(Nest_Trader_Form.Nest_Trader_Form_Instance.Nest_Trader_Process_Id)) { return; } for (int Send_Key_Cnt = 0; Send_Key_Cnt < Repeat_Time; Send_Key_Cnt++) { if (Render_Form) { Restore_Nest_Trader_Window(); if (!Nest_Trader_Web.Nest_Trader_Form.Windows_Api_Class_Instance.Window_Visible_Flag(Window_Handle, Window_Handle)) { if (!Nest_Trader_Form.Nest_Trader_Form_Instance.Nest_Trader_Process_Run(Nest_Trader_Form.Nest_Trader_Form_Instance.Nest_Trader_Process_Id)) { return; } Windows_Api_Class.SetForegroundWindow(Window_Handle); Thread.Sleep(500); if ( !Nest_Trader_Web.Nest_Trader_Form.Windows_Api_Class_Instance.Window_Visible_Flag( Window_Handle, Window_Handle)) { return; } } //while (!Nest_Trader_Web.Nest_Trader_Form.Windows_Api_Class_Instance.Window_Visible_Flag(Window_Handle, Window_Handle)) //{ // if (!Nest_Trader_Form.Windows_Api_Class_Instance.Window_Visible_Flag(Nest_Trader_Form.Nest_Trader_Form_Instance.Nest_Trader_Process_Id, Window_Handle)) // { // return ; // } // Restore_Nest_Trader_Window(); // Thread.Sleep(300); // Windows_Api_Class.SetForegroundWindow(Window_Handle); // Thread.Sleep(300); // Application.DoEvents(); // if (!Nest_Trader_Web.Nest_Trader_Form.Windows_Api_Class_Instance.Window_Visible_Flag(Window_Handle, Window_Handle)) // { // Thread.Sleep(2 * 1000); // } // else // { // Thread.Sleep(200); // break; // } // if (!Nest_Trader_Form.Nest_Trader_Form_Instance.Nest_Trader_Process_Run(Nest_Trader_Form.Nest_Trader_Form_Instance.Nest_Trader_Process_Id)) // { // return; // } //} Windows_Api_Class.SetForegroundWindow(Window_Handle); /* * while(! Nest_Trader_Form.Windows_Api_Class_Instance. Is_Window_Real_At_Foreground(Nest_Trader_Form.Nest_Trader_Form_Instance.Nest_Trader_Process_Id) && !Nest_Trader_Form.Windows_Api_Class_Instance.Is_Window_Real_At_Foreground(Nest_Trader_Form.Nest_Trader_Form_Instance.Nest_Trader_Id)) * { * Thread.Sleep(300); * * if (!Nest_Trader_Form.Nest_Trader_Form_Instance.Nest_Trader_Process_Run(Nest_Trader_Form.Nest_Trader_Form_Instance.Nest_Trader_Process_Id)) * { * return; * } * } * */ } SendKeys.SendWait(Keys_Message); SendKeys.Flush(); Thread.Sleep(Sleep_Time); } }