SetBkMode Transparent takes no effekt

From: Lukas Thanei (thanei_at_pro-design.it)
Date: 08/30/04


Date: Mon, 30 Aug 2004 14:17:32 +0200

Hi,

i'm developing a program to print out some richtext with pictures. My
problem is, that Im not able to output the richtext with transparent
background. I use the SetBkMode function and get no errors. When I run
GetBkMode I get the right mode, which I set before. However, the output
draws a filled rectangle instead of just writing the text over my orginal
background.

Any ideas? Im happy about every suggestion I get.

Thanks,
Lukas

Here's the code I use:

public int FormatRange(bool measureOnly, PrintPageEventArgs e, int charFrom,
int charTo) {

// Specify which characters to print
STRUCT_CHARRANGE cr;
cr.cpMin = charFrom;
cr.cpMax = charTo;

// Specify the area inside page margins
STRUCT_RECT rc;
rc.top = HundredthInchToTwips(e.MarginBounds.Top);
rc.bottom = HundredthInchToTwips(e.MarginBounds.Bottom);
rc.left = HundredthInchToTwips(e.MarginBounds.Left);
rc.right = HundredthInchToTwips(e.MarginBounds.Right);

// Specify the page area
STRUCT_RECT rcPage;
rcPage.top = HundredthInchToTwips(e.PageBounds.Top);
rcPage.bottom = HundredthInchToTwips(e.PageBounds.Bottom);
rcPage.left = HundredthInchToTwips(e.PageBounds.Left);
rcPage.right = HundredthInchToTwips(e.PageBounds.Right);

// Get device context of output device
IntPtr hdc = e.Graphics.GetHdc();

// Fill in the FORMATRANGE struct
STRUCT_FORMATRANGE fr;
fr.chrg = cr;
fr.hdc = hdc;
fr.hdcTarget = hdc;
fr.rc = rc;
fr.rcPage = rcPage;

// Non-Zero wParam means render, Zero means measure
Int32 wParam = (measureOnly ? 0 : 1);

// Allocate memory for the FORMATRANGE struct and
// copy the contents of our struct to this memory
IntPtr lParam = Marshal.AllocCoTaskMem( Marshal.SizeOf( fr ) );
Marshal.StructureToPtr(fr, lParam, false);

SetBkMode(hdc,TRANPARENT);
System.Diagnostics.Debug.WriteLine(GetBkMode(hdc).ToString());

int res = SendMessage(Handle, EM_FORMATRANGE, wParam, lParam);

// Free allocated memory
Marshal.FreeCoTaskMem(lParam);

// and release the device context
e.Graphics.ReleaseHdc(hdc);
return res;
}



Relevant Pages


Quantcast