Ask a questionAsk a question
 

AnswerLow cursor quality in high DPI

  • Saturday, November 07, 2009 5:27 AMAmol P Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Has Code

    My need is to get the current system cursor and draw it on a device context (DC). Operating system is Vista and Windows 7.
    To do this I am using GetCursorInfo API. I retrieve the cursor handle from CURSORINFO structure and then pass it to DrawIcon API to paint the cursor on DC.
    This works perfectly when system is set to normal DPI. The cursor quality is good and cursor size is exactly same as the system cursor.
    But when when DPI is changed to some high value, the cursor which is drawn is of low quality and also bigger in size than the system cursor.
    How to get the exact same cursor as the current system cursor even in High DPI? I even tried loading a custom cursor but even it has the same issue.

    Is there any other method to do this?

    Thanks 

    HCURSOR hcur;
    
    
    
    CURSORINFO cursorinfo;
    
    
    
    cursorinfo.cbSize = sizeof(CURSORINFO);
    
    
    
    if(GetCursorInfo(&cursorinfo))
    
    {
    
    	hcur = cursorinfo.hCursor;
    
    
    
    // Draw cursor on screen
    
    	HDC hdc = ::GetDC(NULL);
    
    	::DrawIcon(hdc,  100,  100, hcur);
    
    	DeleteDC(hdc);
    
    }
    

    Thanks, Amol Patki

Answers

  • Monday, November 09, 2009 5:56 AMAmol P Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     AnswerHas Code
    Thanks Nikita,
    Your reply was indeed helpful. I have voted it helpful.
    I tried with with DI_DEFAULLTSIZE but did not work.

    But DrawIconEx is the solution. I am positing the modified code here. (Note that DI_DEFAULLTSIZE is not used because using this flag gave same result as DrawIcon API)

    HCURSOR hcur;
    CURSORINFO cursorinfo;
    cursorinfo.cbSize = sizeof(CURSORINFO);
    if(GetCursorInfo(&cursorinfo))
    {
    	hcur = cursorinfo.hCursor;
    
             BITMAP bitmap;
    	GetObject(iconinfo.hbmColor, sizeof(BITMAP), &bitmap);
    
    // Draw cursor on screen
    
    	HDC hdc = ::GetDC(NULL);
    
    	::DrawIconEx(m_hMemDC, 100, 100, hcur, bitmap.bmWidth, bitmap.bmHeight, 0, NULL, DI_NORMAL);
    
    	DeleteDC(hdc);
    }
    

    Thanks, Amol Patki
    • Marked As Answer byAmol P Monday, November 09, 2009 5:59 AM
    •  

All Replies

  • Saturday, November 07, 2009 11:09 PMNikita Leontiev Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Try DrawIconEx with DI_DEFAULTSIZE flag.
  • Monday, November 09, 2009 5:56 AMAmol P Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     AnswerHas Code
    Thanks Nikita,
    Your reply was indeed helpful. I have voted it helpful.
    I tried with with DI_DEFAULLTSIZE but did not work.

    But DrawIconEx is the solution. I am positing the modified code here. (Note that DI_DEFAULLTSIZE is not used because using this flag gave same result as DrawIcon API)

    HCURSOR hcur;
    CURSORINFO cursorinfo;
    cursorinfo.cbSize = sizeof(CURSORINFO);
    if(GetCursorInfo(&cursorinfo))
    {
    	hcur = cursorinfo.hCursor;
    
             BITMAP bitmap;
    	GetObject(iconinfo.hbmColor, sizeof(BITMAP), &bitmap);
    
    // Draw cursor on screen
    
    	HDC hdc = ::GetDC(NULL);
    
    	::DrawIconEx(m_hMemDC, 100, 100, hcur, bitmap.bmWidth, bitmap.bmHeight, 0, NULL, DI_NORMAL);
    
    	DeleteDC(hdc);
    }
    

    Thanks, Amol Patki
    • Marked As Answer byAmol P Monday, November 09, 2009 5:59 AM
    •