Detect screen resolution in ASP.NET

  • Thread starter Thread starter simchajoy2000
  • Start date Start date
S

simchajoy2000

Is there anyway to dynamically detect the screen resolution of a
client's computer in ASP.NET?? All the code I have found on the
internet was specifically for Access forms. I found this code:

'Module Declarations
Const WM_HORZRES = 8
Const WM_VERTRES = 10

Declare Function WM_apiGetDeviceCaps _
Lib "gdi32" Alias "GetDeviceCaps" _
(ByVal hdc As Long, ByVal nIndex As Long) As Long
Declare Function WM_apiGetDesktopWindow _
Lib "user32" Alias "GetDesktopWindow" () As Long
Declare Function WM_apiGetDC _
Lib "user32" Alias "GetDC" _
(ByVal hwnd As Long) As Long
Declare Function WM_apiReleaseDC _
Lib "user32" Alias "ReleaseDC" _
(ByVal hwnd As Long, ByVal hdc As Long) As Long
Declare Function WM_apiGetSystemMetrics _
Lib "user32" Alias "GetSystemMetrics" _
(ByVal nIndex As Long) As Long

Function xg_GetScreenResolution() As String
'return the display height and width
Dim DisplayHeight As Integer
Dim DisplayWidth As Integer
Dim hDesktopWnd As Long
Dim hDCcaps As Long
Dim iRtn As Integer

'* make API calls to get desktop settings
hDesktopWnd = WM_apiGetDesktopWindow() 'get handle to desktop
hDCcaps = WM_apiGetDC(hDesktopWnd) 'Get Display Context
DisplayHeight = WM_apiGetDeviceCaps(hDCcaps, WM_VERTRES)
DisplayWidth = WM_apiGetDeviceCaps(hDCcaps, WM_HORZRES)
iRtn = WM_apiReleaseDC(hDesktopWnd, hDCcaps)

xg_GetScreenResolution = DisplayWidth & "x" & DisplayHeight

End Function

But whenever VB.NET gets to the DisplayHeight part, it says that "the
Arithmetic operation resulted in an overflow"

Can anyone help me either fix this problem or find another solution???
Thanks!!

Joy
 
Dies this help...

screen_width = System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width
screen_height = System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height

If it works, it looks easier than your solution :)
 
Back
Top