Windows 10: Turning "Fix scaling for apps" Off breaks our app's behavior (breaks .NET Framework Image...

Discus and support Turning "Fix scaling for apps" Off breaks our app's behavior (breaks .NET Framework Image... in Windows 10 Customization to solve the problem; Am I correct that when a user sets "Fix scaling for apps" to Off that Windows essentially treats all apps as DPI Unaware? If so, is there a way for... Discussion in 'Windows 10 Customization' started by TCC Developer, Oct 20, 2019.

  1. Turning "Fix scaling for apps" Off breaks our app's behavior (breaks .NET Framework Image...


    Am I correct that when a user sets "Fix scaling for apps" to Off that Windows essentially treats all apps as DPI Unaware?

    If so, is there a way for our app to say "treat us as DPI Aware anyway"? (That would be the easiest work-around.)


    Background: our WinForms app targets .NET Framework 4.5.1 and calls SetProcessDPIAware() during startup, which makes it "system" aware, not "per monitor"... and we generally autoscale pretty well. Our app constructs Metafiles (EMF+) that it saves to a database and displays in WinForms PictureBox controls. That code has been working great for many years.


    However, with Windows 10 1903 and .NET Framework 4.8, if a user sets "Fix scaling for apps" to Off with Scaling at 150% or higher, it not only makes our UI a little fuzzier by telling us 100% and then doing the scaling its own way, it ALSO breaks the Metafiles we construct... our Image processing. In particular, it seems to scale up what is drawn by Graphics.DrawImage by 150%... or scales back the resulting dimensions by 150%... not sure... but the result is the image we are drawing into the Metafile gets cropped. This is not just what is showing on the screen... the images we are computing in memory and then saving to our SQL Server database are getting wrongly cropped.


    If we change the calls to "new Metafile" to pre-specify the frame size, then that avoids the bug. Unfortunately, we don't know the resultant size... we keep building up the Image as we go. So, we normally do not specify a Rectangle and it just auto sizes to the contents that we draw into the Metafile. (It just does it off by the Scaling factor now that "Fix scaling for apps" can be turned off.)


    Work-around question #2: Is there some way we can construct the Metafile without specify a size that will still not result in cropping when "Fix scaling for apps" is turned Off?


    Work-around question #3: Is there some way for us to detect that "Fix scaling for apps" is turned Off such that we can warn the user that we will malfunction... that they need to turn that back On?


    We created a tiny sample program to illustrate the problem. It is a simple WinForm with two PictureBoxes and a button that takes the Image in the first, draws it into a new Metafile, then puts the new Metafile into the second PictureBox. That works as expected, UNLESS you set Scaling 150% or more and turn "Fix scaling for apps" Off, in which case the computed Metafile will only be the upper left portion of the original Image. Here's some code snippets...


    The main program setting it DPI Aware:


    static class Program


    {
    [
    System.Runtime.InteropServices.DllImport("user32.dll")]
    private static extern bool SetProcessDPIAware();

    /// <summary>
    /// The main entry point for the application.
    /// </summary>
    [
    STAThread]
    static void Main()
    {
    //if (Environment.OSVersion.Version.Major >= 6)
    SetProcessDPIAware();

    Application.EnableVisualStyles();
    Application.SetCompatibleTextRenderingDefault(false);
    Application.Run(new Form1());
    }


    }



    Our call to create a new Metafile with offscreen device context and no pre-computed bounds such that it grows to its contents:


    public static Metafile NewMetafile()


    {
    using (Graphics g = Graphics.FromHwnd(IntPtr.Zero)) // offscreen device context
    {
    IntPtr hdc = g.GetHdc(); // gets released by g.Dispose() called by using g
    return new Metafile(hdc, EmfType.EmfPlusOnly);
    }


    }



    The implementation of the button click, copying the Image into a new Metafile:


    private void DrawUsingMetafile()


    {
    try
    {
    Image img = this.pictureBox1.Image;

    Metafile mf = NewMetafile();

    using (Graphics gmf = Graphics.FromImage(mf))
    {
    gmf.
    DrawImage(img, 0, 0, img.Width, img.Height);
    }

    this.pictureBox2.Image = mf;
    }
    catch (Exception ex)
    {

    MessageBox.Show(ex.Message, "Exception", MessageBoxButtons.OK, MessageBoxIcon.Error);

    }

    }



    Any suggested work-arounds for this inconsistent Windows behavior would be greatly appreciated.

    :)
     
    TCC Developer, Oct 20, 2019
    #1

  2. Microsoft .NET Framework, Unhandled exception

    Hi,

    Welcome to Microsoft Community.

    I suggest you to un-check and recheck .Net framework 3.5 and .Net framework 4.6 advance series from Windows features.

    Try the following steps:

    • Press Windows + R keys to open Run command.
    • Type Appwiz.cpl and select "turn Windows feature on or off" from the left
    • Uncheck .Net framework 3.5 and .Net framework 4.6 advance series.
    • Restart the computer
    • Repeat step 1 and 2 and check .Net framework 3.5 and .Net framework 4.6 advance series.
    • Restart the computer.
    Regards,
     
    Waseemulla S, Oct 20, 2019
    #2
  3. Scaling Breaks after Restart

    I just purchased an i5, 256GB Surface Pro 4. I have a critical issue where the scaling breaks after re-logging in. Basically, if I start at 100% and then change to 200%, everything works great (even though there is a warning stating that some things shouldn't
    be working). However, if I restart with the setting at 200%, the scaling breaks and all applications are incredibly small. Even, worse the text gets scaled but the rest of the UI does not. The result is that the text overflows the buttons.
     
    kearneylackas, Oct 20, 2019
    #3
  4. Brink Win User

    Turning "Fix scaling for apps" Off breaks our app's behavior (breaks .NET Framework Image...

    Brink, Oct 20, 2019
    #4
Thema:

Turning "Fix scaling for apps" Off breaks our app's behavior (breaks .NET Framework Image...

Loading...
  1. Turning "Fix scaling for apps" Off breaks our app's behavior (breaks .NET Framework Image... - Similar Threads - Turning Fix scaling

  2. Windows Mail App Keeps Breaking

    in Windows 10 Gaming
    Windows Mail App Keeps Breaking: I have my iCloud mail set up on my computer's mail app, I can receive emails fine but every few days, my outgoing emails would get stuck in the outbox. I can fix this temporarily by resetting the app but the issue appears again soon after....
  3. Windows Mail App Keeps Breaking

    in Windows 10 Software and Apps
    Windows Mail App Keeps Breaking: I have my iCloud mail set up on my computer's mail app, I can receive emails fine but every few days, my outgoing emails would get stuck in the outbox. I can fix this temporarily by resetting the app but the issue appears again soon after....
  4. Xbox Gamepass App completly breaking

    in Windows 10 Gaming
    Xbox Gamepass App completly breaking: I am so anoyed, the Gamepass App doesn´t load any pannels and i can only play games i have installed and you can´t close the app with x How does it happen? If you klick on any Game to look at screenshots etc. The App corupts and stops working. Than i can´t do anything in the...
  5. Xbox Gamepass App completly breaking

    in Windows 10 Software and Apps
    Xbox Gamepass App completly breaking: I am so anoyed, the Gamepass App doesn´t load any pannels and i can only play games i have installed and you can´t close the app with x How does it happen? If you klick on any Game to look at screenshots etc. The App corupts and stops working. Than i can´t do anything in the...
  6. WKSCLI.DLL is breaking my apps

    in Windows 10 BSOD Crashes and Debugging
    WKSCLI.DLL is breaking my apps: Recently I've been having a problem with a few apps, like spotify or ubisoft connect. I try to open them and I get the error message that WKSCLI.DLL isnt working and the error code 0xc0000006. I've tried redownloading the apps that havent worked several times now but they...
  7. WKSCLI.DLL is breaking my apps

    in Windows 10 Gaming
    WKSCLI.DLL is breaking my apps: Recently I've been having a problem with a few apps, like spotify or ubisoft connect. I try to open them and I get the error message that WKSCLI.DLL isnt working and the error code 0xc0000006. I've tried redownloading the apps that havent worked several times now but they...
  8. WKSCLI.DLL is breaking my apps

    in Windows 10 Software and Apps
    WKSCLI.DLL is breaking my apps: Recently I've been having a problem with a few apps, like spotify or ubisoft connect. I try to open them and I get the error message that WKSCLI.DLL isnt working and the error code 0xc0000006. I've tried redownloading the apps that havent worked several times now but they...
  9. How to break a USB association with an app

    in Windows 10 Drivers and Hardware
    How to break a USB association with an app: I have a program associated with plugging in a USB connector to my GoPro. It starts the Quik program as it should. However, recently something prompted me after plugging in the USB and asked me what I wanted to have happen. I accidentally clicked on something that now...
  10. Turn On or Off Fix Scaling for Apps that are Blurry in Windows 10

    in Windows 10 Tutorials
    Turn On or Off Fix Scaling for Apps that are Blurry in Windows 10: How to: Turn On or Off Fix Scaling for Apps that are Blurry in Windows 10 How to Turn On or Off Fix Scaling for Apps that are Blurry in Windows 10 Starting with sign in to Windows to have these apps render properly. You can now instead turn on the Fix scaling for apps...