I noticed a small bug in my remote desktop application related to drawing the cursor of the remote machine and im not sure how to solve it. The problem is that sometime, the cursor is not drawn at the proper location depending on the cursor. Also im using a weird hack to make it work for windows 7 and above and i don't think that's the right way to do it.
Here's the code im using right now:
void CScreenshot::DrawScreenCursor(HDC hDC)
{
CURSORINFO CursorInfo;
CursorInfo.cbSize = sizeof(CURSORINFO);
GetCursorInfo(&CursorInfo);
static DWORD Version = WinVer.DetectWindowsVersion();
//static HCURSOR hCur = LoadCursor(NULL, IDC_ARROW);
DWORD CursorWidth = GetSystemMetrics(SM_CXCURSOR);
DWORD CursorHeight = GetSystemMetrics(SM_CYCURSOR);
POINT CursorPos;
GetCursorPos(&CursorPos);
// Needed for XP or older windows
if(Version < _WIN_VISTA_){
CursorPos.x -= CursorWidth >> 2;
CursorPos.y -= CursorHeight >> 2;
}
DrawIconEx(hDC, CursorPos.x, CursorPos.y, CursorInfo.hCursor, CursorWidth, CursorHeight, 0, NULL, DI_NORMAL);
}
If the cursor is the default arrow, this work fine, but if the cursor change for, let say, the resize cursor, then it's offset a little.
Now, after reading this post, im pretty sure this function could solve my problem, but im not sure how to do it.
The question is, how do i get the icon from the current cursor (so i can call GetIconInfo() with the right cursor)?
And, why do i need to divide the cursor width by 4 in recent version of windows? It's like i have all the pieces of the puzzle but i don't know how to make them fit togeter... Maybe if i could debug this or something that could help a lot.
Note: The mouse click always happen at the right spot, it's just the cursor that's offset a little.
EDIT: I just realised im already getting the cursor from GetCursorInfo(), but im still lost on how to solve the problem. Maybe the width and height im getting are wrong?
Any help appreciated.