ShadowWnd.cpp
上传用户:wpp2016
上传日期:2010-02-01
资源大小:1250k
文件大小:3k
源码类别:

Telnet服务器

开发平台:

Visual C++

  1. // ShadowWnd.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "ShadowWnd.h"
  5. //#include "anywhere.h"
  6. #ifdef _DEBUG
  7. #define new DEBUG_NEW
  8. #undef THIS_FILE
  9. static char THIS_FILE[] = __FILE__;
  10. #endif
  11. /////////////////////////////////////////////////////////////////////////////
  12. // CShadowWnd
  13. static int aPattern[]={0xAA,0x55,0xAA,0x55,0xAA,0x55,0xAA,0x55};
  14. #define SPOPUP_SHADOWWIDTH 10
  15. #define SPOPUP_SHADOWHEIGHT 13
  16. #define MAXWIDTH 400
  17. CShadowWnd::CShadowWnd()
  18. {
  19. CBitmap bmp;
  20. bmp.CreateBitmap(8,8,1,1,(void*)aPattern);
  21. m_bmpBrush.CreatePatternBrush(&bmp);
  22. }
  23. CShadowWnd::~CShadowWnd()
  24. {
  25. }
  26. BEGIN_MESSAGE_MAP(CShadowWnd, CWnd)
  27. //{{AFX_MSG_MAP(CShadowWnd)
  28. ON_WM_NCPAINT()
  29. ON_WM_PAINT()
  30. ON_WM_CREATE()
  31. //}}AFX_MSG_MAP
  32. END_MESSAGE_MAP()
  33. /////////////////////////////////////////////////////////////////////////////
  34. // CShadowWnd message handlers
  35. void CShadowWnd::OnNcPaint() 
  36. {
  37.   CWindowDC dc(this);
  38.   CRect rc;
  39.   GetWindowRect(&rc);
  40.   rc.right-=rc.left;
  41.   rc.bottom-=rc.top;
  42.   rc.top=0;
  43.   rc.left=0;
  44.   m_bmpBrush.UnrealizeObject();
  45.   CBrush* OldBrush=dc.SelectObject(&m_bmpBrush);
  46.   dc.PatBlt(rc.left+SPOPUP_SHADOWWIDTH,rc.bottom-SPOPUP_SHADOWHEIGHT,rc.right-SPOPUP_SHADOWWIDTH,SPOPUP_SHADOWHEIGHT,PATCOPY);
  47.   dc.PatBlt(rc.right-SPOPUP_SHADOWWIDTH,rc.top+SPOPUP_SHADOWHEIGHT,SPOPUP_SHADOWWIDTH,rc.bottom,PATCOPY);
  48.   dc.SelectObject(OldBrush);
  49.   CBrush *pBrush=CBrush::FromHandle(GetSysColorBrush(COLOR_WINDOWFRAME));
  50.   rc.right-=SPOPUP_SHADOWWIDTH;
  51.   rc.bottom-=SPOPUP_SHADOWHEIGHT;
  52.   dc.FrameRect(rc,pBrush);
  53. // Do not call CWnd::OnNcPaint() for painting messages
  54. }
  55. void CShadowWnd::OnPaint() 
  56. {
  57. CPaintDC dc(this); // device context for painting
  58.    CRect rect;
  59.    GetClientRect(&rect);
  60.    rect.left+=5;
  61.    rect.top+=5;
  62.    rect.right-=SPOPUP_SHADOWWIDTH;
  63.    rect.bottom-=SPOPUP_SHADOWHEIGHT;
  64.    dc.SetTextColor(RGB(0,0,255));
  65.    dc.DrawText(m_sShowText,rect,DT_WORDBREAK|DT_NOPREFIX);
  66. // Do not call CWnd::OnPaint() for painting messages
  67. }
  68. BOOL CShadowWnd::Create(const RECT &rect, CWnd *pParentWnd)
  69. {
  70. const char *pClassName=AfxRegisterWndClass(CS_HREDRAW|CS_VREDRAW);
  71.   
  72.   return CWnd::CreateEx(WS_EX_STATICEDGE,pClassName,"Shadow window",WS_POPUP,rect.left,rect.top,rect.right,rect.bottom,pParentWnd->GetSafeHwnd(),0,NULL);
  73. }
  74. void CShadowWnd::ShowReadOnlyText(CString sText)
  75. {
  76. m_sShowText=sText;
  77. CDC dc;
  78. dc.CreateDC("DISPLAY",NULL,NULL,NULL);
  79. dc.SelectObject(GetStockObject(SYSTEM_FONT));
  80. CRect rect(0,0,MAXWIDTH,0);
  81. dc.DrawText(sText,rect,DT_WORDBREAK|DT_CENTER|DT_CALCRECT|DT_NOPREFIX);
  82. rect.right+=3*SPOPUP_SHADOWWIDTH;
  83. rect.bottom+=3*SPOPUP_SHADOWHEIGHT;
  84. this->Create(rect,0);
  85. this->ShowWindow(SW_SHOW);
  86. this->UpdateWindow();
  87. MSG Msg;
  88. BOOL bDone;
  89. SetCapture();
  90. bDone=FALSE;
  91. while(!bDone)
  92. {
  93. if(PeekMessage(&Msg,NULL,0,0,PM_REMOVE))
  94. if(Msg.message==WM_KEYDOWN||Msg.message==WM_SYSKEYDOWN||Msg.message==WM_LBUTTONDOWN||Msg.message==WM_RBUTTONDOWN)
  95. bDone=TRUE;
  96. else
  97. {
  98. TranslateMessage(&Msg);
  99. DispatchMessage(&Msg);
  100. }
  101. }
  102. ReleaseCapture();
  103. DestroyWindow();
  104. }
  105. int CShadowWnd::OnCreate(LPCREATESTRUCT lpCreateStruct) 
  106. {
  107. if (CWnd::OnCreate(lpCreateStruct) == -1)
  108. return -1;
  109.    CenterWindow();
  110. return 0;
  111. }