Tag Archives: twincontrol

Preserve Internal State (/Window Handle) when Changing Parent or Style for an ActiveX Control – aka How To RecreateWnd “Properly” for TOleContainer ancestors

In any (VCL) Delphi application more stuff happens behind the scenes than you might be aware of.
As known, every (TWinControl descendant) control placed on a form (like TButton or TEdit) and even the (T)Form itself is actually a wrapper for a Windows screen object. Every such object is “defined” by something called Window Handle. You can use the Handle value to do stuff with the underlying Windows screen object like hide or show it or move around its parent (another Windows screen object) or change some of its properties.
Continue reading

Receive Windows Messages In Your Custom Delphi Class – NonWindowed Control/Object

Windows messages are a key ingredient in communication between Windows and (your) application and also in communication between (two) applications.

Even without your knowledge Windows messages are being posted and handled by forms in your application.

For example, when the user closes the form in your application, the WM_CLOSE message is sent to the window/form and the form gets closed (if you do not react programmatically).

For an application to receive a Window message, the application must provide a *window* a message will be sent to. In normal situation this window is the (main) form in your application. You write a procedure to handle a specific message, like WM_NCHitTest, and you are done.

BUT, what if you do NOT have a window to receive a message? What if you want to handle messages in your custom class derived from TObject?
Continue reading

Generic Solution to Coloring the Focused Entry Control in Delphi Applications

Coloring Focused Entry Control
Looking for the best approach to change the background color (and other properties) of the focused data entry control in a Delphi (VCL) application?

By (Windows) design, the control on a data entry form which has the input focus is not drawn (/highlighted) differently from other controls (i.e. those without the input focus). In case of the TEdit (or TMemo and alike) control, only the blinking insertion point is displayed.

To provide visually more attractive user-friendly interfaces for your Delphi applications, you could decide to change the background color (and maybe some other properties) of the currently selected control – the one that has the input focus. Of course, this would include restoring to the original background color when the focus shifts to another control.
Continue reading