下面是进度条部分的代码BOOL CProgressWnd::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) pParent = AfxGetMainWnd();
// 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();
{
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)
pParent = AfxGetMainWnd();
// 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;
}