Assign a HWND to an OpenCV named window - opencv

I have a win32 child window handle from a win32 application and I want to draw my openCV stuff on that child window. Is there a way to set the HWND of an openCV named window. I only found a function cvGetWindowHandle to get the HWND of an already created named window, but not an equivalent one to set the HWND of a new named window.
Any pointers on how that could be done?
Thanks!

Related

Firemonkey TFrame - how to fire ancestor TFrame events?

I created a base TFrame class, eg TBasicFrame
There is one button called btnTest, which do a simple task
showmessage('test');
On another TForm or TFrame, I place this TBasicFrame on it. However, when I click this btnTest on this or TForm/TFrame which has an instance of TBasicFrame on it, the showmessage does not run.
What must I do to ensure that all code in the ancestor frame will execute? That means the showmessage('test') will run even when new instances of TBasicFrame is placed anywhere.
Any advice?
I think, you overrided this event by simple double click on button (on object of your Frame) in IDE. So you dont have original call event.
Check *.fmx files of TBasicFrame and TForm with object TBasicFrame.

Create a VCL Button Component with sound

I'm trying to create a custom VCL component that can have a custom sound played when clicked. The sound is accessed from a resource DLL.
Question is, the sound is played using Direct X, and for it to be created it need a valid window handle.
My naive initial test was to initialize the sound in the components constructor:
__fastcall TArrayBotButton::TArrayBotButton(TComponent* Owner)
: TBitBtn(Owner),
FSoundID("BUTTON_CLICK_1")
{
initABCoreLib();
HWND hWnd = Application->MainFormHandle;
mSound.Create(FSoundID.c_str(), hWnd);
}
but the above does not work, as the MainFormHandle at this point is NULL. Also, being a component, using the Application variable is probably not safe in the constructor(?).
Any pointers on where to initialize the sound?
Why not just use the button's own HWND instead? TBitBtn is a windowed control. Its HWND is not available in the constructor, but you can (and should) override the button's virtual CreateWnd() method to create the DirectX object, and override the virtual DestroyWnd() method to release it. This way you also account for window recreations during the button's lifetime.

What is the difference between Owner and Parent of a control?

I am bit curious about the two properties of a Delphi VCL control.
Each component has 2 properties as Owner and Parent at runtime. Can anyone help me to understand the difference between both? And how are they used by windows for displaying control or form?
Owner
Owner is a property introduced in TComponent, and Owner itself has type TComponent. The Owner is used primarily to manage the lifetime of designed components. That is, components that you place on the form designer (or indeed other design surfaces) and whose lifetime is managed entirely by the framework. The documentation says:
Indicates the component that is responsible for streaming and freeing this component.
When a form is created, the streaming framework parses the .dfm file and instantiates the components that are listed within. These components are typically created with Owner specified to be the form.
At the other end of a component's life is destruction. When a component is destroyed, it also destroys all of the components which it owns. Consider, for the sake of a concrete example, a TButton that sits on a TForm, placed there at design time. The streaming framework creates the button setting its Owner to be the form. The form, as a descendent of TComponent maintains a list of all the components that it owns. When the form is destroyed it walks over that list of owned components and destroys them. The button is destroyed in this manner.
There are many nuances to this:
Components don't need to be owned by the form. For instance, components created at run time are owned by whatever component you pass to the constructor.
Components need not have an owner, you can pass nil to the constructor. In this case, the programmer remains responsible for destroying the component.
Ownership can be changed during the lifetime of a component.
Because the streaming framework instantiates components, the constructor of TComponent is declared virtual:
constructor Create(AOwner: TComponent); virtual;
If you derived from a TComponent descendent, and you wish for that derived component to be placed on a design surface, then you must respect this virtual constructor. If you define a constructor in your TComponent descendent then it must override this virtual constructor.
It is worth pointing out that Win32 has a completely different concept of a window's owner, that should not be confused with the VCL concept of the same name. The Windows documentation says:
Owned Windows
An overlapped or pop-up window can be owned by another overlapped or
pop-up window. Being owned places several constraints on a window.
- An owned window is always above its owner in the z-order.
- The system automatically destroys an owned window when its owner is destroyed.
- An owned window is hidden when its owner is minimized.
Only an overlapped or pop-up window can be an owner window; a child
window cannot be an owner window.
In VCL terms, this concept is exposed by the PopupParent property. That property was introduced after Delphi 7 so will not be available to you. In Delphi 7, the framework sets the window owner, and gives no easy mechanism to override the framework's choice. If you do need to influence window ownership then you must override CreateParams and set Params.WndParent. Unfortunately, there are a number of problems with the VCL handling of ownership in Delphi 7 and it is sometimes necessary to grub around in these somewhat gory details.
To show how easy it is to get confused, the VCL documentation says:
WndParent: The window handle of the parent window. This is the same as the Handle property of the parent control.
This is simply wrong. For a top-level window, this is the owner rather than the parent.
Parent
Parent is a property defined in TControl and has type TWinControl. This property is used, broadly, to expose the Win32 concept of parent and child controls. The Windows documentation says:
A window can have a parent window. A window that has a parent is called a child window. The parent window provides the coordinate system used for positioning a child window. Having a parent window affects aspects of a window's appearance; for example, a child window is clipped so that no part of the child window can appear outside the borders of its parent window. A window that has no parent, or whose parent is the desktop window, is called a top-level window.
Essentially, the VCL Parent property maps directly onto the Win32 parent concept.
Note however, that Parent is defined in TControl. Now, TControl is not windowed, so a TControl is not a child control in the Win32 sense, because a Win32 window's children are themselves windows. So, a TControl with a defined Parent is a child in the VCL sense, known as a non-windowed child control. These non-windowed controls paint themselves as part of their parent's paint handlers. The canonical example of such a control is TLabel.
Note that when a windowed control, that is a TWinControl descendent, is destroyed, it also destroys all of its children.
A TWinControl descendent can enumerate its children using the ControlCount and Controls[] properties. These enumerate both windowed and non-windowed children.

Delphi: What is type of window appears after you click a ComboBox

There is a window appear after you click that triangle icon of ComboBox. This I know it's not just a panel like object because for example in the following picture it' out of main form.
What is its type and how can I create something like this?
It is a standard ListBox control that the ComboBox creates internally (its HWND is accessible via the CB_GETCOMBOBOXINFO message). It is implemented as a free-floating window (so it can appear outside the ComboBox's parent window), except when the Style property is set to csSimple, in which case the ListBox resides as a child within the ComboBox's client area instead.

Creating custom Hint window

I'm trying to find a way to use my 2nd form as a hint window for a component (for example a TLabel) in my 1st form.
At the moment, I'm exploring the use of THintWindow and HintWindowClass, but it is not possible to directly assign a TForm to HintWindowClass. Some examples I've seen so far use a TBitmap which is then drawn on the THintWindow.Canvas, which is not bad, but I'd still like to use some kind of integrated automatic mechanism.
Another solution that crossed my mind is to manually implement this functionality using OnMouseEnter, OnMouseMove and OnMouseLeave events of the said Tlabel.
If there actually is a way to "assign" a TForm to HintWindowClass, I'd like to ask if anyone can provide a code snippet illustrating this. Thanks.
THintWindow is a descendant of TCustomControl. TForm is not a descendant of either of those classes, so you cannot assign any TForm class to HintWindowClass. Hint windows need to descend from THintWindow. Anything you can put on a form you can also put on a THintWindow. You'll just have to instantiate it manually and assign its Parent property to make it appear.
The closest you can probably get to "visually" designing a hint window is to design a frame. Make your THintWindow descendant create an instance of the frame, and then override ActivateHint (and ActivateHintData, if you need the data) to forward the hint text and desired size to your frame.

Resources