FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Anywhere can I learn dwt from examples

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.     Forum Index -> DWT
View previous topic :: View next topic  
Author Message
samsam698



Joined: 10 Jan 2008
Posts: 63

PostPosted: Fri Mar 28, 2008 12:25 am    Post subject: Anywhere can I learn dwt from examples Reply with quote

I wanna learn dwt lib but can not find any useful examples.Is learning SWT the only way?

Thanks,
Back to top
View user's profile Send private message
doob



Joined: 06 Jan 2007
Posts: 367

PostPosted: Fri Mar 28, 2008 5:11 pm    Post subject: Reply with quote

No, you can look at the dwt-samples project: http://www.dsource.org/projects/dwt-samples

But reading the SWT API, documentation, examples, snippets and tutorials should work very well too. It's very little that's different in DWT compared to SWT. Look at the bottom of http://www.dsource.org/projects/dwt/wiki/Installation "Differences between SWT and DWT" and "Things added or changed in DWT". You can find some useful links on the DWT main page: http://www.dsource.org/projects/dwt
Back to top
View user's profile Send private message
samsam698



Joined: 10 Jan 2008
Posts: 63

PostPosted: Sat Mar 29, 2008 12:00 am    Post subject: Reply with quote

Thanks.
I wanna learn more about event.For example,when click on a button,something happens.I found a few examples in the trunck of dwt,but it can not compile.Below code is from \\examples\mis\hello2.d:

module hello2;


import dwt.all;

version(build){
debug{
pragma(link, "dwtd.lib");
}else{
pragma(link, "dwt.lib");
}

pragma(link, "advapi32.lib");
pragma(link, "comctl32.lib");
pragma(link, "gdi32.lib");
pragma(link, "shell32.lib");
pragma(link, "comdlg32.lib");
pragma(link, "ole32.lib");
pragma(link, "uuid.lib");
pragma(link, "phobos.lib");

pragma(link, "user32_dwt.lib");
pragma(link, "imm32_dwt.lib");
pragma(link, "shell32_dwt.lib");
pragma(link, "msimg32_dwt.lib");
pragma(link, "gdi32_dwt.lib");
pragma(link, "kernel32_dwt.lib");
pragma(link, "usp10_dwt.lib");
pragma(link, "olepro32_dwt.lib");
pragma(link, "oleaut32_dwt.lib");
pragma(link, "oleacc_dwt.lib");
}

class Hello
{
private Shell shell;

public Shell open(Display display)
{
shell = new Shell(display);
shell.setText("Hello world");
shell.setSize(400, 250);
shell.setLayout(new FillLayout());
Button btn = new Button(shell, DWT.PUSH);
btn.setText("Hello, DWT");
btn.handleEvent(this, DWT.Selection, &onButtonClick);


with(new Button(shell, DWT.PUSH))
{
setText("Button 2");
// embeded delegate
handleEvent(this, DWT.Selection, delegate(Event e){
// Use Event.cData (means custom data) to pass argument
Hello pthis = cast(Hello)e.cData;
MessageBox.showMsg("You clicked button 2", null, pthis.shell);
});
}
shell.open();
return shell;
}

// click event handler
private void onButtonClick(Event e)
{
MessageBox.showMessage("You clicked hello button", "Information", shell);
}

public static void run()
{
Display display = Display.getDefault();
Hello hello = new Hello();
Shell shell = hello.open(display);
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}

}

void main(char[][] args)
{
try {
Hello.run();
}catch(Object o){
MessageBox.showMsg(o.toString());
}
}


I struggled for several hours but still failed.The question is not ' import dwt.all',but 'handleEvent' function!!!I searched the whole dwt source file but there is no such function.Simply put,just wanna know how to connect a control and let the certain event fire.
Back to top
View user's profile Send private message
doob



Joined: 06 Jan 2007
Posts: 367

PostPosted: Sat Mar 29, 2008 6:06 am    Post subject: Reply with quote

I think you found an example from the old dwt (read the top of http://www.dsource.org/projects/dwt/wiki/AccessMercurialRepo "History and packages").

DWT and SWT uses listeners and not delegates (there are thoughts on how to implement delegates in DWT without changing too much).

All widgets have an addListener method (http://help.eclipse.org/stable/nftopic/org.eclipse.platform.doc.isv/reference/api/index.html).
Use it like this:
Code:
Button btn = new Button(shell, DWT.PUSH);
btn.setText("Hello, DWT");
btn.addListener(DWT.Selection, new class Listener { public void handleEvent(Event event) {MessageBox.showInfo("You clicked hello button", "Information");}} );


You can also have the a class like this:
Code:
class ButtonListener : Listener
{
    public void handleEvent(Event event)
    {
        MessageBox.showInfo("You clicked hello button", "Information"); // uses the DWT.INFORMATION style
    }
}


and then use it like this:
Code:
btn.addListener(DWT.Selection, new ButtonListener);


You can also look here: http://www.dsource.org/projects/dwt-samples/browser/dwtexamples/simple.d

and here is a Hello World DWT example (look under "19. Test DWT with the following example:") :
http://www.dsource.org/projects/dwt/wiki/Installation

BTW read the whole DWT installation guide if you haven't - http://www.dsource.org/projects/dwt/wiki/Installation

(I haven't compiled this code)
Back to top
View user's profile Send private message
samsam698



Joined: 10 Jan 2008
Posts: 63

PostPosted: Sat Mar 29, 2008 6:32 pm    Post subject: Reply with quote

Both 2 ways work!!!Thanks,thanks.
Yes,if dwt implemented delegates,it is cool,also if it implements properties other than setter and getter method,it is cool dead.
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.     Forum Index -> DWT All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group