2012-07-10 4 views
1

C++을 사용하여 마우스 이미지를 얻고 싶었습니다. 내가 가지고있는 코드를
How to get mouse cursor icon VS c++ 질문에서 사용했습니다. 나는 Visual Studio 2010 IDE를 사용했다. 나는 C++ win32 프로젝트를 생성하고 그 코드 스 니펫을 _tmain 메소드에 입력했다. 누락 된 구조 (CURSORINFO 및 ICONINFO)도 추가했다. 프로젝트를 빌드 한 후 오류 콘솔이 표시됩니다.캡쳐 마우스 커서 아이콘 C++

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; 
} 

답변

3

Windows SDK 헤더에 선언 된 struct을 다시 정의하지 마십시오. 이것이 오류의 원인 일 수 있습니다.

기본적으로이 추가

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

을 그 stdafx.h 이미 그러하지 아니하다. 그런 경우 자신의 typedef 개를 제거하십시오.

+0

정말 고마워요. 그것은 오류입니다 ....... :) – lakshman