![]() |
Desktop Development »
Dialogs and Windows »
Dialogs
Intermediate
An Animation-Style Dialog ClassBy =[ Abin ]=CAniDialog : An Animation-Style Dialog Class Derived from CDialog and Using DrawWireRects |
VC6Win2K, WinXP, MFC, Dev
|
|
Advanced Search Add to IE Search |
|
|
|
||||||||||||||||

I've been using Almond and Maunder's DrawWireRects function because
I always like my programs to look cool. That function is great and all, however,
to use it I need to overload OnCreate and OnDestroy functions in
EVERY dialog class which I want it to be effected, there are a few inconvenience
on directly reusing the DrawWireRects function:
OnCreate and OnDestroy functions in every class
and add some other members which are needed to complement the animation effect. Those
will be quite a lot of duplicated code. CMyDialog open from
center and close towards its bottom-right corner, then a few minutes later I
change my mind and want it close towards the system tray... anyway, I should
be able to do those kind of stuff by simply using the DrawWireRects, but quickly I'll find out size of
MyDialog.cpp grows
up rapidly, and so do other dialog classes in that project.
It would be nice if there was an existing class that encapsulates all those necessary stuff,
I could just derive my classes from it and it does all the dirty work for me.
So that's where the CAniDialog class came from.
First of all, the heart and soul of this class is the DrawWireRects function,
which was written by Almond and Maunder, so credits go there. I tried to
leave that function as intact as possible, some small changes were necessary to be done,
however, in order to make it cooperate with other class members well.
The CAniDialog class is derived from CDialog, the
aim of this class is to make using animated dialog boxes as simple as using
the MessageBox function, the only thing that really needed to be
provided by the user is a CPoint object, which specifies where the dialog box should pop up from
and close towards if you are going to use the AS_REFER animation style flag.
All other elements have default values and, in most case, are already optimized and need not be changed.
// construction CAniDialog(UINT nDlgID, CWnd* pParent); CAniDialog(CPoint pt, UINT nDlgID, CWnd* pParent); // operation // access frame number UINT GetFrameNum() const; void SetFrameNum(UINT nFrames); // access animation speed UINT GetAniSpeed() const; void SetAniSpeed(UINT nMillSec); // access the reference point CPoint GetRefPt() const; void SetRefPt(CPoint pt); // access animation styles WORD GetOpenStyle() const; WORD GetCloseStyle() const; void SetAniStyles(WORD wOpenStyle, WORD wCloseStyle); WORD GetDispStyle() const; void SetDispStyle(WORD wDispStyle); // temporarily enable/disable animation void EnableAni(BOOL bEnable = TRUE); // check object status BOOL IsAniValid() const;
Predefined animation style flags:
// animation styles // animate from/to the refer point #define AS_REFER 0 // animate from/to center #define AS_CENTER 1 // animate from/to corners #define AS_TOPLEFT 2 #define AS_TOPRIGHT 3 #define AS_BOTTOMLEFT 4 #define AS_BOTTOMRIGHT 5 // animate from/to sides #define AS_LEFT 6 #define AS_TOP 7 #define AS_RIGHT 8 #define AS_BOTTOM 9 // animate from/to a random point inside of dialog #define AS_RANDOM 10 // define displaying style // call "DrawWireRects" #define DS_WIRE 0 // call "::DrawAnimatedRects" #define DS_CAPTION 1
To use the CAniDialog class, you need to:
CMyDlg and let CDialog be its base class. CDialog with CAniDialog in whole file. CDialog with CAniDialog in whole file. At this point you have changed the base
class of CMyDlg from CDialog into CAniDialog.
CMyDlg class so it looks like this:
// CMyDlg(CWnd* pParent = NULL); // original CMyDlg(CPoint pt, CWnd* pParent = NULL); // now
CMyDlg::CMyDlg(CPoint pt, CWnd* pParent /*=NULL*/) : // CDialog(CMyDlg::IDD, pParent) // original CAniDialog(pt, CMyDlg::IDD, pParent) // now { //{{AFX_DATA_INIT(CDemoPopupDlg) // NOTE: the ClassWizard will add // member initialization here //}}AFX_DATA_INIT }
That's it! Now the CMyDlg class is ready to go.
When you create a CMyDlg object, you need to pass it a CPoint
object which tells the dialog where to pop up from and where to close towards.
// If you are going to use the AS_REFER flag, // you must provide a valid CPoint. // If you are not going to use the AS_REFER flag, // then the value of this CPoint // does not matter at all, in that case, // just give it one so the compiler won't // complain. CPoint pt; // we are going to use the AS_REFER flag so // we need a valid CPoint value. ::GetCursorPos(&pt); // fetch current cursor position CMyDlg dlg(pt); // optional // you can specify animation styles, displaying // styles, animation speed, animation // frame numbers etc. // the dialog will pop up from you cursor dlg.SetAniStyles(AS_REFER, AS_CENTER); // position and close inwards its own center dlg.DoModal(); // watch the animation!
| You must Sign In to use this message board. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
General
News
Question
Answer
Joke
Rant
Admin
|
PermaLink |
Privacy |
Terms of Use
Last Updated: 12 Feb 2002 Editor: Nishant Sivakumar |
Copyright 2002 by =[ Abin ]= Everything else Copyright © CodeProject, 1999-2009 Web22 | Advertise on the Code Project |