I capture images using BitBlt / StretchBlt API's on windows 10, depending upon the necessity for scaling the screen or not. Whenever I capture the 2nd monitor that is not being configured as primary, there seems to be a strange behaviour that the captured screen's first half is the replica of the second half of the screen. This occurs randomly once for every 10 images on an average.
I could not find any documents over the internet related to this kind of strange problems. I'm not even doing any multi-threading. Might there be a problem with the capturing frequency?, But that doesn't even look sense, as there is no issue with screen capture whenever I set the monitor as primary.
Here is the original image
captured image
monitor alignment
Note: I have been able to reproduce the issue only when the forground window is Notepad++ as of now. I'm not sure whether the issue happens for other applications as well., I could not go for directX based approach as the program must run on WindowsXP as well.
Here is an excerpt of the code:
HDC memDC = CreateCompatibleDC ( hDC ) ;
HBITMAP previousImage = ( HBITMAP ) SelectObject ( memDC , curImage )
if ( ( previousImage ) == NULL )
{
return -1;
}
BOOL blitok ;
if ( lf_ImageScalingFactor != (double)1.0 )
{
SetStretchBltMode ( memDC , HALFTONE ) ;
if ( capture_all )
{
blitok = StretchBlt ( memDC , 0 , 0 , (int)(clientwindow.Width () ) , (int) (clientwindow.Height () ),
hDC , clientwindow.left - (physicalscreenrect.left * lf_ImageScalingFactor), clientwindow.top - (physicalscreenrect.top * lf_ImageScalingFactor), physicalscreenrect.Width(), physicalscreenrect.Height(), SRCCOPY | CAPTUREBLT ) ;
}
else
{
blitok = StretchBlt ( memDC , 0 , 0 , (int)(clientwindow.Width ()) , (int)(clientwindow.Height ()),
hDC , clientwindow.left - (physicalscreenrect.left * lf_ImageScalingFactor), clientwindow.top - (physicalscreenrect.top * lf_ImageScalingFactor),physicalscreenrect.Width(), physicalscreenrect.Height(), SRCCOPY ) ;
}
}
else
{
if ( capture_all )
{
blitok = BitBlt ( memDC , 0 , 0 , clientwindow.Width (), clientwindow.Height (),
hDC , clientwindow.left - physicalscreenrect.left , clientwindow.top - physicalscreenrect.top , SRCCOPY | CAPTUREBLT ) ;
}
else
{
blitok = BitBlt ( memDC , 0 , 0 , clientwindow.Width (), clientwindow.Height (),
hDC , clientwindow.left - physicalscreenrect.left , clientwindow.top - physicalscreenrect.top , SRCCOPY ) ;
}
}
SelectObject ( memDC , previousImage ) ;
DeleteDC ( memDC ) ;
DeleteDC ( hDC ) ;
Am I doing something wrong over here?.
Any help is appreciable, Thanks in advance.