//+------------------------------------------------------------------+ //| Demo_BitmapOffset.mq5 | //| Copyright 2011, MetaQuotes Software Corp. | //| http://www.mql5.com | //+------------------------------------------------------------------+ #property copyright "Copyright 2010, MetaQuotes Software Corp." #property link "http://www.mql5.com" #property version "1.00" #define X_left_top 50 #define Y_left_top 50 #define show_frame_time 20 #resource "\\Files\\thousands_rubies_galaxy.bmp"; #resource "\\Files\\space_wind.wav"; //+------------------------------------------------------------------+ //| Script program start function | //+------------------------------------------------------------------+ void OnStart() { //--- 照片文件名 "M85 Lenticular Galaxy" string image_resource="::Files\\thousands_rubies_galaxy.bmp"; string bitmap_label="bitmap"; //--- 创建对象 ObjectCreate(0,bitmap_label,OBJ_BITMAP_LABEL,0,0,0,0,0); //--- 设置左上角坐标点 ObjectSetInteger(0,bitmap_label,OBJPROP_XDISTANCE,X_left_top); ObjectSetInteger(0,bitmap_label,OBJPROP_YDISTANCE,Y_left_top); //--- 从资源中加载图像 bool set=ObjectSetString(0,bitmap_label,OBJPROP_BMPFILE,0,image_resource); //--- 如果失败,输出提示 if(!set) { PrintFormat("从文件中加载图像错误 %s. 错误码 %d", image_resource, GetLastError()); } //--- 得到图像尺寸 (需要用它来指定图像可视区域) long x_size=ObjectGetInteger(0,bitmap_label,OBJPROP_XSIZE); long y_size=ObjectGetInteger(0,bitmap_label,OBJPROP_YSIZE); PrintFormat("加载图像尺寸 %d x %d 点", x_size, y_size); //--- 图表刷新 ChartRedraw(); //--- 1 秒钟暂停用来显示整个图像 Sleep(1000); //--- 设置边框尺寸用于显示图像片段 ObjectSetInteger(0,bitmap_label,OBJPROP_XSIZE,x_size); //--- 计算可视范围的垂直尺寸 (图形高度的 1/3) long visual_y_size=y_size/3; //--- 设置可视高度 ObjectSetInteger(0,bitmap_label,OBJPROP_YSIZE,visual_y_size); //--- 设置图像内垂直帧的偏移 ObjectSetInteger(0,bitmap_label,OBJPROP_XOFFSET,0); //--- 设置背景 ObjectSetInteger(0,bitmap_label,OBJPROP_BACK,true); //--- 播放声音 PlaySound("::Files\\space_wind.wav"); //--- 开始 for(int j=0;j<5 && !_StopFlag;j++) { int i; // 相对于图像左上角的可视区域偏移 //--- 向下移动 for(i=0;i=0;i--) { ObjectSetInteger(0,bitmap_label,OBJPROP_YDISTANCE,Y_left_top+i); //--- 设置图像内垂直帧的偏移 ObjectSetInteger(0,bitmap_label,OBJPROP_YOFFSET,i); ChartRedraw(); //--- 画下一帧前暂停 Sleep(show_frame_time); } } //--- 最后显示完整帧 Sleep(3000); //--- 删除对象 ObjectDelete(0,bitmap_label); } //+------------------------------------------------------------------+