2

Say, if I have a default EDIT common control in my MFC-based dialog window:

enter image description here

I'm looking for a way to add a small "X" (or delete) button inside of it (here's my Photoshop rendering of what I need):

enter image description here

Is there a way to do it by modifying the default edit control?

c00000fd
  • 20,994
  • 29
  • 177
  • 400
  • 1
    Is that button at the right side really part of the mentioned _EDIT common control_? You may use owner drawing to achieve what you want. – πάντα ῥεῖ Apr 20 '15 at 21:51
  • @πάνταῥεῖ: I was thinking of somehow using another common control, i.e. Button for that. The issue with owner drawing is... well, drawing everything by myself. That obviously involves visual styles and themes, etc. With an already defined button I could eliminate all that if I could somehow display it on top of the edit control, make Edit ctrl not draw where button is placed and limit the right-side edge of the Edit to right before the button. – c00000fd Apr 20 '15 at 22:05
  • 4
    [Insert buttons into an edit control](http://www.catch22.net/tuts/insert-buttons-edit-control) is basically, what you're looking for. In essence, you subclass a standard Edit control, and place a standard Button control in its non-client area. As long as you properly [subclass your control](https://msdn.microsoft.com/en-us/library/windows/desktop/bb773183.aspx) you should be good to go. – IInspectable Apr 20 '15 at 22:11
  • I'm afraid such thing like a UserControl combined from other control elements, isn't available natively for MFC, unless you're using OLE, COM (ATL) or such techniques IIRC. – πάντα ῥεῖ Apr 20 '15 at 22:12
  • @IInspectable: Thanks. That's what I was looking for. It's not as simple as I thought, but sounds like it's doable. – c00000fd Apr 20 '15 at 23:36

3 Answers3

3

Please consider using new class CMFCEditBrowseCtrl. It does have method CMFCEditBrowseCtrl::EnableBrowseButton() to do exactly what you need.

Andrew Komiagin
  • 6,446
  • 1
  • 13
  • 23
0

If I wanted more than one button, I would investigate alternatives:

  • See the CMFCEditBrowseCtrl class' code. Then decide if derive a class from it and extend; or else derive from CEdit, copy CMFCEditBrowseCtrl code and extend.

  • Case the edit is multi-line, I would investigate the methods CEdit::SetRect and CEdit::SetRectNP. Case it is single-line I would look to CEdit::SetMargins. Then implement normal buttons over the text area of the edit.

sergiol
  • 4,122
  • 4
  • 47
  • 81
0

Please refer this article for CMFCEditBrowseCtrl class..

https://www.codeproject.com/Articles/35722/MFC-Feature-Pack-CMFCEditBrowseCtrl

  • The additional contribution this provides to the existing answers is the link and ... – Yunnosch Sep 29 '20 at 09:22
  • A link to a solution is welcome, but please ensure your answer is useful without it: [add context around the link](//meta.stackexchange.com/a/8259) so your fellow users will have some idea what it is and why it’s there, then quote the most relevant part of the page you're linking to in case the target page is unavailable. [Answers that are little more than a link may be deleted.](/help/deleted-answers) – Yunnosch Sep 29 '20 at 09:22