Delen via


CWinApp Class

The base class from which you derive a Windows application object.

class CWinApp : public CWinThread

Members

Public Constructors

Name

Description

CWinApp::CWinApp

Constructs a CWinApp object.

Public Methods

Name

Description

CWinApp::AddDocTemplate

Adds a document template to the application's list of available document templates.

CWinApp::AddToRecentFileList

Adds a filename to the most recently used (MRU) file list.

CWinApp::ApplicationRecoveryCallback

Called by the framework when the application unexpectedly exits.

CWinApp::CloseAllDocuments

Closes all open documents.

CWinApp::CreatePrinterDC

Creates a printer device context.

CWinApp::DelRegTree

Deletes a specified key and all its subkeys.

CWinApp::DoMessageBox

Implements AfxMessageBox for the application.

CWinApp::DoWaitCursor

Turns the wait cursor on and off.

CWinApp::EnableD2DSupport

Enables application D2D support. Call this method before the main window is initialized.

CWinApp::EnableHtmlHelp

Implements HTMLHelp for the application, rather than WinHelp.

CWinApp::EnableTaskbarInteraction

Enables Taskbar interaction.

CWinApp::ExitInstance

Override to clean up when your application terminates.

CWinApp::GetApplicationRecoveryParameter

Retrieves the input parameter for the application recovery method.

CWinApp::GetApplicationRecoveryPingInterval

Returns the length of time that the restart manager waits for the recovery callback function to return.

CWinApp::GetApplicationRestartFlags

Returns the flags for the restart manager.

CWinApp::GetAppRegistryKey

Returns key for HKEY_CURRENT_USER\"Software"\RegistryKey\ProfileName.

CWinApp::GetDataRecoveryHandler

Gets the data recovery handler for this instance of the application.

CWinApp::GetFirstDocTemplatePosition

Retrieves the position of the first document template.

CWinApp::GetHelpMode

Retrieves the type of help used by the application.

CWinApp::GetNextDocTemplate

Retrieves the position of a document template. Can be used recursively.

CWinApp::GetPrinterDeviceDefaults

Retrieves the printer device defaults.

CWinApp::GetProfileBinary

Retrieves binary data from an entry in the application's .INI file.

CWinApp::GetProfileInt

Retrieves an integer from an entry in the application's .INI file.

CWinApp::GetProfileString

Retrieves a string from an entry in the application's .INI file.

CWinApp::GetSectionKey

Returns key for HKEY_CURRENT_USER\"Software"\RegistryKey\AppName\lpszSection.

CWinApp::HideApplication

Hides the application before closing all documents.

CWinApp::HtmlHelp

Calls the HTMLHelp Windows function.

CWinApp::InitInstance

Override to perform Windows instance initialization, such as creating your window objects.

CWinApp::IsTaskbarInteractionEnabled

Tells whether Windows 7 Taskbar interaction is enabled.

CWinApp::LoadCursor

Loads a cursor resource.

CWinApp::LoadIcon

Loads an icon resource.

CWinApp::LoadOEMCursor

Loads a Windows OEM predefined cursor that the OCR_ constants specify in WINDOWS.H.

CWinApp::LoadOEMIcon

Loads a Windows OEM predefined icon that the OIC_ constants specify in WINDOWS.H.

CWinApp::LoadStandardCursor

Loads a Windows predefined cursor that the IDC_ constants specify in WINDOWS.H.

CWinApp::LoadStandardIcon

Loads a Windows predefined icon that the IDI_ constants specify in WINDOWS.H.

CWinApp::OnDDECommand

Called by the framework in response to a dynamic data exchange (DDE) execute command.

CWinApp::OnIdle

Override to perform application-specific idle-time processing.

CWinApp::OpenDocumentFile

Called by the framework to open a document from a file.

CWinApp::ParseCommandLine

Parses individual parameters and flags in the command line.

CWinApp::PreTranslateMessage

Filters messages before they are dispatched to the Windows functions TranslateMessage and DispatchMessage.

CWinApp::ProcessMessageFilter

Intercepts certain messages before they reach the application.

CWinApp::ProcessShellCommand

Handles command-line arguments and flags.

CWinApp::ProcessWndProcException

Intercepts all unhandled exceptions thrown by the application's message and command handlers.

CWinApp::Register

Performs customized registration.

CWinApp::RegisterWithRestartManager

Registers the application with the restart manager.

CWinApp::ReopenPreviousFilesAtRestart

Determines whether the restart manager reopens the files that were open when the application exited unexpectedly.

CWinApp::RestartInstance

Handles an application restart initiated by the restart manager.

CWinApp::RestoreAutosavedFilesAtRestart

Determines whether the restart manager restores the autosaved files when it restarts the application.

CWinApp::Run

Runs the default message loop. Override to customize the message loop.

CWinApp::RunAutomated

Tests the application's command line for the /Automation option. Obsolete. Instead, use the value in CCommandLineInfo::m_bRunAutomated after calling ParseCommandLine.

CWinApp::RunEmbedded

Tests the application's command line for the /Embedding option. Obsolete. Instead, use the value in CCommandLineInfo::m_bRunEmbedded after calling ParseCommandLine.

CWinApp::SaveAllModified

Prompts the user to save all modified documents.

CWinApp::SelectPrinter

Selects a printer previously indicated by a user through a print dialog box.

CWinApp::SetHelpMode

Sets and initializes the type of help used by the application.

CWinApp::SupportsApplicationRecovery

Determines whether the restart manager recovers an application that exited unexpectedly.

CWinApp::SupportsAutosaveAtInterval

Determines whether the restart manager autosaves open documents at a regular interval.

CWinApp::SupportsAutosaveAtRestart

Determines whether the restart manager autosaves any open documents when the application restarts.

CWinApp::SupportsRestartManager

Determines whether the application supports the restart manager.

CWinApp::Unregister

Unregisters everything known to be registered by the CWinApp object.

CWinApp::WinHelp

Calls the WinHelp Windows function.

CWinApp::WriteProfileBinary

Writes binary data to an entry in the application's .INI file.

CWinApp::WriteProfileInt

Writes an integer to an entry in the application's .INI file.

CWinApp::WriteProfileString

Writes a string to an entry in the application's .INI file.

Protected Methods

Name

Description

CWinApp::EnableShellOpen

Allows the user to open data files from the Windows File Manager.

CWinApp::LoadStdProfileSettings

Loads standard .INI file settings and enables the MRU file list feature.

CWinApp::OnContextHelp

Handles SHIFT+F1 Help within the application.

CWinApp::OnFileNew

Implements the ID_FILE_NEW command.

CWinApp::OnFileOpen

Implements the ID_FILE_OPEN command.

CWinApp::OnFilePrintSetup

Implements the ID_FILE_PRINT_SETUP command.

CWinApp::OnHelp

Handles F1 Help within the application (using the current context).

CWinApp::OnHelpFinder

Handles the ID_HELP_FINDER and ID_DEFAULT_HELP commands.

CWinApp::OnHelpIndex

Handles the ID_HELP_INDEX command and provides a default Help topic.

CWinApp::OnHelpUsing

Handles the ID_HELP_USING command.

CWinApp::RegisterShellFileTypes

Registers all the application's document types with the Windows File Manager.

CWinApp::SetAppID

Explicitly sets Application User Model ID for the application. This method should be called before any user interface is presented to user (the best place is the application constructor).

CWinApp::SetRegistryKey

Causes application settings to be stored in the registry instead of .INI files.

CWinApp::UnregisterShellFileTypes

Unregisters all the application's document types with the Windows File Manager.

Public Data Members

Name

Description

CWinApp::m_bHelpMode

Indicates if the user is in Help context mode (typically invoked with SHIFT+F1).

CWinApp::m_eHelpType

Specifies the type of help used by the application.

CWinApp::m_hInstance

Identifies the current instance of the application.

CWinApp::m_lpCmdLine

Points to a null-terminated string that specifies the command line for the application.

CWinApp::m_nCmdShow

Specifies how the window is to be shown initially.

CWinApp::m_pActiveWnd

Pointer to the main window of the container application when an OLE server is in-place active.

CWinApp::m_pszAppID

Application User Model ID.

CWinApp::m_pszAppName

Specifies the name of the application.

CWinApp::m_pszExeName

The module name of the application.

CWinApp::m_pszHelpFilePath

The path to the application's Help file.

CWinApp::m_pszProfileName

The application's .INI filename.

CWinApp::m_pszRegistryKey

Used to determine the full registry key for storing application profile settings.

Protected Data Members

Name

Description

CWinApp::m_dwRestartManagerSupportFlags

Flags that determine how the restart manager behaves.

CWinApp::m_nAutosaveInterval

The length of time in milliseconds between autosaves.

CWinApp::m_pDataRecoveryHandler

Pointer to the data recovery handler for the application.

Remarks

An application object provides member functions for initializing your application (and each instance of it) and for running the application.

Each application that uses the Microsoft Foundation classes can only contain one object derived from CWinApp. This object is constructed when other C++ global objects are constructed and is already available when Windows calls the WinMain function, which is supplied by the Microsoft Foundation Class Library. Declare your derived CWinApp object at the global level.

When you derive an application class from CWinApp, override the InitInstance member function to create your application's main window object.

In addition to the CWinApp member functions, the Microsoft Foundation Class Library provides the following global functions to access your CWinApp object and other global information:

  • AfxGetApp   Obtains a pointer to the CWinApp object.

  • AfxGetInstanceHandle   Obtains a handle to the current application instance.

  • AfxGetResourceHandle   Obtains a handle to the application's resources.

  • AfxGetAppName   Obtains a pointer to a string containing the application's name. Alternately, if you have a pointer to the CWinApp object, use m_pszExeName to get the application's name.

See CWinApp: The Application Class for more on the CWinApp class, including an overview of the following:

  • CWinApp-derived code written by the Application Wizard.

  • CWinApp's role in the execution sequence of your application.

  • CWinApp's default member function implementations.

  • CWinApp's key overridables.

The m_hPrevInstance data member no longer exists. For information on detecting a previous instance of CWinApp, see the Knowledge Base article "How To Identify a Previous Instance of an Application" (KB106385) at https://support.microsoft.com/default.aspx?scid=kb;en-us;106385.

Inheritance Hierarchy

CObject

CCmdTarget

CWinThread

CWinApp

Requirements

Header: afxwin.h

See Also

Tasks

How to: Add Restart Manager Support

Reference

CWinThread Class

Hierarchy Chart