编程论坛's Archiver

beyondabcd 发表于 2007-9-18 15:46

窗口弹出前保存窗口内容到XMS

<P>当窗口弹出前保存窗口内容到XMS<BR>char buf[800];//全局数组变量,每次取一行800个像素<BR>unsigned short xms_handle;//XMS句柄<BR>/**********************************************************/<BR>/* 保存窗口内容到XMS<BR>/**********************************************************/<BR>void  Save_Window_XMS(int x1,int y1,int x2,int y2)<BR>{<BR>    int i,j;<BR>    unsigned short size,len;<BR>    unsigned long offset = 0;<BR>    char *pp;</P>

<P>    size = (x2-x1+1)*(y2-y1+1)/<STRONG><FONT style="BACKGROUND-COLOR: #f7f709">1024</FONT></STRONG> +1;<BR>    if (XMS_Size() &lt; size)<BR>        puts("not enough XMS");<BR>    if ((xms_handle = XMS_Alloc(size)) == 0)//XMS申请空间成功<BR>        puts("XMS handle Error...\n");<BR>    for (i= y1; i&lt;=y2;i++)<BR>    {<BR>        pp=buf;<BR>        for (j= x1; j&lt;=x2;j++)<BR>            *pp++ = getpixel(j,i);//在屏幕上获取像素点<BR>        len = x2-x1+1;<BR>        Write_To_XMS(buf,len,xms_handle,offset);//缓冲区buf中存储的像素送至XMS<BR>        offset += len;<BR>    }<BR>}<BR>--------------------------------------------------------------------------------------------------------<BR>原程序是800X600模式的,用除1024,我想用640 X 480的模式,应该除什么数呀?</P>

ba_wang_mao 发表于 2007-9-19 08:59

你没有搞明白,其实size = (x2-x1+1)*(y2-y1+1)/1024 +1;就是计算窗口区域占用多少K(1K=1024字节)<BR>因为子程序XMS_Size() 返回的是内存剩余空间有多少K<BR>

一笔苍穹 发表于 2007-9-19 09:52

TC256 XMS/EMS双内核版(未发布)的源码可能对LZ有帮助:<BR><a href="http://www.ds0101.com/DownLoad/ShowInfo.asp?ID=48" target="_blank" >http://www.ds0101.com/DownLoad/ShowInfo.asp?ID=48</A>

ba_wang_mao 发表于 2007-9-19 12:00

<P>支持!</P>

beyondabcd 发表于 2007-9-19 14:49

不好意思,我问一个很莱的问题

beyondabcd 发表于 2007-9-19 15:10

<P>#include "graphics.h"<BR>#include&lt;dos.h&gt;</P>
<P>#include&lt;conio.h&gt;</P>
<P>#include "stdio.h"<BR>#include "fcntl.h"<BR>#include "malloc.h"<BR>#include "io.h"<BR>#include "showbmp.c"<BR> #include "rsvga256.h" </P>
<P>typedef unsigned int XMS_HANDLE;<BR>XMS_HANDLE xms_handle;                /*  伪指针 */<BR>XMS_HANDLE xms_save_restore_handle;                /*  伪指针 */</P>
<P>typedef struct emm {<BR>  unsigned int length;<BR>  unsigned source_handle;<BR>  unsigned long source_offset;<BR>  unsigned dest_handle;<BR>  unsigned long dest_offset;<BR>} xmm;<BR>xmm xms;</P>

<P>int far(* XMS_Function)( );<BR>int xms_installed( )<BR>{<BR>  _AX=0x4300;<BR>  geninterrupt(0x2f);<BR>  if(_AL==0x80)  <BR>    {<BR>        _AX=0x4310;<BR>        geninterrupt(0x2f);<BR>        XMS_Function=MK_FP(_ES,_BX);<BR>        return(1);<BR>    }<BR>  else<BR>    {<BR>        printf("XMS is not installed\n!");<BR>        return(0);<BR>    }<BR>}</P>
<P>int test_xms(unsigned int size)<BR>    {<BR>        _AH=8;<BR>        XMS_Function( );<BR>        if(_AX&lt;size)<BR>            {<BR>                printf("No enough XMS to be used!\n");<BR>                return(0);<BR>             }<BR>        else<BR>        return(1);<BR>    }</P>
<P>unsigned int alloc_xms(unsigned int size)<BR>    {<BR>        _DX=size;<BR>        _AH=9;<BR>        XMS_Function( );<BR>        if(_AX!=1)  <BR>            {<BR>                printf("XMS allocation is error\n");<BR>                return(0);<BR>            }<BR>        else<BR>        return(_DX);<BR>    }</P>
<P><BR>int move_xms(xms)<BR>    {<BR>        _DS=FP_SEG(xms);<BR>        _SI=FP_OFF(xms);<BR>        _AH=0x0b;<BR>        XMS_Function( );</P>
<P>        if(_AX!=1)   <BR>            {<BR>                printf("XMS move error! %d\n",_BL);<BR>                return(0);<BR>            }<BR>        else<BR>        return(1);<BR>    }</P>
<P>void free_xms(unsigned int handle)<BR>    {<BR>        _DX=handle;<BR>        _AH=0x0a;<BR>        XMS_Function( );<BR>    }</P>
<P><BR>/*----------------------------------------------------------- */<BR>/* 从常规内存缓冲区buf装载到扩充内存 */<BR>/*-----------------------------------------------------------*/</P>
<P><BR>void  Write_To_XMS(char *buf,  unsigned int size,unsigned  handle,unsigned long offset)<BR>{<BR>        xms.length=size;<BR>    xms.source_handle = 0;<BR>    xms.source_offset  = FP_SEG((void far *)buf);<BR>    xms.source_offset &lt;&lt;= 16;<BR>    xms.source_offset += FP_OFF((void far *)buf);<BR>    xms.dest_handle = handle;<BR>    xms.dest_offset = offset;<BR>    move_xms(&amp;xms);<BR>}</P>

<P><BR>/*-----------------------------------------------------------  */<BR>/* 从扩充内存中读取信息到常规内存缓冲区buf */<BR>/*-----------------------------------------------------------*/<BR>void  Read_From_XMS(char *buf,unsigned int size,unsigned  handle,unsigned long offset)<BR>{<BR>    xms.length = size;<BR>    xms.source_handle = handle;<BR>    xms.source_offset = offset;<BR>    xms.dest_handle = 0;<BR>    xms.dest_offset = FP_SEG((void far *)buf);<BR>    xms.dest_offset &lt;&lt;= 16;<BR>    xms.dest_offset  += FP_OFF((void far *)buf);<BR>   move_xms(&amp;xms);<BR>}</P>

<P><BR>char sssbuf[400];<BR>void  Save_Image_XMS(int POPUP_x1,int POPUP_x2,int POPUP_y1,int POPUP_y2 )<BR>{<BR>    int i,j;<BR>    unsigned int size;<BR>    unsigned long offset = 0;<BR>    char *pp;</P>

<P>    size = (POPUP_x2-POPUP_x1+1)*(POPUP_y2-POPUP_y1+1)/1024+1;</P>
<P>    if (test_xms(size)==0)<BR>        puts("not enough XMS");     printf("%d",test_xms(size));getch();<BR>    if ((xms_save_restore_handle = alloc_xms(size)) == 0)<BR>        puts("XMS handle Error...\n");<BR>    for (i= POPUP_y1; i&lt;=POPUP_y2;i++)<BR>    {<BR>        size = POPUP_x2-POPUP_x1;   printf("%d",size);<BR>        pp = sssbuf;<BR>        for (j= POPUP_x1; j&lt;=POPUP_x2;j++)<BR>            *pp++ = getpixel(j,i);<BR>        Write_To_XMS(sssbuf,size,xms_save_restore_handle,offset);<BR>        offset += size;<BR>    }<BR>}</P>

<P><BR>void  Restore_Image_XMS(int POPUP_x1,int POPUP_x2,int POPUP_y1,int POPUP_y2)<BR>{<BR>    int i,j;<BR>    unsigned short size;<BR>    unsigned long offset = 0;<BR>    char *pp;</P>

<P>    size = POPUP_x2-POPUP_x1;<BR>    for (i= POPUP_y1; i&lt;=POPUP_y2;i++)<BR>    {<BR>        Read_From_XMS(sssbuf,size,xms_save_restore_handle,offset);<BR>        offset += size;<BR>        pp = sssbuf;<BR>        for (j= POPUP_x1; j&lt;=POPUP_x2;j++)<BR>            putpixel(j,i,*pp++);/* sssbuf[j-POPUP_x1]); */<BR>    }<BR>    free_xms(xms_save_restore_handle);<BR>}</P>
<P><BR>int huge rReturn_SVGA256(void)<BR>{<BR>  return(SVGA640x480x256);<BR>}</P>
<P> void main()<BR>{   int iii=DETECT, jjj=0;</P>
<P> installuserdriver("Svga256", rReturn_SVGA256);       /* 对于svga256必需执行该函数以安装BGI驱动 */<BR>         initgraph(&amp;iii, &amp;jjj, "");<BR>     printf("%d",xms_installed( ));getch();<BR>         show_bmp("main.bmp",0,0); getch();<BR>    Save_Image_XMS(50,110,50,100 );<BR>    getch();<BR>    show_bmp("bell.bmp",40,40);<BR>     getch();<BR>    Restore_Image_XMS(50,110,50,100);<BR>    getch();<BR>    closegraph();<BR>}</P>
<P>程序走到黄体字时,就走不了,大家帮忙看看</P>

<P><BR> </P>
<P><BR> </P>[attach]27691[/attach]<BR>

eakcon 发表于 2007-11-14 10:10

<P>好强呀!</P>
<P><BR>此主题相关图片如下:<BR></P>

页: [1]

Powered by Discuz! Archiver 6.1.0  © 2001-2007 Comsenz Inc.