www.pudn.com > cwin.rar > ASK.C


    /*----------------------------------------------------------- 
        函数 ask : 逻辑提示框 
    -----------------------------------------------------------*/ 
    #include  
    #include  
 
    /*------------ 宏定义 : 两个按钮的鼠标范围 ----------------*/ 
    #define YES_l      (col*8+buttons[YES].x) 
    #define YES_t      (pmtline+buttons[YES].y) 
    #define YES_r      (col*8+buttons[YES].x+buttons[YES].w) 
    #define YES_b      (pmtline+buttons[YES].y+buttons[YES].h) 
    #define NO_l       (col*8+buttons[NO].x) 
    #define NO_t       (pmtline+buttons[NO].y) 
    #define NO_r       (col*8+buttons[NO].x+buttons[NO].w) 
    #define NO_b       (pmtline+buttons[NO].y+buttons[NO].h) 
 
    int _Cdecl ask(col,line,width,high,title,prompt) 
    int col;               /* 提示框左上角列坐标(以字节为单位) */ 
    int line;              /* 提示框左上角行坐标(以象素为单位) */ 
    int width;             /* 提示框宽度(以字节为单位)         */ 
    int high;              /* 提示框高度(以象素为单位)         */ 
    char *title;           /* 提示框名称                       */ 
    char *prompt;          /* 提示信息                         */ 
    { 
        char **block;      /* 存储提示框背景的缓冲区指针       */ 
        unsigned key; 
        int pmtwidth; 
        int pmthigh; 
        int pmtcol; 
        int pmtline = line+8; 
        int old_l   = _TextWinLeft; 
        int old_t   = _TextWinTop; 
        int old_r   = _TextWinRight; 
        int old_b   = _TextWinBottom; 
        BUTTON_TYPE buttons[2]; 
 
        delight_mouse(); 
 
        /*--------------- 存储提示框的背景 --------------------*/ 
        block = getblock(col,line,width,high); 
 
        /*------------------- 画提示框 ------------------------*/ 
        _Box(col*8,line,width*8,high); 
 
        /*-------- 如果有标题,则显示标题并调整有关参数 --------*/ 
        if(title) 
        { 
            pmtcol    = col*8+4; 
            pmtwidth  = (width-1)*8; 
            pmthigh   = (_CurrentHZK->fonthigh+2)*_Ytimes; 
 
            _Bar(pmtcol,line+4,pmtwidth,pmthigh+4,_TitleBk,0xffff0000); 
            if(prompt) 
                _H_Line(pmtcol,pmtline+pmthigh,pmtwidth,_BoxLineColor,0xff); 
 
            pmtwidth  = strlen(title)*_CurrentHZK->fontwidth*_Xtimes/2; 
            pmtcol    = col+(width-pmtwidth)/2; 
            outxystr(pmtcol,pmtline,_TitleColor,title); 
            pmtline  += (pmthigh+1); 
        } 
 
        /*--------- 如果有提示,则显示提示并调整有关参数 -------*/ 
        if(prompt) 
        { 
            pmtcol    = col+1; 
            pmtwidth  = strlen(prompt)*_CurrentHZK->fontwidth*_Xtimes/2; 
            pmthigh   = (pmtwidth/(width-1)+1)*(_CurrentHZK->fonthigh+2)*_Ytimes; 
            pmtwidth  = width-2; 
            set_window(pmtcol,pmtline,pmtcol+pmtwidth-1,pmtline+pmthigh-1); 
            _TextCol  = pmtcol; 
            _TextLine = pmtline; 
            outstr(prompt); 
            set_window(old_l,old_t,old_r,old_b); 
            pmtline  += pmthigh; 
        } 
 
        /*----------------- 设置按钮的有关参数 ----------------*/ 
        pmtwidth               = _CurrentHZK->fontwidth*_Xtimes; 
        pmtwidth              += 2*(width-pmtwidth-3)/7; 
        pmtwidth              *= 8; 
 
        buttons[NO].x          = (width*8-pmtwidth*2-8)/3+4; 
        buttons[NO].y          = 4*_Ytimes; 
        buttons[NO].w          = pmtwidth; 
        buttons[NO].h          = (_CurrentHZK->fonthigh+8)*_Ytimes; 
        buttons[NO].butncolor  = _BarColor; 
        buttons[NO].pushcolor  = _BarColor; 
        buttons[NO].fonttimes  = _Ytimes<<8|_Xtimes; 
        buttons[NO].name       = "否"; 
        buttons[NO].key        = 'N'; 
        buttons[NO].pressed    = NO; 
        buttons[NO].high       = 1; 
        buttons[NO].lock       = NO; 
        buttons[NO].fun        = NULL; 
 
        buttons[YES].x         = (width*8-pmtwidth*2-8)/3*2+4+pmtwidth; 
        buttons[YES].y         = 4*_Ytimes; 
        buttons[YES].w         = pmtwidth; 
        buttons[YES].h         = (_CurrentHZK->fonthigh+8)*_Ytimes; 
        buttons[YES].butncolor = _BarColor; 
        buttons[YES].pushcolor = _BarColor; 
        buttons[YES].fonttimes = _Ytimes<<8|_Xtimes; 
        buttons[YES].name      = "是"; 
        buttons[YES].key       = 'Y'; 
        buttons[YES].pressed   = YES; 
        buttons[YES].high      = 1; 
        buttons[YES].lock      = NO; 
        buttons[YES].fun       = NULL; 
 
        /*------------------- 显示按钮 ------------------------*/ 
        _DrawButton(buttons[YES],col,pmtline,NO,0); 
        _DrawButton(buttons[NO] ,col,pmtline,NO,0); 
 
        /*------ 主循环:根据键盘和鼠标信息进行逻辑选择 --------*/ 
        light_mouse(); 
        do 
        { 
            key = geth(); 
            switch(key) 
            { 
                case LEFT_BUTTON: 
                    if(mouse_enter(YES_l,YES_t,YES_r,YES_b)) 
                    { 
                        delight_mouse(); 
                        _DrawButton(buttons[YES],col,pmtline,NO,1); 
                        light_mouse(); 
                        till_mouse_pop(LEFT_BUTTON); 
                        key = 'Y'; 
                    } 
                    else if(mouse_enter(NO_l,NO_t,NO_r,NO_b)) 
                    { 
                        delight_mouse(); 
                        _DrawButton(buttons[NO] ,col,pmtline,NO,1); 
                        light_mouse(); 
                        till_mouse_pop(LEFT_BUTTON); 
                        key = 'N'; 
                    } 
                    break; 
                case 'y': 
                case 'Y': 
                    delight_mouse(); 
                    _DrawButton(buttons[YES],col,pmtline,NO,1); 
                    light_mouse(); 
                    delay(200); 
                    break; 
                case 'n': 
                case 'N': 
                    delight_mouse(); 
                    _DrawButton(buttons[NO] ,col,pmtline,NO,1); 
                    light_mouse(); 
                    delay(200); 
                    break; 
                case RIGHT_BUTTON: 
                    key = KEY_ESC; 
                    break; 
            } 
        }while(!strchr("YyNn",key) && key!=KEY_ESC); 
 
        /*------------ 恢复提示框处原来的背景 -----------------*/ 
        delight_mouse(); 
        putblock(col,line,width,high,block); 
        light_mouse(); 
 
        /*------------ 将键码转换为逻辑值并返回 ---------------*/ 
        if(key=='Y' || key=='y') 
            key = YES; 
        else if(key=='N' || key=='n') 
            key = NO; 
        else            /* key==KEY_ESC || RIGHT_BUTTON */ 
            key = -1; 
        return key; 
    }