Sign in to follow this  
soumya_iiitc

Multiple Monitor

Recommended Posts

I have already developed a application which is doing the following: 1. This a MFC dialog based application 2. It has three button "Capture","List Windows","Exit" 3. It is listing all the windows and then 4. After selecting a window and if you press capture it will capture selected window data. 5. Now i have the captured image into a buffer. Question/Probelm: 1. How can i display this buffer only in the secondary monitor? 2. Is it possible to show the output in fullscreen mode on secondary monitor. 3.How can i maintain the aspect ration of the buffer on secondary monitor if the captured data dimension is smaller than the secondary monitor resolution? Please help.

Share this post


Link to post
Share on other sites
Now i can display something on second monitor.I am able to display a solid fill blue rectangle and able to display a text on it.

You need a dual monitor input graphics card NVIDIA,MATROX or ATI
Dual Card

Now i want to display a bitmap image on my second monitor.


How can send a bitmap image?
Is it possible to send the raw image data without using the BITMAP?

Below is the code:

int count = 0;
void CMonitorTestDlg::OnBnClickedButtonFlashAll()
{
CMonitor monitor;
CMonitors monitors;

CString cstr[2];


for ( int i = 0; i < monitors.GetCount(); i++ )
{
count = i+1;
monitor = monitors.GetMonitor( i );
FlashMonitor( monitor);
Sleep( 500 );
}
}
void CMonitorTestDlg::FlashMonitor( CMonitor& monitor, bool WorkSpace)
{
CRect rect;

if ( WorkSpace )
//get the work area rect of the monitor this window is on
monitor.GetWorkAreaRect( &rect );
else
monitor.GetMonitorRect( &rect );

CMonitorDC dc( &monitor );

if(count ==1)
{
// create and select a solid blue brush
CBrush brushBlue(RGB(0, 255, 0));
CBrush* pOldBrush = dc.SelectObject(&brushBlue);

rect.DeflateRect(200,200);
dc.Rectangle(&rect);

COLORREF clr1 = RGB(0,0,0);
dc.SetTextColor(clr1);
dc.DrawText("Primary Monitor",17,&rect,1);

// put back the old objects
dc.SelectObject(pOldBrush);
}
else
{

// create and select a solid blue brush
CBrush brushBlue(RGB(0, 0, 255));
CBrush* pOldBrush = dc.SelectObject(&brushBlue);

rect.DeflateRect(200,200);
dc.Rectangle(&rect);

COLORREF clr1 = RGB(0,0,0);
dc.SetTextColor(clr1);
dc.DrawText("Secondary Monitor",17,&rect,1);

// put back the old objects
dc.SelectObject(pOldBrush);

/*How can i send a bitmap image or a image buffer to second
monitor.I have tried to use Bltblt but create compatibleDc
need a CDC object not the CMonitor dc.*/

}

Sleep( 2000 );

::InvalidateRect( NULL, &rect, TRUE );
}





Code that i have tried to send a bitmap

// load IDB_BITMAP1 from our resources
CBitmap bmp;
if (bmp.LoadBitmap(IDB_BITMAP1))
{
// Get the size of the bitmap
BITMAP bmpInfo;
bmp.GetBitmap(&bmpInfo);

// Create an in-memory DC compatible with the
// display DC we're using to paint

CDC dcMemory;
//dcMemory.CreateCompatibleDC(dc); // Cant do this CMonitorDC * to CDC *

// Select the bitmap into the in-memory DC
CBitmap* pOldBitmap = dcMemory.SelectObject(&bmp);

// Find a centerpoint for the bitmap in the client area
CRect rect1;
GetClientRect(&rect1);
int nX = rect.left + (rect1.Width() - bmpInfo.bmWidth) / 2;
int nY = rect.top + (rect1.Height() - bmpInfo.bmHeight) / 2;

// Copy the bits from the in-memory DC into the on-
// screen DC to actually do the painting. Use the centerpoint
// we computed for the target offset.
dc.BitBlt(nX, nY, bmpInfo.bmWidth, bmpInfo.bmHeight, &dcMemory,
0, 0, SRCCOPY);

dcMemory.SelectObject(pOldBitmap);
}






Thanks
Soumyadipta De

Share this post


Link to post
Share on other sites
Have you tried StretchDIBits() instead of BitBlt()? It copies a DIB(Device Independent Bitmap) to a destination DC. (not DC to DC)

Share this post


Link to post
Share on other sites
I have copied the bitmap into the dc using StretchDIBits() functions.The pro gramme didn't crash but no images is displayed in any of the monitors.

If required i can post the complete code or can upload a link of the complete project.

Share this post


Link to post
Share on other sites
Yes, Now i am able to display a bitmap file on the secondary monitor.Below is the simple code that i have used to do so.



// load IDB_BITMAP1 from our resources
HBITMAP hbmp;
hbmp =LoadBitmap(GetModuleHandle(NULL), MAKEINTRESOURCE(IDB_BITMAP1));


if(hbmp == NULL)
{
MessageBox("Unable to load bitmap file from resource");
return;
}

HDC hdcMem = CreateCompatibleDC(dc);

HGDIOBJ hbmOld = SelectObject(hdcMem,hbmp);

BITMAP bm;

GetObject(hbmp,sizeof(bm),&bm);
BitBlt(dc,1050,30,bm.bmWidth,bm.bmHeight,hdcMem,0,0,SRCCOPY);
SelectObject(hdcMem,hbmOld);
DeleteDC(hdcMem);




Thanks,
Soumyadipta De

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