directx - GetFrontBufferData returns black screen on any game -


i writing screen capture application. used code mentioned on this link application.

following entire code reference:

    // wangsnotesscrcapt2.cpp : defines entry point application. //  #include "stdafx.h" #include "wangsnotesscrcapt2.h"  //include d3d library #include <d3d9.h> #include <d3dx9tex.h> #include <dinput.h>   //link d3d library #pragma comment (lib, "d3d9.lib") #pragma comment (lib, "d3dx9.lib")  #define max_loadstring 100 #define wm_keydown 0x0100  // global variables: hinstance hinst;                                // current instance tchar sztitle[max_loadstring];                  // title bar text tchar szwindowclass[max_loadstring];            // main window class name  //d3d objects lpdirect3d9 d3d = null; lpdirect3ddevice9 d3ddev = null;   // forward declarations of functions included in code module: atom                myregisterclass(hinstance hinstance); bool                initinstance(hinstance, int); lresult callback    wndproc(hwnd, uint, wparam, lparam); int_ptr callback    about(hwnd, uint, wparam, lparam);  void released3d(); void capturescreend3d(); void initd3d(hwnd hwnd);   int apientry _twinmain(_in_ hinstance hinstance,                      _in_opt_ hinstance hprevinstance,                      _in_ lptstr    lpcmdline,                      _in_ int       ncmdshow) {     unreferenced_parameter(hprevinstance);     unreferenced_parameter(lpcmdline);      // todo: place code here.     msg msg;     haccel hacceltable;      // initialize global strings     loadstring(hinstance, ids_app_title, sztitle, max_loadstring);     loadstring(hinstance, idc_wangsnotesscrcapt2, szwindowclass, max_loadstring);     myregisterclass(hinstance);      // perform application initialization:     if (!initinstance (hinstance, ncmdshow))     {         return false;     }      hacceltable = loadaccelerators(hinstance, makeintresource(idc_wangsnotesscrcapt2));      // main message loop:     while (getmessage(&msg, null, 0, 0))     {         if (!translateaccelerator(msg.hwnd, hacceltable, &msg))         {             translatemessage(&msg);             dispatchmessage(&msg);         }      }         (int k = 0; k < 10000; k++)             {                 (int j = 0; j < 10000; j++)                 {                     (int = 0; < 100; i++)                     {                     }                 }              }       //capture screen     capturescreend3d();       //release d3d objects when program closed     released3d();      return (int) msg.wparam; }   #define bufsize 65535  #define shifted 0x8000    // //  function: myregisterclass() // //  purpose: registers window class. // atom myregisterclass(hinstance hinstance) {     wndclassex wcex;      wcex.cbsize = sizeof(wndclassex);      wcex.style          = cs_hredraw | cs_vredraw;     wcex.lpfnwndproc    = wndproc;     wcex.cbclsextra     = 0;     wcex.cbwndextra     = 0;     wcex.hinstance      = hinstance;     wcex.hicon          = loadicon(hinstance, makeintresource(idi_wangsnotesscrcapt2));     wcex.hcursor        = loadcursor(null, idc_arrow);     wcex.hbrbackground  = (hbrush)(color_window+1);     wcex.lpszmenuname   = makeintresource(idc_wangsnotesscrcapt2);     wcex.lpszclassname  = szwindowclass;     wcex.hiconsm        = loadicon(wcex.hinstance, makeintresource(idi_small));      return registerclassex(&wcex); }  // //   function: initinstance(hinstance, int) // //   purpose: saves instance handle , creates main window // //   comments: // //        in function, save instance handle in global variable , //        create , display main program window. // bool initinstance(hinstance hinstance, int ncmdshow) {    hwnd hwnd;     hinst = hinstance; // store instance handle in our global variable     hwnd = createwindow(szwindowclass, sztitle, ws_overlappedwindow,       cw_usedefault, 0, cw_usedefault, 0, null, null, hinstance, null);     if (!hwnd)    {       return false;    }     //init d3d objects    initd3d(hwnd);     showwindow(hwnd, ncmdshow);    updatewindow(hwnd);     return true; }  // //  function: wndproc(hwnd, uint, wparam, lparam) // //  purpose:  processes messages main window. // //  wm_command  - process application menu //  wm_paint    - paint main window //  wm_destroy  - post quit message , return // // lresult callback wndproc(hwnd hwnd, uint message, wparam wparam, lparam lparam) {     int wmid, wmevent;     paintstruct ps;     hdc hdc;      switch (message)     {     case wm_command:         wmid    = loword(wparam);         wmevent = hiword(wparam);         // parse menu selections:         switch (wmid)         {         case idm_about:             dialogbox(hinst, makeintresource(idd_aboutbox), hwnd, about);             break;         case idm_exit:             destroywindow(hwnd);             break;         default:             return defwindowproc(hwnd, message, wparam, lparam);         }         break;     case wm_paint:         hdc = beginpaint(hwnd, &ps);         // todo: add drawing code here...         endpaint(hwnd, &ps);         break;     case wm_destroy:         postquitmessage(0);         break;     default:         return defwindowproc(hwnd, message, wparam, lparam);     }     return 0; }  // message handler box. int_ptr callback about(hwnd hdlg, uint message, wparam wparam, lparam lparam) {     unreferenced_parameter(lparam);     switch (message)     {     case wm_initdialog:         return (int_ptr)true;      case wm_command:         if (loword(wparam) == idok || loword(wparam) == idcancel)         {             enddialog(hdlg, loword(wparam));             return (int_ptr)true;         }         break;     }     return (int_ptr)false; }  void initd3d(hwnd hwnd) {     d3d = direct3dcreate9(d3d_sdk_version);     d3dpresent_parameters d3dpp;     zeromemory(&d3dpp, sizeof(d3dpp));     d3dpp.windowed = true;     d3dpp.swapeffect = d3dswapeffect_discard;     d3dpp.hdevicewindow = hwnd;     d3d->createdevice(d3dadapter_default,         d3ddevtype_hal,         hwnd,         d3dcreate_software_vertexprocessing,         &d3dpp,         &d3ddev); }  void capturescreend3d() {     uint screenw = getsystemmetrics(sm_cxscreen);     uint screenh = getsystemmetrics(sm_cyscreen);     lpdirect3dsurface9 psurface;     d3ddev->createoffscreenplainsurface(screenw, screenh, d3dfmt_a8r8g8b8, d3dpool_scratch, &psurface, null);     d3ddev->getfrontbufferdata(0, psurface);     d3dxsavesurfacetofile(l"screen.bmp", d3dxiff_bmp, psurface, null, null);     psurface->release(); }  void released3d() {     d3ddev->release();     d3d->release(); } 

it returns actual screen normal window if run game returns black image.

is there way can make work fullscreen games well?

edit:

so changed way call capturescreen() function.

now call in main suggested @pauld

d3ddev->beginscene(); //capture screen capturescreend3d(); d3ddev->endscene(); d3ddev->present(null, null, null, null); released3d(); 

i still getting black image fullscreen games , works fine every other application.


Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -

How to provide Authorization & Authentication using Asp.net, C#? -