C++ 用C+打印文本和图像+;(WinAPI或QT)

C++ 用C+打印文本和图像+;(WinAPI或QT),c++,image,qt,text,C++,Image,Qt,Text,在一个基本程序中,我需要知道如何制作一个文本显示小部件和图像显示,它们都可以通过命令更改为不同的字符串和图像。这些将显示在基本GUI上 任何具体的帮助都将不胜感激,因为我已经坚持了10多个星期了!在这里在线询问是我最后的选择 我正在制作一个基本的程序,用来提问(这是我想要打印的文本),并在下面显示问题的图像。我已经在控制台命令窗口中成功地制作了这个程序(下面我将分享代码),但这当然意味着无法显示图像,因此我必须在支持图像的GUI中重新制作它 这是我在C++中做的第一个项目,只知道基本知识(我的有

在一个基本程序中,我需要知道如何制作一个文本显示小部件和图像显示,它们都可以通过命令更改为不同的字符串和图像。这些将显示在基本GUI上

任何具体的帮助都将不胜感激,因为我已经坚持了10多个星期了!在这里在线询问是我最后的选择

我正在制作一个基本的程序,用来提问(这是我想要打印的文本),并在下面显示问题的图像。我已经在控制台命令窗口中成功地制作了这个程序(下面我将分享代码),但这当然意味着无法显示图像,因此我必须在支持图像的GUI中重新制作它

<>这是我在C++中做的第一个项目,只知道基本知识(我的有限知识的全部程度让我在没有帮助的情况下制作了控制台命令窗口程序)。 我第一次使用WinAPI是因为它是在microsoft visual studio中与我的计算机一起使用的,我尝试了许多不同的建议,其他人的类似问题已经回答了,但总是有两个问题之一;1.他们提供的代码有许多错误,其中大多数读取“u未定义”或未正确导入,或2。已成功创建基本文本,但未指定创建后如何更改它(到目前为止,我还没有成功打印图像)。我已经尝试了3个来自CPLUS PLUS的问题和答案,3个来自堆栈溢出(下面将是链接),并且它们都有2个问题,这些问题是由于我没有C++的bug修复技巧而造成的。 使用WinAPI的建议会在QT上预先查询,因为我不知道自己在QT中做什么,并且在导入代码时(即使导入了正确的目录),会出现两位数的错误,而WinAPI不会出现导入错误

命令控制台程序的代码:

//G-Learning
//@author: James Monk
//@completed: 7/6/16
//@version 1.0

//These are the libraries (external files) to include at the start.
#include <cstdio>
#include <windows.h>
#include <iostream>
#include <stdlib.h>
#include <time.h>
#include <string>
using namespace std;

//Defining the [global] variables that will be used throughout the program

int running = 1;
int menuSelection;
int questionsLeft = 5;
int questionTextPicked;
int questionImagePicked;
int questionRandomised;
int score = 0;
int userInput;
int userInputDummy;

string stringPointer;
int intPointer;

string questionText[10] = {
    "Would this most likely be, (1) an enemy (2) a player?\n",
    "Is this (1) how many hearts the player has inside their body, or (2) a number of lives the player has?\n", 
    "Is this (1) a health bar, or (2) a set of red lights?\n",
    "Is this (1) a money counter, or (2) a yellow ball counter?\n",
    "Would this be a good object to touch with your character? (1) no or (2) yes?\n",
    "What would this object likely have in it? (1) rewards, or (2) punishments\n", 
    "What does 'Game Over' mean? (1) your session has ended, or (2) the game is no longer playable\n", 
    "What would an icon like this likely be for? (1) show wheels, or (2) options\n", 
    "In a racing game, what would this be for? (1) health bar, or (2) fuel tank meter\n", 
    "What would this button likely do? (1) exit or cancel, or (2) mark a spot with an x\n" };

//Defining what happens with the different functions
void introduction() {
    printf("\nG-Learning is a program built to teach people who know little about games the basic features of them. \n\n\
Questions will be asked, and you will need to answer them by choosing the correct answer.\n\
You will need to press 1, 2, or 3 followed by enter to choose.\n\n\
Press any number key followed by enter to return to the main menu.\n\n");
    cin >> userInputDummy;
    menuSelection = 0;
}

void start() {
    printf("\nThe questions will now start, good luck!\n\n");
    while (questionsLeft > 0) {
        questionTextPicked = (rand() % 10);
        if (questionTextPicked == 0) {
            questionRandomised = (rand() % 4);
            questionImagePicked = (7 + questionRandomised);
        } 
        else if (questionTextPicked == 4) {
            questionRandomised = (rand() % 3);
            questionImagePicked = (11 + questionRandomised);
        }
        else {
            questionImagePicked = questionTextPicked;
        }
        printf("after calculations, questionTextPicked is %d, questionRandomised is %d, and questionImagePicked is %d\n\n", questionTextPicked, questionRandomised, questionImagePicked);

        //answering questions should be here
        stringPointer = questionText[questionTextPicked];
        intPointer = questionAnswer[questionImagePicked];

        printf("answer is %d\n\n", intPointer);
        printf("%s\n", stringPointer, intPointer);
        printf("answer is %d\n\n", intPointer);
        cin >> userInput;

        if (userInput == questionAnswer[questionImagePicked]) {
            printf("\nCorrect!\n\n");
            score++;
        }
        else {
            printf("\nIncorrect answer.\n\n");
        }
        questionsLeft--;

        if (questionsLeft > 0) {
            printf("%d questions to go!\n\n", questionsLeft);
        }

        if (questionsLeft == 0) {
            printf("All questions have been answered, you scored %d/5.\n\nReturning you to the main menu\n\n", score);
            score = 0;
        }
    } //end of start's while loop
    menuSelection = 0;
} //end of start's function

void exit() {
    menuSelection = 0;
    running = 0;
}

//||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||

    //Main function, where everything starts
    int main(int argc, char ** argv) {
        while (running == 1) {
            //Welcoming the user to the program, and asking them what they want to do (starts functions)
            printf("welcome to G-Learning! Press a key to get started.\n1: Instructions\n2: Start\n3: Exit\n\n");
            questionsLeft = 5; //Resetting this so that the start function can begin again
            cin >> menuSelection;

            if (menuSelection == 1) {
                introduction();
            }
            else if (menuSelection == 2) {
                start();
            }
            else if (menuSelection == 3) {
                exit();
            }
            else {
                printf("Invalid input, please use the 1, 2, or 3 key.");
            }
        }
        return 0;
        return EXIT_SUCCESS;
    } //end of main function
//G-Learning
//@作者:詹姆斯·蒙克
//@完成日期:2016年7月6日
//@版本1.0
//这些是要在开始时包含的库(外部文件)。
#包括
#包括
#包括
#包括
#包括
#包括
使用名称空间std;
//定义将在整个程序中使用的[全局]变量
int运行=1;
int菜单选择;
int-questionsLeft=5;
整数问题;
整数问题;
随机分组;
智力得分=0;
int用户输入;
int userInputDummy;
字符串指针;
int指针;
字符串问题文本[10]={
“这很可能是(1)敌人(2)玩家吗?\n”,
“这是(1)玩家体内有多少颗心脏,还是(2)玩家有多少条生命?\n”,
“这是(1)一个健康酒吧还是(2)一组红灯?\n”,
“这是(1)一个货币计数器还是(2)一个黄色的球形计数器?\n”,
“这是接触角色的好对象吗?(1)否还是(2)是?\n”,
“此对象可能包含哪些内容?(1)奖励或(2)惩罚\n”,
“游戏结束”是什么意思?(1)您的会话已结束,或(2)游戏不再可玩\n”,
“像这样的图标可能用于什么?(1)显示控制盘,或(2)选项\n”,
“在赛车游戏中,这是为了什么?(1)健康栏,或(2)油箱表\n”,
此按钮可能会执行什么操作?(1)退出或取消,或(2)用x\n“}标记一个点;
//定义不同函数的作用
无效导言(){
printf(“\n学习是一个专门为教授对游戏知之甚少的人游戏的基本功能而设计的程序。\n\n\
将提出问题,您需要选择正确答案来回答这些问题。\n\
您需要按1、2或3,然后按enter键进行选择。\n\n\
按任意数字键,然后按enter键返回主菜单。\n\n“;
cin>>userInputDummy;
菜单选择=0;
}
void start(){
printf(“\n问题现在开始,祝你好运!\n\n”);
而(问题英尺>0){
questionTextPicked=(rand()%10);
如果(questionTextPicked==0){
问题随机=(rand()%4);
问题图像拾取=(7+随机问卷);
} 
否则如果(问题文本选择==4){
问题随机=(rand()%3);
问题图像拾取=(11+随机问卷);
}
否则{
questionImagePicked=questionTextPicked;
}
printf(“计算后,questionTextPicked为%d,QuestionRandomized为%d,questionImagePicked为%d\n\n”,questionTextPicked,QuestionRandomized,questionImagePicked);
//回答问题应该在这里
stringPointer=questionText[questionTextPicked];
intPointer=问题答案[questionImagePicked];
printf(“答案是%d\n\n”,intPointer);
printf(“%s\n”,stringPointer,intPointer);
printf(“答案是%d\n\n”,intPointer);
cin>>用户输入;
如果(userInput==questionAnswer[questionImagePicked]){
printf(“\n更正!\n\n”);
分数++;
}
否则{
printf(“\n回答不正确。\n\n”);
}
问题是;
如果(问题英尺>0){
printf(“%d个问题要处理!\n\n”,questionsLeft);
}
如果(问题left==0){
printf(“所有问题均已回答,得分为%d/5。\n\n请返回主菜单\n\n”,得分);
得分=0;
}
}//开始的while循环结束
菜单选择=0;
}//start函数的结束
无效退出(){
菜单选择=0;
运行=0;
}
//||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
//主功能,一切从这里开始
int main(int argc,字符**argv){
while(运行==1){
//欢迎用户加入程序,并询问他们想要做什么(启动功能)
printf(“欢迎来到G-Learning!按一个键开始。\n1:说明\n2:开始\n3:退出\n\n”);
//These are the libraries (external files) to include at the start.
#include <cstdio>
#include <windows.h>
#include <iostream>
#include <stdlib.h>
#include <time.h>
#include <string>
using namespace std;

int textHorizontal = 10;
int textVertical = 10;

//Variables used in making the program window
int numberInput;
char charictorInput;
string stringInput;
const char g_szClassName[] = "myWindowClass";

HINSTANCE hInstance;

// Function to get the size of the text
int GetTextSize(LPSTR a0)
{
    for (int iLoopCounter = 0; ; iLoopCounter++)
    {
        if (a0[iLoopCounter] == '\0')
            return iLoopCounter;
    }
}

LPSTR TextArray[] = {
    "Hello World"
};

LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
    switch (msg)
    {
    case WM_CLOSE:
        DestroyWindow(hwnd);
        break;

    case WM_DESTROY:
        PostQuitMessage(0);
        break;

    case WM_PAINT:
    {
        PAINTSTRUCT ps;
        HDC hdc = BeginPaint(hwnd, &ps);
        TextOut(hdc,
            // Location of the text
            textHorizontal,
            textVertical,
            // Text to print
            TextArray[0],
            // Size of the text, my function gets this for us
            GetTextSize(TextArray[0]));
        EndPaint(hwnd, &ps);
    }
    break;
    }
    return DefWindowProc(hwnd, msg, wParam, lParam);
}

//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

int WINAPI WinMain(HINSTANCE hInstanace, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
    WNDCLASSEX WindowClass;
    WindowClass.cbClsExtra = 0;
    WindowClass.cbWndExtra = 0;
    WindowClass.cbSize = sizeof(WNDCLASSEX);
    WindowClass.lpszClassName = "1";
    WindowClass.lpszMenuName = NULL;
    WindowClass.lpfnWndProc = WndProc;
    WindowClass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
    WindowClass.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
    WindowClass.hCursor = LoadCursor(NULL, IDC_ARROW);
    WindowClass.style = 0;
    WindowClass.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
    RegisterClassEx(&WindowClass);

    HWND hwnd = CreateWindowEx(WS_EX_CLIENTEDGE,
        "1",
        "G-Learning by James Monk",
        WS_OVERLAPPEDWINDOW,
        315, 115,
        1080, 720,
        NULL,
        NULL,
        hInstance,
        NULL);

    ShowWindow(hwnd, SW_SHOWNORMAL);

    MSG msg;

    while (GetMessage(&msg, NULL, 0, 0) > 0)
    {
        TranslateMessage(&msg);
        DispatchMessage(&msg);
        if (VK_ESCAPE == msg.wParam)
            break;
    }
    return 0;
}
HINSTANCE hInstance;
int WINAPI WinMain(HINSTANCE hInstanace...
CreateWindowEx(... hInstance ...)
WNDCLASSEX WindowClass = {0}
#include <cstdio>
#include <iostream>
#include <windows.h>
LPSTR TextArray[] = {
    "Hello World"
};
int GetTextSize(LPSTR a0)
{
    for (int iLoopCounter = 0; ; iLoopCounter++)
    {
        if (a0[iLoopCounter] == '\0')
            return iLoopCounter;
    }
}
#include <windows.h>
#include <string>
#include <vector>

LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
    static HWND combobox;
    static std::vector<std::string> vec = {
        "Would this most likely be, (1) an enemy (2) a player?\n",
        "Is this (1) how many hearts the player has inside their body, or (2) a number of lives the player has?\n",
        "Is this (1) a health bar, or (2) a set of red lights?\n",
        "Is this (1) a money counter, or (2) a yellow ball counter?\n",
        "Would this be a good object to touch with your character? (1) no or (2) yes?\n",
        "What would this object likely have in it? (1) rewards, or (2) punishments\n",
        "What does 'Game Over' mean? (1) your session has ended, or (2) the game is no longer playable\n",
        "What would an icon like this likely be for? (1) show wheels, or (2) options\n",
        "In a racing game, what would this be for? (1) health bar, or (2) fuel tank meter\n",
        "What would this button likely do? (1) exit or cancel, or (2) mark a spot with an x\n"
    };

    switch (msg)
    {
    case WM_CREATE:
        combobox = CreateWindow("ComboBox", 0, CBS_DROPDOWNLIST | CBS_HASSTRINGS | WS_CHILD | WS_OVERLAPPED | WS_VISIBLE, 0, 100, 700, 30, hwnd, HMENU(100), 0, 0);
        for (auto line : vec) SendMessage(combobox, CB_ADDSTRING, 0, LPARAM(line.c_str()));
        break;

    case WM_KEYDOWN:
        if (wParam == VK_ESCAPE)
            DestroyWindow(hwnd);
        break;

    case WM_COMMAND:
        if (HIWORD(wParam) == CBN_SELCHANGE)
            InvalidateRect(hwnd, NULL, TRUE);
        break;

    case WM_CLOSE:
        DestroyWindow(hwnd);
        break;

    case WM_DESTROY:
        PostQuitMessage(0);
        break;

    case WM_PAINT:
    {
        PAINTSTRUCT ps;
        HDC hdc = BeginPaint(hwnd, &ps);
        int sel = SendMessage(combobox, CB_GETCURSEL, 0, 0);
        if (sel < 0) sel = 0;
        TextOut(hdc, 0, 0, vec[sel].c_str(), vec[sel].size());
        EndPaint(hwnd, &ps);
        break;
    }

    }
    return DefWindowProc(hwnd, msg, wParam, lParam);
}

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
    WNDCLASSEX wcx = { 0 };
    wcx.cbSize = sizeof(WNDCLASSEX);
    wcx.lpszClassName = "ClassName";
    wcx.lpfnWndProc = WndProc;
    wcx.hIcon = LoadIcon(NULL, IDI_APPLICATION);
    wcx.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
    wcx.hCursor = LoadCursor(NULL, IDC_ARROW);
    wcx.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
    RegisterClassEx(&wcx);

    HWND hwnd = CreateWindowEx(0, wcx.lpszClassName, "G-Learning by James Monk", WS_VISIBLE|WS_OVERLAPPEDWINDOW, 0,0,800,600, NULL, NULL, hInstance, NULL);

    MSG msg;
    while (GetMessage(&msg, NULL, 0, 0) > 0)
    {
        TranslateMessage(&msg);
        DispatchMessage(&msg);
    }

    return 0;
}