2017-04-16 12 views
0

나는 현재 지금처럼 내 SFML/C++ 응용 프로그램에서 윈도우 마우스 커서를 변경하고있어 동안 실패에서는 SetCursor()는 때때로 빠른 마우스 움직임

#include <iostream> 
#include <SFML/Graphics.hpp> 
#include <Windows.h> 

int main() { 
    sf::RenderWindow window; 
    window.create(sf::VideoMode(1280, 720), "Window", sf::Style::Close); 
    static int cursorNum = 0; 

    HCURSOR cursor = LoadCursorFromFile("graphics\\cursors\\cursor.cur"); 
    HCURSOR cursorTarget = LoadCursorFromFile("graphics\\cursors\\cursor-target.cur"); 

    while (window.isOpen()) { 
    if (window.hasFocus()) { 

     //...Irrelevant that decides the value of cursorNum... 

     ////Mouse Cursors//// 
     if (sf::IntRect(0, 0, 1280, 720).contains(sf::Mouse::getPosition(window).x, sf::Mouse::getPosition(window).y)) { 
     switch (cursorNum) { 
      case 0: 
      SetCursor(cursor); 
      SetClassLongPtr(window.getSystemHandle(), GCLP_HCURSOR, reinterpret_cast<LONG_PTR>(cursor)); 
      break; 
      case 1: 
      SetCursor(cursorTarget); 
      SetClassLongPtr(window.getSystemHandle(), GCLP_HCURSOR, reinterpret_cast<LONG_PTR>(cursorTarget)); 
      break; 
     } 
     } 
     ///////////////////// 
    } 

    ////Clear//// 
    window.clear(sf::Color(30, 0, 30)); 
    ///////////// 

    window.display(); 
    } 

    sf::Event event; 
    while (window.pollEvent(event)) { 
    if (event.type == sf::Event::Closed) { 
     window.close(); 
    } 
    } 

    return 0; 
} 

나는 빠르게 마우스를 이동할 때이를 제외하고 완벽하게 잘 작동합니다. 내 사용자 정의 마우스 커서 외에도 기본 창 마우스 커서를 볼 수있는 몇 가지 부족한 경우가 있습니다. 왜 이것이 될 수 있을까요?

답변

0

커서를 동적으로 변경하려면 WM_SETCURSOR 알림을 창 proc에 처리해야합니다. WM_MOUSEMOVE에 대한 응답으로 커서를 변경하는 것이 너무 늦을 수 있습니다 (귀하의 경우에 발생할 수있는 일). 나는 WM_SETCURSOR이 SFML에서 어떻게 다루어 지는지 모르겠다. 어쩌면 시스템 커서를 숨기고 스스로를 그릴 필요가있을 것이다.

+0

나는 당신이 무엇을 묘사하는지 잘 모르겠습니다. 답변에 코드 예제를 추가해 주시겠습니까? – TrampolineTales

+0

각 창은 [WindowProc 콜백] (https://msdn.microsoft.com/en-us/library/windows/desktop/ms633573(v=vs.85).aspx)을 통해 메시지를받습니다. 시스템이 커서를 업데이트하려고 할 때 커서를 즉시 업데이트하려면 처리해야하는 'WM_SETCURSOR' 알림을 보냅니다. 'WindowProc'은 SFML의 어딘가에있을 수 있으므로 시스템 커서를 숨기고 직접 그릴 필요가 있습니다. – VTT