WindowScreenShot Issue

 

Good morning all.

I use the this code to take screenshot yet when I open the file there are no picture. Can somebody identify my dumb dumb. Many thanks in advance.

//+------------------------------------------------------------------+
//| Take  Screenshot                                                 |
//+------------------------------------------------------------------+
void TakeScreenshot(string folder)
//+------------------------------------------------------------------+
  {
   string year;
   string month;
   string day;
   string date;
   string time;

   switch(TimeYear(TimeCurrent()))
     {
      case 2017: year = "2017";break;
      case 2018: year = "2018";break;
      case 2019: year = "2019";break;
      case 2020: year = "2020";break;
      case 2021: year = "2021";break;
      case 2022: year = "2022";break;
      case 2023: year = "2023";break;
      case 2024: year = "2024";break;
      case 2025: year = "2025";break;
      default: year="Other";break;
     }

   switch(TimeMonth(TimeCurrent()))
     {
      case 1: month = "January";break;
      case 2: month = "February";break;
      case 3: month = "March";break;
      case 4: month = "April";break;
      case 5: month = "May";break;
      case 6: month = "June";break;
      case 7: month = "July";break;
      case 8: month = "August";break;
      case 9: month = "September";break;
      case 10: month = "October";break;
      case 11: month = "November";break;
      case 12: month = "December";break;
     }

   switch(TimeDayOfWeek(TimeCurrent()))
     {
      case 0: day = "Sunday";break;
      case 1: day = "Monday";break;
      case 2: day = "Tuesday";break;
      case 3: day = "Wednesday";break;
      case 4: day = "Thursday";break;
      case 5: day = "Friday";break;
      case 6: day = "Saturday";break;
     }

   date = IntegerToString(TimeDay(TimeCurrent()));
   time = TimeToStr(TimeCurrent(),TIME_MINUTES|TIME_SECONDS);

   string filename= folder+"\\"+year+"\\"+month+"\\"+day+" "+date+"\\"+time+".gif";
   int ChartWidth = guiGetChartWidth(hwnd);
   int ChartHeight= guiGetChartHeight(hwnd);

   bool TakeScreenShot=WindowScreenShot(filename,ChartWidth,ChartHeight);
  }
//+------------------------------------------------------------------+


 

 
  1.  bool TakeScreenShot=WindowScreenShot(filename,ChartWidth,ChartHeight);

    Where do you test the return code and the error?
              What are Function return values ? How do I use them ? - MQL4 and MetaTrader 4 - MQL4 programming forum
              Common Errors in MQL4 Programs and How to Avoid Them - MQL4 Articles

  2. string filename= folder+"\\"+year+"\\"+month+"\\"+day+" "+date+"\\"+time+".gif";
    Are you sure there is a folder "<data folder>\MQL4\files\<folder>\<year>\<month>\<day> <date>\"
 

Updated the code

   if(!WindowScreenShot(filename,ChartWidth,ChartHeight))
    Print ("Failed to take "+folder+"   ",GetLastError());

Got a 5004 error

ERR_FILE_CANNOT_OPEN


Yet the folder is being created in windows - refer to original post

 
Robert Browne:

Yet the folder is being created in windows - refer to original post

Your code is trying to create a filename such as 12:18:43.gif. Colons (:) in filenames are not permitted by Windows.
 
JC:
Your code is trying to create a filename such as 12:18:43.gif. Colons (:) in filenames are not permitted by Windows.

Thank you JC. Made the changes and all working now. 

Here is my code changes although I will be altering to get a more attractive file name.

   date = IntegerToString(TimeDay(TimeCurrent()));
   hour = IntegerToString(TimeHour(TimeCurrent()));
   minute = IntegerToString(TimeMinute(TimeCurrent()));

   string filename= folder+"\\"+Symbol()+"\\"+year+"\\"+month+"\\"+day+" "+date+"\\"+Symbol()+" "+day+" "+date+" "+month+" "+year+"     "+hour+"_"+minute+".gif";
   int ChartWidth = guiGetChartWidth(hwnd);
   int ChartHeight= guiGetChartHeight(hwnd);

   if(!WindowScreenShot(filename,ChartWidth,ChartHeight))
     Print ("Failed to take "+folder+"   ",GetLastError());
   else
     Print(folder+" successfully taken");
 
Robert Browne:

Here is my code changes although I will be altering to get a more attractive file name.

You could also do something like the following:

StringReplace(time, ":", "_");

By the way, guiGetChartWidth(hwnd) looks like it may turn into a Windows API call to get the chart dimensions, which is no longer necessary since MQL added ChartGetInteger(0, CHART_WIDTH_IN_PIXELS)

 
JC:

By the way, guiGetChartWidth(hwnd) looks like it may turn into a Windows API call to get the chart dimensions, which is no longer necessary since MQL added ChartGetInteger(0, CHART_WIDTH_IN_PIXELS)


I'm building a trading panel with the MT4GUI interface from the good people at fx1.net. I like their buttons and check boxes. But the big advantage is it produces tics allowing me to place manual trades using strategy tester. The guiGetChartWidth is one of their commands. 

Do you think there are any pros or cons to using a third party software command over and "in-house" command? (if I have used the word "in-house correctly, forgive me if I haven't.) 

 
Robert Browne:

Do you think there are any pros or cons to using a third party software command over and "in-house" command? (if I have used the word "in-house correctly, forgive me if I haven't.) 

Given the context, no, no pros or cons.

ChartGetInteger() avoids the need to turn on "Allow DLL imports", which prevents you selling things through the MQL Market or using MT4's built-in pseudo-VPS hosting. But neither of those sounds applicable here, and you will be using lots of other features which require "Allow DLL imports" to be turned on.

 

Many thanks for taking the time to answer my questions JC. Most appreciated.