Mateen
asked on
CHANGING DISPLAY SETTING THROUGH PROGRMME
We are going to develop a programme in our PowerBuilder Application __through which users can change display setting like 1024 x 768, 800x 600 etc. And when he/she leave Application, system reset to its previous display setting.
In this regard, we search various resources but did not find any suitable and comprehensive code in PowerBuilder. But we do find one Code which is in V.B. This is as follows:
Option Explicit
Const WM_DISPLAYCHANGE = &H7E
Const HWND_BROADCAST = &HFFFF&
Const EWX_LOGOFF = 0
Const EWX_SHUTDOWN = 1
Const EWX_REBOOT = 2
Const EWX_FORCE = 4
Const CCDEVICENAME = 32
Const CCFORMNAME = 32
Const DM_BITSPERPEL = &H40000
Const DM_PELSWIDTH = &H80000
Const DM_PELSHEIGHT = &H100000
Const CDS_UPDATEREGISTRY = &H1
Const CDS_TEST = &H4
Const DISP_CHANGE_SUCCESSFUL = 0
Const DISP_CHANGE_RESTART = 1
Const BITSPIXEL = 12
Private Type DEVMODE
dmDeviceName As String * CCDEVICENAME
dmSpecVersion As Integer
dmDriverVersion As Integer
dmSize As Integer
dmDriverExtra As Integer
dmFields As Long
dmOrientation As Integer
dmPaperSize As Integer
dmPaperLength As Integer
dmPaperWidth As Integer
dmScale As Integer
dmCopies As Integer
dmDefaultSource As Integer
dmPrintQuality As Integer
dmColor As Integer
dmDuplex As Integer
dmYResolution As Integer
dmTTOption As Integer
dmCollate As Integer
dmFormName As String * CCFORMNAME
dmUnusedPadding As Integer
dmBitsPerPel As Integer
dmPelsWidth As Long
dmPelsHeight As Long
dmDisplayFlags As Long
dmDisplayFrequency As Long
End Type
Private Declare Function EnumDisplaySettings Lib "user32" Alias "EnumDisplaySettingsA" (ByVal lpszDeviceName As Long, ByVal iModeNum As Long, lpDevMode As Any) As Boolean
Private Declare Function ChangeDisplaySettings Lib "user32" Alias "ChangeDisplaySettingsA" (lpDevMode As Any, ByVal dwFlags As Long) As Long
Private Declare Function ExitWindowsEx Lib "user32" (ByVal uFlags As Long, ByVal dwReserved As Long) As Long
Private Declare Function GetDeviceCaps Lib "gdi32" (ByVal hdc As Long, ByVal nIndex As Long) As Long
Private Declare Function CreateDC Lib "gdi32" Alias "CreateDCA" (ByVal lpDriverName As String, ByVal lpDeviceName As String, ByVal lpOutput As String, ByVal lpInitData As Any) As Long
Private Declare Function DeleteDC Lib "gdi32" (ByVal hdc As Long) As Long
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Dim OldX As Long, OldY As Long, nDC As Long
Sub ChangeRes(X As Long, Y As Long, Bits As Long)
Dim DevM As DEVMODE, ScInfo As Long, erg As Long, an As VbMsgBoxResult
'Get the info into DevM
erg = EnumDisplaySettings(0&, 0&, DevM)
'This is what we're going to change
DevM.dmFields = DM_PELSWIDTH Or DM_PELSHEIGHT Or DM_BITSPERPEL
DevM.dmPelsWidth = X 'ScreenWidth
DevM.dmPelsHeight = Y 'ScreenHeight
DevM.dmBitsPerPel = Bits '(can be 8, 16, 24, 32 or even 4)
'Now change the display and check if possible
erg = ChangeDisplaySettings(DevM
'Check if succesfull
Select Case erg&
Case DISP_CHANGE_RESTART
an = MsgBox("You've to reboot", vbYesNo + vbSystemModal, "Info")
If an = vbYes Then
erg& = ExitWindowsEx(EWX_REBOOT, 0&)
End If
Case DISP_CHANGE_SUCCESSFUL
erg = ChangeDisplaySettings(DevM
ScInfo = Y * 2 ^ 16 + X
'Notify all the windows of the screen resolution change
SendMessage HWND_BROADCAST, WM_DISPLAYCHANGE, ByVal Bits, ByVal ScInfo
MsgBox "Everything's ok", vbOKOnly + vbSystemModal, "It worked!"
Case Else
MsgBox "Mode not supported", vbOKOnly + vbSystemModal, "Error"
End Select
End Sub
Private Sub Form_Load()
'KPD-Team 1999
'URL: http://www.allapi.net/
'E-Mail: KPDTeam@Allapi.net
Dim nDC As Long
'retrieve the screen's resolution
OldX = Screen.Width / Screen.TwipsPerPixelX
OldY = Screen.Height / Screen.TwipsPerPixelY
'Create a device context, compatible with the screen
nDC = CreateDC("DISPLAY", vbNullString, vbNullString, ByVal 0&)
'Change the screen's resolution
ChangeRes 640, 480, GetDeviceCaps(nDC, BITSPIXEL)
End Sub
Private Sub Form_Unload(Cancel As Integer)
'restore the screen resolution
ChangeRes OldX, OldY, GetDeviceCaps(nDC, BITSPIXEL)
'delete our device context
DeleteDC nDC
End Sub
How to do the same in PB7
Zaheer:
http://www.rgagnon.com/pbdetails/pb-0049.html
ASKER
Thank you for your answer but we have already implemented this. This solution simply detect current Display Setting but does not change it.
Works for vb, what o/p value did you get i guess it must be -2 ---> "The specified graphics mode is not supported".
Also the code was for older OS ( my guess ).
The below link is in vb, see if that helps you out
http://www.mangovision.com/vbapi/ref/c/changedisplaysettings.html
Also the code was for older OS ( my guess ).
The below link is in vb, see if that helps you out
http://www.mangovision.com/vbapi/ref/c/changedisplaysettings.html
oops, sorry you already have it in vb, dont u.!!
silly me.
silly me.
ASKER
Dear Experts:
I have found pb script and constantly working in it. First I am trying to remove some difficulties myself. If I coudn't succeed then I would paste the script for help.
Regards:
Zaheer
I have found pb script and constantly working in it. First I am trying to remove some difficulties myself. If I coudn't succeed then I would paste the script for help.
Regards:
Zaheer
Would help others a lot if you pasted your pb script even if you succeed :-).
You can always ask for a refund of your points and paste the completed pb script so others can have it as a reference.
You can always ask for a refund of your points and paste the completed pb script so others can have it as a reference.
ASKER
Dear Experts of Powerbuilder:
I am Mateen co-worker of Zaheer (tasks transferred to me).
By copying something from here and something from there I managed to reach so far
Exportable version of w_res: (May please be imported by dear experts.)
$PBExportHeader$w_res.srw
$PBExportComments$change resolution
forward
global type w_res from window
end type
type cb_2 from commandbutton within w_res
end type
type cb_1 from commandbutton within w_res
end type
type devmode from structure within w_res
end type
end forward
type devmode from structure
character dmdevicename[32]
integer dmspecversion
integer dmdriverversion
integer dmsize
integer dmdriverextra
long dmfields
integer dmorientation
integer dmpapersize
integer dmpaperlength
integer dmpaperwidth
integer dmscale
integer dmcopies
integer dmdefaultsource
integer dmprintquality
integer dmcolor
integer dmduplex
integer dmyresolution
integer dmttoption
integer dmcollate
character dmformname[32]
integer dmlogpixels
long dmbitsperpel
long dmpelswidth
long dmpelsheight
long dmdisplayflags
long dmdisplayfrequency
long dmicmmethod
long dmicmintent
long dmmediatype
long dmdithertype
long dmreserved1
long dmreserved2
end type
global type w_res from window
integer x = 837
integer y = 388
integer width = 795
integer height = 496
boolean titlebar = true
string title = "Untitled"
boolean controlmenu = true
boolean minbox = true
boolean maxbox = true
boolean resizable = true
cb_2 cb_2
cb_1 cb_1
end type
global w_res w_res
type prototypes
FUNCTION long ChangeDisplaySettingsA (ref devmode lpst, ulong Flags) LIBRARY "USER32.DLL"
FUNCTION int GetSystemMetrics(int indexnum) LIBRARY "user32.dll"
//function long GetDeviceCaps(ulong HDC,long nIndex) LIBRARY "gdi32.dll"
//function long GetDC(ulong HWND) LIBRARY "user32.dll"
end prototypes
type variables
long CurrHRes ,CurrVRes ,CurrBPP
ulong DM_BITSPERPEL_H = 4*16*16*16*16
long DM_PELSWIDTH_H = 8*16*16*16*16
long DM_PELSHEIGHT_H = 16*16*16*16*16
long DM_DISPLAYFLAGS_H = 2*16*16*16*16*16
long CDS_FORCE = 4*16*16*16*16*16*16*16
end variables
on w_res.create
this.cb_2=create cb_2
this.cb_1=create cb_1
this.Control[]={this.cb_2, &
this.cb_1}
end on
on w_res.destroy
destroy(this.cb_2)
destroy(this.cb_1)
end on
type cb_2 from commandbutton within w_res
integer x = 224
integer y = 220
integer width = 297
integer height = 88
integer taborder = 2
integer textsize = -10
integer weight = 400
fontpitch fontpitch = variable!
fontfamily fontfamily = swiss!
string facename = "Arial"
string text = "1024x768"
end type
event clicked;devmode dm
long ret
dm.dmPelsWidth = 1024
dm.dmPelsHeight = 768
dm.dmBitsPerPel = 16
dm.dmFields = DM_PELSWIDTH_H + DM_PELSHEIGHT_H + DM_BITSPERPEL_H + DM_DISPLAYFLAGS_H
dm.dmSize = 148
CurrHRes = GetSystemMetrics(0)
CurrVRes = GetSystemMetrics(1)
CurrBPP = 16
if dm.dmPelsWidth = CurrHRes and dm.dmPelsHeight = CurrVRes and dm.dmBitsPerPel = CurrBPP then
messagebox("current Screen Resolution", string(CurrHRes) + " , " + string(CurrVRes) + ", " +string (CurrBPP) )
else
ret = ChangeDisplaySettingsA(dm, CDS_FORCE)
Messagebox('',"the Screen Resolution had been chenged")
end if
/*
if ChangeDisplaySettingsA(dm, CDS_FORCE) <>0 then
Messagebox('Error',"Perhap s Your harware is not up to a task ")
end if
*/
end event
type cb_1 from commandbutton within w_res
integer x = 224
integer y = 124
integer width = 297
integer height = 88
integer taborder = 1
integer textsize = -10
integer weight = 400
fontpitch fontpitch = variable!
fontfamily fontfamily = swiss!
string facename = "Arial"
string text = "800x600"
end type
event clicked;devmode dm
long ret
int modeSwitch
dm.dmPelsWidth = 800
dm.dmPelsHeight = 600
dm.dmBitsPerPel = 16
dm.dmFields = DM_PELSWIDTH_H + DM_PELSHEIGHT_H + DM_BITSPERPEL_H + DM_DISPLAYFLAGS_H
dm.dmSize = 148
CurrHRes = GetSystemMetrics(0)
CurrVRes = GetSystemMetrics(1)
CurrBPP = 16
if dm.dmPelsWidth = CurrHRes and dm.dmPelsHeight = CurrVRes and dm.dmBitsPerPel = CurrBPP then
messagebox("current Screen Resolution", string(CurrHRes) + " , " + string(CurrVRes) + ", " +string (CurrBPP) )
else
ret = ChangeDisplaySettingsA(dm, CDS_FORCE)
end if
/*if ChangeDisplaySettingsA(dm, CDS_FORCE) <>0 then
Messagebox('Error',"Perhap s Your harware is not up to a task ")
end if */
end event
This window when run waits to be clicked any of the two command button cb_1(text=800x600) and cb_2 (text=1024x768)
and when clicked the screen resolution is changed accordingly. Alothoug it is working but I don't know why (cut from here and cut from there and giving various tries, but truly don't know conceptually what is happening). Therefore, I am unable to make a small change in this and that is
when a user logs in (off course throug my standard login window) it should keep the current user's computer resolution in memory and then change the resolution always to 1024x768 and the window is exited the compueter'sresolution should be changed back to its original.
Thanks in advance:
Mateen:
I am Mateen co-worker of Zaheer (tasks transferred to me).
By copying something from here and something from there I managed to reach so far
Exportable version of w_res: (May please be imported by dear experts.)
$PBExportHeader$w_res.srw
$PBExportComments$change resolution
forward
global type w_res from window
end type
type cb_2 from commandbutton within w_res
end type
type cb_1 from commandbutton within w_res
end type
type devmode from structure within w_res
end type
end forward
type devmode from structure
character dmdevicename[32]
integer dmspecversion
integer dmdriverversion
integer dmsize
integer dmdriverextra
long dmfields
integer dmorientation
integer dmpapersize
integer dmpaperlength
integer dmpaperwidth
integer dmscale
integer dmcopies
integer dmdefaultsource
integer dmprintquality
integer dmcolor
integer dmduplex
integer dmyresolution
integer dmttoption
integer dmcollate
character dmformname[32]
integer dmlogpixels
long dmbitsperpel
long dmpelswidth
long dmpelsheight
long dmdisplayflags
long dmdisplayfrequency
long dmicmmethod
long dmicmintent
long dmmediatype
long dmdithertype
long dmreserved1
long dmreserved2
end type
global type w_res from window
integer x = 837
integer y = 388
integer width = 795
integer height = 496
boolean titlebar = true
string title = "Untitled"
boolean controlmenu = true
boolean minbox = true
boolean maxbox = true
boolean resizable = true
cb_2 cb_2
cb_1 cb_1
end type
global w_res w_res
type prototypes
FUNCTION long ChangeDisplaySettingsA (ref devmode lpst, ulong Flags) LIBRARY "USER32.DLL"
FUNCTION int GetSystemMetrics(int indexnum) LIBRARY "user32.dll"
//function long GetDeviceCaps(ulong HDC,long nIndex) LIBRARY "gdi32.dll"
//function long GetDC(ulong HWND) LIBRARY "user32.dll"
end prototypes
type variables
long CurrHRes ,CurrVRes ,CurrBPP
ulong DM_BITSPERPEL_H = 4*16*16*16*16
long DM_PELSWIDTH_H = 8*16*16*16*16
long DM_PELSHEIGHT_H = 16*16*16*16*16
long DM_DISPLAYFLAGS_H = 2*16*16*16*16*16
long CDS_FORCE = 4*16*16*16*16*16*16*16
end variables
on w_res.create
this.cb_2=create cb_2
this.cb_1=create cb_1
this.Control[]={this.cb_2,
this.cb_1}
end on
on w_res.destroy
destroy(this.cb_2)
destroy(this.cb_1)
end on
type cb_2 from commandbutton within w_res
integer x = 224
integer y = 220
integer width = 297
integer height = 88
integer taborder = 2
integer textsize = -10
integer weight = 400
fontpitch fontpitch = variable!
fontfamily fontfamily = swiss!
string facename = "Arial"
string text = "1024x768"
end type
event clicked;devmode dm
long ret
dm.dmPelsWidth = 1024
dm.dmPelsHeight = 768
dm.dmBitsPerPel = 16
dm.dmFields = DM_PELSWIDTH_H + DM_PELSHEIGHT_H + DM_BITSPERPEL_H + DM_DISPLAYFLAGS_H
dm.dmSize = 148
CurrHRes = GetSystemMetrics(0)
CurrVRes = GetSystemMetrics(1)
CurrBPP = 16
if dm.dmPelsWidth = CurrHRes and dm.dmPelsHeight = CurrVRes and dm.dmBitsPerPel = CurrBPP then
messagebox("current Screen Resolution", string(CurrHRes) + " , " + string(CurrVRes) + ", " +string (CurrBPP) )
else
ret = ChangeDisplaySettingsA(dm,
Messagebox('',"the Screen Resolution had been chenged")
end if
/*
if ChangeDisplaySettingsA(dm,
Messagebox('Error',"Perhap
end if
*/
end event
type cb_1 from commandbutton within w_res
integer x = 224
integer y = 124
integer width = 297
integer height = 88
integer taborder = 1
integer textsize = -10
integer weight = 400
fontpitch fontpitch = variable!
fontfamily fontfamily = swiss!
string facename = "Arial"
string text = "800x600"
end type
event clicked;devmode dm
long ret
int modeSwitch
dm.dmPelsWidth = 800
dm.dmPelsHeight = 600
dm.dmBitsPerPel = 16
dm.dmFields = DM_PELSWIDTH_H + DM_PELSHEIGHT_H + DM_BITSPERPEL_H + DM_DISPLAYFLAGS_H
dm.dmSize = 148
CurrHRes = GetSystemMetrics(0)
CurrVRes = GetSystemMetrics(1)
CurrBPP = 16
if dm.dmPelsWidth = CurrHRes and dm.dmPelsHeight = CurrVRes and dm.dmBitsPerPel = CurrBPP then
messagebox("current Screen Resolution", string(CurrHRes) + " , " + string(CurrVRes) + ", " +string (CurrBPP) )
else
ret = ChangeDisplaySettingsA(dm,
end if
/*if ChangeDisplaySettingsA(dm,
Messagebox('Error',"Perhap
end if */
end event
This window when run waits to be clicked any of the two command button cb_1(text=800x600) and cb_2 (text=1024x768)
and when clicked the screen resolution is changed accordingly. Alothoug it is working but I don't know why (cut from here and cut from there and giving various tries, but truly don't know conceptually what is happening). Therefore, I am unable to make a small change in this and that is
when a user logs in (off course throug my standard login window) it should keep the current user's computer resolution in memory and then change the resolution always to 1024x768 and the window is exited the compueter'sresolution should be changed back to its original.
Thanks in advance:
Mateen:
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Solution of this question is in
https://www.experts-exchange.com/questions/20966034/Screen-Resolution.html
https://www.experts-exchange.com/questions/20966034/Screen-Resolution.html