Exemple #1
0
HRESULT WINAPI
DirectDrawCreate
(GUID *lpGUID, LPDIRECTDRAW *lplpDD, IUnknown *pUnkOuter)
{
	HRESULT rc = E_OUTOFMEMORY;
	WIN32API_ENTER("HRESULT", "DirectDrawCreate", "GUID *", lpGUID, "LPDIRECTDRAW *", lplpDD, "IUnknown *", pUnkOuter, NULL);
	if (NULL != lpGUID) WIN32API_GUID("guid", lpGUID);
	IDirectDraw *ddraw = new DirectDraw();
	if (NULL == ddraw) {
		*lplpDD = NULL;
	} else {
		rc = ddraw->Initialize(lpGUID);
		if (SUCCEEDED(rc)) {
			ddraw->AddRef();
			*lplpDD = (LPDIRECTDRAW)ddraw;
		} else {
			delete ddraw;
		}
	}
	unsigned long *p = *(unsigned long **)ddraw;
	for (int i = 0; i < 16; i++) {
		WIN32API_INFO("\t%3d: %p\n", i, p[i]);
	}
	WIN32API_INFO("\tlplpDD = %p\n", *lplpDD);
	WIN32API_LEAVE(rc);
	return rc;
}
static IDirectDrawSurface* GetBlitSurface()
{
  IDirectDrawSurface* blitSurface;

  if(PrimarySurfaceVersion < 4)
  {
    IDirectDrawSurface *surf = (IDirectDrawSurface *) PrimarySurface;

    DDSURFACEDESC ddsd;
    ZeroMemory(&ddsd,sizeof(ddsd));
    ddsd.dwSize = sizeof(ddsd);
    if(FAILED(surf->GetSurfaceDesc(&ddsd)))
      printLog("video: can't get surface desc\n");
    else
    {
      ddsd.dwWidth = captureWidth;
      ddsd.dwHeight = captureHeight;

      ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
      ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY;
      IDirectDraw *dd = (IDirectDraw *) PrimaryDDraw;
      if(FAILED(dd->CreateSurface(&ddsd,&blitSurface,0)))
        printLog("video: could not create blit target\n");
    }
  }
  else
  {
    IDirectDrawSurface4 *srf4 = (IDirectDrawSurface4 *) PrimarySurface;

    DDSURFACEDESC2 ddsd;
    ZeroMemory(&ddsd,sizeof(ddsd));
    ddsd.dwSize = sizeof(ddsd);
    if(FAILED(srf4->GetSurfaceDesc(&ddsd)))
      printLog("video: can't get surface desc\n");
    else
    {
      ddsd.dwWidth = captureWidth;
      ddsd.dwHeight = captureHeight;

      ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
      ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY;
      ddsd.ddsCaps.dwCaps2 = 0;
      IDirectDraw4 *dd = (IDirectDraw4 *) PrimaryDDraw;
      if(FAILED(dd->CreateSurface(&ddsd,(IDirectDrawSurface4 **) &blitSurface,0)))
        printLog("video: could not create blit target\n");
    }
  }

  return blitSurface;
}
Exemple #3
0
wxDisplayImpl *wxDisplayFactoryDirectDraw::CreateDisplay(unsigned n)
{
    wxCHECK_MSG( n < m_displays.size(), NULL, wxT("invalid display index") );

    wxDisplayInfoDirectDraw *
        info = static_cast<wxDisplayInfoDirectDraw *>(m_displays[n]);

    if ( !info->m_pDD2 )
    {
        IDirectDraw *pDD;
        GUID guid(info->m_guid);
        HRESULT hr = (*m_pfnDirectDrawCreate)(&guid, &pDD, NULL);

        if ( FAILED(hr) || !pDD )
        {
            // what to do??
            wxLogApiError(wxT("DirectDrawCreate"), hr);
            return NULL;
        }

        // we got IDirectDraw, but we need IDirectDraw2
        hr = pDD->QueryInterface(wxIID_IDirectDraw2, (void **)&info->m_pDD2);
        pDD->Release();

        if ( FAILED(hr) || !info->m_pDD2 )
        {
            wxLogApiError(wxT("IDirectDraw::QueryInterface(IDD2)"), hr);
            return NULL;
        }

        // NB: m_pDD2 will now be only destroyed when m_displays is destroyed
        //     which is ok as we don't want to recreate DD objects all the time
    }
    //else: DirectDraw object corresponding to our display already exists

    return new wxDisplayImplDirectDraw(n, *info, info->m_pDD2);
}
DDraw *DDraw::CreateDDrawObject(GUID *lpGUID) {

    DTRACE_PRINTLN("DDraw::Init");
    HRESULT ddResult;
    DXObject *newDXObject;

    // First, try to create a DX7 object
    FnDDCreateExFunc ddCreateEx = NULL;

    if (getenv("NO_J2D_DX7") == NULL) {
	ddCreateEx = (FnDDCreateExFunc)
	::GetProcAddress(hLibDDraw, "DirectDrawCreateEx");
    }

    if (ddCreateEx) {

	DTRACE_PRINTLN("Using DX7");
	// Success - we are going to use the DX7 interfaces
	// create ddraw object
	IDirectDraw7 	*ddObject;

	ddResult = (*ddCreateEx)(lpGUID, (void**)&ddObject, IID_IDirectDraw7, NULL);
	if (ddResult != DD_OK) {
	    DebugPrintDirectDrawError(ddResult, "DDCreateDD dd create");
	    return NULL;
	}
	ddResult = ddObject->SetCooperativeLevel(NULL, 
						 (DDSCL_NORMAL | 
						  DDSCL_FPUPRESERVE));
	if (ddResult != DD_OK) {
	    DebugPrintDirectDrawError(ddResult,
		"DDraw::Init setting cooperative level");
	    return NULL;
	}
	newDXObject = new DX7Object(ddObject);
    
    } else {
	DTRACE_PRINTLN("Using DX5");
	// No DX7, try for DX3/5
	IDirectDraw 	*ddObject;
	IDirectDraw2 	*dd2Object;

	FnDDCreateFunc ddCreate = (FnDDCreateFunc)
	    ::GetProcAddress(hLibDDraw, "DirectDrawCreate");
	if (!ddCreate) {
	    // REMIND: might want to shut down ddraw (useDD == FALSE?)
	    // if this error occurs
	    DTRACE_PRINTLN("Could not create DDraw");
	    return NULL;
	}
	// create ddraw object
	ddResult = (*ddCreate)(lpGUID, &ddObject, NULL);
	if (ddResult != DD_OK) {
	    DebugPrintDirectDrawError(ddResult, "DDCreateDD dd create");
	    return NULL;
	}
	ddResult = ddObject->QueryInterface(IID_IDirectDraw2,
	    (void**)&dd2Object);
	if (ddResult != S_OK) {
	    // DirectDraw2 was supported in DX3; don't bother
	    // with anything less than this
	    DebugPrintDirectDrawError(ddResult,
		"DDraw::CreateDDrawObject finding dd3 interface");
	    return NULL;
	}

	ddResult = dd2Object->SetCooperativeLevel(NULL, DDSCL_NORMAL);
	if (ddResult != DD_OK) {
	    DebugPrintDirectDrawError(ddResult,
				      "DDraw::CreateDD setting coop level");
	    return NULL;
	}
	newDXObject = new DX5Object(dd2Object);
    }

    return new DDraw(newDXObject);
}
Exemple #5
0
int main(int argc, char *argv[])
{
    /*! blitz window handle */
    HWND hWnd = 0;

    /*! blitz window client rectangle */
    RECT clientRect = { 0 };

    /*! directdraw interfaces */
    IDirectDraw         *pDD = NULL;
    IDirectDraw7        *pDD7 = NULL;

    /*! return code */
    HRESULT hRet;

    /*! advertise */
    {
        printf("autoblitz\n");
        printf("\n");
    }

    /*! ask user for blitz hwnd (found using spyxx, for example) */
    {
        printf("hwnd : ");
        scanf("%X", &hWnd);
    }

    /*! retrieve blitz window rectangle */
    GetWindowRect(hWnd, &windowRect);

    /*! retrieve blitz window client rectangle */
    GetClientRect(hWnd, &clientRect);

    /*! calculate blitz window width/height */
    windowWidth = windowRect.right - windowRect.left;
    windowHeight = windowRect.bottom - windowRect.top;

    /*! allocate rgb data */
    rgb32 = (uint32*)calloc(windowWidth*windowHeight*4, 1);

    /*! initialize capture */
    {
        rp_debug_trace("DirectDrawCreate\n");

        hRet = DirectDrawCreate(NULL, &pDD, NULL);

        if(FAILED(hRet)) { goto cleanup; }

        rp_debug_trace("pDD->QueryInterface\n");

        hRet = pDD->QueryInterface(IID_IDirectDraw7, (void**)&pDD7);

        if(FAILED(hRet)) { goto cleanup; }

        rp_debug_trace("pDD7->SetCooperativeLevel\n");

        hRet = pDD7->SetCooperativeLevel(NULL, DDSCL_NORMAL);

        if(FAILED(hRet)) { goto cleanup; }

        rp_debug_trace("pDD7->CreateSurface\n");

        /*! initialize surfaces */
        {
            DDSURFACEDESC2 ddsd;

            ZeroMemory(&ddsd, sizeof(ddsd));

            ddsd.dwSize = sizeof(ddsd);
            ddsd.dwFlags = DDSD_CAPS;
            ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;

            hRet = pDD7->CreateSurface(&ddsd, &pDDSurface7, NULL);

            if(FAILED(hRet)) { goto cleanup; }

            rp_debug_trace("pDD7->CreateSurface (Sys)\n");

            ZeroMemory(&ddsd, sizeof(DDSURFACEDESC2));
            ZeroMemory(&ddsd.ddpfPixelFormat, sizeof(DDPIXELFORMAT));

            ddsd.dwSize = sizeof(ddsd);
            ddsd.dwFlags = DDSD_WIDTH | DDSD_HEIGHT | DDSD_LPSURFACE | DDSD_PITCH | DDSD_PIXELFORMAT | DDSD_CAPS;
            ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY;
            ddsd.dwWidth = windowWidth;
            ddsd.dwHeight = windowHeight;
            ddsd.lPitch = windowWidth*4;
            ddsd.lpSurface = rgb32;
            ddsd.ddpfPixelFormat.dwSize = sizeof(DDPIXELFORMAT);
            ddsd.ddpfPixelFormat.dwFlags= DDPF_RGB;
            ddsd.ddpfPixelFormat.dwRGBBitCount = (DWORD)4*8;
            ddsd.ddpfPixelFormat.dwRBitMask = 0x00FF0000;
            ddsd.ddpfPixelFormat.dwGBitMask = 0x0000FF00;
            ddsd.ddpfPixelFormat.dwBBitMask = 0x000000FF;

            hRet = pDD7->CreateSurface(&ddsd, &pDDSysSurface7, NULL);

            if(FAILED(hRet)) { goto cleanup; }
        }

        rp_debug_trace("Init success!\n");

        /*! press button to start the game */
        click_window(hWnd, 229, 196);

        while(true)
        {
            /*! wait for user to tell us when to continue on to the next move */
            //int ret = MessageBox(0, L"Press OK to take the next move (wait for animation to stop)", L"autoblitz [blog.caustik.com]", MB_OKCANCEL);

            /*! if cancel was pressed, we're done */
            //if(ret == IDCANCEL) { break; }

            /*! if mouse cursor is within the flash window, wait */
            {
                POINT pt;

                GetCursorPos(&pt);

                if( (pt.x > windowRect.left) && (pt.x < windowRect.right)
                 && (pt.y > windowRect.top)  && (pt.y < windowRect.bottom) )
                {
                    printf("(cursor is inside window..waiting)\n");
                    rp_thread::sleep(100);
                    continue;
                }
            }

            /*! current grid */
            blockColor gameBoard[8][8];

            /*! capture the board */
            capture_board(gameBoard);

            /*! display gameboard */
            {
                printf("\n");
                printf("- current game board -\n");
                printf("\n");

                display_board(gameBoard);
            }

            /*! check for end of game */
            {
                int x;

                for(x=0;x<8;x++)
                {
                    if(gameBoard[7][x] != BC_BLUE) { break; }

                    /*! if last row was entirely blue, click the "play again?" button */
                    if(x == 7)
                    {
                        int clickX = baseX + eachW*1 + halfW;
                        int clickY = baseY + eachH*6 + halfH;

                        click_window(hWnd, clickX, clickY);
                    }
                }
            }

            /*! analyze gameBoard and make the best move */
            {
                int aX=0, aY=0, bX=0, bY=0;

                /*! analyze gameBoard */
                analyze_board(gameBoard, aX, aY, bX, bY);

                /*! click first piece */
                {
                    int clickX = baseX + eachW*aX + halfW;
                    int clickY = baseY + eachH*aY + halfH;

                    click_window(hWnd, clickX, clickY);
                }

                rp_thread::sleep(150);

                /*! click second piece */
                {
                    int clickX = baseX + eachW*bX + halfW;
                    int clickY = baseY + eachH*bY + halfH;

                    click_window(hWnd, clickX, clickY);
                }
            }
#if 0
            /*! wait for animation to start */
            rp_thread::sleep(250);

            /*! wait for board to stabilize */
            while(true)
            {
                /*! current grid */
                blockColor tmpBoard[8][8];

                /*! wait a little */
                rp_thread::sleep(150);

                /*! capture current game board */
                capture_board(tmpBoard);

                /*! if board has not changed, stop waiting */
                if(memcmp(tmpBoard, gameBoard, sizeof(tmpBoard)) == 0) { break; }

                /*! remember this board for next loop */
                memcpy(gameBoard, tmpBoard, sizeof(tmpBoard));
            }
#endif
        }
    }

cleanup:

    /*! cleanup rgb pixels */
    if(rgb32 != 0) { free(rgb32); }

    /*! cleanup system service */
    if(pDDSysSurface7 != 0) { pDDSysSurface7->Release(); }

    /*! cleanup primary surface */
    if(pDDSurface7 != 0) { pDDSurface7->Release(); }

    /*! cleanup directdraw7 */
    if(pDD7 != 0) { pDD7->Release(); }

    /*! cleanup directdraw */
    if(pDD != 0) { pDD->Release(); }

    return 0;
}