how to read current screen resolution from registry?

Hi! All

how can i read current screen resolution from registry so that i can fix my form's height and width properties according to the user's current screen resolution.

and you never know what windows OS is used by the user, 'cause registry of Win 9x and NT/2000/xp they all differ from each other. so plz help me that where win 9x and win NT/2000/xp put screen resolution like DefaultSetting.XResolution.

another thing is when i check registry by regedit or regedt32 utilities of two different pcs running Windows xp. i see different registry keys for same setting. i don't know how to resolve it. for example

PC 1 has:
My Computer\HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Hardware Profiles\0001\System\CurrentControlSet\Control\VIDEO\{174B9BA7-C42A-4AB2-A608-0B2AB712F81}\0000\DefaultSettings.XResolution = 1024

and PC 2 has:

My Computer\HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Hardware Profiles\0001\System\CurrentControlSet\Control\VIDEO\{760A9AB2-D21B-2EA1-B201-9A2AA374A43}\0000\DefaultSettings.XResolution = 1024

I get confused when i see the change in values between { } braces. it means every pc has different no in braces and i don't know what key to open 'cause u have to put constant values for each computer when opening the keys by RegCreateKey API for same OS.

thanx in advance for helping me.

regards
:wave:
[1446 byte] By [yaardilbar] at [2007-11-18 21:56:53]
# 1 Re: how to read current screen resolution from registry?
why bother?

why not:

Dim screenW as Integer, screenH As Integer
screenW = Screen.Width/Screen.twipsPerPixelX
screenH = Screen.Height/Screen.twipsPerPixelY

-

need to put the calc in there because standard measurements are in twips
cjard at 2007-11-9 23:02:01 >
# 2 Re: how to read current screen resolution from registry?
but bear in mind that form width and height are also in twips
cjard at 2007-11-9 23:02:56 >
# 3 Re: how to read current screen resolution from registry?
and what about my {} braces Question?
:confused:
yaardilbar at 2007-11-9 23:04:00 >
# 4 Re: how to read current screen resolution from registry?
Cjard,

I'm sort of a newbie and this is exactly what I'm looking for.

Dim screenW as Integer, screenH As Integer
screenW = Screen.Width/Screen.twipsPerPixelX
screenH = Screen.Height/Screen.twipsPerPixelY

need to put the calc in there because standard measurements are in twips

I developed a program that fills the screen for a 800X600 screen. There are others, including me, that use a 1024X768 screen.

Might you go into a little more detail on how to do this? I would like to use the mim/max button that comes with the form. (That is if it's not difficult).

Thanks
nbCathy at 2007-11-9 23:05:00 >
# 5 Re: how to read current screen resolution from registry?
A post thought - I need to changed the resolution and not just the widthheight. ( I think ).

Regards
nbCathy at 2007-11-9 23:06:00 >
# 6 Re: how to read current screen resolution from registry?
and what about my {} braces Question?
:confused:
What you are looking at are GUID's. However, as the earlier posts have stated, you do not normally check the registry to know the current resolution.
WizBang at 2007-11-9 23:07:05 >
# 7 Re: how to read current screen resolution from registry?
Hallo yaardilbar,

trust WizBang.

Here a documentation (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/sysinfo/base/getsystemmetrics.asp) and an example on how to get what you want from the screen.

Option Explicit
Private Declare Function GetSystemMetrics Lib "user32.dll" _
(ByVal nIndex As Long) _
As Long


' Constant Name(Value)..Description
Private Const SM_CXSCREEN = 0 'Width of screen
Private Const SM_CYSCREEN = 1 'Height of screen
Private Const SM_CXVSCROLL = 2 'Width of arrow bitmap on vertical scroll bar
Private Const SM_CYHSCROLL = 3 'Height of arrow bitmap on horizontal scroll bar
Private Const SM_CYCAPTION = 4 'Height of caption
Private Const SM_CXBORDER = 5 'Width of window frame that cannot be sized
Private Const SM_CYBORDER = 6 'Height of window frame that cannot be sized
Private Const SM_CXDLGFRAME = 7 'Width of frame when window has WS_DLGFRAME style
Private Const SM_CYDLGFRAME = 8 'Height of frame when window has WS_DLGFRAME style
Private Const SM_CXHTHUMB = 10 'Width of thumb on horizontal scroll bar
Private Const SM_CYHTHUMB = 9 'Height of thumb on horizontal scroll bar
Private Const SM_CXICON = 11 'Width of icon
Private Const SM_CYICON = 12 'Height of icon
Private Const SM_CXCURSOR = 13 'Width of cursor
Private Const SM_CYCURSOR = 14 'Height of cursor
Private Const SM_CYMENU = 15 'Height of single-line menu
Private Const SM_CXFULLSCREEN = 13 'Width of window client area for full-screen window
Private Const SM_CYFULLSCREEN = 17 'Height of window client area for full-screen window (Height - Caption)
Private Const SM_CYKANJIWINDOW = 18 'Height of Kanji window
Private Const SM_MOUSEPRESENT = 19 'Mouse present
Private Const SM_CYVSCROL = 20 'Height of arrow bitmap on vertical scroll bar
Private Const SM_CXHSCROLL = 21 'Width of arrow bitmap on horizontal scroll bar
Private Const SM_DEBUG = 22 'Nonzero if Windows debug version
Private Const SM_CXMIN = 28 'Minimum width of window
Private Const SM_CYMIN = 29 'Minimum width of window
Private Const SM_CXSIZE = 30 'Width of bitmaps contained in the title bar
Private Const SM_CYSIZE = 31 'Height of bitmaps contained in the title bar
Private Const SM_CXFRAME = 32 'Width of window frame that can be sized
Private Const SM_CYFRAME = 33 'Height of window frame that can be sized
Private Const SM_CXMINTRACK = 34 'Minimum tracking width of window
Private Const SM_CYMINTRACK = 35 'Minimum tracking height of window

Private Sub Form_Load()
Dim strScreen As String
strScreen = "ScreenX = " & CStr(GetSystemMetrics(SM_CXSCREEN)) & " - "
strScreen = strScreen & "ScreenY = " & CStr(GetSystemMetrics(SM_CYSCREEN))
Me.Caption = strScreen
End Sub

James
jamesa at 2007-11-9 23:08:04 >
# 8 Re: how to read current screen resolution from registry?
i have a similar issue wherby i need to extract data fot the screen resolution into XML. did you find out how to get this data from the registry for different "no#'s" in the brackets?
mrbuggerlugs at 2007-11-9 23:09:02 >