Panel Region Screenshot Helper
A dashboard EA or indicator that wants to publish just its own panel - for documentation, a support ticket, or a CodeBase screenshot - has no built-in way to do it: ChartScreenShot() writes an image of the whole chart, panel included, with no region parameter. This library captures the full chart to a temporary file and then does the cropping itself by reading and rewriting the BMP format directly - there is no image library shipped with the platform to lean on. Only uncompressed 24-bit BMP is supported. GIF and PNG are genuinely compressed formats with real encoders/decoders behind them, not something to hand-roll inside a header; both filenames passed to CaptureRegion() must end in ".bmp", and anything else is refused before a capture is even attempted rather than silently producing a corrupt file. The crop itself walks the BMP's bottom-up row storage explicitly, converting the caller's top-left-origin rectangle (the same frame OBJPROP_XDISTANCE/YDISTANCE and mouse events use) into the file's actual row order, and pads each output row to the BMP format's required 4-byte boundary - getting either of those wrong produces a file that "looks right" in a hex editor but renders as diagonally-skewed garbage in an image viewer. ChartScreenShot() only queues the capture; it does not write the file synchronously. CaptureRegion() polls for the temp file to both exist and have a stable size across two checks before attempting to read it, rather than assuming the file is ready the instant the call returns. Notes and limitations - Only uncompressed 24-bit BMP is supported (the format ChartScreenShot produces when given a ".bmp" filename in this MetaEditor build). GIF and PNG filenames are refused outright rather than mishandled. - Only bottom-up BMP (positive height field) is handled - the format ChartScreenShot writes. A top-down BMP from another source is rejected. - The requested rectangle is clipped to the captured image's bounds rather than failing when a panel sits flush against a chart edge; LastCroppedWidth()/Height() report the actual output size. - Files are written into MQL4's sandboxed Files folder, like every MQL4 file operation - there is no way to write directly outside it. - No money is at risk. This library only reads/writes image files and chart objects.
Script · MT4 · v1.0 · Free
About Panel Region Screenshot Helper
Panel Region Screenshot Helper is a script for MetaTrader 4. MQL source code included.
Files in the download: PanelRegionScreenshot.mqh, PanelRegionScreenshot.txt, PanelRegionScreenshotDemo.mq4.
How to install
- Download the ZIP from your PolyMaria library and unzip it.
- In MetaTrader 4 open File → Open Data Folder, then go to MQL4 → Scripts.
- Copy the .mq4 file(s) there. Put any .mqh files in MQL4 → Include.
- Open the .mq4 file in MetaEditor and press Compile (F7) if MetaTrader does not show it.
- Drag the script onto a chart to run it once.
Tags: Dashboards & Scanners · MT4 Script · MQL4 Source Code