Quick Search for:  in language:    
Function,will,change,your,Windows,Resolution,
   Code/Articles » |  Newest/Best » |  Community » |  Jobs » |  Other » |  Goto » | 
CategoriesSearch Newest CodeCoding ContestCode of the DayAsk A ProJobsUpload
Visual Basic Stats

 Code: 3,011,557. lines
 Jobs: 115. postings

 How to support the site

 
Sponsored by:

 

You are in:

 
Login



Latest Code Ticker for Visual Basic.
AniViewer
By Jerrame Hertz on 6/30


Click here to see a screenshot of this code!Raw Packet Sniffer
By Coding Genius on 6/30

(Screen Shot)

Check the support of a record set
By Freebug on 6/30


B++ Builder - VB without runtimes
By Anthonius on 6/30


Mr Blonde - Chat Program
By Mr Blonde on 6/30


MSN Messenger Status Detector
By Ryan Cain on 6/30


MSN advanced
By alias1990 on 6/30


MSN Messenger advanced
By alias1990 on 6/30


Locate Database
By Erica Ziegler-Roberts on 6/30


Click here to put this ticker on your site!


Add this ticker to your desktop!


Daily Code Email
To join the 'Code of the Day' Mailing List click here!





Affiliate Sites



 
 
   

ChangeRes

Print
Email
 

Submitted on: 6/1/1999
By: ScAnFrEaK  
Level: Not Given
User Rating: By 3 Users
Compatibility:VB 5.0, VB 6.0

Users have accessed this code 9659 times.
 
 
     This Function will change your Windows Resolution. It is very simple, and it does what most Resolution Change Functions don't do, it changes the the Bits Per Pixels as well as the Screen Width and Height.
 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
 
Terms of Agreement:   
By using this code, you agree to the following terms...   
1) You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.   
2) You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
3) You may link to this code from another website, but ONLY if it is not wrapped in a frame. 
4) You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.

'**************************************
' Name: ChangeRes
' Description:This Function will change 
'     your Windows Resolution. It is very simp
'     le, and it does what most Resolution Cha
'     nge Functions don't do, it changes the t
'     he Bits Per Pixels as well as the Screen
'     Width and Height.
' By: ScAnFrEaK
'
' Inputs:Dim RetValue As Integer
RetValue = ChangeRes(800, 600, 32)
'
' Returns:1 = Resolution Successfully Ch
'     anged
0 = Resolution Was Not Changed
'
'This code is copyrighted and has' limited warranties.Please see http://w
'     ww.Planet-Source-Code.com/vb/scripts/Sho
'     wCode.asp?txtCodeId=1943&lngWId;=1'for details.'**************************************

Function ChangeRes(Width As Single, Height As Single, BPP As Integer) As Integer

On Error Goto ERROR_HANDLER Dim DevM As DEVMODE, I As Integer, ReturnVal As Boolean, _ RetValue, OldWidth As Single, OldHeight As Single, _ OldBPP As Integer Call EnumDisplaySettings(0&, -1, DevM) OldWidth = DevM.dmPelsWidth OldHeight = DevM.dmPelsHeight OldBPP = DevM.dmBitsPerPel I = 0 Do ReturnVal = EnumDisplaySettings(0&, I, DevM) I = I + 1 Loop Until (ReturnVal = False)
DevM.dmFields = DM_PELSWIDTH Or DM_PELSHEIGHT Or DM_BITSPERPEL DevM.dmPelsWidth = Width DevM.dmPelsHeight = Height DevM.dmBitsPerPel = BPP Call ChangeDisplaySettings(DevM, 1) RetValue = MsgBox("Do You Wish To Keep Your Screen Resolution To " & Width & "x" & Height & " - " & BPP & " BPP?", vbQuestion + vbOKCancel, "Change Resolution Confirm:") If RetValue = vbCancel Then DevM.dmPelsWidth = OldWidth DevM.dmPelsHeight = OldHeight DevM.dmBitsPerPel = OldBPP Call ChangeDisplaySettings(DevM, 1) MsgBox "Old Resolution(" & OldWidth & " x " & OldHeight & ", " & OldBPP & " Bit) Successfully Restored!", vbInformation + vbOKOnly, "Resolution Confirm:" ChangeRes = 0 Else ChangeRes = 1 End If
Exit Function ERROR_HANDLER: ChangeRes = 0 End Function

 
Report Bad Submission
Use this form to notify us if this entry should be deleted (i.e contains no code, is a virus, etc.).
Reason:
 
Your Vote!

What do you think of this code(in the Not Given category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor See Voting Log
 
Other User Comments
6/2/1999 4:00:00 AM:JACQPRO
This is cool!
Just think of all the 
*** you can stuff into you 
Registry!
Auwsome!
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
6/18/1999 5:05:00 AM:John Leabeater
DEVMODE is not defined in this code in 
VB6. An Error pops up.
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
6/18/1999 5:12:00 AM:John Leabeater
OK, well... it does work when the APIs 
are placed in a form rather than a 
module. However, how do you set the 
resolution to, say, 800x600 16 bit?
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
7/4/1999 7:26:00 AM:Cliff Lane
In some cases a user may have a photo 
as background with desktop icons placed 
around it.  It there a way to make sure 
the icons are returned to their 
original position when returning the 
screen to its original 
resolution?
Thanks Cliff Lane
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
8/4/1999 3:19:00 AM:Job
Call EnumDisplaySettings(0&, -1, 
DevM)
    OldWidth = 
DevM.dmPelsWidth
    OldHeight = 
DevM.dmPelsHeight
    OldBPP = 
DevM.dmBitsPerPel
This fuction call 
returns me funny value which I can't 
use it DevM.dmPelsHeight return zero to 
me and 
DevM.dmPelsHeight = 30805 
DevM.dmBitsPerPel returns 31256 ???
my 
resolution is 800x600x16 display card 
is S3 Trio64+ please advise.
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
8/10/1999 7:17:00 AM:Martijn
Hmzz... Why does the Wingdi.h field 
states:
#define DM_BITSPERPEL 
0x00040000
So in VB that value 
should be:
Private Const DM_BITSPERPEL 
= &H40000
That should do it.. i 
might be wrong, and if i am wrong 
please tell me why.
:)
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
8/10/1999 7:19:00 AM:Martijn
But hey.. see the question of 
Job!!!!!!
He says the dmBITSPERPEL 
return a strange value which is very 
likely when you refer to a strange 
address (0x60000 instead of 0x40000) 
Change your code please! 
Martijn
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
8/12/1999 7:15:00 AM:Job
I found a solution and want to share 
see ChangeRes Fix (the code is longer 
than 1000 chars this comments box is 
not allow me to past here)
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
8/23/1999 12:39:00 PM:Matt
How do I change the screen.width and 
height properties to reflect the 
resolution change? I use these to 
center object on my form, so it's 
really important that these be the 
proper values.
If these can't be 
changed, could somebody tell me how to 
calculate the new screen.height & width?
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
2/2/2002 12:22:09 AM:Tony Aquilano
i'm having a little problem.  im 
writing a game and i want to change the 
resolution if its not 1024x768.  then 
if the resolution is changed, i want to 
change it back when i exit the game.  
for some reason it won't change back.  
any ideas what i'm doing wrong?
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
10/10/2002 5:19:43 AM:
I have 300 windows 98 machines on a 
network when they are shut down 
improperly the screen res goes back 
640x480 I want them to stay at 800x600 
I have tried the code above and I get 
error Line 16 Char 1 Error expected 
statement code 800a0400 Source 
Microsoft vbscript compilation error 
Would be garteful if anyone could tell 
me what Iam doing wrong.
Thanks In 
Advace     Dave!!!!!!!!
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
Add Your Feedback!
Note:Not only will your feedback be posted, but an email will be sent to the code's author in your name.

NOTICE: The author of this code has been kind enough to share it with you.  If you have a criticism, please state it politely or it will be deleted.

For feedback not related to this particular code, please click here.
 
Name:
Comment:

 

Categories | Articles and Tutorials | Advanced Search | Recommended Reading | Upload | Newest Code | Code of the Month | Code of the Day | All Time Hall of Fame | Coding Contest | Search for a job | Post a Job | Ask a Pro Discussion Forum | Live Chat | Feedback | Customize | Visual Basic Home | Site Home | Other Sites | About the Site | Feedback | Link to the Site | Awards | Advertising | Privacy

Copyright© 1997 by Exhedra Solutions, Inc. All Rights Reserved.  By using this site you agree to its Terms and Conditions.  Planet Source Code (tm) and the phrase "Dream It. Code It" (tm) are trademarks of Exhedra Solutions, Inc.