由于我需要在操作画面上弹出一个窗口,因此必须将窗口覆盖区域的屏幕内容保存,由于常规内存紧张,因此决定在XMS内存中申请空间。
1、我检测了我的XMS空间总共有8000K,采用XMS_Size()函数检测的。
2、为保证显示速度及硬盘寿命,汉字库HZK16加载到XMS,占用260K。
当我再申请XMS空间比较小时,申请成功,而申请空间稍大时,却提示"XMS not enough"。如何解决申请比较大的空间呢(因为我有可能将整个屏幕800X600保存)?
//-----------------------------------------------------------
//检测XMS是否安装
//-----------------------------------------------------------
int _Cdecl XMS_Test(void)
{
_AX = 0x4300;
__int__(0x2F);
if (_AL == 0x80)
{
_AX = 0x4310;
__int__(0x2F);
XMS_Function=(void far *)MK_FP(_ES,_BX);
return (1);
}
return (-1);
}
//-----------------------------------------------------------
//查询空闲的扩充内存空间(不包括HMA)
//-----------------------------------------------------------
int _Cdecl XMS_Size(void)
{
_AH = 0x08;
XMS_Function();
return (_DX);
}
//-----------------------------------------------------------
//分配扩充内存
//-----------------------------------------------------------
int _Cdecl XMS_Alloc(int size)
{
_DX = size;
_AH = 0x09;
XMS_Function();
if(_AX == 1)
return (_DX);
return (-1);
}
//-----------------------------------------------------------
//汉字库hzk16装载到扩充内存
//-----------------------------------------------------------
void _Cdecl ReadHzkXMS(char *Hzkname)
{
unsigned long hzksize;
unsigned short size;
unsigned long offset = 0;
char buf[32];
FILE *fp;
if (XMS_Test() == -1)
{
puts("not found XMS");
exit(1);
}
if ((fp = fopen(Hzkname,"rb")) == NULL)
{
puts("Cannot Open HZK16 ...\n");
exit(1);
}
fseek(fp,0L,SEEK_END);
hzksize = ftell(fp);
fseek(fp,0L,SEEK_SET);
size = hzksize/1024 +1; // 262K
if (XMS_Size() < size)
{
puts("not enough XMS");
fclose(fp);
exit(-1);
}
if ((xms_handle = XMS_Alloc(size)) == 0)
{
puts("XMS handle Error...\n");
fclose(fp);
exit(-1);
}
while (!feof(fp))
{
size = fread(buf,sizeof(char),32,fp);
Write_To_XMS(buf,size,xms_handle,offset);//点阵字模移到XMS
offset += size;
}
fclose(fp);
}
//-----------------------------------------------------------
//将POPUP_x1,POPUP_y1,POPUP_x2,POPUP_y2
//包含区域的屏幕内容保存到XMS
//-----------------------------------------------------------
char XMSBuffer[800];
void _Cdecl Save_Image_XMS(void)
{
int i,j;
unsigned short size;
unsigned long offset = 0;
char *pp;
size = (POPUP_x2-POPUP_x1+1)*(POPUP_y2- POPUP_y1+1)/1024+1;
if (XMS_Size() < size)
puts("not enough XMS");
if ((xms_save_restore_handle = XMS_Alloc(size)) == 0)
puts("XMS handle Error...\n");
for (i= POPUP_y1; i<=POPUP_y2;i++)
{
size = POPUP_x2-POPUP_x1;
pp = XMSBuffer;
for (j= POPUP_x1; j<=POPUP_x2;j++)
*pp++ = getpixel(j,i);
Write_To_XMS(XMSBuffer,size,xms_save_restore_handle,offset);
offset += size;
}
}
void main()
{
ReadHzkXMS("HZK16");//汉字库hzk16装载到扩充内存
POPUP_x1 = 100;
POPUP_x2 = 550;
POPUP_y1 = 200;
POPUP_y2 = 500;
Save_Image_XMS();//此处提示申请XMS失败,而XMS空间有8000K
//而如果POPUP_x1 = 300 POPUP_y1 = 450 POPUP_x2 = 250
// POPUP_y2 = 450却能申请成功能?