Develop and Download Open Source Software

Browse CVS Repository

Contents of /gikonavigoeson/gikonavi/GikoUtil.pas

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.1 - (show annotations) (download) (as text)
Sat Aug 9 13:51:05 2003 UTC (20 years, 8 months ago) by hi_
Branch point for: MAIN, hi
File MIME type: text/x-pascal
Initial revision

1 unit GikoUtil;
2
3 interface
4
5 uses
6 Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms;
7
8 function MsgBox(const hWnd: HWND; const Text, Caption: string; Flags: Longint = MB_OK): Integer;
9 function MsgMoveProc(nCode: Integer; wParam: WPARAM; lParam: LPARAM): LRESULT; stdcall;
10
11 implementation
12 var
13 hhk: HHOOK;
14
15 function MsgBox(const hWnd: HWND; const Text, Caption: string; Flags: Longint = MB_OK): Integer;
16 begin
17 hhk := SetWindowsHookEx(WH_CBT, @MsgMoveProc, 0, GetCurrentThreadId());
18 Result := Windows.MessageBox(hwnd, PChar(Text), PChar(Caption), Flags);
19 if hhk <> 0 then
20 UnhookWindowsHookEx(hhk);
21 end;
22
23 function MsgMoveProc(nCode: Integer; wParam: WPARAM; lParam: LPARAM): LRESULT; stdcall;
24 function GetW(ARect: TRect): Integer;
25 begin
26 Result := ARect.Right - ARect.Left;
27 end;
28 function GetH(ARect: TRect): Integer;
29 begin
30 Result := ARect.Bottom - ARect.Top;
31 end;
32 function MoveRect(ARect: TRect; X, Y: Integer): TRect;
33 var
34 W, H: Integer;
35 begin
36 W := GetW(ARect);
37 H := GetH(ARect);
38 Result := Rect(X, Y, X + W, Y + H);
39 end;
40 var
41 hParent: HWND;
42 hMsgBox: HWND;
43 ParentR: TRect;
44 MsgBoxR: TRect;
45 begin
46 if nCode = HCBT_ACTIVATE then begin
47 hMsgBox := wParam;
48 hParent := GetParent(wParam);
49 if (hParent <> 0) and (hMsgBox <> 0) and
50 (GetWindowRect(hParent, ParentR)) and
51 (GetWindowRect(hMsgBox, MsgBoxR)) then begin
52 MsgBoxR := MoveRect(MsgBoxR,
53 ParentR.Left + ((GetW(ParentR) - GetW(MsgBoxR)) div 2),
54 ParentR.Top + ((GetH(ParentR) - GetH(MsgBoxR)) div 2));
55 if MsgBoxR.Left < 0 then
56 MsgBoxR := MoveRect(MsgBoxR, 0, MsgBoxR.Top);
57 if MsgBoxR.Top < 0 then
58 MsgBoxR := MoveRect(MsgBoxR, MsgBoxR.Left, 0);
59 if MsgBoxR.Left + GetW(MsgBoxR) > Screen.WorkAreaWidth then
60 MsgBoxR := MoveRect(MsgBoxR, Screen.WorkAreaWidth - GetW(MsgBoxR), MsgBoxR.Top);
61 if MsgBoxR.Top + GetH(MsgBoxR) > Screen.WorkAreaHeight then
62 MsgBoxR := MoveRect(MsgBoxR, MsgBoxR.Left, Screen.WorkAreaHeight - GetH(MsgBoxR));
63 MoveWindow(hMsgBox, MsgBoxR.Left, MsgBoxR.Top, GetW(MsgBoxR), GetH(MsgBoxR), False);
64 end;
65 UnhookWindowsHookEx(hhk);
66 hhk := 0;
67 end else begin
68 CallNextHookEx(hhk, nCode, wParam, lParam);
69 end;
70 Result := 0;
71 end;
72
73 end.

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26