4

マウス カーソルの下のピクセルの色を返すには、高速なコマンド ライン アプリが必要です。

これを VC++ でビルドするにはどうすればよいですか。これに似たものが必要ですが、理想的には .NET ではないので、1 秒間に何度も実行できますか?

4

1 に答える 1

15

私の頭の上から、簡単な方法:

#include <stdio.h>
#include <Windows.h>

int main(void) {
    POINT p;
    COLORREF color;
    HDC hDC;
    BOOL b;

    // Get the device context for the screen
    hDC = GetDC(NULL);
    if (hDC == NULL)
        return 3;

    // Get the current cursor position
    b = GetCursorPos(&p);
    if (!b)
        return 2;

    // Retrieve the color at that position
    color = GetPixel(hDC, p.x, p.y);
    if (color == CLR_INVALID)
        return 1;

    // Release the device context again
    ReleaseDC(GetDesktopWindow(), hDC);

    printf("%i %i %i", GetRValue(color), GetGValue(color), GetBValue(color));
    return 0;
}

ETA:少なくとも私にとってはうまくいっているようです。

ETA2:いくつかのエラー チェックを追加しました

ETA3:コメント付きのコード、コンパイル済みの実行可能ファイル、および Visual Studio ソリューションは、私の SVN リポジトリにあります。

于 2010-06-20T10:53:28.367 に答える