Add simple clock example.

This commit is contained in:
haru-s 2024-03-29 23:54:42 +09:00
parent 3d9fc4aee3
commit 497e87cfa5
10 changed files with 136 additions and 1 deletions

View file

@ -21,6 +21,7 @@ DFL is a Win32 windowing library for the D language.
![screen shot](./examples/contextmenu/image/screenshot.png "screen shot")
![screen shot](./examples/toolbar/image/screenshot.png "screen shot")
![screen shot](./examples/richtextbox/image/screenshot.png "screen shot")
![screen shot](./examples/dclock/image/screenshot.png "screen shot")
## Recent major features
- **Module "dfl.printing" is now comming.**
@ -81,7 +82,7 @@ In order to make and move *.lib to paths below:
- **go.bat 32mscoff** (MSVC required) : ditto
- **go64.bat** (MSVC required) : Make and move *.lib to %dmd_path%\lib64
## With DUB
## With DUB **(RECOMMENDED)**
First, add DFL to local DUB registry:
```bat
> cd dfl
@ -102,4 +103,5 @@ See also **./examples/hello_dfl/dub.json**.
## License
DFL is under the boost and/or zlib/libpng license.
However, trackbar.d is covered by the MIT license.

16
examples/dclock/.gitignore vendored Normal file
View file

@ -0,0 +1,16 @@
.dub
docs.json
__dummy.html
docs/
/hello_dfl
hello_dfl.so
hello_dfl.dylib
hello_dfl.dll
hello_dfl.a
hello_dfl.lib
hello_dfl-test-*
*.exe
*.pdb
*.o
*.obj
*.lst

13
examples/dclock/.vscode/launch.json vendored Normal file
View file

@ -0,0 +1,13 @@
{
"version": "0.1.0",
"configurations": [
{
"name": "C++ Launch (Windows) Dclock",
"type": "cppvsdbg",
"request": "launch",
"cwd": "${workspaceRoot}",
"program": "./bin/dclock.exe",
"console": "internalConsole"
}
]
}

20
examples/dclock/.vscode/tasks.json vendored Normal file
View file

@ -0,0 +1,20 @@
{
"version": "2.0.0",
"tasks": [
{
"type": "dub",
"run": false,
"cwd": ".",
"compiler": "$current",
"archType": "$current",
"buildType": "$current",
"configuration": "$current",
"problemMatcher": [
"$dmd"
],
"group": "build",
"label": "dub: Build dclock",
"detail": "dub build --compiler=dmd.EXE -a=x86_64 -b=debug -c=application"
}
]
}

View file

@ -0,0 +1,2 @@
# Screen Shot
![screen shot](./image/screenshot.png "screen shot")

View file

@ -0,0 +1,12 @@
{
"folders": [
{
"path": "."
}
],
"settings": {
"d.projectImportPaths": [
"..\\..\\..\\dfl\\source"
]
}
}

16
examples/dclock/dub.json Normal file
View file

@ -0,0 +1,16 @@
{
"authors": ["haru-s"],
"copyright": "Copyright (C) 2024 haru-s",
"description": "Dclock",
"name": "dclock",
"targetType": "executable",
"targetPath": "bin",
"dependencies": {
"dfl": {
"path": "../../../dfl"
}
},
"lflags-windows-x86_omf-dmd": ["/exet:nt/su:windows:6.0"],
"lflags-windows-x86_mscoff-dmd": ["/SUBSYSTEM:WINDOWS", "/ENTRY:mainCRTStartup"],
"lflags-windows-x86_64-dmd": ["/SUBSYSTEM:WINDOWS", "/ENTRY:mainCRTStartup"]
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 38 KiB

View file

@ -0,0 +1,3 @@
set dmd_path=c:\d\dmd2\windows
set dmc_path=c:\dmc\dm
cmd

View file

@ -0,0 +1,51 @@
import std;
import dfl;
class MainForm : Form
{
private Label _label;
private Timer _timer;
public this()
{
this.text = "Dclock";
this.size = Size(300, 150);
this.formBorderStyle = FormBorderStyle.FIXED_SINGLE;
this.maximizeBox = false;
this.topMost = true;
void drawClock()
{
DateTime now = cast(DateTime)Clock.currTime();
_label.text = format(
"%.4d/%.2d/%.2d\n(%s)%.2d:%.2d",
now.year, now.month, now.day,
["日","月","火","水","木","金","土"][now.dayOfWeek],
now.hour, now.minute);
}
_label = new Label;
_label.location = Point(0, 0);
_label.font = new Font("MS Gothic", 40f);
_label.autoSize = true;
_label.parent = this;
drawClock();
_timer = new Timer;
_timer.interval = 1000;
_timer.start();
_timer.tick ~= (Timer t, EventArgs e) {
drawClock();
};
}
}
static this()
{
Application.enableVisualStyles();
}
void main()
{
Application.run(new MainForm());
}