⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 life.c

📁 开放源码的编译器open watcom 1.6.0版的源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
#include <string.h>
#include <stdio.h>

#define DEFINE_GLOBAL_VARS
#include "life.h"

static char LifeClass[32]="LifeClass";
static BOOL AnyInstance( HINSTANCE this_inst, int cmdshow );
static BOOL FirstInstance( HINSTANCE this_inst );

extern void Error( char *str )
/*****************************
    Pop up an error message box
*/
{
    MessageBox( NULL, str, Buffer, MB_ICONHAND+MB_OK+MB_SYSTEMMODAL );
}


extern BOOL NoMemory()
/********************/
{
    Error( "Out of memory" );
    return( FALSE );
}


int PASCAL WinMain( HINSTANCE this_inst, HINSTANCE prev_inst,
                    LPSTR cmdline, int cmdshow )
/***********************************************

    Initialization, message loop.
*/
{
    MSG         msg;

    cmdline = cmdline;

#ifdef __WINDOWS_386__
    sprintf( LifeClass,"LifeClass%d", this_inst );
    prev_inst = 0;
#endif
    if( !prev_inst ) {
        if( !FirstInstance( this_inst ) ) return( FALSE );
    }
    if( !AnyInstance( this_inst, cmdshow ) ) return( FALSE );

    while( GetMessage( &msg, NULL, NULL, NULL ) ) {

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

    }

    return( msg.wParam );

}

extern long _EXPORT FAR PASCAL WindowProc( HWND, unsigned, UINT, LONG );

static BOOL FirstInstance( HINSTANCE this_inst )
/********************************************

    Register window class for the application,
    and do any other application initialization.
*/
{
    WNDCLASS    wc;
    BOOL        rc;

    wc.style = CS_HREDRAW+CS_VREDRAW;
    wc.lpfnWndProc = (LPVOID) WindowProc;
    wc.cbClsExtra = 0;
    wc.cbWndExtra = 0;
    wc.hInstance = this_inst;
    wc.hIcon = 0;
    wc.hCursor = LoadCursor( NULL, IDC_ARROW );
    wc.hbrBackground = GetStockObject( WHITE_BRUSH );
    wc.lpszMenuName = "LifeMenu";
    wc.lpszClassName = LifeClass;
    rc = RegisterClass( &wc );
    return( rc );

}

static BOOL AnyInstance( HINSTANCE this_inst, int cmdshow )
/*******************************************************

    Do work required for every instance of the application:
    create the window, initialize data.
*/
{
    pixels      screen_x, screen_y;

    screen_x = GetSystemMetrics( SM_CXSCREEN );
    screen_y = GetSystemMetrics( SM_CYSCREEN );
    ScreenHeight = screen_y;

    ThisInst = this_inst;

    if( !ReadPatterns() ) return( FALSE );

    Pen = (HPEN)GetStockObject( BLACK_PEN );
    Brush = (HBRUSH)GetStockObject( HOLLOW_BRUSH );

    WinHandle = CreateWindow(
        LifeClass,              /* class */
        "Life",                 /* caption */
        WS_OVERLAPPEDWINDOW,    /* style */
        screen_x / 8,           /* init. x pos */
        screen_y / 8,           /* init. y pos */
        3 * screen_x / 4,       /* init. x size */
        3 * screen_y / 4,       /* init. y size */
        NULL,                   /* parent window */
        NULL,                   /* menu handle */
        this_inst,              /* program handle */
        NULL                    /* create parms */
        );

    if( !WinHandle ) return( FALSE );

    /*
     * display window
     */
    ShowWindow( WinHandle, cmdshow );
    UpdateWindow( WinHandle );

    Births[3] = TRUE;
    memset( Deaths, TRUE, sizeof( Deaths ) );
    Deaths[2] = FALSE;
    Deaths[3] = FALSE;
    CurvedSpace = TRUE;
    Mode = MENU_RESUME;
    MouseMode = MENU_FLIP_PATTERNS;
    return( InitTimer() );
}

BOOL _EXPORT FAR PASCAL About( HWND win_handle, unsigned msg,
                               UINT wparam, LONG lparam )
/************************************************************

    Process messages for the rules dialogue.
*/
{
    lparam = lparam;                    /* turn off warning */

    switch( msg ) {
    case WM_INITDIALOG:
        return( TRUE );

    case WM_COMMAND:
        if( LOWORD(wparam) == IDOK ) {
            EndDialog( win_handle, TRUE );
            return( TRUE );
        }
        break;
    }
    return( FALSE );

}


BOOL _EXPORT FAR PASCAL Rules( HWND win_handle, unsigned msg,
                                UINT wparam, LONG lparam )
/************************************************************

    Process messages for the rules dialogue.
*/
{
    static BOOL         WorkBirths[9], WorkDeaths[9];

    int         i;

    lparam = lparam;                    /* turn off warning */

    switch( msg ) {
    case WM_INITDIALOG:
        for( i = 0; i < 9; ++i ) {
            WorkBirths[ i ] = Births[ i ];
            WorkDeaths[ i ] = Deaths[ i ];
            CheckDlgButton( win_handle, BM_BIRTH_0+i, WorkBirths[ i ] );
            CheckDlgButton( win_handle, BM_DEATH_0+i, WorkDeaths[ i ] );
        }
        return( TRUE );

    case WM_COMMAND:
        switch( LOWORD(wparam) ) {
        case IDOK:
            for( i = 0; i < 9; ++i ) {
                Births[ i ] = WorkBirths[ i ];
                Deaths[ i ] = WorkDeaths[ i ];
            }
            /* fall through to next case */
        case IDCANCEL:
            EndDialog( win_handle, TRUE );
            return( TRUE );
        case BM_BIRTH_0:
        case BM_BIRTH_1:
        case BM_BIRTH_2:
        case BM_BIRTH_3:
        case BM_BIRTH_4:
        case BM_BIRTH_5:
        case BM_BIRTH_6:
        case BM_BIRTH_7:
        case BM_BIRTH_8:
            i = LOWORD(wparam) - BM_BIRTH_0;
            WorkBirths[ i ] = !WorkBirths[ i ];
            CheckDlgButton( win_handle, wparam, WorkBirths[ i ] );
            return( TRUE );
        case BM_DEATH_0:
        case BM_DEATH_1:
        case BM_DEATH_2:
        case BM_DEATH_3:
        case BM_DEATH_4:
        case BM_DEATH_5:
        case BM_DEATH_6:
        case BM_DEATH_7:
        case BM_DEATH_8:
            i = LOWORD(wparam) - BM_DEATH_0;
            WorkDeaths[ i ] = !WorkDeaths[ i ];
            CheckDlgButton( win_handle, wparam, WorkDeaths[ i ] );
            return( TRUE );
        case BM_DEATH_NEVER:
            for( i = 0; i < 9; ++i ) {
                WorkDeaths[ i ] = FALSE;
                CheckDlgButton( win_handle, BM_DEATH_0+i, WorkDeaths[ i ] );
            }
            return( TRUE );
        }
    }
    return( FALSE );

}



extern void FlushMouse()
/***********************

    Flush out any pending mouse events.
*/
{
    MSG         peek;
    while( PeekMessage( &peek, WinHandle, WM_MOUSEFIRST,
                        WM_MOUSELAST, PM_REMOVE ) );
}


static void DisplayDialog( char *name, BOOL _EXPORT FAR PASCAL rtn() )
/**********************************************************************

    Display a given dialog box.
*/
{
    FARPROC     proc;

    proc = MakeProcInstance( (FARPROC)rtn, ThisInst );
    DialogBox( ThisInst, name, WinHandle, (DLGPROC)proc );
    FreeProcInstance( proc );
}


static void ToPauseMode()
{
    Mode = MENU_PAUSE;
}

static void ToResumeMode()
{
    Mode = MENU_RESUME;
    SelectOff();
    MouseMode = MENU_FLIP_PATTERNS;
}


static void ToSelectMode()
{
    MouseMode = MENU_SELECT;
    Mode = MENU_PAUSE;
}

static void ToPatternFlipMode()
{
    SelectOff();
    MouseMode = MENU_FLIP_PATTERNS;
}


static void ToSingleStepMode()
{
    SelectOff();
    MouseMode = Mode = MENU_SINGLE_STEP;
}


static void MenuItem( WORD wparam )
/**********************************

    Handle a menu item which has been selected by the user.
*/
{
    if( wparam >= MENU_PATTERN && wparam <= MENU_PATTERN+NumberPatterns ) {
        SelectOff();
        MouseMode = MENU_FLIP_PATTERNS;
        SetCurrPattern( wparam-MENU_PATTERN );
        return;
    }
    switch( wparam ) {
    case MENU_ABOUT:

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -