Question

I have a form that I am attempting to override the WndProc subroutine on. I am using GetDCEx to get a DC handle to my form. According to Microsoft's documentation on using GetDCEx, my form must have the CS_OWNDC or the CS_PARENTDC flag set my window class in order to use GetDCEx. According to Spy++, my window does not have these class attributes. My question is, how can I assign CS_OWNDC or make the form owner-drawable so I can use GetDCEx in my program? I am using C#, by the way.

Was it helpful?

Solution

I think you should override CreateParams in your code like this:

/// <summary>
/// Overrides the control's class style parameters.
/// </summary>
protected override CreateParams CreateParams
{
    get
    {
    Int32 CS_VREDRAW = 0x1;
    Int32 CS_HREDRAW = 0x2;
    Int32 CS_OWNDC = 0x20;
    CreateParams cp = base.CreateParams;
    cp.ClassStyle = cp.ClassStyle | CS_VREDRAW | CS_HREDRAW | CS_OWNDC | ...;
    return cp;
    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top