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に行くと、それは適切にin​​tに変換できないので、postmessageなどは失敗します。そうでなければ、「handle」を必要とするものはポインタであるはずなので失敗します。

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

基本的には、intfindwindow関数を使用しながらこれを実行したいと思います。どのようにアイデア?また、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 に答える