CPackage::OnStatus

The CPackage::OnStatus function performs user-defined actions following firing of a status event.

BOOL OnStatus(
LPPATCH_STATUS_INFORMATION lpInfo // pointer to status information structure
);

Parameters

lpInfo
[in] Pointer to status information structure.

Return Values

The default implementation returns TRUE in all circumstances.

A return value of FALSE will cause whatever method of the class that was running when the event fired to return with an error.

Remarks

This is a virtual function that may be implemented in a class derived from CPackage. The default implementation does nothing but return a value of TRUE. CPackage::OnStatus is called by an internal callback function defined within the class. The internal callback function is called whenever a method of the class such as CPackage::CreatePackage or CPackage::ApplyPackage has status information to report. The name of the internal callback function is InternalCallback. It is a private member of the CPackage class. DO NOT modify it.

An implementation of OnStatus in a class derived from CPackage may (for example):

  • Report the name of the file currently being processed to a status window.
  • Update a progress bar.
  • Process a user's Cancel action.

Example

Here is an implementation of OnStatus that is used in a dialog application that does all of the processing listed under Remarks:

    CBuildguiDlg* pdlg;

    // Allow other events in the application to be processed,
    // Such as button-presses.

    MSG msg;
    while (::PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE))
    {
        if (!AfxGetThread()->PumpMessage())
        {
            ::PostQuitMessage(0);
            return FALSE;
        }
    }

    // Allow MFC do its idle processing
    LONG lIdle = 0;
    while ( AfxGetApp()->OnIdle(lIdle++ ) )
        ;

    // Check whether the user has cancelled the current operation.
    // Exiting here with FALSE will cause that operation to end,
    // with an error.
    if (m_bCancel)
        return FALSE;

    // Get a pointer to the main dialog window
    pdlg = (CBuildguiDlg*) theApp.m_pMainWnd;

    // If this is the first time this virtual function has been called
    // then initialize the timer for the reporting phase of the operation.
    if (m_dwMidTime == 0L)
        m_dwMidTime = GetTickCount();

    // Update the progress bar
    pdlg->m_pbar.SetPos(lpInfo->dwTotalProgress);

    // Only update the status report once per package file
    if (strcmp(lpInfo->szFileName,m_szPrevStatusFile) == 0)
        return TRUE;
    pdlg->UpdateStatus(lpInfo->szFileName);
    strcpy(m_szPrevStatusFile,lpInfo->szFileName);

    return TRUE;

Requirements

Windows NT/2000/XP: Requires Windows NT 4.0 SP3 or later.
Windows 95/98: Requires Windows 95 or later.
Header: Include apatch.h.
Library: Use apatch32.lib.
Unicode: Implemented as Unicode and ANSI versions on Windows NT/2000/XP.

See Also

PATCH_STATUS_INFORMATION, CPackage::ApplyPackage, CPackage::CreatePackage, CPackage::OpenPackage