📄 mywindow.h
字号:
void MoveWindow(Hwnd handle, int MoveX, int MoveY){
if (handle==0) return;
pWindow Window=GetWindow(handle);
if (MoveX==0 && MoveY<Window->Height) {
if (MoveY>0)
HideWindow(WndStack[pStack-2],Window->left,Window->top,Window->right,Window->top+MoveY,pStack-2);
else
HideWindow(WndStack[pStack-2],Window->left,Window->bottom-MoveY,Window->right,Window->bottom,pStack-2);
}else if (MoveY==0 && MoveX<Window->Width){
if (MoveX>0)
HideWindow(WndStack[pStack-2],Window->left,Window->top,Window->left+MoveX,Window->bottom,pStack-2);
else
HideWindow(WndStack[pStack-2],Window->right-MoveX,Window->top,Window->right,Window->bottom,pStack-2);
} else
HideWindow(WndStack[pStack-2],Window->left,Window->top,Window->right,Window->bottom,pStack-2);
Window->top+=MoveY;
Window->bottom+=MoveY;
Window->left+=MoveX;
Window->right+=MoveX;
DrawWindow(handle);
}
/*=====================================*/
/* 本函数实现窗体拖动时虚线的绘制 */
/* 该部分由异或运算实现,2次调用可还原 */
/*=====================================*/
void DragWindow(Hwnd handle,int MoveX,int MoveY,int Color){
if (handle==0) return;
pWindow Window=GetWindow(handle);
int x1=Window->left+MoveX;
int y1=Window->top+MoveY;
int x2=Window->right+MoveX;
int y2=Window->bottom+MoveY;
int i,j;
setcolor(Color);
DestroyMouse();
for (i=0;i*10<=Window->Width;i++)
for (j=0;j<=5 && i*10+j<=Window->Width;j++){
putpixel(x1+i*10+j,y1,getpixel(x1+i*10+j,y1)^Color);
putpixel(x1+i*10+j,y2,getpixel(x1+i*10+j,y2)^Color);
}
for (i=0;i*10<=Window->Height;i++)
for (j=0;j<=5 && i*10+j<=Window->Height;j++){
putpixel(x1,y1+i*10+j,getpixel(x1,y1+i*10+j)^Color);
putpixel(x2,y1+i*10+j,getpixel(x2,y1+i*10+j)^Color);
}
DrawMouse();
}
/*=================================*/
/* 列表框添加内容函数定义 */
/*=================================*/
void ListAdd( Hwnd handle, /*列表框句柄*/
pchar Str[], /*文本*/
int tag) /*该行的标记*/
{
pList List=GetList(handle);
memcpy(List->Text[++(List->count)],Str,sizeof List->Text[0]);
List->tags[List->count]=tag;
}
/*=================================*/
/* 列表框翻页函数定义 */
/*=================================*/
void ListPageDown( Hwnd handle, /*列表框句柄*/
int Lines) /*翻多少行*/
{
pList List=GetList(handle);
if (Lines<0 && List->Show>1 || Lines>0 && List->Show<List->count){
List->Show+=Lines;
DrawList(handle);
}
}
void ListSort( Hwnd handle, /*列表框句柄*/
int target) /*排序对象*/
{
int min,max;
int i,j;
double t1,t2;
Pchar buf[10];
pList List=GetList(handle);
bool CheckValue=true; /*检查该字段是否能作为数字比较*/
for (i=1;i<=List->count && CheckValue;i++)
if (atof(List->Text[i][target])==0)
for (j=0;List->Text[i][target][j];j++)
if (List->Text[i][target][j]!='0' && List->Text[i][target][j]!='.'){
CheckValue=false;
break;
}
int count;
count=strcmp("总计",List->Text[List->count][0])?List->count:List->count-1;
if (target==List->sorted){ /*升序排列*/
List->sorted=-1;
for (i=1;i<count;i++){
max=i;
for (j=i+1;j<=count;j++){
if (CheckValue){
t1=atof(List->Text[j][target]);
t2=atof(List->Text[max][target]);
if (t1>t2) max=j;
}
else if (strcmp(List->Text[j][target],List->Text[max][target])>0) max=j;
}
memcpy(buf,List->Text[i],sizeof List->Text[i]);
memcpy(List->Text[i],List->Text[max],sizeof List->Text[i]);
memcpy(List->Text[max],buf,sizeof List->Text[i]);
j=List->tags[i];
List->tags[i]=List->tags[max];
List->tags[max]=j;
}
} else {
List->sorted=target;
for (i=1;i<count;i++){ /*降序排列*/
min=i;
for (j=i+1;j<=count;j++){
if (CheckValue){
t1=atof(List->Text[j][target]);
t2=atof(List->Text[min][target]);
if (t1<t2) min=j;
}
else if (strcmp(List->Text[j][target],List->Text[min][target])<0) min=j;
}
memcpy(buf,List->Text[i],sizeof List->Text[i]);
memcpy(List->Text[i],List->Text[min],sizeof List->Text[i]);
memcpy(List->Text[min],buf,sizeof List->Text[i]);
j=List->tags[i];
List->tags[i]=List->tags[min];
List->tags[min]=j;
}
}
List->Selected=0;
List->SelectTag=0;
List->Show=1;
DrawList(handle);
}
/*=================================*/
/* 列表框创建函数定义 */
/*=================================*/
Hwnd CreateList( Hwnd father, /*指定父窗体句柄*/
int left, /*列表框左边X坐标*/
int top, /*列表框顶部Y坐标*/
int Width, /*列表框宽度*/
int Height, /*列表框高度*/
pchar Title[]) /*列表框标题*/
{
pList List;
List=(pList)malloc(sizeof *List);
if (List==NULL) return 0;
memset(List,0,sizeof *List);
List->father=father;
List->left=left;
List->top=top;
List->Width=Width;
List->Height=Height;
List->right=left+Width;
List->bottom=top+Height;
List->sorted=-1;
List->handle=(Hwnd)List;
int i;
for (i=0;Title[i];i++)
List->Text[0][i]=Title[i];
List->kinds=i;
GetWindow(father)->FirstList=List->handle;
return List->handle;
}
void AddItems( Hwnd handle, /*编辑框句柄*/
char Text[]) /*加入的文字*/
{
if (handle==0) return;
pEdit Edit=GetEdit(handle);
int i;
for (i=0;i<10 && Edit->Items[i];i++);
if (i<10) Edit->Items[i]=Text;
if (i==0) Edit->MaxChars-=2;
}
/*=================================*/
/* 编辑框创建函数定义 */
/*=================================*/
Hwnd CreateEdit( char Text[], /*编辑框标题*/
Hwnd father, /*指定父窗体句柄*/
int left, /*编辑框左边X坐标*/
int top, /*编辑框顶部Y坐标*/
int Width=DEF_EDIT_WIDTH) /*编辑框宽度*/
{
pEdit Edit;
Edit=(pEdit)malloc(sizeof *Edit);
if (Edit==NULL) return 0;
memset(Edit,0,sizeof *Edit);
if (Text!=NULL)
strcpy(Edit->Text,Text);
Edit->father=father;
Edit->left=left;
Edit->top=top;
Edit->Width=Width;
Edit->MaxChars=(Width-6)/8;
Edit->handle=(Hwnd)Edit;
Hwnd p=((pWindow)father)->FirstEdit; /*建立标签链表*/
if ( p == 0)
((pWindow)father)->FirstEdit=Edit->handle;
else{
while ( NextEdit(p) !=0)
p=NextEdit(p);
NextEdit(p)=Edit->handle;
}
return Edit->handle;
}
/*=================================*/
/* 图标创建函数定义 */
/*=================================*/
Hwnd CreateIco( TIcoBuf IcoBuf, /*指定图标内容*/
Hwnd father, /*指定父窗体句柄*/
int left, /*标签左边X坐标*/
int top) /*标签顶部Y坐标*/
{
pIco Ico;
Ico=(pIco)malloc(sizeof *Ico);
if (Ico==NULL) return 0;
memset(Ico,0,sizeof *Ico);
Ico->IcoBuf=IcoBuf;
Ico->father=father;
Ico->top=top;
Ico->left=left;
Ico->handle=(Hwnd)Ico;
Hwnd p=((pWindow)father)->FirstIco; /*建立图标链表*/
if ( p == 0)
((pWindow)father)->FirstIco=Ico->handle;
else{
while ( NextIco(p) !=0)
p=NextIco(p);
NextIco(p)=Ico->handle;
}
return Ico->handle;
}
/*=================================*/
/* 标签创建函数定义 */
/*=================================*/
Hwnd CreateLabel( char Caption[], /*标签标题*/
Hwnd father, /*指定父窗体句柄*/
int left, /*标签左边X坐标*/
int top, /*标签顶部Y坐标*/
int Color=BLACK) /*标签颜色*/
{
pLabel Label;
Label=(pLabel)malloc(sizeof *Label);
if (Label==NULL) return 0;
memset(Label,0,sizeof *Label);
if (Caption!=NULL)
strcpy(Label->Caption,Caption);
Label->father=father;
Label->left=left;
Label->top=top;
Label->Color=Color;
Label->handle=(Hwnd)Label;
Hwnd p=((pWindow)father)->FirstLabel; /*建立标签链表*/
if ( p == 0)
((pWindow)father)->FirstLabel=Label->handle;
else{
while ( NextLabel(p) !=0)
p=NextLabel(p);
NextLabel(p)=Label->handle;
}
return Label->handle;
}
/*=================================*/
/* 按钮创建函数定义 */
/*=================================*/
Hwnd CreateButton( char Caption[], /*按钮标题*/
Hwnd father, /*指定父窗体句柄*/
MouseClick OnClick, /*鼠标按下事件处理函数指针*/
int left, /*按钮左边X坐标*/
int top, /*按钮顶部Y坐标*/
int Width=DEF_BUT_WIDTH, /*按钮宽度*/
int Height=DEF_BUT_HEIGHT, /*按钮高度*/
byte *Ico=NULL) /*指定按钮图标*/
{
pButton NewButton;
NewButton=(pButton)malloc(sizeof *NewButton);
if (NewButton==NULL) return 0;
memset(NewButton,0,sizeof *NewButton);
if (Caption!=NULL) strcpy(NewButton->Caption,Caption);
NewButton->OnClick=OnClick;
NewButton->left=left;
NewButton->top=top;
NewButton->Width=Width;
NewButton->Height=Height;
NewButton->right=left+Width-1;
NewButton->bottom=top+Height-1;
NewButton->father=father;
NewButton->Ico=Ico;
NewButton->handle=(Hwnd)NewButton;
Hwnd p=((pWindow)father)->FirstButton; /*建立按钮链表*/
if ( p == 0)
((pWindow)father)->FirstButton=NewButton->handle;
else{
while ( NextButton(p) !=0)
p=NextButton(p);
NextButton(p)=NewButton->handle;
}
return NewButton->handle;
}
/*=================================*/
/* 窗体创建函数定义 */
/*=================================*/
Hwnd CreateWindow( char Caption[], /*窗体标题*/
int left, /*窗体左边X坐标*/
int top, /*窗体顶部Y坐标*/
int right, /*窗体右边X坐标*/
int bottom, /*窗体底部Y坐标*/
byte *Ico=NULL, /*指定窗体图标*/
Hwnd father=0, /*指定父窗体句柄*/
bool CanSwitch=false, /*是否可以切换窗体*/
int Color=DEF_COLOR) /*指定窗体颜色*/
{
pWindow NewWindow;
NewWindow=(pWindow)malloc(sizeof *NewWindow);
if (NewWindow==NULL) return 0;
memset(NewWindow,0,sizeof *NewWindow);
strcpy(NewWindow->Caption,Caption);
NewWindow->left=left;
NewWindow->top=top;
NewWindow->right=right;
NewWindow->bottom=bottom;
NewWindow->Color=Color;
NewWindow->father=father;
NewWindow->Width=right-left+1;
NewWindow->Height=bottom-top+1;
NewWindow->Ico=Ico;
NewWindow->CanSwitch=CanSwitch;
NewWindow->handle=(Hwnd)NewWindow;
CreateButton(NULL,NewWindow->handle,&DefCloseButton,NewWindow->Width-21,2,18,18,CloseIco);
return NewWindow->handle;
}
bool FindList(int x,int y){
pWindow Window=GetWindow(TopWnd);
pList List=GetList(Window->FirstList);
if (!List || x<List->left || y<List->top
|| x>List->right || y>List->bottom) return false;
x-=List->left;
y-=List->top;
if (x>=List->Width-20){
if (y<=20){
ListPageDown(List->handle,-5);
} else if (y>=List->Height-20) {
ListPageDown(List->handle,5);
}
return true;
}
int i;
if (y>20) {
i=(y-20)/19+List->Show;
SelectList(List->handle,i);
return true;
}
if (y<=20) {
int Width=(List->Width-22)/List->kinds;
i=(x-2)/Width;
if (i>=0 && i<List->kinds)
ListSort(List->handle,i);
}
return true;
}
bool FindItems(int x,int y){
pWindow Window=GetWindow(TopWnd);
pEdit Edit=GetEdit(Window->focus);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -