Skip to main content

SalApplication

Namespace: PPJ.Runtime.Windows

Assembly: PPJ.Runtime.50 (5.0.0.0)

Hosts a translated SAL Windows Forms application and supplies lifecycle hooks, form tracking, profile storage, tracing, and skin integration.

public class SalApplication

Construct one application instance before entering Run. Startup runs on the first idle notification, followed by automatic form creation. Registered top-level forms keep the application alive; releasing the last form requests application exit.

Example:

public class ExampleApplication : PPJ.Runtime.Windows.SalApplication
{
[System.STAThread]
public static int Main(string[] args)
{
return new ExampleApplication().Run(args);
}

protected override void OnAppCreateAutomaticForms()
{
var form = new System.Windows.Forms.Form { Text = "Customer Browser" };
AddForm(form);
form.Show();
}
}

Constructors

Instance member SalApplication()

Registers this application instance and its lifecycle handlers without additional command-line arguments.

Instance member SalApplication(args)

Registers this application instance, saves its namespace and arguments, and attaches lifecycle handlers.

NameTypeDescription
argsString[]The command-line arguments, or null. The executable path is stored separately at index zero of the SAL argument array.

Properties

Static member ApplicationType

Type: Gets the runtime type of the most recently constructed SAL application instance.

Static member CompanyName

String: Gets or sets the company name, initially taken from the entry assembly company attribute and normalized to an empty string when null.

Static member DefaultPrinterSettings

PrinterSettings: Gets or sets the shared printer settings used by the application.

The first read after a null assignment creates settings with all page margins set to 10 and the print-file name set to the executable name without its extension.

Static member FormsScaleFactor

SizeF: Gets or sets the global form scaling factor; an empty size leaves the standard scaling behavior in effect.

Static member Instance

SalApplication: Gets the most recently constructed SAL application instance, or null before one has been constructed.

Static member SkinApplication

Boolean: Gets or sets whether application skinning is enabled for the current thread, updating the skin engine when the application is active.

Static member ThreadModel

ApartmentState: Gets the current thread's OLE apartment state, initializing OLE through Windows Forms when required.

Static member Title

String: Gets or sets the application title.

The initial value comes from the entry assembly title, falling back to the application-domain friendly name. A null assignment becomes an empty string.

Static member TopLevelForms

Form[]: Gets a snapshot array of forms registered with the application, or an empty array if none are tracked.

Static member UseCompatibleTextRendering

Boolean: Gets or sets the Windows Forms default for compatible text rendering.

Set this value before creating application windows, as required by SetCompatibleTextRenderingDefault.

Static member Version

Int32: Gets the framework version encoded as 900 plus ten times the assembly major version plus its minor version.

Static member VisualStyler

VisualStyler: Gets the VisualStyler component associated with the current thread's skin integration.

Static member VisualStyles

Boolean: Gets or sets whether startup should enable Windows visual styles.

Enabling is ignored when the operating system does not report theme support. Setting this flag alone does not restyle existing controls.

Static member XPStyle

Deprecated memberDeprecated: This property has been deprecated. Use SalApplication.VisualStyles. Boolean: Gets or sets the obsolete alias for VisualStyles.

Methods

Static member AddForm(form)

Registers a top-level form and increments the application lifetime count once for that instance.

ParameterTypeDescription
formFormThe form to register.

Returns: Int32. The resulting lifetime count, or zero when the application is not in run mode.

Non-SAL forms are automatically removed when their native handles are destroyed. Throws:

Static member ApplySkin(form)

Applies skin integration for a form.

ParameterTypeDescription
formFormThe form to update.

Static member ApplySkin(control, children)

Applies skin integration for a control and optionally its descendants.

ParameterTypeDescription
controlControlThe control to update.
childrenBooleanTrue to include child controls.

Static member DelayDispose(obj)

Queues an object for disposal during the next application idle notification.

ParameterTypeDescription
objIDisposableThe non-null object to dispose later.

Already-disposed Windows Forms controls are skipped. Other objects receive a Dispose call when dequeued.

Static member Disable()

Disables native input for every tracked top-level form whose handle exists.

Returns: Boolean. True after visiting the registered forms.

Static member Enable()

Enables native input for every disabled tracked top-level form whose handle exists.

Returns: Boolean. True after visiting the registered forms.

This does not preserve the reason a form was disabled; all disabled tracked forms are enabled.

Static member EndTrace()

Disables application tracing and releases any open event-log component.

Returns: Boolean. True after resetting the trace configuration.

Static member Find(name, activate)

Finds a visible window belonging to another process with the specified executable name in the current session.

ParameterTypeDescription
nameStringThe executable name or path; its directory and extension are ignored for comparison.
activateBooleanTrue to restore a minimized matching window or bring it to the top.

Returns: IntPtr. The matching window handle, or zero if no suitable window is found.

Static member GetProfileInt(section, entry, defaultValue, fileName)

Reads an integer from an INI section or the configured registry profile store.

ParameterTypeDescription
sectionStringThe section name.
entryStringThe value name.
defaultValueUInt32The value to return when the requested entry is absent.
fileNameStringThe INI file name, or application subkey when registry profiles are enabled.

Returns: UInt32. The stored value converted to an unsigned integer, or the supplied default.

Static member GetProfileString(section, entry, defaultValue, value, fileName)

Reads a string from an INI section or the configured registry profile store.

ParameterTypeDescription
sectionStringThe section name.
entryStringThe value name.
defaultValueStringThe value used when the requested entry is absent.
value by referenceSalStringReceives the retrieved string.
fileNameStringThe INI file name, or application subkey when registry profiles are enabled.

Returns: Int32. The length of the string assigned to value .

INI reads use a fixed buffer with a capacity of 2048 characters.

Static member IdleKick()

Synchronously sends registered idle messages and processes the delayed-disposal queue.

Returns: Boolean. True after idle processing completes.

Static member IdleRegister(ctrl, msg, wParam, lParam)

Registers a control's current native handle to receive a message on each application idle notification.

ParameterTypeDescription
ctrlControlThe target control; accessing its handle may create it.
msgInt32The message identifier.
wParamInt32The first message parameter.
lParamInt32The second message parameter.

Returns: Boolean. False when the control is null; otherwise, true.

Repeated calls add separate registrations.

Static member IdleUnregister(ctrl)

Removes the first idle registration matching the control's current handle.

ParameterTypeDescription
ctrlControlThe control whose registration should be removed.

Returns: Boolean. False for a null control or a control without a created handle; otherwise, true, even if no registration exists.

Static member LoadApp(name, args)

Starts an application with normal window presentation without waiting for it to exit.

ParameterTypeDescription
nameStringThe executable command, quoted as needed for paths containing spaces.
argsStringThe command-line arguments to append.

Returns: Boolean. True if process creation and the initial exit-code query succeed; otherwise, false.

Static member LoadAppAndProcessMsgs(name, mode, retCode)

Starts a process and waits for its exit without disabling tracked forms.

ParameterTypeDescription
nameStringThe executable command line, quoted as needed.
modeInt32A SAL Window_* presentation constant.
retCode by referenceSalNumberReceives the process exit code, a Win32 creation error, or zero after a caught exception.

Returns: Boolean. True if creation, waiting, and the exit-code query complete successfully; otherwise, false.

Despite the legacy name, the current wait loop does not pump Windows Forms messages.

Static member LoadAppAndWait(name, mode, retCode)

Starts a process, disables tracked forms while it runs, and waits for its exit.

ParameterTypeDescription
nameStringThe executable command line, quoted as needed.
modeInt32A SAL Window_* presentation constant.
retCode by referenceSalNumberReceives the process exit code, a Win32 creation error, or zero after a caught exception.

Returns: Boolean. True if creation, waiting, and the exit-code query complete successfully; otherwise, false.

Static member LoadSkinFile(path)

Enables skinning and loads the specified skin file.

ParameterTypeDescription
pathStringThe skin file path.

Static member LoadSkinResource(name)

Enables skinning and loads a skin from application resources.

ParameterTypeDescription
nameStringThe embedded skin resource name.

Static member LoadSkinResource(assembly, name)

Enables skinning and loads a skin from the specified assembly.

ParameterTypeDescription
assemblyAssemblyThe assembly containing the skin resource.
nameStringThe embedded skin resource name.

Protected member OnAppCreateAutomaticForms()

Creates automatically opened forms after startup completes successfully.

Override to create and show the application's initial forms. The base implementation does nothing.

Protected member OnAppExit()

Runs the application exit action and supplies the process exit code.

Returns: Int32. The exit code; the base implementation returns zero.

Protected member OnAppStartup()

Runs the application startup action on the first idle notification.

Override to implement SAM_AppStartup. The base implementation does nothing.

Protected member OnSqlError(Error)

Receives a SQL failure routed to the global application error handler.

ParameterTypeDescription
ErrorSalSqlErrorThe SQL error whose Return property can carry the handler result.

Override to implement SAM_SqlError. The base implementation does nothing.

Protected member OnThreadException(sender, args)

Routes UI-thread exceptions through SAL abort/quit handling, optional event logging, and the unhandled-exception hook.

ParameterTypeDescription
senderObjectThe event source, passed as a thread when possible.
argsThreadExceptionEventArgsThe exception to process.

Protected member OnUnhandledException(thread, args)

Displays the standard thread-exception dialog, or terminates the process when interaction is unavailable or the user chooses Abort.

ParameterTypeDescription
threadThreadThe thread supplied by the exception dispatcher; not used by the base implementation.
argsThreadExceptionEventArgsThe unhandled exception.

Static member Pause(usec)

Waits for the requested interval while sleeping briefly and dispatching Windows Forms messages.

ParameterTypeDescription
usecInt32The wait duration in milliseconds, despite the legacy parameter name. Zero or negative values return immediately.

Message dispatch can reenter application code during the wait.

Instance member Quit()

Requests closure of every tracked form and then requests Windows Forms application exit, ignoring repeated quit requests.

Static member RemoveForm(form)

Unregisters a tracked form and requests application exit when the lifetime count reaches zero.

ParameterTypeDescription
formFormThe registered form to remove.

Returns: Int32. The resulting lifetime count, or zero when form tracking is inactive.

Static member RemoveSkin(form)

Removes skin integration for a form.

ParameterTypeDescription
formFormThe form to update.

No action is taken when application skinning is disabled.

Static member RemoveSkin(control, children)

Removes skin integration for a control and optionally its descendants.

ParameterTypeDescription
controlControlThe control to update.
childrenBooleanTrue to include child controls.

No action is taken when application skinning is disabled.

Instance member Run(args)

Processes startup options and runs the Windows Forms message loop until application exit.

ParameterTypeDescription
argsString[]The command-line arguments to expose through the SAL system variables and process for runtime options.

Returns: Int32. The process exit code, normally supplied by OnAppExit.

Recognized options include /xp, /noxp, /visualstyles=on, /visualstyles=off, and /log or /log=filename.

Static member SetProfileString(section, entry, value, fileName)

Writes or deletes a string setting in an INI file or the configured registry profile store.

ParameterTypeDescription
sectionStringThe section to update.
entryStringThe setting name, or null to delete the section.
valueStringThe string to store, or null to delete the setting.
fileNameStringThe INI file name, or application subkey when registry profiles are enabled.

Returns: Boolean. False for a null section or file name, or an unsuccessful INI write; true after a completed registry operation or successful INI write.

Registry access and deletion exceptions propagate to the caller.

Static member StartTrace(outputType, traceFile, clear)

Selects the destination for subsequent application trace messages.

ParameterTypeDescription
outputTypeInt32One of Sys.TRACE_Event, Sys.TRACE_File, Sys.TRACE_Output, or Sys.TRACE_stdout.
traceFileStringThe output path when file tracing is selected.
clearBooleanTrue to delete an existing trace file before writing new messages.

Returns: Boolean. True for a supported output type; otherwise, false.

Static member Trace(severity, text)

Writes a message to the configured trace destination.

ParameterTypeDescription
severityInt32The event-log entry type when event logging is selected; ignored by other destinations.
textStringThe message to write.

Returns: Boolean. False when tracing has no active supported destination; otherwise, true after dispatching the message.

Static member UseEventLog(useLog, logAndcontinue)

Configures Windows event logging for unhandled UI-thread exceptions.

ParameterTypeDescription
useLogBooleanTrue to write exceptions to the event log.
logAndcontinueBooleanTrue to return after logging instead of invoking the unhandled-exception hook.

Returns: Boolean. True after updating the settings.

Static member UseRegistry(useRegistry, companyName)

Switches profile operations between INI files and the current user's registry.

ParameterTypeDescription
useRegistryBooleanTrue to use registry profiles; false to use INI files.
companyNameStringThe subkey under HKEY_CURRENT_USER\Software; null or empty uses the Windows Forms application company name.

Returns: Boolean. True if registry profiles were enabled before the call; otherwise, false.

Events

Static member SkinChanged

EventHandler Occurs when the loaded skin changes; the sender is the VisualStyler component.