{"id":363,"date":"2021-10-20T12:21:32","date_gmt":"2021-10-20T19:21:32","guid":{"rendered":"https:\/\/devblogs.microsoft.com\/math-in-office\/?p=363"},"modified":"2021-10-20T12:21:32","modified_gmt":"2021-10-20T19:21:32","slug":"richedit-place-holder","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/math-in-office\/richedit-place-holder\/","title":{"rendered":"RichEdit Place Holder"},"content":{"rendered":"<p>Sometimes you need a text box that cues the user to type something in, such as, \u201cStart a conversation\u201d. As soon as the user types something, the cue text vanishes, and the user sees what the user typed. If the user deletes all the text, the cue text reappears. Such a text box is called a <em>place-holder<\/em> control. The Microsoft 365 RichEdit has such a control. This post explains how to include it in your application.<\/p>\n<p>Send two messages to set up a place-holder control: 1) <a href=\"https:\/\/docs.microsoft.com\/en-us\/windows\/win32\/controls\/em-settextex\">EM_SETTEXTEX<\/a>\u200e to set the place-holder text, and 2) <a href=\"https:\/\/docs.microsoft.com\/en-us\/windows\/win32\/controls\/em-seteditstyleex\">EM_SETEDITSTYLEEX<\/a>\u200e to enable the place-holder functionality. For setting the text, write something like<\/p>\n<pre>    const WCHAR wszPlaceholder [] = L\"Start a conversation\";\r\n    SETTEXTEX settext = {ST_PLACEHOLDERTEXT, 1200};\r\n\r\n    SendMessage (hwndRE, EM_SETTEXTEX, (WPARAM)&amp;settext, (LPARAM)wszPlaceholder);\r\n<\/pre>\n<p>To enable the place-holder functionality, send EM_SETEDITSTYLEEX to an empty control by<\/p>\n<pre>    SendMessage (hwndRE, EM_SETEDITSTYLEEX, SES_EX_SHOWPLACEHOLDERONFOCUS,\r\n        SES_EX_SHOWPLACEHOLDERONFOCUS);\r\n<\/pre>\n<p>At this point, the place-holder text \u201cStart a conversation\u201d is displayed. The constants ST_PLACEHOLDERTEXT and SES_EX_SHOWPLACEHOLDERONFOCUS aren\u2019t documented on the web, so here they are<\/p>\n<pre>    #define SES_EX_SHOWPLACEHOLDERONFOCUS\u00a0\u00a0\u00a0\u00a0\u00a00x80000000\r\n    #define ST_PLACEHOLDERTEXT\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 0x0010\r\n<\/pre>\n<p>Internally, the place-holder functionality is implemented using two stories, one for the main text and one for the place-holder text. A story is a programming object that <em>stores<\/em> rich text. More about this kind of story in another post. Whenever the main text is empty, the place-holder story is displayed on screen. As soon as the user types something, the main story is displayed. The initial place-holder facility was added in 2005, but SES_EX_SHOWPLACEHOLDERONFOCUS functionality was added in 2018 and isn\u2019t in the Windows msftedit.dll. The XAML TextBox uses RichEdit and <a href=\"https:\/\/docs.microsoft.com\/en-us\/uwp\/api\/windows.ui.xaml.controls.textbox.placeholdertext?view=winrt-22000\">supports<\/a> place-holders.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Sometimes you need a text box that cues the user to type something in, such as, \u201cStart a conversation\u201d. As soon as the user types something, the cue text vanishes, and the user sees what the user typed. If the user deletes all the text, the cue text reappears. Such a text box is called [&hellip;]<\/p>\n","protected":false},"author":40611,"featured_media":55,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[],"class_list":["post-363","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-math-in-office"],"acf":[],"blog_post_summary":"<p>Sometimes you need a text box that cues the user to type something in, such as, \u201cStart a conversation\u201d. As soon as the user types something, the cue text vanishes, and the user sees what the user typed. If the user deletes all the text, the cue text reappears. Such a text box is called [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/math-in-office\/wp-json\/wp\/v2\/posts\/363","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/math-in-office\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/math-in-office\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/math-in-office\/wp-json\/wp\/v2\/users\/40611"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/math-in-office\/wp-json\/wp\/v2\/comments?post=363"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/math-in-office\/wp-json\/wp\/v2\/posts\/363\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/math-in-office\/wp-json\/wp\/v2\/media\/55"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/math-in-office\/wp-json\/wp\/v2\/media?parent=363"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/math-in-office\/wp-json\/wp\/v2\/categories?post=363"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/math-in-office\/wp-json\/wp\/v2\/tags?post=363"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}