0
我目前更改Windows鼠标光标在我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;
}
当我快速移动鼠标时,此作品除了完美的罚款。除了我自定义的鼠标光标外,还有几个可以看到默认窗口鼠标光标的稀缺实例。为什么会这样呢?
我不确定你在描述什么。你能否给你的答案添加一个代码示例? – TrampolineTales
每个窗口通过它的[WindowProc回调](https://msdn.microsoft.com/en-us/library/windows/desktop/ms633573(v = vs.85).aspx)接收消息。当系统即将更新游标时,它会发送“WM_SETCURSOR”通知,如果要立即更新游标,则需要处理该通知。 'WindowProc'可能在SFML的内容中,所以你可能需要隐藏系统光标并自己绘制一个。 – VTT