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

📄 wintext.c

📁 frasr200的win 版本源码(18.21),使用make文件,使用的vc版本较低,在我的环境下编译有问题! 很不错的分形程序代码!
💻 C
📖 第 1 页 / 共 2 页
字号:
           /* someday we might want to do something special here */
           return (TRUE);

     case WM_COMMAND:
         /* if we added menu items, they would go here */
         return (DefWindowProc(hWnd, message, wParam, lParam));

     case WM_CLOSE:
         wintext_textmode = 1;
         wintext_AltF4hit = 1;
         return (DefWindowProc(hWnd, message, wParam, lParam));

        case WM_SIZE:
            /* code to prevent the window from exceeding a "full text page" */
            if (LOWORD(lParam) > wintext_max_width ||
                HIWORD(lParam) > wintext_max_height)
                SetWindowPos(wintext_hWndCopy,
                   GetNextWindow(wintext_hWndCopy, GW_HWNDPREV),
                   0, 0, wintext_max_width, wintext_max_height, SWP_NOMOVE);
            break;

     case WM_SETFOCUS : /* get focus - display caret */
          /* create caret & display */
          wintext_cursor_owned = 1;
          CreateCaret( wintext_hWndCopy, wintext_bitmap[wintext_cursor_type],
              wintext_char_width, wintext_char_height);
          SetCaretPos( wintext_cursor_x*wintext_char_width,
              wintext_cursor_y*wintext_char_height);
                SetCaretBlinkTime(500);
                ShowCaret( wintext_hWndCopy );
          break;

     case WM_KILLFOCUS : /* kill focus - hide caret */
          wintext_cursor_owned = 0;
          DestroyCaret();
          break;

       case WM_PAINT:  /* "Paint" routine - call the worker routine */
            hDC = BeginPaint(hWnd, &ps);
            GetUpdateRect(hWnd, &tempRect, FALSE);
            ValidateRect(hWnd, &tempRect);
            /* the routine below handles *all* window updates */
            wintext_paintscreen(0, wintext_char_xchars-1, 0, wintext_char_ychars-1);
            EndPaint(hWnd, &ps);
            break;

       case WM_KEYDOWN:   /* KEYUP, KEYDOWN, and CHAR msgs go to the 'keypressed' code */
            /* a key has been pressed - maybe ASCII, maybe not */
            /* if it's an ASCII key, 'WM_CHAR' will handle it  */
            {
            unsigned int i, j, k;
            i = (MapVirtualKey(wParam,0));
            j = (MapVirtualKey(wParam,2));
            k = (i << 8) + j;
            if (wParam == 0x10 || wParam == 0x11) { /* shift or ctl key */
                j = 0;       /* send flag: special key down */
                k = 0xff00 + wParam;
                }
            if (j == 0)        /* use this call only for non-ASCII keys */
                wintext_addkeypress(k);
            }
            break;

       case WM_KEYUP:   /* KEYUP, KEYDOWN, and CHAR msgs go to the SG code */
            /* a key has been released - maybe ASCII, maybe not */
            /* Watch for Shift, Ctl keys  */
            {
            unsigned int i, j, k;
            i = (MapVirtualKey(wParam,0));
            j = (MapVirtualKey(wParam,2));
            k = (i << 8) + j;
            j = 1;
            if (wParam == 0x10 || wParam == 0x11) { /* shift or ctl key */
                j = 0;       /* send flag: special key up */
                k = 0xfe00 + wParam;
                }
            if (j == 0)        /* use this call only for non-ASCII keys */
                wintext_addkeypress(k);
            }
            break;

       case WM_CHAR:   /* KEYUP, KEYDOWN, and CHAR msgs go to the SG code */
            /* an ASCII key has been pressed */
            {
            unsigned int i, j, k;
            i = (lParam & 0x00ff0000) >> 16;
            j = wParam;
            k = (i << 8) + j;
            wintext_addkeypress(k);
            }
            break;

     default:
         return (DefWindowProc(hWnd, message, wParam, lParam));
    }
    return (NULL);
}

/*
     simple keyboard logic capable of handling 80
     typed-ahead keyboard characters (more, if BUFMAX is changed)
          wintext_addkeypress() inserts a new keypress
          wintext_getkeypress(0) returns keypress-available info
          wintext_getkeypress(1) takes away the oldest keypress
*/

void wintext_addkeypress(unsigned int keypress)
{

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

if (wintext_keypress_count >= BUFMAX)
    /* no room */
    return;

if ((keypress & 0xfe00) == 0xfe00) {
    if (keypress == 0xff10) wintext_keypress_initstate |= 0x01;
    if (keypress == 0xfe10) wintext_keypress_initstate &= 0xfe;
    if (keypress == 0xff11) wintext_keypress_initstate |= 0x02;
    if (keypress == 0xfe11) wintext_keypress_initstate &= 0xfd;
    return;
    }

if (wintext_keypress_initstate != 0) {              /* shift/ctl key down */
    if ((wintext_keypress_initstate & 1) != 0) {    /* shift key down */
        if ((keypress & 0x00ff) == 9)             /* TAB key down */
                keypress = (15 << 8);             /* convert to shift-tab */
        if ((keypress & 0x00ff) == 0) {           /* special character */
            int i;
            i = (keypress >> 8) & 0xff;
            if (i >= 59 && i <= 68)               /* F1 thru F10 */
                keypress = ((i + 25) << 8);       /* convert to Shifted-Fn */
            }
        }
    else {                                        /* control key down */
        if ((keypress & 0x00ff) == 0) {           /* special character */
            int i;
            i = ((keypress & 0xff00) >> 8);
            if (i >= 59 && i <= 68)               /* F1 thru F10 */
                keypress = ((i + 35) << 8);       /* convert to Ctl-Fn */
            if (i == 71)
                keypress = (119 << 8);
            if (i == 73)
                keypress = (132 << 8);
            if (i == 75)
                keypress = (115 << 8);
            if (i == 77)
                keypress = (116 << 8);
            if (i == 79)
                keypress = (117 << 8);
            if (i == 81)
                keypress = (118 << 8);
            }
        }
    }

wintext_keypress_buffer[wintext_keypress_head] = keypress;
wintext_keypress_state[wintext_keypress_head] = wintext_keypress_initstate;
if (++wintext_keypress_head >= BUFMAX)
    wintext_keypress_head = 0;
wintext_keypress_count++;
}

unsigned int wintext_getkeypress(int option)
{
int i;

wintext_look_for_activity(option);

if (wintext_textmode != 2)  /* not in the right mode */
    return(27);

if (wintext_keypress_count == 0)
    return(0);

i = wintext_keypress_buffer[wintext_keypress_tail];

if (option != 0) {
    if (++wintext_keypress_tail >= BUFMAX)
        wintext_keypress_tail = 0;
    wintext_keypress_count--;
    }

return(i);

}


/*
     simple event-handler and look-for-keyboard-activity process

     called with parameter:
          0 = tell me if a key was pressed
          1 = wait for a keypress
     returns:
          0 = no activity
          1 = key pressed
*/

int wintext_look_for_activity(int wintext_waitflag)
{
MSG msg;
int i;

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

for (;;) {
    if (PeekMessage(&msg, NULL, NULL, NULL, PM_NOREMOVE) == 0)
        if (wintext_waitflag == 0 || wintext_keypress_count != 0
            || wintext_textmode != 2)
            return(wintext_keypress_count == 0 ? 0 : 1);

    if (GetMessage(&msg, NULL, NULL, NULL)) {
        TranslateMessage(&msg);
        DispatchMessage(&msg);
        }
    }

return(wintext_keypress_count == 0 ? 0 : 1);

}

/*
	general routine to send a string to the screen
*/

void wintext_putstring(int xpos, int ypos, int attrib, char far *string)
{
    int i, j, k, maxrow, maxcol;
    char xc, xa;

    xa = (attrib & 0x0ff);
    j = maxrow = ypos;
    k = maxcol = xpos-1;

    for (i = 0; (xc = string[i]) != 0; i++) {
        if (xc == 13 || xc == 10) {
            if (j < 24) j++;
            k = -1;
            }
        else {
            if ((++k) >= 80) {
                if (j < 24) j++;
                k = 0;
                }
            if (maxrow < j) maxrow = j;
            if (maxcol < k) maxcol = k;
            wintext_chars[j][k] = xc;
            wintext_attrs[j][k] = xa;
            }
        }
    if (i > 0) {
        wintext_paintscreen(xpos, maxcol, ypos, maxrow);
        }
}

/*
     general routine to repaint the screen
*/

void wintext_paintscreen(
    int xmin,       /* update this rectangular section */
    int xmax,       /* of the 'screen'                 */
    int ymin,
    int ymax)
{
int i, j, k;
int istart, jstart, length, foreground, background;
unsigned char wintext_oldbk;
unsigned char wintext_oldfg;
HDC hDC;
HWND hWnd;

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

/* first time through?  Initialize the 'screen' */
if (wintext_buffer_init == 0) {
    wintext_buffer_init = 1;
    wintext_oldbk = 0x00;
    wintext_oldfg = 0x0f;
    k = (wintext_oldbk << 4) + wintext_oldfg;
    wintext_buffer_init = 1;
    for (i = 0; i < wintext_char_xchars; i++) {
        for (j = 0; j < wintext_char_ychars; j++) {
            wintext_chars[j][i] = ' ';
            wintext_attrs[j][i] = k;
            }
        }
    }

if (xmin < 0) xmin = 0;
if (xmax >= wintext_char_xchars) xmax = wintext_char_xchars-1;
if (ymin < 0) ymin = 0;
if (ymax >= wintext_char_ychars) ymax = wintext_char_ychars-1;

hDC=GetDC(wintext_hWndCopy);
SelectObject(hDC, wintext_hFont);
SetBkMode(hDC, OPAQUE);
SetTextAlign(hDC, TA_LEFT | TA_TOP);

if (wintext_cursor_owned != 0)
    HideCaret( wintext_hWndCopy );

/*
   the following convoluted code minimizes the number of
   discrete calls to the Windows interface by locating
   'strings' of screen locations with common foreground
   and background colors
*/

for (j = ymin; j <= ymax; j++) {
    length = 0;
    wintext_oldbk = 99;
    wintext_oldfg = 99;
    for (i = xmin; i <= xmax+1; i++) {
        k = -1;
        if (i <= xmax)
            k = wintext_attrs[j][i];
        foreground = (k & 15);
        background = (k >> 4);
        if (i > xmax || foreground != wintext_oldfg || background != wintext_oldbk) {
            if (length > 0) {
                SetBkColor(hDC,wintext_color[wintext_oldbk]);
                SetTextColor(hDC,wintext_color[wintext_oldfg]);
                TextOut(hDC,
                    istart*wintext_char_width,
                    jstart*wintext_char_height,
                    &wintext_chars[jstart][istart],
                    length);
                }
            wintext_oldbk = background;
            wintext_oldfg = foreground;
         istart = i;
         jstart = j;
         length = 0;
            }
        length++;
        }
    }

if (wintext_cursor_owned != 0)
    ShowCaret( wintext_hWndCopy );

ReleaseDC(wintext_hWndCopy,hDC);

}

void wintext_cursor(int xpos, int ypos, int cursor_type)
{

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

    wintext_cursor_x = xpos;
    wintext_cursor_y = ypos;
    if (cursor_type >= 0) wintext_cursor_type = cursor_type;
    if (wintext_cursor_type < 0) wintext_cursor_type = 0;
    if (wintext_cursor_type > 2) wintext_cursor_type = 2;
    if (wintext_cursor_owned != 0)
        {
        CreateCaret( wintext_hWndCopy, wintext_bitmap[wintext_cursor_type],
              wintext_char_width, wintext_char_height);
              SetCaretPos( wintext_cursor_x*wintext_char_width,
                  wintext_cursor_y*wintext_char_height);
              SetCaretBlinkTime(500);
              ShowCaret( wintext_hWndCopy );
        }

}

⌨️ 快捷键说明

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