Create custom Inputquery/Messagebox etc. without pain.

Create custom Inputquery/Messagebox etc. without pain.


It is possible, generic Message boxes will change and the icon, edit, button, size, etc., with a manner which makes it look like a Hack...

The idea behind this customization is to create a user-defined message, send it to the queue * before * the call message box. In the message (if it is a Messagebox), you can call the Handle of the window, or the Form (if there is Inputbox/Inputquery/Messagedlg) and change what you want. I will give you two examples, one for a regular api Messagebox and on the other with an input query.

1. Example: you need to change the default label of the Yes/no regular Messagebox.

type
TForm1 = class(TForm)
Button1: TButton
procedure Button1Click(Sender: TObject)
Private
Procedure WMHackBox (Var Message: TMessage) message WM_USER 1025
end
...
implementation
...
procedure TForm1.Button1Click(Sender: TObject)
begin
Our user-defined message
PostMessage (Handle, WM_USER 1025, 0, 0)
MessageBox call
Application.MessageBox ("I" completely stupid.', 'MyApplication', MB_YESNO or MB_ICONINFORMATION)
end of

Procedure TForm1.WMHackBox (Var Message: TMessage)
var
h: HWND

The message box appears, let its Handle to retrieve
h: = FindWindow (WC_DIALOG, 'MyApplication')
this Is the right Messagebox, let it
If GetParent(h) = Application.Handle then
begin
SetDlgItemText (h, ID_YES, ' I vote&')


SetDlgItemText (h, ID_NO, ' I created it & not agree ')
end
end of

Note that when using MessageDlg any regular API Messagebox but a Form of Delphi dynamic. See 2. Example.

Result & #039

2. Example: You need to match an input query, for example, the passwordchar property

type
TForm1 = class(TForm)
Button1: TButton
procedure Button1Click(Sender: TObject)
Private
Procedure WMHack (Var Message: TMessage) message WM_USER 1024
end
...
implementation
...
const
ACaption = 'caption'

procedure TForm1.Button1Click(Sender: TObject)
begin
PostMessage (Handle, WM_USER 1024, 0, 0)
InputBox (ACaption, 'Prompt', 'default')
end of

Procedure TForm1.WMHack (Var Message: TMessage)
var
i: Integer
j: Integer
begin
for i: = 0 to Screen.Form count-1
If Screen.Forms[i]. Caption = ACaption then
begin
for j: = 0 to Screen.Forms[i]. Control count-1
If Screen.Forms[i]. Controls [j] is TEdit.
begin
TEdit (Screen.Forms [i]. Controls[j]). PasswordChar: = "#"
TEdit (Screen.Forms [i]. Controls[j]). SelectAll
exit
end
end
end
Result








Create custom Inputquery/Messagebox etc. without pain.


Create custom Inputquery/Messagebox etc. without pain. : Multi-thousand tips to make your life easier.


It is possible, generic Message boxes will change and the icon, edit, button, size, etc., with a manner which makes it look like a Hack...

The idea behind this customization is to create a user-defined message, send it to the queue * before * the call message box. In the message (if it is a Messagebox), you can call the Handle of the window, or the Form (if there is Inputbox/Inputquery/Messagedlg) and change what you want. I will give you two examples, one for a regular api Messagebox and on the other with an input query.

1. Example: you need to change the default label of the Yes/no regular Messagebox.

type
TForm1 = class(TForm)
Button1: TButton
procedure Button1Click(Sender: TObject)
Private
Procedure WMHackBox (Var Message: TMessage) message WM_USER 1025
end
...
implementation
...
procedure TForm1.Button1Click(Sender: TObject)
begin
Our user-defined message
PostMessage (Handle, WM_USER 1025, 0, 0)
MessageBox call
Application.MessageBox ("I" completely stupid.', 'MyApplication', MB_YESNO or MB_ICONINFORMATION)
end of

Procedure TForm1.WMHackBox (Var Message: TMessage)
var
h: HWND

The message box appears, let its Handle to retrieve
h: = FindWindow (WC_DIALOG, 'MyApplication')
this Is the right Messagebox, let it
If GetParent(h) = Application.Handle then
begin
SetDlgItemText (h, ID_YES, ' I vote&')


SetDlgItemText (h, ID_NO, ' I created it & not agree ')
end
end of

Note that when using MessageDlg any regular API Messagebox but a Form of Delphi dynamic. See 2. Example.

Result & #039

2. Example: You need to match an input query, for example, the passwordchar property

type
TForm1 = class(TForm)
Button1: TButton
procedure Button1Click(Sender: TObject)
Private
Procedure WMHack (Var Message: TMessage) message WM_USER 1024
end
...
implementation
...
const
ACaption = 'caption'

procedure TForm1.Button1Click(Sender: TObject)
begin
PostMessage (Handle, WM_USER 1024, 0, 0)
InputBox (ACaption, 'Prompt', 'default')
end of

Procedure TForm1.WMHack (Var Message: TMessage)
var
i: Integer
j: Integer
begin
for i: = 0 to Screen.Form count-1
If Screen.Forms[i]. Caption = ACaption then
begin
for j: = 0 to Screen.Forms[i]. Control count-1
If Screen.Forms[i]. Controls [j] is TEdit.
begin
TEdit (Screen.Forms [i]. Controls[j]). PasswordChar: = "#"
TEdit (Screen.Forms [i]. Controls[j]). SelectAll
exit
end
end
end
Result

Create custom Inputquery/Messagebox etc. without pain.

Create custom Inputquery/Messagebox etc. without pain. : Multi-thousand tips to make your life easier.
Create custom Inputquery/Messagebox etc. without pain.
Create custom Inputquery/Messagebox etc. without pain.
Recommend to friends
  • gplus
  • pinterest

Comment

Leave comment

Rating