How to use a form without scaling in C++Builder 11

394 Views Asked by At

I create a new application with a form that needs to be displayed without scaling but as designed with a fixed dimension in pixels (Position is poScreenCenter for example). When setting Scaled to false, the form is instead displayed with some default width and height, ignoring the designed dimensions. Setting Scaled to true works, it is displayed as designed, but scaling is not wanted.

I have tried to set DPI awareness to None or Unaware, but this has no effect.

1

There are 1 best solutions below

0
On

I got similar if not the same issues while porting huge CAD/CAM project from BDS2006 C++ -> RAD11 C++ as a test of functionality before purchasing new RAD11:

  • scaled up all VCL components
  • but not scaled all glyphs causing very small glyphs
  • not scaled some forms and dynamic panels causing scaled up components will not fit into their designed area
  • speed buttons containing Captions even if they should not
  • ManualDock is corrupting Width,Height causing scale is applied twice on docked windows messing up custom layouts

I was planning to change the sizes of problematic VCL components (really just few form sizes and all glyphs) with code at apps init (or maybe create some utility that adjust *.dfm files like I did before for app auto translations and other stuff before so I have parsers ready to go so that it would not be a big deal) and planning to obtain scaling needed for this either by winapi GetScaleFactorForDevice or by the bugged behavior of ManualDock in RAD11

However before that I needed to start my app with admin priviledges from within RAD11 IDE as I deal with device drivers and stuff that needs admin priviledges...

I found and follow this tutorial:

Which Immediately solved all my scaling issues too so no need to handle those for me anymore... Hope it helps you too (maybe even the scaling off option will work again as should have not tested it yet).

Now the App is scaled but correctly (it behaves as not scaled app just bigger)...

So in a nutshell (if the link got broken in time) you need to Add to project a XML file with *.manifest extention like this one:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
  <assemblyIdentity type="win32" name="Here_Your_Project_filename_without_extention" version="1.0.0.0" processorArchitecture="x86"/>
  <dependency>
    <dependentAssembly>
      <assemblyIdentity
        type="win32"
        name="Microsoft.Windows.Common-Controls"
        version="6.0.0.0"
        publicKeyToken="6595b64144ccf1df"
        language="*"
        processorArchitecture="*"/>
    </dependentAssembly>
  </dependency>
  <!-- Windows Vista application security requirements. -->
  <trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
    <security>
      <requestedPrivileges>
        <requestedExecutionLevel
          level="requireAdministrator"
          uiAccess="false"/>
        </requestedPrivileges>
       </security>
  </trustInfo>
  <compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
    <application>
      <!--Windows 7-->
      <supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}"/>
      <!--Windows Vista-->
      <supportedOS Id="{e2011457-1546-43c5-a5fe-008deee3d3f0}"/>
    </application>
  </compatibility>
</assembly>

note that Here_Your_Project_filename_without_extention in 3th line just replace it with the projects name. After that you open your:

Project->Options->Application->Manifest

set Manifest file to custom and at the bottom browns and select the created manifest file ...

That is it just recompile your App and run ... Please let me know if it helped or not.

I tested this on Win10 and RAD11 C++ (trial version win32 target)

This let me thinking that scaling related bugs might be caused by something in auto-generated manifest (have no knowledge and experience with those so I am just wild guessing) file which is bypassed by this approach...

I think you also do not need to use the admin rights part of the manifest so you might want to change that once this is already working for you.