"Scaling" my applications

Something I haven't given much thought until now:

I recently wrote an application while using a high screen resolution (1024 x 768).  I sent the same application to a friend of mine, who was running in 640 x 480.  You can guess what happened:  The program was HUGE on his machine!

I need some advice on how best to handle this nuance of windows application programming.  I've tried programming all my applications in 640 x 480, knowing that they'll work in higher resolutions, but this not the resolution of choice for me when doing development work, and also not the best way to solve this problem, I'm guessing.

I messed-around with "scaling" the apps[right-click on a button component on the form, for example, and choose "Scale"] but I'm not sure if I'm doing it properly.  Do you just scale the form, or do you scale everything?  How much do you scale by?
LVL 5
Tom KnowltonWeb developerAsked:
Who is Participating?
 
viktornetConnect With a Mentor Commented:
Hello Tom!

Here is a component I wrote once for a use on E-E (venks I think was the guy :)), and it's not really complete, but I think will do what you want... If you want everything to be okay, you should probably play around with it a little :)

It scales the font's and the form, as well as the controls inside the form...

================

unit Scaler;

     interface

     uses
       Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
     Dialogs;
     const
        ScreenWidth  : Integer = 800; //If you don't want to declare
constants
                                     //you'd have to have a
        ScreenHeight : Integer = 600;//property for each of these two so
you can
    // declare it at //designtime
     type
       TScaler = class(TComponent)
       private
         FAllScaled : Boolean;
       protected
         { Protected declarations }
       public
         constructor Create(AOwner : TComponent);override;
         procedure Loaded;override;
       published
         { Published declarations }
       end;
     procedure Register;
     implementation
constructor TScaler.Create(AOwner : TComponent);
begin
  Inherited Create(AOwner);
  fAllScaled := False;
end;
procedure TScaler.Loaded;
begin
  Inherited;
  if not(csDesigning in ComponentState) then
    if Owner is TForm then
    with TForm(Owner) do begin
      Font.Pitch := fpVariable;
      if (not

fAllScaled)and((Screen.Width<>ScreenWidth)or(Screen.Height<>ScreenHeight))then
       begin
         Scaled := True;
         AutoScroll := False;
          if Screen.Width < ScreenWidth then
         ScaleBy(Screen.Width, ScreenWidth)
         else ScaleBy(ScreenWidth, Screen.Width);
         fAllScaled := True;
       end;
     end;
end;
procedure Register;
begin
  RegisterComponents('System', [TScaler]);
end;
end.
=======
..-=fOoL=-..
0
 
EpsylonCommented:
Everything but font sizes are scaled. And everything that inherit its size to a font doesn't scale to.

use form1.ScaleBy(75,100) scales to 75%

Use it with care!!!

Regards,

Epsylon
0
 
EpsylonCommented:
A better idea is not to use large forms but use a pagecontrol (TAB's) to group some stuff.
0
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
viktornetCommented:
btw, replace the following two lines

if Owner is TForm then
     with TForm(Owner) do begin
....

with this one...

with GetParentForm(self) do begin
....

This should wok just fine...

..-=ViKtOr=-..
0
 
HencahCommented:
HI knowlton,

Here is the simple solution (but it greats): All you need just to set the scale property from main form to TRUE and then add this to the oncreate event of the form, maybe like this:
procedure Tform1.Create()
begin
 PixelsPerInch := Getdevicecaps(handle, LOGPIXELSY);
 { your code...if any}
end;

may this help you

0
 
Tom KnowltonWeb developerAuthor Commented:
I'm looking for solutions that do not rely on components.  Did I misunderstand your answer, Viktor?
0
 
viktornetCommented:
Just place the component on the form and that will do it...

if you don't want a component simply extract the pieces of code and place them in the appropriate events of the form, but this way you will have to place the same code over and over... a component is just easier to deal with..

..-=ViKtOr=-..
0
 
Tom KnowltonWeb developerAuthor Commented:
I see your point.

Now, when I think of component, I think of something I click on the component palette.  How does the code you pasted into E-E translate into a working component.

Please -- forgive my ignorance.  I obviously still have a lot to learn.
0
 
viktornetCommented:
first, copy the above code and save it as a PAS file somewhere on your HD>..
then go to Components->INstall Component from the Delphi IDE, (the menu that is) and then click browse on the top button, and find the PAS file that you just created... then click OK or Open or whatever the button's caption is... then, click OK, and it will ask you something... click OK.... then it should be installed in your SAMPLE Palette.. go find it, drop it on your form, and you're ready to go... no need to do anything, just keep it in the form ;)

btw, in the above unit you will see too constants, Width and Height set to certain values... make sure that those values are the resolution of your monitor, where  you're compiling your app...

..-=ViKtOr=-..
0
 
Tom KnowltonWeb developerAuthor Commented:
Viktor:

It may be a day or two before I have time to try this out.

If you're confident this works, I can give you your points now.

What do you think?
0
 
viktornetCommented:
You better test it first and then award me the points if you think it's what you've been looking for.. if not just reject...  :)

..-=ViKtOr=-..
0
 
viktornetCommented:
Did it work?
0
 
Tom KnowltonWeb developerAuthor Commented:
Viktor:

Didn't have a chance to try it out yet.

I will let you know if it works.

You got your points, right?
0
 
viktornetCommented:
Yeah but I wanted you to try it out first...
0
 
Tom KnowltonWeb developerAuthor Commented:
I have faith in your abilities.  I really have no idea when I'll have time to try this out (this is a minor project, and just for fun).

If it DOESN'T work, I know where to find you.  :)

Tom
0
 
viktornetCommented:
hehe, okay :)) No problem!

If there are any problems please e-mail me at viktor@megsinet.net ;)

..-=ViKtOr=-..
0
 
Tom KnowltonWeb developerAuthor Commented:
Okay!
0
All Courses

From novice to tech pro — start learning today.