您的位置:首页 > 其它

一个类似QQ登陆框的EDIT

2005-12-22 20:25 525 查看
网易的登陆框也有这个功能,就是其中显示一串提示字符,当用户把输入焦点定位到EDIT中后,提示信息自动消失,这个类很简单,所以我没有做demo,大家看一下就会用了。
.h文件:
#if !defined(AFX_STEDIT_H__FA85F3FB_68AC_48E7_8108_5A61A09148CE__INCLUDED_)
#define AFX_STEDIT_H__FA85F3FB_68AC_48E7_8108_5A61A09148CE__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
// STEdit.h : header file
//
/////////////////////////////////////////////////////////////////////////////
// CSTEdit window
class CSTEdit : public CEdit
{
// Construction
public:
CSTEdit();
// Attributes
public:
// Operations
public:
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CSTEdit)
protected:
virtual LRESULT DefWindowProc(UINT message, WPARAM wParam, LPARAM lParam);
//}}AFX_VIRTUAL
// Implementation
public:
virtual ~CSTEdit();
// Generated message map functions
protected:
int nSetText;
//{{AFX_MSG(CSTEdit)
afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
afx_msg void OnSetFocus(CWnd* pOldWnd);
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
/////////////////////////////////////////////////////////////////////////////
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
#endif // !defined(AFX_STEDIT_H__FA85F3FB_68AC_48E7_8108_5A61A09148CE__INCLUDED_)
.cpp文件:
// STEdit.cpp : implementation file
//
#include "stdafx.h"
#include "STEdit.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CSTEdit
CSTEdit::CSTEdit()
{
nSetText = 0;
}
CSTEdit::~CSTEdit()
{
}

BEGIN_MESSAGE_MAP(CSTEdit, CEdit)
//{{AFX_MSG_MAP(CSTEdit)
ON_WM_LBUTTONDOWN()
ON_WM_SETFOCUS()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CSTEdit message handlers
LRESULT CSTEdit::DefWindowProc(UINT message, WPARAM wParam, LPARAM lParam)
{
if (nSetText < 2)
if (WM_SETTEXT == message)
nSetText++;
else if (WM_CHAR == message)
nSetText = 2;
return CEdit::DefWindowProc(message, wParam, lParam);
}
void CSTEdit::OnLButtonDown(UINT nFlags, CPoint point)
{
if (1 == nSetText)
SetWindowText("");
CEdit::OnLButtonDown(nFlags, point);
}
void CSTEdit::OnSetFocus(CWnd* pOldWnd)
{
CEdit::OnSetFocus(pOldWnd);
if (1 == nSetText && IsWindowVisible() && pOldWnd && GetParent() == pOldWnd->GetParent())
SetWindowText("");
}
大家自行将其分为.h和.cpp即可,使用的时候,关联一个CSTEdit控制型变量,设置提示信息的时候,用SetWindowText等均可。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐