Wiki Page Content

Differences between revisions 1 and 9 (spanning 8 versions)
Revision 1 as of 2010-01-11 06:48:54
Size: 732
Editor: SheenaSmith
Comment: create page, add content
Revision 9 as of 2013-07-06 08:38:15
Size: 1994
Comment: Corrected includes.
Deletions are marked like this. Additions are marked like this.
Line 3: Line 3:
||<tablewidth="100%" style="color: #FF0000;" :> DRAFT||
Line 6: Line 5:
Use this function to set the title of the window, in UTF-8 format. Use this function to set the title of a window.
Line 12: Line 11:
void SDL_SetWindowTitle(SDL_WindowID windowID,
                        const char*  title)
void SDL_SetWindowTitle(SDL_Window* window,
                        const char* title)
Line 17: Line 16:
||'''windowID'''||the type used to identify the window||
||'''title'''||the desired window title||
||'''window'''||the window to change||
||'''title'''||the desired window title in UTF-8 format||
Line 22: Line 21:
You can add your code example here // dynamically setting a window title

#include "SDL.h"
#include <string>

using std::string;

int main(int argc, char* argv[]){

  SDL_Init(SDL_INIT_VIDEO); // Init SDL2
  
  // Create a window.
  SDL_Window *window = SDL_CreateWindow(
    "This will surely be overwritten", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 320, 240, SDL_WINDOW_RESIZABLE
  );
  
  string titles[] = { // just for fun, let's make the title animate like a marquee and annoy users
    "t", "thi", "this w", "this win", "this windo", "this window's", "this window's ti", "this window's title",
    "chis window's title is", "chih window's title is ", "chih wandnw's title is ", "c h wandnw'g title is ",
    "c h a nw'g titln is ", "c h a n g i n ig ", "c h a n g i n g!", "",
    "c h a n g i n g!", "", "c h a n g i n g!", "c h a n g i n g!"
  };
  
  // Enter the main loop. Press any key or hit the x to exit.
  for(SDL_Event e; e.type!=SDL_QUIT&&e.type!=SDL_KEYDOWN; SDL_PollEvent(&e)){
    static int i = 0, t = 0;
    
    if(!(++t%9)){ // every 9th frame...
      SDL_SetWindowTitle(window, titles[i].c_str()); // loop through the
      if(++i >= sizeof(titles)/sizeof(string)) i = 0; // array of titles
    }
    
    SDL_Delay(10);
    
  }
  
  SDL_DestroyWindow(window);
  SDL_Quit();
  return 0;
  
}

SDL_SetWindowTitle

Use this function to set the title of a window.

Syntax

void SDL_SetWindowTitle(SDL_Window* window,
                        const char* title)

Function Parameters

window

the window to change

title

the desired window title in UTF-8 format

Code Examples

// dynamically setting a window title

#include "SDL.h"
#include <string>

using std::string;

int main(int argc, char* argv[]){

  SDL_Init(SDL_INIT_VIDEO); // Init SDL2
  
  // Create a window. 
  SDL_Window *window = SDL_CreateWindow(
    "This will surely be overwritten", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 320, 240, SDL_WINDOW_RESIZABLE
  );
  
  string titles[] = { // just for fun, let's make the title animate like a marquee and annoy users
    "t", "thi", "this w", "this win", "this windo", "this window's", "this window's ti", "this window's title",
    "chis window's title is", "chih window's title is ", "chih wandnw's title is ", "c  h wandnw'g title is ",
    "c  h  a  nw'g titln is ", "c  h  a  n  g  i  n ig ", "c  h  a  n  g  i  n  g!", "", 
    "c  h  a  n  g  i  n  g!", "", "c  h  a  n  g  i  n  g!", "c  h  a  n  g  i  n  g!"
  };
  
  // Enter the main loop. Press any key or hit the x to exit.
  for(SDL_Event e; e.type!=SDL_QUIT&&e.type!=SDL_KEYDOWN; SDL_PollEvent(&e)){ 
    static int i = 0, t = 0;
    
    if(!(++t%9)){ // every 9th frame...
      SDL_SetWindowTitle(window, titles[i].c_str());  // loop through the 
      if(++i >= sizeof(titles)/sizeof(string)) i = 0; // array of titles
    }
    
    SDL_Delay(10);
    
  }
  
  SDL_DestroyWindow(window);
  SDL_Quit();
  return 0;
  
}

Remarks

You can add useful comments here


CategoryAPI, CategoryVideo

None: SDL_SetWindowTitle (last edited 2014-12-12 21:22:50 by PhilippWiesemann)

Feedback
Please include your contact information if you'd like to receive a reply.
Submit