473,320 Members | 2,041 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Detect screen resolution in ASP.NET

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
1 3765
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Michael Hill | last post by:
I have a perl script that i use to render a html page. In that page i call out a stylesheet. If the user has a 800x600 display the fonts are really too big. Since screen resolution is a function...
157
by: Dennis | last post by:
Is there some way --using, say, DOM or javascript-- to detect the current pixel width and/or height of a relatively sized table or of one of its columns or rows. I'm going to be writing javascript...
8
by: Brent | last post by:
Does anyone know the best way to detect and track a visitors screen resolution. I know the javascript to detect the users resolution but I am a bit confused on the best way to track and save this....
2
by: EMW | last post by:
I created my page to work on a 800x600 size window, but when the user has his/her screen set on a larger size, they'll get a empty area at the right side of the screen. I don't like this, looks...
3
by: Luis Esteban Valencia | last post by:
Detect screen resolution? IS THAT POSSIBLE? -- LUIS ESTEBAN VALENCIA MICROSOFT DCE 2. MIEMBRO ACTIVO DE ALIANZADEV
3
by: What-a-Tool | last post by:
I recently created an application on my 19" monitor - looked good. Tried running it on a 17 inch monitor - didn't look so good anymore. Is there a way that monitor resolution/screen size can be...
1
by: simchajoy2000 | last post by:
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: ...
0
by: JaimeM26 | last post by:
Does anyone know how to detect and move/resize the Taskbar in VB.NET? I am able to determine if it is on the top or bottom by comparing the following 2 items. ...
3
by: A. Gaubatz | last post by:
Does anyone know a fast and easy way of detecting the user's current screen resolution in VB.NET? Thanks in advance, *** Sent via Developersdex http://www.developersdex.com ***
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.