 |
|
Join the Discussion
|
"Post your questions, concerns, views and comments to this article..."
Discuss!
|
|
 |
 |
|
|
 |
 |
 |
Few weeks ago, I saw a little program that was able to display a magnified view of whatever is beneath the mouse cursor. "Wow really cool, can you do something like that, Zarko?" was my first thought. (...2-3 programming days...)
Read on, and see what I have made.
Recipe
One form, one image control, one panel, few labels, a button, timer, and a slider. Put image and panel on the form. Place all other controls on the panel. Now, we have everything we need. Before coding, change some properties of those controls. Finally, do some coding (precisely do some API coding). Download full project (6 K).
The idea is to track mouse cursor movement over the screen, and show enlarged (2x to 8x) section around the cursor, in the image control.
To the Screen
Here are some snippets of the program.
// variables
var Srect,Drect,PosForme:TRect;
iWidth,iHeight,DmX,DmY:Integer;
iTmpX,iTmpY:Real;
C:TCanvas;
hDesktop: Hwnd;
Kursor:TPoint;
// Magnify screen iff app is not iconic
If not IsIconic(Application.Handle) then begin
// Get cursor coordinates
GetCursorPos(Kursor);
hDesktop:= GetDesktopWindow;
// PosForm represents the rectangle with the
// Form (image control) coordinates.
PosForme:=Rect(Form1.Left,
Form1.Top,
Form1.Left+Form1.Width,
Form1.Top+Form1.Height);
//Show magnified screen //if cursor is outside the form.
If not PtInRect(PosForme,Kursor) then begin
// Code below is used to magnify selected
// portion of the screen. With a few
// modifications you could use
// it to shrink the screen
iWidth:=Image1.Width;
iHeight:=Image1.Height;
Drect:=Bounds(0,0,iWidth,iHeight);
iTmpX:=iWidth / (Slider.Position * 4);
iTmpY:=iHeight / (Slider.Position * 4);
Srect:=
Rect(Kursor.x,Kursor.y,Kursor.x,Kursor.y);
InflateRect(Srect,Round(iTmpX),Round(iTmpY));
//Retrieve a handle of a desktop window.
C:=TCanvas.Create;
try
C.Handle:=GetDC(GetDesktopWindow);
//Transfer part of the screen image on TImage.
Image1.Canvas.CopyRect(Drect,C,Srect);
finally
ReleaseDC(hDesktop, C.Handle);
C.Free;
end;
end;
// Be sure to process all Windows messages.
Application.ProcessMessages;
end; // IsIconic
|
Modifications
It is obvious, that program could have few modifications just to look more like loupe (precisely: rectangular loupe). First why not hide title bar, and enable dragging without clicking on the caption of the form. Second, it may be good to limit form resizing. (In fact, I have included this one)
I hope you will find it useful (130 K). Don't hesitate to alter code (6 K) so that it suits you better.
Some related components:
TransitionEffect. On the moment, the component does stretches, slides, zooms and pushes. From The Basic Zone.
ZImage is a freeware Delphi VCL component that can be used to display any images: pictures, faxes etc. Using the mouse one can easily zoom image in and out, scroll by simple dragging. At right and bottom side scrollbar-like zoom indicators of arbitrary width can be displayed. From Alexander Rublinetsky.
|