www.gusucode.com > 一个包括树控、Tab的多用途窗体的VC程序-源码程序 > 一个包括树控、Tab的多用途窗体的VC程序-源码程序/code/WindowMagicDlg.cpp
//Download by http://www.NewXing.com // WindowMagicDlg.cpp : implementation file // #include "stdafx.h" #include "TabWnd.h" #include "WindowMagicDlg.h" #include "WindowAnima.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CAboutDlg dialog used for App About ///////////////////////////////////////////////////////////////////////////// // CWindowMagicDlg dialog CWindowMagicDlg::CWindowMagicDlg(CWnd* pParent /*=NULL*/) : CDialog(CWindowMagicDlg::IDD, pParent) { //{{AFX_DATA_INIT(CWindowMagicDlg) // NOTE: the ClassWizard will add member initialization here //}}AFX_DATA_INIT // Note that LoadIcon does not require a subsequent DestroyIcon in Win32 m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); } void CWindowMagicDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CWindowMagicDlg) DDX_Control(pDX, IDC_TEST, m_btnTest); //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CWindowMagicDlg, CDialog) //{{AFX_MSG_MAP(CWindowMagicDlg) ON_WM_SYSCOMMAND() ON_WM_PAINT() ON_WM_QUERYDRAGICON() ON_BN_CLICKED(IDC_Blinds, OnBlinds) ON_BN_CLICKED(IDC_MELT, OnMelt) ON_BN_CLICKED(IDC_SCATTER4, OnScatter4) ON_BN_CLICKED(IDC_SCATTER6, OnScatter6) ON_BN_CLICKED(IDC_SLIDEOUT, OnSlideout) ON_BN_CLICKED(IDC_WIPE, OnWipe) ON_BN_CLICKED(IDC_TEST, OnTest) //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CWindowMagicDlg message handlers BOOL CWindowMagicDlg::OnInitDialog() { CDialog::OnInitDialog(); // Add "About..." menu item to system menu. // IDM_ABOUTBOX must be in the system command range. // ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX); // ASSERT(IDM_ABOUTBOX < 0xF000); /* CMenu* pSysMenu = GetSystemMenu(FALSE); if (pSysMenu != NULL) { CString strAboutMenu; strAboutMenu.LoadString(IDS_ABOUTBOX); if (!strAboutMenu.IsEmpty()) { pSysMenu->AppendMenu(MF_SEPARATOR); pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu); } } */ // Set the icon for this dialog. The framework does this automatically // when the application's main window is not a dialog SetIcon(m_hIcon, TRUE); // Set big icon SetIcon(m_hIcon, FALSE); // Set small icon // TODO: Add extra initialization here return TRUE; // return TRUE unless you set the focus to a control } void CWindowMagicDlg::OnSysCommand(UINT nID, LPARAM lParam) { /* if ((nID & 0xFFF0) == IDM_ABOUTBOX) { CRect myRect; CAboutDlg dlgAbout; // a bit of hacking around to get this working but here it is // get the postion of our window this->GetWindowRect(&myRect); // send the this window's postion to the about box dialog // using are little helper function that we put in dlgAbout.SetDlgXYPos(myRect.left,myRect.top+30); // set this window to be the top most window. We do this because when // the user clicks okay on the about box, for some reason MS Windows // sends the parent window to the bottom of the heap if you call // this->ShowWindow(SW_HIDE) from within the about box dialog this // in turn makes for a messy animation. SetWindowPos(&wndTopMost,NULL,NULL,NULL,NULL,SWP_NOMOVE|SWP_NOSIZE); // show our modal dialog box dlgAbout.DoModal(); // don't leave this window as an always on top window SetWindowPos(&wndNoTopMost,NULL,NULL,NULL,NULL,SWP_NOMOVE|SWP_NOSIZE); // animations are all done, the about box dialog was modal so no one // was any the wiser that our app was temporarily always on top. } else { */ CDialog::OnSysCommand(nID, lParam); // } } // If you add a minimize button to your dialog, you will need the code below // to draw the icon. For MFC applications using the document/view model, // this is automatically done for you by the framework. void CWindowMagicDlg::OnPaint() { if (IsIconic()) { CPaintDC dc(this); // device context for painting SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0); // Center icon in client rectangle int cxIcon = GetSystemMetrics(SM_CXICON); int cyIcon = GetSystemMetrics(SM_CYICON); CRect rect; GetClientRect(&rect); int x = (rect.Width() - cxIcon + 1) / 2; int y = (rect.Height() - cyIcon + 1) / 2; // Draw the icon dc.DrawIcon(x, y, m_hIcon); } else { CDialog::OnPaint(); } } // The system calls this to obtain the cursor to display while the user drags // the minimized window. HCURSOR CWindowMagicDlg::OnQueryDragIcon() { return (HCURSOR) m_hIcon; } void CWindowMagicDlg::OnBlinds() { CWindowAnima wa; // sets the window for animation to be this dialog window wa.SetWindow(this); // Blind the window into invisibility using hoizontal blinds wa.Blind(WA_HORZ); Sleep(1000); // Blind the window into visibility using the default // vertical blinds wa.UnBlind(); } void CWindowMagicDlg::OnMelt() { // set the window for animation and specify that it should // not draw over the task bar CWindowAnima wa(this, WA_KEEP_TASKBAR_ONTOP); // melt the window to the left side of the screen, using 6 segments and // stagger each segment 80 pixels wa.Melt(WA_LEFT,6,80); // wait 3 secs Sleep(3000); // move the window to a new position wa.MoveWindowPosition(600,400); // Unmelt the window using the default (WA_AUTO) which unmelts the window // from the side of the screen closest to the top-left corner of the // window wa.UnMelt(); } void CWindowMagicDlg::OnScatter4() { CWindowAnima wa(this); // scatter each of the four segments 90 pixels from the center point // of the window at a rate of 10 pixels per loop wa.Scatter4(90,10); // ReAssemble the window using four segments and the default speed wa.ReAssemble4(); } void CWindowMagicDlg::OnScatter6() { CWindowAnima wa(this); // scatter each of the six segments 90 pixels from the center point // of the window at a rate of 10 pixels per loop wa.Scatter6(90,10); Sleep(500); // ReAssemble the window using six segments and the default speed wa.ReAssemble6(); } void CWindowMagicDlg::OnSlideout() { // create the animation object but specify that // it should not draw over the task bar CWindowAnima wa(this,WA_KEEP_TASKBAR_ONTOP); // slide the window out of view wa.SlideVanish(); // sleep for three seconds Sleep(3000); // skip window capture and do not restore window nor image behind the // window when a "restoring" animation is performed wa.FlagSet(WA_WND_SKIPCAPTURE|WA_WND_SKIPRESTORE); // replace the window with the image with resource ID "IDB_HOUSE" wa.ReplaceWindowImage(IDB_HOUSE); // slide our window into view (except) now it's the image IDB_HOUSE // also don't restore the window until we're specifically told to. wa.SlideAppear(); // wait 2 secs Sleep(2000); // called like this, Restores the window irrespective of the // WA_WND_SKIPRESTORE flag. wa.RestoreWindow(); } void CWindowMagicDlg::OnWipe() { CWindowAnima wa(this); // wipe the window out using a random (default) direction wa.Wipe(); // unwipe the window out using a random (default) direction wa.UnWipe(); } void CWindowMagicDlg::OnTest() { CWindowAnima wa; // set the button as the window to be animated wa.SetWindow(&m_btnTest); // explode the button into six pieces wa.Scatter6(); }