Cags
Well-known member
I wasnt sure whether to place this in the Graphics section or the Interop section, but eventually decided on here.
My problem is as follows, the following code works as I expect it to....
It copies a small section of the Bitmap.bmp to the screen. After getting this working I decided to try and buffer it before blitting it to the screen. So I amended the code as follows.
The problem is this section of code simply draws a black square rather than a small section of the Bitmap.bmp as I expected. Has anyone got any idea what Im doing wrong here?
Before I forget the API methods are declared as follows, Im pretty sure they are all right so I dont think thats the problem.
My problem is as follows, the following code works as I expect it to....
C#:
this.Capture = true;
formHandle = GetCapture();
this.Capture = false;
formDC = GetDC(formHandle);
spriteDC = CreateCompatibleDC(formDC);
spriteBitmap = SHLoadDIBitmap(@"\My Documents\Cags\Bitmap.bmp");
SelectObject(spriteDC, spriteBitmap);
// draw sprite to form
BitBlt(formDC, 0, 0, 25, 25, spriteDC, 0, 0, SRCCOPY);
C#:
this.Capture = true;
formHandle = GetCapture();
this.Capture = false;
formDC = GetDC(formHandle);
memoryDC = CreateCompatibleDC(formDC);
memoryBitmap = CreateCompatibleBitmap(memoryDC, this.Width, this.Height);
SelectObject(memoryDC, memoryBitmap);
spriteDC = CreateCompatibleDC(formDC);
spriteBitmap = SHLoadDIBitmap(@"\My Documents\Cags\Bitmap.bmp");
SelectObject(spriteDC, spriteBitmap);
// draw sprite to buffer
BitBlt( memoryDC, 25, 25, 25, 25, spriteDC, 26, 26, SRCCOPY );
// draw buffer to form
BitBlt( formDC, 25, 25, 25, 25, memoryDC, 25, 25, SRCCOPY);
Before I forget the API methods are declared as follows, Im pretty sure they are all right so I dont think thats the problem.
C#:
[DllImport("coredll.dll")]
public static extern int BitBlt(IntPtr hdcDest, int nXDest, int nYDest, int nWidth, int nHeight, IntPtr hdcSrc, int nXSrc, int nYSrc, uint dwRop);
[DllImport("coredll.dll")]
public static extern IntPtr SHLoadDIBitmap(string szFileName);
[DllImport("coredll.dll")]
static extern IntPtr CreateCompatibleBitmap(IntPtr hdc, int nWidth, int nHeight);
[DllImport("coredll.dll")]
public static extern IntPtr CreateCompatibleDC(IntPtr hdc);
[DllImport("coredll.dll")]
public static extern IntPtr GetDC(IntPtr hWnd);
[DllImport("coredll.dll")]
public static extern IntPtr GetCapture();
[DllImport("coredll.dll")]
static extern IntPtr SelectObject(IntPtr hdc, IntPtr hgdiobj);
const int SRCCOPY = 0x00CC0020;