nanogui: Length of Window extra bytes.


Previous by date: 18 Jan 2000 01:29:14 -0000 Re: Length of Window extra bytes., Greg Haerr
Next by date: 18 Jan 2000 01:29:14 -0000 Re: Length of Window extra bytes., Greg Haerr
Previous in thread: 18 Jan 2000 01:29:14 -0000 Re: Length of Window extra bytes., Greg Haerr
Next in thread: 18 Jan 2000 01:29:14 -0000 Re: Length of Window extra bytes., Greg Haerr

Subject: Re: Length of Window extra bytes.
From: Chris Johns ####@####.####
Date: 18 Jan 2000 01:29:14 -0000
Message-Id: <3883BF78.81E43A7A@acm.org>

Greg Haerr wrote:
> 
> : Oh. I assumed that the `lpParam' was just not implemented and was to be
> : implemented. What is the purpose of the `lpParam' parameter when
> : creating a window ?
> :
> 
> No, the lpParam parameter to CreateWindowEx is passed as a member
> of the CREATESTRUCT structure to the WM_CREATE message, as
> are all of parameters to CreateWindowEx.  It's only purpose is to provide
> a user-defined parameter from CreateWindowEx to the WM_CREATE
> handler.  It is not stored in the window structure.  The application must
> save it in window or class extra bytes if required later.
> 

Sure. I have no problem with this model. I am now wondering why the
lpParam to CreateWindowEx exists ?

> : I cannot use the WM_CREATE message as I do not yet know the relationship
> : between the C++ object and hwnd when my WndProc function is called
> : (assuming synchronous message sends).
> 
> That's OK.  When you do know the relationship, call
> 
>         SetWindowLong(hwnd, 0, objectptr);
> 
> Then it will be stored with the hwnd.
> 

I will use the create structure to handle this now I know it exists and
understand it.

> :
> : I have a single `WndProc' function for all windows created using a
> : window class created with the WindowClass class (blah, too many
> : classes). In my common WndProc function I need to obtain the object
> : pointer so I can call a virtual method `HandleMessage'. This is my per
> : window object WndProc function.
> 
> Yep, get it with a call to:
> 
>         GetWindowLong(hwnd, 0);
> 

Agreed. I would like the pointer to be at the end hidden from the user
which might also allocate bytes. They would own 0 to the length they
set.

> :
> : I see in the demo code the `HMENU' window create parameter is really an
> : `id' and it is used to handle different windows from within a common
> : WndProc function. I would use `id' how-ever is only an `int' and I
> : cannot assume the size of int is large enough for a pointer.
> 
> You're right.  The hMenu parm is used as an ID for child windows, and
> as a menu handle for top level windows.  The correct answer is where
> you started: use extra window bytes.  Remember, if the window class
> sets the cbWndExtra value non-zero, that many bytes will be allocated
> at CreateWindow time.  You can set/get the value anytime afterwards...
> 

It is the best solution as the C interface is not altered. I do need to
be able to get the length of the extra bytes. This allows me to place
the object pointer at the end of the extra bytes allowing the user to
allocate extra bytes they might need.

To make sure I understand this I will outline what I will do :

 In `class WindowClass' I add sizeof (class Window*) to 
 the extra bytes supplied by the user. The user of 
 `class Window' must use a window class created by 
 the WindowClass class.

 When creating a window fill in a CREATESTRUCT and pass in 
 the first parameter of the CreateWindowEx function.

 Filter the WM_CREATE and take the object pointer from
 the CREATESTRUCT and set in the extra bytes.

 Use the extra bytes to get the object pointer.

This makes the only change I need the macro I posted earlier plus the
code to set a long word.


-- 
 Chris Johns, ####@####.####

Previous by date: 18 Jan 2000 01:29:14 -0000 Re: Length of Window extra bytes., Greg Haerr
Next by date: 18 Jan 2000 01:29:14 -0000 Re: Length of Window extra bytes., Greg Haerr
Previous in thread: 18 Jan 2000 01:29:14 -0000 Re: Length of Window extra bytes., Greg Haerr
Next in thread: 18 Jan 2000 01:29:14 -0000 Re: Length of Window extra bytes., Greg Haerr


Powered by ezmlm-browse 0.20.