Defining a custom *constructor* (not initializer!)
Mehrdad
wfunction at hotmail.com
Fri May 11 06:33:54 PDT 2012
> OK, I understand what you are saying now.
>
> What about using NVI?
>
> class Window
> {
> protected void processMessage_impl(int message) // virtual
> call
> {}
> final public void processMessage(int message)
> {
> if(message == WM_CREATE)
> {
> // handle specially
> }
> else if(message == WM_DELETE)
> {
> // handle specially
> }
> else
> {
> processMessage_impl(int message);
> }
> }
> private HWND window;
> this()
> {
> window = CreateWindow(&processMessage); // or whatever
> mechanism, you get the idea
> }
> ~this()
> {
> DestroyWindow(window);
> }
> }
>
> -Steve
The trouble is that if you "handle these specially", then your
subclasses won't....
But your subclasses MUST still be able to handle these messages,
because they might need to do something special when the messages
are sent. (For example, you might need to calculate the size of
the window when WM_CREATE or WM_NCCREATE is sent. Or something
else... there are a ton of situations that can happen -- such as
MDI window creation, etc. -- that don't happen too often, but
happen often enough that you simply can't assume you can get by
without allowing them to handle the messages.)
More information about the Digitalmars-d
mailing list