| 1 | #include <stdlib.h> 
 | 
|---|
| 2 | #include <string.h>
 | 
|---|
| 3 | 
 | 
|---|
| 4 | #include "Utility.h"
 | 
|---|
| 5 | #include "log.h"
 | 
|---|
| 6 | 
 | 
|---|
| 7 | char GetBootDrive()
 | 
|---|
| 8 | {
 | 
|---|
| 9 |   ULONG buffer;
 | 
|---|
| 10 |   DosQuerySysInfo( QSV_BOOT_DRIVE, 
 | 
|---|
| 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 |   {
 | 
|---|
| 42 |     parent = WinQueryWindow( hwnd, QW_PARENT );    
 | 
|---|
| 43 |     if (    parent == hDesktopWindow
 | 
|---|
| 44 |          || parent == NULLHANDLE )
 | 
|---|
| 45 |       // this is a frame (top level) window
 | 
|---|
| 46 |       break;
 | 
|---|
| 47 |     hwnd = parent; 
 | 
|---|
| 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 | 
 | 
|---|
| 63 |   if ( WinQueryClassName( hwnd, 
 | 
|---|
| 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 | 
 | 
|---|
| 86 | void StoreString( char** dest,
 | 
|---|
| 87 |                   char* source )
 | 
|---|
| 88 | {
 | 
|---|
| 89 |   if ( *dest != NULL )  
 | 
|---|
| 90 |   {
 | 
|---|
| 91 |     free( *dest );
 | 
|---|
| 92 |     *dest = NULL;
 | 
|---|
| 93 |   }
 | 
|---|
| 94 |   
 | 
|---|
| 95 |   if ( source == NULL )  
 | 
|---|
| 96 |     return;
 | 
|---|
| 97 | 
 | 
|---|
| 98 |   *dest = (char*) malloc( strlen( source ) + 1 );
 | 
|---|
| 99 |   strcpy( *dest, source );
 | 
|---|
| 100 | }
 | 
|---|
| 101 | 
 | 
|---|