home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Chip 1997 October
/
Chip_1997-10_cd.bin
/
tema
/
sybase
/
powerj
/
hpp.z
/
WAPPLIC.HPP
< prev
next >
Wrap
C/C++ Source or Header
|
1997-01-23
|
30KB
|
866 lines
/********************************************************************
*
* WApplication
*
* Events:
*
* Start -- Called when the application is starting. User can
* decide if application should continue.
*
* Run -- Called to run the application.
*
* End -- Called when the application is terminating.
*
********************************************************************/
#ifndef _WAPPLIC_HPP_INCLUDED
#define _WAPPLIC_HPP_INCLUDED
#ifndef _WNO_PRAGMA_PUSH
#pragma pack(push,8);
#pragma enum int;
#endif
#include "wdef.hpp"
#ifndef _WOBJECT_HPP_INCLUDED
# include "wobject.hpp"
#endif
#ifndef _WBITMAP_HPP_INCLUDED
# include "wbitmap.hpp"
#endif
#ifndef _WSTRING_HPP_INCLUDED
# include "wstring.hpp"
#endif
#ifndef _WTHREAD_HPP_INCLUDED
# include "wthread.hpp"
#endif
#ifndef _WMODULE_HPP_INCLUDED
# include "wmodule.hpp"
#endif
#ifndef _WWINDOW_HPP_INCLUDED
# include "wwindow.hpp"
#endif
#ifndef _WLLIST_HPP_INCLUDED
# include "wllist.hpp"
#endif
#ifndef _WFILPATH_HPP_INCLUDED
# include "wfilpath.hpp"
#endif
struct WStartEventData : public WEventData {
WBool abortRun;
WLong exitCode;
};
typedef WStartEventData WEndEventData;
typedef WStartEventData WRunEventData;
typedef WEventData WThreadAttachEventData;
typedef WEventData WThreadDetachEventData;
struct WProcessAttachEventData : public WEventData {
WBool dynamic;
};
typedef WProcessAttachEventData WProcessDetachEventData;
enum WWaitReturn {
WFailed = 0xFFFFFFFFL,
WSucceeded = 0x00000000L,
WAbandoned = 0x00000080L,
WTimeout = 0x00000102L
};
class WForm;
enum WHelpType {
WHelpContext = 0x0001,
WHelpQuit = 0x0002,
WHelpIndex = 0x0003,
WHelpContents = 0x0003,
WHelpHelpOnHelp = 0x0004,
WHelpSetContents = 0x0005,
WHelpSetIndex = 0x0005,
WHelpContextPopup = 0x0008,
WHelpOnContextMenu = 0x000a,
WHelpFinder = 0x000b,
WHelpOnHelp = 0x000c,
WHelpKey = 0x0101,
WHelpCommand = 0x0102,
WHelpPartialKey = 0x0105
};
#define WClipboardText WTEXT("WCLASS_CLIPBOARD_TEXT")
#define WClipboardDIF WTEXT("WCLASS_CLIPBOARD_DIF")
#define WClipboardBitmap WTEXT("WCLASS_CLIPBOARD_BITMAP")
#define WClipboardDIBitmap WTEXT("WCLASS_CLIPBOARD_DI_BITMAP")
#define WClipboardDSPBitmap WTEXT("WCLASS_CLIPBOARD_DSP_BITMAP")
#define WClipboardOEMText WTEXT("WCLASS_CLIPBOARD_OEM_TEXT")
#define WClipboardUnicodeText WTEXT("WCLASS_CLIPBOARD_UNICODE_TEXT")
#define WClipboardTIFF WTEXT("WCLASS_CLIPBOARD_TIFF")
#define WClipboardWave WTEXT("WCLASS_CLIPBOARD_WAVE")
#define WClipboardSYLK WTEXT("WCLASS_CLIPBOARD_SYLK")
#define WClipboardRIFF WTEXT("WCLASS_CLIPBOARD_RIFF")
#define WClipboardPenData WTEXT("WCLASS_CLIPBOARD_PEN_DATA")
#define WClipboardPalette WTEXT("WCLASS_CLIPBOARD_PALETTE")
#define WClipboardOwnerDisplay WTEXT("WCLASS_CLIPBOARD_OWNER_DISPLAY")
#define WClipboardMetaFile WTEXT("WCLASS_CLIPBOARD_META_FILE")
#define WClipboardLocale WTEXT("WCLASS_CLIPBOARD_LOCALE")
#define WClipboardHDROP WTEXT("WCLASS_CLIPBOARD_HDROP")
#define WClipboardDSPText WTEXT("WCLASS_CLIPBOARD_DSP_TEXT")
#define WClipboardDSPMetaFile WTEXT("WCLASS_CLIPBOARD_DSP_META_FILE")
#define WClipboardEnhancedMetaFile WTEXT("WCLASS_CLIPBOARD_EN_META_FILE")
#define WClipboardDSPEnhancedMetaFile WTEXT("WCLASS_CLIPBOARD_DSP_EN_META_FILE")
typedef WBool WCMDEF (WObject::*WEnumCallback)( WWindow * win,
WWindowHandle winHandle,
void * userData );
#ifndef _WIN16
#undef FindExecutable
#undef ExtractIcon
#undef GetFileAttributes
#undef SetFileAttributes
#undef GetUserName
#undef GetComputerName
#undef GetCommandLine
#undef SendMessage
#undef PostMessage
#undef PlaySound
#undef GetSystemDirectory
#undef GetWindowsDirectory
#undef GetWorkingDirectory
#undef CopyFile
#undef MoveFile
#undef DeleteFile
#undef InitiateSystemShutdown
#undef GetEnvironmentVariable
#undef SetEnvironmentVariable
#if defined( _UNICODE )
#define GetUserName GetUserNameW
#define GetComputerName GetComputerNameW
#define GetCommandLine GetCommandLineW
#define GetEnvironmentVariable GetEnvironmentVariableW
#define SetEnvironmentVariable SetEnvironmentVariableW
#define SendMessage SendMessageW
#define PostMessage PostMessageW
#define PlaySound PlaySoundW
#define GetSystemDirectory GetSystemDirectoryW
#define GetWindowsDirectory GetWindowsDirectoryW
#define GetWorkingDirectory GetWorkingDirectoryW
#define SetFileAttributes SetFileAttributesW
#define CopyFile CopyFileW
#define MoveFile MoveFileW
#define DeleteFile DeleteFileW
#define InitiateSystemShutdown InitiateSystemShutdownW
#define GetFileAttributes GetFileAttributesW
#define FindExecutable FindExecutableW
#define ExtractIcon ExtractIconW
#define GetProfileString GetProfileStringW
#define WritePrivateProfileString WritePrivateProfileStringW
#else
#define GetUserName GetUserNameA
#define GetComputerName GetComputerNameA
#define GetCommandLine GetCommandLineA
#define GetEnvironmentVariable GetEnvironmentVariableA
#define SetEnvironmentVariable SetEnvironmentVariableA
#define SendMessage SendMessageA
#define PostMessage PostMessageA
#define PlaySound PlaySoundA
#define GetSystemDirectory GetSystemDirectoryA
#define GetWindowsDirectory GetWindowsDirectoryA
#define GetWorkingDirectory GetWorkingDirectoryA
#define GetFileAttributes GetFileAttributesA
#define SetFileAttributes SetFileAttributesA
#define CopyFile CopyFileA
#define MoveFile MoveFileA
#define DeleteFile DeleteFileA
#define InitiateSystemShutdown InitiateSystemShutdownA
#define FindExecutable FindExecutableA
#define ExtractIcon ExtractIconA
#define GetProfileString GetProfileStringA
#define WritePrivateProfileString WritePrivateProfileStringA
#endif
#endif
enum WBeepSound {
WBeepOK = 0x00000000L, WBeepDefault = WBeepOK,
WBeepHand = 0x00000010L,
WBeepQuestion = 0x00000020L,
WBeepExclamation = 0x00000030L,
WBeepAsterisk = 0x00000040L,
WBeepStandard = 0xFFFFFFFF,
};
#define WPSFlagSync 0x0000 // SND_SYNC
#define WPSFlagAsync 0x0001 // SND_ACYNC
#define WPSFlagNoDefault 0x0002 // SND_NODEFAULT
#define WPSFlagMemory 0x0004 // SND_MEMORY
#define WPSFlagLoop 0x0008 // SND_LOOP
#define WPSFlagNoStop 0x0010 // SND_NOSTOP
#define WPSFlagNoWait 0x00002000L // SND_NOWAIT
#define WPSFlagAlias 0x00010000L // SND_ALIAS
#define WPSFlagAliasID 0x00110000L // SND_ALIAS_ID
#define WPSFlagFileName 0x00020000L // SND_FILENAME
#define WPSFlagResource 0x00040004L // SND_RESOURCE
#if(WINVER >= 0x0400)
#define WPSFlagPurge 0x0040 // SND_PURGE
#define WPSFlagApplication 0x0080 // SND_APPLICATION
#endif /* WINVER > = 0x0400 */
struct WOSVersionInfo {
WDWord platform;
WDWord majorVersion;
WDWord minorVersion;
WDWord buildNumber;
WChar extraInfo[ 128 ];
WDWord reserved;
};
class WCMCLASS WTime {
public:
WTime();
~WTime();
public:
WUShort _year;
WUShort _month;
WUShort _dayOfWeek;
WUShort _day;
WUShort _hour;
WUShort _minute;
WUShort _second;
WUShort _milliseconds;
};
enum WOSType {
WOST_Win16 = 0,
WOST_WinNT = 1,
WOST_Win95 = 2,
WOST_Win32s = 3,
};
typedef WULong WSHFileFlag;
#define WSFFMultiDestFiles ((WSHFileFlag)0x00000001L)
#define WSFFMultiDestinationFiles ((WSHFileFlag)0x00000001L)
#define WSFFMultipleDestFiles ((WSHFileFlag)0x00000001L)
#define WSFFMultipleDestinationFiles ((WSHFileFlag)0x00000001L)
#define WSFFConfirmMouse ((WSHFileFlag)0x00000002L)
#define WSFFSilent ((WSHFileFlag)0x00000004L)
#define WSFFRenameOnCollision ((WSHFileFlag)0x00000008L)
#define WSFFNoConfirmation ((WSHFileFlag)0x00000010L)
#define WSFFWantMappingHandle ((WSHFileFlag)0x00000020L)
#define WSFFAllowUndo ((WSHFileFlag)0x00000040L)
#define WSFFFilesOnly ((WSHFileFlag)0x00000080L)
#define WSFFSimpleProgress ((WSHFileFlag)0x00000100L)
#define WSFFNoConfirmMkdir ((WSHFileFlag)0x00000200L)
#define WSFFNoConfirmMakeDir ((WSHFileFlag)0x00000200L)
#define WSFFNoConfirmMakeDirectory ((WSHFileFlag)0x00000200L)
#define WSFFDefaultCopy ((WSHFileFlag)0x0000025CL)
#define WSFFDefaultMove ((WSHFileFlag)0x0000025CL)
#define WSFFDefaultDelete ((WSHFileFlag)0x0000025CL)
#define WSFFDefaultRename ((WSHFileFlag)0x0000025CL)
typedef WULong WFileAttribute;
#define WFAReadOnly ((WFileAttribute)0x00000001L)
#define WFAHidden ((WFileAttribute)0x00000002L)
#define WFASystem ((WFileAttribute)0x00000004L)
#define WFADirectory ((WFileAttribute)0x00000010L)
#define WFAArchive ((WFileAttribute)0x00000020L)
#define WFANormal ((WFileAttribute)0x00000080L)
#define WFATemporary ((WFileAttribute)0x00000100L)
#define WFACompressed ((WFileAttribute)0x00000800L)
enum WExecutableFileType {
WNonEXE,
WWindowsEXE,
WDosEXE,
WWin32ConsoleEXE
};
//
// WApplication
//
#define WAppObject (*WApplication::GetApplicationObject())
class WCMCLASS WApplication : public WEventGenerator {
WDeclareSubclass( WApplication, WEventGenerator );
public:
/***************************************************************
* Constructors and Destructors
****************************************************************/
WApplication();
~WApplication();
/***************************************************************
* Properties
***************************************************************/
// AutomaticContextHelpHandling
WBool GetAutomaticContextHelpHandling() const;
WBool SetAutomaticContextHelpHandling( WBool autoContextHelp );
// ClipboardBitmap
//
// NOTE: On the Set, the bmp must have its handle detached first.
// This can be accomplished by calling bmp.DetachHandle().
// NOTE: On the Get, the bitmap that is returned cannot be
// relied upon for long-term use, so the best idea is to
// make a copy of it, as in bmp.Create( bmp, 0, 0, TRUE );
WBool SetClipboardBitmap( const WBitmap & bmp, WWindow *owner=NULL );
WBitmap GetClipboardBitmap( WWindow * owner=NULL );
// ClipboardData
//
// NOTE: Can't rely on return value of GetClipboardData for
// long-term use, so the best idea is to make a copy of it
WBool SetClipboardData( void * data, WInt data_size,
const WChar * format,
WWindow * owner=NULL, WBool indirect=TRUE );
WBool SetClipboardData( void * data, WInt data_size, WInt format,
WWindow * owner=NULL, WBool indirect=TRUE );
void * GetClipboardData( const WChar * format, WWindow * owner=NULL,
WBool indirect=TRUE );
void * GetClipboardData( WInt format, WWindow * owner=NULL,
WBool indirect=TRUE );
// ClipboardText
WBool SetClipboardText( const WString & str, WWindow * owner=NULL );
WString GetClipboardText( WWindow * owner=NULL );
// HelpFile
//
// Identifies the module-wide help file.
WFilePath GetHelpFile() const;
WBool SetHelpFile( const WFilePath & helpFile );
// LocalModule
//
// Identifies the module that created the application
// object. In a EXE, the local module is either the
// exe module or the library module. In a DLL, the
// local module is either the library module or a
// completely different module.
const WModule & GetLocalModule() const;
// MultiOSWarnings
WBool GetMultiOSWarnings() const;
WBool SetMultiOSWarnings( WBool warnings );
/*************************************************************
* Methods
*************************************************************/
// EmptyClipboard
WBool EmptyClipboard( WWindow * owner=NULL );
// Initialize
//
// Call this to initialize the library. Appropriate defaults
// are used.
WBool Initialize( unsigned int instance,
unsigned int prevInstance,
const WAnsiChar *commandLine, int showState );
WBool Initialize( WModuleHandle instance=0,
WModuleHandle prevInstance=0,
WAnsiChar *commandLine=NULL, int showState=0 );
// Quit
void Quit( WDWord exitCode=0 );
// Run
WLong Run();
// Uninitialize
WLong Uninitialize();
/*************************************************************
* Static Properties
*************************************************************/
// ActiveWindow
static WWindow *GetActiveWindow();
static WBool SetActiveWindow( WWindow *win );
// ApplicationObject
static WApplication *GetApplicationObject();
static WBool SetApplicationObject( WApplication * appObj );
// CaptionSize
static WInt GetCaptionSize();
// CommandLine
//
// Return the command line used to start the app.
static WString GetCommandLine();
// GetWorkArea
static WRect GetWorkArea();
// ComputerName
//
// Name of this computer.
static WString GetComputerName();
// DesktopWindowHandle
static WWindowHandle GetDesktopWindowHandle();
// DialogBaseWidth
static WFloat WCMRETURNSFLOAT GetDialogBaseHeight( const WFont & font );
// DialogBaseWidth
static WFloat WCMRETURNSFLOAT GetDialogBaseWidth( const WFont & font );
// DialogFrameHeight
static WInt GetDialogFrameHeight();
// DialogFrameWidth
static WInt GetDialogFrameWidth();
// EnvironmentVariable
static WString GetEnvironmentVariable( const WString & name );
static WBool SetEnvironmentVariable( const WString & name,
const WString & value );
// ExecutableModule
//
// Identifies the EXE's module.
static const WModule & GetExecutableModule();
// ExecutableType
static WExecutableFileType GetExecutableType( const WFilePath & exe );
// FileAttributes
static WFileAttribute GetFileAttributes( const WFilePath & file );
static WBool SetFileAttributes( const WFilePath & file,
WFileAttribute attribute=0 );
// FileDisplayName
static WString GetFileDisplayName( const WFilePath & file,
WBool useFileAttributes=FALSE,
WFileAttribute attribute=0 );
// FileType
static WString GetFileType( const WFilePath & file,
WBool useFileAttributes=FALSE,
WFileAttribute attribute=0 );
// FocusWindow
static WWindow * GetFocusWindow();
// ForegroundWindow
static WBool SetForegroundWindow( WWindow * window );
static WWindow * GetForegroundWindow();
// ForegroundWindowHandle
static WWindowHandle GetForegroundWindowHandle();
// FrameHeight
static WInt GetFrameHeight();
// FrameWidth
static WInt GetFrameWidth();
// HScrollBarHeight
static WInt GetHScrollBarHeight();
// KeyboardState
static WULong GetKeyboardState();
// LibraryModule
//
// Identifies the WClass DLL's module. Note that in a
// standalone exe LibraryModule == ExecutableModule.
static const WModule & GetLibraryModule();
// MousePresent
static WBool GetMousePresent();
// MenuCheckMarkHeight
static WInt GetMenuCheckMarkHeight();
// MenuCheckMarkWidth
static WInt GetMenuCheckMarkWidth();
// ProfileString
static WString GetProfileString( WString sectionName, WString keyName,
WString defaultString,
WString fileName = "WIN.INI" );
static WBool SetProfileString( WString sectionName, WString keyName,
WString value,
WString fileName = "WIN.INI",
WBool flushCache = TRUE );
// ProgramPath
//
// Return the full path to the running executable.
static WString GetProgramPath();
// ScreenSize
static WRect GetScreenSize();
// SystemDirectory
//
// Returns path of the system directory.
static WString GetSystemDirectory();
// SystemTime
//
//
static WTime GetSystemTime();
// UserName
//
// User's login name.
static WString GetUserName();
// VScrollBarWidth
static WInt GetVScrollBarWidth();
// WindowsDirectory
//
// Returns path of the Windows directory.
static WString GetWindowsDirectory();
// WorkingDirectory
//
// Return the full path of the current directory.
static WString GetWorkingDirectory();
/*************************************************************
* Static Methods
*************************************************************/
// AbortSystemShutdown
static WBool AbortSystemShutdown( WChar * machineName=NULL );
// AddToRecentDocumentList
static void AddToRecentDocumentList( const WFilePath & file );
// Beep
static WBool Beep( WBeepSound sound=WBeepStandard );
// ClearRecentDocumentList
static void ClearRecentDocumentList();
// CopyFile
static WBool CopyFile( const WFilePath & source,
const WFilePath & dest, WWindow * parent=NULL,
WSHFileFlag flags=WSFFDefaultCopy,
const WChar * progressTitle=NULL,
WBool * userAborted=NULL );
// DeleteFile
static WBool DeleteFile( const WFilePath & source,
WWindow * parent=NULL,
WSHFileFlag flags=WSFFDefaultDelete,
const WChar * progressTitle=NULL,
WBool * userAborted=NULL );
// EnumerateAllWindows
static WBool EnumerateAllWindows( WObject * client,
WEnumCallback callback,
void * userData );
// EnumerateChildWindows
static WBool EnumerateChildWindows( WObject * client,
WEnumCallback callback,
void * userData,
WWindow * parent );
// EnumerateTopLevelWindows
static WBool EnumerateTopLevelWindows( WObject * client,
WEnumCallback callback,
void * userData );
// Execute
static WBool Execute(const WFilePath & file,
const WString & operation = WNullString,
const WString & parameters = WEmptyString,
WInt cmdShow = WWinStateShowNormal,
WWindow* parent = NULL);
// ExtractIcon
static WIcon ExtractIcon(const WFilePath & file,
WBool associated = TRUE,
WUInt index = 0);
// FindExecutable
static WBool FindExecutable(const WFilePath & file, WString & nameEXE);
// ForceDelete
static void ForceDelete( WBool evenInEventHandler=FALSE,
WObject * calledFrom=NULL );
// InitiateSystemShutdown
static WBool InitiateSystemShutdown( WChar * message=NULL,
WLong timeout=0,
WBool forceAppsToClose=TRUE,
WBool reboot=FALSE,
WChar * machineName=NULL );
// InvokeHelp
//
// Invoke the help subsystem. A form is required for the
// help subsystem to keep track of help requests. If no
// filename is specified, the file in the HelpFile property
// is used instead.
static WBool InvokeHelp( WWindow * window, WHelpType type,
WULong helpID, const WChar * helpFileName=NULL,
WWindowHandle windowHandle=NULLHWND );
static WBool InvokeHelp( WWindow * window, WHelpType type,
const WChar * helpCommand,
const WChar * helpFileName=NULL );
// MoveFile
static WBool MoveFile( const WFilePath & source,
const WFilePath & dest,
WWindow * parent=NULL,
WSHFileFlag flags=WSFFDefaultMove,
const WChar * progressTitle=NULL,
WBool * userAborted=NULL );
// MultiOSWarning
static void MultiOSWarning( WOSType os, WChar * message );
// OSType
//
// Return the type of OS we're running on (NT, Win95, Win16,
// or Win32s) and optionally fill in a WOSVersionInfo
// structure.
static WOSType OSType( WOSVersionInfo *info=NULL );
// PlaySound (WAVEFORM sound file format)
static WBool PlaySound( const WString & sound,
WULong flag=WPSFlagFileName|WPSFlagAsync,
WModuleHandle module=_ApplicationModule );
// PostMessage
static WLong PostMessage( WWindow * win, const WMessage & msg );
static WLong PostMessage( const WMessage & msg );
// RegisterDeleteObject (alternative to delete this)
static WBool RegisterDeleteObject( WObject * object );
// RenameFile
static WBool RenameFile( const WFilePath & source,
const WFilePath & dest,
WWindow * parent=NULL,
WSHFileFlag flags=WSFFDefaultRename,
const WChar * progressTitle=NULL,
WBool * userAborted=NULL );
// SendMessage
static WLong SendMessage( WWindow * win, const WMessage & msg );
static WLong SendMessage( const WMessage & msg );
// Wait
//
// Wait for semaphore, thread, process, et. al.
static WWaitReturn Wait( WULong handle, WULong secondsToWait=0,
WBool waitForever=FALSE );
/*************************************************************
* Data members
*************************************************************/
#ifdef __BUILDING_WCM__
public:
#else
protected:
#endif
WStartEventData _event;
WModule _localModule;
WFilePath _helpFile;
WDWord _mainThreadID;
WBool _multiOSWarnings;
WBool _autoContextHelp;
static WApplication *_globalObject;
static WModule _libraryModule;
static WModule _exeModule;
};
class WCMCLASS WExeApplication : public WApplication {
WDeclareSubclass( WExeApplication, WApplication );
public:
WExeApplication();
~WExeApplication();
/*************************************************************
* Methods
*************************************************************/
// EntryPoint
//
// Note that the second just calls the first and is provided
// for backwards compatibility.
int EntryPoint( WModuleHandle inst, WModuleHandle prev,
WAnsiChar *command, int show );
int EntryPoint( unsigned int inst, unsigned int prev,
const WAnsiChar *command, int show );
/*************************************************************
* Data members
*************************************************************/
private:
};
/********************************************************************
*
* WDLLApplication
*
* Events:
*
* ProcessAttach --
*
* ProcessDetach --
*
* ThreadAttach --
*
* ThreadDetach --
*
********************************************************************/
class WCMCLASS WDLLApplication : public WApplication {
WDeclareSubclass( WDLLApplication, WApplication );
public:
WDLLApplication();
~WDLLApplication();
/*************************************************************
* Methods
*************************************************************/
// EntryPoint
//
// Note that the second just calls the first and is provided
// for backwards compatibility.
WBool EntryPoint( WModuleHandle inst, unsigned int reason,
void * data );
WBool EntryPoint( unsigned int inst, unsigned int reason,
void * data );
/*************************************************************
* Data members
*************************************************************/
private:
};
#if defined( _DEBUG ) && defined( __BUILDING_WCM__ )
#define WMULTIOSWARNING( os, msg ) \
if( WApplication::_globalObject && \
WApplication::_globalObject->_multiOSWarnings && \
___WCMOSVersion == os ){ \
WApplication::MultiOSWarning( os, msg );\
}
#elif defined( _DEBUG )
#define WMULTIOSWARNING( os, msg ) \
if( WApplication::GetApplicationObject() != NULL && WApplication::GetApplicationObject()->GetMultiOSWarnings() && WApplication::OSType() == os ) { \
WApplication::MultiOSWarning( os, msg ); \
}
#else
#define WMULTIOSWARNING( os, msg )
#endif
#ifndef _WNO_PRAGMA_PUSH
#pragma enum pop;
#pragma pack(pop);
#endif
#endif // _WAPPLIC_HPP_INCLUDED