回答
您可以使用delphi的CreateMessageDialog
函數創建自己的自定義對話框。下面
實施例:
var
Dlg: TForm;
begin
Dlg := CreateMessageDialog('message', mtInformation, [mbOk], mbOK);
// Treat Dlg like any other form
Dlg.Caption := 'Hello World';
try
// The message label is named 'message'
with TLabel(Dlg.FindComponent('message')) do
begin
Font.Style := [fsUnderline];
// extraordinary code goes here
end;
// The icon is named... icon
with TPicture(Dlg.FindComponent('icon')) do
begin
// more amazing code regarding the icon
end;
Dlg.ShowModal;
finally
Dlg.Free;
end;
,當然可以插入其他部件藏漢成形式動態。
該對話框將使用Application.Title
的內容作爲標題。所以你可以在致電ShowMessage
之前設置它。
但是,如果要顯示具有不同標題的多個對話框,調用Windows MessageBox
函數會更方便。當然,如果你有一箇舊版本的Delphi,這會讓你的對話更加原生。
procedure MyShowMessage(const Msg, Caption: string);
begin
MessageBox(GetParentWindowHandleForDialog, PChar(Msg), PChar(Caption), MB_OK);
end;
function GetParentWindowHandleForDialog: HWND;
begin
//we must be careful that the handle we use here doesn't get closed while the dialog is showing
if Assigned(Screen.ActiveCustomForm) then begin
Result := Screen.ActiveCustomForm.Handle;
end else if Assigned(Application.MainForm) then begin
Result := Application.MainFormHandle;
end else begin
Result := Application.Handle;
end;
end;
如果你想控制顏色和大小,然後最明顯的選擇是創建自己的對話框爲TForm
後代。
這是我寫的一段代碼,你可能想用它做筆記。
function SetHook(Code : Integer; wparam : Integer; LParam : Integer) : Longint; stdcall;
function HookWndProc(wnd : HWND ;uMsg : UINT; wParam : WPARAM; lParam : LPARAM) : LRESULT; stdcall;
var
CaptHook : HHOOK;
GHookProc : TFNWndProc;
GOldHookProc : TFNWndProc;
implementation
uses Messages, Types, Graphics;
function SetHook(Code : Integer; wparam : Integer; LParam : Integer) : Longint; stdcall;
var
pwp : CWPSTRUCT;
begin
if Code = HC_ACTION then
begin
pwp := CWPStruct(Pointer(LParam)^);
if pwp.message = WM_INITDIALOG then
begin
GOldHookProc := TFnWndProc(SetWindowLong(pwp.hwnd, GWL_WNDPROC, LongInt(GHookProc)));
end;
end;
result := CallNextHookEx(CaptHook, Code, wparam, lparam);
end;
function HookWndProc(wnd : HWND ;uMsg : UINT; wParam : WPARAM; lParam : LPARAM) : LRESULT;
var
DC : HDC;
WndRect : Trect;
BR: HBRUSH;
WndText : array[1..20] of char;
begin
result := CallWindowProc(GOldHookProc, wnd, uMsg, wParam, lParam);
if uMsg = WM_ERASEBKGND then
begin
GetWindowText(wnd, @wndText, 20);
//do stuff here (I colored the button red)
DC := GetDC(wnd);
WndRect := Rect(0, 0, 200,200);
BR := CreateSolidBrush(clRed);
FillRect(dc, WndRect, BR);
DeleteObject(BR);
ReleaseDC(wnd, dc);
end;
end;
...
把這個在你的窗體創建要做出時髦的消息框
uses windows;
...
CaptHook := SetWindowsHookEx(WH_CALLWNDPROC, @SetHook, 0, GetCurrentThreadId);
GHookProc := @HookWndProc;
那麼,這是什麼不會掛鉤到Windows的對話框彈出功能中,你可以獲取對話框的上下文並繪製它。
這是幹什麼的? –
@David我不得不爲此編寫內部應用程序,因爲這裏的一些技術人員想要在重要警告消息上使用紅色按鈕。它本質上是一個可以在彈出的對話框的「畫布」上繪製的鉤子。你可以在評論的地方畫畫。 –
- 1. JQuery的屬性未改變對話框的標題
- 2. 創建對話框時更改對話框的標題
- 3. 更改raphael對象的標題屬性
- 4. Knockout JS和jQuery UI對話框的標題屬性
- 5. C#無法更改對話框中的標籤和按鈕屬性
- 6. 更改對話框中標題文本的顏色和字體
- 7. 對話框和FPS更改
- 8. jquery對話框和會話屬性
- 9. 在javascript確認對話框中更改標題和選項
- 10. 更改Android中對話框標題周圍框架的顏色
- 11. 在刷新對話框時動態更改dojo對話框的標題
- 12. 如何引用從對JavaScript變量:對話框標題屬性
- 13. mfc從另一個對話框更改對話框的光標
- 14. 更改android中的主題對話框
- 15. 打印機屬性對話框保存的更改
- 16. 更改Facebook SDK請求對話標題和通知標題
- 17. 對文本框的jQuery標題屬性
- 18. 更改對話框
- 19. 更改打開的p對話框的標題
- 20. 授權屬性和模態對話框
- 21. 使用文件對話框動態更改嵌入src屬性
- 22. WIX對話框更改屬性文本值
- 23. VS2008 WinForm屬性顏色選擇器對話框已更改
- 24. 如何更改JFileChooser對話框的標題
- 25. 如何更改對話框的標題背景顏色?
- 26. 如何更改對話框的標題顏色?
- 27. 更改對話框標題的字體大小android
- 28. 如何更改Android Alert對話框的背景標題
- 29. 如何更改MacOS認證對話框中的應用標題?
- 30. 如何在運行時更改對話框的標題?
+1這似乎與Shirish正在尋找的最佳匹配 –
@aldo感謝您的想法 – Shirish11
我從來不知道FindComponent存在。 +1! –