夜雨聆风学习资料网

ARTICLE · 1417302

用古董级TC2.0,我在纯C语言里手搓了一个Win98桌面!附完整源码

用古董级TC2.0,我在纯C语言里手搓了一个Win98桌面!附完整源码
在如今动辄几GB内存、各种复杂前端框架横行的时代,我们每天都在享受着高科技带来的便利。但你是否还记得,微型计算机刚刚走进千家万户时,那纯蓝色的桌面、清脆的提示音,以及充满极客感的命令行?
前几天,我用上世纪90年代的古董级编译器 ——Turbo C 2.0(纯DOS环境),在纯C语言下硬核复刻了一个微型版的Windows 98 登录与桌面系统,并在短视频平台发布了17秒的演示视频,瞬间唤醒了无数老极客的青春记忆。

🌟 项目核心亮点:全套界面均为纯C手打,支持登录验证、桌面UI、开始菜单、状态栏、动态实时时钟,以及可交互的 MSDOS 命令行工具(支持内存查看、磁盘信息及安全退出)。

一、 核心功能模块展示

整个微型系统在有限的资源下还原了经典的交互体验:
登录验证模块:模仿 Win98 经典的蓝底灰框登录界面,输入正确的账号密码后方可进入桌面。
桌面与任务栏环境:成功登录后淡入经典蓝色桌面,左下角展示“开始”菜单,底部为任务栏,右下角实现动态时间更新。
交互式 MSDOS 命令行:桌面中央放置了 MSDOS 图标。双击(点击)即可唤醒黑色命令行窗口,支持以下内置指令:

二、 核心源码架构设计

由于 TC2.0 运行在 16 位 DOS 实模式下,我们需要借助图形库  来进行底层的像素点阵绘制、界面刷新以及事件捕获。

三、 源码获取

用代码致敬经典,用热爱对抗时间。虽然 TC2.0 已经是几十年前的古董,但它承载了老一辈程序员对计算机最初的梦想与纯粹的热爱。
如果你也想在本地亲自体验、修改甚至扩展这个项目,欢迎在后台回复关键词“Win98”即可获取完整的 C 语言源代码及 TC2.0 运行环境配置指南!
#include <dos.h>
#include <bios.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <mem.h>
#defineVMEM 0xA0000000L
#defineSCRW 320
#defineSCRH 200
#defineCLR_TEAL 3
#defineCLR_GRAY 7
#defineCLR_DGRAY 8
#defineCLR_WHITE 15
#defineCLR_BLACK 0
#defineCLR_BLUE 1
#defineCLR_LTBLUE 9
#defineCLR_RED 4
#defineCLR_LTGRAY 7
#defineCLR_YELLOW 14
#defineCLR_GREEN 2
char far *vga = (char far *) VMEM;
int mousepresent = 0;
int mx = 160;
int my = 100;
unsigned char cursave[16 * 16];
int cursaved = 0;
int savex, savey;
unsigned char font8x8[96][8] = {
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
{0x18,0x3C,0x3C,0x18,0x18,0x00,0x18,0x00},
{0x36,0x36,0x24,0x00,0x00,0x00,0x00,0x00},
{0x36,0x36,0x7F,0x36,0x7F,0x36,0x36,0x00},
{0x0C,0x3E,0x03,0x1E,0x30,0x1F,0x0C,0x00},
{0x00,0x63,0x33,0x18,0x0C,0x66,0x63,0x00},
{0x1C,0x36,0x1C,0x6E,0x3B,0x33,0x6E,0x00},
{0x06,0x06,0x03,0x00,0x00,0x00,0x00,0x00},
{0x18,0x0C,0x06,0x06,0x06,0x0C,0x18,0x00},
{0x06,0x0C,0x18,0x18,0x18,0x0C,0x06,0x00},
{0x00,0x66,0x3C,0xFF,0x3C,0x66,0x00,0x00},
{0x00,0x0C,0x0C,0x3F,0x0C,0x0C,0x00,0x00},
{0x00,0x00,0x00,0x00,0x00,0x0C,0x0C,0x06},
{0x00,0x00,0x00,0x3F,0x00,0x00,0x00,0x00},
{0x00,0x00,0x00,0x00,0x00,0x0C,0x0C,0x00},
{0x60,0x30,0x18,0x0C,0x06,0x03,0x01,0x00},
{0x3E,0x63,0x73,0x7B,0x6F,0x67,0x3E,0x00},
{0x0C,0x0E,0x0C,0x0C,0x0C,0x0C,0x3F,0x00},
{0x1E,0x33,0x30,0x1C,0x06,0x33,0x3F,0x00},
{0x1E,0x33,0x30,0x1C,0x30,0x33,0x1E,0x00},
{0x38,0x3C,0x36,0x33,0x7F,0x30,0x78,0x00},
{0x3F,0x03,0x1F,0x30,0x30,0x33,0x1E,0x00},
{0x1C,0x06,0x03,0x1F,0x33,0x33,0x1E,0x00},
{0x3F,0x33,0x30,0x18,0x0C,0x0C,0x0C,0x00},
{0x1E,0x33,0x33,0x1E,0x33,0x33,0x1E,0x00},
{0x1E,0x33,0x33,0x3E,0x30,0x18,0x0E,0x00},
{0x00,0x0C,0x0C,0x00,0x00,0x0C,0x0C,0x00},
{0x00,0x0C,0x0C,0x00,0x00,0x0C,0x0C,0x06},
{0x18,0x0C,0x06,0x03,0x06,0x0C,0x18,0x00},
{0x00,0x00,0x3F,0x00,0x3F,0x00,0x00,0x00},
{0x06,0x0C,0x18,0x30,0x18,0x0C,0x06,0x00},
{0x1E,0x33,0x30,0x18,0x0C,0x00,0x0C,0x00},
{0x3E,0x63,0x7B,0x7B,0x7B,0x03,0x1E,0x00},
{0x0C,0x1E,0x33,0x33,0x3F,0x33,0x33,0x00},
{0x3F,0x66,0x66,0x3E,0x66,0x66,0x3F,0x00},
{0x3C,0x66,0x03,0x03,0x03,0x66,0x3C,0x00},
{0x1F,0x36,0x66,0x66,0x66,0x36,0x1F,0x00},
{0x7F,0x46,0x16,0x1E,0x16,0x46,0x7F,0x00},
{0x7F,0x46,0x16,0x1E,0x16,0x06,0x0F,0x00},
{0x3C,0x66,0x03,0x03,0x73,0x66,0x7C,0x00},
{0x33,0x33,0x33,0x3F,0x33,0x33,0x33,0x00},
{0x1E,0x0C,0x0C,0x0C,0x0C,0x0C,0x1E,0x00},
{0x78,0x30,0x30,0x30,0x33,0x33,0x1E,0x00},
{0x67,0x66,0x36,0x1E,0x36,0x66,0x67,0x00},
{0x0F,0x06,0x06,0x06,0x46,0x66,0x7F,0x00},
{0x63,0x77,0x7F,0x7F,0x6B,0x63,0x63,0x00},
{0x63,0x67,0x6F,0x7B,0x73,0x63,0x63,0x00},
{0x1C,0x36,0x63,0x63,0x63,0x36,0x1C,0x00},
{0x3F,0x66,0x66,0x3E,0x06,0x06,0x0F,0x00},
{0x1E,0x33,0x33,0x33,0x3B,0x1E,0x38,0x00},
{0x3F,0x66,0x66,0x3E,0x36,0x66,0x67,0x00},
{0x1E,0x33,0x07,0x0E,0x38,0x33,0x1E,0x00},
{0x3F,0x2D,0x0C,0x0C,0x0C,0x0C,0x1E,0x00},
{0x33,0x33,0x33,0x33,0x33,0x33,0x3F,0x00},
{0x33,0x33,0x33,0x33,0x33,0x1E,0x0C,0x00},
{0x63,0x63,0x63,0x6B,0x7F,0x77,0x63,0x00},
{0x63,0x63,0x36,0x1C,0x1C,0x36,0x63,0x00},
{0x33,0x33,0x33,0x1E,0x0C,0x0C,0x1E,0x00},
{0x7F,0x63,0x31,0x18,0x4C,0x66,0x7F,0x00},
{0x1E,0x06,0x06,0x06,0x06,0x06,0x1E,0x00},
{0x03,0x06,0x0C,0x18,0x30,0x60,0x00,0x00},
{0x1E,0x18,0x18,0x18,0x18,0x18,0x1E,0x00},
{0x08,0x1C,0x36,0x63,0x00,0x00,0x00,0x00},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF},
{0x0C,0x0C,0x18,0x00,0x00,0x00,0x00,0x00},
{0x00,0x00,0x1E,0x30,0x3E,0x33,0x6E,0x00},
{0x07,0x06,0x06,0x3E,0x66,0x66,0x3B,0x00},
{0x00,0x00,0x1E,0x33,0x03,0x33,0x1E,0x00},
{0x38,0x30,0x30,0x3E,0x33,0x33,0x6E,0x00},
{0x00,0x00,0x1E,0x33,0x3F,0x03,0x1E,0x00},
{0x1C,0x36,0x06,0x0F,0x06,0x06,0x0F,0x00},
{0x00,0x00,0x6E,0x33,0x33,0x3E,0x30,0x1F},
{0x07,0x06,0x36,0x6E,0x66,0x66,0x67,0x00},
{0x0C,0x00,0x0E,0x0C,0x0C,0x0C,0x1E,0x00},
{0x30,0x00,0x30,0x30,0x30,0x33,0x33,0x1E},
{0x07,0x06,0x66,0x36,0x1E,0x36,0x67,0x00},
{0x0E,0x0C,0x0C,0x0C,0x0C,0x0C,0x1E,0x00},
{0x00,0x00,0x33,0x7F,0x7F,0x6B,0x63,0x00},
{0x00,0x00,0x1F,0x33,0x33,0x33,0x33,0x00},
{0x00,0x00,0x1E,0x33,0x33,0x33,0x1E,0x00},
{0x00,0x00,0x3B,0x66,0x66,0x3E,0x06,0x0F},
{0x00,0x00,0x6E,0x33,0x33,0x3E,0x30,0x78},
{0x00,0x00,0x3B,0x6E,0x66,0x06,0x0F,0x00},
{0x00,0x00,0x3E,0x03,0x1E,0x30,0x1F,0x00},
{0x08,0x0C,0x3E,0x0C,0x0C,0x2C,0x18,0x00},
{0x00,0x00,0x33,0x33,0x33,0x33,0x6E,0x00},
{0x00,0x00,0x33,0x33,0x33,0x1E,0x0C,0x00},
{0x00,0x00,0x63,0x6B,0x7F,0x7F,0x36,0x00},
{0x00,0x00,0x63,0x36,0x1C,0x36,0x63,0x00},
{0x00,0x00,0x33,0x33,0x33,0x3E,0x30,0x1F},
{0x00,0x00,0x3F,0x19,0x0C,0x26,0x3F,0x00},
{0x38,0x0C,0x0C,0x07,0x0C,0x0C,0x38,0x00},
{0x18,0x18,0x18,0x00,0x18,0x18,0x18,0x00},
{0x07,0x0C,0x0C,0x38,0x0C,0x0C,0x07,0x00},
{0x6E,0x3B,0x00,0x00,0x00,0x00,0x00,0x00},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}
};
void setmode13h(void)
{
union REGS r;
r.h.ah = 0x00;
r.h.al = 0x13;
int86(0x10, &r, &r);
}
void settextmode(void)
{
union REGS r;
r.h.ah = 0x00;
r.h.al = 0x03;
int86(0x10, &r, &r);
}
void putpixel(int x, int y, unsigned char c)
{
if (x < 0 || x >= SCRW || y < 0 || y >= SCRH) return;
vga[(long) y * SCRW + x] = c;
}
unsigned char getpixel(int x, int y)
{
if (x < 0 || x >= SCRW || y < 0 || y >= SCRH) return 0;
return (unsigned char) vga[(long) y * SCRW + x];
}
void fillrect(int x1, int y1, int x2, int y2, unsigned char c)
{
int x, y;
for (y = y1; y <= y2; y++)
for (x = x1; x <= x2; x++)
putpixel(x, y, c);
}
void drawline(int x1, int y1, int x2, int y2, unsigned char c)
{
int dx, dy, sx, sy, err, e2;
dx = abs(x2 - x1);
dy = abs(y2 - y1);
sx = x1 < x2 ? 1 : -1;
sy = y1 < y2 ? 1 : -1;
err = dx - dy;
for (;;)
{
putpixel(x1, y1, c);
if (x1 == x2 && y1 == y2) break;
e2 = 2 * err;
if (e2 > -dy) { err -= dy; x1 += sx; }
if (e2 < dx) { err += dx; y1 += sy; }
}
}
void drawrect(int x1, int y1, int x2, int y2, unsigned char c)
{
drawline(x1, y1, x2, y1, c);
drawline(x1, y2, x2, y2, c);
drawline(x1, y1, x1, y2, c);
drawline(x2, y1, x2, y2, c);
}
void draw3dbox(int x1, int y1, int x2, int y2, int raised)
{
unsigned char top, bot;
fillrect(x1, y1, x2, y2, CLR_GRAY);
if (raised)
{
top = CLR_WHITE;
bot = CLR_BLACK;
}
else
{
top = CLR_BLACK;
bot = CLR_WHITE;
}
drawline(x1, y1, x2, y1, top);
drawline(x1, y1, x1, y2, top);
drawline(x1, y2, x2, y2, bot);
drawline(x2, y1, x2, y2, bot);
}
void drawchar(int x, int y, char ch, unsigned char fg)
{
int row, col;
unsigned char bits;
int idx;
idx = ch - 32;
if (idx < 0 || idx > 95) return;
for (row = 0; row < 8; row++)
{
bits = font8x8[idx][row];
for (col = 0; col < 8; col++)
{
if (bits & (0x80 >> col))
putpixel(x + col, y + row, fg);
}
}
}
void drawtext(int x, int y, char *s, unsigned char fg)
{
int cx;
cx = x;
while (*s)
{
drawchar(cx, y, *s, fg);
cx += 8;
s++;
}
}
void drawtextbg(int x, int y, char *s, unsigned char fg, unsigned char bg)
{
int len;
len = strlen(s);
fillrect(x - 2, y - 2, x + len * 8 + 1, y + 9, bg);
drawtext(x, y, s, fg);
}
void mouseinit(void)
{

union REGS r;

r.x.ax = 0x0000;
int86(0x33, &r, &r);
mousepresent = r.x.ax;
if (mousepresent)
{
r.x.ax = 0x0007;
r.x.cx = 0;
r.x.dx = SCRW - 1;
int86(0x33, &r, &r);
r.x.ax = 0x0008;
r.x.cx = 0;
r.x.dx = SCRH - 1;
int86(0x33, &r, &r);
r.x.ax = 0x0004;
r.x.cx = SCRW / 2;
r.x.dx = SCRH / 2;
int86(0x33, &r, &r);
}
}
void mousegetstate(int *px, int *py, int *pbtn)
{
union REGS r;
if (!mousepresent)
{
*px = mx;
*py = my;
*pbtn = 0;
return;
}
r.x.ax = 0x0003;
int86(0x33, &r, &r);
*px = r.x.cx;
*py = r.x.dx;
*pbtn = r.x.bx;
}
void savecursorarea(int x, int y)
{
int i, j, k;
k = 0;
savex = x;
savey = y;
for (j = 0; j < 12; j++)
{
for (i = 0; i < 8; i++)
{
cursave[k] = getpixel(x + i, y + j);
k++;
}
}
cursaved = 1;
}
void restorecursorarea(void)
{
int i, j, k;
if (!cursaved) return;
k = 0;
for (j = 0; j < 12; j++)
{
for (i = 0; i < 8; i++)
{
putpixel(savex + i, savey + j, cursave[k]);
k++;
}
}
}
void drawcursorat(int x, int y)
{
static unsigned char cshape[12][8] = {
{1,0,0,0,0,0,0,0},
{1,1,0,0,0,0,0,0},
{1,2,1,0,0,0,0,0},
{1,2,2,1,0,0,0,0},
{1,2,2,2,1,0,0,0},
{1,2,2,2,2,1,0,0},
{1,2,2,2,2,2,1,0},
{1,2,2,2,2,2,2,1},
{1,2,2,2,2,1,1,1},
{1,2,1,2,2,1,0,0},
{1,1,0,1,2,2,1,0},
{0,0,0,0,1,2,2,1}
};
int i, j;
unsigned char v;
for (j = 0; j < 12; j++)
{
for (i = 0; i < 8; i++)
{
v = cshape[j][i];
if (v == 1) putpixel(x + i, y + j, CLR_BLACK);
else if (v == 2) putpixel(x + i, y + j, CLR_WHITE);
}
}
}
void showcursorat(int x, int y)
{
savecursorarea(x, y);
drawcursorat(x, y);
}
void hidebiosblock(void)
{
union REGS r;
r.h.ah = 0x01;
r.h.ch = 0x20;
int86(0x10, &r, &r);
}
void waitkeyclear(void)
{
while (bioskey(1)) bioskey(0);
}
void getcurtime_str(char *buf)
{
struct time t;
int h;
char *ap;
gettime(&t);
h = t.ti_hour;
if (h == 0) { h = 12; ap = "AM"; }
else if (h < 12) { ap = "AM"; }
else if (h == 12) { ap = "PM"; }
else { h = h - 12; ap = "PM"; }
sprintf(buf, "%2d:%02d %s", h, t.ti_min, ap);
}
int mouseinbox(int mxp, int myp, int x1, int y1, int x2, int y2)
{
if (mxp >= x1 && mxp <= x2 && myp >= y1 && myp <= y2) return 1;
return 0;
}
void drawtextfield(int x, int y, int w, char *buf, int ispass)
{
int i, len;
char c;
draw3dbox(x, y, x + w, y + 13, 0);
fillrect(x + 2, y + 2, x + w - 2, y + 11, CLR_WHITE);
len = strlen(buf);
for (i = 0; i < len; i++)
{
c = ispass ? '*' : buf[i];
if (x + 3 + i * 8 + 8 > x + w - 2) break;
drawchar(x + 3 + i * 8, y + 3, c, CLR_BLACK);
}
}
void drawbutton(int x, int y, int w, int h, char *label, int pressed)
{
int tx, ty, len;
draw3dbox(x, y, x + w, y + h, !pressed);
len = strlen(label);
tx = x + (w - len * 8) / 2;
ty = y + (h - 8) / 2;
if (pressed) { tx++; ty++; }
drawtext(tx, ty, label, CLR_BLACK);
}
void inputstring(int x, int y, int w, char *buf, int maxlen, int ispass)
{
int len;
int k, ch;
len = strlen(buf);
for (;;)
{
drawtextfield(x, y, w, buf, ispass);
showcursorat(mx, my);
k = bioskey(0);
restorecursorarea();
ch = k & 0x00FF;
if (ch == 13)
{
return;
}
else if (ch == 9)
{
return;
}
else if (ch == 8)
{
if (len > 0)
{
len--;
buf[len] = 0;
}
}
else if (ch >= 32 && ch <= 126)
{
if (len < maxlen - 1 && (len + 1) * 8 < w - 4)
{
buf[len] = ch;
len++;
buf[len] = 0;
}
}
}
}
void drawerrorbox(char *title, char *msg)
{
int bx1, by1, bx2, by2;
int k, ch;
int px, py, btn;
int okx1, oky1, okx2, oky2;
int msgw;
bx1 = 55;
by1 = 65;
bx2 = 265;
by2 = 125;
draw3dbox(bx1, by1, bx2, by2, 1);
fillrect(bx1 + 2, by1 + 2, bx2 - 2, by1 + 12, CLR_RED);
drawtext(bx1 + 4, by1 + 3, title, CLR_WHITE);
fillrect(bx1 + 8, by1 + 22, bx1 + 22, by1 + 36, CLR_RED);
drawtext(bx1 + 12, by1 + 24, "X", CLR_WHITE);
msgw = strlen(msg) * 8;
if (bx1 + 30 + msgw > bx2 - 4)
{
drawtext(bx1 + 30, by1 + 22, "Wrong username", CLR_BLACK);
drawtext(bx1 + 30, by1 + 32, "or password", CLR_BLACK);
}
else
{
drawtext(bx1 + 30, by1 + 27, msg, CLR_BLACK);
}
okx1 = (bx1 + bx2) / 2 - 15;
oky1 = by2 - 18;
okx2 = okx1 + 30;
oky2 = oky1 + 12;
drawbutton(okx1, oky1, 30, 12, "OK", 0);
showcursorat(mx, my);
for (;;)
{
mousegetstate(&px, &py, &btn);
if (px != mx || py != my)
{
restorecursorarea();
mx = px;
my = py;
showcursorat(mx, my);
}
if (bioskey(1))
{
k = bioskey(0);
ch = k & 0x00FF;
if (ch == 13 || ch == 27)
{
restorecursorarea();
break;
}
}
if (btn & 1)
{
if (mouseinbox(px, py, okx1, oky1, okx2, oky2))
{
while (btn & 1) mousegetstate(&px, &py, &btn);
restorecursorarea();
break;
}
}
}
}
void drawinfobox(char *title, char *msg)
{
int bx1, by1, bx2, by2;
int k, ch;
int px, py, btn;
int okx1, oky1, okx2, oky2;
bx1 = 80;
by1 = 70;
bx2 = 240;
by2 = 120;
draw3dbox(bx1, by1, bx2, by2, 1);
fillrect(bx1 + 2, by1 + 2, bx2 - 2, by1 + 12, CLR_BLUE);
drawtext(bx1 + 4, by1 + 3, title, CLR_WHITE);
drawtext(bx1 + 10, by1 + 25, msg, CLR_BLACK);
okx1 = (bx1 + bx2) / 2 - 15;
oky1 = by2 - 18;
okx2 = okx1 + 30;
oky2 = oky1 + 12;
drawbutton(okx1, oky1, 30, 12, "OK", 0);
showcursorat(mx, my);
for (;;)
{
mousegetstate(&px, &py, &btn);
if (px != mx || py != my)
{
restorecursorarea();
mx = px;
my = py;
showcursorat(mx, my);
}
if (bioskey(1))
{
k = bioskey(0);
ch = k & 0x00FF;
if (ch == 13 || ch == 27)
{
restorecursorarea();
break;
}
}
if (btn & 1)
{
if (mouseinbox(px, py, okx1, oky1, okx2, oky2))
{
while (btn & 1) mousegetstate(&px, &py, &btn);
restorecursorarea();
break;
}
}
}
}
void drawdosicon(int x, int y)
{
draw3dbox(x, y, x + 32, y + 32, 1);
fillrect(x + 3, y + 3, x + 28, y + 22, CLR_BLACK);
drawrect(x + 3, y + 3, x + 28, y + 22, CLR_DGRAY);
fillrect(x + 5, y + 6, x + 26, y + 8, CLR_LTGRAY);
drawchar(x + 6, y + 12, 'C', CLR_LTGRAY);
drawchar(x + 14, y + 12, ':', CLR_LTGRAY);
drawchar(x + 20, y + 12, '>', CLR_GREEN);
fillrect(x + 6, y + 24, x + 25, y + 26, CLR_LTGRAY);
}
int loginscreen(void)
{
int bx1, by1, bx2, by2;
char username[32];
char password[32];
int lbx1, lby1, lbx2, lby2;
int cbx1, cby1, cbx2, cby2;
int px, py, btn;
int fldusr_x, fldusr_y, fldpwd_x, fldpwd_y;
fillrect(0, 0, SCRW - 1, SCRH - 1, CLR_TEAL);
bx1 = 45;
by1 = 55;
bx2 = 275;
by2 = 145;
username[0] = 0;
password[0] = 0;
fldusr_x = bx1 + 95;
fldusr_y = by1 + 25;
fldpwd_x = bx1 + 95;
fldpwd_y = by1 + 45;
for (;;)
{
draw3dbox(bx1, by1, bx2, by2, 1);
fillrect(bx1 + 2, by1 + 2, bx2 - 2, by1 + 14, CLR_BLUE);
drawtext(bx1 + 4, by1 + 4, "Windows 98 Login", CLR_WHITE);
drawtext(bx1 + 10, by1 + 27, "Username:", CLR_BLACK);
drawtextfield(fldusr_x, fldusr_y, 90, username, 0);
drawtext(bx1 + 10, by1 + 47, "Password:", CLR_BLACK);
drawtextfield(fldpwd_x, fldpwd_y, 90, password, 1);
lbx1 = bx1 + 40;
lby1 = by2 - 22;
lbx2 = lbx1 + 60;
lby2 = lby1 + 15;
drawbutton(lbx1, lby1, 60, 15, "Login", 0);
cbx1 = bx1 + 130;
cby1 = by2 - 22;
cbx2 = cbx1 + 60;
cby2 = cby1 + 15;
drawbutton(cbx1, cby1, 60, 15, "Cancel", 0);
inputstring(fldusr_x, fldusr_y, 90, username, 20, 0);
inputstring(fldpwd_x, fldpwd_y, 90, password, 20, 1);
showcursorat(mx, my);
for (;;)
{
mousegetstate(&px, &py, &btn);
if (px != mx || py != my)
{
restorecursorarea();
mx = px;
my = py;
showcursorat(mx, my);
}
if (bioskey(1))
{
bioskey(0);
restorecursorarea();
break;
}
if (btn & 1)
{
if (mouseinbox(px, py, lbx1, lby1, lbx2, lby2))
{
while (btn & 1) mousegetstate(&px, &py, &btn);
restorecursorarea();
break;
}
if (mouseinbox(px, py, cbx1, cby1, cbx2, cby2))
{
username[0] = 0;
password[0] = 0;
while (btn & 1) mousegetstate(&px, &py, &btn);
restorecursorarea();
break;
}
}
}
if (strcmp(username, "admin") == 0 && strcmp(password, "admin") == 0)
{
return 1;
}
else
{
drawerrorbox("Warning", "Wrong username or password");
username[0] = 0;
password[0] = 0;
}
}
}
void getmemorystring(char *buf)
{
union REGS r;
unsigned int conv, ext;
r.h.ah = 0x88;
int86(0x15, &r, &r);
ext = r.x.ax;
r.x.ax = 0x0000;
int86(0x12, &r, &r);
conv = r.x.ax;
sprintf(buf, "Conv:%uKB Ext:%uKB", conv, ext);
}
void getdiskstring(char *buf)
{
union REGS r;
unsigned int spc, bps, avail, total;
unsigned long totalbytes, freebytes;
r.h.ah = 0x36;
r.h.dl = 0;
int86(0x21, &r, &r);
if (r.x.ax == 0xFFFF)
{
sprintf(buf, "Drive C: no disk info");
return;
}
spc = r.x.ax;
avail = r.x.bx;
bps = r.x.cx;
total = r.x.dx;
totalbytes = (unsigned long) total * spc * bps;
freebytes = (unsigned long) avail * spc * bps;
sprintf(buf, "C: Tot=%luB Free=%luB", totalbytes, freebytes);
}
void drawcmdwindow(void)
{
int wx1, wy1, wx2, wy2;
char line[16];
char inputbuf[64];
int cy;
int running;
char infobuf[80];
int promptw;
wx1 = 15;
wy1 = 15;
wx2 = 305;
wy2 = 185;
fillrect(wx1, wy1, wx2, wy2, CLR_BLACK);
drawrect(wx1, wy1, wx2, wy2, CLR_GRAY);
cy = wy1 + 5;
drawtext(wx1 + 5, cy, "MS-DOS Prompt", CLR_WHITE);
cy += 12;
drawtext(wx1 + 5, cy, "C:\\WINDOWS>", CLR_WHITE);
cy += 12;
drawtext(wx1 + 5, cy, "memory disk quit", CLR_WHITE);
cy += 14;
strcpy(line, "C:\\WINDOWS>");
promptw = strlen(line) * 8;
running = 1;
while (running)
{
drawtext(wx1 + 5, cy, line, CLR_WHITE);
inputbuf[0] = 0;
if (wx1 + 5 + promptw + 8 > wx2 - 5)
{
inputstring(wx1 + 5, cy + 10, wx2 - wx1 - 10, inputbuf, 30, 0);
}
else
{
inputstring(wx1 + 5 + promptw, cy, wx2 - wx1 - 10 - promptw, inputbuf, 30, 0);
}
cy += 12;
if (cy > wy2 - 30)
{
fillrect(wx1 + 1, wy1 + 30, wx2 - 1, wy2 - 1, CLR_BLACK);
cy = wy1 + 30;
}
if (strcmp(inputbuf, "memory") == 0)
{
getmemorystring(infobuf);
drawtext(wx1 + 5, cy, infobuf, CLR_WHITE);
cy += 12;
}
else if (strcmp(inputbuf, "disk") == 0)
{
getdiskstring(infobuf);
drawtext(wx1 + 5, cy, infobuf, CLR_WHITE);
cy += 12;
}
else if (strcmp(inputbuf, "quit") == 0)
{
running = 0;
}
else
{
drawtext(wx1 + 5, cy, "Bad command", CLR_WHITE);
cy += 12;
}
if (cy > wy2 - 30)
{
fillrect(wx1 + 1, wy1 + 30, wx2 - 1, wy2 - 1, CLR_BLACK);
cy = wy1 + 30;
}
}
}
int drawstartmenu(void)
{
int mx1, my1, mx2, my2;
int itemy;
int k, ch;
int selrc;
int chosen;
int px, py, btn;
int ry1, sy1;
mx1 = 2;
my2 = SCRH - 18;
mx2 = 100;
my1 = my2 - 90;
draw3dbox(mx1, my1, mx2, my2, 1);
itemy = my1 + 6;
drawtext(mx1 + 6, itemy, "Programs", CLR_BLACK);
itemy += 14;
drawtext(mx1 + 6, itemy, "Documents", CLR_BLACK);
itemy += 14;
drawtext(mx1 + 6, itemy, "Settings", CLR_BLACK);
itemy += 14;
drawline(mx1 + 2, itemy, mx2 - 2, itemy, CLR_DGRAY);
itemy += 4;
ry1 = itemy;
drawtext(mx1 + 6, itemy, "Restart", CLR_BLACK);
itemy += 14;
sy1 = itemy;
drawtext(mx1 + 6, itemy, "Shut Down", CLR_BLACK);
chosen = 0;
selrc = 0;
showcursorat(mx, my);
while (!chosen)
{
mousegetstate(&px, &py, &btn);
if (px != mx || py != my)
{
restorecursorarea();
mx = px;
my = py;
showcursorat(mx, my);
}
if (bioskey(1))
{
k = bioskey(0);
ch = k & 0x00FF;
if (ch == 'r' || ch == 'R')
{
chosen = 1;
selrc = 1;
}
else if (ch == 's' || ch == 'S')
{
chosen = 1;
selrc = 2;
}
else if (ch == 27)
{
chosen = 1;
selrc = 0;
}
}
if (btn & 1)
{
if (mouseinbox(px, py, mx1, ry1, mx2, ry1 + 10))
{
chosen = 1;
selrc = 1;
}
else if (mouseinbox(px, py, mx1, sy1, mx2, sy1 + 10))
{
chosen = 1;
selrc = 2;
}
else if (!mouseinbox(px, py, mx1, my1, mx2, my2))
{
chosen = 1;
selrc = 0;
}
while (btn & 1) mousegetstate(&px, &py, &btn);
}
}
restorecursorarea();
if (selrc == 1)
{
drawinfobox("System", "Restarting system now");
return 1;
}
else if (selrc == 2)
{
drawinfobox("System", "Safe to shut down");
return 2;
}
return 0;
}
void drawdesktop(void)
{
int running;
int startaction;
int px, py, btn;
int stx1, sty1, stx2, sty2;
int icx1, icy1, icx2, icy2;
char timebuf[16];
long lastclock, curclock;
running = 1;
stx1 = 2;
sty1 = SCRH - 16;
stx2 = 50;
sty2 = SCRH - 2;
icx1 = 20;
icy1 = 20;
icx2 = icx1 + 32;
icy2 = icy1 + 32;
fillrect(0, 0, SCRW - 1, SCRH - 19, CLR_TEAL);
fillrect(0, SCRH - 18, SCRW - 1, SCRH - 1, CLR_GRAY);
drawline(0, SCRH - 18, SCRW - 1, SCRH - 18, CLR_WHITE);
draw3dbox(stx1, sty1, stx2, sty2, 1);
drawtext(stx1 + 6, sty1 + 4, "Start", CLR_BLACK);
drawdosicon(icx1, icy1);
drawtextbg(icx1, icy2 + 4, "MS-DOS", CLR_WHITE, CLR_TEAL);
getcurtime_str(timebuf);
fillrect(248, SCRH - 14, 318, SCRH - 4, CLR_GRAY);
drawtext(251, SCRH - 12, timebuf, CLR_BLACK);
lastclock = 0L;
showcursorat(mx, my);
while (running)
{
mousegetstate(&px, &py, &btn);

回首页,搜索你想要的文档

在首页搜索框输入关键词,快速定位资料

文库首页搜索指引 立即搜索

相关学习资料