MQL4 - automated forex trading   /  

Forum

using SendFTP() How to copy to clipboard?

Back to topics list To post a new topic, please log in or register

avatar
110
ricx 2010.03.25 11:06 
Guys i need help with coding...
The goal is to... "take screen shot" (done) and "send it to ftp server" (done) then "copy file link to windows clipboard" (problem)

This is the code i use, for the script:

//create a filename based on "year-month-day_hour minute symbol"
  string filename = TimeYear(TimeCurrent())+"-"+TimeMonth(TimeCurrent())+"-"+TimeDay(TimeCurrent())+"_"+TimeHour(TimeCurrent())+""+TimeMinute(TimeCurrent())+"-"+Symbol(); 

//take screenshot of current chart
  if(!WindowScreenShot(filename+".gif",1280,600,-1,-1,-1)) GetLastError();

//send "year-month-day_hour minute symbol.gif" to specified ftp server
  else if(!SendFTP(filename+".gif","/Journal/Current Month/")) GetLastError();

/*when send is complete and no error, copy the entire link to clipboard.
example: "http://www.someftpsite.com/someftpfolder/year-month-day_hour minute symbol.gif" is copied into the clipboard so we can paste that link text anywhere we need.
Please help me how to do this?? */
:'(
All about Automated Trading Championship: Reporting the Championship 2006

All about Automated Trading Championship: Reporting the Championship 2006

This article contains Weekly Reports of the ATC 2006. These materials are like snapshots, they are interesting-to-read not only during the Championship, but years later as well.


avatar
876
7bit 2010.03.25 15:40 
The easiest way is to call Alert() with the link. You can the select the text (in the upper gray area, not in the list) and copy it into the clipboard.

Directly copying into the clipboard is possible only with some direct calls into the windows API: http://www.codeproject.com/KB/clipboard/archerclipboard1.aspx. These naked windows API calls always look like it is really great "fun" using them, especially from mql4 which has not the ability to define data structures :-/

avatar
1138
jjc 2010.03.25 16:06 
ricx:
The goal is to... "take screen shot" (done) and "send it to ftp server" (done) then "copy file link to windows clipboard" (problem)
I find it a little hard to believe that there isn't a better way to achieve whatever overall aim you have in mind, but the following MQL4 code will set the clipboard with a specified piece of text:

#import "kernel32.dll"
   int GlobalAlloc(int Flags, int Size);
   int GlobalLock(int hMem);
   int GlobalUnlock(int hMem);
   int GlobalFree(int hMem);
   int lstrcpyA(int ptrhMem, string Text);
#import


#import "user32.dll"
   int OpenClipboard(int hOwnerWindow);
   int EmptyClipboard();
   int CloseClipboard();
   int SetClipboardData(int Format, int hMem);
#import

#define GMEM_MOVEABLE   2
#define CF_TEXT         1

// Copies the specified text to the clipboard, returning true if successful
bool CopyTextToClipboard(string Text)
{
   bool bReturnvalue = false;
   
   // Try grabbing ownership of the clipboard 
   if (OpenClipboard(0) != 0) {
      // Try emptying the clipboard
      if (EmptyClipboard() != 0) {
         // Try allocating a block of global memory to hold the text 
         int lnString = StringLen(Text);
         int hMem = GlobalAlloc(GMEM_MOVEABLE, lnString + 1);
         if (hMem != 0) {
            // Try locking the memory, so that we can copy into it
            int ptrMem = GlobalLock(hMem);
            if (ptrMem != 0) {
               // Copy the string into the global memory
               lstrcpyA(ptrMem, Text);            
               // Release ownership of the global memory (but don't discard it)
               GlobalUnlock(hMem);            

               // Try setting the clipboard contents using the global memory
               if (SetClipboardData(CF_TEXT, hMem) != 0) {
                  // Okay
                  bReturnvalue = true;   
               } else {
                  // Failed to set the clipboard using the global memory
                  GlobalFree(hMem);
               }
            } else {
               // Meemory allocated but not locked
               GlobalFree(hMem);
            }      
         } else {
            // Failed to allocate memory to hold string 
         }
      } else {
         // Failed to empty clipboard
      }
      // Always release the clipboard, even if the copy failed
      CloseClipboard();
   } else {
      // Failed to open clipboard
   }

   return (bReturnvalue);
}


avatar
110
ricx 2010.03.25 16:39 
@7bit & jjc Thank you very much :)
there are many ways to achieve "the clipboard" goals... wow... :D

again, thanks guys.

avatar
1
goddoes8 2012.01.20 16:29 

The following code copy text to clipboard.

I need an opposite function.

Could you help me copy text from clipboard?

string CopyTextFromClipboard()

{

}

The following code is by jjc.

jjc 2010.03.25 16:06

#import "kernel32.dll"
   int GlobalAlloc(int Flags, int Size);
   int GlobalLock(int hMem);
   int GlobalUnlock(int hMem);
   int GlobalFree(int hMem);
   int lstrcpyA(int ptrhMem, string Text);
#import


#import "user32.dll"
   int OpenClipboard(int hOwnerWindow);
   int EmptyClipboard();
   int CloseClipboard();
   int SetClipboardData(int Format, int hMem);
#import

#define GMEM_MOVEABLE   2
#define CF_TEXT         1

// Copies the specified text to the clipboard, returning true if successful
bool CopyTextToClipboard(string Text)
{
   bool bReturnvalue = false;
   
   // Try grabbing ownership of the clipboard 
   if (OpenClipboard(0) != 0) {
      // Try emptying the clipboard
      if (EmptyClipboard() != 0) {
         // Try allocating a block of global memory to hold the text 
         int lnString = StringLen(Text);
         int hMem = GlobalAlloc(GMEM_MOVEABLE, lnString + 1);
         if (hMem != 0) {
            // Try locking the memory, so that we can copy into it
            int ptrMem = GlobalLock(hMem);
            if (ptrMem != 0) {
               // Copy the string into the global memory
               lstrcpyA(ptrMem, Text);            
               // Release ownership of the global memory (but don't discard it)
               GlobalUnlock(hMem);            

               // Try setting the clipboard contents using the global memory
               if (SetClipboardData(CF_TEXT, hMem) != 0) {
                  // Okay
                  bReturnvalue = true;   
               } else {
                  // Failed to set the clipboard using the global memory
                  GlobalFree(hMem);
               }
            } else {
               // Meemory allocated but not locked
               GlobalFree(hMem);
            }      
         } else {
            // Failed to allocate memory to hold string 
         }
      } else {
         // Failed to empty clipboard
      }
      // Always release the clipboard, even if the copy failed
      CloseClipboard();
   } else {
      // Failed to open clipboard
   }

   return (bReturnvalue); 

}

Back to topics list  

To add comments, please log in or register