我在C ++中有下面的代码(不是完整的代码),想转换成C#。我只想使用user32.dll
C ++
HBITMAP image::takeImage(HWND handle, int x, int y, int w, int h, LPCWSTR fname ){
HDC hdcs = GetWindowDC(handle);
HDC hdcm = CreateCompatibleDC(hdcs);
HDC hdcp = CreateCompatibleDC(hdcs);
RECT rect;
GetWindowRect(handle, &rect);
hBitmap = CreateCompatibleBitmap( hdcs, w, h);
hBitmap2 = CreateCompatibleBitmap(hdcs, rect.right - rect.left, rect.bottom - rect.top);
HBITMAP hBitmapOld = (HBITMAP)SelectObject(hdcm, hBitmap);
int error = GetObject(hBitmap, sizeof(BITMAP), &Bitmap);
bool ret = PrintWindow(handle, hdcp, NULL);
BitBlt(hdcm, 0, 0, w, h, hdcp, x, y, SRCCOPY);
return ""; //something
}
我在下面的C ++函数的C#中寻找等效项。
GetWindowDC
-可以在这里找到此功能
[DllImport("user32.dll")]
static extern IntPtr GetWindowDC(IntPtr hWnd);
CreateCompatibleDC
GetWindowRect
CreateCompatibleBitmap
SelectObject
GetObject
PrintWindow
BitBlt
我从未从事过C ++。只是寻找等效的函数名称或文档链接。谢谢。
那是你需要的吗?
gdi32.dll
[DllImport("gdi32.dll",EntryPoint="DeleteDC")]
public static extern IntPtr DeleteDC(IntPtr hDc);
[DllImport("gdi32.dll",EntryPoint="DeleteObject")]
public static extern IntPtr DeleteObject(IntPtr hDc);
[DllImport("gdi32.dll",EntryPoint="BitBlt")]
public static extern bool BitBlt(IntPtr hdcDest,int xDest,
int yDest,int wDest,int hDest,IntPtr hdcSource,
int xSrc,int ySrc,int RasterOp);
[DllImport ("gdi32.dll",EntryPoint="CreateCompatibleBitmap")]
public static extern IntPtr CreateCompatibleBitmap(IntPtr hdc,
int nWidth, int nHeight);
[DllImport ("gdi32.dll",EntryPoint="CreateCompatibleDC")]
public static extern IntPtr CreateCompatibleDC(IntPtr hdc);
[DllImport ("gdi32.dll",EntryPoint="SelectObject")]
public static extern IntPtr SelectObject(IntPtr hdc,IntPtr bmp);
user32.dll
[DllImport("user32.dll", EntryPoint="GetDesktopWindow")]
public static extern IntPtr GetDesktopWindow();
[DllImport("user32.dll",EntryPoint="GetDC")]
public static extern IntPtr GetDC(IntPtr ptr);
[DllImport("user32.dll",EntryPoint="GetSystemMetrics")]
public static extern int GetSystemMetrics(int abc);
[DllImport("user32.dll",EntryPoint="GetWindowDC")]
public static extern IntPtr GetWindowDC(Int32 ptr);
[DllImport("user32.dll",EntryPoint="ReleaseDC")]
public static extern IntPtr ReleaseDC(IntPtr hWnd,IntPtr hDc);
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句