i have c++ program capture screenshot of specific window , save using following code
int main() { gdiplusstartupinput gdiplusstartupinput; ulong_ptr gdiplustoken; gdiplusstartup(&gdiplustoken, &gdiplusstartupinput, null); rect rc; hwnd hwnd = findwindow(null,text("window title here")); if(hwnd == null) { cout<<"can't find window"; return 0; } getclientrect(hwnd,&rc); hdc hdcscreen = getdc(null); hdc hdc = createcompatibledc(hdcscreen); hbitmap hbmp = createcompatiblebitmap(hdcscreen,rc.right - rc.left,rc.bottom - rc.top); selectobject(hdc,hbmp); printwindow(hwnd,hdc,null); bitmaptojpg(hbmp,rc.right - rc.left,rc.bottom-rc.top); //function convert hbmp bitmap jpg deletedc(hdc); deleteobject(hbmp); releasedc(null,hdcscreen); } this code works many of windows, of windows, output black image correct width , height. on searching found solution use bitblt(). cannot figure out how replace printwindow() bitblt() , output hbitmap. need
first, replace hdcscreen hdcwnd, getdc(hwnd) instead of getdc(null). won't change anything, more adequate, printwindow().
then, replace :
printwindow(hwnd,hdc,null); by :
bitblt( hdc, 0, 0, rc.right - rc.left,rc.bottom-rc.top, hdcwnd, 0, 0, srccopy );
Comments
Post a Comment