Qbasicnews.com

Full Version: Mouse, no SDL.
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I'd like to know if I can use any API functions to read the mouse status (position and buttons, most likely). If so, which.

I don't like having to include SDL.DLL just for mouse support, y'know Wink
There are API functions to load a cursor, Show, Hide, check your windows reference.

To get the mouse clicks you must check in your callback function for these messages:

Inside the client area:
WM_LBUTTONDOWN
WM_LBUTTONUP
WM_LBUTTONDBLCLK >> only if window's windclass.style has the bit CS_DBLCLKS
(the same for RBUTTON and MBUTTON)

also
WM_MOUSEMOVE

The hparam of the message comes with the position of the mouse buttons and control keys HT_xxxx (Winuser.h)

The mouse position in client area coords comes in the lparam of each message..
pt[iCount].x = LOWORD (lParam) ;
pt[iCount].y = HIWORD (lParam) ;


If mouse is outside the client area of the window you will receive
WM_NCLBUTTONDOWN WM_NCLBUTTONUP WM_NCLBUTTONDBLCLK
WM_NCMBUTTONDOWN WM_NCMBUTTONUP WM_NCMBUTTONDBLCLK
WM_NCRBUTTONDOWN WM_NCRBUTTONUP WM_NCRBUTTONDBLCLK

In the lparam you will have screen coords and in the hparam you will have an enum HT_xxxx (Winuser.h) indicating where the user has clicked.

You have these functions to convert client coords to screen coords and vice-versa
ScreenToClient (hwnd, &pt) ;
ClientToScreen (hwnd, &pt) ;

What I don't know is how will combine this with FB's graphics lib...
Yeah, but I want to avoid the message loop as much as possible. I was wondering if there were any easy-to-call functions. I'll keep researching.
We could ask Angelo to add mouse and a multikey handler to the to the graphics lib...

The event loop must be somewhere inside the graphics lib...
Yeah, that would be really useful. The problem is that he claimed that his replacement was... a replacement Wink I'll ask him anyways. If he added those two things, coding a game in fB would be easy as hell.
Code:
The GetCursorPos function retrieves the cursor's position, in screen coordinates.

BOOL GetCursorPos(

    LPPOINT lpPoint     // address of structure for cursor position  
   );    


Parameters

lpPoint

Points to a POINT structure that receives the screen coordinates of the cursor.



Return Values

If the function succeeds, the return value is nonzero.
If the function fails, the return value is zero. To get extended error information, call GetLastError.

Remarks

The cursor position is always given in screen coordinates and is not affected by the mapping mode of the window that contains the cursor.
The calling process must have WINSTA_READATTRIBUTES access to the window station.

See Also

ClipCursor, POINT, SetCursor, SetCursorPos, ShowCursor [/code]
Awesome, thank you very much. That's exactly what I needed. I'll work the other functions out myself, knowing that it is in user32.dll (Google wonders Wink)

Thanks again.