
c# 使用BitBlt函数在窗体上画图的问题 10
我想自己重新封装form,现在要写WM_PAINT消息的处理,按照WIN32的画图方法,我是这样做的:PAINTSTRUCTps=newPAINTSTRUCT();Int...
我想自己重新封装form,现在要写WM_PAINT消息的处理,按照WIN32的画图方法,我是这样做的:
PAINTSTRUCT ps = new PAINTSTRUCT();
IntPtr hdc = WinApi.BeginPaint(handle, ref ps);
IntPtr hdcMem = WinApi.CreateCompatibleDC(hdc);
Bitmap b = new Bitmap("1.bmp");
IntPtr hBitmap = b.GetHbitmap();
IntPtr Bitmap = IntPtr.Zero;
WinApi.GetObject(hBitmap, 24, Bitmap);
WinApi.SelectObject(hdcMem, Bitmap);
WinApi.BitBlt(hdc, 0, 0, b.Width, b.Height, hdcMem, 0, 0, 0xCC0020);
WinApi.DeleteDC(hdcMem);
WinApi.EndPaint(handle, ref ps);
WinApi.DeleteObject(hBitmap);
WinApi.DeleteObject(Bitmap);
这些代码在Win32程序中可以运行,但是在C#中死活画不出来,永远是一片白色。
要怎么样才能画出这个图片呢 展开
PAINTSTRUCT ps = new PAINTSTRUCT();
IntPtr hdc = WinApi.BeginPaint(handle, ref ps);
IntPtr hdcMem = WinApi.CreateCompatibleDC(hdc);
Bitmap b = new Bitmap("1.bmp");
IntPtr hBitmap = b.GetHbitmap();
IntPtr Bitmap = IntPtr.Zero;
WinApi.GetObject(hBitmap, 24, Bitmap);
WinApi.SelectObject(hdcMem, Bitmap);
WinApi.BitBlt(hdc, 0, 0, b.Width, b.Height, hdcMem, 0, 0, 0xCC0020);
WinApi.DeleteDC(hdcMem);
WinApi.EndPaint(handle, ref ps);
WinApi.DeleteObject(hBitmap);
WinApi.DeleteObject(Bitmap);
这些代码在Win32程序中可以运行,但是在C#中死活画不出来,永远是一片白色。
要怎么样才能画出这个图片呢 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询