1. Technology

Your suggestion is on its way!

An email with a link to:

http://delphi.about.com/od/graphics/l/aa120198.htm

was emailed to:

Thanks for sharing About.com with others!

Zoom
How to write a Delphi application that is able to zoom in portion of your desktop screen - like a loupe.
Join the Discussion
"Post your questions, concerns, views and comments to this article..."
Discuss!
Related Resources
Weird Delphi
Graphics programming

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:

©2014 About.com. All rights reserved.