D / GtkD for SQL Server

John Joyus john.joyus at gmail.com
Mon Oct 21 23:33:08 PDT 2013


On 10/21/2013 07:27 PM, Adam D. Ruppe wrote:
> On Monday, 21 October 2013 at 22:23:16 UTC, John Joyus wrote:
>> 1. When I click the OK button, the message dialog pops-up *after* the
>> main window is closed, though the window.close(); line is after the
>> call to the MessageBox..
>
> that's because the MessageBox class here is implemented as another
> window with an event loop, so it doesn't stop execution.
>
> If you want a message box that stops execution, you should just use the
> regular Windows call
>
> http://msdn.microsoft.com/en-us/library/windows/desktop/ms645505%28v=vs.85%29.aspx
>
>
> it is available in D if you do this:
>
> import core.sys.windows.windows;
> import std.string : toStringz;
> MessageBoxA(null, toStringz("You clicked ok."), toStringz("title here"),
> MB_OK);
>
> (or you can use MessageBoxW and toUTF16z instead of toStringz if you
> need unicode support)
>
>> 2. The controls appear to align to client by default. How do I
>> position them where I want them and with the height and width of my
>> choice.
>
> I just added a new thing called StaticLayout that lets you do this:
>
>          auto window = new MyMainWindow();
>          auto layout = new StaticLayout(layout);
>
>          auto btn = new Button("test", layout);
>
>          btn.x = 100;
>          btn.y = 200;
>          btn.width = 100;
>          btn.height = 50;
>
>
> If the only child of the window is a StaticLayout, you can set the x,y,
> width, height on each part of it and it will honor that.
>
> The method registerMovement() btw is the key here. When it is called, it
> calls MoveWindow to inform Windows of the updated position. It is called
> automatically by the function recomputeChildLayout(), which by default,
> also changes the size and position automatically.
>
> The new StaticLayout class overrides recomputeChildLayout to call
> registerMovement without trying to change things itself.
>
>
> (This is new btw becuase I kinda hate doing manual positioning and
> wanted the automatic grid to work first. But then I didn't get back to
> finish the other options when another project took over, so there's a
> lot of minigui.d that isn't quite done, including this.)


That works! Thanks.
I have tried the previous example like below, with manual positioning.

Having this light weight minigui is very encouraging to me to learn D :)
The 99% of my programs demand a basic GUI. And I personally love to 
create stand-alone tools that do not have a ton of dependencies, 
esecially anything that doesn't come with Winodws by default.
I think Delphi has spoiled me! :)


import arsd.minigui;
import core.sys.windows.windows;
import std.string : toStringz;

void main() {
     auto window = new MainWindow();

     // use StaticLayout to position the controls manually (or use 
HorizontalLayout to put them side-by-side)
     auto layout = new StaticLayout(window);

     auto lblName = new TextLabel("Your Name:", layout);
         lblName.x = 20;
         lblName.y = 40;
     auto edtName = new LineEdit(layout);
         edtName.x = 110;
         edtName.y = 40;
         edtName.height = 20;
         edtName.width = 200;

     auto cbUseful = new Checkbox("Useful?", layout);
         cbUseful.x = 110;
         cbUseful.y = 100;
         cbUseful.width = 750;
         cbUseful.height = 25;

     auto btnOk = new Button("OK", layout);
         btnOk.x = 20;
         btnOk.y = 425;
         btnOk.width = 75;
         btnOk.height = 25;

      auto btnClose = new Button("Close", layout);
         btnClose.x = 110;
         btnClose.y = 425;
         btnClose.width = 75;
         btnClose.height = 25;

     // 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
     btnOk.addEventListener(EventType.triggered, {
         if(cbUseful.isChecked)
             MessageBoxA(null, toStringz(" Thanks for liking MiniGUI"), 
toStringz("D App with MiniGUI"), MB_OK);
         else
             MessageBoxA(null, toStringz(" Thanks for trying MiniGUI"), 
toStringz("D App with MiniGUI"), MB_OK);
         window.close();
     });

     btnClose.addEventListener(EventType.triggered, {
       if (MessageBoxA(null, toStringz("Are you sure you want to close 
this application?"), toStringz("D App with MiniGUI"), MB_YESNO | 
MB_ICONQUESTION) == IDYES)
        window.close();
     });

     // run the event loop. it terminates when the last window is closed.
     window.loop();
}



More information about the Digitalmars-d-learn mailing list