Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/70.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中创建类似PowerShell的多行文本框_C_Powershell_Textbox - Fatal编程技术网

如何在C中创建类似PowerShell的多行文本框

如何在C中创建类似PowerShell的多行文本框,c,powershell,textbox,C,Powershell,Textbox,在PowerShell中,您可以在类似于多行GUI的文本框中定义类或函数。但是这些事情实际上发生在控制台窗口中。它为您提供了多行文本编辑的完整控件。我只想在C/C++中的控制台中创建这种文本框。Win32 API是否有相应的过程/函数?有密码吗?或者任何图书馆?任何提示或线索都将不胜感激 谢谢。您可以使用以下包装: pragma once #include "SDL.h" #include "SDL_ttf.h" #include "SDLUtils.h" #include <string

在PowerShell中,您可以在类似于多行GUI的文本框中定义类或函数。但是这些事情实际上发生在控制台窗口中。它为您提供了多行文本编辑的完整控件。我只想在C/C++中的控制台中创建这种文本框。Win32 API是否有相应的过程/函数?有密码吗?或者任何图书馆?任何提示或线索都将不胜感激


谢谢。

您可以使用以下包装:

pragma once
#include "SDL.h"
#include "SDL_ttf.h"
#include "SDLUtils.h"
#include <string>
#include <vector>

class Textbox
{
public:
    Textbox(int w, int h, int xPos, int yPos);
    ~Textbox(void);
    void draw();
    void edit(string s);
private:
    TTF_Font *font;
    int width;
    int height;
    Point pos;
    SDL_Surface *textSurface;
    SDL_Color textColor;
    std::string str;
    int maxCharsPerLine;
    int currentLine;
    std::vector<std::string> lines; 
};
pragma一次
#包括“SDL.h”
#包括“SDL_ttf.h”
#包括“SDLUtils.h”
#包括
#包括
类文本框
{
公众:
文本框(intw、inth、intxpos、intypos);
~Textbox(无效);
无效抽取();
无效编辑(字符串s);
私人:
TTF_字体*字体;
整数宽度;
内部高度;
点位;
SDL_表面*文本表面;
SDL_颜色文本颜色;
std::字符串str;
int-maxCharsPerLine;
int电流线;
std::矢量线;
};
CPP

#include "Textbox.h"
#include <iostream>

using namespace std;

Textbox::Textbox(int w, int h, int xPos, int yPos)
{
    TTF_Init();
    font = TTF_OpenFont("DOTMATRI.ttf", 20);
    textColor.r = 255;
    textColor.g = 0;
    textColor.b = 0;

    width = w;
    height = h;

    pos.x = xPos;
    pos.y = yPos;

    int x, y;
    TTF_SizeText(font,"a",&x,&y);
    cout << "width: " << x << endl;
    cout << "height: " << y << endl;

    maxCharsPerLine = width / x;

    str = "";
    lines.push_back(str);
    currentLine = 0;
}

Textbox::~Textbox(void)
{
    SDL_FreeSurface(textSurface);
    TTF_CloseFont(font);
    TTF_Quit();
}

void Textbox::draw()
{
    SDL_Rect rect;
    rect.x = pos.x;
    rect.y = pos.y;
    rect.w = width;
    rect.h = height;

    SDL_FillRect(SDL_GetVideoSurface(), &rect, SDL_MapRGB(SDL_GetVideoSurface()->format, 100, 100, 0));


    for(int i = 0; i < lines.size(); i++)
    {
        textSurface = TTF_RenderText_Solid(font, lines[i].c_str(), textColor);
        applySurface(pos.x, pos.y, textSurface, SDL_GetVideoSurface());
        pos.y += 21;
    }

    pos.y = 200;
}

void Textbox::edit(string s)
#包括“Textbox.h”
#包括
使用名称空间std;
Textbox::Textbox(intw,inth,intxpos,intypos)
{
TTF_Init();
font=TTF_OpenFont(“dotmari.TTF”,20);
textColor.r=255;
textColor.g=0;
textColor.b=0;
宽度=w;
高度=h;
pos.x=xpo;
pos.y=yPos;
int x,y;
TTF_SizeText(字体“a”、“x”、“y”);

难道没有C/C++这样的东西吗?挑一个。@Freyr99:np。享受编码吧