hey people, does anyone of you have a code snippet or source code on how to fill the DEVMODE structure and to change the screen resolution to 800x600 or 1024x768... I searched the board and several webpages aleady but i couldn't find any usefull code for me, I don't have problems with using the ChangeDisplaySettings API, but i don't know to 100% how to fill the DEVMODE structure in MASM. Thanks in advance, Olli
Posted on 2001-04-21 23:55:00 by Typhoon
High, I use this to switch the color modus, but I think you can modify it to switch the screen resolution. align 4 ; - DEVMODE Structure ( API=EnumDisplaySettings / ChangeDisplaySettings ) - dmDeviceName db 32 dup (?) dmSpecVersion dw ? dmDriverVersion dw ? dmSize dw ? dmDriverExtra dw ? dmFields dd ? dmOrientation dw ? dmPaperSize dw ? dmPaperLength dw ? dmPaperWidth dw ? dmScale dw ? dmCopies dw ? dmDefaultSource dw ? dmPrintQuality dw ? dmColor dw ? dmDuplex dw ? dmYResolution dw ? dmTTOption dw ? dmCollate dw ? dmFormName db 32 dup (?) dmLogPixels dw ? dmBitsPerPel dd ? dmPelsWidth dd ? dmPelsHeight dd ? dmDisplayFlags dd ? dmDisplayFrequency dd ? dmICMMethod dd ? ;Windows 95 only dmICMIntent dd ? ;Windows 95 only dmMediaType dd ? ;Windows 95 only dmDitherType dd ? ;Windows 95 only dmReserved1 dd ? ;Windows 95 only dmReserved2 dd ? ;Windows 95 only ;------------------------------------------------------------------------------ ; API "GetDC" retrieves a handle of a display device context (DC) for the ; client area of the specified window. ;------------------------------------------------------------------------------ push WP1_hWnd ;hwnd, handle of window call GetDC ;- API Function - mov handleDC,eax ;handle of DC ;------------------------------------------------------------------------------ ; API "GetDeviceCaps" retrieves device-specific infos about a specified device. ;------------------------------------------------------------------------------ push 12 ;nIndex, index to query, BITSPIXEL push handleDC ;hdc, device-context handle call GetDeviceCaps ;- API Function - mov ScreenBpp,eax ; ;------------------------------------------------------------------------------ ; API "ReleaseDC" releases a device context (DC), freeing it for use by other. ;------------------------------------------------------------------------------ push handleDC ;hdc, handle of device context push WP1_hWnd ;hwnd, handle of window call ReleaseDC ;- API Function - RGB: cmp ScreenBpp,24 ; jae ReadyOnCreate ;if display >=24 bit skip EnumDisplay ;------------------------------------------------------------------------------ ; API "GetSystemMetrics" retrieves system metrics and system config. settings. ;------------------------------------------------------------------------------ push 0h ;nIndex, parameter to retrieve, SM_CXSCREEN call GetSystemMetrics ;- API Function - mov ScreenWidth,eax ;store result push 1h ;nIndex, parameter to retrieve, SM_CYSCREEN call GetSystemMetrics ;- API Function - mov ScreenHeight,eax ;store result EnumDisplay: ;------------------------------------------------------------------------------ ; API "EnumDisplaySettingsA" obtains information about one of a display ; device's graphics modes. ;------------------------------------------------------------------------------ push OFFSET dmDeviceName ;lpDevMode, structure to receive settings push ModeNum ;iModeNum, specifies the graphics mode push 0h ;lpszDeviceName, specifies display device call EnumDisplaySettingsA ;- API Function - cmp eax,0h ;compare, error or max entry je ErrorOnCreate
Posted on 2001-04-22 03:53:00 by Test Department
tanks, but i got it figured out about an hour ago... i just tried until it worked, it's only made for my computer so i use the sizes and hertz that already work on mine: here's the code

.data
ChangeDisplay DEVMODE <>

.const
DM_BITSPERPEL                        equ 40000h
DM_PELSWIDTH                         equ 80000h
DM_PELSHEIGHT                        equ 100000h
DM_DISPLAYFLAGS                      equ 200000h
DM_DISPLAYFREQUENCY                  equ 400000h

.code
.IF eax==0
            mov ChangeDisplay.dmFields,DM_BITSPERPEL or DM_PELSWIDTH or DM_PELSHEIGHT or DM_DISPLAYFLAGS or DM_DISPLAYFREQUENCY
            mov ChangeDisplay.dmBitsPerPel,32
            mov ChangeDisplay.dmPelsWidth,1024
            mov ChangeDisplay.dmPelsHeight,768
            mov ChangeDisplay.dmDisplayFlags,0
            mov ChangeDisplay.dmDisplayFrequency,60
            mov ChangeDisplay.dmSize,sizeof ChangeDisplay
            invoke ChangeDisplaySettings,addr ChangeDisplay,0
            invoke EndDialog,hWin,NULL
           .ELSE
            mov ChangeDisplay.dmFields,DM_BITSPERPEL or DM_PELSWIDTH or DM_PELSHEIGHT or DM_DISPLAYFLAGS or DM_DISPLAYFREQUENCY
            mov ChangeDisplay.dmBitsPerPel,32
            mov ChangeDisplay.dmPelsWidth,800
            mov ChangeDisplay.dmPelsHeight,600
            mov ChangeDisplay.dmDisplayFlags,0
            mov ChangeDisplay.dmDisplayFrequency,84
            mov ChangeDisplay.dmSize,sizeof ChangeDisplay
            invoke ChangeDisplaySettings,addr ChangeDisplay,0
            invoke EndDialog,hWin,NULL
           .ENDIF
it works fine for me cya
Posted on 2001-04-22 04:54:00 by Typhoon