- UID
- 11009
- 积分
- 0
- 精华
- 贡献
-
- 威望
-
- 活跃度
-
- D豆
-
- 在线时间
- 小时
- 注册时间
- 2002-10-10
- 最后登录
- 1970-1-1
|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
CPopupTipWnd::CPopupTipWnd()
{
RegisterWindowClass();
}
CPopupTipWnd::~CPopupTipWnd()
{
}
BEGIN_MESSAGE_MAP(CPopupTipWnd, CWnd)
//{{AFX_MSG_MAP(CPopupTipWnd)
// NOTE - the ClassWizard will add and remove mapping macros here.
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CPopupTipWnd message handlers
BOOL CPopupTipWnd::Create(CWnd *pParentWnd)
{
_ASSERTE(pParentWnd);
m_pParentWnd = pParentWnd;
DWORD dwStyle = WS_BORDER | WS_POPUP;
DWORD dwExStyle = WS_EX_TOOLWINDOW | WS_EX_TOPMOST;
BOOL bCreated = CreateEx(dwExStyle,
"CPopupTipWnd",
NULL,
dwStyle,
0, 0, 0, 0,
NULL, NULL, NULL);
return bCreated;
}
bool CPopupTipWnd::RegisterWindowClass()
{
WNDCLASS wndcls = {0};
wndcls.style = CS_SAVEBITS | CS_DBLCLKS | CS_HREDRAW | CS_VREDRAW;
wndcls.lpfnWndProc = ::DefWindowProc;
wndcls.hCursor = (HCURSOR)::LoadImage(NULL, IDC_ARROW, IMAGE_CURSOR, 0, 0, LR_DEFAULTSIZE);
wndcls.hbrBackground = (HBRUSH)(COLOR_INFOBK + 1);
wndcls.lpszClassName = "CPopupTipWnd";
if(!::RegisterClass(&wndcls))
{
// AfxThrowResourceException();
return false;
}
return true;
}
void CPopupTipWnd::ShowPopupWindow(CString strText, CPoint point, CRect rect)
{
// If there is no password, instead hide the window and be done with it
if(strText.IsEmpty())
{
HidePopupWindow();
return;
}
CClientDC dc(this);
// Use same font as parent window
CFont *pOldFont = dc.SelectObject(m_pParentWnd->GetFont());
// Calculate the window size.
CSize sizeText = dc.GetTextExtent(strText);
CSize sizeWindow;
sizeWindow.cx = sizeText.cx + 2 * 3;
sizeWindow.cy = sizeText.cy + 2 * 3;
// Calculate window rectangle position on screen
CRect rectWindow;
rectWindow.left = rect.left;
rectWindow.right = rectWindow.left + sizeWindow.cx;
rectWindow.top = rect.top - (sizeWindow.cy + 20);
if(rectWindow.top <= 0)
rectWindow.top = rect.bottom + 20;
rectWindow.bottom = rectWindow.top + sizeWindow.cy;
// Display window
SetWindowPos(&wndTop,
rectWindow.left,
rectWindow.top,
rectWindow.Width(),
rectWindow.Height(),
SWP_SHOWWINDOW | SWP_NOACTIVATE);
// Draw information in window
dc.SetBkMode(TRANSPARENT);
dc.DrawText(strText, CRect(0, 0, sizeWindow.cx, sizeWindow.cy), DT_CENTER | DT_VCENTER | DT_SINGLELINE);
dc.SelectObject(pOldFont);
}
void CPopupTipWnd::HidePopupWindow()
{
ShowWindow(SW_HIDE);
} |
|