[360] | 1 | #include <stdlib.h>
|
---|
[26] | 2 | #include <string.h>
|
---|
| 3 |
|
---|
| 4 | #include "Utility.h"
|
---|
| 5 | #include "log.h"
|
---|
| 6 |
|
---|
| 7 | char GetBootDrive()
|
---|
| 8 | {
|
---|
| 9 | ULONG buffer;
|
---|
[360] | 10 | DosQuerySysInfo( QSV_BOOT_DRIVE,
|
---|
[26] | 11 | QSV_BOOT_DRIVE,
|
---|
| 12 | & buffer,
|
---|
| 13 | sizeof( buffer ) );
|
---|
| 14 | return 'A' + buffer - 1;
|
---|
| 15 | }
|
---|
| 16 |
|
---|
| 17 | void GetApplicationFilename( char* Buffer, ULONG BufferLength )
|
---|
| 18 | {
|
---|
| 19 | PTIB pThreadInfo;
|
---|
| 20 | PPIB pProcessInfo;
|
---|
| 21 |
|
---|
| 22 | DosGetInfoBlocks( & pThreadInfo,
|
---|
| 23 | & pProcessInfo );
|
---|
| 24 | DosQueryModuleName( pProcessInfo -> pib_hmte,
|
---|
| 25 | BufferLength,
|
---|
| 26 | Buffer );
|
---|
| 27 | }
|
---|
| 28 |
|
---|
| 29 | // Returns the top level parent of given window
|
---|
| 30 | //--------------------------------------------------------------------------------
|
---|
| 31 | HWND GetTopLevelWindow( HWND hwnd )
|
---|
| 32 | {
|
---|
| 33 | HWND parent;
|
---|
| 34 | HWND hDesktopWindow;
|
---|
| 35 | HAB hab;
|
---|
| 36 |
|
---|
| 37 | hab = WinQueryAnchorBlock( hwnd );
|
---|
| 38 | hDesktopWindow = WinQueryDesktopWindow( hab, NULLHANDLE );
|
---|
| 39 |
|
---|
| 40 | while( TRUE )
|
---|
| 41 | {
|
---|
[360] | 42 | parent = WinQueryWindow( hwnd, QW_PARENT );
|
---|
[26] | 43 | if ( parent == hDesktopWindow
|
---|
| 44 | || parent == NULLHANDLE )
|
---|
| 45 | // this is a frame (top level) window
|
---|
| 46 | break;
|
---|
[360] | 47 | hwnd = parent;
|
---|
[26] | 48 | }
|
---|
| 49 |
|
---|
| 50 | return hwnd;
|
---|
| 51 | }
|
---|
| 52 |
|
---|
| 53 | // Returns true if the given window has the
|
---|
| 54 | // given standard class (e.g. WC_FRAME)
|
---|
| 55 | //--------------------------------------------------------------------------------
|
---|
| 56 | BOOL IsStandardWindowClass( HWND hwnd, PSZ ClassID )
|
---|
| 57 | {
|
---|
| 58 | char szClassName[ 256 ];
|
---|
| 59 | USHORT usClass;
|
---|
| 60 |
|
---|
| 61 | LogEvent( "IsStandardWindowClass" );
|
---|
| 62 |
|
---|
[360] | 63 | if ( WinQueryClassName( hwnd,
|
---|
[26] | 64 | sizeof( szClassName ),
|
---|
| 65 | szClassName ) == 0 )
|
---|
| 66 | // not a valid window
|
---|
| 67 | return FALSE;
|
---|
| 68 |
|
---|
| 69 | LogEvent( " Valid window" );
|
---|
| 70 |
|
---|
| 71 | if ( szClassName[ 0 ] != '#' )
|
---|
| 72 | // not a standard class
|
---|
| 73 | return FALSE;
|
---|
| 74 |
|
---|
| 75 | LogEvent( " Is standard class" );
|
---|
| 76 |
|
---|
| 77 | // Predefined class
|
---|
| 78 | usClass = atoi( szClassName + 1 );
|
---|
| 79 |
|
---|
| 80 | LogEvent( " usClass: %hu", usClass );
|
---|
| 81 | LogEvent( " Match class: %hu", (USHORT) ClassID );
|
---|
| 82 |
|
---|
| 83 | return usClass == (USHORT) ClassID;
|
---|
| 84 | }
|
---|
| 85 |
|
---|
[361] | 86 | void StoreString( char** dest, char* source )
|
---|
[26] | 87 | {
|
---|
[360] | 88 | if ( *dest != NULL )
|
---|
[26] | 89 | {
|
---|
| 90 | free( *dest );
|
---|
| 91 | *dest = NULL;
|
---|
| 92 | }
|
---|
[360] | 93 |
|
---|
| 94 | if ( source == NULL )
|
---|
[26] | 95 | return;
|
---|
| 96 |
|
---|
| 97 | *dest = (char*) malloc( strlen( source ) + 1 );
|
---|
| 98 | strcpy( *dest, source );
|
---|
| 99 | }
|
---|
[360] | 100 |
|
---|