Class methods in D?
Sean Cavanaugh
WorksOnMyMachine at gmail.com
Thu May 3 23:09:34 PDT 2012
On 5/3/2012 1:32 PM, Simon wrote:
> On 03/05/2012 18:21, Mehrdad wrote:
>> In Windows, you need to register a "window class" before you can
>> actually create an instance of it.
>
> If you are mucking about on 'doze you might find my dubious port of the
> ATL window classes relevant:
>
> http://www.sstk.co.uk/atlWinD.php
>
> That does all that tedious registering of windows classes etc.
> I used a static class member IIRC.
>
> I've ripped this off of MS so use at your own risk. ;)
>
Heh, I've got a miniature (probably 20-30% complete) version of the WTL
ported to D here, but without any ATL aside from the parts of CWindow.
The WTL uses the curiously recurring template design which also works in
D, so a window class is something like this in D:
class GameWindow : CWindowUserBase!(CWindow, GameWindow)
{
bool isFullscreen;
bool isResizing;
bool suppressRendering;
bool allowCapture;
wGameMessageLoop messageLoop;
GameScene gameScene;
RenderDevice renderDevice;
DeviceContext immediateContext;
SwapChain swapChain;
Tid renderingThread;
mixin DECLARE_WND_CLASS!("wWindowClass", CS_HREDRAW | CS_VREDRAW |
CS_DBLCLKS, COLOR_WINDOWFRAME);
static DWORD GetWndStyle(DWORD InStyle)
{
return InStyle | WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN |
WS_CLIPSIBLINGS;
}
static DWORD GetWndExStyle(DWORD InStyleEx)
{
return InStyleEx | WS_EX_APPWINDOW | WS_EX_WINDOWEDGE;
}
static string GetWndCaption()
{
return "";
}
/// lots of code deleted
mixin(HOOK_MSG_WM_DESTROY!(OnDestroy));
mixin(HOOK_MSG_WM_MOVE!(OnMove));
mixin(HOOK_MSG_WM_SIZE!(OnSize));
mixin REGISTER_MESSAGE_MAP!(
BIND_MSG_WM_DESTROY!(OnDestroy),
BIND_MSG_WM_MOVE!(OnMove),
BIND_MSG_WM_SIZE!(OnSize));
mixin MESSAGE_HANDLER!();
}
So the answer to the OP's question is, make the class stuff static and
use mixins for the functions so the scope works out.
More information about the Digitalmars-d
mailing list