⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 progresswnd.cpp

📁 3D reconstruction, medical image processing from colons, using intel image processing for based clas
💻 CPP
📖 第 1 页 / 共 2 页
字号:
// ProgressWnd.cpp : implementation file//// Written by Chris Maunder (chrismaunder@codeguru.com)// Copyright 1998.//// RxProgressWnd is a drop-in popup progress window for use in// programs that a time consuming. Check out the header file// or the accompanying HTML doc file for details.//// This code may be used in compiled form in any way you desire. This// file may be redistributed by any means PROVIDING it is not sold for// profit without the authors written consent, and providing that this// notice and the authors name is included. If the source code in // this file is used in any commercial application then an email to// the me would be nice.//// This file is provided "as is" with no expressed or implied warranty.// The author accepts no liability if it causes any damage to your// computer, causes your pet cat to fall ill, increases baldness or// makes you car start emitting strange noises when you start it up.//// Expect bugs.// // Please use and enjoy. Please let me know of any bugs/mods/improvements // that you have found/implemented and I will fix/incorporate them into this// file. //// Updated May 18 1998 - added PeekAndPump function to allow modal operation,//                       with optional "Cancel on ESC" (Michael <mbh-ep@post5.tele.dk>)//         Nov 27 1998 - Removed modal stuff from PeekAndPump//         Dec 18 1998 - added WS_EX_TOPMOST to the creation flag#include "stdafx.h"#include "ProgressWnd.h"#include "fusionglobal.h"//#include "PloutosCommon3d.h"#ifdef _DEBUG#define new DEBUG_NEW#undef THIS_FILEstatic char THIS_FILE[] = __FILE__;#endif#define IDC_CANCEL   10#define IDC_TEXT     11#define IDC_PROGRESS 12LPCTSTR szSection = _T("Settings");   LPCTSTR szEntryX  = _T("X");LPCTSTR szEntryY  = _T("Y");/////////////////////////////////////////////////////////////////////////////// RxProgressWndRxProgressWnd::RxProgressWnd(){    CommonConstruct();}RxProgressWnd::RxProgressWnd(CWnd* pParent, LPCTSTR pszTitle, BOOL bSmooth /* = FALSE */)//RxProgressWnd::RxProgressWnd(RxMainFrame* pParent, LPCTSTR pszTitle, BOOL bSmooth /* = FALSE */){    CommonConstruct();    m_strTitle = pszTitle;    Create(pParent, pszTitle, bSmooth);}void RxProgressWnd::CommonConstruct(){    m_nNumTextLines  = 4;    m_nPrevPos       = 0;    m_nPrevPercent   = 0;    m_nStep          = 1;    m_nMinValue      = 0;    m_nMaxValue      = 100;    m_strTitle       = _T("Progress");    m_strCancelLabel = _T(" Cancel ");    m_bCancelled     = FALSE;    m_bModal         = FALSE;    m_bPersistantPosition = TRUE;   // saves and restores position automatically}RxProgressWnd::~RxProgressWnd(){    DestroyWindow();}BOOL RxProgressWnd::Create(CWnd* pParent, LPCTSTR pszTitle, BOOL bSmooth) {    BOOL bSuccess;    // Register window class    CString csClassName = AfxRegisterWndClass(CS_OWNDC|CS_HREDRAW|CS_VREDRAW,                                              ::LoadCursor(NULL, IDC_APPSTARTING),                                              CBrush(::GetSysColor(COLOR_BTNFACE)));    // Get the system window message font for use in the cancel button and text area    NONCLIENTMETRICS ncm;    ncm.cbSize = sizeof(NONCLIENTMETRICS);    VERIFY(SystemParametersInfo(SPI_GETNONCLIENTMETRICS, sizeof(NONCLIENTMETRICS), &ncm, 0));    m_font.CreateFontIndirect(&(ncm.lfMessageFont));     // If no parent supplied then try and get a pointer to it anyway    if (!pParent) {		if (m_bNoCancel)			pParent = AfxGetMainWnd();		else			pParent = RxGetFrameMain();	}    // Create popup window    bSuccess = CreateEx(WS_EX_DLGMODALFRAME,//|WS_EX_TOPMOST, // Extended style                        csClassName,                       // Classname                        pszTitle,                          // Title                        WS_POPUP|WS_BORDER|WS_CAPTION,     // style                        0,0,                               // position - updated soon.                        390,130,                           // Size - updated soon                        pParent->GetSafeHwnd(),            // handle to parent                        0,                                 // No menu                        NULL);        if (!bSuccess) return FALSE;    // Now create the controls    CRect TempRect(0,0,10,10);    bSuccess = m_Text.Create(_T(""), WS_CHILD|WS_VISIBLE|SS_NOPREFIX|SS_LEFTNOWORDWRAP,                             TempRect, this, IDC_TEXT);    if (!bSuccess) return FALSE;    DWORD dwProgressStyle = WS_CHILD|WS_VISIBLE;#ifdef PBS_SMOOTH        if (bSmooth)       dwProgressStyle |= PBS_SMOOTH;#endif    bSuccess = m_wndProgress.Create(dwProgressStyle, TempRect, this, IDC_PROGRESS);    if (!bSuccess) return FALSE;    bSuccess = m_CancelButton.Create(m_strCancelLabel,                                      WS_CHILD|WS_VISIBLE|WS_TABSTOP| BS_PUSHBUTTON,                                      TempRect, this, IDC_CANCEL);    if (!bSuccess) return FALSE;    m_CancelButton.SetFont(&m_font, TRUE);    m_Text.SetFont(&m_font, TRUE);    // Resize the whole thing according to the number of text lines, desired window    // width and current font.    SetWindowSize(m_nNumTextLines, 390);    // Center and show window    if (m_bPersistantPosition)        GetPreviousSettings();    else        CenterWindow();    Show();    return TRUE;}BOOL RxProgressWnd::GoModal(LPCTSTR pszTitle /*=_T("Progress")"*/, BOOL bSmooth /*=FALSE*/, BOOL bNoCancel /*=FALSE*/){	CWnd* pMainWnd;	m_bNoCancel = bNoCancel;	if (bNoCancel)		pMainWnd = AfxGetMainWnd();	else		pMainWnd = RxGetFrameMain();//AfxGetMainWnd();    if (!::IsWindow(m_hWnd) && !Create(pMainWnd, pszTitle, bSmooth))        return FALSE;	this->CenterWindow();    // Disable main window	if (pMainWnd)		pMainWnd->EnableWindow(FALSE);    // Re-enable this window    EnableWindow(TRUE);    m_bModal = TRUE;    return TRUE;}    void RxProgressWnd::SetWindowSize(int nNumTextLines, int nWindowWidth /*=390*/){    int nMargin = 10;    CSize EdgeSize(::GetSystemMetrics(SM_CXEDGE), ::GetSystemMetrics(SM_CYEDGE));    CRect TextRect, CancelRect, ProgressRect;    CSize CancelSize;    // Set up a default size for the text area in case things go wrong    TextRect.SetRect(nMargin,nMargin, nWindowWidth-2*nMargin, 100+2*nMargin);    // Get DrawText to tell us how tall the text area will be (while we're at    // it, we'll see how big the word "Cancel" is)    CDC* pDC = GetDC();    if (pDC) {        CFont* pOldFont = pDC->SelectObject(&m_font);        CString str = _T("M");        for (int i = 0; i < nNumTextLines-1; i++) str += _T("\nM");        pDC->DrawText(str, TextRect, DT_CALCRECT|DT_NOCLIP|DT_NOPREFIX);        TextRect.right = TextRect.left + nWindowWidth;        CancelSize = pDC->GetTextExtent(m_strCancelLabel + _T("  ")) +                                             CSize(EdgeSize.cx*4, EdgeSize.cy*3);        pDC->SelectObject(pOldFont);        ReleaseDC(pDC);    }        // Work out how big (and where) the cancel button should be    CancelRect.SetRect(TextRect.right-CancelSize.cx, TextRect.bottom+nMargin,                        TextRect.right, TextRect.bottom+nMargin + CancelSize.cy);    // Work out how big (and where) the progress control should be    ProgressRect.SetRect(TextRect.left, CancelRect.top + EdgeSize.cy,                          CancelRect.left-nMargin, CancelRect.bottom - EdgeSize.cy);    // Resize the main window to fit the controls    CSize ClientSize(nMargin + TextRect.Width() + nMargin,                     nMargin + TextRect.Height() + nMargin + CancelRect.Height() + nMargin);    CRect WndRect, ClientRect;    GetWindowRect(WndRect); GetClientRect(ClientRect);    WndRect.right = WndRect.left + WndRect.Width()-ClientRect.Width()+ClientSize.cx;    WndRect.bottom = WndRect.top + WndRect.Height()-ClientRect.Height()+ClientSize.cy;    MoveWindow(WndRect);    // Now reposition the controls...    m_wndProgress.MoveWindow(ProgressRect);    m_CancelButton.MoveWindow(CancelRect);    m_Text.MoveWindow(TextRect);}    void RxProgressWnd::SetWindowSizeForNoCancel(int nNumTextLines, int nWindowWidth /*=390*/){    int nMargin = 10;    CSize EdgeSize(::GetSystemMetrics(SM_CXEDGE), ::GetSystemMetrics(SM_CYEDGE));    CRect TextRect, CancelRect, ProgressRect;    CSize CancelSize;    // Set up a default size for the text area in case things go wrong    TextRect.SetRect(nMargin,nMargin, nWindowWidth-2*nMargin, 100+2*nMargin);	//TextRect = (10,10,370,120)    	// Get DrawText to tell us how tall the text area will be (while we're at    // it, we'll see how big the word "Cancel" is)    CDC* pDC = GetDC();    if (pDC) {        CFont* pOldFont = pDC->SelectObject(&m_font);        CString str = _T("M");        for (int i = 0; i < nNumTextLines-1; i++) str += _T("\nM");        pDC->DrawText(str, TextRect, DT_CALCRECT|DT_NOCLIP|DT_NOPREFIX);        TextRect.right = TextRect.left + nWindowWidth;        CancelSize = pDC->GetTextExtent(m_strCancelLabel + _T("  ")) + CSize(EdgeSize.cx*4, EdgeSize.cy*3);        pDC->SelectObject(pOldFont);        ReleaseDC(pDC);    }        // Work out how big (and where) the cancel button should be    CancelRect.SetRect(TextRect.right-CancelSize.cx, TextRect.bottom+nMargin,                        TextRect.right, TextRect.bottom+nMargin + CancelSize.cy);    // Work out how big (and where) the progress control should be    ProgressRect.SetRect(TextRect.left, CancelRect.top + EdgeSize.cy,                          TextRect.right-nMargin, CancelRect.bottom - EdgeSize.cy);    // Resize the main window to fit the controls

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -