Change/save Screen-resolution to Applic.-resol. at Runtime ?

Change/save Screen-resolution to Applic.-resol. at Runtime ?

Postby ukoenig » Wed Mar 30, 2011 7:09 pm

Hello,

I found some API-functions to make it possible, to adjust the Screen-resolution
to Application-resolution.
Does it make sense, to adjust it at Prog-start and restore the original Resolution at Prog.-end ?
I don't know, if it is possible, to change the Resolution in silent-mode.
Maybe somebody found a working Solution ?

// get existing Resolution
Declare Function EnumDisplaySettings Lib "user32" Alias "EnumDisplaySettingsA" _
(ByVal lpszDeviceName As Long, ByVal iModeNum As Long, lptypDevMode As Any) As Boolean

// Change Resolution
Declare Function ChangeDisplaySettings Lib "user32" Alias "ChangeDisplaySettingsA" _
(lptypDevMode As Any, ByVal dwFlags As Long) As Long


// Exit Windows
Declare Function ExitWindowsEx Lib "user32" (ByVal uFlags As Long, ByVal dwReserved _
As Long) As Long

Best Regards
Uwe :?:
Last edited by ukoenig on Thu Apr 07, 2011 8:16 am, edited 1 time in total.
Since 1995 ( the first release of FW 1.9 )
i work with FW.
If you have any questions about special functions, maybe i can help.
User avatar
ukoenig
 
Posts: 4043
Joined: Wed Dec 19, 2007 6:40 pm
Location: Germany

Re: Changing Screen-resolution to Applic.-resol. at Runtime ?

Postby Bayron » Wed Mar 30, 2011 10:34 pm

Uwe,

I think that this code does what you need...

Code: Select all  Expand view
CamReso ( 1024, 768, .f. )


Code: Select all  Expand view
///////////////////////////////////////////////////////////////////
/// FUNCION CamReso
/// CAMBIA RESOLUCION DE PANTALLA TEMPORALMENTE
/// Manuel Valdenebro 2008
/// Adaptación ChangeRes() Marcelo Gomes/Yuri Marcelino
/// http://www.fivewin.com.br/forum/topic.a ... C_ID=10465
/// ---------------------------------------
// nAncho ancho pantalla
// nAlto alto pantalla
// lPreguntar si pregunta antes de realizar el cambio
///////////////////////////////////////////////////////////////////

#Include "dll.ch"
#Include "Struct.ch"

Function CamReso(nAncho, nAlto, lPreguntar)
Local DM_PELSWIDTH := nHex("80000")
Local DM_PELSHEIGHT := nHex("100000")
Local oDevMode
Local lPosible
Local cBuffer
Local lCamReso := .f.
*DEFAULT lPreguntar := .t.
*DEFAULT nAlto := GetSysMetrics(1)
*DEFAULT nAncho := GetSysMetrics(0)

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
// Comprueba si es posible cambiar la resolución
lPosible := EnumDisplaySettings(0, 0, @cBuffer)

// Si es posible cambiar la resolución
IF lPosible
if lPreguntar
if MsgYesNo("Desea cambiar la resolución?", "Atención")
else
RETURN lCamReso
endif
endi
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 FUNCTION ChangeDisplaySettings(@lpDevMode AS LPSTR,;
dwFlags AS DWORD) AS DWORD;
FROM "ChangeDisplaySettingsA" LIB "User32.dll"

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

 
=====>

Bayron Landaverry
(215)2226600 Philadelphia,PA, USA
+(502)46727275 Guatemala
MayaBuilders@gMail.com

FWH12.04||Harbour 3.2.0 (18754)||BCC6.5||UEstudio 10.10||
Windows 7 Ultimate

FiveWin, One line of code and it's done...
User avatar
Bayron
 
Posts: 815
Joined: Thu Dec 24, 2009 12:46 am
Location: Philadelphia, PA

Re: Changing Screen-resolution to Applic.-resol. at Runtime ?

Postby ukoenig » Thu Mar 31, 2011 11:18 am

Hello Byron,

Thank You very much.
The Function works perfect.
But there is still a problem, I have to find out :

After changing the Screen-resolution, I get a System-Message : cannot continue.
Maybe I have to create a extra small Exe-file.

I tested a PRG-Structure like :

Code: Select all  Expand view

Function MAIN()
..
..
IF CHANGE_SCR(1152, 864, .T.) = .F. // new Resolution
   MsgAlert( "Cannot change Screen-resolution !","Attention"
ELSE
   DEFINE DIALOG oWndMain FROM  0, 0 TO 260, 400 PIXEL TRANSPARENT ;
   STYLE WS_POPUP | WS_VISIBLE | WS_DLGFRAME | WS_THICKFRAME
   ..
   ..
   ACTIVATE DIALOG oWndMain CENTERED

   CHANGE_SCR( 1024, 768, .T.) // old Resolution
ENDIF

RETURN NIL
 


Best Regards
Uwe :?:
Since 1995 ( the first release of FW 1.9 )
i work with FW.
If you have any questions about special functions, maybe i can help.
User avatar
ukoenig
 
Posts: 4043
Joined: Wed Dec 19, 2007 6:40 pm
Location: Germany

Re: Changing Screen-resolution to Applic.-resol. at Runtime ?

Postby Bayron » Fri Apr 01, 2011 12:52 am

Hi Uwe, the function should be called with .F. so It does not ask's for confirmation to change the resolution
Code: Select all  Expand view
CHANGE_SCR(1152, 864, .F.)


Maybe that is the problem, or it may be a problem with your video card????

I used it a while ago and did not had problems...

If you post an compiled example, I can test in my computer to see if gives me the same problem....
=====>

Bayron Landaverry
(215)2226600 Philadelphia,PA, USA
+(502)46727275 Guatemala
MayaBuilders@gMail.com

FWH12.04||Harbour 3.2.0 (18754)||BCC6.5||UEstudio 10.10||
Windows 7 Ultimate

FiveWin, One line of code and it's done...
User avatar
Bayron
 
Posts: 815
Joined: Thu Dec 24, 2009 12:46 am
Location: Philadelphia, PA

Re: Changing Screen-resolution to Applic.-resol. at Runtime ?

Postby ukoenig » Fri Apr 01, 2011 1:35 pm

Hello Byron,

the Screenshots of my Tests :

started with 1152 x 864
Image

switching to Application Screen-resolution 1024 x 768,
the Application stopps.
Image

Maybe it is a Dialog and not a Window ?

The Main-prgstructure :
Code: Select all  Expand view

FUNCTION MAIN()
LOCAL oWndMain
LOCAL nScrwidth := GetSysmetrics( 0 )
LOCAL nScrheight := GetSysmetrics( 1 )
LOCAL cRestart := "NO"
...
... 
SetBalloon( .T. ) // Balloon shape required for tooltips
c_path := CURDRIVE() + ":\" + GETCURDIR()  

IF nScrwidth <> 1024 .and. nScrheight <> 768
    cRestart := "
YES"
ENDIF

oFont1 := TFont():New( "
Arial", 0, 16,.F.,.T.,  0,  0,  0,.F.,.F.)

DEFINE BITMAP oAlpha FILENAME c_Path + "
\bitmaps\LOGO2.bmp"

DEFINE DIALOG oWndMain FROM  0, 0 TO 260, 400 PIXEL TRANSPARENT ;
STYLE WS_POPUP | WS_VISIBLE | WS_DLGFRAME | WS_THICKFRAME
...
...
@ 90, 125 BTNBMP oBtn5 OF oWndMain  ;
SIZE 40, 40 ;
TOP NOBORDER ;
FILE c_path + "
\Bitmaps\32Screen.bmp" ;      
PROMPT "
&Screen" ;
FONT oFont1 ;
ACTION ( TEST_SCR(oWndMain) )
oBtn5:cTooltip :=  { "
New" + CRLF + ;
      "
Screen-resolution 1024 x 768","Screen", 1, CLR_BLACK, 14089979 }
oBtn5:lTransparent := .T.
oBtn5:l2007 := .F.
oBtn5:SetColor( 16312263 )
...
...
ACTIVATE DIALOG oWndMain CENTERED ;
ON INIT GRADBRU1(oWndMain, 0.8, 8388608, 14853684, .T.) ;
ON PAINT ABPaint( hDC, 50, 10, oAlpha:hBitmap, 255 )  // Horiz / Vertical

oFont1:End()  

// Back to different Screen-resolution RESET
IF cRestart = "
YES"
    CHANGE_SCR( nScrwidth, nScrheight, .T.)
ENDIF

RETURN NIL  

// --------- Use 1024 x 768 if Screenresolution is different ------------

FUNCTION TEST_SCR(oWndMain)

IF cRestart = "
YES"
   IF CHANGE_SCR(1024, 768, .T.) = .F.
      MsgAlert( "
Cannot change Screen-resolution !","Attention")
   ENDIF
ELSE
    MsgAlert( "
No Screen-resolution-change needed !","Attention" )
ENDIF

RETURN NIL


Added to Sample : Testbtn.prg
I got the same Result. After changing the Screen-resolution
Message : Testbtn.exe doesn't work anymore ....

Image

Code: Select all  Expand view

// Defining ButtonBar buttons which uses Bitmaps files from disk

#include "FiveWin.ch"

static oWnd

//----------------------------------------------------------------------------//

function Main()

   local oBar
   local oBrush
   local oPopup

   DEFINE BRUSH oBrush COLOR nRGB( 12, 129, 87 )

   DEFINE WINDOW oWnd FROM 1, 10 TO 20, 60 ;
      TITLE "Testing Buttons from disk" ;
      BRUSH oBrush

   DEFINE BUTTONBAR oBar OF oWnd _3D

   DEFINE BUTTON OF oBar FILE "..\bitmaps\16x16\exit.bmp" ;
      ACTION MsgInfo( CHANGE_SCR( 1152, 864, .T.) ) ;
      MESSAGE "You can place..."

   MENU oPopup POPUP
      MENUITEM "Test" WHEN .f.
      MENUITEM "Test" ACTION MsgInfo( "Any action" )
      MENU
         MENUITEM "Another" WHEN .f.
         MENUITEM "More..."
      ENDMENU
   ENDMENU

   DEFINE BUTTON OF oBar FILE "..\bitmaps\16x16\Open.bmp" GROUP ;
      ACTION MsgInfo( FWVERSION ) ;
      MESSAGE "Any BMP File here..." ;
      MENU oPopup

   DEFINE BUTTON OF oBar FILE "..\bitmaps\16x16\Cut.bmp" ;
      ACTION MsgInfo( FWVERSION ) ;
      MESSAGE "Reading it from disk !!!"

   SET MESSAGE OF oWnd TO FWVERSION + " " + FWCOPYRIGHT

   ACTIVATE WINDOW oWnd

return nil

///////////////////////////////////////////////////////////////////
/// FUNCION CamReso
/// CAMBIA RESOLUCION DE PANTALLA TEMPORALMENTE
/// Manuel Valdenebro 2008
/// Adaptación ChangeRes() Marcelo Gomes/Yuri Marcelino
/// http://www.fivewin.com.br/forum/topic.a ... C_ID=10465
/// ---------------------------------------
// nAncho ancho pantalla
// nAlto alto pantalla
// lPreguntar si pregunta antes de realizar el cambio
///////////////////////////////////////////////////////////////////

#Include "dll.ch"
#Include "Struct.ch"

Function CHANGE_SCR(nScrwidth, nScrheight, lChange)
Local DM_PELSWIDTH := nHex("80000")
Local DM_PELSHEIGHT := nHex("100000")
Local oDevMode
Local lPosible
Local cBuffer
Local lScrReso := .f.
*DEFAULT lPreguntar := .t.
*DEFAULT nScrwidth := GetSysMetrics(1) // Width
*DEFAULT nScrheight := GetSysMetrics(0) // Height

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
// Comprueba si es posible cambiar la resolución
lPosible := EnumDisplaySettings(0, 0, @cBuffer)
// Change if possible
IF lPosible
    IF lChange
        IF MsgYesNo("Do You want to change the Resolution ?", "Attention")
        ELSE
            RETURN lScrReso
        ENDIF
    ENDIF
    oDevMode:nFields := nOr(DM_PELSWIDTH, DM_PELSHEIGHT )
    oDevMode:nPelWidth := nScrwidth
    oDevMode:nPelHeigh := nScrheight
    cBuffer:=oDevMode:cBuffer
    TRY
        ChangeDisplaySettings(@cBuffer, 4)
        lScrReso := .T.
    CATCH
        MsgAlert("Modo no soportado", "Error" )
    END
ELSE
    MsgAlert("Modo no soportado", "Error" )
ENDIF

RETURN lScrReso


//----------------------------------------------------------------------------//

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

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

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


Best Regards
Uwe :?:
Last edited by ukoenig on Fri Apr 01, 2011 8:16 pm, edited 1 time in total.
Since 1995 ( the first release of FW 1.9 )
i work with FW.
If you have any questions about special functions, maybe i can help.
User avatar
ukoenig
 
Posts: 4043
Joined: Wed Dec 19, 2007 6:40 pm
Location: Germany

Re: Changing Screen-resolution to Applic.-resol. at Runtime ?

Postby Bayron » Fri Apr 01, 2011 4:11 pm

Hi Uwe, I confirm that there is a problem with the code!!!

I was able to temporaly change the resolution by using the function directly right after declaring Local Variables without using a button to call it. No error was produced, but the window was not created and the original resolution was restored after a few seconds...

Sorry I can not help you any further in the issue...
=====>

Bayron Landaverry
(215)2226600 Philadelphia,PA, USA
+(502)46727275 Guatemala
MayaBuilders@gMail.com

FWH12.04||Harbour 3.2.0 (18754)||BCC6.5||UEstudio 10.10||
Windows 7 Ultimate

FiveWin, One line of code and it's done...
User avatar
Bayron
 
Posts: 815
Joined: Thu Dec 24, 2009 12:46 am
Location: Philadelphia, PA

Re: Changing Screen-resolution to Applic.-resol. at Runtime ?

Postby Bayron » Fri Apr 01, 2011 4:27 pm

I just read in the Brasilian forum, that it seem that it produces the error when using xHarbour...

I don't use Harbour, maybe someone can test it...
=====>

Bayron Landaverry
(215)2226600 Philadelphia,PA, USA
+(502)46727275 Guatemala
MayaBuilders@gMail.com

FWH12.04||Harbour 3.2.0 (18754)||BCC6.5||UEstudio 10.10||
Windows 7 Ultimate

FiveWin, One line of code and it's done...
User avatar
Bayron
 
Posts: 815
Joined: Thu Dec 24, 2009 12:46 am
Location: Philadelphia, PA

Re: Changing Screen-resolution to Applic.-resol. at Runtime ?

Postby Daniel Garcia-Gil » Fri Apr 01, 2011 5:14 pm

Hello

it's a sample using the function from C

Code: Select all  Expand view


#include "fivewin.ch"


function main()

? CHANGEDISLPAYRESOLUTION( 1440, 900 )

return nil


#pragma BEGINDUMP
#include <hbapi.h>
#include <windows.h>


HB_FUNC( CHANGEDISLPAYRESOLUTION )
{
   DWORD dmBitsPerPel = hb_pcount() > 2 ? hb_parnl( 3 ) : 0 ;
   DWORD dmPelsWidth  = hb_parnl( 1 );
   DWORD dmPelsHeight = hb_parnl( 2 );   
     DEVMODE DevMode;
   
   EnumDisplaySettings( NULL, ENUM_CURRENT_SETTINGS, &DevMode );
   
   DevMode.dmPelsWidth = dmPelsWidth;
   DevMode.dmPelsHeight = dmPelsHeight;
   if( dmBitsPerPel > 0 )
      DevMode.dmBitsPerPel = dmBitsPerPel;

   hb_retnl( ChangeDisplaySettings( &DevMode, CDS_RESET ) );
    
}

#pragma ENDDUMP
 
User avatar
Daniel Garcia-Gil
 
Posts: 2365
Joined: Wed Nov 02, 2005 11:46 pm
Location: Isla de Margarita

Re: Changing Screen-resolution to Applic.-resol. at Runtime ?

Postby ukoenig » Fri Apr 01, 2011 6:33 pm

Daniel,

Thank You very much.
This Function works GREAT without any Problems.
As well the RESET, to restore the old Screen-resolution after finishing the Application.
No Validation needed ( works in silent Mode ).
It's funny, that calling original API-functions, making Problems.

CHANGEDISLPAYRESOLUTION( 1152, 864 )
must use supported Values :
1024 x 768
1152 x 864
1280 x 720
1280 x 768
1280 x 960
1280 x 1024
1600 x 1200

Sample :
Code: Select all  Expand view

#include "FiveWin.ch"

FUNCTION MAIN()
LOCAL oWndMain
LOCAL nScrwidth := GetSysmetrics( 0 ), nScrheight := GetSysmetrics( 1 )

IF nScrwidth <> 1024 .and. nScrheight <> 768
     CHANGEDISLPAYRESOLUTION( 1024, 768 ) // Application Screen-resolution
ENDIF

DEFINE DIALOG oWndMain FROM  0, 0 TO 260, 400 PIXEL TRANSPARENT ;
STYLE WS_POPUP | WS_VISIBLE | WS_DLGFRAME | WS_THICKFRAME
// ...
// ...
ACTIVATE DIALOG oWndMain CENTERED

// Back to different Screen-resolution RESET
IF nScrwidth <> 1024 .and. nScrheight <> 768
     CHANGEDISLPAYRESOLUTION( nScrwidth, nScrheight )
ENDIF

RETURN NIL  

// ----------------

#pragma BEGINDUMP
#include <hbapi.h>
#include <windows.h>


HB_FUNC( CHANGEDISLPAYRESOLUTION )
{
   DWORD dmBitsPerPel = hb_pcount() > 2 ? hb_parnl( 3 ) : 0 ;
   DWORD dmPelsWidth  = hb_parnl( 1 );
   DWORD dmPelsHeight = hb_parnl( 2 );  
     DEVMODE DevMode;
   
   EnumDisplaySettings( NULL, ENUM_CURRENT_SETTINGS, &DevMode );
   
   DevMode.dmPelsWidth = dmPelsWidth;
   DevMode.dmPelsHeight = dmPelsHeight;
   if( dmBitsPerPel > 0 )
      DevMode.dmBitsPerPel = dmBitsPerPel;

   hb_retnl( ChangeDisplaySettings( &DevMode, CDS_RESET ) );
   
}

#pragma ENDDUMP
 


Best Regards
Uwe :lol:
Last edited by ukoenig on Fri Apr 01, 2011 7:26 pm, edited 2 times in total.
Since 1995 ( the first release of FW 1.9 )
i work with FW.
If you have any questions about special functions, maybe i can help.
User avatar
ukoenig
 
Posts: 4043
Joined: Wed Dec 19, 2007 6:40 pm
Location: Germany

Re: Changing Screen-resolution to Applic.-resol. at Runtime ?

Postby Bayron » Fri Apr 01, 2011 7:09 pm

Am I missing something???

I Compiled Uwe's sample, but the resolution does not changes!!!!

When I press escape to exit, I see the screen blink, but nothing else happens!!!!
=====>

Bayron Landaverry
(215)2226600 Philadelphia,PA, USA
+(502)46727275 Guatemala
MayaBuilders@gMail.com

FWH12.04||Harbour 3.2.0 (18754)||BCC6.5||UEstudio 10.10||
Windows 7 Ultimate

FiveWin, One line of code and it's done...
User avatar
Bayron
 
Posts: 815
Joined: Thu Dec 24, 2009 12:46 am
Location: Philadelphia, PA

Re: Changing Screen-resolution to Applic.-resol. at Runtime ?

Postby Daniel Garcia-Gil » Fri Apr 01, 2011 7:34 pm

Byron

did you tested my sample?
User avatar
Daniel Garcia-Gil
 
Posts: 2365
Joined: Wed Nov 02, 2005 11:46 pm
Location: Isla de Margarita

Re: Changing Screen-resolution to Applic.-resol. at Runtime ?

Postby Bayron » Fri Apr 01, 2011 8:01 pm

Daniel Garcia-Gil wrote:Byron

did you tested my sample?


Yes I did; I got a dialog Alert:
Image
=====>

Bayron Landaverry
(215)2226600 Philadelphia,PA, USA
+(502)46727275 Guatemala
MayaBuilders@gMail.com

FWH12.04||Harbour 3.2.0 (18754)||BCC6.5||UEstudio 10.10||
Windows 7 Ultimate

FiveWin, One line of code and it's done...
User avatar
Bayron
 
Posts: 815
Joined: Thu Dec 24, 2009 12:46 am
Location: Philadelphia, PA

Re: Changing Screen-resolution to Applic.-resol. at Runtime ?

Postby Daniel Garcia-Gil » Fri Apr 01, 2011 8:05 pm

Bayron


you're trying set a mode not supported...

Code: Select all  Expand view
DISP_CHANGE_SUCCESSFUL=  0      ;The settings change was successful.
DISP_CHANGE_RESTART=     1  ;The computer must be restarted in order for the graphics mode to work.
DISP_CHANGE_FAILED=     -1  ;The display driver failed the specified graphics mode.
DISP_CHANGE_BADMODE=    -2  ;The graphics mode is not supported.
DISP_CHANGE_NOTUPDATED= -3      ;Unable to write settings to the registry.
DISP_CHANGE_BADFLAGS=   -4      ;An invalid set of flags was passed in.
DISP_CHANGE_BADPARAM=   -5  ; Bad parameters
User avatar
Daniel Garcia-Gil
 
Posts: 2365
Joined: Wed Nov 02, 2005 11:46 pm
Location: Isla de Margarita

Re: Changing Screen-resolution to Applic.-resol. at Runtime ?

Postby Bayron » Fri Apr 01, 2011 8:15 pm

Thanks Daniel,
That is why I compiled Uwe's sample...

I did not get the error, but the resolution does not changes....

By the way, the resolution in your sample should be supported in my system!!!

Image

Maybe it has something to do that I have 2 monitors???
=====>

Bayron Landaverry
(215)2226600 Philadelphia,PA, USA
+(502)46727275 Guatemala
MayaBuilders@gMail.com

FWH12.04||Harbour 3.2.0 (18754)||BCC6.5||UEstudio 10.10||
Windows 7 Ultimate

FiveWin, One line of code and it's done...
User avatar
Bayron
 
Posts: 815
Joined: Thu Dec 24, 2009 12:46 am
Location: Philadelphia, PA

Re: Changing Screen-resolution to Applic.-resol. at Runtime ?

Postby ukoenig » Fri Apr 01, 2011 8:20 pm

A better sample with Button-selection :
( The Exit-button restores to original Screen-resolution )

Image

Code: Select all  Expand view

#include "FiveWin.ch"

FUNCTION MAIN()
LOCAL oWndMain, oFont
LOCAL nScrwidth := GetSysmetrics( 0 ), nScrheight := GetSysmetrics( 1 )

// adjust to Application Screen-resolution
// --------------------------------------------------
IF nScrwidth <> 1024 .and. nScrheight <> 768
     CHANGEDISLPAYRESOLUTION( 1024, 768 )
ENDIF

DEFINE FONT oFont NAME 'MS Sans Serif' SIZE 16, 16

DEFINE DIALOG oWndMain FROM  0, 0 TO 260, 400 PIXEL TRANSPARENT ;
STYLE WS_POPUP | WS_VISIBLE | WS_DLGFRAME | WS_THICKFRAME

@ 15,30 BUTTON "Exit" size 100,25 font oFont OF oWndMain PIXEL ;
ACTION ( nScrwidth := 1024, ; // Application Screen-resolution
        nScrheight := 768, ;
        oWndMain:End() )

@ 45,30 BUTTON "1280 x 720" size 100,25 font oFont OF oWndMain PIXEL ;
ACTION ( CHANGEDISLPAYRESOLUTION( 1280, 720 ), ;
                 nScrwidth := GetSysmetrics( 0 ), ;
         nScrheight := GetSysmetrics( 1 ) )

@ 75,30 BUTTON "1280 x 720" size 100,25 font oFont OF oWndMain PIXEL ;
ACTION ( CHANGEDISLPAYRESOLUTION( 1280, 1024 ), ;
                 nScrwidth := GetSysmetrics( 0 ), ;
         nScrheight := GetSysmetrics( 1 ) )

ACTIVATE DIALOG oWndMain CENTERED

oFont:End()

// RESET to 1024 x 768
// ------------------------
CHANGEDISLPAYRESOLUTION( nScrwidth, nScrheight )

RETURN NIL  

// ----------------

#pragma BEGINDUMP
#include <hbapi.h>
#include <windows.h>


HB_FUNC( CHANGEDISLPAYRESOLUTION )
{
   DWORD dmBitsPerPel = hb_pcount() > 2 ? hb_parnl( 3 ) : 0 ;
   DWORD dmPelsWidth  = hb_parnl( 1 );
   DWORD dmPelsHeight = hb_parnl( 2 );  
     DEVMODE DevMode;
   
   EnumDisplaySettings( NULL, ENUM_CURRENT_SETTINGS, &DevMode );
   
   DevMode.dmPelsWidth = dmPelsWidth;
   DevMode.dmPelsHeight = dmPelsHeight;
   if( dmBitsPerPel > 0 )
      DevMode.dmBitsPerPel = dmBitsPerPel;

   hb_retnl( ChangeDisplaySettings( &DevMode, CDS_RESET ) );
   
}

#pragma ENDDUMP
 


Best Regards
Uwe :lol:
Since 1995 ( the first release of FW 1.9 )
i work with FW.
If you have any questions about special functions, maybe i can help.
User avatar
ukoenig
 
Posts: 4043
Joined: Wed Dec 19, 2007 6:40 pm
Location: Germany

Next

Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 97 guests