Sign in to follow this  
johndirect

Presented image going beyond screen

Recommended Posts

johndirect    122
Hello, I have a simple program below, where I am creating a plain surface and loading it with an image and then presenting it. As you can see in the example code beow, I create a window and surface of 1400x900 dimension. The image appears fine and within the boundaries of the screen. However if I create a window and surface of 1920x1440 dimension, the image appears to be displayed partially beyond the screen. I am wondering why this is happening. If the screen resolution, window size (and hence backbuffer default size) and surface size are all of the same dimensions, shound'nt the image be displayed within the screen(monitor) limits?

// Global variable 
 IDirect3DDevice9* pReturnedDeviceInterface; 
 IDirect3DSurface9* pSurface; 
 LPDIRECT3D9 g_pD3D = NULL; 
 
 
// Message Loop CallBack Function prototype 
LRESULT CALLBACK fnMessageProcessor (HWND, UINT, WPARAM, LPARAM); 
// Fuction called automatically when the program starts 
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstande, PSTR szCmdLine, int iCmdShow) 
{ 
 HWND hWnd; 
 MSG  msg; 
 WNDCLASSEX wndclass; 
 
 // Set up window class 
 wndclass.cbSize  = sizeof(WNDCLASSEX); 
 wndclass.style  = CS_HREDRAW | CS_VREDRAW; 
 wndclass.lpfnWndProc = fnMessageProcessor; 
 wndclass.cbClsExtra  = 0; 
 wndclass.cbWndExtra  = 0; 
 wndclass.hInstance  = hInstance; 
 wndclass.hIcon   = LoadIcon(NULL, IDI_APPLICATION); 
 wndclass.hCursor  = LoadCursor(NULL, IDC_ARROW); 
 wndclass.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH); 
 wndclass.lpszMenuName = NULL; 
 wndclass.lpszClassName = L"Window Class"; // Class Name 
 wndclass.hIconSm  = LoadIcon(NULL, IDI_APPLICATION); 
 
 // Register the window class 
 if(RegisterClassEx(&wndclass) == 0) 
 { 
  // The program failed, exit 
  exit(1); 
 } 
 
 // Create the window 
 hWnd = CreateWindowEx( 
  WS_EX_OVERLAPPEDWINDOW,  
  L"Window Class",    // Class Name 
  L"Create Window Example", // Title bar text 
  WS_OVERLAPPEDWINDOW, 
  0, 
  0, 
  1440, 
  900, 
  NULL, 
  NULL, 
  hInstance, 
  NULL); 
 // Display the window 
 ShowWindow(hWnd, iCmdShow); 
 
 HRESULT Result=0; 
 D3DCAPS9 caps; 
 int vp;   
 D3DSURFACE_DESC surfaceDesc; 
 D3DLOCKED_RECT lockedRect; 
 
 
 g_pD3D = Direct3DCreate9(D3D_SDK_VERSION); 
 if(g_pD3D == NULL)  
 { 
  MessageBox(hWnd,L"Direct3DCreate9 failed!",L"ERROR!",MB_ICONERROR|MB_OK); 
  return E_FAIL; 
 } 
 
 D3DPRESENT_PARAMETERS d3dpp;

 ZeroMemory( &d3dpp, sizeof(d3dpp) );
    d3dpp.Windowed = TRUE;
    d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
    d3dpp.BackBufferFormat = D3DFMT_UNKNOWN;

 Result = g_pD3D->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &pReturnedDeviceInterface); 
 if (Result != D3D_OK ) 
 {  
  g_pD3D->Release(); 
  MessageBox(hWnd,L"CreateDevice failed!",L"ERROR!",MB_ICONERROR|MB_OK); 
  return E_FAIL; 
 } 

LPDIRECT3DSURFACE9 Surface;
if ( FAILED(pReturnedDeviceInterface->CreateOffscreenPlainSurface(1440, 900, D3DFMT_X8R8G8B8, D3DPOOL_DEFAULT, &Surface, NULL)))
{
   return E_FAIL;
}
D3DXLoadSurfaceFromFile(Surface,NULL,NULL,L"flower.jpg",NULL,D3DX_DEFAULT,0,NULL);

pReturnedDeviceInterface->Clear( 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(255, 255 ,255), 1.0f, 0 );

//Presenting the surface


LPDIRECT3DSURFACE9 pBackBuffer=NULL;
pReturnedDeviceInterface->GetBackBuffer(0,0,D3DBACKBUFFER_TYPE_MONO, &pBackBuffer);
pReturnedDeviceInterface->BeginScene() ;		{
pReturnedDeviceInterface->StretchRect( Surface, NULL,pBackBuffer, NULL, D3DTEXF_NONE ); 
pReturnedDeviceInterface->EndScene();
pBackBuffer->Release();
pReturnedDeviceInterface->Present( NULL, NULL, NULL, NULL );

 // Process messages until the program is terminated 
 while(GetMessage (&msg, NULL, 0, 0)) 
 { 
  TranslateMessage(&msg); 
  DispatchMessage(&msg); 
 } 
 
 return (msg.wParam); 
 
} 
}
 
LRESULT CALLBACK fnMessageProcessor(HWND hWnd, UINT iMsg, WPARAM wParam, LPARAM lParam) 
{ 
 switch(iMsg) 
 { 
  // Called when window is first created 
  case WM_CREATE: 
   return(0); 
  // Called when window is refreshed 
  case WM_PAINT: 
   pReturnedDeviceInterface->Present(NULL,NULL,NULL,NULL); 
   return(0); 
  // Called when th user closes the window 
  case WM_DESTROY: 
   pSurface->Release(); 
   pReturnedDeviceInterface->Release(); 
   g_pD3D->Release(); 
   PostQuitMessage(0); 
   return(0); 
  case WM_KEYDOWN: 
   if ( wParam == VK_ESCAPE ) 
   { 
    ::DestroyWindow(hWnd); 
    return(0); 
   } 
  default: 
   return DefWindowProc(hWnd, iMsg, wParam, lParam); 
 
 }}  
 
 

Share this post


Link to post
Share on other sites
MJP    19755
If you create a window and resize it so its client size is the dimensions of your desktop, the window will be too large to display on the screen. Is the actual client area larger than the screen as well?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this