Direct3D and MFC/CView HWnd

This is a discussion on Direct3D and MFC/CView HWnd within the Windows Programming forums, part of the Platform Specific Boards category; Hey, I've got an SDI MFC application that initialises a Direct3D Device inside one of the View Classes. CApp >> ...

  1. #1
    Registered User
    Join Date
    Sep 2006
    Location
    UK
    Posts
    13

    Question Direct3D and MFC/CView HWnd

    Hey,

    I've got an SDI MFC application that initialises a Direct3D Device inside one of the View Classes.
    CApp >> CMainFrame >> CView >> DirectX

    I'm also using the basic View switching model(no splitter Wnd) taken straight from Microsofts' sample program - 'swsplit', it basically copies a few pointers, deletes the existing View and then creates a new one.

    The Problem:

    If i use the main windows HWND :
    Code:
    InitD3D( AfxGetApp()->m_pMainWnd->GetSafeHwnd() );
    It works correctly all the time but the D3D device floats on top of the toolbars and statusbar, i guess because it's attached to the main window not the child window.

    however, if i do it the way i want and use the CViews HWnd :
    Code:
    InitD3D( GetSafeHwnd() );
    It will only work when the view class is created by the MFC framework at startup, as soon as i switch the view class and then switch back Direct3D fails to start and gives the error: 'Internal Driver Error'

    Any ideas

    Thanks in advance

  2. #2
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,856
    I don't do alot of DirectX but I use MFC so just tossing in some ideas....

    Can you get any error info when it goes wrong? (GetLastError() for DirectX?)

    Add some error checking for invalid handles.

    I perfer to log my errors to file but would this work?

    Code:
    InitD3D( ASSERT(GetSafeHwnd()) );
    MFC starts up in stages. I find I have to monitor the OnSize() type msgs as a window changes size as it starts (and recreate HDCs as it does). Could you be creating small (as the window starts small and grows a number of times) and drawing to it larger later (when it gets to full screen)?

    Do you need to over-ride the OnIdle() (and OnPaint()) to PeekMessage() for directX msgs?

    Have you tried using the DirectX window (created from the main wnd) and 'pasting' it to the views client area?
    I mean create the directx the same size as the main view. If the view moves or changes size you move or re-size the directx window.

    (sometimes with MFC, as in life, the path of least resistance is to let it do it how it wants and to work with it, not change it )
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  3. #3
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,590
    You must init your D3D renderer in CView::OnOnInitialUpdate(). Then you must add code to call the render function repeatedly from CWinApp::OnIdle() or have that function call an Update() function in your renderer class.

    Pass your renderer the HWND of your CView derived view class and it will act just like a CView. If you don't like that then create a generic CWnd class and make it a member of your CView derived class. When the window is created, it will call your CWnd object and also will also call your OnPaint().

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21