473,386 Members | 1,785 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,386 software developers and data experts.

Change Resolution

Hi All,
I am currently working on a product using vb and ms- access..
I want to change the resolution of my own software irrespective of windows settings
as done in case of various games.The product best works on 800-600
Feb 3 '08 #1
2 1541
lotus18
866 512MB
Hi

I'm using this for some of my program. This example came from allapi.net

Expand|Select|Wrap|Line Numbers
  1.  
  2. Option Explicit
  3. Const WM_DISPLAYCHANGE = &H7E
  4. Const HWND_BROADCAST = &HFFFF&
  5. Const EWX_LOGOFF = 0
  6. Const EWX_SHUTDOWN = 1
  7. Const EWX_REBOOT = 2
  8. Const EWX_FORCE = 4
  9. Const CCDEVICENAME = 32
  10. Const CCFORMNAME = 32
  11. Const DM_BITSPERPEL = &H40000
  12. Const DM_PELSWIDTH = &H80000
  13. Const DM_PELSHEIGHT = &H100000
  14. Const CDS_UPDATEREGISTRY = &H1
  15. Const CDS_TEST = &H4
  16. Const DISP_CHANGE_SUCCESSFUL = 0
  17. Const DISP_CHANGE_RESTART = 1
  18. Const BITSPIXEL = 12
  19. Private Type DEVMODE
  20.     dmDeviceName As String * CCDEVICENAME
  21.     dmSpecVersion As Integer
  22.     dmDriverVersion As Integer
  23.     dmSize As Integer
  24.     dmDriverExtra As Integer
  25.     dmFields As Long
  26.     dmOrientation As Integer
  27.     dmPaperSize As Integer
  28.     dmPaperLength As Integer
  29.     dmPaperWidth As Integer
  30.     dmScale As Integer
  31.     dmCopies As Integer
  32.     dmDefaultSource As Integer
  33.     dmPrintQuality As Integer
  34.     dmColor As Integer
  35.     dmDuplex As Integer
  36.     dmYResolution As Integer
  37.     dmTTOption As Integer
  38.     dmCollate As Integer
  39.     dmFormName As String * CCFORMNAME
  40.     dmUnusedPadding As Integer
  41.     dmBitsPerPel As Integer
  42.     dmPelsWidth As Long
  43.     dmPelsHeight As Long
  44.     dmDisplayFlags As Long
  45.     dmDisplayFrequency As Long
  46. End Type
  47. Private Declare Function EnumDisplaySettings Lib "user32" Alias "EnumDisplaySettingsA" (ByVal lpszDeviceName As Long, ByVal iModeNum As Long, lpDevMode As Any) As Boolean
  48. Private Declare Function ChangeDisplaySettings Lib "user32" Alias "ChangeDisplaySettingsA" (lpDevMode As Any, ByVal dwFlags As Long) As Long
  49. Private Declare Function ExitWindowsEx Lib "user32" (ByVal uFlags As Long, ByVal dwReserved As Long) As Long
  50. Private Declare Function GetDeviceCaps Lib "gdi32" (ByVal hdc As Long, ByVal nIndex As Long) As Long
  51. Private Declare Function CreateDC Lib "gdi32" Alias "CreateDCA" (ByVal lpDriverName As String, ByVal lpDeviceName As String, ByVal lpOutput As String, ByVal lpInitData As Any) As Long
  52. Private Declare Function DeleteDC Lib "gdi32" (ByVal hdc As Long) As Long
  53. Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
  54. Dim OldX As Long, OldY As Long, nDC As Long
  55. Sub ChangeRes(X As Long, Y As Long, Bits As Long)
  56.     Dim DevM As DEVMODE, ScInfo As Long, erg As Long, an As VbMsgBoxResult
  57.     'Get the info into DevM
  58.     erg = EnumDisplaySettings(0&, 0&, DevM)
  59.     'This is what we're going to change
  60.     DevM.dmFields = DM_PELSWIDTH Or DM_PELSHEIGHT Or DM_BITSPERPEL
  61.     DevM.dmPelsWidth = X 'ScreenWidth
  62.     DevM.dmPelsHeight = Y 'ScreenHeight
  63.     DevM.dmBitsPerPel = Bits '(can be 8, 16, 24, 32 or even 4)
  64.     'Now change the display and check if possible
  65.     erg = ChangeDisplaySettings(DevM, CDS_TEST)
  66.     'Check if succesfull
  67.     Select Case erg&
  68.         Case DISP_CHANGE_RESTART
  69.             an = MsgBox("You've to reboot", vbYesNo + vbSystemModal, "Info")
  70.             If an = vbYes Then
  71.                 erg& = ExitWindowsEx(EWX_REBOOT, 0&)
  72.             End If
  73.         Case DISP_CHANGE_SUCCESSFUL
  74.             erg = ChangeDisplaySettings(DevM, CDS_UPDATEREGISTRY)
  75.             ScInfo = Y * 2 ^ 16 + X
  76.             'Notify all the windows of the screen resolution change
  77.             SendMessage HWND_BROADCAST, WM_DISPLAYCHANGE, ByVal Bits, ByVal ScInfo
  78.             MsgBox "Everything's ok", vbOKOnly + vbSystemModal, "It worked!"
  79.         Case Else
  80.             MsgBox "Mode not supported", vbOKOnly + vbSystemModal, "Error"
  81.     End Select
  82. End Sub
  83. Private Sub Form_Load()
  84.     Dim nDC As Long
  85.     'retrieve the screen's resolution
  86.     OldX = Screen.Width / Screen.TwipsPerPixelX
  87.     OldY = Screen.Height / Screen.TwipsPerPixelY
  88.     'Create a device context, compatible with the screen
  89.     nDC = CreateDC("DISPLAY", vbNullString, vbNullString, ByVal 0&)
  90.     'Change the screen's resolution
  91.     ChangeRes 800, 600, GetDeviceCaps(nDC, BITSPIXEL)
  92. End Sub
  93. Private Sub Form_Unload(Cancel As Integer)
  94.     'restore the screen resolution
  95.     ChangeRes OldX, OldY, GetDeviceCaps(nDC, BITSPIXEL)
  96.     'delete our device context
  97.     DeleteDC nDC
  98. End Sub
  99.  
  100.  
Rey Sean
Feb 3 '08 #2
Hi Rey Sean,
It is also helpful for others.

Regards,
shuvo2k6
Feb 3 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Erik Bethke | last post by:
Hello All, I am trying to clean up some polish bugs with the Shanghai game I am working on and I am currently stuck on trying to get the right event for detecting when the user has changed the...
1
by: Erik Bethke | last post by:
Hello All, I am trying to clean up some polish bugs with the Shanghai game I am working on and I am currently stuck on trying to get the right event for detecting when the user has changed the...
3
by: Jeroen van vliet | last post by:
Hello, my website is best viewed, and specially designed for 1024 X 786 and higher, when shown on 800 X 600 it look horrible, now is it possible when the viewer enters my site, his/her...
12
by: techie | last post by:
Hi All, I have a portal working on an intranet for a company. The portal was designed keeping in mind the resolution of 1024*768. I am including a ..css file in all the files. Now i have to make...
4
by: pjac | last post by:
I need some help with some VB language that will change the screen resolution on a monitor when a MS-Access 2000 database is opened from 1024 x 768 to 800 x 600. Any help with this effort would be...
8
by: lauren quantrell | last post by:
Is there a way to force a change in a user's screen resolution using VBA code without having any input from the user? Example: User John Backwards has his screen set to 800 x 600 pixels. Backwards...
1
by: Bertrand1978 | last post by:
Hi All. I am using VC++/Visual Studio 6.0. I can get the current screen resolution with GetSystemMetrics(), but how do you change the screen resolution ? I guess I couldn't find a...
7
by: JaimeM26 | last post by:
I have been able to determine the resolution on the users machine, but i am looking for a way to force the resolution to 1024 X 768 if it is not that already in VB.NET. Can someone please help me...
8
by: Lad | last post by:
Is it possible to change a picture resolution with Python? Let's say I have a picture with a resolution of 96 dpi and I would like to increase to 256dpi or higher. Thank you for your reply. LL
8
by: miladhatam | last post by:
can i change the size of a file dynamically ? for example have 100 Kb and i want to decrease it to 20 Kb thanks
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.