Re: Grabbing desktop image under a window
Hi Asm,
If you hide the window and then show it again you will disrupt the some
message like WM_MOVE. So your window will be very hard to move.
I did this using layered windows, it works pretty good, the only thing that
needs work is the flickering of the border. (NOTE: this will only work for
WinXP and above.)
BOOL CMagnifyDlg::OnInitDialog()
{
CDialog::OnInitDialog();
SetWindowLong(m_hWnd,GWL_EXSTYLE,GetWindowLong(m_hWnd, GWL_EXSTYLE) |
WS_EX_LAYERED);
SetLayeredWindowAttributes(0,255,LWA_ALPHA);
GetImage();
return TRUE;
}
void CMagnifyDlg::GetImage()
{
//make window completely transparent
SetLayeredWindowAttributes(0,0,LWA_ALPHA);
CRect Rect;
GetClientRect(&Rect);
ClientToScreen(&Rect);
m_Bmp.DeleteObject();
CDC *pDC = GetDesktopWindow()->GetDC();
CDC MemDC;
MemDC.CreateCompatibleDC(pDC);
m_Bmp.CreateCompatibleBitmap(pDC,Rect.Width(),Rect.Height());
int Saved = MemDC.SaveDC();
MemDC.SelectObject(&m_Bmp);
MemDC.BitBlt(0,0,Rect.Width(),Rect.Height(),pDC,Rect.left,Rect.top,SRCCOPY);
MemDC.RestoreDC(Saved);
GetDesktopWindow()->ReleaseDC(pDC);
//bring the window back
SetLayeredWindowAttributes(0,255,LWA_ALPHA);
Invalidate();
}
void CMagnifyDlg::OnPaint()
{
CPaintDC dc(this); // device context for painting
CRect Rect;
GetClientRect(&Rect);
CDC MemDC;
MemDC.CreateCompatibleDC(&dc);
int Saved = MemDC.SaveDC();
MemDC.SelectObject(&m_Bmp);
dc.BitBlt(0,0,Rect.Width(),Rect.Height(),&MemDC,0,0,SRCCOPY);
MemDC.RestoreDC(Saved);
}
AliR.
"MrAsm" <mrasm@usa.com> wrote in message
news:islqu29lmiofj4k3h5ltv78b4a7talloih@4ax.com...
Hi,
I would like to do some processing on a rectangular area of an image.
I would like to use a window in a way similar to a magnifier glass,
e.g. I would like to move the window onto the desktop, and process the
desktop image under the window's client area.
Could you please suggest me some ideas to implement this?
A trivial approach - but I think ugly and inefficient - I thought
would be:
1. Get window client area rect
2. Hide the window
3. Grab desktop sub-image corresponding to client area rect of point 1
4. Show the window
5. Show the processed image
Thanks for your suggestions,
MrAsm