MessageBox text centring

    This site uses cookies. By continuing to browse this site, you are agreeing to our Cookie Policy.

    • MessageBox text centring

      The text centring for the MessageBox doesn't appear to work on my system, in both the Teapot Wars example game, and the game I'm working on myself.

      Source Code

      1. RECT rc;
      2. SetRect( &rc, 0,0,0,0);
      3. m_UI.CalcTextRect( msg.c_str(), m_UI.GetDefaultElement(DXUT_CONTROL_STATIC,0), &rc );
      4. int msgWidth = rc.right - rc.left;
      5. int msgHeight = rc.bottom - rc.top;


      msgWidth and msgHeight both come out as 0 (because rc stays at 0, 0, 0, 0), so the text is just placed starting at the centre of the message box, and spills out over its boundaries. Does this happen for everyone or is it something to do with my DirectX? Either way, I'm not very familiar with DirectX so I have no idea how to fix it. Any ideas why this might be happening?
    • I remember this working at some point but I haven't looked at it in quite a while.

      Sadly, CalcTextRect() is a DXUT function, so we don't have control over it. My best guess is that something broke with the switch to DirectX 11. Have you tested it in DX9? Also, CalcTextRect() returns an HRESULT. What's the value of that HRESULT? It might give you a clue to what's wrong.

      Either way, your best option is probably to write your own version of this function.

      -Rez