Poser une questionPoser une question
 

TraitéeLow cursor quality in high DPI

  • samedi 7 novembre 2009 05:27Amol P Médailles de l'utilisateurMédailles de l'utilisateurMédailles de l'utilisateurMédailles de l'utilisateurMédailles de l'utilisateur
     A du 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

Réponses

  • lundi 9 novembre 2009 05:56Amol P Médailles de l'utilisateurMédailles de l'utilisateurMédailles de l'utilisateurMédailles de l'utilisateurMédailles de l'utilisateur
     TraitéeA du 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
    • Marqué comme réponseAmol P lundi 9 novembre 2009 05:59
    •  

Toutes les réponses

  • samedi 7 novembre 2009 23:09Nikita Leontiev Médailles de l'utilisateurMédailles de l'utilisateurMédailles de l'utilisateurMédailles de l'utilisateurMédailles de l'utilisateur
     
    Try DrawIconEx with DI_DEFAULTSIZE flag.
  • lundi 9 novembre 2009 05:56Amol P Médailles de l'utilisateurMédailles de l'utilisateurMédailles de l'utilisateurMédailles de l'utilisateurMédailles de l'utilisateur
     TraitéeA du 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
    • Marqué comme réponseAmol P lundi 9 novembre 2009 05:59
    •