Results 1 to 6 of 6

Thread: [VB6, twinBASIC] DirectComposition Effects Demo

Hybrid View

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Jul 2010
    Location
    NYC
    Posts
    6,336

    Cool [VB6, twinBASIC] DirectComposition Effects Demo


    DirectComposition Effects Demo


    This demo is a just a basic proof of concept, a close-as-possible port of the Microsoft DirectComposition Effects SDK example. Since the demo is ported as close as possible, you'll find something additional of interest in this project: Instead of using a Form, it creates it's own window from scratch using API and handles the entire message pump (error handlers omitted):

    Code:
    Private Function CreateApplicationWindow() As Long
    
            Dim hr As Long = S_OK
        
            Dim wcex As WNDCLASSEX
        
            wcex.cbSize = LenB(wcex)
            wcex.style = CS_HREDRAW Or CS_VREDRAW
            wcex.lpfnWndProc = AddressOf WindowProc
            wcex.cbClsExtra = 0
            wcex.cbWndExtra = 0
            wcex.hInstance = App.hInstance
            wcex.hIcon = 0
            wcex.hCursor = LoadCursor(0, IDC_ARROW)
            wcex.hbrBackground = GetStockObject(WHITE_BRUSH)
            wcex.lpszMenuName = 0
            wcex.lpszClassName = StrPtr(wndClass)
            wcex.hIconSm = 0
        
            hr = IIf(RegisterClassEx(wcex), S_OK, E_FAIL)
    
            If SUCCEEDED(hr) Then
                PostLog "RegisterClassEx succeeded"
                Dim RECT As RECT
                RECT.Right = windowWidth: RECT.Bottom = windowHeight
                AdjustWindowRect RECT, WS_OVERLAPPED Or WS_CAPTION Or WS_SYSMENU Or WS_MINIMIZEBOX, 0
            
                m_hWnd = CreateWindowExW(0, StrPtr(wndClass), StrPtr(wndName), _
                                    WS_OVERLAPPED Or WS_CAPTION Or WS_SYSMENU Or WS_MINIMIZEBOX, _
                                    CW_USEDEFAULT, CW_USEDEFAULT, RECT.Right - RECT.Left, RECT.Bottom - RECT.Top, _
                                    0, 0, App.hInstance, ByVal 0)
            End If
    Code:
        Private Function EnterMessageLoop() As Long
            Dim result As Long
        
            If ShowApplicationWindow() Then
                Dim tMSG As MSG
                Dim hr As Long
                PostLog "Entering message loop"
                hr = GetMessage(tMSG, 0, 0, 0)
                Do While hr <> 0
                    If hr = -1 Then
                        PostLog "Error: 0x" & Hex$(Err.LastDllError)
                    Else
                        TranslateMessage tMSG
                        DispatchMessage tMSG
                    End If
                    hr = GetMessage(tMSG, 0, 0, 0)
                Loop
                PostLog "Exited message loop"
                result = CLng(tMSG.wParam)
            End If
            
            EnterMessageLoop = result
        End Function
    After that, we get into all the DirectComposition/Direct2D code, which is too complex to go into much detail here; but the basic steps are to start with the D3D11CreateDevice and D2D1CreateFactory APIs to create the root DirectX objects, get a DXGI interface from the former, then use the DCompositionCreateDevice to create the rendering object. After that, we create surfaces, make those into DirectComposition visuals, and apply various transform effects and animations.

    I recommend following the code starting from BeforeEnteringMessageLoop to see all the object creation, then following from OnKeyDown and OnLeftButton to see how it responds to the two actions.

    There's two versions of this project included in the zip:

    VB6:
    Module that runs from Sub Main
    Requires oleexp.tlb v6.3 or newer (only for the IDE, not required once compiled to exe)
    (Note: If you saw my thread about this, I mapped the differences in matrix layout so it could use the existing oleexp version.)

    twinBASIC:
    Runs from Form provisioned for multiple demos in it's own thread with log sync'd in critical section. Can also be configured to run from Sub Main without the form by changing the startup object.
    Supports both 32bit and 64bit
    Uses tbShellLib, which is included within the project file but will have to be added if you make a new project using this code or these interfaces.
    You'll see the module code is nearly identical, except where I took advantage of some modern twinBASIC language additions like inline initialization of variables and Err.LastHResult, and that the VB6 version has it's APIs declared in the module since oleexp.tlb doesn't include them like tbShellLib does.

    Required for both:
    DirectX 11, which is preinstalled on Windows 7 and newer.

    Download from GitHub.

    The latest update compresses to 1.51MB, which is over the VBForums limit. Click the green 'Code' button on GitHub, then 'Download ZIP'.

    (Note: The large size is the oleexp-sized WinDevLib package being included in the .twinproj)
    Last edited by fafalone; Feb 17th, 2024 at 11:59 AM.

  2. #2
    Fanatic Member
    Join Date
    Jun 2016
    Location
    España
    Posts
    546

    Re: [VB6, twinBASIC] DirectComposition Effects Demo

    good job fafalone

  3. #3
    Fanatic Member
    Join Date
    Jul 2017
    Posts
    580

    Re: [VB6, twinBASIC] DirectComposition Effects Demo

    How could I escape your wonderful codes for so long...?

  4. #4
    PowerPoster
    Join Date
    Jan 2020
    Posts
    4,465

    Re: [VB6, twinBASIC] DirectComposition Effects Demo

    that's good,do you have a sample for?VB6 code like EXCEL recording macro.?
    it's can use on twinbasic add-in or ERP SOFTWARE

  5. #5

    Thread Starter
    PowerPoster
    Join Date
    Jul 2010
    Location
    NYC
    Posts
    6,336

    Re: [VB6, twinBASIC] DirectComposition Effects Demo

    I already posted a VB6 version as well you could trivially convert to 32bit Excel, but for 64bit you'd need to make your own type library because there's no 64bit oleexp and tB doesn't support exporting WDL yet. I don't know why you'd want to put 3d accelerated graphics in an addin... you could, but I'm not spending time on it.

  6. #6
    PowerPoster yereverluvinuncleber's Avatar
    Join Date
    Feb 2014
    Location
    Norfolk UK (inbred)
    Posts
    2,615

    Re: [VB6, twinBASIC] DirectComposition Effects Demo

    Very good.
    https://github.com/yereverluvinunclebert

    Skillset: VMS,DOS,Windows Sysadmin from 1985, fault-tolerance, VaxCluster, Alpha,Sparc. DCL,QB,VBDOS- VB6,.NET, PHP,NODE.JS, Graphic Design, Project Manager, CMS, Quad Electronics. classic cars & m'bikes. Artist in water & oils. Historian.

    By the power invested in me, all the threads I start are battle free zones - no arguing about the benefits of VB6 over .NET here please. Happiness must reign.

Tags for this Thread

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