fMOUSE


Quick Data

Header file:mouse.h
Object name:fMOUSE
Object index:1 of 1 Object

General Description

The fMOUSE class is a class to do some menial tasks related to the mouse. For example, this class can return the co-ordinates of the mouse, as well as change the mosue cursor, or hide the mouse cursor altogether! I think that you shall find this class most useful.

Please note that when this class deals with a cursor - it maintains an internal cursor that is loaded into memory. Loading another cursor will overwrite that current cursor. Once you have the cursor loaded, you can use another function to apply that cursor to your window.

Now I can not see much use for more than one of these - so a global mouse object is created for you. Its called Mouse. If you didn't want that, then #define F_NOGLOBALMOUSE before you include the file.


Methods


Prototype Description

void cLoadCursor(char* Name, int ID); This function loads a cursor from your program's resources into memory. You can either specify Name or ID - but not both. If you specify Name, then ID should be 0 (Zero), and if you use ID, then Name should be NULL.
void cLoadCursor(HINSTANCE Instance, char* Name, int ID); This function is exactly like the above function, except that it takes an extra parameter - Instance. You can specify a module to load the cursor from with Instance. So, via this method, you could load a DLL and then load a cursor from that.
void cLoadCursor(HCURSOR Cursor); This function sets this classes cursor from a handle to a cursor that you may have just had lying around. Handy, that, just having a cursor lying around...
void cLoadCursorFF(char* FileName); This function loads a cursor from file. FileName specifies the location from which to get the file from.
HCURSOR cGetCursor(void); This function returns the handle to the cursor. Simple.
void cSetCursor(void); This function applys the cursor that is currently loaded into memory. There isn't a whole lot more to this function... but if you are wondering how to unset the cursor, then please see the next function.
void cResetCursor(void); This function resets the cursor to what it was before you applied a cursor.
void Show(void); This function shows the mouse cursor, if it was not already showing. If you wish to hide the cursor (for example, if you have a full-screen display and don't want the mouse cursor showing) then you can use the next function.
void Hide(void); This function hides the cursor from view. You may like to use this function should you have a full-screen display or something like that.
void HourglassOn(void); This function makes your application's cursor into the hourglass cursor. This hourglass (I think) stays an hourglass even if you move the mouse outside your window - but try it to see if it does work this way.
void HourglassOff(void); This function turns the hourglass back off, if you turned it on with the last function.
int GetMouseX(void); This function returns the X co-ordinate of the mouse cursor for you. (0,0) is at the top left hand corner.
void GetMouseY(void); This function returns the Y co-ordinate of the mouse cursor for you. (0,0) is at the top left hand corner.
void SetMousePosition(int X, int Y); This function sets the position of the mouse cursor. Please note that (0,0) is at the top left hand corner of the screen - and you can set the cursor to be anywhere on the screen that you want it to be.
void SetAllowableRegion(int X, int Y, int Width, int Height); This function sets the area inside which you will be permitted to move the mouse. Attempting to move the cursor outside this area will result in the cursor 'sticking' at the edge of the box. X and Y are the co-ordinates of the top left hand corner of the box, and Width and Height are the size of the box.
void ResetAllowableRegion(void); This function resets the allowable mouse area which you set with the last function. You may wish to unset this region at some point in time - or otherwise you could annoy the user a bit. Maybe that was the idea in the first place...
int GetAllowableRegion_Left(void);
int GetAllowableRegion_Top(void);
int GetAllowableRegion_Right(void);
int GetAllowableRegion_Bottom(void);
This function gets the area of the allowable mouse region. This could be useful information to get if you forgot what area you set, or if you find yourself under a restricted area.

Sample Code

The following snippet gives a basic idea of how to use this component.


//No need to generate an instance of the object, it's already done.
//Just reference it as 'Mouse', as below...

//Now load a cursor from the resources and apply it...
Mouse.cLoadCursor("MYCURSOR", 0);
Mouse.cSetCursor();

//Clear the cursor back to the default...
Mouse.cResetCursor();

//Now apply an Hourglass cursor, and then unset it...
Mouse.HourglassOn();
Mouse.HourglassOff();

//Now it's time to annoy the user: let's restrict
//the area in which they can move the mouse around in!
//Restrict movement to a 100x100 pixel box, starting
//at (10,10).
Mouse.SetAllowableRegion(10,10, 100,100);

//Now, let's be nice and let the mouse go back to being
//able to move around without restriction. Penning up
//animals for extended periods of time is not nice, and
//mice are no exception.
Mouse.ResetAllowableRegion();

Back to indexThe FreeFoote Foundation Classes Documentation