在编程开发的我遇到如下问题,我想象MSN哪样在屏幕右下角慢慢弹出一个窗口,而不会得到当前焦点。
因为如果得到焦点的话,会让我正在工作的窗口失去焦点,很烦人的。
我采用了以下代码实现,但还是会得到焦点。SetWindowPos(&CWnd::wndTopMost, m_pt.x, m_pt.y, m_sz.cx, m_sz.cy, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOOWNERZORDER); 请教,如何让最顶层窗口移动不得到焦点?换句话说:最顶层窗口移动时,不会影正在工作的窗口。像MSN弹出式窗口一样。
谢谢。
因为如果得到焦点的话,会让我正在工作的窗口失去焦点,很烦人的。
我采用了以下代码实现,但还是会得到焦点。SetWindowPos(&CWnd::wndTopMost, m_pt.x, m_pt.y, m_sz.cx, m_sz.cy, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOOWNERZORDER); 请教,如何让最顶层窗口移动不得到焦点?换句话说:最顶层窗口移动时,不会影正在工作的窗口。像MSN弹出式窗口一样。
谢谢。
解决方案 »
- vs2012中新建的mfc工程直接运行报错
- 一个exe文件如何嵌入到vc++对话框中 运行一个vc++界面后,一个已经存在的exe文件如何嵌入到界面上
- 请问,像QQ这样的漂亮界面,是如何做的?也是用的MFC框架吗?
- 多线程调试的问题
- 如何在程序结束时播放一段动画再结束!!!!!
- 在网卡驱动上开发应用程序的问题,快来看看!
- vc怎样对modem操作?
- 如何把CString ps:"12345“ 转成 int
- 通过打开按扭在列表框显示一副图,该怎么办啊?
- 我的可用分只有21分了,怎样才能提高可用分呢?想给给分都没分了啊!!
- 请问怎样将外部的应用程序嵌入到VC开发环境的工具条中?即每次打开VC时都可以找到该功能。需要用到哪方面的知识?请说明大致的思路,谢谢
- CStatic的Style如何动态更改
#define __MY_TOOL_TIPS_H__class MyToolTips: public CWnd
{
DECLARE_DYNAMIC(MyToolTips);
public:
MyToolTips();
~MyToolTips(); //Create ToolTips Window
BOOL Create(CWnd* pParentWnd);
//Set ToolTips Text
void SetText(const CString &strText);
//Set ToolTips Text
void SetText(LPCSTR lpcszText);
//Show the ToolTips Window
BOOL Show(const CPoint &pointCur);
void MoveToolTipWnd(const CPoint &pointCur);
//Close the ToolTips Window
void Close(); //{{AFX_VIRTUAL(MyToolTips)
public:
virtual BOOL PreTranslateMessage(MSG* pMsg);
//}}AFX_VIRTUALprotected:
CString m_strText; //ToolTips Text
CWnd *m_pParentWnd; //Parent Window
BOOL m_bShowStatus; //Show Status
CPoint m_ptCurrent; //Current point where tooltip is displayed
CFont m_font; //Font
UINT m_nMaxWidth; //Max Width of ToolTips Window
//Get the Text of Current Line of ToolTips Text
BOOL GetLine(CString strSource, CString &strDest, int nLineNumber);
//Display the ToolTips Window
void DisplayToolTip(const CPoint &pointCur);
//{{AFX_MSG(MyToolTips)
afx_msg void OnPaint();
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};#endif
#include "stdafx.h"
#include "MyToolTips.h"#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endifMyToolTips::MyToolTips()
{
m_strText = "";
m_pParentWnd = NULL;
m_bShowStatus = FALSE;
m_nMaxWidth = 0;
}MyToolTips::~MyToolTips()
{
}IMPLEMENT_DYNAMIC(MyToolTips, CWnd);
BEGIN_MESSAGE_MAP(MyToolTips, CWnd)
//{{AFX_MSG_MAP(MyToolTips)
ON_WM_PAINT()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()//Create ToolTips Window
BOOL MyToolTips::Create(CWnd* pParentWnd)
{
ASSERT(this != NULL);
ASSERT(pParentWnd != NULL); m_pParentWnd = pParentWnd;
//Create Font
if(!m_font.CreatePointFont(100, "宋体"))
m_font.CreatePointFont(100, "MS Sans Serif"); //Initial Window size. Will be dynamically changed later.
CRect rectInitialSize(0,0,0,0); return CreateEx(WS_EX_TOOLWINDOW , NULL, NULL, WS_POPUP | WS_CHILD | WS_CLIPSIBLINGS,
rectInitialSize, pParentWnd, NULL, NULL);
}//Set ToolTips Text
void MyToolTips::SetText(const CString &strText)
{
ASSERT(this != NULL);
m_strText = strText;
m_strText.TrimRight();
}//Set ToolTips Text
void MyToolTips::SetText(LPCSTR lpcszText)
{
ASSERT(this != NULL);
m_strText = lpcszText;
m_strText.TrimRight();
}//Show the ToolTips
//pointCur specifies current mouse position and it is in
//client coordinates of parent window(Not in screen coordinates).
BOOL MyToolTips::Show(const CPoint &pointCur)
{
ASSERT(this != NULL);
ASSERT(m_hWnd != NULL); if(m_strText.IsEmpty() || m_bShowStatus)
return FALSE; m_ptCurrent = pointCur;
m_bShowStatus = TRUE;
//Show the ToolTips
DisplayToolTip(m_ptCurrent);
return TRUE;
}//Close the ToolTips
void MyToolTips::Close()
{
ASSERT(this != NULL);
ASSERT(m_hWnd != NULL); //Hide the ToolTips
ShowWindow(SW_HIDE);
m_bShowStatus = FALSE;
}void MyToolTips::OnPaint()
{
CPaintDC dc(this); DisplayToolTip(m_ptCurrent);
}//Display the ToolTips Window
void MyToolTips::DisplayToolTip(const CPoint& rCurrentPoint)
{
CDC *pDC = GetDC();
int x = 0;
int nLargest = 0;
CString strLine;
CSize size; CBrush brushToolTip(GetSysColor(COLOR_INFOBK));
CPen penBlack(PS_SOLID, 0, COLORREF(RGB(0, 0, 0))); CFont *pOldFont = pDC->SelectObject(&m_font);
while(GetLine(m_strText, strLine, x))
{
size = pDC->GetTextExtent(strLine);
pDC->LPtoDP(&size);
if(size.cx > nLargest)
nLargest = size.cx;
x++;
}
int nHeight = size.cy;
size.cx = nLargest;
size.cy *= x;
//Form tooltip rectangle
CRect rectToolTip(rCurrentPoint.x,
rCurrentPoint.y,
rCurrentPoint.x+size.cx+7,
rCurrentPoint.y+size.cy+2); //Draw Tooltip Rect and Text
pDC->SetBkMode(TRANSPARENT);
CBrush *pOldBrush = pDC->SelectObject(&brushToolTip); //Select thick black pen
CPen* pOldPen = pDC->SelectObject(&penBlack); //Draw rectangle filled with COLOR_INFOBK
pDC->Rectangle(0, 0, rectToolTip.Width(), rectToolTip.Height()); //Draw tooltip text
//Tool Tip color set in control panel settings
pDC->SetTextColor( GetSysColor(COLOR_INFOTEXT));
pDC->SetTextAlign(TA_LEFT);
x = 0;
while(GetLine(m_strText, strLine, x))
{
pDC->TextOut(3, 1 + (x * nHeight), strLine);
x++;
} CRect rectWnd = rectToolTip;
//Convert from client to screen coordinates
m_pParentWnd->ClientToScreen(rectWnd);
CPoint ptToolTipLeft = rectWnd.TopLeft(); //Now display tooltip
SetWindowPos(&wndTop,
ptToolTipLeft.x+1,
ptToolTipLeft.y+1,
rectWnd.Width(),
rectWnd.Height(),
SWP_SHOWWINDOW|SWP_NOOWNERZORDER|SWP_NOACTIVATE); //put back old objects
pDC->SelectObject(pOldBrush);
pDC->SelectObject(pOldPen);
pDC->SelectObject(pOldFont); ReleaseDC(pDC);
}//Get the Text of Current Line of ToolTips Text
BOOL MyToolTips::GetLine(CString strSource, CString &strDest, int nLineNumber)
{
int x = 0;
int nStart = 0; while(x < nLineNumber)
{
nStart = strSource.Find('\n', nStart) + 1; if(nStart == 0)
{
strDest = strSource;
return false;
}
x++;
} //Go from the offset, to the next \n or end of string
int nEnd = strSource.Find('\n', nStart);
if(nEnd == -1)
nEnd = strSource.GetLength(); strDest = strSource.Mid(nStart, nEnd - nStart);
return true;
}void MyToolTips::MoveToolTipWnd(const CPoint &pointCur)
{
CRect rectWindow;
this->GetWindowRect(rectWindow); rectWindow.right = pointCur.x + rectWindow.Width();
rectWindow.bottom = pointCur.y + rectWindow.Height();
rectWindow.left = pointCur.x;
rectWindow.top = pointCur.y;
m_pParentWnd->ClientToScreen(rectWindow);
this->MoveWindow(rectWindow);
}BOOL MyToolTips::PreTranslateMessage(MSG* pMsg)
{
if(pMsg->message >= WM_MOUSEFIRST
&& pMsg->message <= WM_MOUSELAST)
{
if(pMsg->message == WM_LBUTTONDOWN
|| pMsg->message == WM_LBUTTONDBLCLK
|| pMsg->message == WM_RBUTTONDOWN
|| pMsg->message == WM_MBUTTONDOWN)
this->Close();
CPoint pt(LOWORD(pMsg->lParam), HIWORD(pMsg->lParam));
this->ClientToScreen(&pt);
this->m_pParentWnd->ScreenToClient(&pt);
return m_pParentWnd->SendMessage(pMsg->message, pMsg->wParam, (pt.y << 16) + pt.x);
}
return CWnd::PreTranslateMessage(pMsg);
}