Skip to main content

Past Blast

Featured Products

Windows Mobile Developer Controls
Windows Mobile Developer Controls
Stay in touch using the DEVBUSS RSS feeds.
 

News

Windows Mobile Developer Controls
Sapphire Soltuions

eVB Magnification Lens for your Pocket PC using Windows CE API.

Written by Marvin Jones  [author's bio]  [read 37790 times]
Edited by Derek

Page 1  Page 2  Page 3 

How it works

When the program loads for the first time we need to establish the form and controls sizes. In the code, the default magnification value is initially set to 10 percent. The forms X/Y or horizontal and vertical positioning is set to zeros, the upper left corner. By designing the form as scaleable this code can work on hand held devices also.

A call to the API GetDC (0),and then calling API GetDeviceCaps to establish the maximum height and width for the device. Since the return value is in pixels and I will need them in twips a conversion is performed using that calculation and the screen object Screen.TwipsPerPixelX and Screen.TwipsPerPixelY.

Using a default form height of 40 percent, I then establish the forms length and height. You may elect to have the screen size as a selectable feature on the options screen but for now lets keep it simple.

Having established the forms boundaries, I then calculate my reference line control width properties to position top bottom reference line.

It is at this point that I will need to check my boundaries to ensure that the form is on the desktop and to transfer the desktop image to the form. A separate function, (MoveMyScreen), and subroutine, PaintMYScreen, will accomplishes this to get my first magnified lens to view.

The first function to code is the most important since it will be used to establish addressability for most of the API calls. This function is the GetDesktopWindow, (GDW) function.

Since most of the API calls require the "handle" and embedded VB does not support the GetDesktopWindow API, it was necessary to create a function, which would get the "handle" or reference of the desktop. One method, which seemed to be the easiest, was to code a loop, which spins through all the current windows until it finds one with the text name of "Desk" as in desktop. It is this reference that is used to copy the image to the form for magnification.

Note - You could also use most of this code to create a task manager with minimal effort.

The function MoveMyScreen is mainly used for the mouse down, mouse up and key down events, and as such it needs to include a parameter (see code). On the form load, this value is zero because the form is being programmatically positioned at start up, but later, the mouse down, mouse up and key down events will also use this function for positioning.

The key down event will pass the ASCII key code values of the button pressed to MoveMyScreen function. I.E. cursors, scrolls and enter. The mouse down and up event was used to let the user change the viewable area using the stylus, dragging it to the desired position. This method could be used to move a borderless form.

Note that the value needed to position the screen for each event is calculated in order to shift the screen correctly from where the previous screen left off regardless of the magnification factor.

Finally the FrmMain.Left property is forced to zero, left justifying the form in the event that it was moved.

The PaintMYScreen subroutine is next. By the time the program gets to this point it has all the necessary values to paint the image from the desktop to the form.

Simply, the way the StretchBlt API call works is that it takes a portion of the screen, less than 100 percent, and copies it to another area increasing it to fill that area. Since the receiving field is greater than the area being copied from, the image gets larger. It stretches the source image from the top most left hand corner to the bottom right most corner on the receiving location, adding bits when necessary. By the way, this API can also be used to rotate a screen 360 degrees but that's another story.

A simple formula, percent = (100 - magnification factor) / 100, is used to calculate the area that will be copied from by a percentage. On the initial load event, only 90 percent of the source image will be copied since the initial magnification value was set to 10. Remember the smaller the copied-from image is, the larger the magnification factor is.

The remaining calculations in the PaintMYScreen subroutine, establishes the remaining parameters required by the StretchBlt function API mainly the copy to and from areas. It is advisable to try to understand the StretchBlt function help on this API.

The next thing this subroutine does is to hide the form. Why? Because in order to copy from what ever is under your form is must be viewable to the program. If your lens form is viewable then the program can't "see" the image. The problem is that between the time the form hides and the API copies the image a delay is required to make sure that the form is gone. A simple loop was coded to affect this delay. You may wish to use another timer but this seemed easier. You may also have to adjust this delay to accommodate a different processor.

Now that the loop has been performed and the form is hidden, the StretchBlt function can be called to copy the image to the form. Once that is done you show your form, release the device context and you're ready for your next event.

The Mouse down and Mouse up events are pretty straightforward but here is how they work together to perform a simulated drag. When the stylus touches the screen a Mouse down event occurs and at this point the program saves those X/Y coordinates. Then when the stylus is removed from the screen, a Mouse up event is triggered. By comparing the Mouse down values with the Mouse up values, you can then calculate the difference of the movement and plot the new X/Y position to copy from. You then do your boundary checking, MoveMYScreen, and perform the PaintMyScreen subroutine. You now have moved the image using the stylus.

The Key Up event works a little differently, hence the different name. When a key is pressed, in this case the cursor, scroll and enter key, (action key), the event triggers. The key code value is received and is then passed to the MoveMyScreen function and acted upon accordingly.

Note that the Key Down event works the same way, but the Key Press event ONLY works with the SIP or Screen keyboard as far as I know.

Notice that in the code a check for a value 134 (enter), causes the branching to the DoubleClick event.

The Double Click event transfers control to the Options form where the magnification factor is set and returns.

The Single Click event is used to left shift the form whenever the form receives the focus. Usually the timer event would control this but if the timer is shut off then this is required to keep things sane. It is also useful for capturing a portion of one screen to compare to another.

Previous Page  Next Page