14 de julio de 2012

Cambiar la resolución del monitor desde VFP

Una excelente función del turco Cetin Basoz que nos permite cambiar la resolución de la pantalla desde Visual FoxPro.

? SetScreenresolution(1024,768)

FUNCTION SetScreenresolution(tnWidth,tnHeight,tnFrequency)

  #DEFINE ENUM_CURRENT_SETTINGS -1
  #DEFINE CDS_UPDATEREGISTRY = 0x01
  #DEFINE CDS_TEST 0x02
  #DEFINE DISP_CHANGE_SUCCESSFUL 0
  #DEFINE DISP_CHANGE_RESTART 1
  #DEFINE DISP_CHANGE_FAILED -1
  #DEFINE DM_PELSWIDTH 0x00080000
  #DEFINE DM_PELSHEIGHT 0x00100000
  #DEFINE DM_DISPLAYFREQUENCY 0x00400000

  LOCAL lpDevMode,result
  DECLARE INTEGER EnumDisplaySettings IN win32API ;
    STRING deviceName,;
    INTEGER modeNum, ;
    STRING @ lpdevMode

  DECLARE LONG ChangeDisplaySettings IN win32API ;
    STRING lpDevMode, ;
    INTEGER dwflags

  lpdevMode = REPLICATE(CHR(0),512)

  EnumDisplaySettings(0,ENUM_CURRENT_SETTINGS,@lpdevMode)

  *!*    ? "Current settings are:",;
  *!*        CTOBIN(Substr(m.lpdevMode,109,4),"4RS"),;
  *!*        CTOBIN(Substr(m.lpdevMode,113,4),"4RS")

  * Width and Height
  lpdevMode = STUFF(m.lpdevMode,109,4,Int2DWord(m.tnWidth))
  lpdevMode = STUFF(m.lpdevMode,113,4,Int2DWord(m.tnHeight))

  IF !EMPTY(m.tnFrequency)
    lpdevMode = STUFF(m.lpdevMode,121,4,Int2DWord(m.tnFrequency)) && Frequency
    lpdevMode = STUFF(m.lpdevMode,41,4,;
      Int2DWord(BITOR(DM_PELSWIDTH,DM_PELSHEIGHT,DM_DISPLAYFREQUENCY))) && dmFields
  ELSE
    lpdevMode = STUFF(m.lpdevMode,41,4,;
      Int2DWord(BITOR(DM_PELSWIDTH,DM_PELSHEIGHT))) && dmFields
  ENDIF

  result = ChangeDisplaySettings(m.lpdevMode,CDS_TEST)

  IF !( result = DISP_CHANGE_SUCCESSFUL )
    MESSAGEBOX("Mode is not supported",0+48,'Monitor settings')
  ELSE
    ChangeDisplaySettings(m.lpdevMode,0)
    TEXT to m.lcSetting noshow
La resolución de su pantalla ha sido cambiada.
Presione [Si] para confirmar el cambio.
Se restablecerá automáticamente la resolución en 30 segundos.
    ENDTEXT

    IF MESSAGEBOX(m.lcSetting,4+64,'Monitor settings',30000) != 6
      ChangeDisplaySettings(0,0) && restore
    ENDIF

  ENDIF
ENDFUNC

FUNCTION Int2DWord(tInt)
  LOCAL lcDWord,ix
  lcDWord = ''
  FOR ix=1 TO 4
    lcDword = m.lcDword + CHR( INT(m.tInt / 256^(m.ix-1)) % 256 )
  ENDFOR
  RETURN m.lcDword
ENDFUNC

1 comentario :

Los comentarios son moderados, por lo que pueden demorar varias horas para su publicación.