How to get HWND of GLUT window?

Just wondering … is it possible to get the HWND of a GLUT window? … to say define your own fonts with wglUseFontBitmaps().

I know I can (and have) used Win32 rather than GLUT. But, is it possible to use GLUT to create window … and just retrieve handle to extend font specifiations? Seems like it should be possible.


This seems to work. Although it might be unorthodox. I placed the following code snippet in the glutIdleFunc(). This gives the OpenGL window time to be completely realized. If you call it before then, you get the shell window … rather than the OpenGL window. I printed the OpenGL window’s text and rectangle to be sure.

void IdleCb()
   static bool firstTime = true;
   if(firstTime == true)
      firstTime = false;
      HWND hwnd = GetForegroundWindow();
      char string[101];
      GetWindowText(hwnd, string, 100);
      std::cout << "Window text = " << string << std::endl;
      RECT rect;
      GetWindowRect(hwnd, &rect);
      std::cout << "Window = (" << rect.left << ","
                                << rect.right << ","
                                << rect.bottom << ","
                                << << ")


It sounds to me like you can probably forget about the HWND and just use the HDC returned from wglGetCurrentDC() to create fonts.


Yep. I’ve been more of a Linux developer over the years. I totally missed that. I must have pulled that from long ago and never revisted. Thanks!!!

Used to do this …

HDC deviceContext = GetDC(hWnd);
newFont = CreateFont(...);
SelectObject(deviceContext, newFont);

Now can just call wglGetCurrentDC without GetDC!

Can’t believe I’ve missed that for THIS LONG :{

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.