📄 mywindow.h
字号:
/* ==================================================== */
/* */
/* 学生宿舍管理系统Ver 1.00.1 源代码 */
/* 文件名: MyWindow.h */
/* 作用: 实现所有的窗体控件,并接收鼠标键盘的输入并 */
/* 转换成消息的形式发送给窗体接收. */
/* 这个部分可以算是整个软件的精华部分了. */
/* 版权所有 (c) 2007 张元龙 保留所有权利 */
/* */
/* ==================================================== */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <graphics.h>
#include <conio.h>
#include <dos.h>
#include <bios.h>
#include <time.h>
#include "MyIco.h"
#include "MyChn.h"
#include "MyMouse.h"
#include "MyImm.h"
#ifndef WindowDefined
#define WindowDefined
/* ================================ */
/* 宏定义 */
/* ================================ */
#define GetWindow(x) ((pWindow)(x)) /*由句柄转换成窗体指针*/
#define GetButton(x) ((pButton)(x)) /*由句柄转换成按钮指针*/
#define GetLabel(x) ((pLabel)(x)) /*由句柄转换成标签指针*/
#define GetIco(x) ((pIco)(x)) /*由句柄转换成图标指针*/
#define GetEdit(x) ((pEdit)(x)) /*由句柄转换成编辑框指针*/
#define GetList(x) ((pList)(x)) /*由句柄转换成列表指针*/
#define NextButton(x) (GetButton(x)->Next) /*获取x按钮的下一个按钮*/
#define NextLabel(x) (GetLabel(x)->Next) /*获取x标签的下一个标签*/
#define NextIco(x) (GetIco(x)->Next) /*获取x图标的下一个图标*/
#define NextEdit(x) (GetEdit(x)->Next) /*获取x编辑框的下一个编辑框*/
/* ================================ */
/* 常量定义部分 */
/* ================================ */
#define DEF_COLOR LIGHTGRAY /*默认窗体颜色*/
#define DEF_BUT_WIDTH 64 /*默认按钮宽度*/
#define DEF_BUT_HEIGHT 26 /*默认按钮高度*/
#define DEF_EDIT_WIDTH 160 /*默认编辑框宽度*/
/* ================================ */
/* 消息定义部分 */
/* ================================ */
#define WM_LEFTDOWN 1 /*鼠标按下事件*/
#define WM_LEFTUP 2 /*鼠标弹出事件*/
#define WM_MOUSEMOVE 3 /*鼠标移动事件*/
#define WM_RIGHTCLICK 4 /*鼠标右击事件*/
#define WM_KEYCLICK 5 /*键盘按下事件*/
#define WM_TIMER 7 /*时间响应事件*/
#define WM_CLOSE 8 /*窗口关闭事件*/
typedef unsigned int Hwnd,HWND,THandle,Thandle; /*定义句柄类型*/
typedef unsigned int UINT;
typedef char *pchar,*Pchar,*PChar;
typedef void *pvoid,*Pvoid,*PVoid;
/* ================================ */
/* 回调函数定义部分 */
/* ================================ */
/*鼠标按下事件回调函数类型定义*/
typedef void (*MouseClick)(
HWND handle /* Button handle*/
);
/*窗口关闭前的回调函数定义*/
/*返回值表示能否被关闭*/
typedef bool (*WindowClose)(
HWND handle /* Window handle*/
);
/*窗口已经关闭的回调函数定义*/
typedef void (*WindowClosed)(
HWND handle /* Window handle*/
);
typedef struct{ /*窗体类型定义*/
Hwnd handle; /*窗体句柄*/
Hwnd father; /*父窗体句柄 (子窗体位于父窗体之上),为0则表示顶级窗体*/
Hwnd FirstButton; /*本窗体的第一个按钮句柄*/
Hwnd FirstLabel; /*本窗体的第一个标签*/
Hwnd FirstIco; /*本窗体的第一个图标*/
Hwnd FirstEdit; /*本窗体的第一个编辑框*/
Hwnd FirstList; /*本窗体的第一个列表框*/
Hwnd focus; /*本窗体的焦点输入框*/
Hwnd DefButton; /*窗体默认按钮,按下回车时调用*/
char Caption[30]; /*窗体标题*/
int left; /*窗体左边X坐标*/
int top; /*窗体顶部Y坐标*/
int right; /*窗体右边X坐标*/
int bottom; /*窗体底部Y坐标*/
int Width; /*窗体宽度*/
int Height; /*窗体高度*/
bool Drawed; /*是否处于画出状态*/
bool Showed; /*是否处于显示状态*/
int Color; /*窗体颜色*/
bool StartDrag; /*窗体是否处于拖动状态*/
bool CanSwitch; /*是否允许前置*/
bool ShowItems; /*是否显示下拉框*/
int DragX; /*窗体拖动时鼠标初始X坐标*/
int DragY; /*窗体拖动时鼠标初始Y坐标*/
int tag; /*标记,用来存储其他数据或指针*/
WindowClose OnClose; /*窗口关闭前的回调函数*/
WindowClosed Closed; /*窗口已经关闭的回调函数*/
byte *Ico; /*窗体图标*/
} TWindow , *pWindow ;
typedef struct{ /*按钮类型定义*/
Hwnd handle; /*按钮句柄*/
Hwnd father; /*所属窗体句柄*/
Hwnd Next; /*同窗体的下一个按钮*/
char Caption[20]; /*按钮文本*/
int left; /*按钮左边X坐标 按钮坐标均为相对于父窗体的坐标*/
int top; /*按钮顶部Y坐标*/
int right; /*按钮右边X坐标*/
int bottom; /*按钮底部Y坐标*/
int Width; /*按钮宽度*/
int Height; /*按钮高度*/
byte *Ico; /*窗体图标*/
MouseClick OnClick; /*按钮按下事件处理函数*/
} TButton, *pButton;
typedef struct{ /*标签类型定义*/
Hwnd handle; /*标签句柄*/
Hwnd father; /*所属窗体句柄*/
Hwnd Next; /*同窗体的下一个标签*/
char Caption[50]; /*标签文本*/
int left; /*标签左边X坐标 标签坐标均为相对于父窗体的坐标*/
int top; /*标签顶部Y坐标*/
int Color; /*标签颜色*/
} TLabel, *pLabel;
typedef struct{ /*图标类型定义*/
Hwnd handle; /*图标句柄*/
Hwnd father; /*所属窗体句柄*/
Hwnd Next; /*同窗体的下一个图标*/
byte *IcoBuf; /*图标图象指针*/
int left; /*图标左边X坐标 图标坐标均为相对于父窗体的坐标*/
int top; /*图标顶部Y坐标*/
} TIco, *pIco;
typedef struct{ /*编辑框类型定义*/
Hwnd handle; /*编辑框句柄*/
Hwnd father; /*所属窗体句柄*/
Hwnd Next; /*同窗体的下一个编辑框*/
int CurLocate; /*光标位置*/
int Index; /*光标在字符串中的位置*/
bool ShowCur; /*是否显示了光标*/
char Text[50]; /*编辑框内容*/
int left; /*编辑框左边X坐标 编辑框坐标均为相对于父窗体的坐标*/
int top; /*编辑框顶部Y坐标*/
int Width; /*编辑框的宽度*/
int MaxChars; /*最大字符数*/
char PasswordChar; /*是否显示为密码*/
char *(Items[10]); /*下拉框文本*/
} TEdit, *pEdit;
typedef struct{ /*列表类型定义*/
Hwnd handle; /*列表句柄*/
Hwnd father; /*所属窗体句柄*/
int left; /*列表左边X坐标 列表坐标均为相对于父窗体的坐标*/
int top; /*列表顶部Y坐标*/
int right; /*列表右边X坐标*/
int bottom; /*列表底部Y坐标*/
int Width; /*列表宽度*/
int Height; /*列表高度*/
int count; /*列表内容总数*/
int kinds; /*列的数目*/
int Selected; /*选中的序号*/
int SelectTag; /*选中的标记*/
int Show; /*开始显示的序号*/
int CanList; /*可显示的数目*/
int sorted; /*记录上次排序对象*/
int tags[100]; /*记录标记*/
int tag; /*标签*/
Pchar Text[100][6]; /*显示内容*/
} TList, *pList;
void DefCloseButton(Hwnd);
void MessageBox(char *,char *,bool );
bool DlgBox(char *,char *,char *,char *);
/* ================================ */
/* 全局变量定义部分 */
/* ================================ */
/*图标变量定义*/
TIcoBuf OKIco,CancelIco,NoIco,WndIco,CloseIco,AboutIco;
TIcoBuf WarnIco,AskIco;
/*上次鼠标状态*/
int OldX,OldY,OldLeft=false,OldRight=false;
/*建立一个栈,以后进先出的方式显示的窗口,栈顶则为顶层窗体*/
Hwnd WndStack[30];
int pStack=0; /*栈的指针*/
/*栈的相关宏定义*/
#define push(x) WndStack[pStack++]=(x)
#define pop (pStack--)
#define TopWnd (pStack>0?WndStack[pStack-1]:0)
/*MsgBox窗口使用句柄*/
Hwnd MsgBoxHd,DlgBoxHd;
void UseColor(int color){
setcolor(color);
setfillstyle(1,color);
}
/*=================================*/
/* 更新系统时间函数定义 */
/*=================================*/
void UpdateTime(){
char buf[6];
static struct time LastTime={0,0,0,0};
struct time mytime;
gettime(&mytime);
if (LastTime.ti_hour==mytime.ti_hour && LastTime.ti_min==mytime.ti_min) return;
LastTime=mytime;
DestroyMouse();
setfillstyle(1,DEF_COLOR);
bar(MAXX-50,MAXY-18,MAXX,MAXY);
buf[0]=mytime.ti_hour/10 +'0';
buf[1]=mytime.ti_hour%10 +'0';
buf[2]=':';
buf[3]=mytime.ti_min/10 +'0';
buf[4]=mytime.ti_min%10 +'0';
buf[5]=0;
WriteText(buf,MAXX-50,MAXY-17,BLACK);
DrawMouse();
}
/*=================================*/
/* 绘制输入栏函数定义 */
/*=================================*/
void DrawImmBar(){
DestroyMouse();
static bool IsFirst=true;
setfillstyle(1,DEF_COLOR);
if (IsFirst){
bar(0,MAXY-18,MAXX,MAXY);
IsFirst=false;
} else bar(0,MAXY-18,MAXX-51,MAXY);
setcolor(WHITE);
line(0,MAXY-20,MAXX,MAXY-20);
setcolor(BLACK);
line(0,MAXY-19,MAXX,MAXY-19);
if (ImmIsChn){
WriteText("[全拼]",10,MAXY-17,BLACK);
WriteText(InBuf,70,MAXY-17,BLACK);
WriteText(ImmBuf,170,MAXY-17,BLACK);
} else
WriteText("[英文]",10,MAXY-17,BLACK);
UpdateTime();
DrawMouse();
}
/*=================================*/
/* 绘制桌面函数定义 */
/*=================================*/
void DrawDesktop(){
setfillstyle(1,ScrColor);
bar(0,0,MAXX,MAXY-21);
}
/*=================================*/
/* 绘制下拉框函数定义 */
/*=================================*/
void DrawItems(){
pWindow Window=GetWindow(TopWnd);
pEdit Edit=GetEdit(Window->focus);
DestroyMouse();
setviewport(Window->left,Window->top,
Window->right,Window->bottom,1);
int i;
setcolor(BLACK);
for (i=0;i<9 && Edit->Items[i];i++);
i*=17;
rectangle(Edit->left,Edit->top+22,Edit->left+Edit->Width,Edit->top+23+i);
setfillstyle(1,WHITE);
bar(Edit->left+1,Edit->top+23,Edit->left+Edit->Width-1,Edit->top+22+i);
for (i=0;i<9 && Edit->Items[i];i++)
WriteText(Edit->Items[i],Edit->left+2,Edit->top+23+i*17,BLACK);
setviewport(0,0,MAXX,MAXY,1);
DrawMouse();
}
/*=================================*/
/* 列表框选中函数定义 */
/*=================================*/
void SelectList(Hwnd handle,int index){
pList List=GetList(handle);
pWindow father=GetWindow(List->father);
if (index<1 || index>List->count || index==List->Selected) return;
DestroyMouse();
setviewport(father->left,father->top,
father->right,father->bottom,1);
int old=List->Selected;
List->Selected=index;
List->SelectTag=List->tags[index];
int i,j=index-List->Show+1;
int Width=(List->Width-22)/List->kinds;
if (j>0 && j<=List->CanList) {
setfillstyle(1,BLUE);
bar(List->left+2,List->top+2+j*19,List->right-20,List->top+19+j*19);
setcolor(DARKGRAY);
for (i=1;i<List->kinds;i++)
line(List->left+2+i*Width,List->top+2+j*19,List->left+2+i*Width,List->top+20+j*19);
i=j-1;
for (j=0;j<List->kinds;j++){
setviewport(List->left+3+j*Width+father->left,List->top+21+i*19+father->top,List->left+1+j*Width+Width+father->left
,List->top+22+17+i*19+father->top,1);
WriteText(List->Text[i+List->Show][j],1,1,WHITE);
}
}
setviewport(father->left,father->top,
father->right,father->bottom,1);
j=old-List->Show+1;
if (j>0 && j<=List->CanList) {
setfillstyle(1,WHITE);
bar(List->left+2,List->top+2+j*19,List->right-20,List->top+19+j*19);
setcolor(DARKGRAY);
for (i=1;i<List->kinds;i++)
line(List->left+2+i*Width,List->top+2+j*19,List->left+2+i*Width,List->top+20+j*19);
i=j-1;
for (j=0;j<List->kinds;j++){
setviewport(List->left+3+j*Width+father->left,List->top+21+i*19+father->top,List->left+1+j*Width+Width+father->left
,List->top+22+17+i*19+father->top,1);
WriteText(List->Text[i+List->Show][j],1,1,BLACK);
}
}
setviewport(0,0,MAXX,MAXY,0);
DrawMouse();
}
/*=================================*/
/* 绘制列表框函数定义 */
/*=================================*/
void DrawList(Hwnd handle){
DestroyMouse();
pList List=GetList(handle);
pWindow father=GetWindow(List->father);
setviewport(father->left,father->top,
father->right,father->bottom,1);
setcolor(BLACK);
rectangle(List->left,List->top,List->right,List->bottom);
line(List->left+1,List->top+1,List->left+1,List->bottom);
line(List->left+1,List->top+1,List->right-1,List->top+1);
line(List->right-2,List->top+1,List->right-2,List->bottom-1);
line(List->right-19,List->top+1,List->right-19,List->bottom-1);
rectangle(List->right-19,List->bottom-20,List->right-3,List->bottom-2);
line(List->right-18,List->bottom-3,List->right-3,List->bottom-3);
line(List->left+1,List->top+20,List->right-1,List->top+20);
line(List->right-18,List->top+19,List->right-3,List->top+19);
line(List->right-3,List->top+2,List->right-3,List->top+19);
setcolor(WHITE);
line(List->right-1,List->top+1,List->right-1,List->bottom-1);
line(List->left+2,List->bottom-1,List->right-1,List->bottom-1);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -