1. Trang chủ
  2. » Biểu Mẫu - Văn Bản

Giáo trình hình thành phân mạch ứng dụng điều chế thiết bị bán dẫn chứa các mạch logic điện tử p8

7 11 0

Đang tải... (xem toàn văn)

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 7
Dung lượng 272,68 KB

Các công cụ chuyển đổi và chỉnh sửa cho tài liệu này

Nội dung

[r]

Trang 1

#include "screen.h"

#define INT_MOUSE 0x33

#define M_CENTER 0x04 /* set if CENTER press */

#define M_CHANGE 0x08 /* set if mouse status is changed */ /* Keyboard coding bits */

#define BACKSPACE 0x8

#define PAGE_DOWN 0xD1

/* Function's keys */

#define SHIFT_TAB 0x8F

//struct time;

typedef struct tagEVENT{

int Msg;

int Posx, Posy; // toa do xay ra bien co chuot

struct time *t;

} EVENT;

typedef EVENT far *LPEVENT;

// Khai bao cac ham toan cuc

extern void SetMouseRange(LPRECT);//LPRECT: xem SCREEN.H

extern int InitMouse(LPRECT);

extern void ShowMouse(void);

extern void HideMouse(void);

extern void MouseRead(LPEVENT);

extern void DeviceRelease(int);

//extern void ButtonPressed(int, LPEVENT);

extern void ResetEvent(LPEVENT);

//extern void MoveMouse(int x,int y);//tri

extern void MouseText(int x,int y,int color1, int color2);//,char s[]);

//extern int GetKey(void);

Trang 2

extern int GetMtx();

extern int GetMty();

//extern EVENT OldEvent();

extern int Double(LPEVENT);

#endif

// End of MOUSE.H

IX.MODULE MOUSE.CPP

#include <conio.h>

#include <graphics.h>

//#include <STDLIB.H>

#include <COMPLEX.H>

#include "mouse.h"

void SetMouseRange(LPRECT lpRect)

// Dat vung di chuyen cho chuot

{

_AX = 0x07;//ham 07 cua ngat 33 de dinh gioi han di chuyen ngang _CX = lpRect->left;

_DX = lpRect->right;

geninterrupt(INT_MOUSE);//INT_MOUSE=0x33:ngat 33

_AX = 0x08;//ham 08 cua ngat 33 dinh gioi han di chuyen doc cho con tro

_CX = lpRect->top;

_DX = lpRect->bottom;

geninterrupt(INT_MOUSE);

}

// -

int InitMouse(LPRECT lpRect)

// Khoi dong chuot

{

int ax;

_AX = 0;

geninterrupt(INT_MOUSE);

ax = _AX;

if (ax == 0)

return FALSE;

SetMouseRange(lpRect);

return TRUE;

}

// -

void ShowMouse(void)

// Hien thi chuot

{

_AX = 1;

geninterrupt(INT_MOUSE);

}

// -

void HideMouse(void)

// Dau chuot

{

_AX = 2;

geninterrupt(INT_MOUSE);

}

// -

#include <CONIO.H>

#include <STDIO.H>

void MouseRead(LPEVENT lpEvent)

// Tra ve bien co nhan duoc tu chuot : Nut trai hay phai duoc an

{

Trang 3

int bx;

_AX = 3;

geninterrupt(INT_MOUSE);

bx = _BX;

//cx = _CX;

//dx = _DX;

lpEvent->Msg = bx;

lpEvent->Posx = _CX;

lpEvent->Posy = _DX;

gettime(lpEvent->t);

}

// -

void ResetEvent(LPEVENT lpEvent)

{

lpEvent->Msg = 0;

lpEvent->Posx = lpEvent->Posy = 0;

}

// -

EVENT PrevEvent, CurEvent;

// -

LPEVENT GetEvent(void)

{

ResetEvent(&CurEvent);

MouseRead(&CurEvent);

// chuyen sang toa do ViewPort

CurEvent.Posx = CurEvent.Posx-MainWindow.rViewPort.left;

CurEvent.Posy = CurEvent.Posy-MainWindow.rViewPort.top;

// xet trang thai chuot co thay doi hay khong

if((CurEvent.Posx!=PrevEvent.Posx)&&(CurEvent.Posy!=PrevEvent.Posy)) CurEvent.Msg |= M_CHANGE;

PrevEvent = CurEvent;

// delay(50);

return (&CurEvent);

}

// -

void DeviceRelease(int Msg)

{

while(GetEvent()->Msg&Msg);

}

// -

int Double(LPEVENT lpEvent)

{

if(lpEvent->Msg==1)

{

delay(100);

ResetEvent(lpEvent);

lpEvent=GetEvent();

if(lpEvent->Msg==1)

//if((abs(CurEvent.Posx-oldEvent.Posx))<=10&&abs(CurEvent.Posy-oldEvent.Posy)<=10)

{

{

return 1;

}

}

else

return 0;

}

else return 0;

}

// -

Trang 4

void MouseText(int x,int y,int color1,int color2)//,char s[])//gia dau nhay con tro

{

HideMouse();

// int h=textheight(s);

int w=5;

int color=getcolor();

do

{

for(int i=0;i<10&&(!kbhit());i++)

{

setcolor(color2);//WHITE);

line(x,y,x+w,y);

line(x,y+1,x+w,y+1);

delay(10);

setcolor(color);

}

setcolor(color1);//GREEN);

line(x,y,x+w,y);

line(x,y+1,x+w,y+1);

setcolor(color);

for(i=0;i<10&&(!kbhit());i++)

{

setcolor(color1);//GREEN);

line(x,y,x+w,y);

line(x,y+1,x+w,y+1);

delay(10);

setcolor(color);

}

}while(!kbhit());

}

// -

int GetMtx()

{

return getx();

}

// -

int GetMty()

{

return gety();

}

// -

// End of MOUSE.CPP

X.CLASS SCREEN.H

#if !defined( SCREEN_H )

#define SCREEN_H

// Dinh nghia cac kieu du lieu

typedef struct tagRECT{

int left, top, right, bottom ;

}RECT;

typedef RECT far *LPRECT;

typedef struct tagWINDOW {

char sCaption[80]; /*Window's caption*/

RECT rWinRect; /*Rectangle in which window is located*/

Trang 5

RECT rSys; /*System area of window*/

RECT rTitleBar; /*Caption area of window*/

RECT rMenuBar; /*Rectangle in which window's menu is located*/

RECT rMessage; /* Rectangle in which messages is display }WINDOWS;

// Dinh nghia cac ham va bien dung toan cuc

extern int LineColor;

extern int VP_WIDTH;

extern int VP_HEIGHT;

extern WINDOWS MainWindow;

extern void InitGraphics(void);

extern void OutMessage(char *Msg);

extern void InitScreen(void);

extern void InitValues(char *lpCaption);

extern int OutError(char *s);

#endif

// End of SCREEN.H

XI.MODULE SCREEN.CPP

#include <conio.h>

#include <stdio.h>

#include <stdlib.h>

#include <string.h>

#include <graphics.h>

#include "screen.h"

#include "mouse.h"

int T_SIZE, W_SIZE, H_SIZE, W_CHAR, H_CHAR, MSG_SIZE;

int COLOR_WINDOW;

int COLOR_BUTTON;

int COLOR_BORDER;

int COLOR_CAPTION;

int COLOR_TEXT;

int VP_WIDTH;

int VP_HEIGHT;

int Maxx, Maxy; // Maxx - Maxy of screen

WINDOWS MainWindow;

//int Xc, Yc; // Goc toa do

//int LineColor = MAGENTA; // Mau cua duong thang can ve - Dung trong thu tuc SetPixel

// -

void InitGraphics(void)

// Khoi tao che do do hoa

{

int grDrv=DETECT, grMode;

initgraph(&grDrv, &grMode, "");

ErrCode = graphresult();

if(ErrCode!= grOk)

{

printf("Graphics error: %s\n", grapherrormsg(ErrCode));

printf("Press any key to halt ");

getch();

exit(1); /* return with error code */

}

Maxx = getmaxx();

Trang 6

{

LineColor = C;

}

// -

void SetPixel(int x, int y)

{

putpixel(Xc+x, Yc-y, LineColor);

}

// -

void Set2Pixel(int Ox, int Oy, int x, int y)

{

putpixel(Ox+x, Oy-y, LineColor);

putpixel(Ox-x, Oy-y, LineColor);

}

// -

void Set2PixelHor(int Ox, int Oy, int x, int y)

{

putpixel(Ox+x, Oy-y, LineColor);

putpixel(Ox+x, Oy+y, LineColor);

}

// -

void ClearViewPort(void)

{

struct fillsettingstype FillInfo;

// luu thong tin cu

getfillsettings(&FillInfo);

setfillstyle(SOLID_FILL, COLOR_WINDOW);

bar(0, 0, VP_WIDTH, VP_HEIGHT);

setfillstyle(FillInfo.pattern, FillInfo.color);

DrawSysCoordinates();

} */

// End of SCREEN.C

// -

#include <alloc.h>

int OutError(char *s)

{

void far *buf;//con tro chi vung luu tru man hinh

unsigned int size = imagesize(200,150,470,240);

LPEVENT lpEvent;

int Cx1=280,Cy1=203,Cx2=337,Cy2=223;

int Ox1=350,Oy1=203,Ox2=405,Oy2=223;

if ((buf = farmalloc(size)) == NULL)

{

return -1;

}

else

{

getimage(200,150,470,240,buf);

}

setfillstyle(SOLID_FILL,BLUE);

HideMouse();

bar(200,150,470,240);

setcolor(WHITE);

rectangle(200,150,470,240);

outtextxy(200+(270-8*strlen(s))/2,170,s);

setfillstyle(SOLID_FILL,LIGHTBLUE);

bar(Cx1,Cy1,Cx2,Cy2);//280,203,337,223);

int OK=0;

outtextxy(285,210,"Cancel");

outtextxy(365,210,"OK");

int event;

do

Trang 7

{

lpEvent=GetEvent();

if(kbhit())

{

if((event=getch())==13)

{

CompleteOk:

HideMouse();

putimage(200,150,buf,COPY_PUT);

ShowMouse();

farfree(buf);

return OK;

}

if(event==27)

{

CompleteCancel:

HideMouse();

putimage(200,150,buf,COPY_PUT);

ShowMouse();

farfree(buf);

return 0;

}

if(event==9)

{

OK=!OK;

Cancel:

if(OK==0)

{

HideMouse();

setfillstyle(SOLID_FILL,BLUE);

bar(Ox1,Oy1,Ox2,Oy2);//350,203,405,223);

outtextxy(365,210,"OK");

setfillstyle(SOLID_FILL,LIGHTBLUE);

bar(Cx1,Cy1,Cx2,Cy2);//280,203,337,223);

outtextxy(285,210,"Cancel");

ShowMouse();

}

Ok:

if(OK==1)

{

HideMouse();

setfillstyle(SOLID_FILL,BLUE);

bar(Cx1,Cy1,Cx2,Cy2);//280,203,337,223);

outtextxy(285,210,"Cancel");

setfillstyle(SOLID_FILL,LIGHTBLUE);

bar(Ox1,Oy1,Ox2,Oy2);//350,203,405,223);

outtextxy(365,210,"OK");

ShowMouse();

}

}

if(event==0)

{

event=getch();

if(event==75)

{

OK=0;

goto Cancel;

}

if(event==77)

{

OK=1;

goto Ok;

}

Ngày đăng: 01/04/2021, 02:12

TÀI LIỆU CÙNG NGƯỜI DÙNG

TÀI LIỆU LIÊN QUAN

🧩 Sản phẩm bạn có thể quan tâm

w