Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I don't know if I'm in love with this answer, but here's a possibility using template argument deduction. <strong>NOTE</strong> I do not have my compiler on me, I'll double-check it tomorrow unless somebody else out there wants to give it a whirl.</p> <pre><code>class sharedWindowOpts { public: sharedWindowOpts() {}; // Commonly used options template &lt;class optType&gt; static optType&amp; at(int x, int y, optType&amp; opts) { opts.mX=x; opts.mY=y; return opts; }; template &lt;class optType&gt; static optType&amp; background(HBRUSH b, optType&amp; opts) { opts.mBackground=b; return opts; }; // etc... } class createWindowOpts : public sharedWindowOpts { public: createWindowOpts() : sharedwindowOpts() {}; // These can't be used with child windows, or aren't needed template &lt;class optType&gt; static optType&amp; menu(HMENU m, optType&amp; opts) { opts.mMenuOrId=m; return opts; }; template &lt;class optType&gt; static optType&amp; owner(HWND hwnd, optType&amp; opts) { opts.mParentOrOwner=hwnd; return opts; }; } </code></pre> <p>Then you would call CreateWindow like this:</p> <pre><code>CreateWindow( createWindowOpts::owner(hwnd, createWindowOpts::at(0, 100, // can use createWindowOpts because it doesn't hide sharedWindowsOpts::at createWindowOpts::menu(hmenu, createWindowOpts() ) ) ) ); </code></pre> <p>The obnoxious things about this, of course, are having to use the static method calling syntax and all the extra parentheses. If you replace the static member functions with non-member functions this can be eliminated. It does avoid the type-casting and the extra template classes, though.</p> <p><strong>Personally, I'd rather have the odd code in the library as with your method, than everywhere the library is being used like in mine.</strong></p>
 

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