在PowerShell中,您可以在多行GUI中定义类或函数,如文本框。但这些东西实际上发生在控制台窗口中。它为您提供多行文本编辑的完全控制。我只想在C / C ++中用控制台创建那种文本框。 Win32 API是否有针对它的过程/函数?任何代码?还是任何图书馆?任何暗示或领导都将非常感激。
感谢。
答案 0 :(得分:2)
您可以使用以下内容包装:
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;
};
<强> 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)
参考链接:Creating TextBox