wRect(&rc);
rc.right-=rc.left;//width
rc.bottom-=rc.top;//height
rc.top=0;
rc.left=0;
m_bmpBrush.UnrealizeObject();
CBrush* OldBrush=dc.SelectObject(&m_bmpBrush);
//画底部阴影
dc.PatBlt(rc.left+SPOPUP_SHADOWWIDTH,rc.bottom-SPOPUP_SHADOWHEIGHT, rc.right-
SPOPUP_SHADOWWIDTH,SPOPUP_SHADOWHEIGHT,PATCOPY);
//画右边阴影
dc.PatBlt(rc.right-SPOPUP_SHADOWWIDTH,rc.top+SPOPUP_SHADOWHEIGHT, SPOPUP_SHADOWWIDTH,
rc.bottom,PATCOPY);
dc.SelectObject(OldBrush); //restore old brush
CBrush* pBrush=CBrush::FromHandle(GetSysColorBrush(COLOR_WINDOWFRAME));
rc.right-=SPOPUP_SHADOWWIDTH;
rc.bottom-=SPOPUP_SHADOWHEIGHT;
dc.FrameRect(rc,pBrush);//画边框
// Do not call CWnd::OnNcPaint() for painting messages
}
void CShadowWnd::OnPaint()
{
CPaintDC dc(this); // device context for painting
// TODO: Add your message handler code here
CRect rect;
GetClientRect(&rect);
rect.left+=5;
rect.top+=5;
rect.right-=SPOPUP_SHADOWWIDTH;
rect.bottom-=SPOPUP_SHADOWHEIGHT;
dc.SetTextColor(RGB(0,0,255));//设置显示文本颜色
dc.DrawText(m_sShowText,rect,DT_WORDBREAK|DT_NOPREFIX);
// Do not call CWnd::OnPaint() for painting messages
}
void CShadowWnd::ShowReadOnlyText(CString sText)
{
m_sShowText=sText; //存入显示字符串
CDC dc;
dc.CreateDC("DISPLAY",NULL,NULL,NULL); //创建一个显示设备描述表
dc.SelectObject(GetStockObject(SYSTEM_FONT)); //选择字体到设备描述表
CRect rect(0,0,MAXWIDTH,0);
//获得待显示的字符串 sText 的实际高度和宽度
dc.DrawText(sText,rect,DT_WORDBREAK|DT_CENTER|DT_CALCRECT|DT_NOPREFIX);
//为矩形留些余量
rect.right+=3*SPOPUP_SHADOWWIDTH;
rect.bottom+=3*SPOPUP_SHADOWHEIGHT;
this->Create(rect,0);//创建窗口
this->ShowWindow(SW_SHOW); //显示窗口
this->UpdateWindow(); //立刻更新窗口
//进入消息循环,获取全部消息,控制整个系统
MSG Msg;
BOOL bDone;
SetCapture();
bDone=FALSE;
while(!bDone)
{
if(PeekMessage(&Msg,NULL,0,0,PM_REMOVE))
if(Msg.message==WM_KEYDOWN||Msg.message==WM_SYSKEYDOWN||
Msg.message==WM_LBUTTONDOWN||Msg.message==WM_RBUTTONDOWN)
bDone=TRUE;
else
{
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
}
ReleaseCapture();
DestroyWindow();
}
int CShadowWnd::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CWnd::OnCreate(lpCreateStruct) == -1)
return -1;
// TODO: Add your specialized creation code here
CenterWindow();
return 0;
}
使用方法:将该类增加到一个项目文件中;在你欲使用函数的类(一般为视类或框架窗口类)中增加一个成员变量(如:CshadowWnd m_ShadowWnd),当需要使用带阴影的弹出窗口显示信息时,调用成员函数(如:m_ShadowWnd.ShowText(String sText))即可,无须考虑其实现细节。
程序在Visual C++ 6.0环境下编译通过。