1、新建乙個繼承cdialog的對話方塊類cmagnetdlg。**如下
class cmagnetdlg : public cdialog
; // child method
bool setmaindlg(cwnd* pwnd);
void removemaindlg(cwnd* pwnd);
// to parent method
void addmagnetismlist(cwnd* pwnd);
void removemagnetismlist(cwnd* pwnd);
// child method
void magnetismrerect(crect & rparent);
private:
cwnd* m_pmaindlg;
carraym_pmagnetismlist;
bool m_bisadsorption;
int m_imagnetismrectdelta;
int m_imagnetismtype;
inline void construct();
//parent method
void moveallmagnetismdlg();
int existmagnetismlist(cwnd* pwnd);
//child method
void setadsorption(bool bisadsorption = true);
bool isadsorption() const
bool childcheckmagnetism(msg* pmsg);
protected:
declare_message_map()
virtual void dodataexchange(cdataexchange* pdx); // ddx/ddv 支援
virtual bool onwndmsg(uint message, wparam wparam, lparam lparam, lresult* presult);
virtual lresult windowproc(uint message, wparam wparam, lparam lparam);
};
inline void cmagnetdlg::construct()
cmagnetdlg::cmagnetdlg()
cmagnetdlg::cmagnetdlg(uint nidtemplate,cwnd* pparent /*=null*/)
: cdialog(nidtemplate, pparent)
cmagnetdlg::cmagnetdlg(lpctstr lpsztemplatename, cwnd* pparentwnd)
: cdialog(lpsztemplatename,pparentwnd)
cmagnetdlg::~cmagnetdlg()
void cmagnetdlg::dodataexchange(cdataexchange* pdx)
begin_message_map(cmagnetdlg, cdialog)
on_wm_moving()
on_wm_erasebkgnd()
end_message_map()
// cmagnetdlg 訊息處理程式
bool cmagnetdlg::setmaindlg(cwnd* pwnd)
void cmagnetdlg::removemaindlg(cwnd* pwnd)
}void cmagnetdlg::addmagnetismlist(cwnd* pwnd)
void cmagnetdlg::removemagnetismlist(cwnd* pwnd)
int cmagnetdlg::existmagnetismlist(cwnd* pwnd)
return -1;
}void cmagnetdlg::setadsorption(bool bisadsorption)
void cmagnetdlg::moveallmagnetismdlg()
}void cmagnetdlg::magnetismrerect(crect& rparent)
///movewindow(l,t,rcld.width(), rcld.height());
setwindowpos(null, l, t, 0, 0, swp_nozorder | swp_nosize | swp_nosendchanging); }}
bool cmagnetdlg::childcheckmagnetism(msg* pmsg)
bool bissizing = rcur.width() != rcld.width() || rcld.height() != rcur.height();
m_imagnetismtype = cmagnetdlg::magnetism_null;
m_imagnetismrectdelta = 0;
setadsorption(false);
int iothesidemagnetismtype = cmagnetdlg::magnetism_null;
int iothesidemagnetismtype1 = cmagnetdlg::magnetism_null;
if (rcld.top > rparent.top - rcld.height() && rcld.top < rparent.bottom) //y範圍限制
else if ( abs(rcld.left - rparent.right) < imindisparitypixel) //右吸附
else
ppos->x = rparent.right;
setadsorption(true);
bisadsorption = true;
} if (bisadsorption)
else
ppos->y = rparent.top;
}if (abs(rcld.bottom - rparent.bottom) < imindisparitypixel)
m_imagnetismrectdelta = ppos->y - rparent.top;
} }
if (rcld.left > rparent.left - rcld.width() && rcld.left < rparent.right) //x範圍限制
else if (abs(rcld.top - rparent.bottom) < imindisparitypixel) //下吸附
else
ppos->y = rparent.bottom;
setadsorption(true);
bisadsorption = true;
} if (bisadsorption)
else
ppos->x = rparent.left;
}if (abs(rcld.right - rparent.right) < imindisparitypixel)
m_imagnetismrectdelta = ppos->x - rparent.left;
} }return isadsorption();
}bool cmagnetdlg::onwndmsg(uint message, wparam wparam, lparam lparam, lresult* presult) //處理移動之後的
return cdialog::onwndmsg(message,wparam,lparam,presult);
}lresult cmagnetdlg::windowproc(uint message, wparam wparam, lparam lparam)
if (message == wm_moving) }
if (message == wm_windowposchanging /*|| wm_sizing == message*/) }
return cdialog::windowproc(msg.message, msg.wparam, msg.lparam);
}
2、吸附視窗都必須繼承cmagnetdlg類,
在主對話方塊中建立子對話方塊:
(必須是非模態對話方塊)
如:
ctestdlg *ptestdlg;
ptestdlg = new ctestdlg();
ptestdlg->create(idd_dlg_child, this);
ptestdlg->showwindow(sw_show);
ptestdlg->setmaindlg(this);
vc吸附視窗
太意外了,乙個小小的吸附視窗效果竟然很難找到,今天總算完成了特此紀念 pcdlgusers new cdlgusers pcdlgusers create cdlgusers idd,this m follow true if pcdlgusers iswindowvisible void ccrm...
c 類似於千千靜聽的桌面停靠程式
c 類似於千千靜聽的桌面停靠程式 using system using system.collections.generic using system.componentmodel using system.data using system.drawing using system.linq us...
c 類似於千千靜聽的桌面停靠程式收藏
c 類似於千千靜聽的桌面停靠程式 using system using system.collections.generic using system.componentmodel using system.data using system.drawing using system.linq us...