Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Screen resolution?

Status
Not open for further replies.

sermac

Programmer
Jul 27, 2002
238
US
Hi:
What is the command/function to determine what screen resolution user is using?
THX in advance.
Bill
 
sermac
Try this:

--------------
Local lcRect
Local lnLeft, lnright, lnRight, lnBottom
Local lnWidth, lnHeight

Declare Long GetDesktopWindow in User32
Declare Long GetWindowRect in User32 ;
Long nhWnd, String @lpRect

lcRect = replicate(chr(0), 16)
If (GetWindowRect(GetDesktopWindow(), @lcRect) != 0)
lnWidth = DWord2Num(substr(lcRect,9,4)) - ;
DWord2Num(substr(lcRect,1,4))
lnHeight = DWord2Num(substr(lcRect,13,4)) - ;
DWord2Num(substr(lcRect,5,4))
?'Current Screen Resolution: ' + ;
alltrim(str(lnWidth)) + 'x' + alltrim(str(lnHeight))
endif
Clear Dlls
Clear all


Function DWord2Num(tcBuffer)
Local lnResult
lnResult = asc(substr(tcBuffer, 1,1)) + ;
asc(substr(tcBuffer, 2,1)) * 256 + ;
asc(substr(tcBuffer, 3,1)) * 65536 + ;
asc(substr(tcBuffer, 4,1)) * 16777216

Return lnResult
EndFunc
-----------

Regards

-- AirCon --
 
See the SYSMETRIC() command.

It returns the size of the operating system's screen
elements. There are 34 different values returned by
sysmetric() - sysmetric(1) through sysmetric(34)

? sysmetric(1) && Screen width
? sysmetric(2) && Screen height

Darrell

'We all must do the hard bits so when we get bit we know where to bite' :)
 
Hi AirCon,

How can we change the screen resolution progrmaticly from VFP.
 
Kurjo

Although feasable with a few API Calls, I would not recommend changing the screen resolution with VFP, you can encounter an video card that cannot support it, or just frustrate the user that has set his monitor the way he wants it, I would suggest you desig your application to suit the lowest common denominator (most likely 800X600 or something close to that).


Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
 
Hi Kurjo

As an addition to what Mike already said, when the display setting is change, icon position on the desktop also change. Some users can get mad when an application change the display resolution without his/her permission.
Do it at your own risk! :)


Here is the code:
--------------
Local lnReturn, lnWidth, lnHeight, lnScrInfo
Local lnhDC, lnBPP, lnPELsWidth, lnPELsHeight
Local lcPELsWidth, lcPELsHeight
Local DeviceMode, OldDeviceMode

Declare Long EnumDisplaySettings in User32 ;
String cDeviceName, Long nGraphicsMode, String @cDevMode

Declare Long ChangeDisplaySettings in User32 ;
String cDevMode, Long nFlags

Declare Integer SendMessage in User32 ;
Long nhWnd, Integer Msg, Integer wParam, Long lParam

*** New Display Settings (800x600)
lnWidth = 800
lnHeight = 600

DeviceMode = replicate(chr(0), 134)
If (EnumDisplaySettings(Null, -1, @DeviceMode) != 0)
OldDeviceMode = DeviceMode
lnBPP = DWord2Num(substr(DeviceMode,105,4))
lnPELsWidth = DWord2Num(substr(DeviceMode,109,4))
lnPELsHeight = DWord2Num(substr(DeviceMode,113,4))

lcPELsWidth = Num2DWord(lnWidth)
lcPELsHeight = Num2DWord(lnHeight)

DeviceMode = left(DeviceMode, 108) + ;
lcPELsWidth + lcPELsHeight + right(DeviceMode, 8)
lnReturn = ChangeDisplaySettings(DeviceMode, 4)
Do case
Case (lnReturn == 0) && success
ChangeDisplaySettings(DeviceMode, 1)

*** Notify all the windows that display settings has changed
lnScrInfo = lnHeight * 2^lnBPP + lnWidth
SendMessage(0xFFFF, 0x7E, lnBPP, lnScrInfo)
MessageBox('Display Settings has been changed' ;
+ chr(13) + 'Press any key to Reset', 64, ;
' Reset Display Settings')

ChangeDisplaySettings(OldDeviceMode, 1)
lnScrInfo = lnPELsHeight * 2^lnBPP + lnPELsWidth
SendMessage(0xFFFF, 0x7E, lnBPP, lnScrInfo)

Case (lnReturn == 1) && need restart
?'Change Display Needs to restart'

Otherwise
MessageBox('Display Settings not supported', ;
16, ' *** ERROR ***')
EndCase
endif
Clear Dlls
Clear all


Function DWord2Num(tcBuffer)
Local lnResult
lnResult = asc(substr(tcBuffer, 1,1)) + ;
asc(substr(tcBuffer, 2,1)) * 256 + ;
asc(substr(tcBuffer, 3,1)) * 65536 + ;
asc(substr(tcBuffer, 4,1)) * 16777216

Return lnResult
EndFunc

Function Num2DWord(tnNum)
Local lc0, lc1, lc2, lc3
lc3 = chr(int(tnNum / 16777216))
tnNum = mod(tnNum, 16777216)

lc2 = chr(int(tnNum / 65536))
tnNum = mod(tnNum, 65536)

lc1 = chr(int(tnNum / 256))
lc0 = chr(mod(tnNum, 256))

Return lc0 + lc1 + lc2 + lc3
EndFunc
---------------


Regards

-- AirCon --
 
And in addition to AirCon's post vis-a-vis messing
up the user's desktop icons, the positions are stored
in a registry key; the name of which I forget.

It might be possible to grab and store that key, make
the screen changes, and then reset the saved key upon
exit.

Of course that won't help if the user mimimizes your app
and wants to do something on the desktop.

Darrell


'We all must do the hard bits so when we get bit we know where to bite' :)
 
To give my reason for the question. . .
I bought a new "flat" screen 700-1 contrast 19". . .they are getting down into my price range!!!
It asks for 1280x1024. . .not just 1024 x768 if I have on anything less than 1280x1024. . .
Would you believe that it looks and has the best clarity at the 1280x1024. . .( and I thought I needed to upgrade my classes. . .)1014x768 looks ok and works, but 800x600 looks a little funky. . .and 620x480 looks terrible. . .
this ties into my previous question today regarding setviewport and the use of scrollbars on the form, thinking maybe I shd just evolve to the 1024x768 and get the advantage of all the desktop real estate
. . .with the price of flat screens coming down makes me think that is where the world is headed.
 
Sounds like a great display!

Getting back to the previous posts, you can change
the screen resolution in mid-stream, but you may
run into problems with recalcitrant applications
when it comes to resetting their own resolution.

And as stated by myself and AirCon, the end users may
get pretty upset if you mess up their desktop icon
positions. There is probably a way to determine the
names and positions of the desktop items, as I eluded to
in my last post, and to align them temporarily or
permanently based on their density and position, but
I've never done it.

Have fun.

Darrell

'We all must do the hard bits so when we get bit we know where to bite' :)
 
Meant to say 'allude' not elude.



'We all must do the hard bits so when we get bit we know where to bite' :)
 
Darrel,

Yes there is a way to save the icon position and restore it. I know there is one small utility can do this. I'll try to figure this out later.

But to adjust the position maybe difficult to accomplish. Especially if users arrange the desktop manually.

Btw, I miscalculated the DeviceMode structure. It should be this:
DeviceMode = replicate(chr(0), 124)

-- AirCon --
 
One workaround to your screen resolution problem might be to size your forms accordingly. You can programmatically resize the form and the controls on a form as the Atkins/Kramek/Schummer book by Hentenwerke shows. Another possibility I've used is to have one form for 'small screens' and one for 'big screens' with controls closer together,etc., and call one or the other form accordingly.

But generally I think your client will be happier if you make your app fit his condition rather than vice versa.

Have fun!
 
Hey I was on vacation. That is why it took so long to reply. Thanks for the tips from Aircon, Mike, Darrelblackhawk & Sermac.

One of my user set his screen in low resolution. In his screen my app looks funny. He dont want to change his resolution due to his strange screen saver. May be a push from the top will change his mind.

kurjo

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top