.


:




:

































 

 

 

 


Windows




4 .

: Windows .

: IBM Pentium 166 .

: Windows 95, 98 NT, Delphi 4 .

:

- Windows;

- , ;

- .

1. Windows . 21 , .

. 21

. Windows ,
  WM_LBUTTONDOWN
  WM_LBUTTONDBLCLK ,
  WM_RBUTTONUP (BorderStyle)
  WM_MOUSEMOVE
  WM_RBUTTONDBLCLK
  WM_KEYDOWN є,
  WM_KEYUP

 

2. , , , .

3. . 22, , .

. 22

. , ,
  TLabel
 
  TLabel
 
  TLabel
 
 

 

.1. Windows , Windows . , , ( , , ..) Windows.

Windows , :

- Handle , ;

- Msg (16 ) () , ;

- lParam wParam (16 32 ) .

, , Msg WM_LBUTTONDOWN, wParam , lParam ( X 16- , Y 16- ).

, Msg WM_KEYDOWN, wParam ASCII , lParam - .

lParam wParam , . , Delphi, Message. , TWMMouse, :

 

Type TWMMouse = record

Msg: Cardinal; { wParam}

Keys: Longint; { wParam}

Case Integer of

0: XPos: SmalInt; { X Y}

YPos: SmalInt;

1: Pos: TSmallPoint; { ]

Result: LongInt; { }

end;

 

Message TWMKey

 

TWMKey = record

Msg: Cardinal; { }

CharCode: Word; {ASCII }

Unused: Word; { }

KeyData: Longint; { }

Result: Longint; { }

end;

 

Windows :

 

procedure Handle_Name (var Msg: TMessageType); message WM_XXX;

 

HandlerName ; Msg , TMessageType - , , message , , WM_XXX - , Windows.

: , .

 

Type

TForm1 = class (TForm)

private

procedure WMRButtuonDown (var Msg: TWMMouse);

message WM_RbuttonDown;

.

end; {TForm1}

 

implementation .

 

procedure TForm1.WmrButtonDown(var Msg: TWMMouse);

begin

MessageDlg( ,mtInformation,[mbOk],0);

end;

 

Delphi , , , . . , .

.2. Delphi , . OnMessage Application, . OnMessage, , .

. OnMessage (MainF).

 

type

TForm1 = class (TForm)

private

procedure ProceedMessage (var Msg:TMsg; var Handled: Boolean);

published

procedure FormCreate (Sender: TObject);

end; {Form1}

..

implementation

procedure TForm1.FormCreate (Sender: TObject);

begin

Application.OnMessage:=ProceedMessage;

end;

procedure TForm1.ProceedMessage (var Msg:TMsg; var Handled: Boolean);

begin

Handled:=False;

If Msg.Message = WM_LBUTTONDBLCLK then

begin

MessageDlg( ,mtInformation,[mbOk],0);

Handled:=True;

end;

end;

 

, , .

, TMsg, Windows:

 

tagMSG = packed record

hwnd: HWND;

message: UINT;

wParam: WPARAM;

lParam: LPARAM;

time: DWORD;

pt: TPoint;

end;

TMsg = tagMSG;

 

hwnd , wParam lParam .

, , :

 

with Msg do

begin

x:=lo(Msg.lParam); { X}

lParam:= lParam shr 16; { 16 }

{ TCoord, Y ]

//y:=lo(TCoord(lParam).ypos);

y:=lo(lParam); { Y}

MessageDlg(' '+IntTostr(x)+:IntToStr(y)+' ',mtInformation,[mbOk],0);

end;

TCoord :

type tCoord = record

xpos:word;

ypos:word;

end;

 

, - , .

:

 

if Msg.hwnd = Form3.Handle then

begin

if Msg.Message = WM_KeyDown then

.

 

.3. Delphi Windows, . , :

- ;

- .

, . Windows 1024 . WM_APP, Messages, .

:

WM_MYMESSAGE = WM_APP+400;

, . (wParam, lParam ..) TMessage.

( ) , , . , Delphi File½New Unit, . interface , Messages.

, , . :

- protected ;

- ;

- var ;

- , implementation ;

CM_CHANGECOLOR.

 

type

TMyForm = class (TForm)

protected

procedure CMChangeColor (var Msg: TMessage); message CM_CHANGECOLOR;

..

end; {TMyForm}

implementation

procedure TMyForm.CMChangeColor(var Msg: TMessage);

begin

Color:=Msg.lParam;

Inherited;

end;

, , , , , . Events , , .

Windows API SendMessage PostMessage.

SendMessage PostMessage , , SendMessage , , PostMessage , .

SendMessage PostMessage , :

 

BOOL PostMessage(

HWND hWnd, // ,

UINT Msg, //

WPARAM wParam, //

LPARAM lParam //

);

LRESULT SendMessage(

HWND hWnd, // ,

UINT Msg, //

WPARAM wParam, //

LPARAM lParam //

);

 

: , , lParam , .

 

procedure TForm2.FormClick(Sender: TObject);

var color:integer;

begin

color:=Random(10000);

PostMessage(Form3.Handle,WM_MYMESSAGE,0,color);

end;

 

, , , , , , , .

1. Windows ?

2. ?

3. Ka ?

4. ?

5. ?

6. ?

7. SendMessage PostMessage?

 

5





:


: 2016-11-24; !; : 509 |


:

:

- , 20 40 . - .
==> ...

1645 - | 1596 -


© 2015-2024 lektsii.org - -

: 0.052 .