Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: SFML interferes with SETCursor(win32 func)  (Read 3427 times)

0 Members and 1 Guest are viewing this topic.

NoIdea

  • Full Member
  • ***
  • Posts: 149
    • View Profile
SFML interferes with SETCursor(win32 func)
« on: October 03, 2010, 02:48:50 pm »
Hi, I've decided to use directly windows to deal with Cursors by doing this :

Code: [Select]
HCURSOR c=LoadCursor(NULL, IDC_WAIT);
if(!c)
      std::cout<<"no cursor";
SetCursor(c);


However, it works fine until an event (Keypress and Textentered don't cause any problem) is emitted. My question : How can I keep my cursor the way it is without having SFML changing it back just after ?

Thank you.

[EDIT] Found the problem : when a WM_SETCURSOR event is emitted, I must return true. However, this can't work because SFML hides the window events. Is there a way to make it so that SFML return true ?.

NoIdea

  • Full Member
  • ***
  • Posts: 149
    • View Profile
SFML interferes with SETCursor(win32 func)
« Reply #1 on: October 04, 2010, 07:26:46 pm »
Found a solution but i'm not completely satisfied.
So, here is the solution :
Code: [Select]

window_handle=FindWindow(NULL,TEXT("SFML Window"));
if(window_handle==0)
    std::cout<<"error";


and,

Code: [Select]
HCURSOR c;
switch(t)
{
     case Cursor::WAIT :
           c=LoadCursor(NULL, IDC_WAIT);
           break;
     case Cursor::HAND :
           c=LoadCursor(NULL, IDC_HAND);
           break;
     case Cursor::NORMAL :
            c=LoadCursor(NULL, IDC_ARROW);
            break;
      case Cursor::TEXT_EDIT :
            c=LoadCursor(NULL, IDC_IBEAM);
            break;
}
if(!c)
   std::cout<<"no cursor";
else
   SetClassLong(window_handle, GCL_HCURSOR, (LONG)c);


However, I do not like the way a get the window handle. Is there a better way ?
Can I do something similar with linux (if so, please lead me in the right direction)?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
SFML interferes with SETCursor(win32 func)
« Reply #2 on: October 04, 2010, 07:46:10 pm »
Quote
However, I do not like the way a get the window handle. Is there a better way ?

In SFML 2 there's a function for that.

But I don't understand why the cursor is changed when an event is emitted, did you find any relevant information about that?
If you use Window::ShowMouseCursor, internally it calls LoadCursor, and as far as I know, the cursor is not reset when an event is emitted.
Laurent Gomila - SFML developer

NoIdea

  • Full Member
  • ***
  • Posts: 149
    • View Profile
SFML interferes with SETCursor(win32 func)
« Reply #3 on: October 04, 2010, 08:05:54 pm »
extract from : msdn

Quote
Your application can change the design of the cursor by using the SetCursor function and specifying a different cursor handle. However, when the cursor moves, the system redraws the class cursor at the new location. To prevent the class cursor from being redrawn, you must process the WM_SETCURSOR message. Each time the cursor moves and mouse input is not captured, the system sends this message to the window in which the cursor is moving.


And when the crusor is redrawn, it is the arrow that is redrawn (found that somewhere else on msdn but having trouble finding it).

this link explains what I was saying.

Furthermore, I couldn't find a similar function for linux. Has someone got any Idea ?

 

anything