마음의 안정을 찾기 위하여 - [Delphi] System-Modal Top Most Message Box
1830049
73
208
관리자새글쓰기
태그위치로그방명록
별일없다의 생각
dawnsea's me2day/2010
색상(RGB)코드 추출기(Color...
Connection Generator/2010
최승호PD, '4대강 거짓말 검...
Green Monkey**/2010
Syng의 생각
syng's me2DAY/2010
천재 작곡가 윤일상이 기획,...
엘븐킹's Digital Factory/2010
[Delphi] System-Modal Top Most Message Box
Delphi/Code | 2016/01/13 15:35
링크 : http://delphi.about.com/od/windowsshellapi/a/notactive_modal.htm




System-Modal Top Most Message Box

Even though this might sound complicated, it is, as you will see, not.
Since Delphi can easily access most of the Windows API calls, executing the "MessageBox" Windows API function will do the trick.

Defined in the "windows.pas" unit - the one included by default in the uses clause of every Delphi form, the MessageBox function creates, displays, and operates a message box. The message box contains an application-defined message and title, along with any combination of predefined icons and push buttons.

Here's how the MessageBox is declared:

 function MessageBox(   hWnd: HWND;   lpText,   lpCaption : PAnsiChar;   uType : Cardinal) : integer;
The first parameter, hwnd, is the Handle of the owner window of the message box to be created. if you create a message box while a dialog box is present, use a handle to the dialog box as the hWnd parameter.
The lpText and lpCaption specify the caption and the message text that gets displayed in the message box.

The uType parameter is the most interesting one. This parameter specifies the contents and behavior of the dialog box.


This parameter can be a combination of various flags.

An Example: System Modal Warning Box when the System Date/Time Changes

For an example of creating a system modal topmost message box I'll handle the Windows message that is dispatched to all the running applications when the system date/time changes - for example using the "Date and Time Properties" Control Panel applet.
The MessageBox function will be called as:

   Windows.MessageBox(     handle,     'This is a system modal message'#13#10'from an inactive application',     'A message from an inactive application!',     MB_SYSTEMMODAL or MB_SETFOREGROUND or MB_TOPMOST or MB_ICONHAND) ;
The most important piece is the last parameter. The "MB_SYSTEMMODAL or MB_SETFOREGROUND or MB_TOPMOST" ensures the message box is system modal, top most and becomes the foreground window.

MB_SYSTEMMODAL flag ensures that the user must respond to the message box before continuing work in the window identified by the hWnd parameter.
MB_TOPMOST flag specifies that the message box should be placed above all non-topmost windows and should stay above them, even when the window is deactivated.
MB_SETFOREGROUND flag ensures that the message box becomes the foreground window.
Well, that's it. :)

And now for the full example code (TForm named "Form1" defined in unit "unit1"):

unit Unit1;
 
 interface
 
 uses
   Windows, Messages, SysUtils, Variants, Classes,
   Graphics, Controls, Forms, Dialogs, ExtCtrls;
 
 type
   TForm1 = class(TForm)
   private
     procedure WMTimeChange(var Msg: TMessage) ; message WM_TIMECHANGE;
   public
     { Public declarations }
   end;
 
 var
   Form1: TForm1;
 
 implementation
 {$R *.dfm}
 
 procedure TForm1.WMTimeChange(var Msg: TMessage) ;
 begin
   Windows.MessageBox(
     handle,
     'This is a system modal message from an inactive application',
     'A message from an inactive application!',
     MB_SYSTEMMODAL or MB_SETFOREGROUND or MB_TOPMOST or MB_ICONHAND) ;
 end;
 
 end.
2016/01/13 15:35 2016/01/13 15:35
Article tag list Go to top
View Comment 0
Trackback URL :: 이 글에는 트랙백을 보낼 수 없습니다
 
 
 
 
: [1] ... [519][520][521][522][523][524][525][526][527] ... [1397] :
«   2018/07   »
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31        
전체 (1397)
출판 준비 (0)
My-Pro... (41)
여행 (42)
사는 ... (954)
블로그... (25)
My Lib... (32)
게임 ... (23)
개발관... (3)
Smart ... (1)
C Builder (0)
Object... (0)
VC, MF... (9)
Window... (1)
Open API (3)
Visual... (0)
Java, JSP (2)
ASP.NET (0)
PHP (4)
리눅스 (28)
Windows (26)
Device... (1)
Embedded (1)
게임 ... (0)
Web Se... (2)
Web, S... (19)
잡다한... (4)
프로젝트 (0)
대통령... (9)
Link (2)
Delphi (96)
Reference (1)
OpenSo... (5)
Apache (2)
Database (21)
프로그램 (0)
2018/05(21)
2018/04(20)
2018/03(22)
2018/02(12)
2018/01(28)