一個很COOL的對話框彈出效果
發表于:2007-07-14來源:作者:點擊數:
標簽:
內容: //1.在實現文件中的include之后加入一個輔助函數 void WINAPI DrawWireRects(LPRECT lprcFrom, LPRECT lprcTo, UINT nMilliSecSpeed) { const int nNumSteps = 10; GdiFlush(); Sleep(50);// Let the desktop window sort itself out // if hwnd is n
內容:
//1.在實現文件中的include之后加入一個輔助函數
void WINAPI DrawWireRects(LPRECT lprcFrom, LPRECT lprcTo, UINT nMilliSecSpeed)
{
const int nNumSteps = 10;
GdiFlush();
Sleep(50); // Let the desktop window sort itself out
// if hwnd is null - "you have the CON".
HDC hDC = ::GetDC(NULL);
// Pen size, urmmm not too thick
HPEN hPen = ::CreatePen(PS_SOLID, 2, RGB(0,0,0));
int nMode = ::SetROP2(hDC, R2_NOT);
HPEN hOldPen = (HPEN) ::SelectObject(hDC, hPen);
for (int i = 0; i < nNumSteps; i++)
{
double dFraction = (double) i / (double) nNumSteps;
RECT transition;
transition.left = lprcFrom->left + (int)((lprcTo->left - lprcFrom->left) * dFraction);
transition.right = lprcFrom->right + (int)((lprcTo->right - lprcFrom->right) * dFraction);
transition.top = lprcFrom->top + (int)((lprcTo->top - lprcFrom->top) * dFraction);
transition.bottom = lprcFrom->bottom + (int)((lprcTo->bottom - lprcFrom->bottom) * dFraction);
POINT pt[5];
pt[0] = CPoint(transition.left, transition.top);
pt[1] = CPoint(transition.right,transition.top);
pt[2] = CPoint(transition.right,transition.bottom);
pt[3] = CPoint(transition.left, transition.bottom);
pt[4] = CPoint(transition.left, transition.top);
// We use Polyline because we can determine our own pen size
// Draw Sides
::Polyline(hDC,pt,5);
GdiFlush();
Sleep(nMilliSecSpeed);
// UnDraw Sides
::Polyline(hDC,pt,5);
GdiFlush();
}
::SetROP2(hDC, nMode);
::SelectObject(hDC, hOldPen);
::ReleaseDC(NULL,hDC);
}
//2.為About對話框加入:
CRect m_rectFrom;//成員變量
//3.在About的OnCreaet中加入:
if (!m_rectFrom.IsRectEmpty())
{
CRect rectTo(lpCreateStruct->x,lpCreateStruct->y,
lpCreateStruct->x + lpCreateStruct->cx,
lpCreateStruct->y + lpCreateStruct->cy);
DrawWireRects(m_rectFrom, rectTo, 20);
// DrawAnimatedRects(m_hWnd, IDANI_CAPTION, m_rectFrom,rectTo);
// 不要效果時
}
//在About的DestoryWindow上加入:
if (!m_rectFrom.IsRectEmpty())
{
CRect rect;
GetWindowRect(rect);
rect.DeflateRect(2,2);
DrawWireRects(rect, m_rectFrom, 20);
// DrawAnimatedRects(m_hWnd,IDANI_CAPTION, rect, m_rectFrom);
// 不要效果時
}
//激活時用:
CAboutDlg about;
m_btn.GetWindowRect(about.m_rectFrom);
about.DoModal();
______________________________________________________________
//如果要用于主窗口,則將上OnCreate和DestoryWindow改為主窗口的
//變量m_rectFrom也改為主窗口的
//然后在APP類的dlg.DoModal();之前加入:
CRect rc(0,0,1,1);//變出的位置
dlg.m_rectFrom=rc;
原文轉自:http://www.anti-gravitydesign.com