/**不规则窗口程序设计----by sword2008
@2008.2.21 刚好元宵节
*/
目标:对话框或者其他窗口控件,利用 函数绘制任意外观的控件或者窗口
int SetWindowRgn(
HWND hWnd,
HRGN hRgn,
BOOL bRedraw
);
hWnd为窗口句柄,
bRedraw为是否重绘
hRgn为外观区域,这个为最重要的,决定整个外观,其包括四大函数
CreateRectRgnIndirect
CreateEllipticRgnIndirect
CreatePolygonRgn
CombineRgn //个人认为比较好用的
用CreateEllipticRgnIndirect做个例子
建立一个空的项目,对话框程序。
OnInitDialog()里面
CRgn MyRgn;
RECT m_rect;
m_rect.left=0;m_rect.top=0;m_rect.right=500;m_rect.bottom=500;
MyRgn.CreateEllipticRgnIndirect(&m_rect);
SetWindowRgn(MyRgn,true);
看看吧!hRgn确定外观的描绘!呵呵!还有其他函数,可以慢慢观看
例子2,用了CombineRgn跟踪轨迹
CDC * pDC = this->GetDC();
CFont rfont,*pOldFont;
rfont.CreatePointFont(500,"隶书");
pOldFont=pDC->SelectObject(&rfont);
CRgn MyRgn;
pDC->BeginPath();
pDC->SetBkMode(TRANSPARENT);
CString stxt = "sword2008";
pDC->SetTextColor(RGB(255,0,0));
pDC->TextOut(0,0,stxt);
pDC->EndPath();
MyRgn.CreateFromPath(pDC);
pDC->SelectObject(pOldFont);
ReleaseDC(pDC);
SetWindowRgn(MyRgn,true);
浮动的IE按钮例子:
IsMouseOn为判断是否移入按钮上
父窗口
void CTest2Dlg::OnMouseMove(UINT nFlags, CPoint point)
{
if(m_b1.IsMouseOn)
{
m_b1.IsMouseOn=false;
m_b1.Invalidate();
}
CDialog::OnMouseMove(nFlags, point);
}
子窗口
CIEBUTTON::CIEBUTTON()
{
IsMouseOn = false;
}
----------
void CIEBUTTON::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
{
CDC ButtonDC;
CBitmap bitmapTrans;
BITMAP bmp;
CDC mem;
CRect rc,rc2;
ButtonDC.Attach(lpDrawItemStruct->hDC);
mem.CreateCompatibleDC(&ButtonDC);
rc=lpDrawItemStruct->rcItem;
rc2=rc;
bitmapTrans.LoadBitmap(IDB_IE);
bitmapTrans.GetBitmap(&bmp);
CBitmap *old = mem.SelectObject(&bitmapTrans);
int x,y;
x=rc.Width()/2 - bmp.bmWidth/2;
y=rc.Height()/2 - bmp.bmHeight/2;
ButtonDC.BitBlt(x,y,rc.right,rc.bottom,&mem,0,0,SRCCOPY);
mem.SelectObject(old);
if(IsMouseOn)
{
rc.top =rc.top+1;rc.bottom =rc.bottom-1;
rc.left=rc.left+1;rc.right =rc.right-1;
ButtonDC.Draw3dRect(&rc2,RGB(255,255,255),RGB(0,0,0));
}
if(lpDrawItemStruct->itemAction &ODA_SELECT)
{
rc2.top =rc.top+1;rc2.bottom =rc.bottom-1;
rc2.left=rc.left+1;rc2.right =rc.right-1;
ButtonDC.Draw3dRect(&rc2,RGB(0,0,0,),RGB(255,255,255));
// ButtonDC.Draw3dRect(&rc2,RGB(255,255,255),RGB(0,0,0));
}
}
void CIEBUTTON::OnMouseMove(UINT nFlags, CPoint point)
{
if(!IsMouseOn)
{
this->IsMouseOn = true;
this->Invalidate();
}
CButton::OnMouseMove(nFlags, point);
}
-------------
void CIEBUTTON::OnMouseMove(UINT nFlags, CPoint point)
{
if(!IsMouseOn)
{
this->IsMouseOn = true;
this->Invalidate();
}
CButton::OnMouseMove(nFlags, point);
}
评论