views:

17

answers:

2

I'm using a CMFCLinkCtrl in my custom dialog that inherits from CDialog. The CMFCLinkCtrl is set dynamically using data that is set by the user in another part of the application, so I have to handle long urls.

Is there a way to have the link control truncate what is displayed in the dialog and add an ellipse to the end? Currently the control is wrapping to the next line when it is too long to fit in the dialog or sees the "//" in the http://.

+1  A: 

Static controls have an SS_ENDELLIPSIS style that does exactly what you want, but unfortunately this won't work with CMFCLinkCtrl which is derived from CButton. So you have two choices:

  1. Use a static control with the SS_ENDELLIPSIS style, but you'll have to set the text colour and font yourself, and handle click events and open the URL manually.

  2. Subclass CMFCLinkCtrl and add custom drawing code to add the ellipsis.

casablanca
I'll probably end up subclassing the CMFCLinkCtrl. However, is there a way to prevent the "//" from inserting a newline?
chris.nullptr
I guess the control is simply breaking the text into words and considers `/` as punctuation. If you're subclassing the control, you'll have full control over the drawing, so you shouldn't have this problem.
casablanca
A: 

I think you're out of luck. You'll have to do what casablanca said or without subclassing truncate the text yourself (calculate the font size and link control size) and set it using SetWindowText.

You can easily resize the control to contain the entire text using SizeToContent, but I don't think this works for you.

Nikola Smiljanić