[C++] Flash & DirectX

Pagina: 1
Acties:

Onderwerpen


Acties:
  • 0 Henk 'm!

  • beany
  • Registratie: Juni 2001
  • Laatst online: 20-09 16:08

beany

Meeheheheheh

Topicstarter
Ik ben bezig om in mijn 3D app Flash te integreren. Dit houd in dat ik een flash window op een texture render en vervolgens render ik de texture op 2 triangles(vierkant).

Opzich werkt het:

Afbeeldingslocatie: http://www.xs4all.nl/~slurcko/d3dflash.png

Okay, de flash wordt op zijn kop getoond, geen idee waar dit in zit maar in mijn app zelf wordt het wel goed getoond. Het plaatje toont een test versie die ik snel in elkaar geknutseld heb om mijn probleem op te lossen. Een pruts projectje dus, getuige de kwaliteit van de code :P Input werkt overigens niet, geen muis & geen keyboard. inmiddels wel

Het probleem:

Als de window de focus heeft, is de tekst-cursur niet zichtbaar. Als de window niet de focus heeft(start programma, klik op de taskbar om de focus van de window af te halen) zie je ineens een cursor knipperen in de TextBox :?

Ik snap werkelijk niet waar dit in zit. Dit is de eerste keer dat ik met ole-achtige dingen aan de slag ga in C++ dus misschien zie ik wat over het hoofd. Ik heb op google gezocht maar ik kan daar weinig vinden over Focus en windowless componenten.

De code, inclusief een executable, is hier te vinden: http://www.xs4all.nl/~slurcko/d3d_flash.rar
Het project is quick & dirty in elkaar gezet specifiek voor dit probleem. Op regel 221 moet je misschien het pad naar flash.ocx aanpassen om het werkend te krijgen.

De belangrijkste stukjes code zijn volgens mij waar het flash component gecreeerd wordt:

code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
void initFlash()
{
    site = new FlashSite();
    
    HMODULE flashLib = LoadLibrary( "c:\\b3d\\Flash.ocx" );

    if(flashLib)
    {
        IClassFactory* factory = 0;
        GetClassObject getClassFunc = (GetClassObject)GetProcAddress(flashLib, "DllGetClassObject");
        HRESULT result = getClassFunc(ShockwaveFlashObjects::CLSID_ShockwaveFlash, IID_IClassFactory, (void**)&factory);
        if(SUCCEEDED(result))
        {
            factory->CreateInstance(NULL, IID_IOleObject, (void**)&oleObject);
            factory->Release(); 
        }
    }

    IOleClientSite* clientSite = 0;
    site->QueryInterface(__uuidof(IOleClientSite), (void**)&clientSite);
    oleObject->SetClientSite(clientSite);
    clientSite->Release();

    IOleInPlaceObject* inPlaceObject = 0;   
    oleObject->QueryInterface(__uuidof(IOleInPlaceObject), (LPVOID*)&inPlaceObject);            

    if(inPlaceObject)
    {
        RECT dirty;
        dirty.left = 0;
        dirty.top = 0;
        dirty.right = flashWidth;
        dirty.bottom = flashHeight;
        inPlaceObject->SetObjectRects(&dirty, &dirty);
        inPlaceObject->Release();
    }

    oleObject->QueryInterface(__uuidof(ShockwaveFlashObjects::IShockwaveFlash), (LPVOID*)&flashInterface);
    
    flashInterface->PutWMode("opaque");

    //I have no idea what this does, but if left out it doesnt work
    oleObject->DoVerb(OLEIVERB_INPLACEACTIVATE, 0, clientSite, 0, 0, 0);


En waar de flash surface gecopieerd wordt naar een D3D texture:

code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
void UpdateFlash()
{
    int dirtyBufSize = flashWidth * flashHeight * 4;

    IViewObject* curView = 0;
    flashInterface->QueryInterface(IID_IViewObject, (void**)&curView);

    if( mainContext )
    {
        DeleteDC( mainContext );
        mainContext = 0;
    }
    if( mainBitmap )
    {
        DeleteObject( mainBitmap );
        mainBitmap = 0;
    }

    HDC hdc = GetDC(0);
    BITMAPINFOHEADER bih = {0};
    bih.biSize = sizeof(BITMAPINFOHEADER);
    bih.biBitCount = 32;
    bih.biCompression = BI_RGB;
    bih.biPlanes = 1;
    bih.biWidth = flashWidth;
    bih.biHeight = flashHeight;
    mainContext = CreateCompatibleDC(hdc);
    mainBitmap = CreateDIBSection(hdc, (BITMAPINFO*)&bih, DIB_RGB_COLORS, (void**)&mainBuffer, 0, 0);
    SelectObject(mainContext, mainBitmap);

    ReleaseDC(0, hdc);

    memset(mainBuffer, 0, dirtyBufSize);
    
    RECT local;
    local.left = 0;
    local.top = 0;
    local.right = flashWidth;
    local.bottom = flashHeight;
    HRESULT hr = OleDraw(curView,DVASPECT_TRANSPARENT, mainContext, &local);

    RECT dirty;
    dirty.left = 0;
    dirty.top = 0;
    dirty.right = flashWidth;
    dirty.bottom = flashHeight;

    copyArea(dirty, mainBuffer, flashWidth * 4);

    D3DLOCKED_RECT lockedRect;
    hr = _flashTexture->LockRect(0, &lockedRect, NULL, D3DLOCK_DISCARD );

    unsigned char* destBuffer = static_cast<unsigned char*>( lockedRect.pBits );
    blitBGR( destBuffer, lockedRect.Pitch, 4 );
    
    hr = _flashTexture->UnlockRect( 0 );
}


Het is nogal frustrerend omdat het verder namelijk heel erg goed werkt. Ik heb geprobeerd messages te sturen naar het flashcontrol(WM_FOCUS) e.d. maar ook dat haalt niks uit. Het meest rare is toch wel dat de cursur wel vrolijk staat te knipperen als de window geen focus heeft.

Wie o wie heeft suggesties voor het oplossen van dit suffe probleem? :)

edit: de SWF file is met Flex gemaakt. Maar dit probleem doet zich ook voor met SWF files die in Flash zijn gemaakt.

Dagelijkse stats bronnen: https://x.com/GeneralStaffUA en https://www.facebook.com/GeneralStaff.ua


Acties:
  • 0 Henk 'm!

  • alienfruit
  • Registratie: Maart 2003
  • Nu online

alienfruit

the alien you never expected

Nou dan toon je het toch op zijn kop zodat het weer correct is :D ?

Acties:
  • 0 Henk 'm!

  • Patriot
  • Registratie: December 2004
  • Laatst online: 16-09 13:49

Patriot

Fulltime #whatpulsert

alienfruit schreef op vrijdag 12 september 2008 @ 15:34:
Nou dan toon je het toch op zijn kop zodat het weer correct is :D ?
Lezen is ook een kunst, hij zegt dat dat niet zozeer het probleem is.

Acties:
  • 0 Henk 'm!

  • beany
  • Registratie: Juni 2001
  • Laatst online: 20-09 16:08

beany

Meeheheheheh

Topicstarter
Okay, hij staat niet meer op zijn kop nu! Plus ik stuur domweg alle windows messages naar de flash control toe waardoor keyboard en muis ook werken.

Stomme is, als ik WM_KILLFOCUS doorlaat verschijnt de cursor nooit. Ook niet als de window de focus verliest. Filter ik die eruit dan is de cursor er wel als de window niet de focus heeft.

Dagelijkse stats bronnen: https://x.com/GeneralStaffUA en https://www.facebook.com/GeneralStaff.ua


Acties:
  • 0 Henk 'm!

  • beany
  • Registratie: Juni 2001
  • Laatst online: 20-09 16:08

beany

Meeheheheheh

Topicstarter
Hmm, subtiel schopje :P

Dagelijkse stats bronnen: https://x.com/GeneralStaffUA en https://www.facebook.com/GeneralStaff.ua