MFC鼠标点至窗口会显示窗口边缘程序
用定时器每隔一定时间显示边缘,我的程序如下voidCBDlg::OnTimer(UINTnIDEvent){//TODO:Addyourmessagehandlercod...
用定时器每隔一定时间显示边缘,我的程序如下
void CBDlg::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
POINT pnt;
RECT rc;
CDC* pdc=GetDC();
int oldRop2=pdc->SetROP2(10);
::GetCursorPos(&pnt);
HWND hwnd=::WindowFromPoint(pnt);
g_hWnd=hwnd;
::GetWindowRect(g_hWnd,&rc);
if(rc.left<0) rc.left=0;
if(rc.top<0) rc.top=0;
CPen *oldpen;
CPen newpen(0,3,RGB(125,0,125));
oldpen=(CPen*)pdc->SelectObject(&newpen);
pdc->Rectangle(&rc);
Sleep(400);
pdc->SetROP2(oldRop2);
pdc->SelectObject(oldpen);
CDialog::OnTimer(nIDEvent);
}
没财富了,谢谢帮忙 展开
void CBDlg::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
POINT pnt;
RECT rc;
CDC* pdc=GetDC();
int oldRop2=pdc->SetROP2(10);
::GetCursorPos(&pnt);
HWND hwnd=::WindowFromPoint(pnt);
g_hWnd=hwnd;
::GetWindowRect(g_hWnd,&rc);
if(rc.left<0) rc.left=0;
if(rc.top<0) rc.top=0;
CPen *oldpen;
CPen newpen(0,3,RGB(125,0,125));
oldpen=(CPen*)pdc->SelectObject(&newpen);
pdc->Rectangle(&rc);
Sleep(400);
pdc->SetROP2(oldRop2);
pdc->SelectObject(oldpen);
CDialog::OnTimer(nIDEvent);
}
没财富了,谢谢帮忙 展开
展开全部
POINT point;
GetCursorPos(&point);//得到鼠标的位置
HWND m_hCurrentWindow=::WindowFromPoint(point);//返回包含了指定点的窗口的句柄。忽略屏蔽、隐藏以及透明窗口
while(::GetParent(m_hCurrentWindow))//这个循环是很关键的,因为鼠标可能指到一个窗口的子窗口上,如一个按钮
m_hCurrentWindow=::GetParent(m_hCurrentWindow);
CDC dc;
CPen *pOldPen;
CBrush *pOldBrush;
RECT rect;
dc.Attach(::GetWindowDC(m_hCurrentWindow));
CPen RectanglePen(PS_SOLID,5,COLORREF(0));
pOldPen=(CPen *)dc.SelectObject(&RectanglePen);
pOldBrush=(CBrush *)dc.SelectStockObject(HOLLOW_BRUSH);
::GetWindowRect(m_hCurrentWindow,&rect);
dc.Rectangle(0,0,rect.right-rect.left,rect.bottom-rect.top);
dc.SelectObject(pOldPen);
dc.SelectObject(pOldBrush);
dc.Detach();
GetCursorPos(&point);//得到鼠标的位置
HWND m_hCurrentWindow=::WindowFromPoint(point);//返回包含了指定点的窗口的句柄。忽略屏蔽、隐藏以及透明窗口
while(::GetParent(m_hCurrentWindow))//这个循环是很关键的,因为鼠标可能指到一个窗口的子窗口上,如一个按钮
m_hCurrentWindow=::GetParent(m_hCurrentWindow);
CDC dc;
CPen *pOldPen;
CBrush *pOldBrush;
RECT rect;
dc.Attach(::GetWindowDC(m_hCurrentWindow));
CPen RectanglePen(PS_SOLID,5,COLORREF(0));
pOldPen=(CPen *)dc.SelectObject(&RectanglePen);
pOldBrush=(CBrush *)dc.SelectStockObject(HOLLOW_BRUSH);
::GetWindowRect(m_hCurrentWindow,&rect);
dc.Rectangle(0,0,rect.right-rect.left,rect.bottom-rect.top);
dc.SelectObject(pOldPen);
dc.SelectObject(pOldBrush);
dc.Detach();
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询