title: C++ Finding Index for Font temporarily added to System Font Table with AddFontResource() to use in Console
body: <p>I am trying to temporarily install a font to use in the win32 console with  </p>
  
  <p><code>int AddFontResource(LPCTSTR lpszFilename);</code></p>
  
  <p>and</p>
  
  <p><code>BOOL WINAPI SetConsoleFont(HANDLE hOutput, DWORD fontIndex)</code></p>
  
  <p>I got hold of this function from <a href="http://blogs.microsoft.co.il/blogs/pavely/archive/2009/07/23/changing-console-fonts.aspx" rel="nofollow">this</a> site.</p>
  
  <p>Although both functions seem to work fine I have no idea how to find the added font index to use with <code>SetConsoleFont</code>. </p>
  
  <p><code>AddFontResource</code> returns no index value or key to the temporary font. </p>
  
  <p>Here is my relevant code:</p>
  
  <pre><code>#include "Level.h"
  #include "ConsoleFont.h" //acquired from above mentioned site
  
  #include &lt;Windows.h&gt;
  
   //-------------------------------------------------------------------------------
  
  void init();
  void cleanup();
  
  int main()
  {
     FileManager *pFileManager = new FileManager();     //unrelated
     Level *lvl1 = new Level("filename",pFileManager);  //unrelated
  
  
     ///TEMPORARY PLANNING
     // using add font resource. how can i get this fonts index value? 
     int err = AddFontResource(L"Files/gamefont.fnt");
     if (err == 0)
     {
         MessageBox(NULL,L"loading font failed",L"Error",0);
     }
     else
     {  
         wchar_t message[100];
         swprintf_s(message,100,L"AddFontResource returned: %d",err);
         MessageBox(NULL,LPTSTR(message),L"error",0);
     }
     SendMessage(HWND_BROADCAST, WM_FONTCHANGE,0,0); 
  
     //acquiring handle to current active screen buffer 
     HANDLE tempHandle = GetStdHandle(STD_OUTPUT_HANDLE);
     if (tempHandle == INVALID_HANDLE_VALUE)
     {
      MessageBox(NULL,L"Failed to aquire Screen Buffer handle",L"Error",0);
     }
  
         //I dont know what to set this to. this is the crux of the problem.
     DWORD  fontIndex = 1;
     if (FALSE == SetConsoleFont(tempHandle,fontIndex))
     {
         MessageBox(NULL,L"loading console font failed",L"Error",0);
     }
  
      //draws a house when in correct font
      std::cout&lt;&lt;"!!!!!!!!#\n"
           &lt;&lt;"!!!!!!!!!\n"
           &lt;&lt;"! !! !! !\n"
           &lt;&lt;"!!!!!!!!!\n"
           &lt;&lt;"! !! !! !\n"
           &lt;&lt;"!!!!!!!!!\n"
           &lt;&lt;"! !! !! !\n"
           &lt;&lt;"!!!!!!!!!\n"
           &lt;&lt;"! !! !! !#\n"
           &lt;&lt;"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"&lt;&lt;std::endl;
  
         ///PLANNING OVERS 
  
  
      bool quit = false;
      while(!quit)
      {
             //still to be implemented
      }
  
  
  
      err = RemoveFontResource(L"Files/gamefont.fnt");
      if (err==0)
      {
          MessageBox(NULL,L"removing font failed",L"Error",0);
      }
      return 0;
  }
  </code></pre>
  
  <p>I don't know how to go about finding my new font's index value or even if this is possible using my current method.</p>
  
  <p>If someone knows or has a better method please help me out.
  any help or hints are appreciated. It must possible to use a custom font in the win32 Console without fiddling with the registry. I'm sure of it :)</p>