Delphi Application.HintColor - delphi

In Delphi 2010 (don't know about other versions) Application.HintColor seems to have no effect when running on Windows 7. On XP it gives the desired color. Any workarounds for this?

HintColor is like some of the other *Color properties in the VCL in that if you are running a themed application on a themed OS, they may be ignored when painting the control. Hints are a little different, because for them it's Vista or above, not XP or above. You can see this if you look at THintWindow.Paint in Controls.pas - it specifically paints the Vista gradient background if it's Vista and if themes are enabled.
This is normally a good thing, because you want your application to fit the look-and-feel of the OS and the user's preferences.
If you really want to override this, you will need to:
Subclass THintWindow
Get your application to use this new hint class when showing hints
In this class, override the painting methods to draw as you wish
Create a new hint class descending from THintWindow somewhere (more on what to implement below.) To get the application to use your new class for hints, assign an event handler to TApplication.OnShowHint (the easiest way to do this is via a TApplicationEvents component on your main form) and change the HintInfo parameter's HintWindowClass field to be your new class.
In your new hint class, you will need to override Paint and NCPaint. NCPaint will paint the border, and you will want to paint a non-themed border (probably using DrawEdge.) Change Paint to fill in the background with your colour of choice, and then draw text using DrawText in the hint's rectangle with appropriate text wrapping and alignment flags. If you look at the VCL code closely you can see a couple of rectangle offsets hardcoded, and you probably want to mimic these to get the same rectangles in your code as the VCL uses.
You can make all sorts of interesting variations of hints using this technique. One I made recently changed the painting so it drew a bold caption and then had other information under that, for example.
Finally: why are you setting the colour? Is it to warn the user of something or provide some other feedback? If so, consider using more than the colour - you can change anything you want about a hint using this technique. Try painting a warning icon or using rich-formatted text instead. I'd recommend you try to keep to the general theme look, and code tweaks to the themed painting, not overriding it entirely, because unless there's a very good reason you should try to keep to the OS / look the user has chosen.

No, not directly. If you have the runtime themes enabled it will take the system color for the hint. (IOW, the hint will be 'themed'). It is like setting a color for a button with the themes enabled (given that you can do this).
However you can use other 'hint' engines. For example you can use TjvBallonHint and/or TjvDesktopAlert (perhaps in conjunction with TjvDesktopAlertStack) from JEDI's JVCL which is free. There are also other (free & paid) alternatives. Also, if you want you can implement your own hint window.
HTH

Turning the 'enable runtime themes' off makes it work.

In Delphi 2010, you have TCustomHint class. You can derive a new class from it which draws a new type of hint.
You can assign your new class to CustomHint property of your forms or any other controls, and Delphi will use your custom hint class for showing hint for that control.
You can check source code of TBalloonHint class which is a sample TCustomHint descendant in Controls.pas

Related

Show TEdit in FireMonkey has an error in it with red border

I'm working on a mobile application where the user needs to login.
The server is returning me if the e-mail is invalid, or subdomain or password and I want to focus the TEdit that has the error. Focus is easy but I would also like to mark the edit as invalid like many web applications do.
What is the best way to do this is a consistent way so it will look correct on both Android as iOS. Is something like this built-in? I'm using Delphi 10.1
Loki's suggestion is a possible solution.
A solution which takes advantage of FMX features would be to use a TGlowEffect for the red frame around the TEdit and then use a TPopup to create the hint.
the style it's just a nightmare in 99% of the case, so i strongly suggest to not touch it. i will instead put a Trectangle as the background of the Tedit, put the Tedit as Transparent (you already have this style ready in the stylelookup in the object inspector), and then simply set the stroke.color of the trectangle.
i m working also right now on a 100% native Tedit on ios/android/windows i guess i will finish this code in around 1 week.

Can I enlarge the menu font size in Delphi 2?

Everything I've found says I can't do this with Delphi 2's TMainMenu but if somebody here has managed it somehow, I'd really like to know the trick. I found code that changes the System menu font size but none that confines the change to only the application. Anyone here know how to do this or do I have to just accept Delphi 2's tiny menu font size that appears on today's large screen monitors? (Moving the app to an upgraded Delphi is not the answer I need ;-)
The only way to achieve per application custom menu fonts is with an owner drawn menu. Delphi 2 does not support owner drawn menu items directly in the VCL properties of a TMainMenu component. This support was introduced only in Delphi 4.
You could still implement an owner drawn menu, but it would involve implementing them using standard Windows API techniques, and handling the required messages on the forms which own the menus involved. It is not especially difficult but not as straightforward as the event based implementation available in Delphi 4 and later.
You can still use a TMainMenu to define your menus but in your application you would then need to programmatically set the owner draw flag on the menu items and handle the resulting messages appropriately. Doing this, you will need to handle all aspects of drawing the menu - you cannot simply set/change the font and leave the system to draw the menu items. You may also need to provide additional handling for any keyboard shortcuts you have set up.
If this is a viable approach then information on implementing owner drawn menus at the API level can be found here.

Delphi XE2 modern looking MainMenu

I am trying to modernize the look of our older Delphi 7 application now that we are using Delphi XE-2. I experimented with the TRibbon, and although I like it, it probably is not the correct solution since we currently use a TMainMenu and make many runtime changes to it - our users can modify the main menu. But the default Mainmenu looks old, especially compared to the image shown.
What I am trying to do is something very close to the attached image, especially with the background color, but I don't quite understand how this was done. Can anyone tell me if this example (the File/View/Insert section) uses a TMainMenu, or is it Buttons on a Toolbar ? If we require a customizable main menu, do you think the example shown is an option ?
This example image comes from DevExpress Print Sample library.
Edit : I am new here so I can't include the image. Here is the link :
http://www.devexpress.com/Products/VCL/ExPrintingSystem/gallery.xml
The second image, the green one that says "Print Preview".
You could use the TActionMainMenuBar but the simpler solution for you is to Use Vcl styles, pick a theme, modify the graphical properties of a MainMenu component and then use StyleHooks to force the style just for the MainMenu component without using it for the whole application.

Flyout window similar to "code parameters" in Delphi IDE

Delphi IDE's "code completion" feature includes a second flyout window with code parameters - the one on the right:
An interesting feature of that window is that it is automatically sized to fit the content. What parameters must be used to create a window like that, and how can the automatic sizing be achieved in Delphi (XE)?
I would call that a hint window. Sizing "automatically" is done by code, and not by parameters alone, unless those parameters are properties in components, and the components then take on the work of auto-sizing to fit the content. In fact, that's probably what you want.
You could do it all yourself in Raw Win32 API terms... But it's a lot of work. Sizing a window to fit text can be done, using a window without a border and with style WS_POPUP set, and by painting it all yourself, and using the DrawTextEx API which can return the size of the text, but the simpler approach would be to use a hint window component, some of which will let you size them based on the content inside them. Unless you have a real need to reinvent the wheel, there are lots of hint window components already written. Use one.
I have used, and can recommend the hint window components from TMS (commercial) and JEDI JVCL (free), and they can both do window hints much like the above. The TMS Html Hint and TMS Office hint components are both capable of result similar to the above.
If you need a free solution, TJvHintWindow, built into the JVCL doesn't have as much functionality as the TMS ones, but could be tweaked and modified with a little work, to do something much like the picture you've shown.

Change the color of the applications title bar

With Delphi 7 trying to change the color of the title bar of the software from the window theme. I have seen code which allows you to change ALL the title bars of all programs, but I am just wanting to change my program.
Anyone seen/done anything like this? Don't mind paying for a component if needed.
I believe Windows sends the WM_NCPAINT message to an application when it should paint the window frame including the title bar. The default behaviour is to fall back to the default Windows handler which draws the default frame. You could replace this, or re-paint the title-bar section right after.
This looks like a good example: http://delphi.about.com/od/adptips2006/qt/draw_captionbar.htm
The answer by Stijn is not fully complete, as the caption and border of the window will also be redrawn when it is (de-)activated. So in addition to WM_NCPAINT you will also need to handle WM_NCACTIVATE. Unfortunately this can not simply be replaced, as there is other code in the default message handler (apart from drawing code) that needs to be executed. But calling the default handler will in turn lead to the default caption and border being drawn first, which you would then need to draw over with your intended colour, resulting in flicker.
One way to work around this is to adjust the drawing region that the default message handler is called with. See "Drawing titlebar on XP with themes" for an example using Windows API calls that should easily translate to Delphi. Note that this deals only with the text in the caption bar, but the principle applies.
You might take a look at a skinning library. ExpressSkin by DevExpress is a good one.

Resources