By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,996 Members | 896 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,996 IT Pros & Developers. It's quick & easy.

Detect screen resolution in ASP.NET

P: n/a
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
Jul 21 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Dies this help...

screen_width = System.Windows.Forms.Screen.PrimaryScreen.Bounds.W idth
screen_height = System.Windows.Forms.Screen.PrimaryScreen.Bounds.H eight

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

<si***********@yahoo.com> wrote in message
news:1d**************************@posting.google.c om...
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

Jul 21 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.