2012-07-10 174 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 s。

+0

非常感谢。这是错误....... :) – lakshman 2012-07-10 14:42:53