/Samples/Chap02/ScrnSize/ScrnSize.d
D | 59 lines | 42 code | 13 blank | 4 comment | 0 complexity | 33cab5292482a1127dceda730a441402 MD5 | raw file
- /+
- + Copyright (c) Charles Petzold, 1998.
- + Ported to the D Programming Language by Andrej Mitrovic, 2011.
- +/
- module ScrnSize;
- import core.runtime;
- import std.string;
- import std.utf;
- auto toUTF16z(S)(S s)
- {
- return toUTFz!(const(wchar)*)(s);
- }
- pragma(lib, "gdi32.lib");
- import core.sys.windows.windef;
- import core.sys.windows.winuser;
- import core.sys.windows.wingdi;
- extern (Windows)
- int WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int iCmdShow)
- {
- int result;
- try
- {
- Runtime.initialize();
- result = myWinMain(hInstance, hPrevInstance, lpCmdLine, iCmdShow);
- Runtime.terminate();
- }
- catch (Throwable o)
- {
- MessageBox(null, o.toString().toUTF16z, "Error", MB_OK | MB_ICONEXCLAMATION);
- result = 0;
- }
- return result;
- }
- int myWinMain(HINSTANCE hInstance,
- HINSTANCE hPrevInstance,
- LPSTR lpCmdLine,
- int iCmdShow)
- {
- int cxScreen, cyScreen;
- cxScreen = GetSystemMetrics(SM_CXSCREEN);
- cyScreen = GetSystemMetrics(SM_CYSCREEN);
- auto echo = format("The screen is %s pixels wide by %s pixels high.",
- cxScreen, cyScreen).toUTF16z;
- MessageBox(NULL, echo, "Screen Size", 0);
- return 0;
- }