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

a1003671336 2011-04-27 10:50:23
怎么用vc6.0编写一个这样的程序:创建一个窗口和一个按钮,当鼠标移动到按钮时按钮消失并在窗口另一个地方出现?
可以的话给出代码 感激~~
...全文
104 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
不二星空 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
  • 打赏
  • 举报
回复
这不就是孙鑫那个程序嘛?

15,979

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 界面
社区管理员
  • 界面
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧