The all mighty mouse: you can have more memory, you can have blue-ray discs but you are still using the mouse (and the keyboard) to control your computer.
The mouse pointer lets you select objects on the screen and operate on them. What and how you operate with the mouse is pretty simple: there's an arrow on the screen that moves when you move the mouse - screen edges are the border - the area where you mouse lives. When you click it, it does something.
How hard is for you to sometimes position the mouse cursor at the exact location?
xMouse - "Beam my Mouse" - the Idea...
What if the mouse arrow would be positioned in the center of two crossing beams, one horizontal and one vertical - both extending to the edges of the screen? Such a mouse handling would help a lot.That's the idea of the xMouse application - draw two beams that appear to cross where the mouse is. While you move the mouse - the beams move also - thus helping you more easily position the mouse related to other screen objects.
xMouse - Implementation
Start with a simple Delphi form. Make it fill the entire screen. Locate the mouse pointer and its coordinates "over" the form. Now simply remove the parts of the form that are outside of the imagined x and y axes where the mouse pointer is in the point of their intersection - the (0,0) coordinate. What's left of your form are two beams crossing where the mouse pointer is :)Do the above process in an OnTimer event of a TTimer component, as in:
procedure TMainForm.ShapingTimerTimer(Sender: TObject) ;The above is an OnTimer event handler for a Delphi form with the following "display" properties set in the OnCreate event handler:
const
HALF_LINE_DIM = 1;
var
mp : TPoint;
shape, shpLT, shpRT, shpLB, shpRB, shapeMouse: HRGN;
begin
mp := Mouse.CursorPos;
shape := CreateRectRgn(0,0,0,0) ;
shpLT := CreateRectRgn(0, 0, mp.X , Height) ;
shpRT := CreateRectRgn(mp.X + HALF_LINE_DIM , 0, Width, Height) ;
shpLB := CreateRectRgn(0, 0, Width, mp.Y ) ;
shpRB := CreateRectRgn(0, mp.Y + HALF_LINE_DIM, Width, Height) ;
//leave "place" for mouse point
shapeMouse := CreateRectRgn(mp.X-1, mp.Y-1, mp.X+2, mp.Y+2) ;
CombineRgn(shape,shape,shpLT,RGN_XOR) ;
CombineRgn(shape,shape,shpRT,RGN_XOR) ;
CombineRgn(shape,shape,shpLB,RGN_XOR) ;
CombineRgn(shape,shape,shpRB,RGN_XOR) ;
CombineRgn(shape,shape,shapeMouse,RGN_DIFF) ;
DeleteObject(shpLT) ;
DeleteObject(shpRT) ;
DeleteObject(shpLB) ;
DeleteObject(shpRB) ;
DeleteObject(shapeMouse) ;
SetWindowRgn(Handle, shape, true) ;
end;
beginLet's get back to the weird looking OnTimer event...
BorderStyle := bsNone;
FormStyle := fsStayOnTop;
WindowState := wsMaximized;
end;
Magic with CreateRectRgn, CombineRgn and SetWindowRgn
The ShapingTimer shapes a Delphi form by removing the 4 rectangular pieces leaving two beams - one horizontal and one vertical with the mouse pointer positioned in their intersection point - the Mouse.CursorPos.shpLT := CreateRectRgn(0, 0, mp.X , Height) ;The shpLT is the left top rectangular area of the form related to where the mouse pointer is. The same goes for shpRT: shape right-top; shpLB: shape left-bottom and shpRB:shape right-bottom.
shpRT := CreateRectRgn(mp.X + HALF_LINE_DIM , 0, Width, Height) ;
shpLB := CreateRectRgn(0, 0, Width, mp.Y ) ;
shpRB := CreateRectRgn(0, mp.Y + HALF_LINE_DIM, Width, Height) ;
The 4 rectangular areas are "cut of" out of the maximized forms client rectangle.
The shapeMouse is a rectangle around the mouse pointer.
CombineRgn is then used to combine the 5 rectangles using unions.
The SetWindowRgn finally shapes our Delphi form - what's left are two "lines" or axes with the intersection point where the mouse pointer is.
Since a picture is worth a thousand words and a working application is worth a thousand screen shots - I'll leave it up to you to download the code and try it for yourself :)
Note: the application uses the TTrayIcon component (Delphi 2007 and up) to have the application icon displayed in the Tray area - this is where you can Activate or deactivate the beams; change the color of the beams or exit the application.


