Does anyone have any experience in using the ComboBox control?
I'm trying to use the ComboBox control that is part of the standard MQL4 library. Creating it is very simple, but when I click it to open the list, it doesn't open.
I do .Create, then .AddItem a few times, and it shows fine on the chart, except that when I click it to show the list of items it doesn't do anything.
It's working fine in MT5, just not in MT4.
I have only been able to find the page below:
https://www.mql5.com/en/docs/standardlibrary/controls/ccombobox
Since it's included in the standard MQL4 library I can only assume that it's supposed to work?
//+------------------------------------------------------------------+ //| Alerts.mq4 | //| Copyright 2023,Obunadike Chioma | //| https://www.t.me/devbidden | //+------------------------------------------------------------------+ #property copyright "Copyright 2023,Obunadike Chioma" #property link "https://t.me/devbidden" #property version "1.00" #property strict #property indicator_chart_window #include <Controls\Dialog.mqh> #include <Controls\Button.mqh> #include <Controls\Edit.mqh> #include <Controls\Panel.mqh> #include <Controls\Label.mqh> #include <Controls\SpinEdit.mqh> #include <Controls\Button.mqh> #include <Controls\ComboBox.mqh> CAppDialog app; CPanel panel; CEdit edit1; CButton btn1; CComboBox cbox; CComboBox box1; CLabel label1; CLabel label2; CLabel label3; #define PANEL_WIDTH 350 #define PANEL_HEIGHT 80 //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int OnInit() { app.Create(0,"Alert Panel ",0, 0, 0,PANEL_WIDTH,PANEL_HEIGHT); int total = app.ControlsTotal(); CWndClient*myclient; for(int i = 0; i < total; i++) { CWnd*obj = app.Control(i); string name = obj.Name(); if(StringFind(name,"Client")>0) { CWndClient *client = (CWndClient*)obj; client.ColorBackground(clrLavender); myclient= client; ChartRedraw(); } if(StringFind(name,"Back")>0) { CPanel*panel2 = (CPanel*) obj; panel2.ColorBackground(clrLavender); ChartRedraw(); } if(StringFind(name,"Caption")>0) { CEdit*edit = (CEdit*) obj; edit.ColorBackground(clrLavender); ChartRedraw(); } if(StringFind(name,"Border")>0) { CPanel*panel3 = (CPanel*) obj; panel3.ColorBorder(clrLavender); ChartRedraw(); } } app.Run(); app.Caption(" "); cbox.Create(0,"boxes",0,90,20,170,40); app.Add(cbox); cbox.AddItem("CA"); cbox.AddItem("CB"); string lot = cbox.Select(); Print (lot); cbox.ListViewItems(2); edit1.Create(0,"edit1",0,10,20,80,40); app.Add(edit1); box1.Create(0,"box1",0,180,20,260,40); app.Add(box1); box1.ItemAdd("Price",0); box1.ItemAdd("EMA",0); box1.ItemAdd("LOD",0); box1.ItemAdd("HOD",0); box1.ItemAdd("YH",0); box1.ItemAdd("YL",0); box1.ItemAdd("FH",0); box1.ItemAdd("FL",0); box1.Select(8); box1.ListViewItems(8); label1.Create(0,"label1",0,10,1,80,30); label1.Text("Price / EMA : "); label1.Font("Bahnschrift Light Condensed"); label1.FontSize(12); label1.Color(clrBlack); app.Add(label1); label2.Create(0,"label2",0,90,1,170,30); label2.Text("Condition : "); label2.Font("Bahnschrift Light Condensed"); label2.FontSize(13); label2.Color(clrBlack); app.Add(label2); label3.Create(0,"label3",0,180,1,260,30); label3.Text("Parameter : "); label3.Font("Bahnschrift Light Condensed"); label3.FontSize(13); label3.Color(clrBlack); app.Add(label3); btn1.Create(0,"button",0,270,20,330,40); btn1.ColorBackground(clrLimeGreen); btn1.ColorBorder(clrBlack); btn1.Text("Set"); app.Add(btn1); return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ int OnCalculate(const int rates_total, const int prev_calculated, const datetime &time[], const double &open[], const double &high[], const double &low[], const double &close[], const long &tick_volume[], const long &volume[], const int &spread[]) { //--- //--- return value of prev_calculated for next call return(rates_total); } //+------------------------------------------------------------------+ void OnDeinit(const int reason) { app.Destroy(reason); box1.Destroy(reason); cbox.Destroy(reason); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void OnChartEvent(const int id, const long &lparam, const double &dparam, const string &sparam) { app.ChartEvent(id,lparam,dparam,sparam); box1.OnEvent(id,lparam,dparam,sparam); cbox.OnEvent(id,lparam,dparam,sparam); } //+------------------------------------------------------------------+
This is the code mate
Run the app only when all controls are added.
So put
app.Run();
at the end of OnInit.
As the Controls are added to the app which is a container and handles the Events, you don't need to do that for each control element:
void OnChartEvent(const int id, const long &lparam, const double &dparam, const string &sparam) { app.ChartEvent(id,lparam,dparam,sparam); /*box1.OnEvent(id,lparam,dparam,sparam); cbox.OnEvent(id,lparam,dparam,sparam);*/ }
Same with destroying them:
void OnDeinit(const int reason) { app.Destroy(reason); /*box1.Destroy(reason); cbox.Destroy(reason);*/ }
Pls Help me to fix my problem Guys
if(!xCmbRiskLot.Create(0,"Test",0,60,200,20,20)) Comment("aabbcc");
ask:
why cant I create combobox..?
it always result false, but when I print the GetLastError() it result 0
//+------------------------------------------------------------------+ //| Trading Assisten.mq4 | //| Copyright 2018, MetaQuotes Software Corp. | //| https://www.mql5.com | //+------------------------------------------------------------------+ #property copyright "Copyright 2018, MetaQuotes Software Corp." #property link "https://www.mql5.com" #property version "1.00" #property strict #include <Controls\Dialog.mqh> #include <Controls\Button.mqh> #include <Controls\Label.mqh> #include <Controls\ComboBox.mqh> #define xPanelName "Trading Assistant" #define xTabMarket "TabMarket" #define xTabPending "TabPending" #define xButtonBuy "ButtonBuy" #define xButtonSell "ButtonSell" #define xLblWaktu "LblWaktu" #define xLblSpread "LblSpread" #define xButtonBuyStop "ButtonBuyStop" #define xButtonSellStop "ButtonSellStop" #define xButtonBuyLimit "ButtonBuyLimit" #define xButtonSellLimit "ButtonSellLimit" #define xComboRiskLot "ComboRiskLot" CAppDialog Panel; CButton TabMarket; CButton TabPending; CButton ButtonBuy; CButton ButtonSell; CLabel LblWaktu; CLabel LblSpread; CButton ButtonBuyStop; CButton ButtonSellStop; CButton ButtonBuyLimit; CButton ButtonSellLimit; CComboBox xCmbRiskLot; string xNmHari[7]; int OnInit() {xNmHari[0]="Minggu";xNmHari[1]="Senin";xNmHari[2]="Selasa";xNmHari[3]="Rabu"; xNmHari[4]="Kamis";xNmHari[5]="Jumat";xNmHari[6]="Sabtu"; CreatePanel(); return(INIT_SUCCEEDED);} void OnDeinit(const int reason) {Panel.Destroy(reason);} void CreatePanel() {Panel.Create(0,xPanelName,0,10,10,550,400); TabMarket.Create(0,xTabMarket,0,250,5,0,0); Panel.Add(TabMarket); TabMarket.Width(80);TabMarket.Height(30); TabMarket.Text("Market");TabMarket.FontSize(15);TabMarket.ColorBackground(clrWhiteSmoke);TabMarket.ColorBorder(clrWhiteSmoke); TabPending.Create(0,xTabPending,0,350,5,0,0); Panel.Add(TabPending); TabPending.Width(80);TabPending.Height(30); TabPending.Text("Pending");TabPending.FontSize(15);TabPending.ColorBackground(clrWhiteSmoke);TabPending.ColorBorder(clrWhiteSmoke); CreateTabMarket(); CreateTabPending(); // if(!xCmbRiskLot.Create(0,"Test",0,60,200,20,20)) Comment(GetLastError()); Panel.Add(xCmbRiskLot); // xCmbRiskLot.Width(80); // xCmbRiskLot.Height(30); xCmbRiskLot.ItemAdd("Risk "); xCmbRiskLot.ItemAdd("Lots"); xCmbRiskLot.Select(0); xCmbRiskLot.ListViewItems(2); Panel.Run(); } void CreateTabMarket() {ButtonBuy.Create(0,xButtonBuy,0,250,60,0,0); Panel.Add(ButtonBuy); ButtonBuy.Width(135);ButtonBuy.Height(30); ButtonBuy.FontSize(12);ButtonBuy.ColorBackground(clrPaleGreen); ButtonSell.Create(0,xButtonSell,0,390,60,0,0); Panel.Add(ButtonSell); ButtonSell.Width(135);ButtonSell.Height(30); ButtonSell.FontSize(12);ButtonSell.Color(clrWhite);ButtonSell.ColorBackground(clrRed); LblWaktu.Create(0,xLblWaktu,0,250,100,0,0); Panel.Add(LblWaktu); LblWaktu.FontSize(12); LblSpread.Create(0,xLblSpread,0,250,120,0,0); Panel.Add(LblSpread); LblSpread.FontSize(12); ShowTabMarket();} void CreateTabPending() {ButtonBuyStop.Create(0,xButtonBuyStop,0,250,60,0,0); Panel.Add(ButtonBuyStop); ButtonBuyStop.Text("Buy Stop"); ButtonBuyStop.Width(135);ButtonBuyStop.Height(30); ButtonBuyStop.FontSize(12);ButtonBuyStop.ColorBackground(clrPaleGreen); ButtonBuyLimit.Create(0,xButtonBuyLimit,0,250,95,0,0); Panel.Add(ButtonBuyLimit); ButtonBuyLimit.Text("Buy Limit"); ButtonBuyLimit.Width(135);ButtonBuyLimit.Height(30); ButtonBuyLimit.FontSize(12);ButtonBuyLimit.ColorBackground(clrPaleGreen); ButtonSellStop.Create(0,xButtonSellStop,0,390,60,0,0); Panel.Add(ButtonSellStop); ButtonSellStop.Text("Sell Stop"); ButtonSellStop.Width(135);ButtonSellStop.Height(30); ButtonSellStop.FontSize(12);ButtonSellStop.ColorBackground(clrRed); ButtonSellLimit.Create(0,xButtonSellLimit,0,390,95,0,0); Panel.Add(ButtonSellLimit); ButtonSellLimit.Text("Sell Limit"); ButtonSellLimit.Width(135);ButtonSellLimit.Height(30); ButtonSellLimit.FontSize(12);ButtonSellLimit.ColorBackground(clrRed);} void ShowTabMarket() {ButtonBuyStop.Hide();ButtonBuyLimit.Hide();ButtonSellStop.Hide();ButtonSellLimit.Hide(); ButtonBuy.Show();ButtonSell.Show();LblWaktu.Show();LblSpread.Show(); TabMarket.ColorBackground(clrSilver);TabPending.ColorBackground(clrWhiteSmoke);} void ShowTabPending() {ButtonBuy.Hide();ButtonSell.Hide();LblWaktu.Hide();LblSpread.Hide(); ButtonBuyStop.Show();ButtonBuyLimit.Show();ButtonSellStop.Show();ButtonSellLimit.Show(); TabPending.ColorBackground(clrSilver);TabMarket.ColorBackground(clrWhiteSmoke);} void DisplayLabel() {string sHari=xNmHari[DayOfWeek()]+", "+IntegerToString(TimeDay(TimeCurrent()))+"/"+IntegerToString(TimeMonth(TimeCurrent()))+"/"+ IntegerToString(TimeYear(TimeCurrent()))+" "+TimeToString(TimeCurrent(),TIME_SECONDS); ButtonBuy.Text("Buy @ "+DoubleToString(Ask,Digits)); ButtonSell.Text("Sell @ "+DoubleToString(Bid,Digits)); LblWaktu.Text(sHari); LblSpread.Text("Spread: "+DoubleToString(MarketInfo(NULL,MODE_SPREAD)/10,2)+" pips");} void OnTick() {DisplayLabel(); } void OnChartEvent(const int id, const long &lparam, const double &dparam, const string &sparam) { Panel.ChartEvent(id,lparam,dparam,sparam); if(id==CHARTEVENT_OBJECT_CLICK) {if(sparam==xTabMarket) {ShowTabMarket();} else if(sparam==xTabPending) {ShowTabPending();} } }
- 2024.09.10
- www.mql5.com
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Does anyone have any experience in using the ComboBox control?
I'm trying to use the ComboBox control that is part of the standard MQL4 library. Creating it is very simple, but when I click it to open the list, it doesn't open.
I do .Create, then .AddItem a few times, and it shows fine on the chart, except that when I click it to show the list of items it doesn't do anything.
It's working fine in MT5, just not in MT4.
I have only been able to find the page below:
https://www.mql5.com/en/docs/standardlibrary/controls/ccombobox
Since it's included in the standard MQL4 library I can only assume that it's supposed to work?