今天下午下個菜單程序試試看,主要是要用鼠標控制的,現在還沒寫完,發現有一些問題值得大家討論下,也希望用c寫過鼠標控制菜單程序的朋友一起來探討下.首先是鼠標假如沒按鍵而位置在菜單選向上的時候,大家覺得這個時候應該在菜單主標題這裡顯示什麼樣的效果呢?是用rectangle畫一個框還是添加背景顏色呢?同樣在菜單選向裡也應該顯示什麼樣的效果.第二個問題是假如有滾屏的話你們覺得是把一大塊保存下來,還是一行行保存好呢?希望寫過類似程序的朋友以及想寫這個程序的朋友提點意見吧,謝謝.
/*email:
[email protected]*/
#include "stdio.h"
#include "dos.h"
#include "stdlib.h"
#include "graphics.h"
#define WA99vING 0xff00
#define LEFTPRESS 0xff01
#define LEFTCLICK 0xff10
#define LEFTDRAG 0xff19
#define MOUSEMOVE 0xff08
int Keystate;/*這裡的開始都與鼠標有關*/
int MouseExist;
int MouseButton;
int MouseX;
int MouseY;
void *save;/*儲存一塊地方用的*/
strUCt time now;/*這裡開始的變量都是時間有關*/
int old,new;
char ss[10];
struct caidan/*用來檢驗是否菜單已經打開*/
{
int on;/*菜單打開1,否則0*/
char ml[5][20];/*子目錄*/
}c[4];
/*鼠標光標外形定義*/
typedef struct
{
unsigned int shape[32];
char hotx;
char hoty;
}SHAPE;
/*箭頭型*/
SHAPE ARROW={
{
0x3fff,0x1fff,0x0fff,0x07ff,
0x03ff,0x01ff,0x00ff,0x007f,
0x003f,0x00ff,0x01ff,0x10ff,
0x30ff,0xf87f,0xf87f,0xfc3f,
0x0000,0x7c00,0x6000,0x7000,
0x7800,0x7c00,0x7e00,0x7f00,
0x7f80,0x7e00,0x7c00,0x4600,
0x0600,0x0300,0x0300,0x0180
},
0,0,
};
void TimeDelay(unsigned long microsec); /*延時函數 傳入微秒數*/
void MouseOn();/*鼠標光標顯示*/
void MouseOff();/*鼠標光標掩示*/
void MouseReset();/*鼠標狀態值初始化*/
void MouseSetXY(int x,int y);/*設置鼠標當前位置*/
int LeftPress();/*獲取鼠標按下鍵的信息*/
void MouseGetXY();/*獲取鼠標當前位置*/
void prtime();/*輸出時間的函數*/
void cdbegain();/*菜單各參數初始狀態*/
void Init();/*開始畫面*/
void delcd();/*先把已有的菜單刪除了*/
void drawcdml(int n);/*輸出菜單中的具體內容*/
void drawcd(int l,int u,int r,int d,int n);/*畫菜單*/
void mouseleft();/*左鍵按下畫菜單具體內容*/
void Move();/*測試過程*/
void main(void)
{
Init();
Move();
MouseOff();
closegraph();
}
void TimeDelay(unsigned long microsec) /*延時函數 傳入微秒數*/
{
union REGS r;
r.h.ah=0x86;
r.x.cx=microsec>>16;
r.x.dx=microsec;
int86(0x15,&r,&r);
}
void MouseOn()/*鼠標光標顯示*/
{
_AX=0x01;
geninterrupt(0x33);
}
void MouseOff()/*鼠標光標掩示*/
{
_AX=0x02;
geninterrupt(0x33);
}
void MouseReset()/*鼠標狀態值初始化*/
{
_AX=0x00;
geninterrupt(0x33);
}
void MouseSetXY(int x,int y)/*設置鼠標當前位置*/
{
_CX=x;
_DX=y;
_AX=0x04;
geninterrupt(0x33);
}
int LeftPress()/*獲取鼠標按下鍵的信息*/
{
_AX=0x03;
geninterrupt(0x33);
return(_BX&1);
}
void MouseGetXY()/*獲取鼠標當前位置*/
{
_AX=0x03;
geninterrupt(0x33);
MouseX=_CX;
MouseY=_DX;
}
void prtime()/*輸出時間的函數*/
{
gettime(&now);
new=now.ti_sec;
if(abs(new-old)>=1)
{
setfillstyle(SOLID_FILL,7);/*把原來的老時間給去除*/
bar(500,8,620,18);
old=new;
sprintf(ss,"%02d:%02d:%02d",now.ti_hour,now.ti_min,now.ti_sec);
setcolor(0);
outtextxy(500,8,ss);
}
}
void cdbegain()/*菜單各參數初始狀態*/
{int i;
for(i=0;i<4;i++)/*所有菜單都已經關閉*/
c[i].on=0;
strcpy(c[0].ml[0],"Open");/*各菜單的各選項*/
strcpy(c[0].ml[1],"New");
strcpy(c[0].ml[2],"Save");
strcpy(c[0].ml[3],"Save as");
strcpy(c[0].ml[4],"Exit");
strcpy(c[1].ml[0],"Undo");
strcpy(c[1].ml[1],"Cut");
strcpy(c[1].ml[2],"Copy");
strcpy(c[1].ml[3],"Paste");
strcpy(c[1].ml[4],"Properties");
strcpy(c[2].ml[0],"Styles");
strcpy(c[2].ml[1],"L Icons");
strcpy(c[2].ml[2],"S Icons");
strcpy(c[2].ml[3],"