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

📄 wintext.c

📁 frasr200的win 版本源码(18.21),使用make文件,使用的vc版本较低,在我的环境下编译有问题! 很不错的分形程序代码!
💻 C
📖 第 1 页 / 共 2 页
字号:
#include <windows.h>
#include <string.h>
#include <stdlib.h>

/*
	WINTEXT.C handles the character-based "prompt screens",
	using a 24x80 character-window driver that I wrote originally
	for the Windows port of the DOS-based "Screen Generator"
	commercial package - Bert Tyler

	the subroutines and their functions are:

BOOL wintext_initialize(HANDLE hInstance, LPSTR title);
    Registers and initializes the text window - must be called
    once (and only once).  Its parameters are the handle of the application
    instance and a pointer to a string containing the title of the window.
void wintext_destroy();
    Destroys items like bitmaps that the initialization routine has
    created.  Should be called once (and only once) as your program exits.

int wintext_texton();
    Brings up and blanks out the text window.  No parameters.
int wintext_textoff();
    Removes the text window.  No parameters.

void wintext_putstring(int xpos, int ypos, int attrib, char far *string);
    Sends a character string to the screen starting at (xpos, ypos)
    using the (CGA-style and, yes, it should be a 'char') specified attribute. 
void wintext_paintscreen(int xmin, int xmax, int ymin, int ymax);
    Repaints the rectangular portion of the text screen specified by
    the four parameters, which are in character co-ordinates.  This
    routine is called automatically by 'wintext_putstring()' as well as
    other internal routines whenever Windows uncovers the window.  It can
    also be called  manually by your program when it wants a portion
    of the screen updated (the actual data is kept in two arrays, which
    your program has presumably updated:)
       unsigned char far wintext_chars[25][80]  holds the text
       unsigned char far wintext_attrs[25][80]  holds the (CGA-style) attributes

void wintext_cursor(int xpos, int ypos, int cursor_type);
    Sets the cursor to character position (xpos, ypos) and switches to
    a cursor type specified by 'cursor_type': 0 = none, 1 = underline,
    2 = block cursor.  A cursor type of -1 means use whatever cursor
    type (0, 1, or 2) was already active.

unsigned int wintext_getkeypress(int option);
    A simple keypress-retriever that, based on the parameter, either checks
    for any keypress activity (option = 0) or waits for a keypress before
    returning (option != 0).  Returns a 0 to indicate no keystroke, or the
    keystroke itself.  Up to 80 keystrokes are queued in an internal buffer.
    If the text window is not open, returns an ESCAPE keystroke (27).
    The keystroke is returned as an integer value identical to that a
    DOS program receives in AX when it invokes INT 16H, AX = 0 or 1.

int wintext_look_for_activity(int option);
    An internal routine that handles buffered keystrokes and lets
    Windows messaging (multitasking) take place.  Called with option=0,
    it returns without waiting for the presence of a keystroke.  Called
    with option !=0, it waits for a keystroke before returning.  Returns
    1 if a keystroke is pending, 0 if none pending.  Called internally
    (and automatically) by 'wintext_getkeypress()'.
void wintext_addkeypress(unsigned int);
    An internal routine, called by 'wintext_look_for_activity()' and
    'wintext_proc()', that adds keystrokes to an internal buffer.
    Never called directly by the applications program.
long FAR PASCAL wintext_proc(HANDLE, unsigned, WORD, LONG);
    An internal routine that handles all message functions while
    the text window is on the screen.  Never called directly by
    the applications program, but must be referenced as a call-back
    routine by your ".DEF" file.

	The 'wintext_textmode' flag tracks the current textmode status.
	Note that pressing Alt-F4 closes and destroys the window *and*
	resets this flag (to 1), so the main program should look at
	this flag whenever it is possible that Alt-F4 has been hit!
	('wintext_getkeypress()' returns a 27 (ESCAPE) if this happens)
	(Note that you can use an 'WM_CLOSE' case to handle this situation.)
        The 'wintext_textmode' values are:
        	0 = the initialization routine has never been called!
        	1 = text mode is *not* active
        	2 = text mode *is* active
	There is also a 'wintext_AltF4hit' flag that is non-zero if
	the window has been closed (by an Alt-F4, or a WM_CLOSE sequence)
	but the application program hasn't officially closed the window yet.
*/

int far wintext_textmode = 0;
int far wintext_AltF4hit = 0;

/* function prototypes */

BOOL wintext_initialize(HANDLE, HWND, LPSTR);
void wintext_destroy();
long FAR PASCAL wintext_proc(HANDLE, unsigned, WORD, LONG);
int wintext_texton();
int wintext_textoff();
void wintext_putstring(int xpos, int ypos, int attrib, char far *string);
void wintext_paintscreen(int, int, int, int);
void wintext_cursor(int, int, int);
int wintext_look_for_activity(int);
void wintext_addkeypress(unsigned int);
unsigned int wintext_getkeypress(int);

/* Local copy of the "screen" characters and attributes */

unsigned char far wintext_chars[25][80];
unsigned char far wintext_attrs[25][80];
int far wintext_buffer_init;     /* zero if 'screen' is uninitialized */

/* font information */

HFONT far wintext_hFont;
int far wintext_char_font;
int far wintext_char_width;
int far wintext_char_height;
int far wintext_char_xchars;
int far wintext_char_ychars;
int far wintext_max_width;
int far wintext_max_height;

/* "cursor" variables (AKA the "caret" in Window-Speak) */
int far wintext_cursor_x;
int far wintext_cursor_y;
int far wintext_cursor_type;
int far wintext_cursor_owned;
HBITMAP far wintext_bitmap[3];
short far wintext_cursor_pattern[3][40];

LPSTR wintext_title_text;         /* title-bar text */

/* a few Windows variables we need to remember globally */

HWND far wintext_hWndCopy;                /* a Global copy of hWnd */
HWND far wintext_hWndParent;              /* a Global copy of hWnd's Parent */
HANDLE far wintext_hInstance;             /* a global copy of hInstance */

/* the keypress buffer */

#define BUFMAX 80
unsigned int  far wintext_keypress_count;
unsigned int  far wintext_keypress_head;
unsigned int  far wintext_keypress_tail;
unsigned char far wintext_keypress_initstate;
unsigned int  far wintext_keypress_buffer[BUFMAX];
unsigned char far wintext_keypress_state[BUFMAX];

/* EGA/VGA 16-color palette (which doesn't match Windows palette exactly) */
/*
COLORREF wintext_color[] = {
    RGB(0,0,0),
    RGB(0,0,168),
    RGB(0,168,0),
    RGB(0,168,168),
    RGB(168,0,0),
    RGB(168,0,168),
    RGB(168,84,0),
    RGB(168,168,168),
    RGB(84,84,84),
    RGB(84,84,255),
    RGB(84,255,84),
    RGB(84,255,255),
    RGB(255,84,84),
    RGB(255,84,255),
    RGB(255,255,84),
    RGB(255,255,255)
    };
*/
/* 16-color Windows Palette */

COLORREF wintext_color[] = {
    RGB(0,0,0),
    RGB(0,0,128),
    RGB(0,128,0),
    RGB(0,128,128),
    RGB(128,0,0),
    RGB(128,0,128),
    RGB(128,128,0),
    RGB(192,192,192),
/*  RGB(128,128,128),  This looks lousy - make it black */  RGB(0,0,0),
    RGB(0,0,255),
    RGB(0,255,0),
    RGB(0,255,255),
    RGB(255,0,0),
    RGB(255,0,255),
    RGB(255,255,0),
    RGB(255,255,255)
    };

/*
     Register the text window - a one-time function which perfomrs
     all of the neccessary registration and initialization
*/

BOOL wintext_initialize(HANDLE hInstance, HWND hWndParent, LPSTR titletext)
{
    WNDCLASS  wc;
    BOOL return_value;
    HDC hDC;
    HFONT hOldFont;
    TEXTMETRIC TextMetric;
    int i, j;

    wintext_hInstance = hInstance;
    wintext_title_text = titletext;
    wintext_hWndParent = hWndParent;

    wc.style = NULL;
    wc.lpfnWndProc = wintext_proc;
    wc.cbClsExtra = 0;
    wc.cbWndExtra = 0;
    wc.hInstance = hInstance;
    wc.hIcon = NULL;
    wc.hCursor = LoadCursor(NULL, IDC_ARROW);
    wc.hbrBackground = GetStockObject(BLACK_BRUSH);
    wc.lpszMenuName =  titletext;
    wc.lpszClassName = "FractintForWindowsV0011";

    return_value = RegisterClass(&wc);

    /* set up the font characteristics */
    wintext_char_font = OEM_FIXED_FONT;
    wintext_hFont = GetStockObject(wintext_char_font);
    hDC=GetDC(hWndParent);
    hOldFont = SelectObject(hDC, wintext_hFont);
    GetTextMetrics(hDC, &TextMetric);
    SelectObject(hDC, hOldFont);
    ReleaseDC(hWndParent, hDC);
    wintext_char_width  = TextMetric.tmMaxCharWidth;
    wintext_char_height = TextMetric.tmHeight;
    wintext_char_xchars = 80;
    wintext_char_ychars = 25;

    wintext_max_width =                           /* maximum screen width */
        wintext_char_xchars*wintext_char_width+
            (GetSystemMetrics(SM_CXFRAME) * 2);
    wintext_max_height =                           /* maximum screen height */
        wintext_char_ychars*wintext_char_height+
            (GetSystemMetrics(SM_CYFRAME) * 2)
            -1
             + GetSystemMetrics(SM_CYCAPTION);

    /* set up the font and caret information */
    for (i = 0; i < 3; i++)
        for (j = 0; j < wintext_char_height; j++)
            wintext_cursor_pattern[i][j] = 0;
    for (j = wintext_char_height-2; j < wintext_char_height; j++)
        wintext_cursor_pattern[1][j] = 0x00ff;
    for (j = 0; j < wintext_char_height; j++)
        wintext_cursor_pattern[2][j] = 0x00ff;
    wintext_bitmap[0] = CreateBitmap(8, wintext_char_height, 1, 1,
        (LPSTR)wintext_cursor_pattern[0]);
    wintext_bitmap[1] = CreateBitmap(8, wintext_char_height, 1, 1,
        (LPSTR)wintext_cursor_pattern[1]);
    wintext_bitmap[2] = CreateBitmap(8, wintext_char_height, 1, 1,
        (LPSTR)wintext_cursor_pattern[2]);

    wintext_textmode = 1;
    wintext_AltF4hit = 0;

    return(return_value);
}

/*
	clean-up routine
*/
void wintext_destroy()
{
int i;

    if (wintext_textmode == 2)  /* text is still active! */
        wintext_textoff();
    if (wintext_textmode != 1)  /* not in the right mode */
        return;

/*
    DeleteObject((HANDLE)wintext_hFont);
*/
    for (i = 0; i < 3; i++)
        DeleteObject((HANDLE)wintext_bitmap[i]);
    wintext_textmode = 0;
    wintext_AltF4hit = 0;
}


/*
     Set up the text window and clear it
*/

int wintext_texton()
{
    HWND hWnd;
    int i, j, k;

    if (wintext_textmode != 1)  /* not in the right mode */
        return(0);

    /* initialize the cursor */
    wintext_cursor_x    = 0;
    wintext_cursor_y    = 0;
    wintext_cursor_type = 0;
    wintext_cursor_owned = 0;

    /* clear the keyboard buffer */
    wintext_keypress_count = 0;
    wintext_keypress_head  = 0;
    wintext_keypress_tail  = 0;
    wintext_keypress_initstate = 0;
    wintext_buffer_init = 0;

    hWnd = CreateWindow(
        "FractintForWindowsV0011",
        wintext_title_text,
        WS_OVERLAPPEDWINDOW,
        CW_USEDEFAULT,               /* default horizontal position */
        CW_USEDEFAULT,               /* default vertical position */
        wintext_max_width,
        wintext_max_height,
        wintext_hWndParent,
        NULL,
        wintext_hInstance,
        NULL);

    /* squirrel away a global copy of 'hWnd' for later */
    wintext_hWndCopy = hWnd;

    wintext_textmode = 2;
    wintext_AltF4hit = 0;

    ShowWindow(wintext_hWndCopy, SW_SHOWNORMAL);
    UpdateWindow(wintext_hWndCopy);

    InvalidateRect(wintext_hWndCopy,NULL,FALSE);

    return(0);
}

/*
     Remove the text window
*/

int wintext_textoff()
{

    wintext_AltF4hit = 0;
    if (wintext_textmode != 2)  /* not in the right mode */
        return(0);
    DestroyWindow(wintext_hWndCopy);
    wintext_textmode = 1;
    return(0);
}

/*
	Window-handling procedure
*/


long FAR PASCAL wintext_proc(hWnd, message, wParam, lParam)
HWND hWnd;
unsigned message;
WORD wParam;
LONG lParam;
{
    RECT tempRect;
    PAINTSTRUCT ps;
    HDC hDC;

    if (hWnd != wintext_hWndCopy)  /* ??? not the text-mode window! */
         return (DefWindowProc(hWnd, message, wParam, lParam));

    switch (message) {

        case WM_INITMENU:
           /* first time through*/

⌨️ 快捷键说明

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