一.問題的提出
在WINDOWS的WINHELPER幫助系統中大量使用一類帶陰影的彈出窗口
二.實現方法的幾個關鍵部分說明如下
要解決怎樣畫非用戶區的問題:當WINDOWS需要創建一個窗口時
void CShadowWnd::ShowText(CString sText)
dc
dc
CRect rect(
//獲得待顯示的字符串 sText 的實際高度和寬度
dc
在帶陰影的彈出窗口顯示之後
//進入消息循環
MSG Msg;
BOOL bDone;
SetCapture();
bDone=FALSE;
while(!bDone)
{
if(PeekMessage(&Msg
if(ssage==WM_KEYDOWN||ssage==WM_SYSKEYDOWN||
ssage==WM_LBUTTONDOWN||ssage==WM_RBUTTONDOWN)
bDone=TRUE;
else
{
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
}
ReleaseCapture();
DestroyWindow();
……
}
//頭文件:
#if !defined(AFX_SHADOWWND_H__B
#define AFX_SHADOWWND_H__B
#if _MSC_VER >=
#pragma once
#endif // _MSC_VER >=
// ShadowWnd
//
/////////////////////////////////////////////////////////////////////////////
// CShadowWnd window
class CShadowWnd : public CWnd
{
// Construction
public:
CShadowWnd();
// Attributes
public:
// Operations
public:
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CShadowWnd)
public:
virtual BOOL Create(const RECT& rect
//}}AFX_VIRTUAL
// Implementation
public:
CString m_sShowText;
void ShowReadOnlyText(CString sText);
CBrush m_bmpBrush;
virtual ~CShadowWnd();
// Generated message map functions
protected:
//{{AFX_MSG(CShadowWnd)
afx_msg void OnNcPaint();
afx_msg void OnPaint();
afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
/////////////////////////////////////////////////////////////////////////////
//{{AFX_INSERT_LOCATION}}
// Microsoft Developer Studio will insert additional declarations immediately before the previous line
#endif // !defined(AFX_SHADOWWND_H__B
//實現文件
}
// ShadowWnd
//
#include
#include
#include
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
//定義常數
static int aPattern[]={
#define SPOPUP_SHADOWWIDTH
#define SPOPUP_SHADOWHEIGHT
#define MAXWIDTH
/////////////////////////////////////////////////////////////////////////////
// CShadowWnd
CShadowWnd::CShadowWnd()
{
CBitmap bmp;
bmp
m_bmpBrush
}
CShadowWnd::~CShadowWnd()
{
}
BEGIN_MESSAGE_MAP(CShadowWnd
//{{AFX_MSG_MAP(CShadowWnd)
ON_WM_NCPAINT()
ON_WM_PAINT()
ON_WM_CREATE()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CShadowWnd message handlers
BOOL CShadowWnd::Create(const RECT& rect
{
// TODO: Add your specialized code here and/or call the base class
const char* pClassName=AfxRegisterWndClass(CS_HREDRAW|CS_VREDRAW);
return CWnd::CreateEx(WS_EX_STATICEDGE
rect
pParentWnd
}
void CShadowWnd::OnNcPaint()
{
// TODO: Add your message handler code here
CWindowDC dc(this);
CRect rc;
GetWindowRect(&rc);
rc
rc
rc
rc
m_bmpBrush
CBrush* OldBrush=dc
//畫底部陰影
dc
rc
//畫右邊陰影
dc
SPOPUP_SHADOWWIDTH
dc
CBrush* pBrush=CBrush::FromHandle(GetSysColorBrush(COLOR_WINDOWFRAME));
rc
rc
dc
// 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
rect
rect
dc
dc
// Do not call CWnd::OnPaint() for painting messages
}
void CShadowWnd::ShowReadOnlyText(CString sText)
{
m_sShowText=sText; //存入顯示字符串
CDC dc;
dc
dc
CRect rect(
//獲得待顯示的字符串 sText 的實際高度和寬度
dc
//為矩形留些余量
rect
rect
this
this
this
//進入消息循環
MSG Msg;
BOOL bDone;
SetCapture();
bDone=FALSE;
while(!bDone)
{
if(PeekMessage(&Msg
if(ssage==WM_KEYDOWN||ssage==WM_SYSKEYDOWN||
ssage==WM_LBUTTONDOWN||ssage==WM_RBUTTONDOWN)
bDone=TRUE;
else
{
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
}
ReleaseCapture();
DestroyWindow();
}
int CShadowWnd::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CWnd::OnCreate(lpCreateStruct) ==
return
// TODO: Add your specialized creation code here
CenterWindow();
return
}
四
本程序在Visual C++
此例也說明了對於WINDOWS 下的程序設計
From:http://tw.wingwit.com/Article/program/net/201311/11375.html