Example #1
1
/*
 * GetFileName - create a window, and get file info
 */
BOOL GetFileName( HINSTANCE inst, int shcmd, char *fname )
{
    BOOL        rc;
    HWND        mh,win;
    HDC         dchandle;
    TEXTMETRIC  tm;
    int         x,y,avgx,avgy;
    int         xp,yp,xs,ys;
    WNDCLASS    wc;
    MSG         msg;
    HANDLE      accel;

    dataPtr = fname;
    wc.style = CS_HREDRAW | CS_VREDRAW;
    wc.lpfnWndProc = StartUpDriver;
    wc.cbClsExtra = 0;
    wc.cbWndExtra = 0;
    wc.hInstance = inst;
    wc.hIcon = LoadIcon( inst, "ApplIcon" );
    wc.hCursor = LoadCursor( NULL, IDC_ARROW );
    wc.hbrBackground = GetStockObject( WHITE_BRUSH );
    wc.lpszMenuName = ResName( "WSampStartMenu" );
    wc.lpszClassName = startClass;
    rc = RegisterClass( &wc );
    if( !rc ) {
        return( FALSE );
    }

    accel = LoadAccelerators( inst, "ApplAccl" );
    if( accel == NULL ) {
        return( FALSE );
    }

    x = GetSystemMetrics( SM_CXSCREEN );
    y = GetSystemMetrics( SM_CYSCREEN );

    mh = CreateWindow(
        startClass,             /* class */
        "Open Watcom Sampler",  /* caption */
        WS_CLIPCHILDREN | WS_OVERLAPPEDWINDOW, /* style */
        x/8,                    /* init. x pos */
        y/6,                    /* init. y pos */
        6*x/8,                  /* init. x size */
        y/2,                    /* init. y size */
        NULL,                   /* parent window */
        NULL,                   /* menu handle */
        inst,                   /* program handle */
        NULL                    /* create parms */
        );

    if( !mh ) {
        return( FALSE );
    }
    ShowWindow( mh, shcmd );
    UpdateWindow( mh );

    dchandle = GetDC( mh );
    GetTextMetrics( dchandle, &tm );
    avgx = AvgXChar( tm );
    avgy = AvgYChar( tm );
    ReleaseDC( mh, dchandle );
    mainWindow = mh;

    xp = 32;
    yp = y/8-10;
    ys = avgy+avgy/2;
    xs = (47+1) * avgx+avgx/2;

    win = CreateWindow(
        "STATIC",               /* class */
        "Sampler Options:",     /* caption */
        WS_CHILD | ES_LEFT,
        xp+(14*avgx)-6,         /* init. x pos */
        yp-3-avgy*3/2,          /* init. y pos */
        16*avgx,                /* init. x size */
        ys,                     /* init. y size */
        mh,                     /* parent window */
        NULL,                   /* child id */
        inst,                   /* program handle */
        NULL                    /* create parms */
        );
    ShowWindow( win, SW_SHOWNORMAL );
    UpdateWindow( win );

    win = CreateWindow(
        "EDIT",                 /* class */
        NULL,                   /* caption */
        WS_CHILD | ES_LEFT | WS_BORDER | ES_AUTOHSCROLL,
        xp+7,                   /* init. x pos */
        yp,                     /* init. y pos */
        xs,                     /* init. x size */
        ys,                     /* init. y size */
        mh,                     /* parent window */
        (HMENU)EDIT_ID,         /* child id */
        inst,                   /* program handle */
        NULL                    /* create parms */
        );


    if( win == NULL ) {
        return( FALSE );
    }
    editChild = win;

    ShowWindow( win, SW_SHOWNORMAL );
    UpdateWindow( win );

    oldClassProc = (FARPROC) GetWindowLong( editChild, GWL_WNDPROC );
    SetWindowLong( editChild, GWL_WNDPROC, (LONG) SubClassProc );

    win = CreateWindow(
        "BUTTON",               /* class */
        "&Select File...",      /* caption */
        WS_CHILD | BS_PUSHBUTTON,
        xp+(6*avgx)-6,          /* init. x pos */
        yp+avgy*3,              /* init. y pos */
        16*avgx,                /* init. x size */
        avgy+avgy/2,            /* init. y size */
        mh,                     /* parent window */
        (HMENU)PUSH_GETFILES_ID,/* child id */
        inst,                   /* program handle */
        NULL                    /* create parms */
        );
    ShowWindow( win, SW_SHOWNORMAL );
    UpdateWindow( win );

    win = CreateWindow(
        "BUTTON",               /* class */
        "S&tart Sampling",      /* caption */
        WS_CHILD | BS_PUSHBUTTON,
        xp+(29*avgx)-6,         /* init. x pos */
        yp+avgy*3,              /* init. y pos */
        16*avgx,                /* init. x size */
        avgy+avgy/2,            /* init. y size */
        mh,                     /* parent window */
        (HMENU)PUSH_OK_ID,      /* child id */
        inst,                   /* program handle */
        NULL                    /* create parms */
        );
    ShowWindow( win, SW_SHOWNORMAL );
    UpdateWindow( win );

    SetFocus( editChild );

    while( GetMessage( &msg, NULL, 0, 0 ) ) {
        if( !TranslateAccelerator( mainWindow, accel, &msg ) ) {
            TranslateMessage( &msg );
            DispatchMessage( &msg );
        }
    }

    return( canContinue );

} /* GetFileName */
Example #2
0
/*
 * MainDriver - message handler for sampler
 */
long __export FAR PASCAL MainDriver( HWND hwnd, UINT message, WPARAM wparam,
                                        LPARAM lparam )
{
    FARPROC     proc;

    switch (message) {
    case WM_TIMER:
        FlushSamples( (3*MAX_SAMPLES)/4 ); /* KLUDGE ALERT - flush
                                             tolerence should be done for
                                             real! */
        break;

    case WM_CLOSE:
        if( SharedMemory->ShopClosed ) {
            KillTimer( MainWindowHandle, TIMER_ID );
            DestroyWindow( MainWindowHandle );
            return( 0 );
        }
        MyOutput( MsgArray[MSG_SAMPLE_13-ERR_FIRST_MESSAGE] );
        return( 0 );
        break;
    case WM_COMMAND:
        switch( wparam ) {
        case MSG_ABOUT:
            proc = MakeProcInstance( (FARPROC)About, InstanceHandle );
            DialogBox(InstanceHandle, ResName( "AboutBox" ), hwnd, (DLGPROC)proc);
            FreeProcInstance(proc);
            break;
        case MSG_OPT:
            Usage();
            break;
        default:
            return( DefWindowProc( hwnd, message, wparam, lparam ) );
        }
        break;

    case WM_DESTROY:
        PostQuitMessage( 0 );
        break;

    default:
        return( DefWindowProc( hwnd, message, wparam, lparam ) );
    }
    return( 0 );

} /* MainDriver */
Example #3
0
/*
 * WindowsInit - windows-specific initialization
*/
int WindowsInit( HANDLE inst, int showcmd )
{
    WNDCLASS    wc;
    BOOL        rc;
    WORD        x,y;
    HGLOBAL     handle;

    if( !SetTimer( MainWindowHandle, TIMER_ID, 32000, 0L) ) {
        return( FALSE );
    }
    handle = GlobalAlloc( GMEM_FIXED | GMEM_ZEROINIT,
                          MAX_SAMPLES * sizeof( samp_save ) );
    if( handle == NULL ) {
        KillTimer( MainWindowHandle, TIMER_ID);
        return( FALSE );
    }
    SampSave = MK_FP( handle, 0 );

    wc.style = 0;
    wc.lpfnWndProc = MainDriver;
    wc.cbClsExtra = 0;
    wc.cbWndExtra = 0;
    wc.hInstance = inst;
    wc.hIcon = LoadIcon(inst, "ApplIcon" );
    wc.hCursor = LoadCursor(NULL, IDC_ARROW);
    wc.hbrBackground = GetStockObject(GRAY_BRUSH);
    wc.lpszMenuName =  ResName( "WSampMenu" );
    wc.lpszClassName = sampleClass;

    rc = RegisterClass( &wc );
    if( !rc ) {
        return( FALSE );
    }

    x = GetSystemMetrics( SM_CXSCREEN );
    y = GetSystemMetrics( SM_CYSCREEN );

    InstanceHandle = inst;

    MainWindowHandle = CreateWindow(
        sampleClass,
        "Open Watcom Sampler for Windows",
        WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN,  /* Window style.                      */
        0,                                      /* Default horizontal position.       */
        0,                                      /* Default vertical position.         */
        x,                                      /* width.                     */
        y,                                      /* height.                    */
        NULL,                                   /* Overlapped windows have no parent. */
        NULL,                                   /* Use the window class menu.         */
        inst,                                   /* This instance owns this window.    */
        NULL                                    /* Pointer not needed.                */
    );

    if( !MainWindowHandle ) return( FALSE );

    ShowWindow( MainWindowHandle, showcmd );
    UpdateWindow( MainWindowHandle );

    rc = StartOutput( x,y );
    return( rc );

} /* WindowsInit */
Example #4
0
/*
 * StartUpDriver - the main message handling loop
 */
long __export FAR PASCAL StartUpDriver( HWND hwnd, UINT message,
                                WPARAM wparam, LPARAM lparam )
{
    FARPROC     farproc;
    HWND        tmpw;
    int         len;
    char        data[_MAX_PATH];
    char        tmp[80 + _MAX_PATH];
    HINSTANCE   inst;

    switch( message ) {
    case WM_DESTROY:
        PostQuitMessage( 0 );
        break;

    case WM_COMMAND:
        switch( wparam ) {
        case MSG_ABOUT:
            inst = (HINSTANCE)GetWindowWord( hwnd, GWW_HINSTANCE );
            farproc = MakeProcInstance( (FARPROC)About2, inst );
            DialogBox( inst, ResName( "AboutBox" ), hwnd, (DLGPROC)farproc );
            FreeProcInstance( farproc );
            SetFocus( editChild );
            break;

        case PUSH_GETFILES_ID:
        case MSG_GETFILES:
            data[0] = 0;
            if( getFile( data ) ) {
                GetWindowText( editChild, tmp, sizeof( tmp ) );
                strcat( tmp, data );
                SetWindowText( editChild, tmp );
            }
            SetFocus( editChild );
            break;

        case PUSH_OK_ID:
        case SELECT_ID:
            len = GetWindowTextLength( editChild ) + 1;
            if( len > _MAX_PATH )
                len = _MAX_PATH;
            GetWindowText( editChild, dataPtr, len );
            canContinue = TRUE;
            tmpw = GetParent( editChild );
            SetWindowLong( editChild, GWL_WNDPROC, (LONG) oldClassProc );
            /* fall through, like exit was picked */

        case MSG_EXIT:
            DestroyWindow( mainWindow );
            PostQuitMessage( 0 );
            break;

        } /* switch */
        break;

    default:
        return( DefWindowProc(hwnd,message,wparam,lparam) );

    } /* switch */
    return( 0L );

} /* StartUpDriver */