Why EM_SETMARGINS does not work under Windows 7?

I have a composite visual control, which consists of an editing window and a drop-down button. The drop-down button is not a window control and is drawn above the edit window. I limit the editing width to the following call:

SendMessage(Handle, EM_SETMARGINS, EC_RIGHTMARGIN, 
  (DropDownButtonWidth + 2) shl 16);

It works fine under Windows XP, but does not work under Windows 7. In the latter case, when the focused button redraws the overlap window and erases its image.

What would be the right way to limit the editing rectangle on both operating systems?

PS: I also tried a different approach:

  SendMessage(Handle, EM_GETRECT, 0, LongInt(@Loc));
  Loc.Bottom := ClientHeight + 1;  
  Loc.Right := ClientWidth - FButton.Width - 2;
  Loc.Top := 0;
  Loc.Left := 0;
  SendMessage(Handle, EM_SETRECTNP, 0, LongInt(@Loc));

But it does not work for Windows 7.

+3
2

.

, - , VCL, , VCL, , VCL ( Windows API ). () Windows, , , VCL, , .

, Windows API, VCL ( , , API , ).

VCL , API - .

, , , .

( Delphi) XP - , SP2 , .

EM_SETMARGINS , , , , TButtonEdit , ( , Windows 7).

, , , , . TCustomPickEdit - , fButton, , . .

:

  • 3 . -, , , , , , , , , :

  • . WndProc . WndProc , .

:

  procedure TCustomPickEdit.ConfigureButton;
  // 1. Apply margins when button settings are changed 
  begin
    fButton.Caption   := Button.Caption;
    fButton.Flat      := Button.Flat;
    fButton.Glyph     := Button.Glyph;
    fButton.NumGlyphs := Button.NumGlyphs;
    fButton.Visible   := Button.Visible;
    ApplyMargins;
  end;

  procedure TCustomPickEdit.CreateHandle;
  // 2. Apply margins when underlying window handle is created 
  begin
    inherited;
    ApplyMargins;
  end;

  procedure TCustomPickEdit.WndProc(var aMessage: TMessage);
  // 3. Adjust clipping rectangle for correct drawing
  // 4. Apply margins when font is changed
  var
    top: Integer;
  begin
    case aMessage.Msg of
      CN_CTLCOLORSTATIC,
      CN_CTLCOLOREDIT    : if Button.Visible then
                           begin
                             top := fButton.Top;
                             if ThemeServices.ThemesEnabled and Ctl3D then
                               Inc(top);

                             ExcludeClipRect(aMessage.WParam, fButton.Left,
                                                              top + 1,
                                                              fButton.Left + fButton.Width,
                                                              fButton.Height);
                           end;
    end;

    inherited;

    case aMessage.Msg of
      CM_FONTCHANGED : if NOT (csLoading in ComponentState) then
                         ApplyMargins;
    end;
  end;
+2

, , , EM_SETMARGINS. :

HIWORD , . , wParam EC_RIGHTMARGIN.

Rich Edit 3.0 : HIWORD EC_USEFONTINFO . , .

EC_USEFONTINFO, . , . , , .

, Rich Edit Controls Edit Boxes , , .

+1

Source: https://habr.com/ru/post/1775695/


All Articles