Note that there are some explanatory texts on larger screens.

plurals
  1. POIf you add extra data space to a DialogBox class be accessed by GetWindowLongPtr, should you add DLGWINDOWEXTRA to access this extra space?
    primarykey
    data
    text
    <p>When creating a window class for use with a DialogBox you need to specify a value of <code>DLGWINDOWEXTRA</code> in the <code>cbWndExtra</code> member of the <code>WNDCLASS</code> struct for "the extra bytes the system requires for each dialog box." If you add your own additional data space to a DialogBox class which is to be accessed using <code>GetWindowLongPtr()</code>, should you add <code>DLGWINDOWEXTRA</code> to the offset in order to access your additional space?</p> <p>(I'll confess that I think I know the answer, and that way the code doesn't break. But, I want to make sure my reasons tally with the collective wisdom.)</p> <p>The major reason why Dialogs are being used with their own class (rather than the default) is to allow each class of Dialog to have its own Icon. Two separate items of extra data are also attached to each window.</p> <pre><code>... wndclass.cbWndExtra = DLGWINDOWEXTRA + EXTRASPACE; wndclass.lpfnWndProc = (WNDPROC) DefDlgProc; wndclass.hIcon = LoadIcon(hInstance, "ICON_MAIN"); wndclass.lpszClassName = WND_CLASS_VLIST_POPUP; wndclass.hIconSm = LoadImage(hInstance, "ICON_MAIN", IMAGE_ICON, 16, 16, LR_DEFAULTCOLOR); ... </code></pre> <p>Effectively the question is which is correct access to the additional user data I want to add over and above the system required dialog data:</p> <pre><code>GetWindowLongPtr(hWnd, 0 + DLGWINDOWEXTRA + SOMETHING_IN_EXTRASPACE); </code></pre> <p>or</p> <pre><code>GetWindowLongPtr(hWnd, 0 + SOMETHING_IN_EXTRASPACE); </code></pre> <p>?</p> <p><strong>NOTE:</strong> Late edit May-15-2009 by David L Morris: <em>removed the incorrect <code>GWLP_USERDATA</code> and replaced with 0</em>. The original question used <code>GWLP_USERDATA</code> in the call to <code>GetWindowLongPtr()</code> which is why the accepted answer mentions <code>GWLP_USERDATA</code>. The examples above were originally written:</p> <pre><code>GetWindowLongPtr(hWnd, GWLP_USERDATA + DLGWINDOWEXTRA + SOMETHING_IN_EXTRASPACE); </code></pre> <p>and</p> <pre><code>GetWindowLongPtr(hWnd, GWLP_USERDATA + SOMETHING_IN_EXTRASPACE); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload