title: Print text and images in C++ (WinAPI or QT)
body: <p>In a basic program, I need to know how to make a text display widget and image display that can both be changed to different strings and images on command. These will display on a basic GUI.</p>
  
  <p>Any specific help would be tremendously appreciated as I have been stuck on this for more than 10 weeks! Asking online here is my last resort.</p>
  
  <p>I am making a basic program that asks questions (which is my text I want to print) and images for the questions come up underneath it. I have successfully made this program in a console command window (the code I will share below) but this of course meant no images could be displayed, so I am having to remake it in a GUI that supports images.</p>
  
  <p>This is my first project ever done in C++, and only know the basics (the full extent of my limited knowledge got me through making that console command window program without help).</p>
  
  <p>I first used WinAPI as it came with my computer in microsoft visual studio, and tried many different suggestions by other's similar questions already answered, but always either had one of two problems; 1. The code they supplied had many errors of which most read "_ is undefined" or wasn't imported properly, or 2. created basic text successfully but didn't specify how to change it after it had been created (I have had no successful image prints so far). I have tried 3 question/answers from cplusplus.com and 3 from stack overflow (links will be below), and all of them have had these 2 problems that are created from my lack of C++ bug fixing skills.</p>
  
  <p>Suggestions using WinAPI would be prefferred over QT as I have no idea what I am doing in Qt and get double digit numbers worth of errors when I import code (even though I import the correct directories), whereas WinAPI doesn't get importing errors.</p>
  
  <p>Code for command console program:</p>
  
  <pre><code>//G-Learning
  //@author: James Monk
  //@completed: 7/6/16
  //@version 1.0
  
  //These are the libraries (external files) to include at the start.
  #include &lt;cstdio&gt;
  #include &lt;windows.h&gt;
  #include &lt;iostream&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;time.h&gt;
  #include &lt;string&gt;
  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 &gt;&gt; userInputDummy;
      menuSelection = 0;
  }
  
  void start() {
      printf("\nThe questions will now start, good luck!\n\n");
      while (questionsLeft &gt; 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 &gt;&gt; userInput;
  
          if (userInput == questionAnswer[questionImagePicked]) {
              printf("\nCorrect!\n\n");
              score++;
          }
          else {
              printf("\nIncorrect answer.\n\n");
          }
          questionsLeft--;
  
          if (questionsLeft &gt; 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 &gt;&gt; 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
  </code></pre>
  
  <p>Code for my best working WinAPI iteration (can print text, but not again on command; also without image functionality. Would like to know how to improve this one!):</p>
  
  <pre><code>//These are the libraries (external files) to include at the start.
  #include &lt;cstdio&gt;
  #include &lt;windows.h&gt;
  #include &lt;iostream&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;time.h&gt;
  #include &lt;string&gt;
  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, &amp;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, &amp;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(&amp;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(&amp;msg, NULL, 0, 0) &gt; 0)
      {
          TranslateMessage(&amp;msg);
          DispatchMessage(&amp;msg);
          if (VK_ESCAPE == msg.wParam)
              break;
      }
      return 0;
  }
  </code></pre>
  
  <p>I am limited to only 2 links, so to view the 3 cplusplus.com pages I tried and the 3 stack overflow pages I tried, the links to them are on a google document here:
  <a href="https://docs.google.com/document/d/1IX2hxzAVka3UmVkaAgv-gXv_cwwmP3FkTYQuFWrrqyE/edit?usp=sharing" rel="nofollow">https://docs.google.com/document/d/1IX2hxzAVka3UmVkaAgv-gXv_cwwmP3FkTYQuFWrrqyE/edit?usp=sharing</a></p>
  
  <p>How I installed QT into Microsoft Visual Studio:
  <a href="https://www.youtube.com/watch?v=P6Mg8FpFPS8" rel="nofollow">https://www.youtube.com/watch?v=P6Mg8FpFPS8</a></p>
  
  <p>Thank you for reading through my issue and even more in advance for helping!</p>