今天偶尔关注了一下D语言。一直以来都在拿C++与C#,Java做比较,后两种对于程序员来说无疑是更顺手的,但
是效率上C++是最强的。D语言虽然刚刚萌芽,但是只看了他的简单介绍之后心里就很激动,“Great, just what I need
”。
介绍D语言的一个中文的Blog:http://blog.csdn.net/uframer/
D语言环境配置教程:http://www.cppblog.com/cpunion/archive/2005/11/02/892.html
D语言官方网站:http://www.digitalmars.com/d/index.html
D语言开源网站:http://www.dsource.org
D语言作者的网站:http://www.walterbright.com/
另外尝试了一下D语言win32编程,下面是一个最小的程序--创建一个窗口:
import std.c.windows.windows;
extern (Windows) BOOL DestroyWindow(HWND hWnd);
enum { PM_REMOVE = 0x0001 }
const LPSTR IDC_ARROW = cast(LPSTR)32512;
extern (C) void *memset(void *dest, int c, size_t count);
extern (Windows) BOOL FreeLibrary(HMODULE hModule);
HWND createWindow()
{
HINSTANCE moduleHandle = GetModuleHandleA(null);
assert(moduleHandle);
WNDCLASS wc;
wc.lpszClassName = "DWndClass";
wc.style = CS_OWNDC | CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc = &windowProc;
wc.hInstance = moduleHandle;
wc.hIcon = LoadIconA(cast(HINSTANCE)null, IDI_APPLICATION);
wc.hCursor = LoadCursorA(cast(HINSTANCE)null, IDC_ARROW);
wc.hbrBackground = cast(HBRUSH) (COLOR_WINDOW + 1);
wc.lpszMenuName = null;
wc.cbClsExtra = wc.cbWndExtra = 0;
assert(RegisterClassA(&wc));
RECT rect;
rect.left = 0; rect.top = 0; rect.right = 640; rect.bottom = 480;
AdjustWindowRect(&rect, WS_CAPTION | WS_MINIMIZEBOX | WS_SYSMENU | WS_VISIBLE, FALSE);
HWND result = CreateWindowA("DWndClass", "Just a window",
WS_CAPTION | WS_MINIMIZEBOX | WS_SYSMENU | WS_VISIBLE,
CW_USEDEFAULT, CW_USEDEFAULT,
rect.right - rect.left, rect.bottom - rect.top, HWND_DESKTOP,
cast(HMENU)null, moduleHandle, null);
assert(result);
return result;
}
extern (Windows) int windowProc(HWND hWnd, uint uMsg, WPARAM wParam, LPARAM lParam)
{
if (uMsg == WM_CLOSE || uMsg == WM_DESTROY)
{
PostQuitMessage(0);
return 0;
}
return DefWindowProcA(hWnd, uMsg, wParam, lParam);
}
bit doEvents(HWND wnd)
{
MSG msg;
while (PeekMessageA(&msg, null, 0, 0, PM_REMOVE))
{
if (WM_QUIT == msg.message) return false;
TranslateMessage(&msg);
DispatchMessageA(&msg);
}
Sleep(16);
return true;
}
int main()
{
HWND wnd = createWindow();
while (true)
{
if (!doEvents(wnd))
break;
}
DestroyWindow(wnd);
return 0;
}
是效率上C++是最强的。D语言虽然刚刚萌芽,但是只看了他的简单介绍之后心里就很激动,“Great, just what I need
”。
介绍D语言的一个中文的Blog:http://blog.csdn.net/uframer/
D语言环境配置教程:http://www.cppblog.com/cpunion/archive/2005/11/02/892.html
D语言官方网站:http://www.digitalmars.com/d/index.html
D语言开源网站:http://www.dsource.org
D语言作者的网站:http://www.walterbright.com/
另外尝试了一下D语言win32编程,下面是一个最小的程序--创建一个窗口:
import std.c.windows.windows;
extern (Windows) BOOL DestroyWindow(HWND hWnd);
enum { PM_REMOVE = 0x0001 }
const LPSTR IDC_ARROW = cast(LPSTR)32512;
extern (C) void *memset(void *dest, int c, size_t count);
extern (Windows) BOOL FreeLibrary(HMODULE hModule);
HWND createWindow()
{
HINSTANCE moduleHandle = GetModuleHandleA(null);
assert(moduleHandle);
WNDCLASS wc;
wc.lpszClassName = "DWndClass";
wc.style = CS_OWNDC | CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc = &windowProc;
wc.hInstance = moduleHandle;
wc.hIcon = LoadIconA(cast(HINSTANCE)null, IDI_APPLICATION);
wc.hCursor = LoadCursorA(cast(HINSTANCE)null, IDC_ARROW);
wc.hbrBackground = cast(HBRUSH) (COLOR_WINDOW + 1);
wc.lpszMenuName = null;
wc.cbClsExtra = wc.cbWndExtra = 0;
assert(RegisterClassA(&wc));
RECT rect;
rect.left = 0; rect.top = 0; rect.right = 640; rect.bottom = 480;
AdjustWindowRect(&rect, WS_CAPTION | WS_MINIMIZEBOX | WS_SYSMENU | WS_VISIBLE, FALSE);
HWND result = CreateWindowA("DWndClass", "Just a window",
WS_CAPTION | WS_MINIMIZEBOX | WS_SYSMENU | WS_VISIBLE,
CW_USEDEFAULT, CW_USEDEFAULT,
rect.right - rect.left, rect.bottom - rect.top, HWND_DESKTOP,
cast(HMENU)null, moduleHandle, null);
assert(result);
return result;
}
extern (Windows) int windowProc(HWND hWnd, uint uMsg, WPARAM wParam, LPARAM lParam)
{
if (uMsg == WM_CLOSE || uMsg == WM_DESTROY)
{
PostQuitMessage(0);
return 0;
}
return DefWindowProcA(hWnd, uMsg, wParam, lParam);
}
bit doEvents(HWND wnd)
{
MSG msg;
while (PeekMessageA(&msg, null, 0, 0, PM_REMOVE))
{
if (WM_QUIT == msg.message) return false;
TranslateMessage(&msg);
DispatchMessageA(&msg);
}
Sleep(16);
return true;
}
int main()
{
HWND wnd = createWindow();
while (true)
{
if (!doEvents(wnd))
break;
}
DestroyWindow(wnd);
return 0;
}