KillerDB Import Utility

The KillerDB Import Utility converts tab delimited text files into a custom database file format, for a database app I'm writing for a client. They wanted to be able to update the data themselves, and GameTune let me add a nice GUI to this command line utility.

Notice how the Save/Load buttons are hidden, and how the Cancel button is disabled. The program can disable/enable/hide/show controls at any time.

INI Example

Here is an example of what a GameTune GTI file looks like. It defines all the tabs and tuners in the interface, as well as properties of the panel itself.

[Options]
WindowTitle = KillerDB Import Utility
ButtonsDisabled = 1
InitialX = 100
InitialY = 100
InitialWidth = 600
InitialHeight = 500


[Import Controls]
TunerFileSelect = InputFile
Name   = Select Input File
Filter = Text Files~*.txt
DefExt = txt


TunerFileSelect = CriteriaFile
Name   = Select Criteria File
Filter = Text Files~*.txt
DefExt = txt


TunerFileSelect = OutputFile
Name   = Select Output File
Filter = KillerDB Files~*.kdb
DefExt = kdb


TunerBool = RefineCriteria
Name   = Refine Criteria
Value  = 0
Style  = YesNo


TunerButton = ImportBtn
Name   = Import Data


TunerLabel
Name   = Current Activity
Style  = Divider


TunerLabel = Activity
Name   = Import Status
Style  = Monitor
Value  = Ready.


TunerProgress = Progress
Name   = Progress
Min    = 0
Max    = 100


TunerButton = CancelBtn
Name   = Cancel
Disabled = 1

Code Example

The following two functions demonstrate using GameTune as a standalone interface. The only special handling needed is to pass NULL as the Parent HWND to gtInit, and to regularly empty the message queue during long operations. It's all pretty straightforward.

int APIENTRY WinMain(HINSTANCE hInstance,
                     HINSTANCE hPrevInstance,
                     LPSTR     lpCmdLine,
                     int       nCmdShow)
{
    MSG msg;

    gtInit( "klimport.gti" );

    // GameTune window is solo here, so pass NULL as the parent window.
    gtCreateWindow( hInstance, NULL );

    // Main message loop:
    while (GetMessage(&msg, NULL, 0, 0)) 
    {
        TranslateMessage(&msg);
        DispatchMessage(&msg);

        // Check the import button.
        if ( gtGetInt( GT_IMPORT ) )
        {
            gtSetDisabled( GT_INPUT_FILE, true );
            gtSetDisabled( GT_CRITERIA_FILE, true );
            gtSetDisabled( GT_OUTPUT_FILE, true );
            gtSetDisabled( GT_REFINE_CRITERIA, true );
            gtSetDisabled( GT_IMPORT, true );
            gtSetDisabled( GT_CANCEL, false );

            DoImport();

            gtSetDisabled( GT_CANCEL, true );
            gtSetDisabled( GT_INPUT_FILE, false );
            gtSetDisabled( GT_CRITERIA_FILE, false );
            gtSetDisabled( GT_OUTPUT_FILE, false );
            gtSetDisabled( GT_REFINE_CRITERIA, false );
            gtSetDisabled( GT_IMPORT, false );
        }

        // See if they closed the GameTune window.
        if ( !gtGetWindow() )
            PostQuitMessage( 0 );
    }

    gtShutdown();
    
    return 0;
}

// Empty the message queue.  This function should be called regularly during long operations.
// Returns false if the Import process has been aborted.
bool CheckMessages()
{
    MSG msg;

    // Main message loop:
    while ( PeekMessage( &msg, NULL, 0, 0, PM_NOREMOVE ) ) 
    {
        if ( !GetMessage( &msg, NULL, 0, 0 ) )
            return false;

        TranslateMessage(&msg);
        DispatchMessage(&msg);

        // Check for closed window.
        if ( !gtGetWindow() )
            return false;
        
        // Check for cancel button.        
        if ( gtGetInt( GT_CANCEL ) )
        {
            gtSetString( GT_ACTIVITY, "Canceled." );
            MessageBeep( MB_ICONHAND );
            return false;
        }
    }

    return true;
}