this-is-me

Changing DPI

4 posts in this topic

#1 ·  Posted (edited)

Larry once made a script that would allow a person to change the screen resolution and depth, but in the process left the DPI change portion to the noobs. Well Larry, I admit I am a noob at dllcall, because I cannot see how to change the DPI using the DEVMODE dllstruct you created, since it does not seem to follow the format on MSDN.

For reference, the original post is here.

My current (very unsuccessful) attempt is here:

Func DisplayChangeDPI($dpi)
    $DM_LOGPIXELS = 0x00020000
    $DEVMODE = DLLStructCreate("byte[32];int[10];byte[32];int[6]")
    $b = DLLCall("user32.dll", "int", "EnumDisplaySettings", "ptr", 0, "long", 0, "ptr", DLLStructGetPtr($DEVMODE))
    If @error Then
        $b = 0
    Else
        $b = $b[0]
    EndIf
    If $b <> 0 Then
        ;??????  DllStructSetData($DEVMODE, 6, $DM_LOGPIXELS)
    EndIf
EndFunc

#cs
Func DisplayChangeDPI($dpi)
{
    DEVMODE DevM;
    long ret;

    EnumDisplaySettings(NULL,0,&DevM);

    DevM.dmFields = DM_LOGPIXELS;
    DevM.dmLogPixels = dpi;

    ret = ChangeDisplaySettings(&DevM, CDS_TEST);

    switch(ret)
    {
        case DISP_CHANGE_RESTART:
            return 2;
        case DISP_CHANGE_SUCCESSFUL:
            ChangeDisplaySettings(&DevM, CDS_UPDATEREGISTRY);
            SendMessage(HWND_BROADCAST, WM_DISPLAYCHANGE, (WPARAM)DevM.dmBitsPerPel, (LPARAM)(DevM.dmPelsHeight * 2 ^ 16 + DevM.dmPelsWidth));
            return 1;
        default:
            return 0;
    }
}
#ce
Edited by this-is-me

Who else would I be?

Share this post


Link to post
Share on other sites



Bumping for Larry's perusal.


Who else would I be?

Share this post


Link to post
Share on other sites

Nevermind, I found information on an undocumented function that allows a DPI change. Here it is for those who want to know:

DllCall("syssetup.dll", "int", "SetupChangeFontSize", "int_ptr", 0, "wstr", "96")

The target DPI (in this case 96) must be specified in string format. This function will only take effect after a system restart.


Who else would I be?

Share this post


Link to post
Share on other sites

Larry, do you mean WM_SETTINGSCHANGE?


Who else would I be?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now