Results 1 to 15 of 15

Thread: VB6: DirectX - how convert from screen to full screen and vice versa?

  1. #1

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,535

    VB6: DirectX - how convert from screen to full screen and vice versa?

    i did a property for convert from full screen to screen:
    Code:
    Public Property Get FullScreen() As Boolean
        FullScreen = blnFullScreen
    End Property
    
    Public Property Let FullScreen(full As Boolean)
        blnFullScreen = full
        If (full = True) Then
            D3DWindow.Windowed = 0
            D3DWindow.SwapEffect = D3DSWAPEFFECT_FLIP
            D3DWindow.BackBufferCount = 1 '//1 backbuffer only
            D3DWindow.BackBufferFormat = D3DFMT_X8R8G8B8 'What we specified earlier
            D3DWindow.BackBufferHeight = 480
            D3DWindow.BackBufferWidth = 640
        Else
            D3DWindow.Windowed = 1
            D3DWindow.SwapEffect = D3DSWAPEFFECT_DISCARD
        End If
    End Property
    but nothing is changed... i'm reading from a directx 8 tutorial: http://directx4vb.vbgamer.com/Direct...R_Lesson01.asp
    on "6. Extending this sample to use fullscreen mode", on bottom of the page.
    so why the full screen isn't changed?
    PS: i'm reading a directx 8 manual, but i use the Directx 9... maybe these is a problem... why!?! because the Directx 9 e-book that i have it's for C\C++
    VB6 2D Sprite control

    To live is difficult, but we do it.

  2. #2

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,535

    Re: VB6: DirectX - how convert from screen to full screen and vice versa?

    finally i get something.. the device must be destroyed and then created:
    Code:
    Public Property Let FullScreen(full As Boolean)
        blnFullScreen = full
        Set d3dev = Nothing
        If (full = True) Then
            D3DWindow.Windowed = False
            D3DWindow.SwapEffect = D3DSWAPEFFECT_COPY
            D3DWindow.BackBufferCount = 1 '//1 backbuffer only
            D3DWindow.BackBufferFormat = D3DFMT_X8R8G8B8 'What we specified earlier
            D3DWindow.BackBufferHeight = 480
            D3DWindow.BackBufferWidth = 640
            Set d3dev = d3d9.CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, D3DWindow.hDeviceWindow, D3DCREATE_SOFTWARE_VERTEXPROCESSING, D3DWindow)
        Else
            D3DWindow.Windowed = True
            D3DWindow.SwapEffect = D3DSWAPEFFECT_COPY
            D3DWindow.BackBufferHeight = 480
            D3DWindow.BackBufferWidth = 640
            Set d3dev = d3d9.CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, D3DWindow.hDeviceWindow, D3DCREATE_SOFTWARE_VERTEXPROCESSING, D3DWindow)
        End If
    End Property
    seems that i get full screen, but just for little time... then i see everything normal.. included my little form...
    what i'm doing wrong?
    VB6 2D Sprite control

    To live is difficult, but we do it.

  3. #3
    Frenzied Member
    Join Date
    Dec 2014
    Posts
    1,610

    Re: VB6: DirectX - how convert from screen to full screen and vice versa?

    I have no idea with DirectX
    for Direct2D Im using the ChangeDisplaySettings API to get the resolution I want and I just make fullscreen the form. while doing that I also need to re-load the assets as they get lost while changing resolution.
    but I think DirectX has its own fullscreen mode.
    Im sure the Trick will know what to do.

  4. #4

  5. #5

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,535

    Re: VB6: DirectX - how convert from screen to full screen and vice versa?

    Code:
    Public Property Let FullScreen(full As Boolean)
        blnFullScreen = full
        'Set d3dev = Nothing
        If (full = True) Then
            D3DWindow.Windowed = False
            D3DWindow.SwapEffect = D3DSWAPEFFECT_COPY
            D3DWindow.BackBufferCount = 1 '//1 backbuffer only
            D3DWindow.BackBufferFormat = DispMode.Format 'What we specified earlier
            D3DWindow.BackBufferHeight = DispMode.Height
            D3DWindow.BackBufferWidth = DispMode.Width
            'Set d3dev = d3d9.CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, D3DWindow.hDeviceWindow, D3DCREATE_SOFTWARE_VERTEXPROCESSING, D3DWindow)
        Else
            D3DWindow.Windowed = True
            D3DWindow.SwapEffect = D3DSWAPEFFECT_COPY
            D3DWindow.BackBufferHeight = DispMode.Height
            D3DWindow.BackBufferWidth = DispMode.Width
            'Set d3dev = d3d9.CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, D3DWindow.hDeviceWindow, D3DCREATE_SOFTWARE_VERTEXPROCESSING, D3DWindow)
        End If
        d3dev.Reset D3DWindow
    End Property
    i continue with bug... i don't see fullscreen...
    i must see an entire black screen with background color by resolution size?
    VB6 2D Sprite control

    To live is difficult, but we do it.

  6. #6

  7. #7

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,535

    Re: VB6: DirectX - how convert from screen to full screen and vice versa?

    class:
    Code:
    Option Explicit
    Private Type RECT
            Left As Long
            Top As Long
            Right As Long
            Bottom As Long
    End Type
    Private Declare Function AdjustWindowRect Lib "user32" (lpRect As RECT, ByVal dwStyle As Long, ByVal bMenu As Long) As Long
    
    Private Const WS_OVERLAPPED = &H0&
    Private Const WS_CAPTION = &HC00000                  '  WS_BORDER Or WS_DLGFRAME
    Private Const WS_BORDER = &H800000
    Private Const WS_DLGFRAME = &H400000
    Private Const WS_SYSMENU = &H80000
    Private Const WS_THICKFRAME = &H40000
    Private Const WS_MINIMIZE = &H20000000
    Private Const WS_MINIMIZEBOX = &H20000
    Private Const WS_MAXIMIZEBOX = &H10000
    Private Const WS_OVERLAPPEDWINDOW = (WS_OVERLAPPED Or WS_CAPTION Or WS_SYSMENU Or WS_THICKFRAME Or WS_MINIMIZEBOX Or WS_MAXIMIZEBOX)
    Private Declare Function UpdateWindow Lib "user32" (ByVal hwnd As Long) As Long
    
    
    Dim d3d9        As IDirect3D9  ' // Direct3D9 object
    
    Dim d3dev       As IDirect3DDevice9 ' // Direct3D device
    Dim D3DWindow As D3DPRESENT_PARAMETERS '//Direct view
    Dim DispMode As D3DDISPLAYMODE '//Describes our Display Mode
    Public blnObjectsDestroyed As Boolean
    '// Estes não são realmente necessários - eles apenas nos mostrarão qual é a taxa de quadros ...
    Private Declare Function GetTickCount Lib "kernel32" () As Long ' // Isso é usado para obter a taxa de quadros.
    Dim LastTimeCheckFPS As Long '// Quando foi a última vez que verificamos a taxa de quadros?
    Public FramesDrawn As Long '// Quantos quadros foram desenhados
    Dim FrameRate As Long ' // Qual é a taxa de quadros atual ...
    Dim blnFullScreen As Boolean
    Public Event Render()
    
    Public Sub Init(Hwndwindow As Long)
        If (blnObjectsDestroyed = False) Then Destroy
       
        Set d3d9 = Direct3DCreate9()
        d3d9.GetAdapterDisplayMode D3DADAPTER_DEFAULT, DispMode '//Retrieve the current display Mode
        D3DWindow.BackBufferCount = 1
        D3DWindow.Windowed = 1 'in these sample is for a window standard size
        D3DWindow.BackBufferFormat = DispMode.Format
        D3DWindow.SwapEffect = D3DSWAPEFFECT_DISCARD
        D3DWindow.EnableAutoDepthStencil = 1
        D3DWindow.AutoDepthStencilFormat = D3DFMT_D16
        D3DWindow.hDeviceWindow = Hwndwindow
        D3DWindow.BackBufferHeight = 0
        D3DWindow.BackBufferWidth = 0
        Set d3dev = d3d9.CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, Hwndwindow, D3DCREATE_SOFTWARE_VERTEXPROCESSING, D3DWindow)
        blnObjectsDestroyed = False
    End Sub
    
    Public Function BGR(Blue As Integer, Green As Integer, Red As Integer) As Long
        BGR = RGB(Blue, Green, Red)
    End Function
    
    Public Sub Draw(BackColor As Long)
        'clear and draw a color using the RGB()...
        'in these case we don't need the alpha value...
        If (blnObjectsDestroyed = True) Then Exit Sub
        d3dev.Clear 0, ByVal 0, D3DCLEAR_TARGET, BackColor, 1#, 0
        
        
        d3dev.BeginScene
    
            'All rendering calls go between these two lines
            'RaiseEvent Render
            DoEvents
            
            'calculate the frame per second:
            If GetTickCount - LastTimeCheckFPS >= 1000 Then
                LastTimeCheckFPS = GetTickCount
                FrameRate = FramesDrawn
                FramesDrawn = 0
            End If
            FramesDrawn = FramesDrawn + 1
    
        d3dev.EndScene
        
        'Now we must show what we did:
        d3dev.Present ByVal 0, ByVal 0, 0, ByVal 0
    
    End Sub
     
    Public Property Get FullScreen() As Boolean
        FullScreen = blnFullScreen
    End Property
    
    Public Property Let FullScreen(full As Boolean)
        Dim WindowRect As RECT
        blnFullScreen = full
        'Set d3dev = Nothing
        On Error Resume Next
        WindowRect.Left = 0
        WindowRect.Top = 0
        If (full = True) Then
            
            
            D3DWindow.Windowed = False
            D3DWindow.SwapEffect = D3DSWAPEFFECT_DISCARD
            D3DWindow.BackBufferCount = 1 '//1 backbuffer only
            D3DWindow.BackBufferFormat = DispMode.Format 'What we specified earlier
            D3DWindow.EnableAutoDepthStencil = True
            D3DWindow.AutoDepthStencilFormat = D3DFMT_D16
            D3DWindow.BackBufferWidth = 1336
            D3DWindow.BackBufferHeight = 768
        Else
            D3DWindow.BackBufferWidth = 0
            D3DWindow.BackBufferHeight = 0
            D3DWindow.Windowed = True
            D3DWindow.SwapEffect = D3DSWAPEFFECT_DISCARD
        End If
        
        Set d3dev = d3d9.CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, D3DWindow.hDeviceWindow, D3DCREATE_SOFTWARE_VERTEXPROCESSING, D3DWindow)
        UpdateWindow D3DWindow.hDeviceWindow
        d3dev.Reset D3DWindow
    End Property
    
    
    
    Public Sub Destroy()
        'Clean Directx 9...
        'yes the directx class's must be setted for destroy their objects:
        If (blnObjectsDestroyed = False) Then
            Set d3dev = Nothing
            Set d3d9 = Nothing
            blnObjectsDestroyed = True
        End If
    End Sub
    
    Public Function EnumerateAdapters() As String()
        
        Dim i As Integer, sTemp As String, J As Integer
        Dim nAdapters As Long
        Dim AdapterInfo As D3DADAPTER_IDENTIFIER9
        '//This'll either be 1 or 2
        nAdapters = d3d9.GetAdapterCount
        Dim strAdpatersList() As String
        ReDim strAdpatersList(nAdapters)
        
        For i = 0 To nAdapters - 1
            'Get the relevent Details
           ' d3d9.GetAdapterIdentifier i, 0, AdapterInfo
            
            'Get the name of the current adapter - it's stored as a long
            'list of character codes that we need to parse into a string
            ' - Dont ask me why they did it like this; seems silly really :)
            sTemp = "" 'Reset the string ready for our use
            For J = 0 To 511
                sTemp = sTemp & Chr$(AdapterInfo.Description(J))
                
            Next J
            sTemp = Replace(sTemp, Chr$(0), " ")
            strAdpatersList(i) = sTemp
            
        Next i
        EnumerateAdapters = strAdpatersList
    End Function
    form with just 2 buttons and a listbox(with automatic names):
    Code:
    Option Explicit
    
    Dim s As Class1
    Dim blnRuning As Boolean
    Dim blnPause As Boolean
    
    
    Private Sub Command1_Click()
        Dim l() As String
        l = s.EnumerateAdapters()
        Dim i As Integer
        For i = 0 To UBound(l) - 1
            List1.AddItem (l(i))
        Next i
        
        blnRuning = Not blnRuning
        GameLoop
        
        
    End Sub
    
    Private Sub Command2_Click()
        On Error Resume Next
        blnRuning = False
        s.FullScreen = Not s.FullScreen
        blnRuning = True
        GameLoop
    End Sub
    
    Private Sub Form_Load()
        Set s = New Class1
        s.Init Me.hwnd
    End Sub
    
    Sub GameLoop()
        blnPause = False
        Do While blnRuning
            
            If blnPause = False Then
                Me.Caption = CStr(s.FramesDrawn)
                s.Draw s.BGR(0, 0, 255)
            End If
            DoEvents
        Loop
    End Sub
    
    Private Sub Form_LostFocus()
        MsgBox "good bye focus"
    End Sub
    
    Private Sub Form_Unload(Cancel As Integer)
        blnRuning = Not blnRuning
        s.Destroy
        'MsgBox "good bye"
        'End
    End Sub
    sometimes the resolution is changed.. but the window seems with same size and i continue seen the desktop
    VB6 2D Sprite control

    To live is difficult, but we do it.

  8. #8

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,535

    Re: VB6: DirectX - how convert from screen to full screen and vice versa?

    The trick: did i miss something?
    VB6 2D Sprite control

    To live is difficult, but we do it.

  9. #9

  10. #10

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,535

    Re: VB6: DirectX - how convert from screen to full screen and vice versa?

    "Why do you re-create the device?"
    i'm learn it....
    "Does the driver supports the resolution you specified?"
    i belive yes...
    but maybe you have right: the device re-creation
    VB6 2D Sprite control

    To live is difficult, but we do it.

  11. #11

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,535

    Re: VB6: DirectX - how convert from screen to full screen and vice versa?

    now works more or less:
    Code:
    Public Property Get FullScreen() As Boolean
        FullScreen = blnFullScreen
    End Property
    
    Public Property Let FullScreen(full As Boolean)
        blnFullScreen = full
        'Set d3dev = Nothing
        If (full = True) Then
            D3DWindow.Windowed = False
            D3DWindow.SwapEffect = D3DSWAPEFFECT_COPY
            D3DWindow.BackBufferCount = 1 '//1 backbuffer only
            D3DWindow.BackBufferFormat = DispMode.Format 'What we specified earlier
            D3DWindow.BackBufferHeight = 768
            D3DWindow.BackBufferWidth = 1024
           
        Else
            D3DWindow.Windowed = True
            D3DWindow.SwapEffect = D3DSWAPEFFECT_COPY
            D3DWindow.BackBufferHeight = 0
            D3DWindow.BackBufferWidth = 0
         
        End If
        d3dev.Reset D3DWindow
    End Property
    i have seen 2 things:
    1 - fullscreen: the resolution is the same of screen size? or i can use a device size and position?
    2 - when i go back to window, why i don't get the previous size and the caption bar? and more bugs
    VB6 2D Sprite control

    To live is difficult, but we do it.

  12. #12

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,535

    Re: VB6: DirectX - how convert from screen to full screen and vice versa?

    finally it's working like i need:
    Code:
    'on class:
    Public Property Get FullScreen() As Boolean
        FullScreen = blnFullScreen
    End Property
    
    Public Property Let FullScreen(full As Boolean)
        blnFullScreen = full
        If (full = True) Then
            D3DWindow.Windowed = False
            D3DWindow.SwapEffect = D3DSWAPEFFECT_COPY
            D3DWindow.BackBufferCount = 1 '//1 backbuffer only
            D3DWindow.BackBufferFormat = DispMode.Format 'What we specified earlier
            D3DWindow.BackBufferHeight = 768
            D3DWindow.BackBufferWidth = 1024
        Else
            D3DWindow.Windowed = True
            D3DWindow.SwapEffect = D3DSWAPEFFECT_COPY
            D3DWindow.BackBufferCount = 1 '//1 backbuffer only
            D3DWindow.BackBufferFormat = DispMode.Format 'What we specified earlier
            D3DWindow.BackBufferHeight = 0
            D3DWindow.BackBufferWidth = 0
        End If
        d3dev.Reset D3DWindow
    End Property
    on form, button:
    Code:
    Private Sub Command2_Click()
        On Error Resume Next
        blnRuning = False
        s.FullScreen = Not s.FullScreen
        blnRuning = True
        
        'i add the border and the initial size:
        Me.BorderStyle = vbSizable
        Me.Width = 4800
        Me.Height = 3600
        
        GameLoop
    End Sub
    but i need ask about 1 'bug': why the Opera browser window size is changed and don't continues maximized?(these is what i'm seen.. i don't know about others programs)
    the
    Code:
     d3dev.Clear 0, ByVal 0, D3DCLEAR_TARGET, BackColor, 1#, 0
    can change only a rectangle size and position space?(instead 'byval 0')
    VB6 2D Sprite control

    To live is difficult, but we do it.

  13. #13

  14. #14

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,535

    Re: VB6: DirectX - how convert from screen to full screen and vice versa?

    thank you so much for all
    VB6 2D Sprite control

    To live is difficult, but we do it.

  15. #15
    Frenzied Member
    Join Date
    Jan 2020
    Posts
    1,635

    Re: VB6: DirectX - how convert from screen to full screen and vice versa?

    how to ScreenCaputre by DirectX with vb6?-VBForums
    https://www.vbforums.com/showthread....42#post5515442

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width