import std.c.windows.windows; import std.c.stdio; import std.string; char[] Test_string="You selected Test menu item"; char[] Hello_string="Hello, my friend"; char[] Goodbye_string="See you again, bye"; HINSTANCE hInstance; enum { IDM_TEST=1, IDM_HELLO, IDM_GOODBYE, IDM_EXIT } int doit() { hInstance = GetModuleHandleA(null); WNDCLASS wc; wc.lpszClassName = "DWndClass"; wc.style = CS_OWNDC | CS_HREDRAW | CS_VREDRAW; wc.lpfnWndProc = &WndProc; wc.hInstance = hInstance; wc.hIcon = LoadIconA(cast(HINSTANCE) null, IDI_APPLICATION); wc.hCursor = LoadCursorA(cast(HINSTANCE) null, IDC_CROSS); wc.hbrBackground = cast(HBRUSH) (COLOR_WINDOW + 1); wc.lpszMenuName = "TestMenu"; wc.cbClsExtra = wc.cbWndExtra = 0; RegisterClassA(&wc); HWND hWnd; char[] sClass="My class 0"; char[] sApp="My Application 0"; /+++++ hWnd = CreateWindowA("DWndClass", "Just a window", WS_THICKFRAME | WS_MAXIMIZEBOX | WS_MINIMIZEBOX | WS_SYSMENU | WS_VISIBLE, CW_USEDEFAULT, CW_USEDEFAULT, 400, 300, HWND_DESKTOP, cast(HMENU) null, hInstance, null); +++++/ hWnd = CreateWindowA(toStringz(sClass), toStringz(sApp), WS_THICKFRAME | WS_MAXIMIZEBOX | WS_MINIMIZEBOX | WS_SYSMENU | WS_VISIBLE, CW_USEDEFAULT, CW_USEDEFAULT, 400, 300, HWND_DESKTOP, cast(HMENU) null, hInstance, null); assert(hWnd); ShowWindow(hWnd,SW_SHOWNORMAL); UpdateWindow(hWnd); MSG msg; while (GetMessageA(&msg, cast(HWND) null, 0, 0)) { TranslateMessage(&msg); DispatchMessageA(&msg); } return 1; }//doit() /**********************************************************/ /* Note the similarity of this code to the console D startup * code in \dmd\src\phobos\dmain2.d * You'll also need a .def file with at least the following in it: * EXETYPE NT * SUBSYSTEM WINDOWS */ extern (C) void gc_init(); extern (C) void gc_term(); extern (C) void _minit(); extern (C) void _moduleCtor(); extern (C) void _moduleUnitTests(); extern (Windows) int WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { int result; // gc_init(); // initialize garbage collector // _minit(); // initialize module constructor table /* try { _moduleCtor(); // call module constructors _moduleUnitTests(); // run unit tests (optional) result = doit(); // insert user code here } */ /* catch (Object o) // catch any uncaught exceptions { MessageBoxA(null, cast(char *)o.toString(), "Error", MB_OK | MB_ICONEXCLAMATION); result = 0; // failed } */ // gc_term(); // run finalizers; terminate garbage collector return result; } extern(Windows) { void DestroyWindow(HANDLE); } extern(Windows) int WndProc(HWND hWnd, uint uMsg, WPARAM wParam, LPARAM lParam) { switch(uMsg) { case WM_DESTROY: PostQuitMessage(cast(int) null); break; case WM_COMMAND: switch (LOWORD(wParam)) { case IDM_TEST: MessageBoxA(cast(HANDLE) null,"Test string","Menu test",MB_OK); case IDM_HELLO: MessageBoxA(cast(HANDLE) null,"Hello in D","Menu test",MB_OK); break; case IDM_GOODBYE: MessageBoxA(cast(HANDLE) null,"Goodbye in D","Menu test", MB_OK); break; default: DestroyWindow(hWnd); }//switch menu selection break; default: return DefWindowProcA(hWnd,uMsg,wParam,lParam); }//switch msg return 0; }//WndProc()