D / GtkD for SQL Server
Adam D. Ruppe
destructionator at gmail.com
Sun Oct 20 11:15:06 PDT 2013
On Sunday, 20 October 2013 at 17:24:30 UTC, John Joyus wrote:
> Regarding the GUI part, all I really need is a form and a bunch
> of buttons. Can I do that through pure Windows API in D to
> create a small stand-alone executable that does everything by
> itself?
yup. I started a thing to do it, but haven't finished it yet
https://github.com/adamdruppe/misc-stuff-including-D-programming-language-web-stuff
Grab the files simpledisplay.d, color,d and minigui.d. Lots of
stuff doesn't work, and the stuff that does work is still subject
to change... but if all ou need are the basics, it might be good
enough as it is.
Then compile:
dmd yourapp.d simpledisplay.d color.d minigui.d
and it should just work. If you avoid phobos throughout your
code, you can get stand-alone executables about 230 KB in size.
With phobos, you'll probably add 200-700 KB, depending on how
much you use.
Add " -L/SUBSYSTEM:WINDOWS:5.0" (no quotes) to the command line
if you don't want a console window to pop up. If you use a
resource and xml manifest, this supports visual theme styles on
XP+ too. (search MSDN if you want to learn more)
(btw there's also database.d and mssql.d in there that might
interest you. mssql.d uses ODBC, but the truth is I've never
actually tested it, so I don't know if it even compiles.)
minigui.d uses native Windows functions for the most part, if you
look at the source, you can see where there's HWNDs and so on
(and simpledisplay.d creates the windows and manages the event
loop, you can find a WndProc in there), but does its own layout
based on min/max size, stretchiness, and a handful of other
virtual functions. This is kinda a pain to customize at this
point, but it works pretty ok if the default is good for you
(fill all available space vertically).
The event model is based on javascript, you use
widget.addEventListener(type, handler).
Here's an example program:
import arsd.minigui;
void main() {
auto window = new MainWindow();
// the constructor often takes a label and a parent
auto checkbox = new Checkbox("Useful?", window);
// use HorizontalLayouts to put things side-by-side
auto field = new HorizontalLayout(window);
auto lbl = new TextLabel("Name:", field);
auto edit = new LineEdit(field);
auto buttonSet = new HorizontalLayout(window);
auto cancelButton = new Button("Cancel", buttonSet);
auto okButton = new Button("OK", buttonSet);
// the triggered event is like click, but also works with
keyboard activation
// other possible events are click, mouseover,
mouseenter, and a few others from javascript, search the
minigui.d source for EventType for a list so far
cancelButton.addEventListener(EventType.triggered, {
window.close();
});
okButton.addEventListener(EventType.triggered, {
// checking the checkbox state...
if(checkbox.isChecked)
// message boxes are done right now with
custom windows and are modeless. you actually prolly shouldn't
use them, perhaps use the raw Windows function instead
auto mb = new MessageBox("You said your name is : " ~
edit.content); // the box's content property gets its text. only
ASCII right now, i gotta fix this to use GetWindowTextW instead
of A...
else
auto mb = new MessageBox("You said this is useless, " ~
edit.content);
window.close();
});
// run the event loop. it terminates when the last window
is closed by your program or by the user.
window.loop();
}
If it works for you, cool, let me know if there's anything I can
do to make it better for you and I'll try to make it happen.
There's also DWT you might want to look at, like Jacob said. It
is a pretty complete port of the Java SWT toolkit so will
probably offer more functionality than my incomplete, minimal
file here.
More information about the Digitalmars-d-learn
mailing list