Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/130.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ Pdcurses';这个术语似乎是随机工作的 #包括 #包括 #包括“SourceFiles/generalFunc.h” int main() { initscr(); int x=调整_项的大小(51,79); sleepMilli(5000);//睡眠5秒 endwin(); std::cout_C++_Curses_Pdcurses - Fatal编程技术网

C++ Pdcurses';这个术语似乎是随机工作的 #包括 #包括 #包括“SourceFiles/generalFunc.h” int main() { initscr(); int x=调整_项的大小(51,79); sleepMilli(5000);//睡眠5秒 endwin(); std::cout

C++ Pdcurses';这个术语似乎是随机工作的 #包括 #包括 #包括“SourceFiles/generalFunc.h” int main() { initscr(); int x=调整_项的大小(51,79); sleepMilli(5000);//睡眠5秒 endwin(); std::cout,c++,curses,pdcurses,C++,Curses,Pdcurses,调整大小\u术语是一个ncurses函数 该函数不会更改终端的大小;它会更改ncurses假定的大小 由于诅咒不会显示任何内容,并且(请参阅),您的示例不会显示任何内容,因此诅咒不会显示任何内容作为更改 有趣的是,PDCurses实现了一个名称相同的函数(受ncurses启发:其中有几个函数),但描述方式不同。引用PDCurses/initscr.c中的注释: #include <iostream> #include <curses.h> #include "Source

调整大小\u术语
是一个ncurses函数

该函数不会更改终端的大小;它会更改ncurses假定的大小

由于诅咒不会显示任何内容,并且(请参阅),您的示例不会显示任何内容,因此诅咒不会显示任何内容作为更改

有趣的是,PDCurses实现了一个名称相同的函数(受ncurses启发:其中有几个函数),但描述方式不同。引用
PDCurses/initscr.c
中的注释:

#include <iostream>
#include <curses.h>
#include "SourceFiles/generalFunc.h"

int main()
{

    initscr();
    int x = resize_term(51, 79);
    sleepMilli(5000); //sleep for 5 seconds
    endwin();
    std::cout << x << " " << int(ERR) << " " << int(OK);

}
函数从以下内容开始:

    resize_term() is effectively two functions: When called with  
    nonzero values for nlines and ncols, it attempts to resize the  
    screen to the given size. When called with (0, 0), it merely  
    adjusts the internal structures to match the current size after  
    the screen is resized by the user. On the currently supported  
    platforms, this functionality is mutually exclusive: X11 allows  
    user resizing, while DOS, OS/2 and Win32 allow programmatic  
    resizing. If you want to support user resizing, you should check  
    for getch() returning KEY_RESIZE, and/or call is_termresized()  
    at appropriate times; if either condition occurs, call  
    resize_term(0, 0). Then, with either user or programmatic  
    resizing, you'll have to resize any windows you've created, as  
    appropriate; resize_term() only handles stdscr and curscr. 
这反过来又为Windows控制台调用此选项:

int resize_term(int nlines, int ncols)
{   
    PDC_LOG(("resize_term() - called: nlines %d\n", nlines));

    if (!stdscr || PDC_resize_screen(nlines, ncols) == ERR)
        return ERR;

    SP->lines = PDC_get_rows();
    LINES = SP->lines - SP->linesrippedoff - SP->slklines;
    SP->cols = COLS = PDC_get_columns();
int PDC\u调整屏幕大小(int nlines,int ncols)
{
小直;
坐标大小,最大值;
如果(nlines<2 | | ncols<2)
返回错误;
最大值=获取最大控制台宽度(pdc控制输出);
rect.Left=rect.Top=0;
rect.Right=ncols-1;
如果(右下>最大X)
右矩形=最大X;
矩形底部=nlines-1;
如果(垂直底部>最大Y)
垂直底部=最大Y;
尺寸X=右矩形+1;
尺寸Y=垂直底部+1;
_安装控制台窗口(pdc控制和校正);
设置控制台屏幕缓冲区大小(pdc\U con\U out,大小);
_安装控制台窗口(pdc控制和校正);
设置控制台屏幕缓冲区大小(pdc\U con\U out,大小);
设置控制台活动屏幕缓冲区(pdc控制输出);
返回OK;
}
因此,您可以看到结果是一个不兼容的函数。(SDL有一个类似的端口)。有几个问题与PDCurses行为有关:

但是,PDCurses通常将其头文件安装为
,以表示它与curses(或ncurses)的区别。我假设问题是关于ncurses的,问题是混淆了库函数的功能:

回到PDCurses,奇怪的是它会两次调用相同的两个函数。PDCurses函数可能会进行多次尝试,减少给定的值,直到它们合适为止-或者不合适:

int PDC_resize_screen(int nlines, int ncols)
{
    SMALL_RECT rect;
    COORD size, max;

    if (nlines < 2 || ncols < 2)
        return ERR;

    max = GetLargestConsoleWindowSize(pdc_con_out);

    rect.Left = rect.Top = 0;
    rect.Right = ncols - 1;

    if (rect.Right > max.X)
        rect.Right = max.X;

    rect.Bottom = nlines - 1;

    if (rect.Bottom > max.Y)
        rect.Bottom = max.Y;

    size.X = rect.Right + 1;
    size.Y = rect.Bottom + 1;

    _fit_console_window(pdc_con_out, &rect);
    SetConsoleScreenBufferSize(pdc_con_out, size);
    _fit_console_window(pdc_con_out, &rect);
    SetConsoleScreenBufferSize(pdc_con_out, size);
    SetConsoleActiveScreenBuffer(pdc_con_out);

    return OK;
}
/*使用给定参数调用SetConsoleWindowInfo,但适合它们
如果边框缩小到最大可能值,则矩形
必须至少适合半个大小的窗户*/
静态BOOL\u fit\u console\u窗口(把手向外,CONST SMALL\u RECT*RECT)
{   
小直跑;
短mx,我的;
if(SetConsoleWindowInfo(con_out、TRUE、rect))
返回TRUE;
run=*rect;
run.Right/=2;
run.Bottom/=2;
mx=run.Right;
我的=跑。下;
if(!SetConsoleWindowInfo(con_out、TRUE和run))
返回FALSE;
对于(run.Right=rect->Right;run.Right>=mx;run.Right--)
if(设置控制台windowinfo(con_out、TRUE和run))
打破
if(run.RightBottom;run.Bottom>=my;run.Bottom--)
if(设置控制台windowinfo(con_out、TRUE和run))
返回TRUE;
返回FALSE;
}
代码看起来…奇怪,除了做了两次相同的事情。参考的MSDN描述,矩形参数是一个in参数(未修改)。在参数之后,它将采用请求的大小,并尝试依次执行

  • 设置请求的大小,或
  • 设置请求的行,同时将列减小到初始大小的一半,或
  • 设置请求的列,同时将行减少到初始大小的一半

  • 它之所以这样做两次,可能是因为控制台API中存在一些不确定的行为。代码中的注释没有任何帮助。

    很抱歉,我不够清楚。问题是关于64位Windows上的PDcurses。我将编辑我的OP。如果您在Win64上,为什么不使用标准控制台函数而不是某些unix端口呢?
     /* Calls SetConsoleWindowInfo with the given parameters, but fits them  
        if a scoll bar shrinks the maximum possible value. The rectangle  
        must at least fit in a half-sized window. */
    
    static BOOL _fit_console_window(HANDLE con_out, CONST SMALL_RECT *rect)
    {   
        SMALL_RECT run;
        SHORT mx, my;
    
        if (SetConsoleWindowInfo(con_out, TRUE, rect))
            return TRUE;
    
        run = *rect;
        run.Right /= 2;
        run.Bottom /= 2;
    
        mx = run.Right;
        my = run.Bottom;
    
        if (!SetConsoleWindowInfo(con_out, TRUE, &run))
            return FALSE;
    
        for (run.Right = rect->Right; run.Right >= mx; run.Right--)
            if (SetConsoleWindowInfo(con_out, TRUE, &run))
                break;
    
        if (run.Right < mx)
            return FALSE;
    
        for (run.Bottom = rect->Bottom; run.Bottom >= my; run.Bottom--)
            if (SetConsoleWindowInfo(con_out, TRUE, &run))
                return TRUE;
    
        return FALSE;
    }