0
    [DllImport("user32.dll")]
    public static extern int FindWindow(string lpClassName, string lpWindowName);
    [DllImport("user32.dll")]
    public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);

像这样。我两个都需要。如果我选择 intptr,它不能正确转换为 int,因此 postmessage 等东西会失败,否则,需要“句柄”的东西会失败,因为它应该是指针。

        Bitmap thisScreenshot = new Bitmap(Width, Height);
        Graphics gfxScreenshot = Graphics.FromImage(thisScreenshot);
        IntPtr hdcBitmap = gfxScreenshot.GetHdc();
        PrintWindow(handle, hdcBitmap, 0);
        gfxScreenshot.ReleaseHdc(hdcBitmap);

我基本上想执行这个,同时也有我的 int findwindow 函数。有什么想法吗?Findwindow 也是句柄,对吧?

4

2 回答 2

2

使用返回 int 的版本是不正确的。FindWindow 返回一个窗口句柄,它总是 IntPtr。您需要改正您的 PostMessage 声明:

[DllImport("user32.dll")]
public static extern bool PostMessage(IntPtr hWnd, int msg, IntPtr wp, IntPtr lp);
于 2012-07-27T10:17:20.107 回答
0

给函数一个不同的名称并使用入口点来指定原始名称

[DllImport("user32.dll")]
public static extern int FindWindow(string lpClassName, string lpWindowName);
[DllImport("user32.dll", EntryPoint="FindWindow")]
public static extern IntPtr FindWindowA(string lpClassName, string lpWindowName);
于 2012-07-27T10:18:31.390 回答