Resolution of monitor

Re: Resolution of monitor

Postby Jimmy » Sun Dec 26, 2021 5:49 am

hi,

there are different Way to get Scale-Factor.

for single Monitor you can use "real" / "virtual" Desktop Size to get Scale-Factor

Code: Select all  Expand view
#define HORZRES              0x0008   // (  8) Horizontal width in pixels
#define VERTRES              0x000A   // ( 10) Vertical width in pixels
#define LOGPIXELSX           0x0058   // ( 88) Logical pixels/inch in X
#define LOGPIXELSY           0x005A   // ( 90) Logical pixels/inch in Y
#define DESKTOPVERTRES       0x0075   // (117) Vertical height  of entire desktop in pixels
#define DESKTOPHORZRES       0x0076   // (118) Horizontal width of entire desktop in pixels

Function GetDeskSize(nHDC,lVirtual)
LOCAL nWidth,nHeight
   nWidth  := HMG_CallDLL('GDI32.dll', DLL_OSAPI, 'GetDeviceCaps', nHDC, iif(lVirtual, HORZRES, DESKTOPHORZRES))
   nHeight := HMG_CallDLL('GDI32.dll', DLL_OSAPI, 'GetDeviceCaps', nHDC, iif(lVirtual, VERTRES, DESKTOPVERTRES))
RETURN{nWidth,nHeight}
 

---

for multi-Monitor you need

MonitorFromWindow https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-monitorfromwindow
GetScaleFactorForMonitor https://docs.microsoft.com/en-us/windows/win32/api/shellscalingapi/nf-shellscalingapi-getscalefactorformonitor
DEVICE_SCALE_FACTOR https://docs.microsoft.com/en-us/windows/win32/api/shtypes/ne-shtypes-device_scale_factor

GetScaleFactorForDevice is IMHO outdate
https://docs.microsoft.com/en-us/windows/win32/api/shellscalingapi/nf-shellscalingapi-getscalefactorfordevice
greeting,
Jimmy
User avatar
Jimmy
 
Posts: 1732
Joined: Thu Sep 05, 2019 5:32 am
Location: Hamburg, Germany

Re: Resolution of monitor

Postby Natter » Sun Dec 26, 2021 10:57 am

Jimmy, great! GetDeviceCaps(DC, 117/118) works correctly
Natter
 
Posts: 1221
Joined: Mon May 14, 2007 9:49 am

Re: Resolution of monitor

Postby karinha » Sun Sep 04, 2022 4:12 pm

Hi Jimmy, how do I do this in FiveWin? I don't use HMG.

Hola Jimmy, ¿cómo hago esto en FiveWin? No uso HMG.

Regards, saludos.
João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
User avatar
karinha
 
Posts: 7826
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil

Re: Resolution of monitor

Postby Jimmy » Sun Sep 04, 2022 4:49 pm

hi karinha,
karinha wrote:how do I do this in FiveWin? I don't use HMG.

FiveWin have in c:\fwh\source\winapi\device.c
Code: Select all  Expand view
HB_FUNC( GETDEVICECAPS )     //  ()    HDC, int iIndex

so as Natter wrote use
Code: Select all  Expand view
#define DESKTOPVERTRES       0x0075   // (117) Vertical height  of entire desktop in pixels
#define DESKTOPHORZRES       0x0076   // (118) Horizontal width of entire desktop in pixels

   Vertical   := GetDeviceCaps(DC, 0x0075)
   Horizontal := GetDeviceCaps(DC, 0x0076)
greeting,
Jimmy
User avatar
Jimmy
 
Posts: 1732
Joined: Thu Sep 05, 2019 5:32 am
Location: Hamburg, Germany

Re: Resolution of monitor

Postby karinha » Sun Sep 04, 2022 5:06 pm

Hola Jimmy, ¿puedes hacer un ejemplo completo y funcional? Necesito cambiar la RESOLUCIÓN DEL VIDEO a 1280x768 en tiempo real y luego volver a la RESOLUCIÓN DEL CLIENTE como estaba antes. ¿Es posible o no?

Hi Jimmy, can you make a complete and working example? I need to change the VIDEO RESOLUTION to 1280x768 in realtime, and then go back to CLIENT RESOLUTION as it was before. Is it possible or not?

WINDOW 7 and WINDOWS 10 please.

Gracias, thanks.

Origen:

http://forums.fivetechsupport.com/viewtopic.php?f=6&t=42143&sid=f7177597dbec68af574f19f84a5e1875

Regards, saludos.
João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
User avatar
karinha
 
Posts: 7826
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil

Re: Resolution of monitor

Postby karinha » Sun Sep 04, 2022 5:25 pm

Like in this example Jimmy. The problem is that it works on WINDOWS 7, but it doesn't work on WNDOWS 10, you know?

Como en este ejemplo Jimmy. El problema es que funciona en WINDOWS 7, pero no funciona en WINDOWS 10, ¿Comprendes?

Code: Select all  Expand view

// C:\FWH..\SAMPLES\RESOLU2.PRG

#include 'fivewin.ch'
#Include "dll.ch"
#Include "Struct.ch"

FUNCTION MAIN()

   LOCAL nResoAncho := GetSysMetrics(0)

   IF nResoAncho < 1280 .OR. nResoAncho > 1280

   // CamReso( 800, 600)

   CamReso( 1280, 768)

   MSGINFO('HECHO. AQUI PUEDES INICIAR TU PROGRAMA ELABORADO PARA 1280 X 768')

   ENDIF

RETU nil

Function CamReso( nAncho, nAlto )

   Local DM_PELSWIDTH := nHex("80000")
   Local DM_PELSHEIGHT := nHex("100000")
   Local oDevMode
   Local lPosible
   Local cBuffer
   Local lCamReso := .f.

   DEFAULT nAncho := GetSysMetrics(0), nAlto := GetSysMetrics(1)

   STRUCT oDevMode

      MEMBER cDevName AS STRING LEN 32
      MEMBER nSpecVer AS WORD
      MEMBER nDrvVer AS WORD
      MEMBER nSize AS WORD
      MEMBER nDrvExtra AS WORD
      MEMBER nFields AS DWORD
      MEMBER nOrientat AS WORD
      MEMBER nPaperSiz AS WORD
      MEMBER nPaperLen AS WORD
      MEMBER nPaperWid AS WORD
      MEMBER nScale AS WORD
      MEMBER nCopies AS WORD
      MEMBER nDefSrc AS WORD
      MEMBER nPrnQlty AS WORD
      MEMBER nColor AS WORD
      MEMBER nDuplex AS WORD
      MEMBER nYResolut AS WORD
      MEMBER nTTOpt AS WORD
      MEMBER nCollate AS WORD
      MEMBER cFormName AS STRING LEN 32
      MEMBER nUnusePad AS WORD
      MEMBER nBitsPPel AS DWORD
      MEMBER nPelWidth AS DWORD
      MEMBER nPelHeigh AS DWORD
      MEMBER nDisFlags AS DWORD
      MEMBER nDisFreq AS DWORD

   ENDSTRUCT

   cBuffer := oDevMode:cBuffer
   lPosible := EnumDisplaySettings(0, 0, @cBuffer)

   IF lPosible

      oDevMode:nFields := nOr(DM_PELSWIDTH, DM_PELSHEIGHT )
      oDevMode:nPelWidth := nAncho
      oDevMode:nPelHeigh := nAlto
      cBuffer:=oDevMode:cBuffer

      TRY
         ChangeDisplaySettings(@cBuffer, 4)
         lCamReso := .T.
      CATCH
         MsgAlert("Modo no soportado", "Error" )
      END
   else
      MsgAlert("Modo no soportado", "Error" )
   endif

return lCamReso

DLL32 FUNCTION EnumDisplaySettings(lpszDeviceName AS DWORD,;
iModeNum AS DWORD, ;
@lpDevMode AS LPSTR) AS BOOL PASCAL;
FROM "EnumDisplaySettingsA" LIB "User32.dll"

DLL32 STATIC FUNCTION ChangeDisplaySettings(@lpDevMode AS LPSTR,;
dwFlags AS DWORD) AS DWORD PASCAL;
FROM "ChangeDisplaySettingsA" LIB "User32.dll"

DLL32 FUNCTION ExitWindowsEx(uFlags AS DWORD,;
dwReserved AS DWORD) AS DWORD PASCAL;
LIB "user32.dll"

// FIN
 


Regards, saludos
João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
User avatar
karinha
 
Posts: 7826
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil

Re: Resolution of monitor

Postby Jimmy » Sun Sep 04, 2022 6:32 pm

hi
karinha wrote:The problem is that it works on WINDOWS 7, but it doesn't work on WNDOWS 10, you know?

it work for me as expect under Windows 10 (32 & 64 Bit), 11 and DEV Insider 25193
Code: Select all  Expand view
#INCLUDE "fivewin.CH"

#define DESKTOPVERTRES       0x0075   // (117) Vertical height  of entire desktop in pixels
#define DESKTOPHORZRES       0x0076   // (118) Horizontal width of entire desktop in pixels

PROCEDURE MAIN
LOCAL nWidth    := 800
LOCAL nHeight   := 600
LOCAL oWnd, oFont, hDC
LOCAL Vertical
LOCAL Horizontal

   DEFINE FONT oFont NAME "TAHOMA" SIZE 0, - 18
   DEFINE WINDOW oWnd FROM 0, 0 TO 100,800 PIXEL //nHeight, nWidth  // NOSYSMENU NOCAPTION BORDER NONE

   hDC := GetDc(0)
   Vertical   := GetDeviceCaps(hDC, 0x0075)
   Horizontal := GetDeviceCaps(hDC, 0x0076)
   msginfo(HB_VALTOSTR(Horizontal) +" x "+HB_VALTOSTR(Vertical))

   ACTIVATE WINDOW oWnd CENTER

RETURN
greeting,
Jimmy
User avatar
Jimmy
 
Posts: 1732
Joined: Thu Sep 05, 2019 5:32 am
Location: Hamburg, Germany

Re: Resolution of monitor

Postby karinha » Mon Sep 05, 2022 12:29 pm

Hola Jimmy. Creo que no entendiste lo que quiero. Por favor, para comprender, debe probar el ejemplo que publiqué anteriormente en una máquina con WINDOW 7 y luego en una máquina con WINDOWS 10, entonces comprenderá lo que quiero, ¿de acuerdo?

Hello Jimmy. I think you didn't understand what I want. Please, to understand, you need to test the example I posted above on a machine with WINDOW 7 and then on a machine with WINDOWS 10, then you will understand what I want, ok?

Gracias, thanks.

Regards, saludos.
João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
User avatar
karinha
 
Posts: 7826
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil

Re: Resolution of monitor

Postby Jimmy » Mon Sep 05, 2022 5:14 pm

hi karinha,

i have run your Sample to "switch" Resolution
but my Answer is not a Solution to "switch"

it "just" is to get "native" (real) Size of Display under Windows 7, 8, 10, 11 and DEV Insider
which is the Theme of this Thread
greeting,
Jimmy
User avatar
Jimmy
 
Posts: 1732
Joined: Thu Sep 05, 2019 5:32 am
Location: Hamburg, Germany

Re: Resolution of monitor

Postby karinha » Tue Sep 06, 2022 1:14 pm

Jimmy wrote:hi karinha,

i have run your Sample to "switch" Resolution
but my Answer is not a Solution to "switch"

it "just" is to get "native" (real) Size of Display under Windows 7, 8, 10, 11 and DEV Insider
which is the Theme of this Thread


Ok Jimmy, I appreciate the intention to help. Thank you very much.

Ok Jimmy, agradezco la intención de ayudar. Muchas gracias.

Regards, saludos.
João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
User avatar
karinha
 
Posts: 7826
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil

Re: Resolution of monitor

Postby Horizon » Tue Jan 09, 2024 8:52 am

karinha wrote:Like in this example Jimmy. The problem is that it works on WINDOWS 7, but it doesn't work on WNDOWS 10, you know?

Como en este ejemplo Jimmy. El problema es que funciona en WINDOWS 7, pero no funciona en WINDOWS 10, ¿Comprendes?

Code: Select all  Expand view

// C:\FWH..\SAMPLES\RESOLU2.PRG

#include 'fivewin.ch'
#Include "dll.ch"
#Include "Struct.ch"

FUNCTION MAIN()

   LOCAL nResoAncho := GetSysMetrics(0)

   IF nResoAncho < 1280 .OR. nResoAncho > 1280

   // CamReso( 800, 600)

   CamReso( 1280, 768)

   MSGINFO('HECHO. AQUI PUEDES INICIAR TU PROGRAMA ELABORADO PARA 1280 X 768')

   ENDIF

RETU nil

Function CamReso( nAncho, nAlto )

   Local DM_PELSWIDTH := nHex("80000")
   Local DM_PELSHEIGHT := nHex("100000")
   Local oDevMode
   Local lPosible
   Local cBuffer
   Local lCamReso := .f.

   DEFAULT nAncho := GetSysMetrics(0), nAlto := GetSysMetrics(1)

   STRUCT oDevMode

      MEMBER cDevName AS STRING LEN 32
      MEMBER nSpecVer AS WORD
      MEMBER nDrvVer AS WORD
      MEMBER nSize AS WORD
      MEMBER nDrvExtra AS WORD
      MEMBER nFields AS DWORD
      MEMBER nOrientat AS WORD
      MEMBER nPaperSiz AS WORD
      MEMBER nPaperLen AS WORD
      MEMBER nPaperWid AS WORD
      MEMBER nScale AS WORD
      MEMBER nCopies AS WORD
      MEMBER nDefSrc AS WORD
      MEMBER nPrnQlty AS WORD
      MEMBER nColor AS WORD
      MEMBER nDuplex AS WORD
      MEMBER nYResolut AS WORD
      MEMBER nTTOpt AS WORD
      MEMBER nCollate AS WORD
      MEMBER cFormName AS STRING LEN 32
      MEMBER nUnusePad AS WORD
      MEMBER nBitsPPel AS DWORD
      MEMBER nPelWidth AS DWORD
      MEMBER nPelHeigh AS DWORD
      MEMBER nDisFlags AS DWORD
      MEMBER nDisFreq AS DWORD

   ENDSTRUCT

   cBuffer := oDevMode:cBuffer
   lPosible := EnumDisplaySettings(0, 0, @cBuffer)

   IF lPosible

      oDevMode:nFields := nOr(DM_PELSWIDTH, DM_PELSHEIGHT )
      oDevMode:nPelWidth := nAncho
      oDevMode:nPelHeigh := nAlto
      cBuffer:=oDevMode:cBuffer

      TRY
         ChangeDisplaySettings(@cBuffer, 4)
         lCamReso := .T.
      CATCH
         MsgAlert("Modo no soportado", "Error" )
      END
   else
      MsgAlert("Modo no soportado", "Error" )
   endif

return lCamReso

DLL32 FUNCTION EnumDisplaySettings(lpszDeviceName AS DWORD,;
iModeNum AS DWORD, ;
@lpDevMode AS LPSTR) AS BOOL PASCAL;
FROM "EnumDisplaySettingsA" LIB "User32.dll"

DLL32 STATIC FUNCTION ChangeDisplaySettings(@lpDevMode AS LPSTR,;
dwFlags AS DWORD) AS DWORD PASCAL;
FROM "ChangeDisplaySettingsA" LIB "User32.dll"

DLL32 FUNCTION ExitWindowsEx(uFlags AS DWORD,;
dwReserved AS DWORD) AS DWORD PASCAL;
LIB "user32.dll"

// FIN
 


Regards, saludos


Hi Karinha,

It works in W10. Is it possiple to change display scale factor with this?

Thanks.
Regards,

Hakan ONEMLI

Harbour & MSVC 2022 & FWH 23.04
Horizon
 
Posts: 1322
Joined: Fri May 23, 2008 1:33 pm

Re: Resolution of monitor

Postby Silvio.Falconi » Tue Jan 09, 2024 9:01 am

I have a similar problem, I'll explain
I create the dialogues with


Code: Select all  Expand view
local nWd  := GetSysMetrics(0) * .58
local nHt  := (GetSysMetrics(1) / 2.5 )

DEFINE DIALOG oDlg SIZE nWd, nHt PIXEL

DEFINE BUTTONBAR oBar OF oDlg  SIZE 80,70  BOTTOM NOBORDER  2015

ACTIVATE DIALOG oDlg CENTERED


Image

on Miix320 Lenovo ( tab10) 1920 x 1200 Pixel

I have the dialog smaller and the button bar on too hight




and it happens that in Win10 as in Win7, depending on the monitor, I have the buttonbar too high

for a sample : if th emonitor resolution have 1280x 1024 run ok

if I have the same resolution on a TAblet 10 window the dialog is wrong
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
User avatar
Silvio.Falconi
 
Posts: 7061
Joined: Thu Oct 18, 2012 7:17 pm

Re: Resolution of monitor

Postby Silvio.Falconi » Tue Jan 09, 2024 9:25 am

it is better to use or


local nWd := GetSysMetrics(0) * .90
local nHt := (GetSysMetrics(1) / 2.1 )


or

local nHt := Int( ScreenHeight() * 0.55 )
local nWd := Int( ScreenWidth() * 0.90 )
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
User avatar
Silvio.Falconi
 
Posts: 7061
Joined: Thu Oct 18, 2012 7:17 pm

Re: Resolution of monitor

Postby karinha » Tue Jan 09, 2024 2:11 pm

Code: Select all  Expand view

        nResHoriz := oWnd:nHorzRes() // retorna a resolucao horizontal
        nResVert  := oWnd:nVertRes() // retorna a resolucao vertical


        // complete...

        IF nResHoriz     = 1440 .AND. nResVert = 900 // RESOLUTION...

           DEFINE DIALOG...


        ELSEIF nResHoriz = 1366 .AND. nResVert = 768


        ELSEIF nResHoriz = 1360 .AND. nResVert = 768


        ELSEIF nResHoriz = 1280 .AND. nResVert = 768


        ELSEIF nResHoriz = 1280 .AND. nResVert = 720


        ELSEIF nResHoriz = 1280 .AND. nResVert = 960


        ELSEIF nResHoriz = 1280 .AND. nResVert = 800


        ELSEIF nResHoriz = 1280 .AND. nResVert = 720


        ELSEIF nResHoriz = 1280 .AND. nResVert = 600


        ELSEIF nResHoriz = 1600 .AND. nResVert = 1200


        ELSEIF nResHoriz = 1680 .AND. nResVert = 1050


        ELSEIF nResHoriz = 2560 .AND. nResVert = 1600


        ELSEIF nResHoriz = 1024 .AND. nResVert = 768

           IF ISWINXP()

           ELSE

           ENDIF

        ELSE

           IF ISWINXP()

            ELSE

           ENDIF

        ENDIF
 


Regards, saludos.
João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
User avatar
karinha
 
Posts: 7826
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil

Re: Resolution of monitor

Postby Silvio.Falconi » Wed Jan 10, 2024 7:57 am

karinha wrote:
Code: Select all  Expand view

        nResHoriz := oWnd:nHorzRes() // retorna a resolucao horizontal
        nResVert  := oWnd:nVertRes() // retorna a resolucao vertical


        // complete...

        IF nResHoriz     = 1440 .AND. nResVert = 900 // RESOLUTION...

           DEFINE DIALOG...


        ELSEIF nResHoriz = 1366 .AND. nResVert = 768


        ELSEIF nResHoriz = 1360 .AND. nResVert = 768


        ELSEIF nResHoriz = 1280 .AND. nResVert = 768


        ELSEIF nResHoriz = 1280 .AND. nResVert = 720


        ELSEIF nResHoriz = 1280 .AND. nResVert = 960


        ELSEIF nResHoriz = 1280 .AND. nResVert = 800


        ELSEIF nResHoriz = 1280 .AND. nResVert = 720


        ELSEIF nResHoriz = 1280 .AND. nResVert = 600


        ELSEIF nResHoriz = 1600 .AND. nResVert = 1200


        ELSEIF nResHoriz = 1680 .AND. nResVert = 1050


        ELSEIF nResHoriz = 2560 .AND. nResVert = 1600


        ELSEIF nResHoriz = 1024 .AND. nResVert = 768

           IF ISWINXP()

           ELSE

           ENDIF

        ELSE

           IF ISWINXP()

            ELSE

           ENDIF

        ENDIF
 


Regards, saludos.





seem a joke.....

local nResHoriz := oWnd:nHorzRes()
local nResVert := oWnd:nVertRes()

where is oWnd ?
I don't always have the main window where I can find the oWnd?
Such a solution seems strange to me
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
User avatar
Silvio.Falconi
 
Posts: 7061
Joined: Thu Oct 18, 2012 7:17 pm

Next

Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 85 guests