ShadowWnd.cpp
资源名称:(vc).rar [点击查看]
上传用户:wpp2016
上传日期:2010-02-01
资源大小:1250k
文件大小:3k
源码类别:
Telnet服务器
开发平台:
Visual C++
- // ShadowWnd.cpp : implementation file
- //
- #include "stdafx.h"
- #include "ShadowWnd.h"
- //#include "anywhere.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CShadowWnd
- static int aPattern[]={0xAA,0x55,0xAA,0x55,0xAA,0x55,0xAA,0x55};
- #define SPOPUP_SHADOWWIDTH 10
- #define SPOPUP_SHADOWHEIGHT 13
- #define MAXWIDTH 400
- CShadowWnd::CShadowWnd()
- {
- CBitmap bmp;
- bmp.CreateBitmap(8,8,1,1,(void*)aPattern);
- m_bmpBrush.CreatePatternBrush(&bmp);
- }
- CShadowWnd::~CShadowWnd()
- {
- }
- BEGIN_MESSAGE_MAP(CShadowWnd, CWnd)
- //{{AFX_MSG_MAP(CShadowWnd)
- ON_WM_NCPAINT()
- ON_WM_PAINT()
- ON_WM_CREATE()
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CShadowWnd message handlers
- void CShadowWnd::OnNcPaint()
- {
- CWindowDC dc(this);
- CRect rc;
- GetWindowRect(&rc);
- rc.right-=rc.left;
- rc.bottom-=rc.top;
- 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);
- 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
- 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
- }
- BOOL CShadowWnd::Create(const RECT &rect, CWnd *pParentWnd)
- {
- const char *pClassName=AfxRegisterWndClass(CS_HREDRAW|CS_VREDRAW);
- return CWnd::CreateEx(WS_EX_STATICEDGE,pClassName,"Shadow window",WS_POPUP,rect.left,rect.top,rect.right,rect.bottom,pParentWnd->GetSafeHwnd(),0,NULL);
- }
- 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);
- 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;
- CenterWindow();
- return 0;
- }