截屏、闪屏(Timer)、输入窗口--DFL for D2.053

这个小练习用D2.053+DFL完成了以下功能:
1.截屏(Chris的例子);
2.用截屏做闪屏,Timer(用Chris的例子);
3.数据库登陆窗口(数据库连接部分暂没做);
4.输入窗口模块module inputbox,从窗口输入中获得一个字符串和一个整数可以这样:
[code]
string input=inputBox.getString("用户自定义提示","用户自定义默认值");
int anInt=inputBox.getInt("","");
[/code]
省略参数则使用默认参数值。
对类型转换未进行错误检查。
5.菜单的创建(Chris的例子)
6.Chris的MemoryGraphic例子收录(只是试了一下);


主程序:
passwordform.d
[code]
/*
Generated by Entice Designer
Entice Designer written by Christopher E. Miller
www.dprogramming.com/entice.php
*/

import dfl.all;

import dfl.internal.winapi;
import std.string;
import std.c.string;
import std.conv;
import std.stdio;

import inputbox;
import splashform;

//extern(Windows) BOOL FindWindowEx
class PasswordForm: dfl.form.Form
{
// Do not modify or move this block of variables.
//~Entice Designer variables begin here.
dfl.label.Label label1;
dfl.textbox.TextBox textBox1;
dfl.label.Label label2;
dfl.textbox.TextBox textBox2;
dfl.button.Button btnOK;
dfl.button.Button btnCancel;
dfl.button.Button btnGetInput;
//~Entice Designer variables end here.


this()
{
initializePasswordForm();

//@ Other PasswordForm initialization code here.

}


private void initializePasswordForm()
{
// Do not manually modify this function.
//~Entice Designer 0.8.5.02 code begins here.
//~DFL Form
formBorderStyle = dfl.all.FormBorderStyle.FIXED_SINGLE;
startPosition = dfl.all.FormStartPosition.CENTER_SCREEN;
text = "Password Form";
clientSize = dfl.all.Size(314, 188);
//~DFL dfl.label.Label=label1
label1 = new dfl.label.Label();
label1.name = "label1";
label1.text = "用户名:";
label1.bounds = dfl.all.Rect(16, 48, 56, 16);
label1.parent = this;
//~DFL dfl.textbox.TextBox=textBox1
textBox1 = new dfl.textbox.TextBox();
textBox1.name = "textBox1";
textBox1.bounds = dfl.all.Rect(88, 40, 144, 24);
textBox1.parent = this;
//~DFL dfl.label.Label=label2
label2 = new dfl.label.Label();
label2.name = "label2";
label2.text = "密码:";
label2.bounds = dfl.all.Rect(16, 88, 64, 16);
label2.parent = this;
//~DFL dfl.textbox.TextBox=textBox2
textBox2 = new dfl.textbox.TextBox();
textBox2.name = "textBox2";
textBox2.bounds = dfl.all.Rect(88, 80, 144, 24);
textBox2.parent = this;
//~DFL dfl.button.Button=btnOK
btnOK = new dfl.button.Button();
btnOK.name = "btnOK";
btnOK.text = "(&O)登陆";
btnOK.bounds = dfl.all.Rect(56, 120, 88, 24);
btnOK.parent = this;
//~DFL dfl.button.Button=btnCancel
btnCancel = new dfl.button.Button();
btnCancel.name = "btnCancel";
btnCancel.text = "(&C)取消";
btnCancel.bounds = dfl.all.Rect(176, 120, 88, 24);
btnCancel.parent = this;
//~DFL dfl.button.Button=btnGetInput
btnGetInput = new Button;
btnGetInput.name = "btnGetInput";
btnGetInput.text = "...";
btnGetInput.bounds = dfl.all.Rect(248, 40, 40, 24);
btnGetInput.parent = this;
//~Entice Designer 0.8.5.02 code ends here.
this.acceptButton=btnOK;
this.cancelButton=btnCancel;

btnCancel.click~=&onCancel;
btnOK.click~=&onOK;


//textBox2.passwordChar='*';
this.centerToParent;

auto menu=new MainMenu;
this.menu=menu;

auto currentMenu=new MenuItem("(&F)文件");
menu.menuItems.add(currentMenu);

auto currentItem=new MenuItem("(&N)新建");
currentMenu.menuItems.add(currentItem);

currentItem=new MenuItem("Recent");
currentMenu.menuItems.add(currentItem);

currentMenu=currentItem;

currentItem=new MenuItem("File");
currentMenu.menuItems.add(currentItem);

currentItem=new MenuItem("Project");
currentMenu.menuItems.add(currentItem);

currentMenu=cast(MenuItem)currentMenu.parent;

currentItem=new MenuItem;
currentItem.barBreak=true;
currentMenu.menuItems.add(currentItem);

currentItem=new MenuItem("E&xit");
currentMenu.menuItems.add(currentItem);

currentItem=new MenuItem("Side Option");
currentItem.breakItem=true;
currentItem.checked=true;
currentMenu.menuItems.add(currentItem);

btnGetInput.click~=&getInputClick;
this.acceptButton=btnOK;
this.cancelButton=btnCancel;

}
protected void getInputClick(Object sender,EventArgs e)
{
string text1Value=textBox1.text;
string text2Value=textBox2.text;

string income=inputBox.getString;

textBox1.text=(income.length>0)?income:text1Value;



int temp=inputBox.getInt;
if(temp!=int.min)
textBox2.text=to!string(temp);
else
textBox2.text=text2Value;

}
protected void onCancel(Object sender,EventArgs e)
{

close;
}
protected void onOK(Object sender,EventArgs e)
{
close;
}

}


class GraphTest: Form
{


this()
{
text = "MemoryGraphics";

Panel panGraphic = new MemDrawer(2000,2000);
panGraphic.backColor = Color(0,0,0);

panGraphic.dock( DockStyle.FILL );
this.controls.add(panGraphic);
}
}

class MemDrawer:Panel
{
private MemoryGraphics memGraph;

this(int w,int h)
{
memGraph = new MemoryGraphics(w,h);

ubyte r = 0 ;
for (int i=0;i<w;i++)
{
r += 10;
if (r>255) r=0;
memGraph.drawLine(new Pen(Color(r,255,255)), i,0,i,h);
}
}

protected override void onPaint(PaintEventArgs ea)
{
memGraph.copyTo(createGraphics,0,0,memGraph.width,memGraph.height);
}
}



class MyForm : Form {
Button btn;
SimplePictureBox pb;

this() {
initializeMyForm();
}
private void initializeMyForm() {
text = "My Form";
clientSize = Size(292, 273);

btn = new Button();
btn.parent(this);
btn.text("Click ME");
btn.dock(DockStyle.TOP);
btn.click ~= &btn_click;

pb = new SimplePictureBox();
pb.parent(this);
pb.sizeMode=PictureBoxSizeMode.STRETCH_IMAGE;
pb.dock(DockStyle.FILL);

}
private void btn_click(Control sender, EventArgs ea) {
HWND hWnd = FindWindowExA(cast(HWND)0, cast(HWND)0, null, toStringz("0")); //or 0 for desktop...
//writefln("HWND = %d", hWnd);
Graphics g = MemoryGraphics.fromHwnd(hWnd);
MemoryGraphics mg = new MemoryGraphics(1280,1024);
g.copyTo(mg, 0,0,1280,1024);
Bitmap bmp = mg.toBitmap(mg);
pb.image(bmp);
}


}


int main()
{
int result = 0;

try
{
Application.enableVisualStyles();

//@ Other application initialization code here.


SplashForm splash=new SplashForm;
Application.run(splash);



Application.run(new PasswordForm);

}
catch(Exception o)
{
msgBox(o.toString(), "Fatal Error", MsgBoxButtons.OK, MsgBoxIcon.ERROR);

result = 1;
}

return result;
}
[/code]

inputbox.d
[code]
/*
Generated by Entice Designer
Entice Designer written by Christopher E. Miller
www.dprogramming.com/entice.php
*/

import dfl.all;
import std.string;
import std.conv;


class InputBox: dfl.form.Form
{
// Do not modify or move this block of variables.
//~Entice Designer variables begin here.
dfl.label.Label promptLabel;
dfl.textbox.TextBox txtInput;
dfl.button.Button btnOK;
dfl.button.Button btnCancel;
//~Entice Designer variables end here.

private string value;
int dlgResult;
this()
{
initializeInputBox();

//@ Other InputBox initialization code here.



}



private void initializeInputBox()
{
// Do not manually modify this function.
//~Entice Designer 0.8.5.02 code begins here.
//~DFL Form
formBorderStyle = dfl.all.FormBorderStyle.FIXED_SINGLE;
startPosition = dfl.all.FormStartPosition.CENTER_PARENT;
text = "Input Box";
clientSize = dfl.all.Size(322, 164);
//~DFL dfl.label.Label=promptLabel
promptLabel = new dfl.label.Label();
promptLabel.name = "promptLabel";
promptLabel.font = new dfl.all.Font("Microsoft Sans Serif", 16f, cast(dfl.all.FontStyle)(dfl.all.FontStyle.BOLD | dfl.all.FontStyle.ITALIC));
promptLabel.foreColor = dfl.all.Color(0, 0, 255);
promptLabel.text = "请输入一个整数:";
promptLabel.bounds = dfl.all.Rect(24, 16, 272, 32);
promptLabel.parent = this;
//~DFL dfl.textbox.TextBox=txtInput
txtInput = new dfl.textbox.TextBox();
txtInput.name = "txtInput";
txtInput.text = "0";
txtInput.bounds = dfl.all.Rect(24, 64, 200, 24);
txtInput.parent = this;
//~DFL dfl.button.Button=btnOK
btnOK = new dfl.button.Button();
btnOK.name = "btnOK";
btnOK.text = "(&O)确定";
btnOK.bounds = dfl.all.Rect(24, 120, 96, 24);
btnOK.parent = this;
//~DFL dfl.button.Button=btnCancel
btnCancel = new dfl.button.Button();
btnCancel.name = "btnCancel";
btnCancel.text = "(&C)取消";
btnCancel.bounds = dfl.all.Rect(216, 120, 88, 24);
btnCancel.parent = this;
//~Entice Designer 0.8.5.02 code ends here.

this.acceptButton=btnOK;
this.cancelButton=btnCancel;

txtInput.focus;

btnOK.click~=&okClick;
btnCancel.click~=&cancelClick;
}
protected void okClick(Object sender,EventArgs e)
{
dlgResult=1;
close;
}
protected void cancelClick(Object sender,EventArgs e)
{
dlgResult=0;
close;
}

//actually method getInt is not so useful to somebody who thinks need to handle carefully with Cancel button
//hit as the result is int.min other than 0 or -1 or the like.
public int getInt(string defaultPrompt="Please enter an integer:",string defaultValue="-999")
{

promptLabel.text=defaultPrompt;
txtInput.text=defaultValue;
//if(this.showDialog()!= DialogResult.CANCEL)
this.showDialog();
if(dlgResult==1)
{
value=txtInput.text;
return to!int(value.length?value:"0");

}
else if(dlgResult==0)
{

return int.min;
}
assert(0);
}



public string getString(string defaultPrompt="Please enter a string:",
string defaultValue="string here")
{

promptLabel.text=defaultPrompt;
txtInput.text=defaultValue;
//Using DialogResult.CANCEL does not work on hit Cancel button first and try a second time later to hit OK.
//if(this.showDialog()!= DialogResult.CANCEL)
this.showDialog();
if(dlgResult==1)
{
value=txtInput.text;
return value;
}
else if(dlgResult==0)
{
return null;
}

assert(0);
}




}
public:
static InputBox inputBox;
static this()
{

inputBox=new InputBox;
}
static ~this()
{
if(inputBox !is null)
inputBox.dispose;
}
[/code]

splashform.d
[code]
/*
Generated by Entice Designer
Entice Designer written by Christopher E. Miller
www.dprogramming.com/entice.php
*/

import dfl.all;
import dfl.internal.winapi;
import std.c.string;
import std.conv;
import std.string;

class SimplePictureBox: PictureBox
{
protected override void onPaintBackground(PaintEventArgs ea)
{
}


protected override void createParams(ref CreateParams cp)
{
super.createParams(cp);
//cp.exStyle |= WS_EX_TRANSPARENT;
}
}

class SplashForm: dfl.form.Form
{
// Do not modify or move this block of variables.
//~Entice Designer variables begin here.
SimplePictureBox pictureBox1;
//~Entice Designer variables end here.

Timer timer;
this()
{
initializeSplashForm();

//@ Other SplashForm initialization code here.
startTimer;
}

protected void startTimer()
{
timer=new Timer;
timer.interval=3000;
timer.tick~=&ticks;
timer.start;

}
protected void ticks(Timer sender,EventArgs e)
{
this.close;
}
private void initializeSplashForm()
{
// Do not manually modify this function.
//~Entice Designer 0.8.5.02 code begins here.
//~DFL Form
formBorderStyle = dfl.all.FormBorderStyle.NONE;
startPosition = dfl.all.FormStartPosition.CENTER_PARENT;
text = "Splash Form";
clientSize = dfl.all.Size(304, 192);
//~DFL SimplePictureBox:dfl.picturebox.PictureBox=pictureBox1
pictureBox1 = new SimplePictureBox();
pictureBox1.name = "pictureBox1";
pictureBox1.dock = dfl.all.DockStyle.FILL;
pictureBox1.bounds = dfl.all.Rect(0, 0, 304, 192);
pictureBox1.parent = this;
//~Entice Designer 0.8.5.02 code ends here.
pictureBox1.sizeMode=PictureBoxSizeMode.STRETCH_IMAGE;

//this.onLoad~=&onLoad;
}
protected override void onLoad(EventArgs ea)
{
super.onLoad(ea);
HWND hWnd = FindWindowExA(cast(HWND)0, cast(HWND)0, null, toStringz("0")); //or 0 for desktop...
//writefln("HWND = %d", hWnd);
Graphics g = MemoryGraphics.fromHwnd(hWnd);
MemoryGraphics mg = new MemoryGraphics(1280,1024);
g.copyTo(mg, 0,0,1280,1024);
Bitmap bmp = mg.toBitmap(mg);
pictureBox1.image(bmp);
}
}
[/code]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值