The GetPageAsMetafile-Function returns very ofter Zero and I don't know why. Is there any chance to get the Error-Code?
Sometime when I am in the Debugger the function returns a correct handle and sometimes not. The last test result with the same original text (2 pages)
first time every thing okay, secound and third try no page loaded fourth try only page 2 loaded.
Here are some parts of my c# code
//// Part 1 Filling copy of the original text and try to get Metafiles
//////////////////////////////////////////////////////////////////////////
public TextDynamicPreviewDialog(WPDLLInt editorToBePreviewed)
{
InitializeComponent();
WPDLLInt editorToPreview = new WPDLLInt();
TextDynamicHelper.RegisterEditor(editorToPreview);
editorToPreview.Memo.LoadFromString(editorToBePreviewed.Memo.SaveToString(false, "RTF"), false, "RTF");
editorToPreview.SpecialTextAttr(SpecialTextSel.wpInsertpoints).Hidden = true;
editorToPreview.OnPaintWatermark += new WPDLLInt.PaintWatermarkEvent(TextEditor_OnPaintWatermark);
editorToPreview.Memo.ReformatAll(true, false);
pages = new Metafile[editorToPreview.Memo.TextCursor.PageCount];
for (int i = 0; i < pages.Length; i++)
{
editorToPreview.Memo.ReformatAll(false, false);
IntPtr metaHandle = editorToPreview.Memo.GetPageAsMetafile(i, 8);
if (metaHandle.ToInt32() == 0)
{
pages[i] = null;
Console.WriteLine("page " + i.ToString() + " not loaded");
}
else
{
Metafile aMetafile = new Metafile(metaHandle, true);
pages[i] = aMetafile;
}
}
editorToPreview.OnPaintWatermark -= TextEditor_OnPaintWatermark;
//// Part 2 OnPaintWatermark-Event
/////////////////////////////////////////////////////////////////////////////////
void TextEditor_OnPaintWatermark(object Sender, int Editor, int Mode, Graphics Canvas, float X, float Y, float X1, float Y1, float Xres, float Yres)
{
Canvas.DrawString("OnWatermark Editor=" +
Editor.ToString() + "; Seite=" + (Mode & 0xffff).ToString() + "; Pos1=" +
X.ToString() + "/" + Y.ToString() + "; Pos2=" +
X1.ToString() + "/" + Y1.ToString() + "; Auflösung=" +
Xres.ToString() + "/" + Yres.ToString(),
new Font("Arial", Convert.ToInt32(12 * Xres / Canvas.DpiX)), Brushes.BlueViolet, new Point(10, 10));
}