View previous topic :: View next topic |
Author |
Message |
samsam698
Joined: 10 Jan 2008 Posts: 63
|
Posted: Fri Mar 28, 2008 12:25 am Post subject: Anywhere can I learn dwt from examples |
|
|
I wanna learn dwt lib but can not find any useful examples.Is learning SWT the only way?
Thanks, |
|
Back to top |
|
|
doob
Joined: 06 Jan 2007 Posts: 367
|
|
Back to top |
|
|
samsam698
Joined: 10 Jan 2008 Posts: 63
|
Posted: Sat Mar 29, 2008 12:00 am Post subject: |
|
|
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 |
|
|
doob
Joined: 06 Jan 2007 Posts: 367
|
|
Back to top |
|
|
samsam698
Joined: 10 Jan 2008 Posts: 63
|
Posted: Sat Mar 29, 2008 6:32 pm Post subject: |
|
|
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 |
|
|
|
|
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
|