1.首先处理自动停靠.
1).建立一个对话框类cdlg.
2).
///dlg.h
class cdlg
{
private:
bool m_isautohide; //窗口是否可以自动隐藏
bool m_iswinhide; // 窗口是否隐藏
...........
}
///dlg.cpp
.....
void cdlg::onmove(int x, int y)
{
cdialog::onmove(x, y);
///窗口从显示到隐藏时,不做其它操作
if(m_iswinhide)
{
return;
}
crect trect;
getwindowrect(trect);
if(trect.top<10)
{///如果窗口移动后的位置和到屏幕上方的距离小于10
///就使窗口停靠到屏幕上方.
trect.bottom-= trect.top;
trect.top= 0;
movewindow(trect);
///窗口停靠后就可以自动隐藏
m_isautohide= true;
}
else
{
///如窗口没有停靠就不可以自动隐藏
m_isautohide= false;
}
}
void cdlg::onmoving(uint fwside, lprect prect)
{
if((prect->top < 10)
&& (!m_isautohide) )
{///如果窗口移动到的位置和到屏幕上方的距离小于10
///就使窗口停靠到屏幕上方.
prect->bottom-= prect->top;
prect->top= 0;
m_isautohide= true;
}
cdialog::onmoving(fwside, prect);
}
2.处理自动收缩
//dlg.h
class cdlg
{
.....
lresult onmouseleave( hwnd hwnd, uint msg,
wparam wparam,lparam lparam );
}
//dlg.cpp
begin_message_map(cdlg, cdialog)