SkinProgress.cpp
资源名称:MiniCA2.rar [点击查看]
上传用户:dengkfang
上传日期:2008-12-30
资源大小:5233k
文件大小:240k
源码类别:
CA认证
开发平台:
Visual C++
- )
- {
- #ifdef dCSP_DIALOG_PROGRESS
- CRect oRectPane;
- // Init
- // Process + Return
- if(m_poWndProgress == NULL)
- {
- #endif // dCSP_DIALOG_PROGRESS
- // A..... Return the current <m_nSize> value
- return m_nSize;
- #ifdef dCSP_DIALOG_PROGRESS
- }
- else
- {
- // B..... Return the CWnd based pane size
- if(GetTargetRect(&oRectPane))
- {
- #ifdef dCSP_VERTICAL_BAR
- if(m_bVertical == false)
- {
- #endif // dCSP_VERTICAL_BAR
- return oRectPane.Width();
- #ifdef dCSP_VERTICAL_BAR
- }
- else
- {
- return oRectPane.Height();
- }
- #endif // dCSP_VERTICAL_BAR
- }
- else
- {
- return 0;
- }
- }
- #endif // dCSP_DIALOG_PROGRESS
- }
- /*--- START FUNCTION HEADER --------------------------------------------------*/
- /* Name : GetPos */
- /* Role : Get <m_nRight> value */
- /* Type : public */
- /* Interface : RETURN (direct value) */
- /* int : Current <m_nRight> position */
- /* OUTPUT (pointer to value) */
- /* None */
- /* INPUT (pointer to value, direct/default value) */
- /* i_bPercent : Return the position in percent */
- /* Pre-condition : None */
- /* Constraints : None */
- /* Behavior : A - Return the current <m_nRight> position */
- /* B - Return the current <m_nRight position in percent */
- /*----------------------------------------------------------------------------*/
- /* PROC SetStart */
- /* */
- /* [IF normal mode] */
- /* : A..... Return the current <m_nRight> position */
- /* [ELSE] */
- /* : B..... Return the current <m_nRight> position in percent */
- /* [ENDIF] */
- /*----------------------------------------------------------------------------*/
- /* If return in percent, 90% gives 23040, divided by 256 (>> 8) returns 90 ! */
- /*--- END FUNCTION HEADER ----------------------------------------------------*/
- int CSkinProgress::GetPos
- ( // Get <m_nRight> value
- BOOL i_bPercent // = false
- )
- {
- if(i_bPercent == false)
- {
- // A..... Return the current <m_nRight> position
- return m_nRight;
- }
- else
- {
- // B..... Return the current <m_nRight> position in 8-bits fixed point percent value ('>> 8' to get the 'int' value)
- return (int) ( // 100% *256 to keep a pseudo 8-bits fixed point value (0.00390625 - 1/256 - resolution)
- (
- (LONGLONG) // Turns the whole calculation in 64 bits
- (m_nRight - m_nLower)
- * 25600
- )
- / (m_nUpper - m_nLower)
- );
- }
- }
- /*--- START FUNCTION HEADER --------------------------------------------------*/
- /* Name : GetStep */
- /* Role : Get <m_nStep> value */
- /* Type : public */
- /* Interface : RETURN (direct value) */
- /* int : Current <m_nStep> value */
- /* OUTPUT (pointer to value) */
- /* None */
- /* INPUT (pointer to value, direct/default value) */
- /* None */
- /* Pre-condition : None */
- /* Constraints : None */
- /* Behavior : A - Return the current <m_nStep> value */
- /*----------------------------------------------------------------------------*/
- /* PROC SetStart */
- /* */
- /* A..... Return the current <m_nStep> value */
- /*----------------------------------------------------------------------------*/
- /*--- END FUNCTION HEADER ----------------------------------------------------*/
- int CSkinProgress::GetStep
- ( // Get <m_nStep> value
- )
- {
- // A..... Return the current <m_nStep> value
- return m_nStep;
- }
- /*--- START FUNCTION HEADER --------------------------------------------------*/
- /* Name : GetLower */
- /* Role : Get <m_nLower> value */
- /* Type : public */
- /* Interface : RETURN (direct value) */
- /* int : Current <m_nLower> value */
- /* OUTPUT (pointer to value) */
- /* None */
- /* INPUT (pointer to value, direct/default value) */
- /* None */
- /* Pre-condition : None */
- /* Constraints : None */
- /* Behavior : A - Return the current <m_nLower> value */
- /*----------------------------------------------------------------------------*/
- /* PROC SetStart */
- /* */
- /* A..... Return the current <m_nLower> value */
- /*----------------------------------------------------------------------------*/
- /*--- END FUNCTION HEADER ----------------------------------------------------*/
- int CSkinProgress::GetLower
- ( // Get <m_nLower> value
- )
- {
- // A..... Return the current <m_nLower> value
- return m_nLower;
- }
- /*--- START FUNCTION HEADER --------------------------------------------------*/
- /* Name : GetUpper */
- /* Role : Get <m_nUpper> value */
- /* Type : public */
- /* Interface : RETURN (direct value) */
- /* int : Current <m_nUpper> value */
- /* OUTPUT (pointer to value) */
- /* None */
- /* INPUT (pointer to value, direct/default value) */
- /* None */
- /* Pre-condition : None */
- /* Constraints : None */
- /* Behavior : A - Return the current <m_nUpper> value */
- /*----------------------------------------------------------------------------*/
- /* PROC SetStart */
- /* */
- /* A..... Return the current <m_nUpper> value */
- /*----------------------------------------------------------------------------*/
- /*--- END FUNCTION HEADER ----------------------------------------------------*/
- int CSkinProgress::GetUpper
- ( // Get <m_nUpper> value
- )
- {
- // A..... Return the current <m_nUpper> value
- return m_nUpper;
- }
- #ifdef dCSP_SLIDERBAR_METHOD
- /*--- START FUNCTION HEADER --------------------------------------------------*/
- /* Name : SetStart */
- /* Role : None */
- /* Type : public */
- /* Interface : RETURN (direct value) */
- /* int : Previous <m_nLeft> position, 0 if error */
- /* OUTPUT (pointer to value) */
- /* None */
- /* INPUT (pointer to value, direct/default value) */
- /* i_nStart : Select the new start position */
- /* i_bDisplay : Display the changes */
- /* Pre-condition : None */
- /* Constraints : None */
- /* Behavior : A - Jump to a specified position */
- /* B - Display the changes */
- /* C - Return the previous position */
- /*----------------------------------------------------------------------------*/
- /* PROC SetStart */
- /* */
- /* A..... Jump to a specified <i_nStart> position */
- /* B..... Display the changes */
- /* C..... Return the previous <m_nLeft> position */
- /*----------------------------------------------------------------------------*/
- /*--- END FUNCTION HEADER ----------------------------------------------------*/
- int CSkinProgress::SetStart
- ( // Set <m_nLeft> value
- int i_nStart // Set a new start position
- #ifndef dCSP_TIMED_REDRAW
- ,BOOL i_bDisplay // = true : Display the changes
- #endif // dCSP_TIMED_REDRAW
- )
- {
- // Init
- // Process + Return
- if(IsWindow(GetSafeHwnd()))
- {
- ASSERT((-0x7FFFFFFF <= i_nStart) && (i_nStart <= 0x7FFFFFFF));
- if(i_nStart > m_nUpper)
- { // Avoid problems
- i_nStart = m_nUpper;
- }else{}
- if(i_nStart < m_nLower)
- { // Avoid problems
- i_nStart = m_nLower;
- }else{}
- if(i_nStart > m_nRight)
- { // Avoid problems
- i_nStart = m_nRight;
- }else{}
- m_nPrevLeft = m_nLeft;
- // A..... Jump to a specified <i_nEnd> position
- m_nLeft = i_nStart;
- // B..... Display the changes
- #ifndef dCSP_TIMED_REDRAW
- if(i_bDisplay != false)
- {
- RefreshPanes();
- }else{}
- #endif // dCSP_TIMED_REDRAW
- // C..... Return the previous <m_nPrevLeft> position
- return m_nPrevLeft;
- }
- else
- {
- return 0;
- }
- }
- /*--- START FUNCTION HEADER --------------------------------------------------*/
- /* Name : GetStart */
- /* Role : Get <m_nLeft> value */
- /* Type : public */
- /* Interface : RETURN (direct value) */
- /* int : Current <m_nLeft> position */
- /* OUTPUT (pointer to value) */
- /* None */
- /* INPUT (pointer to value, direct/default value) */
- /* i_bPercent : Return the position in percent */
- /* Pre-condition : None */
- /* Constraints : None */
- /* Behavior : A - Return the current <m_nLeft> position */
- /* B - Return the current <m_nLeft> position in percent */
- /*----------------------------------------------------------------------------*/
- /* PROC SetStart */
- /* */
- /* [IF normal mode] */
- /* : A..... Return the current <m_nLeft> position */
- /* [ELSE] */
- /* : B..... Return the current <m_nLeft> position in percent */
- /* [ENDIF] */
- /*----------------------------------------------------------------------------*/
- /* If return in percent, 90% gives 23040, divided by 256 (>> 8) returns 90 ! */
- /*--- END FUNCTION HEADER ----------------------------------------------------*/
- int CSkinProgress::GetStart
- ( // Get <m_nLeft> value
- BOOL i_bPercent // = false
- )
- {
- if(i_bPercent == false)
- {
- // A..... Return the current <m_nLeft> position
- return m_nLeft;
- }
- else
- {
- // B..... Return the current <m_nLeft> position in 8-bits fixed point percent value ('>> 8' to get the 'int' value)
- return (int) ( // 100% *256 to keep a pseudo 8-bits fixed point value (0.00390625 - 1/256 - resolution)
- (
- (LONGLONG) // Turns the whole calculation in 64 bits
- (m_nLeft - m_nLower)
- * 25600
- )
- / (m_nUpper - m_nLower)
- );
- }
- }
- #endif // dCSP_SLIDERBAR_METHOD
- /*--- START FUNCTION HEADER --------------------------------------------------*/
- /* Name : Reset */
- /* Role : // Restart the progress bar */
- /* Type : public */
- /* Interface : RETURN (direct value) */
- /* None */
- /* OUTPUT (pointer to value) */
- /* None */
- /* INPUT (pointer to value, direct/default value) */
- /* i_bDisplay : Display the changes */
- /* Pre-condition : None */
- /* Constraints : None */
- /* Behavior : A - Get the creation date and time of the progress bar */
- /* B - Set the position of the bar to its beginning */
- /*----------------------------------------------------------------------------*/
- /* PROC StepIt */
- /* */
- /* A..... Get the creation date and time of the progress bar */
- /* B..... Set the position of the bar to its beginning */
- /*----------------------------------------------------------------------------*/
- /*--- END FUNCTION HEADER ----------------------------------------------------*/
- void CSkinProgress::Reset
- ( // Restart the progress bar
- #ifndef dCSP_TIMED_REDRAW
- BOOL i_bDisplay // = true : Display the changes
- #endif // dCSP_TIMED_REDRAW
- )
- {
- FILETIME sStartTimeFile;
- // Init
- // Process
- // A..... Get the creation date and time of the progress bar
- // GetSystemTime(&m_sStartTimeSystem);
- GetLocalTime(&m_sStartTimeSystem);
- SystemTimeToFileTime(&m_sStartTimeSystem, &sStartTimeFile);
- m_nStartTimeLongLong = (
- (
- (LONGLONG) // Turns the whole calculation in 64 bits
- sStartTimeFile.dwHighDateTime
- << 32
- )
- | sStartTimeFile.dwLowDateTime
- );
- // B..... Set the position of the bar to its beginning
- SetPos
- (
- m_nLower
- #ifndef dCSP_TIMED_REDRAW
- ,i_bDisplay
- #endif // dCSP_TIMED_REDRAW
- );
- }
- // *** TEXT INTERFACE ***
- /*--- START FUNCTION HEADER --------------------------------------------------*/
- /* Name : SetText */
- /* Role : Change the text */
- /* Type : public */
- /* Interface : RETURN (direct value) */
- /* BOOL = false : NEVER */
- /* true : ALWAYS */
- /* OUTPUT (pointer to value) */
- /* None */
- /* INPUT (pointer to value, direct/default value) */
- /* i_poStrMessage : New text to display */
- /* i_bDisplay : Display the changes */
- /* Pre-condition : None */
- /* Constraints : None */
- /* Behavior : A - Set the new text */
- /* B - Display the new text */
- /*----------------------------------------------------------------------------*/
- /* PROC SetText */
- /* */
- /* A..... Set the new text */
- /* B..... Display the changes */
- /*----------------------------------------------------------------------------*/
- /*--- END FUNCTION HEADER ----------------------------------------------------*/
- BOOL CSkinProgress::SetText
- ( // Set the new text
- LPCTSTR i_poStrMessage // New text to display
- #ifndef dCSP_TIMED_REDRAW
- ,BOOL i_bDisplay // = true : Display the changes
- #endif // dCSP_TIMED_REDRAW
- )
- {
- // Init
- // A..... Set the new text
- m_oStrMessage = i_poStrMessage;
- // Process
- // B..... Display the changes
- #ifndef dCSP_TIMED_REDRAW
- if(i_bDisplay != false)
- {
- RefreshPanes();
- }else{}
- #endif // dCSP_TIMED_REDRAW
- // Return
- return true;
- }
- /*--- START FUNCTION HEADER --------------------------------------------------*/
- /* Name : SetProgress */
- /* Role : Change the completion status text */
- /* Type : public */
- /* Interface : RETURN (direct value) */
- /* BOOL = false : NEVER */
- /* true : ALWAYS */
- /* OUTPUT (pointer to value) */
- /* None */
- /* INPUT (pointer to value, direct/default value) */
- /* i_nProgress : Any <eProgressSkinText> entry value */
- /* i_bDisplay : Display the changes */
- /* Pre-condition : None */
- /* Constraints : None */
- /* Behavior : A - Set the new progress text */
- /* B - Display the new progress text */
- /*----------------------------------------------------------------------------*/
- /* PROC SetProgress */
- /* */
- /* A..... Set the new progress text */
- /* B..... Display the new progress text */
- /*----------------------------------------------------------------------------*/
- /*--- END FUNCTION HEADER ----------------------------------------------------*/
- BOOL CSkinProgress::SetProgress
- ( // Set <m_nProgressText> value
- int i_nProgress // Set progress text
- #ifndef dCSP_TIMED_REDRAW
- ,BOOL i_bDisplay // = true : Display the changes
- #endif // dCSP_TIMED_REDRAW
- )
- {
- // Init
- // A..... Set the new progress text
- m_nProgressText = i_nProgress;
- // Process
- // B..... Display the resized progress bar
- #ifndef dCSP_TIMED_REDRAW
- if(i_bDisplay != false)
- {
- RefreshPanes();
- }else{}
- #endif // dCSP_TIMED_REDRAW
- // Return
- return true;
- }
- /*--- START FUNCTION HEADER --------------------------------------------------*/
- /* Name : GetProgress */
- /* Role : Get the completion status message currently used */
- /* Type : public */
- /* Interface : RETURN (direct value) */
- /* int : The current <m_nProgressText> value */
- /* OUTPUT (pointer to value) */
- /* None */
- /* INPUT (pointer to value, direct/default value) */
- /* None */
- /* Pre-condition : None */
- /* Constraints : None */
- /* Behavior : A - Return the current <m_nProgressText> value */
- /*----------------------------------------------------------------------------*/
- /* PROC GetProgress */
- /* */
- /* A..... Return the current <m_nProgressText> value */
- /*----------------------------------------------------------------------------*/
- /*--- END FUNCTION HEADER ----------------------------------------------------*/
- int CSkinProgress::GetProgress
- ( // Get <m_nProgressText> value
- )
- {
- // Init
- // Process
- // Return
- // A..... Return the current <m_nProgressText> value
- return m_nProgressText;
- }
- // *** UPDATE PROCESS ***
- /*--- START FUNCTION HEADER --------------------------------------------------*/
- /* Name : RefreshPanes */
- /* Role : None */
- /* Type : public */
- /* Interface : RETURN (direct value) */
- /* BOOL = false : Error while trying to resize the text */
- /* true : Process completed without error */
- /* OUTPUT (pointer to value) */
- /* None */
- /* INPUT (pointer to value, direct/default value) */
- /* None */
- /* Pre-condition : None */
- /* Constraints : None */
- /* Behavior : A - Get the text pane pointer and dimension */
- /* B - Progress pane size calculation */
- /* C - Get optional message length */
- /* D - Compact the text in the remaining space */
- /* E - Create the complete information message */
- /* F - Modify the progress bar size according of its size */
- /* G - Refresh the progress bar */
- /* H - Display the complete information message */
- /*----------------------------------------------------------------------------*/
- /* PROC RefreshPanes */
- /* */
- /* A..... Get the text pane pointer and dimension */
- /* [IF it is in dialog mode, in a CWnd target pane] */
- /* : [IF there is a CWnd text pane] */
- /* : : AA.... Dialog CWnd text anchor */
- /* : [ENDIF] */
- /* [ELSE] */
- /* : [IF there is a status bar] */
- /* : : AB.... Status bar pane 0 */
- /* : [ENDIF] */
- /* [ENDIF] */
- /* B..... Progress pane size calculation */
- /* [IF the progress bar dimension is valid] */
- /* : BA.... Set the size of the progress bar to the full width of its pane */
- /* : [IF there is a text pane] */
- /* : : BB.... Get text pane's DC */
- /* : : [IF text in status bar] */
- /* : : : BC.... Calculate the fixed size of the progress bar */
- /* : : : [IF progress in pane 0 and have a fixed size] */
- /* : : : : [IF size > 0] */
- /* : : : : : BCA... Calculate the remaining size for the text */
- /* : : : : [ELSE] */
- /* : : : : : BCB... Calculate the size of the text to use */
- /* : : : : [ENDIF] */
- /* : : : [ELSE] */
- /* : : : : BCC... Use whole width of pane 0 for the text */
- /* : : : [ENDIF] */
- /* : : [ELSE] */
- /* : : : BD.... Use all the space of the CWnd text anchor */
- /* : : [ENDIF] */
- /* : : [IF text is visble] */
- /* : : : C..... Get optional message length */
- /* : : : [IF there is a message to add] */
- /* : : : : CA.... Get the length of the cSPT_PERCENT message */
- /* : : : : [IF the message is at least TIMED] */
- /* : : : : : CB.... Get the length of the cSPT_TIMED message */
- /* : : : : [ENDIF] */
- /* : : : [ENDIF] */
- /* : : : CC.... Get the length of the text to display */
- /* : : : D..... Compact the text in the remaining space */
- /* : : : [IF there is no message] */
- /* : : : : DA.... Compact the text according to just its length */
- /* : : : [ELSE] */
- /* : : : : DB.... Compact the text minus the length of the cSPT_PERCENT */
- /* : : : [ELSE] */
- /* : : : : DC.... Compact the text minus the length of the cSPT_TIMED */
- /* : : : [ELSE] */
- /* : : : : DD.... Compact the text according to the remaining place */
- /* : : : : [IF the message is at least TIMED] */
- /* : : : : : DDA... Try to compact the text with cSPT_TIMED at first */
- /* : : : : [ELSE] */
- /* : : : : : [IF the message is at least TIMED] */
- /* : : : : : : DDB... Reset the text */
- /* : : : : : : DDC... Calculate the length of the three dots */
- /* : : : : : : DDD... Compact the text minus the three doted cSPT_PERCENT */
- /* : : : : : : DDE... Indicate the message used is cRTP_PERCENT */
- /* : : : : : [ELSE] */
- /* : : : : : : DDF... Indicate the message used is cSPT_TIMED */
- /* : : : : : [ENDIF] */
- /* : : : : [ENDIF] */
- /* : : : [ELSE] */
- /* : : : : DE.... Compact the text according to just its length */
- /* : : : [ENDIF] */
- /* : : : [IF there is no message] */
- /* : : : : DF.... Indicate the text is completely compacted, */
- /* : : : [ENDIF] */
- /* : : : [IF there is no message] */
- /* : : : : DG.... Indicate that there is no text, but perhaps a message */
- /* : : : [ENDIF] */
- /* : : : E..... Create the complete information message */
- /* : : : [IF there is no message] */
- /* : : : : EA.... Add the cSPT_PERCENT message */
- /* : : : [ELSE] */
- /* : : : : EB.... Add the cSPT_TIMED message */
- /* : : : [ELSE] */
- /* : : : : [IF the message is at least TIMED] */
- /* : : : : : EC.... Add the cSPT_PERCENT message */
- /* : : : : [ELSE] */
- /* : : : : : ED.... Add the cSPT_TIMED message */
- /* : : : : [ENDIF] */
- /* : : : [ENDIF] */
- /* : : : EE.... Scrub the text to delete trailing characters */
- /* : : : F..... Modify the progress bar size according of its size */
- /* : : : [IF there is no message] */
- /* : : : : FA.... Get the length of the complete text plus its margin */
- /* : : : [ENDIF] */
- /* : : : [IF there is no message] */
- /* : : : : FB.... Get the maximum length of the text pane */
- /* : : : [ENDIF] */
- /* : : : FC.... Set the new progress bar rectangle */
- /* : : : FD.... Move the left side of the progress bar after the text */
- /* : : : FE.... Move the right side of the text to the beginning of the bar */
- /* : : [ENDIF] */
- /* : : FF.... Make sure the previous text is erased */
- /* : [ENDIF] */
- /* : G..... Refresh the progress bar */
- /* : [IF the progress bar is visible] */
- /* : : [IF text is visble] */
- /* : : : GA.... Move the progress bar */
- /* : : [ELSE] */
- /* : : : [IF there is no message] */
- /* : : : : GB.... Display the modified progress bar */
- /* : : : [ENDIF] */
- /* : : [ENDIF] */
- /* : [ENDIF] */
- /* : H..... Display the complete information message */
- /* : [IF the progress bar is visible] */
- /* : : [IF text is visble] */
- /* : : : [IF there is no message] */
- /* : : : : HA.... Text in pane 0 of the status bar */
- /* : : : [ELSE] */
- /* : : : : HB.... Text in the CWnd text pane */
- /* : : : [ENDIF] */
- /* : : [ENDIF] */
- /* : [ENDIF] */
- /* [ENDIF] */
- /*----------------------------------------------------------------------------*/
- /*--- END FUNCTION HEADER ----------------------------------------------------*/
- #define cRTP_BLOCK ( 1 << 0)
- #define cRTP_NOTEXT (cRTP_BLOCK << 1)
- #define cRTP_PERCENT (cRTP_NOTEXT << 1)
- #define cRTP_TIMED (cRTP_PERCENT << 1)
- BOOL CSkinProgress::RefreshPanes
- ( // Resize the text pane and the progress bar
- )
- {
- CStatusBar* poStatusBar;
- CWnd* poTextCWnd;
- CFont* poFontOld;
- CString oStrMessage; // Working buffer for m_oStrMessage
- CString oStrPercent; // Percent of completion level
- CString oStrTimed; // Timed completion level
- int nProgressText; // Absolute value of <m_nProgressText>
- int nLenMessage; // Len of m_oStrMessage in pixel
- int nLenPercent; // Len of oStrPercent in pixel
- int nLenTimed; // Len of oStrTimed in pixel
- int nLenMargin; // Len of 2*' ' in pixel
- int nLenCompact; // Number of character packed
- int nLenText; // Allowed len of the text (used to wrap it)
- int nLenPane; //
- int nLenBlock; // Flags for computation (text wrapping)
- CRect oRectText; // Rect of pane 0 -> oRectPane at the end of the process if m_nPane == 0
- CRect oRectPane; // Rect of pane m_nPane, can be also pane 0
- // Init
- poStatusBar = NULL; // AVOID /W4 -> HA.... *STUPID COMPILER*
- poTextCWnd = NULL; // AVOID /W4 -> BA.... *STUPID COMPILER*
- nLenPercent = 0; // AVOID /W4 -> DB.... *STUPID COMPILER*
- nLenTimed = 0; // AVOID /W4 -> DDA... *STUPID COMPILER*
- nLenText = 0; // AVOID /W4 -> DE.... *STUPID COMPILER*
- nLenBlock = 0; // AVOID /W4 -> F..... *STUPID COMPILER*
- if(m_nProgressText < 0)
- {
- nProgressText = 0 - m_nProgressText; // Make it positive
- }
- else
- {
- nProgressText = m_nProgressText;
- }
- // Process + Return
- if(IsWindow(GetSafeHwnd()))
- {
- // A..... Get the text pane pointer and dimension
- #ifdef dCSP_DIALOG_PROGRESS
- if(m_poWndProgress != NULL)
- {
- // AA.... Dialog CWnd text anchor
- if(m_poWndMessage != NULL)
- {
- poTextCWnd = m_poWndMessage;
- poTextCWnd->GetWindowRect(oRectText);
- }else{}
- }
- else
- {
- #endif // dCSP_DIALOG_PROGRESS
- poStatusBar = GetStatusBar();
- if(poStatusBar != NULL)
- {
- // AB.... Status bar pane 0
- poTextCWnd = poStatusBar;
- poStatusBar->GetItemRect(0, oRectText);
- }
- else
- {
- return false;
- }
- #ifdef dCSP_DIALOG_PROGRESS
- }
- #endif // dCSP_DIALOG_PROGRESS
- // B..... Progress pane size calculation
- if(GetTargetRect(&oRectPane))
- {
- // BA.... Set the size of the progress bar to the full width of its current pane
- nLenPane = oRectPane.Width();
- if(poTextCWnd != NULL)
- {
- // BB.... Get text pane's DC
- CClientDC oDC(poTextCWnd);
- poFontOld = oDC.SelectObject(poTextCWnd->GetFont());
- #ifdef dCSP_DIALOG_PROGRESS
- if(m_poWndProgress == NULL)
- {
- #endif // dCSP_DIALOG_PROGRESS
- // BC.... Calculate the fixed size of the progress bar
- if(
- (m_nPane == 0)
- && (m_nSize != 0)
- )
- { // If the text pane is shared with the progress bar, calculate how much space the text takes up
- if(m_nSize > 0)
- { // Force progress bar size
- // BCA... Calculate the remaining size for the text once removed the fixed size of the progress bar
- nLenPane = oRectText.Width() - (m_nSize - 3); // Minus 3 to keep the same spacing with the others ways just below, to resize the text
- nLenText = nLenPane; // Use the remaining space left by the resized progress bar
- }
- else
- { // Resize the progress bar if the text is too long
- // BCB... Calculate the size of the text to use (here the whole width of pane 0)
- nLenPane = oRectText.Width() + m_nSize; // *BEWARE* : m_nSize < 0 -> Get the optimal width of the progress bar before resizing it if necessary
- nLenText = oRectText.Width() - 3; // Use the whole space of pane 0, minus 3 to avoid a complete pane 0 disclosure leading to a windows bug
- }
- }
- else
- { // Resize the text if it is too long (even in pane 0 if m_nSize == 0)
- // BCC... Use whole width of pane 0 for the text, and what remains for the progress bar
- nLenPane = 0; // Full length for the progress bar, might be resized for pane 0
- nLenText = oRectText.Width() - 3; // Use the whole space of pane 0, minus 3 to avoid a complete pane 0 disclosure leading to a windows bug
- }
- #ifdef dCSP_DIALOG_PROGRESS
- }
- else
- {
- // BD.... Use all the space of the CWnd text anchor
- if(poTextCWnd != NULL)
- { // Use the whole lenght of the CWnd text pane
- nLenText = oRectText.Width();
- }else{}
- }
- #endif // dCSP_DIALOG_PROGRESS
- if(poTextCWnd->IsWindowVisible())
- { // Redraw the text window
- // C..... Get optional message length
- if(nProgressText != cSPT_NONE)
- { // Calculate progress text
- // CA.... Get the length of the cSPT_PERCENT message
- oStrPercent.Format
- (
- "%d%%",
- (int) // Result on 'int'
- ( // From 0 to 100
- (
- (LONGLONG) // Turns the whole calculation in 64 bits
- (m_nRight - m_nLower)
- * 100
- )
- / (m_nUpper - m_nLower)
- )
- );
- if(m_nProgressText > 0)
- {
- oStrPercent = "(" + oStrPercent + ")";
- }else{}
- oStrPercent = " " + oStrPercent;
- nLenPercent = oDC.GetTextExtent(oStrPercent).cx; // Length of Percent
- if(nProgressText >= cSPT_TIMED)
- {
- // CB.... Get the length of the cSPT_TIMED message
- GetTimed(&oStrTimed);
- nLenTimed = oDC.GetTextExtent(oStrTimed).cx; // Length of Timed
- }else{}
- }else{}
- // CC.... Get the length of the text to display
- oStrMessage = m_oStrMessage;
- nLenMessage = oDC.GetTextExtent(oStrMessage).cx; // Length of Message
- nLenMargin = oDC.GetTextExtent(" ").cx << 1; // Text margin
- // D..... Compact the text in the remaining space
- // Dompact the text
- switch(nProgressText)
- {
- case cSPT_NONE :
- // DA.... Compact the text according to just its length
- nLenCompact = CompactText(&oStrMessage, &oDC, nLenText, nLenMargin);
- break;
- case cSPT_PERCENT :
- // DB.... Compact the text according to its length minus the length of the cSPT_PERCENT message
- nLenCompact = CompactText(&oStrMessage, &oDC, nLenText, nLenMargin + nLenPercent);
- break;
- case cSPT_TIMED :
- // DC.... Compact the text according to its length minus the length of the cSPT_TIMED message
- nLenCompact = CompactText(&oStrMessage, &oDC, nLenText, nLenMargin + nLenTimed);
- break;
- case cSPT_AUTOSIZE :
- // DD.... Compact the text according to the most usable remaining place between the text and the progress bar
- // DDA... Try to compact the text with the cSPT_TIMED message at first
- nLenCompact = CompactText(&oStrMessage, &oDC, nLenText, nLenMargin + nLenTimed);
- if(
- (nLenCompact != 0)
- && (nLenCompact != oStrMessage.GetLength())
- )
- { // If the message was compacted, try with Percent
- // DDB... Reset the text
- oStrMessage = m_oStrMessage; // Restore the message
- // DDC... Calculate the length of the three dots that will be displayed after the cSPT_PERCENT message
- // In case of Timed wrapping, use Percent instead, but add "..." to show that the Timed information was wrapped
- oStrPercent += "...";
- nLenPercent = oDC.GetTextExtent(oStrPercent).cx; // Length of Percent
- // DDD... Compact the text according to its length minus the length of the cSPT_PERCENT message and the added three dots
- // Dompact the Percent + "..." information
- nLenCompact = CompactText(&oStrMessage, &oDC, nLenText, nLenMargin + nLenPercent);
- // DDE... Indicate the message used is cRTP_PERCENT
- nLenBlock |= cRTP_PERCENT;
- }
- else
- { // There was enough place to add the Timed information
- // DDF... Indicate the message used is cSPT_TIMED
- nLenBlock |= cRTP_TIMED;
- }
- break;
- default :
- // DE.... Compact the text according to just its length
- nLenCompact = CompactText(&oStrMessage, &oDC, nLenText, nLenMargin);
- }
- #ifdef dCSP_DIALOG_PROGRESS
- if(m_poWndProgress == NULL)
- {
- #endif // dCSP_DIALOG_PROGRESS
- // Block the text wrapping if there is nothing more to wrap
- if(
- (nLenCompact < 0)
- || (
- (oStrMessage.GetLength() <= 4)
- && (oStrMessage.Right(3) == "...")
- )
- )
- {
- // DF.... Indicate the text is completely compacted,
- nLenBlock |= cRTP_BLOCK;
- }else{}
- if(oStrMessage == "")
- {
- // DG.... Indicate that there is no text, but there might be a message
- nLenBlock |= cRTP_NOTEXT;
- }else{}
- #ifdef dCSP_DIALOG_PROGRESS
- }else{}
- #endif // dCSP_DIALOG_PROGRESS
- // E..... Create the complete information message with the user text and the completion report
- // Add the information
- switch(nProgressText)
- {
- case cSPT_NONE :
- break;
- case cSPT_PERCENT :
- // EA.... Add the cSPT_PERCENT message
- oStrMessage += oStrPercent;
- break;
- case cSPT_TIMED :
- // EB.... Add the cSPT_TIMED message
- oStrMessage += oStrTimed;
- break;
- case cSPT_AUTOSIZE :
- if((nLenBlock & cRTP_PERCENT) != 0)
- { // If the message was compacted, try with Percent
- // EC.... Add the cSPT_PERCENT message
- oStrMessage += oStrPercent;
- }
- else
- { // There was enough place to add the Timed information
- // ED.... Add the cSPT_TIMED message
- oStrMessage += oStrTimed;
- }
- break;
- default :
- break;
- }
- // EE.... Scrub the text to delete trailing characters
- oStrMessage.TrimLeft();
- #ifdef dCSP_DIALOG_PROGRESS
- if(m_poWndProgress == NULL)
- {
- #endif // dCSP_DIALOG_PROGRESS
- // F..... Modify the progress bar size according of its size
- if(m_nPane == 0)
- { // If the text pane is shared with the progress bar, calculate how much space the text takes up to
- nLenMessage = oDC.GetTextExtent(oStrMessage).cx; // Length of the compacted Message
- if(
- (
- (
- (nLenMessage + nLenMargin) // Lenght of Message + Margin
- > (nLenPane) // Lenght of remaining space for text
- )
- && (
- (m_nSize <= 0) // Resize of the progress bar if the text is longer, also used for m_nSize == 0
- || (
- (nLenMessage > 0)
- && ((nLenBlock & cRTP_NOTEXT) != 0)
- )
- )
- )
- || ((nLenBlock & cRTP_BLOCK) != 0) // Avoid paning if the text is wrapped to the max (when only "...'+information remains)
- )
- { // *IF* the packed text is larger than the space left by the resized progress bar *AND* the resizing of the progress bar is allowed *OR* the wrapping is blocked
- // FA.... Get the length of the complete text plus its margin
- nLenPane = nLenMessage;
- if(nLenMessage > 0)
- {
- nLenPane += nLenMargin;
- }else{}
- }else{}
- if(nLenPane > oRectText.Width())
- { // Make sure the length will stay positive
- // FB.... Get the maximum length of the text pane
- nLenPane = oRectText.Width();
- }else{}
- if(nLenPane < 2)
- {
- nLenPane = 2;
- }else{}
- // FC.... Set the new progress bar rectangle
- // This is the pane to display
- oRectPane = oRectText;
- // FD.... Move the left side of the progress bar to the right of the text
- // Move left edge of the progress bar to the right, to leave some place for the text
- oRectPane.left = nLenPane;
- // FE.... Move the right side of the text to the beginning of the bar
- oRectText.right = nLenPane;
- }else{}
- #ifdef dCSP_DIALOG_PROGRESS
- }else{}
- #endif // dCSP_DIALOG_PROGRESS
- }else{}
- // FF.... Make sure the previous text is erased, so display at least a space character
- if(oStrMessage == "")
- {
- oStrMessage = " "; // If no text, force the pane to be cleared
- }else{}
- // Release DC
- oDC.SelectObject(poFontOld);
- }else{}
- if(IsWindowVisible())
- {
- // G..... Refresh the progress bar
- if(
- (m_oRectPane != oRectPane)
- && ( // Avoid pane disclosure, so that you can reopen the window and the pane won't stay closed
- (oRectPane.Width() > 2)
- && (oRectPane.Height() > 2)
- )
- )
- {
- // GA.... Move the progress bar
- m_oRectPane = oRectPane; // The new progress rectangle
- MoveWindow(&oRectPane);
- Invalidate(); // Display the progress bar on its new position
- }
- else
- {
- if(UpdateProgress())
- {
- // GB.... Display the modified progress bar
- Invalidate(); // Display the changes
- }else{}
- }
- }else{}
- if(poTextCWnd != NULL)
- {
- if(m_oStrPrevMessage != oStrMessage)
- { // If the new message has changed from the previous, set it
- // H..... Display the complete information message
- #ifdef dCSP_DIALOG_PROGRESS
- if(m_poWndProgress == NULL)
- {
- #endif // dCSP_DIALOG_PROGRESS
- // HA.... Text in pane 0 of the status bar
- poStatusBar->SetPaneText(0, oStrMessage); // Force text in pane 0
- m_oStrPrevMessage = oStrMessage;
- #ifdef dCSP_DIALOG_PROGRESS
- }
- else
- {
- if(m_poWndMessage != NULL)
- {
- // HB.... Text in the CWnd text pane
- m_poWndMessage->SetWindowText(oStrMessage);
- m_oStrPrevMessage = oStrMessage;
- }else{}
- }
- #endif // dCSP_DIALOG_PROGRESS
- }else{}
- }else{}
- return true;
- }
- else
- {
- return false;
- }
- }
- else
- {
- return false;
- }
- }
- // *** DATA PROCESS ***
- /*--- START FUNCTION HEADER --------------------------------------------------*/
- /* Name : CompactText */
- /* Role : None */
- /* Type : PROTECTED */
- /* Interface : RETURN (direct value) */
- /* int : > 0 = Number of character packed */
- /* 0 = Nothing packed */
- /* < 0 = Pack blocked */
- /* OUTPUT (pointer to value) */
- /* io_poString : Packed and three-doted text */
- /* INPUT (pointer to value, direct/default value) */
- /* io_poString : Text to compact */
- /* i_poDC : Target DC */
- /* i_nMaxWidth : Width in pixel the text should fits in */
- /* i_nAddWidth : Additional width for some purposes */
- /* Pre-condition : None */
- /* Constraints : None */
- /* Behavior : A - Get the current DC */
- /* B - Remove any ending dots */
- /* C - Verify there is something to do */
- /* D - Check if the text can be compacted */
- /* E - Compact the string */
- /* F - Add the three dots at the end of the string */
- /*----------------------------------------------------------------------------*/
- /* PROC CompactText */
- /* */
- /* [IF a string is provided to process] */
- /* : [IF no DC specified] */
- /* : : A..... Get the current DC */
- /* : [ENDIF] */
- /* : [IF there is ending dots] */
- /* : : B..... Remove any ending dots */
- /* : [ENDIF] */
- /* : C..... Verify there is something to do */
- /* : [IF something have to be done] */
- /* : : D..... Check if the text can be compacted */
- /* : : [IF the text can be compacted] */
- /* : : : E..... Compact the string as long as it does'nt fit */
- /* : : : D..... Add the three dots at the end of the string */
- /* : : [ENDIF] */
- /* : [ENDIF] */
- /* [ENDIF] */
- /*----------------------------------------------------------------------------*/
- /* Quite easy and fun to use... No trailing blank characters ! */
- /*--- END FUNCTION HEADER ----------------------------------------------------*/
- int CSkinProgress::CompactText
- (
- CString* io_poString,
- CDC* i_poDC,
- int i_nMaxWidth,
- int i_nAddWidth
- )
- {
- int nLenString;
- int nLenDots;
- int nCountChar;
- TCHAR nFirstChar;
- // Init
- if(io_poString != NULL)
- {
- if(i_poDC == NULL)
- { // If no target device context provided, use the current one
- // A..... Get the current DC
- CClientDC oDC(this);
- i_poDC = &oDC;
- }else{}
- nLenString = io_poString->GetLength();
- if(io_poString->Right(3) == "...")
- {
- // B..... Remove any ending dots
- nLenString -= 3;
- *io_poString = io_poString->Left(nLenString);
- }else{}
- // Process + Return
- // C..... Verify there is something to do
- if(
- (nLenString == 0) // No text
- || ( // Enough space for the unmodified text and the margin
- (i_poDC->GetTextExtent(*io_poString, nLenString).cx + i_nAddWidth)
- <= i_nMaxWidth
- )
- )
- {
- return 0;
- }
- else
- {
- // D..... Check if the three doted first character is longer than the whole string (VERY few characters only)
- nFirstChar = io_poString->GetAt(0);
- nLenDots = i_poDC->GetTextExtent(anThreeDots, sizeof(anThreeDots)).cx;
- if(
- i_poDC->GetTextExtent(*io_poString, nLenString).cx
- <= (i_poDC->GetTextExtent(&nFirstChar, sizeof(nFirstChar)).cx + nLenDots)
- )
- {
- return (0 - nLenString);
- }
- else
- {
- nCountChar = 0;
- // E..... Compact the string as long as it does'nt fit in the desired space
- while( // As long as something remains *AND* the stuff is bigger than the allowed space
- (nLenString > 1) // Leading character must remain at least
- && (
- (i_poDC->GetTextExtent(*io_poString, nLenString).cx + (nLenDots >> 1) + i_nAddWidth)
- > i_nMaxWidth
- )
- )
- {
- *io_poString = io_poString->Left(io_poString->GetLength() - 1); // BEWARE : Modify the original object
- io_poString->TrimRight(); // Kill spaces
- nLenString = io_poString->GetLength(); // Get the real length after trim
- nCountChar += 1;
- }
- // F..... Add the three dots at the end of the string
- *io_poString += anThreeDots;
- return nCountChar;
- }
- }
- }
- else
- {
- return 0;
- }
- }
- /*--- START FUNCTION HEADER --------------------------------------------------*/
- /* Name : GetTimed */
- /* Role : Get a complete and accurate timed text message */
- /* Type : PROTECTED */
- /* Interface : RETURN (direct value) */
- /* BOOL = false : NEVER */
- /* true : ALWAYS */
- /* OUTPUT (pointer to value) */
- /* o_poTimed : Timed message */
- /* INPUT (pointer to value, direct/default value) */
- /* None */
- /* Pre-condition : None */
- /* Constraints : None */
- /* Behavior : A - Get current date and time */
- /* B - Add start date in timed message if necessary */
- /* C - Add start time int timed message */
- /* D - Add the time elapsed from start */
- /* E - Add the current progress completion status */
- /* F - Add the remaining progress completion */
- /* G - Get the remaining time before end */
- /* H - Display the expected date and time of the end */
- /*----------------------------------------------------------------------------*/
- /* PROC GetTimed */
- /* */
- /* A..... Get current date and time */
- /* B..... Add start date in timed message if necessary */
- /* C..... Add start time int timed message */
- /* D..... Add the time elapsed from start */
- /* E..... Add the current progress completion status */
- /* F..... Add the remaining progress completion */
- /* G..... Get the remaining time before end */
- /* H..... Display the expected date and time of the end */
- /*----------------------------------------------------------------------------*/
- /* I will in the next update recode a bit this mess because if the progress */
- /* is not linear, the end time is far from being accurate. You might see that */
- /* when grabing the bottom-right corner of the main window to resize it. It */
- /* block the progress, but the timer continue to elapse, so the end time */
- /* grows fast. Then, once you release the corner, the progress restart, but */
- /* then the time to finish is quite short so the remaining time decrease very */
- /* fast, instead to readapt to show a 1:1 linear timer till the end. */
- /*--- END FUNCTION HEADER ----------------------------------------------------*/
- BOOL CSkinProgress::GetTimed
- (
- CString* o_poTimed
- )
- {
- CString oStrTempo;
- unsigned long nTempo;
- SYSTEMTIME sCurrentTimeSystem;
- SYSTEMTIME sTempoTimeSystem;
- FILETIME sTempoTimeFile;
- LONGLONG nTempoTimeLongLong;
- LONGLONG nDeltaTimeLongLong;
- // Init
- // A..... Get current date and time
- // GetSystemTime(&nCurrentTime);
- GetLocalTime(&sTempoTimeSystem);
- sCurrentTimeSystem = sTempoTimeSystem; // For the Date of End and Time of End
- SystemTimeToFileTime(&sTempoTimeSystem, &sTempoTimeFile);
- nTempoTimeLongLong = (
- (
- (LONGLONG) // Turns the whole calculation in 64 bits
- sTempoTimeFile.dwHighDateTime
- << 32
- )
- | sTempoTimeFile.dwLowDateTime
- );
- // Process
- *o_poTimed = " ";
- if(m_nProgressText > 0)
- {
- *o_poTimed += "(";
- }else{}
- // B..... Add start date in timed message if necessary
- if( // *IF* Date of Start is different from Current Date
- (sTempoTimeSystem.wDay != m_sStartTimeSystem.wDay) // Check what change first, days
- || (sTempoTimeSystem.wMonth != m_sStartTimeSystem.wMonth)
- || (sTempoTimeSystem.wYear != m_sStartTimeSystem.wYear)
- )
- { // Date of Start
- oStrTempo.Format
- (
- "%04d/%02d/%02d/%02d ",
- m_sStartTimeSystem.wYear,
- m_sStartTimeSystem.wMonth,
- m_sStartTimeSystem.wDay,
- m_sStartTimeSystem.wDayOfWeek + 1
- );
- *o_poTimed += oStrTempo;
- }else{}
- // C..... Add start time in timed message
- // Time of Start
- oStrTempo.Format
- (
- "%02d:%02d:%02d - ",
- m_sStartTimeSystem.wHour,
- m_sStartTimeSystem.wMinute,
- m_sStartTimeSystem.wSecond
- );
- *o_poTimed += oStrTempo;
- // D..... Add the time elapsed from start
- // Calculate time from start
- nDeltaTimeLongLong = nTempoTimeLongLong - m_nStartTimeLongLong;
- nTempoTimeLongLong = nDeltaTimeLongLong; // Keep nDeltaTimeLongLong safe
- sTempoTimeFile.dwLowDateTime = (DWORD) nTempoTimeLongLong;
- sTempoTimeFile.dwHighDateTime = (DWORD) ((LONGLONG) nTempoTimeLongLong >> 32);
- FileTimeToSystemTime(&sTempoTimeFile, &sTempoTimeSystem);
- sTempoTimeSystem.wYear -= 1600; // Starts from 1601, so if 1601 you get year 1
- // Day from start
- if(
- (sTempoTimeSystem.wYear != 1)
- || (sTempoTimeSystem.wMonth != 1)
- || (sTempoTimeSystem.wDay != 1)
- )
- { // If not the same day, calculate the number of days elapsed from start
- nTempo = (unsigned long) (
- nTempoTimeLongLong // Already in 64 bits, so the calculation will be done in 64 bits
- / (nDeltaTimeLongLong / 864000000000) // Number of days given in 100 nanosecond (0.1us)
- );
- if(nTempo != 0)
- { // If there is some days elapsed
- oStrTempo.Format("%d:", nTempo);
- *o_poTimed += oStrTempo;
- }else{}
- }else{}
- // Time from start
- oStrTempo.Format
- (
- "%02d:%02d:%02d - ",
- sTempoTimeSystem.wHour,
- sTempoTimeSystem.wMinute,
- sTempoTimeSystem.wSecond
- );
- *o_poTimed += oStrTempo;
- // E..... Add the current progress completion status
- // Elapsed percent
- #ifndef dCSP_SLIDERBAR_METHOD
- nTempo = (int) ( // 100% *256 to keep a pseudo 8-bits fixed point value (0.00390625 - 1/256 - resolution)
- (
- (LONGLONG) // Turns the whole calculation in 64 bits
- (m_nRight - m_nLower)
- * 25600
- )
- / (m_nUpper - m_nLower)
- );
- #else
- nTempo = (int) ( // 100% *256 to keep a pseudo 8-bits fixed point value (0.00390625 - 1/256 - resolution)
- (
- (LONGLONG) // Turns the whole calculation in 64 bits
- (m_nRight - m_nLeft)
- * 25600
- )
- / (m_nUpper - m_nLower)
- );
- #endif // dCSP_SLIDERBAR_METHOD
- oStrTempo.Format("%d%% / ", nTempo >> 8); // '>> 8' == '/ 256'
- *o_poTimed += oStrTempo;
- // F..... Add the remaining progress completion
- // Remaining percent
- oStrTempo.Format("%d%% - ", 100 - (nTempo >> 8));
- *o_poTimed += oStrTempo;
- // G..... Get the remaining time before end
- // Remaining time
- if(nTempo == 0)
- { // Avoid zero divide
- nTempoTimeLongLong = 0; // No more time to wait
- }
- else
- {
- nTempoTimeLongLong = ((nDeltaTimeLongLong * 25600) / nTempo) - nDeltaTimeLongLong; // The remaining time, 100% - Elasped (100% = Elapsed / Percent)
- }
- sTempoTimeFile.dwLowDateTime = (DWORD) nTempoTimeLongLong;
- sTempoTimeFile.dwHighDateTime = (DWORD) ((LONGLONG) nTempoTimeLongLong >> 32);
- FileTimeToSystemTime(&sTempoTimeFile, &sTempoTimeSystem);
- sTempoTimeSystem.wYear -= 1600;
- // Day to end
- if(
- (sTempoTimeSystem.wDay != 1) // Check what change first, days
- || (sTempoTimeSystem.wMonth != 1)
- || (sTempoTimeSystem.wYear != 1)
- )
- { // If not the same day, calculate the number of days elapsed from start
- nTempo = (unsigned long) (nDeltaTimeLongLong / 864000000000); // Number of days given in 100 nanosecond (0.1us)
- if(nTempo != 0)
- { // If there is some days elapsed
- oStrTempo.Format("%d:", nTempo);
- *o_poTimed += oStrTempo;
- }else{}
- }else{}
- // Time to end
- oStrTempo.Format("%02d:%02d:%02d - ", sTempoTimeSystem.wHour, sTempoTimeSystem.wMinute, sTempoTimeSystem.wSecond);
- *o_poTimed += oStrTempo;
- // H..... Display the expected date and time of the end
- // Date of End
- if(nTempo == 0)
- { // Avoid zero divide
- nTempoTimeLongLong = m_nStartTimeLongLong + nDeltaTimeLongLong; // Current time, Delta = Tempo - Start, see above
- }
- else
- {
- nTempoTimeLongLong = m_nStartTimeLongLong + ((nDeltaTimeLongLong * 25600) / nTempo); // Start + 100% (100% = Elapsed / Percent)
- }
- sTempoTimeFile.dwLowDateTime = (DWORD) nTempoTimeLongLong;
- sTempoTimeFile.dwHighDateTime = (DWORD) ((LONGLONG) nTempoTimeLongLong >> 32);
- FileTimeToSystemTime(&sTempoTimeFile, &sTempoTimeSystem);
- if(
- (sTempoTimeSystem.wYear != sCurrentTimeSystem.wYear)
- && (sTempoTimeSystem.wMonth != sCurrentTimeSystem.wMonth)
- && (sTempoTimeSystem.wDay != sCurrentTimeSystem.wDay)
- )
- {
- oStrTempo.Format
- (
- "%04d/%02d/%02d/%02d ",
- sTempoTimeSystem.wYear,
- sTempoTimeSystem.wMonth,
- sTempoTimeSystem.wDay,
- sTempoTimeSystem.wDayOfWeek + 1
- );
- *o_poTimed += oStrTempo;
- }else{}
- // Time of End
- oStrTempo.Format
- (
- "%02d:%02d:%02d",
- sTempoTimeSystem.wHour,
- sTempoTimeSystem.wMinute,
- sTempoTimeSystem.wSecond
- );
- *o_poTimed += oStrTempo;
- if(m_nProgressText > 0)
- {
- *o_poTimed += ")";
- }else{}
- // Return
- return true;
- }
- // *** UPDATE PROCESS ***
- /*--- START FUNCTION HEADER --------------------------------------------------*/
- /* Name : UpdateProgress */
- /* Role : None */
- /* Type : PROTECTED */
- /* Interface : RETURN (direct value) */
- /* BOOL = false : The progress bar has not changed */
- /* true : The display needs to be updated */
- /* OUTPUT (pointer to value) */
- /* o_poRectPaint : Return the progress bar client rect */
- /* INPUT (pointer to value, direct/default value) */
- /* None */
- /* Pre-condition : None */
- /* Constraints : None */
- /* Behavior : A - Get the current progress bar dimension */
- /* B - Set variables for calculation */
- /* C - Calculate the elements' position in pixel */
- /* D - Reverse the left and right element position */
- /* E - On progress bar change, return the need to refresh it */
- /*----------------------------------------------------------------------------*/
- /* PROC UpdateProgress */
- /* */
- /* A..... Get the current progress bar dimension */
- /* B..... Set variables for calculation */
- /* C..... Calculate the elements' position */
- /* CA.... Get the position of the end of the progress bar */
- /* CB.... Get the length in pixel of the prgress bar */
- /* CC.... Get the position of the left end of the progress bar */
- /* [IF the lenght of the progress bar exceed the end position] */
- /* : CD... Reset the length of the progress bar to its maximum size */
- /* [ENDIF] */
- /* [IF the left element is located after the right element] */
- /* : CE... Set the start before the end */
- /* [ENDIF] */
- /* [IF the display is reversed] */
- /* : D..... Reverse the left and right elements position */
- /* [ENDIF] */
- /* E..... On progress bar change, return the need to refresh it */
- /*----------------------------------------------------------------------------*/
- /*--- END FUNCTION HEADER ----------------------------------------------------*/
- BOOL CSkinProgress::UpdateProgress
- ( // Update of the progress bar values
- CRect* o_poRectPaint // = NULL
- )
- {
- CRect oRectPaint;
- #ifdef dCSP_SLIDERBAR_METHOD
- int nCurrentPos; // Pos of the current calculated position
- #endif // dCSP_SLIDERBAR_METHOD
- int nLenPos;
- int nStepPos;
- // Init
- // Init
- // A..... Get the current progress bar dimension
- GetClientRect(&oRectPaint); // the CStatic currently being repaint
- if(o_poRectPaint != NULL)
- {
- *o_poRectPaint = oRectPaint;
- }else{}
- // GetParent()->GetClientRect(&rcStatusBar); // For old test purpose, just stay here to recall me the syntax
- // GetParent()->ClientToScreen(&rcStatusBar);
- // ScreenToClient(&rcStatusBar);
- // B...... Set variables for calculation
- #ifdef dCSP_VERTICAL_BAR
- if(m_bVertical == false)
- { // Horizontal bar
- #endif // dCSP_VERTICAL_BAR
- nLenPos = oRectPaint.Width();
- nStepPos = m_nBmpWidth;
- #ifdef dCSP_VERTICAL_BAR
- }
- else
- { // Vertical bar
- nLenPos = oRectPaint.Height();
- nStepPos = m_nBmpHeight;
- }
- #endif // dCSP_VERTICAL_BAR
- // Process
- // m_nEndAff ----------------------------------------------------,
- // m_nRightAff ----------------------------, |
- // m_nLeftAff ---------, | m_nBmpWidth --,-, |
- // |<------ bar ------>| | | |
- // ProgressBar = [ : : :(:=:=:=:=:=:=:=:=:=:): : : : : : : : : : : ]
- // | | | |
- // | '- 0% --------- m_nRightAff --------- 100% -+-'
- // '- 0% --------- m_nLeftAff ------------ 100% -'
- // C..... Calculate the elements' position in pixel
- // CA.... Get the position of the end of the progress bar
- m_nEndAff = nLenPos - nStepPos; // Position of the cSPB_RIGHT element
- // CB.... Get the position of the right end of the progress bar
- m_nRightAff = (int) ( // Position of the cSPB_RIGHT element
- (
- (LONGLONG) // Turns the whole calculation in 64 bits
- (m_nRight - m_nLower)
- * (nLenPos - (nStepPos << 1))
- )
- / (m_nUpper - m_nLower)
- ) + nStepPos;
- #ifdef dCSP_SLIDERBAR_METHOD
- // CC.... Get the position of the left end of the progress bar
- m_nLeftAff = (int) ( // Position of the cSPB_LEFT element
- (
- (LONGLONG) // Turns the whole calculation in 64 bits
- (m_nLeft - m_nLower)
- * (nLenPos - (nStepPos << 1))
- )
- / (m_nUpper - m_nLower)
- );
- #endif // dCSP_SLIDERBAR_METHOD
- if(m_nRightAff > m_nEndAff)
- { // Cannot be be bigger than the bar itselves
- // CD.... Reset the length of the progress bar to its maximum size
- m_nRightAff = m_nEndAff;
- }else{}
- #ifdef dCSP_SLIDERBAR_METHOD
- if(m_nLeftAff > (m_nRightAff - nStepPos))
- { // Cannot be be bigger than the bar itselves
- // CE.... Set the start before the end
- m_nLeftAff = m_nRightAff - nStepPos;
- }else{}
- #endif // dCSP_SLIDERBAR_METHOD
- // D..... Reverse the left and right elements position
- #ifdef dCSP_SLIDERBAR_METHOD
- if(m_bReverse != false)
- { // If reversing the display, just invert the positions in dCSP_SLIDERBAR_METHOD mode, TRICKY ISN'T IT !
- nCurrentPos = nLenPos - m_nRightAff - nStepPos; // Will become m_nLeftAff
- m_nRightAff = nLenPos - m_nLeftAff - nStepPos; // m_nLeftAff becomes m_nRightAff
- m_nLeftAff = nCurrentPos; // m_nRightAff becomes m_nLeftAff
- }else{}
- #endif // dCSP_SLIDERBAR_METHOD
- // Return
- // E..... On progress bar change, return the need to refresh it
- if(
- (m_nPrevEndAff != m_nEndAff)
- || (m_nPrevRightAff != m_nRightAff)
- #ifdef dCSP_SLIDERBAR_METHOD
- || (m_nPrevLeftAff != m_nLeftAff)
- #endif // dCSP_SLIDERBAR_METHOD
- )
- {
- return true;
- }
- else
- {
- return false;
- }
- }
- // *** WINDOWS MAPPED PROCESSING ***
- /*--- START FUNCTION HEADER --------------------------------------------------*/
- /* Name : OnEraseBkgnd */
- /* Role : Erase the background (with a filled rect) before [OnPaint] */
- /* Type : PROTECTED */
- /* Interface : RETURN (direct value) */
- /* None */
- /* OUTPUT (pointer to value) */
- /* None */
- /* INPUT (pointer to value, direct/default value) */
- /* i_poDC : current DC */
- /* Pre-condition : None */
- /* Constraints : None */
- /* Behavior : A - Erase the background */
- /* B - Resize and display the text */
- /*----------------------------------------------------------------------------*/
- /* PROC OnEraseBkgnd */
- /* */
- /* A..... Erase the background */
- /* B..... Resize and display the text */
- /*----------------------------------------------------------------------------*/
- /* This function is called prior to [OnSizing] because we cannot over-ride */
- /* the status bar [OnSizing] function from here. And we also cannot do it for */
- /* the main window also, which is the parent window of the status bar. So, in */
- /* order to resize the text in real-time while it is moved/resized, just call */
- /* the [RefreshPanes] function when the status bar is asked to be erased. */
- /*--- END FUNCTION HEADER ----------------------------------------------------*/
- BOOL CSkinProgress::OnEraseBkgnd
- (
- CDC* i_poDC
- )
- {
- BOOL bResult;
- // Init
- // A..... Erase the background
- bResult = CStatic::OnEraseBkgnd(i_poDC);
- // Process
- // B..... Resize and display the text
- RefreshPanes();
- // Return
- return bResult;
- }
- BEGIN_MESSAGE_MAP(CSkinProgress, CStatic)
- //{{AFX_MSG_MAP(CSkinProgress)
- ON_WM_ERASEBKGND()
- ON_WM_PAINT()
- ON_WM_TIMER()
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CSkinProgress message handlers
- /*--- START FUNCTION HEADER --------------------------------------------------*/
- /* Name : OnPaint */
- /* Role : Repaint the progress bar according to its new size */
- /* Type : PROTECTED */
- /* Interface : RETURN (direct value) */
- /* None */
- /* OUTPUT (pointer to value) */
- /* None */
- /* INPUT (pointer to value, direct/default value) */
- /* None */
- /* Pre-condition : None */
- /* Constraints : None */
- /* Behavior : A - Update values, get dimension and check refresh */
- /* B - Set variables for calculation */
- /* C - Draw the progress bar */
- /* D - Display the progress bar */
- /*----------------------------------------------------------------------------*/
- /* PROC OnPaint */
- /* */
- /* A..... Update values, get dimension and check refresh */
- /* [IF the progress bar needs to be refreshed] */
- /* : B..... Set variables for calculation */
- /* : C..... Draw the progress bar */
- /* : [IF the progress bar size is different from the previous time] */
- /* : : CA.... Redraw the complete bar from scratch */
- /* : : [IF the progress bar was existing] */
- /* : : : CAA... Delete the previous progress bar bitmap */
- /* : : [ENDIF] */
- /* : : CAB... Create the new progress bar bitmap with the new dimension */
- /* : [ENDIF] */
- /* : CB.... Select the DC on the progress bar bitmap */
- /* : [IF the progress bar size is different from the previous time] */
- /* : : CC.... Start the complete redraw of the progress bar from the end */
- /* : : CCA... Draw the background element */
- /* : : CCAA.. Draw the background element at the most right position */
- /* : : [UNTIL the right end of the progress bar is not reached] */
- /* : : : CCAB.. Draw background element until the right end of the bar */
- /* : : [NEXT] */
- /* : : CCB... Save the previous position of the end of the progress bar */
- /* : : CCC... Draw the bar element */
- /* : : CCCA.. Reset the drawing position on a base of an element's width */
- /* : : [UNTIL the beginning is not reached] */
- /* : : : CCCB.. Draw the bar element until the left end of the bar */
- /* : : [NEXT] */
- /* : : CCD... Draw the center element */
- /* : : [IF not under the start element] */
- /* : : : CCE... Draw the before-left element */
- /* : : [ENDIF] */
- /* : : [IF not under the end element] */
- /* : : : CCF... Draw the after-right element */
- /* : : [ENDIF] */
- /* : : CCG... Draw the start element */
- /* : : CCH... Draw the end element */
- /* : : CCI... Draw the left element of the bar */
- /* : : CCJ... Draw the right element of the bar */
- /* : [ELSE] */
- /* : : CD.... Modify the moved elements without redrawing everything */
- /* : : CDA... Start to update the progress bar from the previous position */
- /* : : [IF going backward (Oh my God, could it be possible ?)] */
- /* : : : CDB... Going backward */
- /* : : : CDBA.. Draw background to replace the end of the progress bar */
- /* : : : CDBB.. Reset drawing position on a base of an element's width */
- /* : : : [UNTIL the right end of the progress bar is not reached] */
- /* : : : : CDBC.. Draw the background until the right end of the bar */
- /* : : : [NEXT] */
- /* : : [ELSE] */
- /* : : : CDC... Going forward */
- /* : : : CDCA.. Draw the bar element to replace the progress bar end */
- /* : : : CDCB.. Reset drawing position on a base of an element's width */
- /* : : : [UNTIL the right end of the progress bar is not reached] */
- /* : : : : CDCC.. Draw the progress bar until the right end of the bar */
- /* : : : [NEXT] */
- /* : : [ENDIF] */
- /* : : CDD... Draw the center element */
- /* : : [IF moved AND not under the start element] */
- /* : : : CDE... Draw the before-left element */
- /* : : [ENDIF] */
- /* : : [IF moved AND not under the end element] */
- /* : : : CDF... Draw the after-right element */
- /* : : [ENDIF] */
- /* : : [IF modifed by BEFORE or LEFT or CENTER] */
- /* : : : CDG... Draw the start element */
- /* : : [ENDIF] */
- /* : : [IF modifed by CENTER or RIGHT or AFTER] */
- /* : : : CDH... Draw the end element */
- /* : : [ENDIF] */
- /* : : [IF LEFT moved OR RIGHT too close from LEFT] */
- /* : : : CDI... Draw the left element of the bar */
- /* : : [ENDIF] */
- /* : : [IF RIGHT moved OR LEFT too close from RIGHT] */
- /* : : : CDJ... Draw the right element of the bar */
- /* : : [ENDIF] */
- /* : [ENDIF] */
- /* : D..... Display the progress bar */
- /* [ENDIF] */
- /*----------------------------------------------------------------------------*/
- /* Specific details about the dCSP_SLIDERBAR_METHOD or the dCSP_VERTICAL_BAR */
- /* are not provided because beyon the scope of the class. The code is also */
- /* fully functionnal, but is not yet intented to be used. It will surely be */
- /* a near update. But right now, anyone who wants to understand how slider */
- /* bars and/or vertical bars works just have to understand first how the */
- /* progress bars works. Hope there is enough comments for this purpose ;p */
- /*--- END FUNCTION HEADER ----------------------------------------------------*/
- void CSkinProgress::OnPaint
- ( // On redraw event
- )
- {
- CPaintDC oDC(this); // Device context for painting - Do not call CStatic::OnPaint() for painting messages
- CDC oDcProgress; // CompatibleDC
- CBitmap* poOldBitmap; // oDC's previous bitmap
- CRect oRectPaint;
- int nCurrentPos; // Pos of the current calculated position
- int nStepPos;
- // LPPAINTSTRUCT sPaintStruct;
- // Init
- // Process
- // A..... Update the progress bar elements position and get the progress bar dimension
- UpdateProgress(&oRectPaint); // the CStatic currently being repaint
- // BeginPaint(sPaintStruct);
- // B...... Set variables for calculation
- #ifdef dCSP_VERTICAL_BAR
- if(m_bVertical == false)
- { // Horizontal bar
- #endif // dCSP_VERTICAL_BAR
- nStepPos = m_nBmpWidth;
- #ifdef dCSP_VERTICAL_BAR
- }
- else
- { // Vertical bar
- nStepPos = m_nBmpHeight;
- }
- #endif // dCSP_VERTICAL_BAR
- // C..... Draw the progress bar
- if( // If the SIZE (don't mind the position) of the ProgressBar has changed
- (oRectPaint.Width() != m_oRectPaint.Width())
- || (oRectPaint.Height() != m_oRectPaint.Height())
- )
- { // If the progress bar size has changed
- // CA.... Redraw the complete bar from scratch
- if(m_poProgressBmp != NULL)
- { // If the ProgressBitmap already exists, delete it and create a new one with the new dimension of the pane
- // CAA... Delete the previous progress bar bitmap
- delete m_poProgressBmp;
- }else{}
- // CAB... Create the new progress bar bitmap with the new dimension
- m_poProgressBmp = new CBitmap;
- m_poProgressBmp->CreateCompatibleBitmap(&oDC, oRectPaint.Width(), oRectPaint.Height()); // *ALWAYS* use '&oDC', *NEVER* '&oDcProgress' otherwise you'll get a monochrom image
- }else{}
- // CB.... Select the DC on the progress bar bitmap
- oDcProgress.CreateCompatibleDC(&oDC);
- poOldBitmap = oDcProgress.SelectObject(m_poProgressBmp);
- if( // If the SIZE (don't mind the position) of the ProgressBar has changed
- (oRectPaint.Width() != m_oRectPaint.Width())
- || (oRectPaint.Height() != m_oRectPaint.Height())
- )
- { // If the ProgressBar has changed, redraw it completly
- // CC.... Start the complete redraw of the progress bar from the end
- // Background
- // CCA... Draw the background element
- // CCAA.. Draw the background element from the most right position
- nCurrentPos = m_nEndAff - (m_nEndAff % nStepPos);
- for(; nCurrentPos > m_nRightAff; nCurrentPos -= nStepPos)
- {
- // CCAB.. Draw the background element until the right end of the bar
- #ifdef dCSP_VERTICAL_BAR
- if(m_bVertical == false)
- { // Horizontal bar
- #endif // dCSP_VERTICAL_BAR
- m_oBarImgLst.Draw(&oDcProgress, cSPB_BACKGROUND, CPoint(nCurrentPos, 0), ILD_NORMAL);
- #ifdef dCSP_VERTICAL_BAR
- }
- else
- { // Vertical bar
- m_oBarImgLst.Draw(&oDcProgress, cSPB_BACKGROUND, CPoint(0, nCurrentPos), ILD_NORMAL);
- }
- #endif // dCSP_VERTICAL_BAR
- }
- // CCB... Save the previous position of the end of the progress bar
- // Position of the end of the bar
- m_nPrevRightAff = m_nRightAff;
- // CCC... Draw the bar element
- // Bar
- // CCCA.. Reset the drawing position on a base of the image list element's width
- nCurrentPos -= (nCurrentPos % nStepPos);
- #ifndef dCSP_SLIDERBAR_METHOD
- for(; nCurrentPos >= nStepPos; nCurrentPos -= nStepPos) // For m_nLeft-less progress bar routine
- #else
- for(; nCurrentPos >= m_nLeftAff; nCurrentPos -= nStepPos)
- #endif // dCSP_SLIDERBAR_METHOD
- {
- // CCCB.. Draw the bar element until the left end of the bar
- #ifdef dCSP_VERTICAL_BAR
- if(m_bVertical == false)
- { // Horizontal bar
- #endif // dCSP_VERTICAL_BAR
- m_oBarImgLst.Draw(&oDcProgress, cSPB_BAR, CPoint(nCurrentPos, 0), ILD_NORMAL);
- #ifdef dCSP_VERTICAL_BAR
- }
- else
- { // Vertical bar
- m_oBarImgLst.Draw(&oDcProgress, cSPB_BAR, CPoint(0, nCurrentPos), ILD_NORMAL);
- }
- #endif // dCSP_VERTICAL_BAR
- }
- #ifdef dCSP_SLIDERBAR_METHOD
- // Position of the beginning of the bar
- m_nPrevLeftAff = m_nLeftAff;
- // Background
- nCurrentPos -= (nCurrentPos % nStepPos);
- for(; nCurrentPos >= nStepPos; nCurrentPos -= nStepPos)
- {
- #ifdef dCSP_VERTICAL_BAR
- if(m_bVertical == false)
- { // Horizontal bar
- #endif // dCSP_VERTICAL_BAR
- m_oBarImgLst.Draw(&oDcProgress, cSPB_BACKGROUND, CPoint(nCurrentPos, 0), ILD_NORMAL);
- #ifdef dCSP_VERTICAL_BAR
- }
- else
- { // Vertical bar
- m_oBarImgLst.Draw(&oDcProgress, cSPB_BACKGROUND, CPoint(0, nCurrentPos), ILD_NORMAL);
- }
- #endif // dCSP_VERTICAL_BAR
- }
- #endif // dCSP_SLIDERBAR_METHOD
- // CCD... Draw the center element
- // Center
- #ifdef dCSP_VERTICAL_BAR
- if(m_bVertical == false)
- { // Horizontal bar
- #endif // dCSP_VERTICAL_BAR
- #ifndef dCSP_SLIDERBAR_METHOD
- m_oBarImgLst.Draw(&oDcProgress, cSPB_CENTER, CPoint(m_nRightAff >> 1, 0), ILD_NORMAL);
- #else
- m_oBarImgLst.Draw(&oDcProgress, cSPB_CENTER, CPoint((m_nLeftAff + m_nRightAff) >> 1, 0), ILD_NORMAL);
- #endif // dCSP_SLIDERBAR_METHOD
- #ifdef dCSP_VERTICAL_BAR
- }
- else
- { // Vertical bar
- #ifndef dCSP_SLIDERBAR_METHOD
- m_oBarImgLst.Draw(&oDcProgress, cSPB_CENTER, CPoint(0, m_nRightAff >> 1), ILD_NORMAL);
- #else
- m_oBarImgLst.Draw(&oDcProgress, cSPB_CENTER, CPoint(0, (m_nLeftAff + m_nRightAff) >> 1), ILD_NORMAL);
- #endif // dCSP_SLIDERBAR_METHOD
- }
- #endif // dCSP_VERTICAL_BAR
- // CCE... Draw the before-left element
- // Before
- #ifdef dCSP_SLIDERBAR_METHOD
- if(m_nLeftAff > nStepPos)
- {
- #ifdef dCSP_VERTICAL_BAR
- if(m_bVertical == false)
- { // Horizontal bar
- #endif // dCSP_VERTICAL_BAR
- m_oBarImgLst.Draw(&oDcProgress, cSPB_BEFORE, CPoint(m_nLeftAff - m_nBmpWidth, 0), ILD_NORMAL);
- #ifdef dCSP_VERTICAL_BAR
- }
- else
- { // Vertical bar
- m_oBarImgLst.Draw(&oDcProgress, cSPB_BEFORE, CPoint(0, m_nLeftAff - m_nBmpHeight), ILD_NORMAL);
- }
- #endif // dCSP_VERTICAL_BAR
- }else{}
- #endif // dCSP_SLIDERBAR_METHOD
- // CCF... Draw the after-right element
- // After
- if(m_nRightAff < (m_nEndAff - nStepPos))
- {
- #ifdef dCSP_VERTICAL_BAR
- if(m_bVertical == false)
- { // Horizontal bar
- #endif // dCSP_VERTICAL_BAR
- m_oBarImgLst.Draw(&oDcProgress, cSPB_AFTER, CPoint(m_nRightAff + m_nBmpWidth, 0), ILD_NORMAL);
- #ifdef dCSP_VERTICAL_BAR
- }
- else
- { // Vertical bar
- m_oBarImgLst.Draw(&oDcProgress, cSPB_AFTER, CPoint(0, m_nRightAff + m_nBmpHeight), ILD_NORMAL);
- }
- #endif // dCSP_VERTICAL_BAR
- }else{}
- // CCG... Draw the start element
- // Start
- #ifdef dCSP_SLIDERBAR_METHOD
- m_oBarImgLst.Draw(&oDcProgress, cSPB_START, CPoint(0, 0), ILD_NORMAL);
- #endif // dCSP_SLIDERBAR_METHOD
- // CCH... Draw the end element
- // End
- #ifdef dCSP_VERTICAL_BAR
- if(m_bVertical == false)
- { // Horizontal bar
- #endif // dCSP_VERTICAL_BAR
- m_oBarImgLst.Draw(&oDcProgress, cSPB_END, CPoint(m_nEndAff, 0), ILD_NORMAL);
- #ifdef dCSP_VERTICAL_BAR
- }
- else
- { // Vertical bar
- m_oBarImgLst.Draw(&oDcProgress, cSPB_END, CPoint(0, m_nEndAff), ILD_NORMAL);
- }
- #endif // dCSP_VERTICAL_BAR
- // CCI... Draw the left element of the bar
- // Left
- #ifdef dCSP_VERTICAL_BAR
- if(m_bVertical == false)
- { // Horizontal bar
- #endif // dCSP_VERTICAL_BAR
- #ifndef dCSP_SLIDERBAR_METHOD
- m_oBarImgLst.Draw(&oDcProgress, cSPB_LEFT, CPoint(0, 0), ILD_NORMAL); // For m_nLeft-less progress bar routine
- #else
- m_oBarImgLst.Draw(&oDcProgress, cSPB_LEFT, CPoint(m_nLeftAff, 0), ILD_NORMAL);
- #endif // dCSP_SLIDERBAR_METHOD
- #ifdef dCSP_VERTICAL_BAR
- }
- else
- { // Vertical bar
- #ifndef dCSP_SLIDERBAR_METHOD
- m_oBarImgLst.Draw(&oDcProgress, cSPB_TOP, CPoint(0, 0), ILD_NORMAL); // For m_nLeft-less progress bar routine
- #else
- m_oBarImgLst.Draw(&oDcProgress, cSPB_TOP, CPoint(0, m_nLeftAff), ILD_NORMAL);
- #endif // dCSP_SLIDERBAR_METHOD
- }
- #endif // dCSP_VERTICAL_BAR
- // CCJ// Car... Draw the right element of the bar
- // Right
- #ifdef dCSP_VERTICAL_BAR
- if(m_bVertical == false)
- { // Horizontal bar
- #endif // dCSP_VERTICAL_BAR
- m_oBarImgLst.Draw(&oDcProgress, cSPB_RIGHT, CPoint(m_nRightAff, 0), ILD_NORMAL);
- #ifdef dCSP_VERTICAL_BAR
- }
- else
- { // Vertical bar
- m_oBarImgLst.Draw(&oDcProgress, cSPB_BOTTOM, CPoint(0, m_nRightAff), ILD_NORMAL);
- }
- #endif // dCSP_VERTICAL_BAR
- m_nPrevEndAff = m_nEndAff;
- m_oRectPaint = oRectPaint;
- }
- else
- {
- // CD.... Modify the moved elements without redrawing the complete progress bar
- if(m_nPrevRightAff != m_nRightAff)
- {
- // CDA... Start to update the progress bar from the previous position
- nCurrentPos = m_nPrevRightAff;
- if(m_nRightAff < m_nPrevRightAff)
- { // If going backward, draw BACKGROUND and last with RIGHT
- // CDB... Going backward
- // CDBA.. Draw the background element to replace the end of the progress bar
- m_oBarImgLst.Draw(&oDcProgress, cSPB_BACKGROUND, CPoint(nCurrentPos, 0), ILD_NORMAL);
- // CDBB.. Reset the drawing position on a base of the image list element's width
- nCurrentPos -= (nCurrentPos % nStepPos);
- for(; nCurrentPos > m_nRightAff; nCurrentPos -= nStepPos)
- {
- // CDBC.. Draw the background element until the right end of the bar
- #ifdef dCSP_VERTICAL_BAR
- if(m_bVertical == false)
- { // Horizontal bar
- #endif // dCSP_VERTICAL_BAR
- m_oBarImgLst.Draw(&oDcProgress, cSPB_BACKGROUND, CPoint(nCurrentPos, 0), ILD_NORMAL);
- #ifdef dCSP_VERTICAL_BAR
- }
- else
- { // Vertical bar
- m_oBarImgLst.Draw(&oDcProgress, cSPB_BACKGROUND, CPoint(0, nCurrentPos), ILD_NORMAL);
- }
- #endif // dCSP_VERTICAL_BAR
- }
- }
- else
- { // If going forward, draw BAR and last with RIGHT
- // CDC... Going forward
- // CDCA.. Draw the progress bar element to replace the end of the progress bar
- m_oBarImgLst.Draw(&oDcProgress, cSPB_BAR, CPoint(nCurrentPos, 0), ILD_NORMAL);
- // CDCB.. Reset the drawing position on a base of the image list element's width
- nCurrentPos += nStepPos;
- nCurrentPos -= (nCurrentPos % nStepPos);
- for(; nCurrentPos < m_nRightAff; nCurrentPos += nStepPos)
- {
- // CDCC.. Draw the progress bar element until the right end of the bar
- #ifdef dCSP_VERTICAL_BAR
- if(m_bVertical == false)
- { // Horizontal bar
- #endif // dCSP_VERTICAL_BAR
- m_oBarImgLst.Draw(&oDcProgress, cSPB_BAR, CPoint(nCurrentPos, 0), ILD_NORMAL);
- #ifdef dCSP_VERTICAL_BAR
- }
- else
- { // Vertical bar
- m_oBarImgLst.Draw(&oDcProgress, cSPB_BAR, CPoint(0, nCurrentPos), ILD_NORMAL);
- }
- #endif // dCSP_VERTICAL_BAR
- }
- }
- }else{}
- #ifdef dCSP_SLIDERBAR_METHOD
- if(m_nLeftAff!= m_nPrevLeftAff)
- {
- nCurrentPos = m_nPrevLeftAff;
- if(m_nLeftAff < m_nPrevLeftAff)
- { // If going backward, draw BAR and last with LEFT
- m_oBarImgLst.Draw(&oDcProgress, cSPB_BAR, CPoint(nCurrentPos, 0), ILD_NORMAL);
- nCurrentPos -= (nCurrentPos % nStepPos);
- for(; nCurrentPos > m_nLeftAff; nCurrentPos -= nStepPos)
- {
- #ifdef dCSP_VERTICAL_BAR
- if(m_bVertical == false)
- { // Horizontal bar
- #endif // dCSP_VERTICAL_BAR
- m_oBarImgLst.Draw(&oDcProgress, cSPB_BAR, CPoint(nCurrentPos, 0), ILD_NORMAL);
- #ifdef dCSP_VERTICAL_BAR
- }
- else
- { // Vertical bar
- m_oBarImgLst.Draw(&oDcProgress, cSPB_BAR, CPoint(0, nCurrentPos), ILD_NORMAL);
- }
- #endif // dCSP_VERTICAL_BAR
- }
- }
- else
- { // If going forward, draw BACKGROUND and last with LEFT
- m_oBarImgLst.Draw(&oDcProgress, cSPB_BACKGROUND, CPoint(nCurrentPos, 0), ILD_NORMAL);
- nCurrentPos += nStepPos;
- nCurrentPos -= (nCurrentPos % nStepPos);
- for(; nCurrentPos < m_nLeftAff; nCurrentPos += nStepPos)
- {
- #ifdef dCSP_VERTICAL_BAR
- if(m_bVertical == false)
- { // Horizontal bar
- #endif // dCSP_VERTICAL_BAR
- m_oBarImgLst.Draw(&oDcProgress, cSPB_BACKGROUND, CPoint(nCurrentPos, 0), ILD_NORMAL);
- #ifdef dCSP_VERTICAL_BAR
- }
- else
- { // Vertical bar
- m_oBarImgLst.Draw(&oDcProgress, cSPB_BACKGROUND, CPoint(0, nCurrentPos), ILD_NORMAL);
- }
- #endif // dCSP_VERTICAL_BAR
- }
- }
- }else{}
- #endif // dCSP_SLIDERBAR_METHOD
- // CDD... Draw the center element
- if(
- (m_nPrevRightAff != m_nRightAff)
- #ifdef dCSP_SLIDERBAR_METHOD
- || (m_nPrevLeftAff != m_nLeftAff)
- #endif // dCSP_SLIDERBAR_METHOD
- )
- {
- #ifdef dCSP_VERTICAL_BAR
- if(m_bVertical == false)
- { // Horizontal bar
- #endif // dCSP_VERTICAL_BAR
- #ifndef dCSP_SLIDERBAR_METHOD
- m_oBarImgLst.Draw(&oDcProgress, cSPB_CENTER, CPoint(m_nRightAff >> 1, 0), ILD_NORMAL);
- #else
- m_oBarImgLst.Draw(&oDcProgress, cSPB_CENTER, CPoint((m_nLeftAff + m_nRightAff) >> 1, 0), ILD_NORMAL);
- #endif // dCSP_SLIDERBAR_METHOD
- #ifdef dCSP_VERTICAL_BAR
- }
- else
- { // Vertical bar
- #ifndef dCSP_SLIDERBAR_METHOD
- m_oBarImgLst.Draw(&oDcProgress, cSPB_CENTER, CPoint(0, m_nRightAff >> 1), ILD_NORMAL);
- #else
- m_oBarImgLst.Draw(&oDcProgress, cSPB_CENTER, CPoint(0, (m_nLeftAff + m_nRightAff) >> 1), ILD_NORMAL);
- #endif // dCSP_SLIDERBAR_METHOD
- }
- #endif // dCSP_VERTICAL_BAR
- }
- // CDE... Draw the before-left element
- // Before
- #ifdef dCSP_SLIDERBAR_METHOD
- if(m_nPrevLeftAff != m_nLeftAff)
- {
- if(m_nLeftAff > nStepPos)
- {
- #ifdef dCSP_VERTICAL_BAR
- if(m_bVertical == false)
- { // Horizontal bar
- #endif // dCSP_VERTICAL_BAR
- m_oBarImgLst.Draw(&oDcProgress, cSPB_BEFORE, CPoint(m_nLeftAff - nStepPos, 0), ILD_NORMAL);
- #ifdef dCSP_VERTICAL_BAR
- }
- else
- { // Vertical bar
- m_oBarImgLst.Draw(&oDcProgress, cSPB_BEFORE, CPoint(0, m_nLeftAff - nStepPos), ILD_NORMAL);
- }
- #endif // dCSP_VERTICAL_BAR
- }else{}
- }else{}
- #endif // dCSP_SLIDERBAR_METHOD
- // CDF... Draw the after-right element
- // After
- if(m_nRightAff != m_nPrevRightAff)
- {
- if(m_nRightAff < (m_nEndAff - nStepPos))
- {
- #ifdef dCSP_VERTICAL_BAR
- if(m_bVertical == false)
- { // Horizontal bar
- #endif // dCSP_VERTICAL_BAR
- m_oBarImgLst.Draw(&oDcProgress, cSPB_AFTER, CPoint(m_nRightAff + nStepPos, 0), ILD_NORMAL);
- #ifdef dCSP_VERTICAL_BAR
- }
- else
- { // Vertical bar
- m_oBarImgLst.Draw(&oDcProgress, cSPB_AFTER, CPoint(0, m_nRightAff + nStepPos), ILD_NORMAL);
- }
- #endif // dCSP_VERTICAL_BAR
- }else{}
- }else{}
- // CDG... Draw the start element
- // Start
- #ifdef dCSP_SLIDERBAR_METHOD
- if(m_nPrevLeftAff != m_nLeftAff)
- #else
- if(m_nPrevRightAff != m_nRightAff) // In non-<dCSP_SLIDERBAR_METHOD> mode, only the right end can move
- #endif // dCSP_SLIDERBAR_METHOD
- {
- #ifdef dCSP_SLIDERBAR_METHOD
- if(m_nLeftAff < (nStepPos << 1))
- #else
- if(m_nRightAff < (nStepPos << 1)) // In non-<dCSP_SLIDERBAR_METHOD> mode, only the right end can move
- #endif // dCSP_SLIDERBAR_METHOD
- { // If the START element was over-written, refresh it
- m_oBarImgLst.Draw(&oDcProgress, cSPB_START, CPoint(0, 0), ILD_NORMAL);
- }else{}
- }else{}
- // CDH... Draw the end element
- // End
- if(m_nPrevRightAff != m_nRightAff)
- {
- if(m_nRightAff > (m_nEndAff - (nStepPos << 1)))
- { // If the END element was over-written, refresh it
- #ifdef dCSP_VERTICAL_BAR
- if(m_bVertical == false)
- { // Horizontal bar
- #endif // dCSP_VERTICAL_BAR
- m_oBarImgLst.Draw(&oDcProgress, cSPB_END, CPoint(m_nEndAff, 0), ILD_NORMAL);
- #ifdef dCSP_VERTICAL_BAR
- }
- else
- { // Vertical bar
- m_oBarImgLst.Draw(&oDcProgress, cSPB_END, CPoint(0, m_nEndAff), ILD_NORMAL);
- }
- #endif // dCSP_VERTICAL_BAR
- }else{}
- }else{}
- // CDI... Draw the left element of the bar
- #ifdef dCSP_SLIDERBAR_METHOD
- if( // In case of slider display, the closeness of the RIGHT element from the LEFT can cause an over-write of the LEFT element with BAR and/or CENTER
- (m_nPrevLeftAff != m_nLeftAff)
- || (m_nRightAff < (m_nLeftAff + (nStepPos << 1)))
- )
- {
- // Position of the start of the bar
- m_nPrevLeftAff = m_nLeftAff;
- #ifdef dCSP_VERTICAL_BAR
- if(m_bVertical == false)
- { // Horizontal bar
- #endif // dCSP_VERTICAL_BAR
- // Left
- m_oBarImgLst.Draw(&oDcProgress, cSPB_LEFT, CPoint(m_nLeftAff, 0), ILD_NORMAL);
- #ifdef dCSP_VERTICAL_BAR
- }
- else
- { // Vertical bar
- // Top
- m_oBarImgLst.Draw(&oDcProgress, cSPB_TOP, CPoint(0, m_nLeftAff), ILD_NORMAL);
- }
- #endif // dCSP_VERTICAL_BAR
- }else{}
- #else
- // As long as the RIGHT element is too close from the LEFT element, the CENTER element over-writes the LEFT element, thus we have to refresh the LEFT element
- if(m_nRightAff < (nStepPos << 1))
- {
- #ifdef dCSP_VERTICAL_BAR
- if(m_bVertical == false)
- { // Horizontal bar
- #endif // dCSP_VERTICAL_BAR
- // Left
- m_oBarImgLst.Draw(&oDcProgress, cSPB_LEFT, CPoint(0, 0), ILD_NORMAL);
- #ifdef dCSP_VERTICAL_BAR
- }
- else
- { // Vertical bar
- // Top
- m_oBarImgLst.Draw(&oDcProgress, cSPB_TOP, CPoint(0, 0), ILD_NORMAL);
- }
- #endif // dCSP_VERTICAL_BAR
- }else{}
- #endif // dCSP_SLIDERBAR_METHOD
- // CDJ... Draw the right element of the bar
- if( // In case of slider display, the closeness of the LEFT element from the RIGHT can cause an over-write of the RIGHT element with BAR and/or CENTER
- (m_nPrevRightAff != m_nRightAff)
- #ifdef dCSP_SLIDERBAR_METHOD
- || (m_nLeftAff> (m_nRightAff - (nStepPos << 1)))
- #endif // dCSP_SLIDERBAR_METHOD
- )
- {
- // Position of the end of the bar
- m_nPrevRightAff = m_nRightAff;
- #ifdef dCSP_VERTICAL_BAR
- if(m_bVertical == false)
- { // Horizontal bar
- #endif // dCSP_VERTICAL_BAR
- // Right
- m_oBarImgLst.Draw(&oDcProgress, cSPB_RIGHT, CPoint(m_nRightAff, 0), ILD_NORMAL);
- #ifdef dCSP_VERTICAL_BAR
- }
- else
- { // Vertical bar
- // Cottom
- m_oBarImgLst.Draw(&oDcProgress, cSPB_BOTTOM, CPoint(0, m_nRightAff), ILD_NORMAL);
- }
- #endif // dCSP_VERTICAL_BAR
- }else{}
- if(m_nPrevEndAff != m_nEndAff)
- {
- m_nPrevEndAff = m_nEndAff;
- }else{}
- }
- // D..... Display the progress bar
- // Copy the progress bitmap each time the object have to be refreshed
- #ifndef dCSP_DISPLAY_STRETCH
- oDC.BitBlt(0, 0, oRectPaint.Width(), oRectPaint.Height(), &oDcProgress, 0, 0, SRCCOPY);
- #else
- CDC oDcStretch; // CompatibleDC
- CBitmap* poOldStretch; // oDC's previous bitmap
- BITMAP sStretchBmp;
- oDcStretch.CreateCompatibleDC(&oDC);
- poOldStretch = oDcStretch.SelectObject(m_poStretchBmp);
- m_poStretchBmp->GetBitmap(&sStretchBmp);
- oDC.BitBlt(0, 0, sStretchBmp.bmWidth, sStretchBmp.bmHeight, &oDcStretch, 0, 0, SRCCOPY);
- oDcStretch.SelectObject(poOldStretch);
- oDcStretch.DeleteDC();
- #endif // dCSP_DISPLAY_STRETCH
- // Release the DC
- oDcProgress.SelectObject(poOldBitmap);
- oDcProgress.DeleteDC();
- // EndPaint(sPaintStruct);
- }
- /*--- START FUNCTION HEADER --------------------------------------------------*/
- /* Name : OnSizing */
- /* Role : Before things are resized */
- /* Type : PROTECTED */
- /* Interface : RETURN (direct value) */
- /* None */
- /* OUTPUT (pointer to value) */
- /* None */
- /* INPUT (pointer to value, direct/default value) */
- /* fwSide : Edge of window to be moved */
- /* pRect : New rectangle */
- /* Pre-condition : None */
- /* Constraints : None */
- /* Behavior : A - Resize the object */
- /* B - Resize the text */
- /*----------------------------------------------------------------------------*/
- /* PROC OnSizing */
- /* */
- /* A..... Resize the object */
- /* B..... Resize the text */
- /*----------------------------------------------------------------------------*/
- /* In normal cases, this is NEVER called */
- /*--- END FUNCTION HEADER ----------------------------------------------------*/
- void CSkinProgress::OnSizing
- (
- UINT fwSide, // Edge of window to be moved
- LPRECT pRect // New rectangle
- )
- {
- // A..... Resize the object
- CStatic::OnSizing(fwSide, pRect);
- // Process
- // B..... Resize the text
- RefreshPanes(); // Recalculate text layout on sizing the window
- }
- /*--- START FUNCTION HEADER --------------------------------------------------*/
- /* Name : OnSize */
- /* Role : Once things were resized */
- /* Type : PROTECTED */
- /* Interface : RETURN (direct value) */
- /* None */
- /* OUTPUT (pointer to value) */
- /* None */
- /* INPUT (pointer to value, direct/default value) */
- /* nType : Type of resizing requested */
- /* cx : Width */
- /* cy : Height */
- /* Pre-condition : None */
- /* Constraints : None */
- /* Behavior : A - Transmit the new dimensions */
- /*----------------------------------------------------------------------------*/
- /* PROC OnSize */
- /* */
- /* A..... Transmit the new dimensions */
- /*----------------------------------------------------------------------------*/
- /* Just over-ridden, ready to use for various purposes ;) */
- /*--- END FUNCTION HEADER ----------------------------------------------------*/
- void CSkinProgress::OnSize
- (
- UINT nType, // Type of resizing requested
- int cx, // Width
- int cy // Height
- )
- {
- // A..... Transmit the new dimensions
- CStatic::OnSize(nType, cx, cy);
- }
- /*--- START FUNCTION HEADER --------------------------------------------------*/
- /* Name : OnTimer */
- /* Role : The object timer has elapsed */
- /* Type : PROTECTED */
- /* Interface : RETURN (direct value) */
- /* None */
- /* OUTPUT (pointer to value) */
- /* None */
- /* INPUT (pointer to value, direct/default value) */
- /* nIDEvent : The Timer handle that elapsed */
- /* Pre-condition : None */
- /* Constraints : None */
- /* Behavior : A - Refresh the text and the progress bar */
- /* B - Transmit the Timer handle to the parent */
- /*----------------------------------------------------------------------------*/
- /* PROC OnTimer */
- /* */
- /* A..... Refresh the text and the progress bar */
- /* B..... Transmit the Timer handle to the parent */
- /*----------------------------------------------------------------------------*/
- /* Just used to refresh the timed message when things are going too slow... */
- /* Also used when on time redrawing the progress bar, to limit to 50 refresh */
- /* per second... */
- /*--- END FUNCTION HEADER ----------------------------------------------------*/
- void CSkinProgress::OnTimer
- ( // On a Timer event
- UINT nIDEvent
- )
- {
- if(nIDEvent == (UINT) this) // Use object's unique address as timer identifier
- {
- // A..... Refresh the text and the progress bar
- RefreshPanes(); // Refresh the whole stuff, each 500 ms or 20 ms if in dCSP_TIMED_REDRAW mode
- }else{}
- // B..... Transmit the Timer handle to the parent
- CStatic::OnTimer(nIDEvent);
- }