问一个非常非常特殊消息框的问题!(50分)

  • 主题发起人 zhang_yz6666
  • 开始时间
Z

zhang_yz6666

Unregistered / Unconfirmed
GUEST, unregistred user!
不知众位高手中,在delphi开发过程中有没有遇到这样一个问题!
当要求系统弹出一个消息框:出现三种情况,如何进行显示,选择和确定。
比如:
要求有条件的删除一个文件:
1.当条件为1是删除。
2.当条件为2是删除。
3.不删除。
问题:
1。我用messagebox()函数,显示只有:yes,no,Cancel等(系统本身差数)类似的
按钮。不可能出现自制的按钮(“删除1”,”删除2“,“不删除”等按钮)。
2。我采用系统其他函数 messageDlg,showMessage,inputbox,Inputquery等都不能满足。
3。假如我采用messagebox
比如:
if Messagebox(Self.Handle,Pchar('你是要删除"'+BBCdwmc+'"全部数据,还是只删除该单位'+ BBCnf +'年' + BBCjd + '的数据!'+#13+'如果是删除全部数据,请选择"是"'+#13+'如果是删除该时段的数据,请选择"否"'+#13+'如果不删除数据,请选择"取消"'),'重要提示',MB_YESNOCANCEL+MB_ICONEXCLAMATION) = IDCancel then
begin
Exit ;
end
Else if Messagebox(Self.Handle,Pchar('你是要删除"'+BBCdwmc+'"全部数据,还是只删除该单位'+ BBCnf +'年' + BBCjd + '的数据!'+#13+'如果是删除全部数据,请选择"是"'+#13+'如果是删除该时段的数据,请选择"否"'+#13+'如果不删除数据,请选择"取消"'),'重要提示',MB_YESNOCANCEL+MB_ICONEXCLAMATION) = IDYes then
begin
showmessage('IDYes');
Exit ;
end
Else if Messagebox(Self.Handle,Pchar('你是要删除"'+BBCdwmc+'"全部数据,还是只删除该单位'+ BBCnf +'年' + BBCjd + '的数据!'+#13+'如果是删除全部数据,请选择"是"'+#13+'如果是删除该时段的数据,请选择"否"'+#13+'如果不删除数据,请选择"取消"'),'重要提示',MB_YESNOCANCEL+MB_ICONEXCLAMATION) = IDNO then
begin
showmessage('IDNO');
Exit ;
end ;
那么,我必须这样才能知道三个返回值。但最后一个消息要出现三次!
我的写法是否有误!请指正。
4。能否提供一个好的解决方法!(按钮方式)
5。能否提供一个类似下来框选择条件的方法!
 
case Messagebox(Self.Handle,Pchar('你是要删除"'+BBCdwmc+'"全部数据,还是只删除该单位'+ BBCnf +'年' + BBCjd + '的数据!'+#13+'如果是删除全部数据,请选择"是"'+#13+'如果是删除该时段的数据,请选择"否"'+#13+'如果不删除数据,请选择"取消"') of
idyes: {CODE 删除一};
idno: {CODE 删除二};
idcancel:{CODE 取消}
end;

用CASE语句可以解决这个问题,MESSAGEBOX只会弹出一次
 
要不自己做一个
要不application.messagebox好像有这个功能,你看看winapi中的messagebox函数帮助
 
可以用MessageBox对象方法的返回值来确定
可能值 数值 意义
IDOK 1 用户选择“确定”按钮
IDCANCEL 2 用户选择“取消”铵钮
IDABORT 3 用户选择“结束”铵钮
IDRETRY 4 用户选择“重试”铵钮
IDIGNORE 5 用户选择“忽略”铵钮
IDYES 6 用户选择“是”铵钮
IDNO 7 用户选择“否”铵钮

可用以下方法实现你的要求
case MessageBox(Handle, PChar(''), PChar('Information'), $00000043) of
IDYES://用户按“是”铵钮
begin
//do 删除1
end;
IDNO://用户按“否”铵钮
begin
//do 删除2
end;
IDCANCEL://用户按“取消”铵钮
begin
//do nonething 不删除
end;
end;
 
要改按钮,可以修改DELPHI的MessageDlg函数的源代码,修改Button的Caption,不过要重新编译一下Dialogs的bpl(MessageDlg应该是在Dialogs里吧)
我以前就改动过Input函数的源代码,因为它的字体太难看了。

!---其实最好的办法是自己做一个窗体,自己放三个按钮,把他当MessageBox用,最好控制了,反正加一个窗体又没什么的。
 
作CBT Hook可以修改系统默认的按钮标题!!!!!!!!

但你的问题完全可以自己定制一个FORM 来实现。不要用Messagebox.
可以参考 Showmessage , Messagedlg 等源代码。
 
var rst: Integer;
begin
rst := Messagebox(Self.Handle,Pchar('你是要删除"'+BBCdwmc+'"全部数据,还是只删除该单位'+ BBCnf +'年' + BBCjd + '的数据!'+#13+'如果是删除全部数据,请选择"是"'+#13+'如果是删除该时段的数据,请选择"否"'+#13+'如果不删除数据,请选择"取消"');
if rst = idyes then
{CODE 删除一}
else if rst = idno then
{CODE 删除二}
else
idcancel:{CODE 取消}
end;
//这样简单明了
 
谢谢众位的回答!~
几位提供的方式挺好!可就是按钮还是系统按钮。能否该按钮标题。????
最好能采用类似下来框选择条件的方法!

TO:jsxjd,
作CBT Hook可以修改系统默认的按钮标题!!!!!!!!能否说的详细一点!
不能做一个form,窗口太多了。想用系统提示的消息实现~!
 
没看到我说的吗,改Dialogs源代码
 
把下面的中文改一下就可以了!!!!!!!!!

一个定义消息框的函数

摘 要:跟调用MESSAGEDLG一样,不过界面是中文的提示及标题
关键字:中文消息框
类 别:用户界面

function CustorMessageDlg(const aMsg, aCaption: string): integer;
var
DialogForm: TForm;
AOkButton: TButton;
aCancelButton: TButton;
aLabel: TLabel;
i: integer;
begin
Result := 2;
DialogForm := TForm.Create(Application);
AOkButton := TButton.Create(Application);
aCancelButton := TButton.Create(Application);
aLabel := TLabel.Create(Application);
with aLabel do
begin
Font.Size := 8;
Caption := ';
for i := 1 to length(aMsg) do
begin
if (I mod 56 = 0) then
Caption := Caption + aMsg + #13
else
Caption := Caption + aMsg;
end;
Left := (400 - Width) div 2;
Top := 10;
Parent := DialogForm;
end;
with AOkButton do
begin
Font.Size := 8;
Left := 110;
Top := 20 + aLabel.Height;
Width := 75;
Height := 25;
TabOrder := 0;
Caption := '确定[&O]';
Parent := DialogForm;
ModalResult := mrOk;
end;
with aCancelButton do
begin
Font.Size := 8;
Left := 215;
Top := 20 + aLabel.Height;
Width := 75;
Height := 25;
TabOrder := 1;
Caption := '取消[&C]';
Parent := DialogForm;
ModalResult := mrCancel;
end;
with DialogForm do
begin
Font.Size := 8;
Name := 'DlgForm';
Width := 400;
Height := 25 + 30 + 25 + aLabel.Height;
Caption := aCaption;
Position := poDesktopCenter;
BorderStyle := bsDialog;
if ShowModal<>2 then
Result := 1;
Free;
end;
end;

 
不介意我关注一下吧。
 
To :jsxjd
非常感谢你!两个按钮每问题,我在你的基础上作了三个按钮的修改!
但还是两个按钮!我改的那里有问题,请指点!
function CustorMessageDlg(const aMsg, aCaption: string): integer;
var
DialogForm: TForm;
Aif1Button: TButton;
aif2Button: TButton;
Aif3Button: TButton;
aLabel: TLabel;
i: integer;
begin
Result := 2;
DialogForm := TForm.Create(Application);
Aif1Button := TButton.Create(Application);
aif2Button := TButton.Create(Application);
aif3Button := TButton.Create(Application);
aLabel := TLabel.Create(Application);
with aLabel do
begin
Font.Size := 8;
Caption := '';
for i := 1 to length(aMsg) do
begin
if (I mod 56 = 0) then
Caption := Caption + aMsg + #13
else
Caption := Caption + aMsg;
end;
Left := (400 - Width) div 2;
Top := 10;
Parent := DialogForm;
end;
with Aif1Button do
begin
Font.Size := 8;
Left := 110;
Top := 20 + aLabel.Height;
Width := 75;
Height := 25;
TabOrder := 0;
Caption := 'if1[&amp;O]';
Parent := DialogForm;
ModalResult := mrYes;
end;
with aif2Button do
begin
Font.Size := 8;
Left := 215;
Top := 20 + aLabel.Height;
Width := 75;
Height := 25;
TabOrder := 1;
Caption := 'if2[&amp;C]';
Parent := DialogForm;
ModalResult := mrNo;
end;
with aif3Button do
begin
Font.Size := 8;
Left := 215;
Top := 20 + aLabel.Height;
Width := 75;
Height := 25;
TabOrder := 1;
Caption := 'if3[&amp;C]';
Parent := DialogForm;
ModalResult := mrCancel;
end;
with DialogForm do
begin
Font.Size := 8;
Name := 'DlgForm';
Width := 400;
Height := 25 + 30 + 25 + aLabel.Height;
Caption := aCaption;
Position := poDesktopCenter;
BorderStyle := bsDialog;
if ShowModal<>2 then
Result := 1;
Free;
end;
end;
 
大家都休息了吗?
 
接受答案了
 
分给谁了?
 
继续,回答完我的问题就给分!!!
 
To:zyg_zm,及高手
能不能关注一下!看看我的代码,为什么出现问题!
function CustorMessageDlg(const aMsg, aCaption: string): integer;
var
DialogForm: TForm;
Aif1Button: TButton;
aif2Button: TButton;
Aif3Button: TButton;
aLabel: TLabel;
i: integer;
begin
Result := 2;
DialogForm := TForm.Create(Application);
Aif1Button := TButton.Create(Application);
aif2Button := TButton.Create(Application);
aif3Button := TButton.Create(Application);
aLabel := TLabel.Create(Application);
with aLabel do
begin
Font.Size := 8;
Caption := '';
for i := 1 to length(aMsg) do
begin
if (I mod 56 = 0) then
Caption := Caption + aMsg + #13
else
Caption := Caption + aMsg;
end;
Left := (400 - Width) div 2;
Top := 10;
Parent := DialogForm;
end;
with Aif1Button do
begin
Font.Size := 8;
Left := 110;
Top := 20 + aLabel.Height;
Width := 75;
Height := 25;
TabOrder := 0;
Caption := 'if1[&amp;O]';
Parent := DialogForm;
ModalResult := mrYes;
end;
with aif2Button do
begin
Font.Size := 8;
Left := 215;
Top := 20 + aLabel.Height;
Width := 75;
Height := 25;
TabOrder := 1;
Caption := 'if2[&amp;C]';
Parent := DialogForm;
ModalResult := mrNo;
end;
with aif3Button do
begin
Font.Size := 8;
Left := 215;
Top := 20 + aLabel.Height;
Width := 75;
Height := 25;
TabOrder := 1;
Caption := 'if3[&amp;C]';
Parent := DialogForm;
ModalResult := mrCancel;
end;
with DialogForm do
begin
Font.Size := 8;
Name := 'DlgForm';
Width := 400;
Height := 25 + 30 + 25 + aLabel.Height;
Caption := aCaption;
Position := poDesktopCenter;
BorderStyle := bsDialog;
if ShowModal<>2 then
Result := 1;
Free;
end;
end;

但还是两个按钮!我改的那里有问题,请指点!
 
老兄,aif2Button 和 aif3Button 的Left属性设成了一样的
有一段:
with aif2Button do
begin
Font.Size := 8;
Left := 215;

下面也一样:
with aif3Button do
begin
Font.Size := 8;
Left := 215;

两个按钮的LEFT都设成了215,所以有一个按钮被另一个按钮覆盖了。你就看不到了,把几个LEFT适当地调整一下吧
 
顶部