求助 !吐血求助一个程序~~!!!!

a1003671336 2011-04-27 10:50:23
怎么用vc6.0编写一个这样的程序:创建一个窗口和一个按钮,当鼠标移动到按钮时按钮消失并在窗口另一个地方出现?
可以的话给出代码 感激~~
...全文
73 点赞 收藏 9
写回复
9 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
不二星空 2011-04-27
孙鑫的。。很简单应该还有源码
回复
thematrix477 2011-04-27
孙鑫那个例子是创建了两个button吧,然后一个隐藏,显示另一个,我这方法有点麻烦了,最简单就直接继承CButton类,响应OnMouseMove事件就行
回复
满月的愿望 2011-04-27
这就是孙鑫的视频教程上的 可以去看看。先弄两个按钮 为两个按钮添加新类 响应鼠标移动响应 一个隐藏,另一个就显示就可以了
回复
King_hhuang 2011-04-27
响应WM_MOUSEMOVE
判断光标是否在按钮上,如果在,就SetWindowPos/MoveWindow到另外一个位置
回复
thematrix477 2011-04-27
BOOL CMoveMouseDlg::PreTranslateMessage(MSG* pMsg)
{
// TODO: Add your specialized code here and/or call the base class
CPoint ptMouse;
if(pMsg->message == WM_MOUSEMOVE)
{
GetCursorPos(&ptMouse);
ScreenToClient(&ptMouse);
char pcTemp[10] = {0};
_itoa_s(ptMouse.x, pcTemp, 10);
OutputDebugString(((std::string)"\nx:" + (std::string)pcTemp).c_str());
_itoa_s(ptMouse.y, pcTemp, 10);
OutputDebugString(((std::string)" y:" + (std::string)pcTemp).c_str());

if (ptMouse.x >= m_rect.left && ptMouse.x <= m_rect.right
&& ptMouse.y >= m_rect.top && ptMouse.y <= m_rect.bottom)
{
int iWidth = m_rect.right - m_rect.left;
int iHeight = m_rect.bottom - m_rect.top;
CRect rectWin;
GetClientRect(&rectWin);
if (m_blIsLeftTop)
{
m_rect.bottom = rectWin.bottom;
m_rect.right = rectWin.right;
m_rect.top = m_rect.bottom - iHeight;
m_rect.left = m_rect.right - iWidth;
m_btnTest.MoveWindow(&m_rect);
}
else
{
m_rect.top = rectWin.top;
m_rect.left = rectWin.left;
m_rect.bottom = m_rect.top + iHeight;
m_rect.right = m_rect.left + iWidth;
m_btnTest.MoveWindow(&m_rect);
}
m_blIsLeftTop = !m_blIsLeftTop;

}
}
return CDialog::PreTranslateMessage(pMsg);
}
回复
Liang4 2011-04-27
写一个 CBtn类吧
.h文件
class CBtn: public CButton
{
public:
BOOL m_bOver;
BOOL m_bTracking;
protected:
//{{AFX_MSG(CBtn)
afx_msg void OnMouseMove(UINT nFlags, CPoint point);
afx_msg LRESULT OnMouseLeave(WPARAM wParam, LPARAM lParam);
afx_msg LRESULT OnMouseHover(WPARAM wParam, LPARAM lParam);
//}}AFX_MSG

DECLARE_MESSAGE_MAP()
}

.cpp

CBtn::CBtn()
{
m_bTracking = FALSE;
m_bOver = FALSE;
}

CBtn::~CBtn()
{
}


BEGIN_MESSAGE_MAP(CBtn, CButton)
//{{AFX_MSG_MAP(CBtn)
ON_WM_MOUSEMOVE()
ON_MESSAGE(WM_MOUSELEAVE, OnMouseLeave)
ON_MESSAGE(WM_MOUSEHOVER, OnMouseHover)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CBtn message handlers
void CBtn::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
if (!m_bTracking)
{
ShowWindow(SW_HIDE);
TRACKMOUSEEVENT tme;
tme.cbSize = sizeof(tme);
tme.hwndTrack = m_hWnd;
tme.dwFlags = TME_LEAVE | TME_HOVER;
tme.dwHoverTime = 1;
m_bTracking = _TrackMouseEvent(&tme);
}

CButton::OnMouseMove(nFlags, point);
}


LRESULT CBtn::OnMouseLeave(WPARAM wParam, LPARAM lParam)
{
m_bOver = FALSE;
m_bTracking = FALSE;
ShowWindow(SW_SHOW);
InvalidateRect(NULL, FALSE);
return 0;
}

LRESULT CBtn::OnMouseHover(WPARAM wParam, LPARAM lParam)
{
m_bOver = TRUE;
InvalidateRect(NULL);
return 0;
}
回复
Dreadnought 2011-04-27
SetWindowPos / MoveWindow 移动也可以
回复
xuayn312 2011-04-27
对话框上面放2个按钮,然后在鼠标移动里面写上
void OnMouseMove(UINT nFlages, CPoint point)
{
ShowWindow(SW_HIDE);
m_pBtn->ShowWindow(SW_SHOW);
CButton::OnMouseMove(UINT nFlages, CPoint point);
}

如果还是不清楚去看下孙鑫写的那本VC++深入详解带源码
回复
HowToP2p 2011-04-27
这不就是孙鑫那个程序嘛?
回复
相关推荐
发帖
界面
创建于2007-09-28

1.5w+

社区成员

VC/MFC 界面
申请成为版主
帖子事件
创建了帖子
2011-04-27 10:50
社区公告
暂无公告