if(fullScreenStretch) { surfaceSizeX = fsWidth; surfaceSizeY = fsHeight; }
bool Direct3DDisplay::initialize(){  sizeX = 240;  sizeY = 160;  switch(videoOption) {  case VIDEO_1X:    surfaceSizeX = sizeX;    surfaceSizeY = sizeY;    break;  case VIDEO_2X:    surfaceSizeX = sizeX * 2;    surfaceSizeY = sizeY * 2;    break;  case VIDEO_3X:    surfaceSizeX = sizeX * 3;    surfaceSizeY = sizeY * 3;    break;  case VIDEO_4X:    surfaceSizeX = sizeX * 4;    surfaceSizeY = sizeY * 4;    break;  case VIDEO_320x240:  case VIDEO_640x480:  case VIDEO_800x600:  case VIDEO_OTHER:    {      RECT r;      GetWindowRect(GetDesktopWindow(), &r);      fsWidth = r.right - r.left;      fsHeight = r.bottom - r.top;      int scaleX = (fsWidth / sizeX);      int scaleY = (fsHeight / sizeY);      int min = scaleX < scaleY ? scaleX : scaleY;      surfaceSizeX = sizeX * min;      surfaceSizeY = sizeY * min;      if(fullScreenStretch) {        surfaceSizeX = fsWidth;        surfaceSizeY = fsHeight;      }    }    break;  }    rect.left = 0;  rect.top = 0;  rect.right = sizeX;  rect.bottom = sizeY;  dest.left = 0;  dest.top = 0;  dest.right = surfaceSizeX;  dest.bottom = surfaceSizeY;  DWORD style = WS_POPUP | WS_VISIBLE;  DWORD styleEx = 0;    if(videoOption <= VIDEO_4X)    style |= WS_OVERLAPPEDWINDOW;  else    styleEx = WS_EX_TOPMOST;  if(videoOption <= VIDEO_4X)    AdjustWindowRectEx(&dest, style, TRUE, styleEx);  else    AdjustWindowRectEx(&dest, style, FALSE, styleEx);      int winSizeX = dest.right-dest.left;  int winSizeY = dest.bottom-dest.top;  if(videoOption > VIDEO_4X) {    winSizeX = fsWidth;    winSizeY = fsHeight;  }    int x = 0;  int y = 0;  if(videoOption <= VIDEO_4X) {    x = windowPositionX;    y = windowPositionY;  }    // Create a window  hWindow = CreateWindowEx(styleEx,                           "GBA",                           "VisualBoyAdvance",                           style,                           x,                           y,                           winSizeX,                           winSizeY,                           NULL,                           NULL,                           hInstance,                           NULL);    if (!hWindow) {    winlog("Error creating Window %08x\n", GetLastError());    //    errorMessage(myLoadString(IDS_ERROR_DISP_FAILED));    return FALSE;  }    updateMenuBar();    adjustDestRect();    d3dDLL = LoadLibrary("D3D8.DLL");  LPDIRECT3D8 (WINAPI *D3DCreate)(UINT);  if(d3dDLL != NULL) {        D3DCreate = (LPDIRECT3D8 (WINAPI *)(UINT))      GetProcAddress(d3dDLL, "Direct3DCreate8");    if(D3DCreate == NULL) {      directXMessage("Direct3DCreate8");      return FALSE;    }  } else {    directXMessage("D3D8.DLL");    return FALSE;  }  pD3D = D3DCreate(120);      if(pD3D == NULL) {    winlog("Error creating Direct3D object\n");    return FALSE;  }    mode320Available = FALSE;  mode640Available = FALSE;  mode800Available = FALSE;  D3DDISPLAYMODE mode;  pD3D->GetAdapterDisplayMode(D3DADAPTER_DEFAULT, &mode);    switch(mode.Format) {  case D3DFMT_R8G8B8:    systemColorDepth = 24;    systemRedShift = 19;    systemGreenShift = 11;    systemBlueShift = 3;    break;  case D3DFMT_X8R8G8B8:    systemColorDepth = 32;    systemRedShift = 19;    systemGreenShift = 11;    systemBlueShift = 3;    break;  case D3DFMT_R5G6B5:    systemColorDepth = 16;    systemRedShift = 11;    systemGreenShift = 6;    systemBlueShift = 0;        break;  case D3DFMT_X1R5G5B5:    systemColorDepth = 16;    systemRedShift = 10;    systemGreenShift = 5;    systemBlueShift = 0;    break;  default:    systemMessage(0,"Unsupport D3D format %d", mode.Format);    return false;  }  fsColorDepth = systemColorDepth;    screenFormat = mode.Format;  // check for available fullscreen modes  ZeroMemory(&dpp, sizeof(dpp));  dpp.Windowed = TRUE;  dpp.BackBufferFormat = mode.Format;  dpp.BackBufferCount = 1;  dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;  dpp.BackBufferWidth = surfaceSizeX;  dpp.BackBufferHeight = surfaceSizeY;    HRESULT hret = pD3D->CreateDevice(D3DADAPTER_DEFAULT,                                    D3DDEVTYPE_HAL,                                    hWindow,                                    D3DCREATE_SOFTWARE_VERTEXPROCESSING,                                    &dpp,                                    &pDevice);  if(!SUCCEEDED(hret)) {    winlog("Error creating Direct3DDevice %08x\n", hret);    return false;  }    restoreDeviceObjects();  switch(systemColorDepth) {  case 16:    {      for(int i = 0; i < 0x10000; i++) {        systemColorMap16[i] = ((i & 0x1f) << systemRedShift) |          (((i & 0x3e0) >> 5) << systemGreenShift) |          (((i & 0x7c00) >> 10) << systemBlueShift);      }    }    break;  case 24:  case 32:    {      for(int i = 0; i < 0x10000; i++) {        systemColorMap32[i] = ((i & 0x1f) << systemRedShift) |          (((i & 0x3e0) >> 5) << systemGreenShift) |          (((i & 0x7c00) >> 10) << systemBlueShift);      }          }    break;  }  for(int i = 0; i < 24;) {    systemGbPalette[i++] = (0x1f) | (0x1f << 5) | (0x1f << 10);    systemGbPalette[i++] = (0x15) | (0x15 << 5) | (0x15 << 10);    systemGbPalette[i++] = (0x0c) | (0x0c << 5) | (0x0c << 10);    systemGbPalette[i++] = 0;  }    updateFilter();  updateIFB();  if(failed)    return false;    DragAcceptFiles(hWindow, TRUE);    return TRUE;  }