i am nasima. I have got a code for setting the screen resolution of my page, but i am unable to understand. Can any one give a complete data explanation of the below code.
Expand|Select|Wrap|Line Numbers
- Sub ChangeRes(X As Long, Y As Long, Bits As Long)
- Dim DevM As DEVMODE, ScInfo As Long, erg As Long, an As VbMsgBoxResult
- 'Get the info into DevM
- erg = EnumDisplaySettings(0&, 0&, DevM)
- 'This is what we're going to change
- DevM.dmFields = DM_PELSWIDTH Or DM_PELSHEIGHT Or DM_BITSPERPEL
- DevM.dmPelsWidth = X 'ScreenWidth
- DevM.dmPelsHeight = Y 'ScreenHeight
- DevM.dmBitsPerPel = Bits '(can be 8, 16, 24, 32 or even 4)
- 'Now change the display and check if possible
- erg = ChangeDisplaySettings(DevM, CDS_TEST)
- 'Check if succesfull
- Select Case erg&
- Case DISP_CHANGE_RESTART
- an = MsgBox("You've to reboot", vbYesNo + vbSystemModal, "Info")
- If an = vbYes Then
- erg& = ExitWindowsEx(EWX_REBOOT, 0&)
- End If
- Case DISP_CHANGE_SUCCESSFUL
- erg = ChangeDisplaySettings(DevM, CDS_UPDATEREGISTRY)
- ScInfo = Y * 2 ^ 16 + X
- 'Notify all the windows of the screen resolution change
- SendMessage HWND_BROADCAST, WM_DISPLAYCHANGE, ByVal Bits, ByVal ScInfo
- MsgBox "Everything's ok", vbOKOnly + vbSystemModal, "It worked!"
- Case Else
- MsgBox "Mode not supported", vbOKOnly + vbSystemModal, "Error"
- End Select
- End Sub
- Private Sub Command1_Click()
- Dim sMyData As String
- Dim iReply As Integer
- Dim aXY As Variant
- aXY = Array("", "")
- sMyData = aPossible(List1.ListIndex + 1)
- iReply = MsgBox("You have chosen:" + vbCrLf + sMyData, vbCritical + vbOKCancel)
- If iReply = vbOK Then
- aXY = Split(sMyData, "x")
- aXY(0) = CInt(aXY(0))
- aXY(1) = CInt(aXY(1))
- ' ChangeRes aXY(0), aXY(1), GetDeviceCaps(nDC, BITSPIXEL)
- End If
- End Sub
- Private Sub Form_Load()
- 'KPD-Team 1999
- 'URL: http://www.allapi.net/
- 'E-Mail: KPDTeam@Allapi.net
- Dim nDC As Long
- Dim sMyString As String
- Dim bReturn As Boolean
- Dim bFound As Boolean
- Dim lX As Long
- Dim iY As Integer 'resrved for the ordinal ubound of apossible
- Dim iz As Integer
- Dim DevM As DEVMODE
- sMyString = "The current list" + vbCrLf + vbCrLf
- sMyString = sMyString + "Screen Width:" + Str(Screen.Width) + vbCrLf
- sMyString = sMyString + "Screen Height:" + Str(Screen.Height) + vbCrLf
- sMyString = sMyString + "Screen TwipsPerPixelX:" + Str(Screen.TwipsPerPixelX) + vbCrLf
- sMyString = sMyString + "Screen TwipsPerPixelY:" + Str(Screen.TwipsPerPixelY) + vbCrLf
- 'retrieve the screen's resolution
- OldX = Screen.Width / Screen.TwipsPerPixelX
- OldY = Screen.Height / Screen.TwipsPerPixelY
- sMyString = sMyString + "X resolution:" + Str(OldX) + vbCrLf
- sMyString = sMyString + "Y resolution:" + Str(OldY) + vbCrLf
- ' MsgBox sMyString
- ' Text2.Text = Trim$(Str(OldX))
- ' Text3.Text = Trim$(Str(OldY))
- ReDim aPossible(1)
- aPossible(0) = Trim$(Str$(OldX)) + " x " + Trim$(Str$(OldY))
- Text4.Text = aPossible(0)
- ' MsgBox aPossible(0)
- sMyString = ""
- lX = 0
- iY = 0
- 'Create a device context, compatible with the screen
- nDC = CreateDC("DISPLAY", vbNullString, vbNullString, ByVal 0&)
- bReturn = True
- While bReturn
- bReturn = EnumDisplaySettings(0&, lX, DevM)
- If bReturn Then 'ie. a valid entry
- ' sMyString = sMyString + Trim$(Str$(DevM.dmBitsPerPel)) + ":" + Trim$(Str$(DevM.dmPelsWidth)) + ":" + Trim$(Str$(DevM.dmPelsHeight)) + ":" + Str(lX) + vbCrLf
- sMyString = Trim$(Str$(DevM.dmPelsWidth)) + " x " + Trim$(Str$(DevM.dmPelsHeight))
- bFound = False
- For iz = 0 To iY
- If sMyString = aPossible(iz) Then
- bFound = True
- Exit For
- End If
- Next
- If Not bFound Then
- iY = iY + 1
- ReDim Preserve aPossible(iY)
- aPossible(iY) = sMyString
- End If
- lX = lX + 1 'Dont forget this
- End If
- Wend
- sMyString = ""
- For iz = 1 To iY
- List1.AddItem aPossible(iz)
- Next
- ' MsgBox sMyString
- 'Change the screen's resolution
- ' ChangeRes 640, 480, GetDeviceCaps(nDC, BITSPIXEL)
- ' Unload Me
- End Sub