1

C++ を使用してマウスの画像を取得したかったのです。
How to get mouse cursor icon VS c++ questionから得たコードを使用しました。Visual Studio 2010 IDE を使用しました。C++ win32 プロジェクトを作成し、そのコード スニペットを _tmain メソッドに入力し、欠落している構造 (CURSORINFO および ICONINFO) も追加しました。プロジェクトをビルドした後、エラーコンソールが表示されます

error C2664: 'GetCursorInfo' : cannot convert parameter 1 from 'CURSORINFO *' to 'PCURSORINFO'

このビルド エラーの理由は何ですか。説明できますか?これは私が構築したコードです。

#include "stdafx.h"
#include <windows.h>

int _tmain(int argc, _TCHAR* argv[])
{
    typedef struct _ICONINFO {
        BOOL    fIcon;
        DWORD   xHotspot;
        DWORD   yHotspot;
        HBITMAP hbmMask;
        HBITMAP hbmColor;
    } ICONINFO, *PICONINFO;

    typedef struct {
        DWORD   cbSize;
        DWORD   flags;
        HCURSOR hCursor;
        POINT   ptScreenPos;
    } CURSORINFO, *PCURSORINFO, *LPCURSORINFO;


    HDC hdcScreen = GetDC(NULL);
    HDC hdcMem = CreateCompatibleDC(hdcScreen);

    CURSORINFO cursorInfo = { 0 };
    cursorInfo.cbSize = sizeof(cursorInfo);

    if (::GetCursorInfo(&cursorInfo))
    {
        ICONINFO ii = {0};
        GetIconInfo(cursorInfo.hCursor, &ii);
        DeleteObject(ii.hbmColor);
        DeleteObject(ii.hbmMask);
        ::DrawIcon(hdcMem, cursorInfo.ptScreenPos.x - ii.xHotspot, cursorInfo.ptScreenPos.y -          ii.yHotspot, cursorInfo.hCursor);
    }
    return 0;
}
4

1 に答える 1

3

structWindows SDK ヘッダーで宣言されている s を再定義しないでください。これがおそらくエラーの原因です。

基本的にこれを追加します:

#include <Windows.h> // includes WinUser.h

それがすでに にある場合を除きstdafx.hます。そうである場合は、自分typedefの を削除します。

于 2012-07-10T14:40:14.857 に答える