Glad to see some people never change, Tony!
Thank you, yes, I did make a mistake in replying too fast to Kerry. After testing out my recommendation, showing the form modally via the Application or Windows, still throws the error. To get around it, you could go really hokie:
- Take a screen cap of the AutoCAD window [see below]
- Size the dialog to the AutoCAD Window and position it over it
- Add the screen cap as the form's background image
- Use Show() instead of ShowModalDialog()
- Do the processing and close the form
Not pretty, but it works.
public static Image CaptureWindow(IntPtr handle)
{
// get te hDC of the target window
IntPtr hdcSrc = User32.GetWindowDC(handle);
// get the size
Win32.RECT windowRect = new Win32.RECT();
User32.GetWindowRect(handle, windowRect);
int width = windowRect.right - windowRect.left;
int height = windowRect.bottom - windowRect.top;
// create a device context to copy to
IntPtr hdcDest = GDI32.CreateCompatibleDC(hdcSrc);
// create a bitmap to copy it to,
// using GetDeviceCaps to get the width/height
IntPtr hBitmap = GDI32.CreateCompatibleBitmap(hdcSrc, width, height);
// select the bitmap object
IntPtr hOld = GDI32.SelectObject(hdcDest, hBitmap);
// bitblt over
GDI32.BitBlt(hdcDest, 0, 0, width, height, hdcSrc, 0, 0, GDI32.SRCCOPY);
// restore selection
GDI32.SelectObject(hdcDest, hOld);
// clean up
GDI32.DeleteDC(hdcDest);
User32.ReleaseDC(handle, hdcSrc);
// get a .NET image object for it
Image img = Image.FromHbitmap(hBitmap);
// free up the Bitmap object
GDI32.DeleteObject(hBitmap);
return img;
}