Thread: MessageBox-a-like

  1. #1
    Registered /usr
    Join Date
    Aug 2001
    Newport, South Wales, UK



    I'm trying to create a function that generates a dialog containing a prompt and an edit box that, much like MessageBox, is sized proportionally to the prompt.

    I've been using GetTextExtentPoint32, but that always gives me a width that's nearly twice the size of the actual prompt. Of course, it's being used at the point of creation of the window, so I'm having to get the desktop's DC and do it there. The desktop DC for some reason doesn't seem to have the standard dialog font as its default font, so I'm assuming it's getting this massive value through its use of the standard System font.

    I suppose it could be done in WM_INITDIALOG, but that would be more complicated as I would have to retrieve the caption text, resize all of the controls, etc.

    Is there a better way?

  2. #2
    Registered User
    Join Date
    Sep 2003
    Well why not. At least Wine code is doing it.

        /* Get the text size */
        GetClientRect(GetDlgItem(hwnd, MSGBOX_IDTEXT), &rect); = rect.left = rect.bottom = 0;
        DrawTextA( hdc, lpszText, -1, &rect,
        /* Min text width corresponds to space for the buttons */
        tleft = 2 * ileft + iwidth;
        twidth = max((bw + bspace) * buttons + bspace - tleft, rect.right);
        theight = rect.bottom;
    And after that they are calling SetWindowPos() for the buttons.
        /* Position the buttons */
        bpos = (wwidth - (bw + bspace) * buttons + bspace) / 2;
        for (buttons = i = 0; i < 7; i++) {
           /* some arithmetic to get the right order for YesNoCancel windows */
           hItem = GetDlgItem(hwnd, (i + 5) % 7 + 1);
           if (GetWindowLongA(hItem, GWL_STYLE) & WS_VISIBLE) {
              if (buttons++ == ((lpmb->dwStyle & MB_DEFMASK) >> 8)) {
                 SendMessageA( hItem, BM_SETSTYLE, BS_DEFPUSHBUTTON, TRUE );
              SetWindowPos(hItem, 0, bpos, tiheight, bw, bh,
              bpos += bw + bspace;
    In this code you can see some Wine internals, but you should be
    able to change it to your own data structs.

    And all of the above is done at WM_INITDIALOG.

    Last edited by Delf; 10-01-2003 at 04:26 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Delete files that are used
    By Yuri in forum C++ Programming
    Replies: 8
    Last Post: 10-18-2005, 01:48 PM
  2. problem with A simple modeless messagebox
    By hanhao in forum C++ Programming
    Replies: 8
    Last Post: 07-05-2005, 11:18 PM
  3. Forcing MessageBox to be non-concurrent?
    By JasonD in forum Windows Programming
    Replies: 17
    Last Post: 12-10-2003, 03:16 PM
  4. EnterCriticalSection and MessageBox
    By novacain in forum Windows Programming
    Replies: 13
    Last Post: 01-30-2003, 08:48 AM
  5. double in a MessageBox
    By Robert602 in forum Windows Programming
    Replies: 3
    Last Post: 12-17-2001, 03:10 PM