HWND
(W32) are created inside Widget::createHandle method using the CreateWindowEx
(W32) routine. But createHandle
is privated, you can't use it (although you can override it), the only one that calls this method is Widget::create. Its main task is to setup the Widget::m_handle member and to do the common Win32 subclassing: m_baseWndProc = (WNDPROC) SetWindowLongPtr(m_handle, GWLP_WNDPROC, (LONG_PTR)getGlobalWndProc());
Frame frame(...); { Button myButton("OK", &frame); // the HWND is created ... } // the Button's destructor calls DestroyWindow ... // at this point myButton (and its HWND) doesn't exist anymore
CreateWindowEx
(W32) call, you can override Widget::createHandle method.Remember that you must to call Widget::create inside the constructor of your own class, and give WidgetClassName::None as className in Widget's constructor.
Here is an example that shows you how to override createHandle:
class MyWidgetClass : public WidgetClass { public: // This returns the name of your class for the Win32's API static MyWidgetClass getClassName() { return MyWidgetClass("Vaca.MyWidgetClass"); } }; class MyWidget : public Register<MyWidgetClass> , public Widget { public: MyWidget(Widget* parent) : Widget(WidgetClassName::None, parent, NoStyle) { create(MyWidgetClass::getClassName(), parent, ChildStyle); } protected: // customized call to CreateWindowEx virtual HWND createHandle(LPCTSTR className, Widget* parent, Style style) { return CreateWindowEx(style.extended, className, _T(""), style.regular, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, parent ? parent->getHandle(): (HWND)NULL, (HMENU)NULL, Application::getHandle(), reinterpret_cast<LPVOID>(this)); } };
The WebCam Example overrides the createHandle
method to use a HWND
(W32) created from other routine that is not CreateWindowEx
(W32).