PRB: Edit Control Margins too Large in Windows 95

Last reviewed: January 9, 1996
Article ID: Q138419
The information in this article applies to:
  • Microsoft Win32 Software Development Kit (SDK) version 4.0

SYMPTOMS

After you change the font in an edit control in Windows 95, the left and right margins are unusually large.

CAUSE

When the edit control receives the WM_SETFONT message, it calculates the left and right margins based on the average character width of the new font. The control does not do this when it is created. This results in the margins changing drastically when the font is changed.

RESOLUTION

Get the margins of the edit control before sending the WM_SETFONT message, and then set the margins back to their original sizes. The following code fragment demonstrates how to do this:

{ DWORD dwMargins;

dwMargins = SendDlgItemMessage( hWnd,

                                 IDC_EDIT,
                                 EM_GETMARGINS,
                                 0,
                                 0);

SendDlgItemMessage( hWnd,
                     IDC_EDIT,
                     WM_SETFONT,
                     (WPARAM)<new font handle>,
                     0);

SendDlgItemMessage( hWnd,
                     IDC_EDIT,
                     EM_SETMARGINS,
                     EC_LEFTMARGIN | EC_RIGHTMARGIN,
                     MAKELPARAM(LOWORD(dwMargins), HIWORD(dwMargins)));

}

STATUS

This behavior is by design.


Additional reference words: 1.30 4.00 Windows 95
KBCategory: kbprg kbui kbprb kbcode
KBSubcategory: UsrCtl W32s


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: January 9, 1996
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.