0

I'm injecting a number of forms into an existing application using a dll.
I don't control the existing application, nor do I have source code for it.
(I doubt the source code exists any more).

I want to show a TextHint in a TEdit.
In the form designer this works, but in the application it doesn't.
I traced it to the fact that StyleServices (This used to be called ThemeServices (now deprecated)) is not enabled, disabling the TextHint.

Obviously I cannot enable styles for the application, all I have is a dll.
Is there a way to show the texthint?

I prefer to use a stock TEdit.

The dll is written in DX and the old application is written in D7.
BTW I don't care a hood about any additional styling/theming or the like. I just want the texthint to display.

Johan
  • 74,508
  • 24
  • 191
  • 319
  • When you say styles, you mean themes right? Not VCL styles, but Windows provided themes. You certainly can enable those in your DLL's forms. You need to use activation context to do so. – David Heffernan May 17 '16 at 12:03
  • I've seen this question: http://stackoverflow.com/questions/31549854/delphi-xe8-tedit-texthint-disappears-when-receiving-focus maybe the solution is somewhere along those lines. – Johan May 17 '16 at 12:04
  • I'm not sure I just want the texthint to display. This seems to be governed by `StyleServices` aka `ThemeServices`. – Johan May 17 '16 at 12:06
  • I found this: http://stackoverflow.com/questions/5132679/apply-windows-theme-to-office-com-add-in/5133222#5133222 Let me see if things blow up when I put this code in DLLMain. – Johan May 17 '16 at 12:13
  • Not DllMain. Don't do anything there. – David Heffernan May 17 '16 at 17:36
  • OK, I'll spawn a new thread and do it there. – Johan May 17 '16 at 20:22

1 Answers1

0

Is there a way to show the texthint?

Standard TextHint functionality in a stock TEdit is dependent on the EM_SETCUEBANNER message, which only works when Visual Styles are enabled:

Note To use this API, you must provide a manifest specifying Comclt32.dll version 6.0. For more information on manifests, see Enabling Visual Styles.

If Visual Styles are not enabled in the app you are injecting your code into, then the only way to do what you are asking for is to subclass the TEdit window and custom-draw it manually when its text is empty.

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
  • You can use an activation context to enable themes – David Heffernan May 17 '16 at 20:41
  • @DavidHeffernan: I'm not familiar with that, but reading up on it, I don't see how that helps. The DLL is being injected into another app to apply a TextHint to an existing Edit control, the DLL is not creating its own Edit control. An activation context applies to the calling thread only, and you can't subclass a window across threads to inject code into the Edit's thread. So the activation context of the Edit's thread can't be changed to force accepting the `EM_SETCUEBANNER` message if Visual Styles were not enabled when the Edit control was created. Unless you know a way to do it... – Remy Lebeau May 17 '16 at 21:22
  • Johan, as I read it, is creating the forms in question in the injected code – David Heffernan May 17 '16 at 21:40
  • Yes, I'm creating the forms on the fly. – Johan May 17 '16 at 21:57
  • @Johan: So the DLL is creating its own TForm with its own TEdit on it? It is not trying to modify a TEdit inside the app being injected into? In that case, the DLL can run its own thread to create and display its TForm, and use an activation context to enable Visual Styles for that thread, like David suggested. – Remy Lebeau May 17 '16 at 22:05
  • OK, must the TForm run in a thread separate from the rest of the app. I can do that. I start the thread, activate context, start form. – Johan May 17 '16 at 22:19