Home > Back-end >  News about Delphi management
News about Delphi management

Time:09-16

1, in order to model the form way, pop-up a child form;
2, when the mouse moves on child form, will be the location of the mouse, the window location and the current time, in the form of news (synchronous) shown in the main form of Caption;
Knowledge: use sendmessage send record structure,

CodePudding user response:

Suggest using PostMessage method, need not blocked, the message can use LParam to pass a pointer to the structure of, however, since it is the same process, can also direct access to the main body of the Handle and then send the SetWindowText message displayed directly

CodePudding user response:

 
The unit Unit1;

Interface

USES the
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, StdCtrls;

Type
TForm1=class (TForm)
Label1: TLabel;
For: TButton;
Procedure Button1Click (Sender: TObject);
Private
{Private declarations}
Public
{Public declarations}
end;

Var
Form1: TForm1;

Implementation

{$R *. DFM}

USES the
Unit2.

Procedure TForm1. Button1Click (Sender: TObject);
The begin
Form1Handle:=Self. Handle;
Form2. ShowModal;
end;

End.

 
The unit Unit2.

Interface

USES the
Windows, Messages, SysUtils, Classes, Graphics, Controls, and Forms;

Type
TForm2=class (TForm)
Procedure FormMouseMove (Sender: TObject; Shift: TShiftState; X, Y: Integer);
end;

Var
Form2: TForm2;
Form1Handle: HWND;

Implementation

{$R *. DFM}

Procedure TForm2. FormMouseMove (Sender: TObject; Shift: TShiftState; X, Y: Integer);
Var
S: a String;
The begin
S:=Format (' Mouse: [] % d, % d, Form2: [% d, % d, % d, % d], Time: ', [X, Y, Left, Top, Width, Height));
S:=S + FormatDateTime (' yyyy - mm - dd_hh: nn: ss ', Now);
SetWindowText (Form1Handle, PChar (S));
end;

End.

CodePudding user response:

Supermantm, hello, how can I make a mistake? Really depressed! Appear the following error: Undeclared identifier: 'Form1Handle', in addition the key is to use: use sendmessage send record structure,

CodePudding user response:

The
reference 3 floor weixin_39864128 response:
supermantm, hello, how can I make a mistake? Really depressed! Appear the following error: Undeclared identifier: 'Form1Handle', and the key is to use: use sendmessage send record structure,

You in Unit1 unit implementation USES Unit2 oh, otherwise this identifier is invalid in Unit1,
You don't want to let Form1 caption displayed on the information? Why can directly setWindowText must also sendMessage?
If is the nature of work, then please independently, if your application problems, I the above code is tested

CodePudding user response:

send record structure using sendmessage,

CodePudding user response:

Second, message management
1, in order to model the form way, pop-up a child form;
2, when the mouse moves on child form, will be the location of the mouse, the window location and the current time, in the form of news (synchronous) shown in the main form of Caption;
Knowledge: use sendmessage send record structure,
Try to create a child form, complete 1, 2 in child form; In addition to use sendmessage send record structure,

CodePudding user response:

Hello, I run the program, you wrote in the form1 to display, but this information should be displayed in form2, not form1, additional variables with record creation show that must use sendmessage to execute

CodePudding user response:

Learn to are needed

CodePudding user response:

If you don't use SendMessage USES PostMessage, can allocate memory when sending data, release the memory, after receive the message and processing effect and SendMessage,

CodePudding user response:

Directly on the code, belongs to the technical point code, the code doesn't do specification
Ideas: traverse to the child forms the cursor position and form location in structure such as time, sendMessage direct structure pointer to the main form,

Main form code
 
The unit Unit1;

Interface

USES the
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Unit2;

Type
TForm1=class (TForm)
For: TButton;
Procedure Button1Click (Sender: TObject);
Private
{Private declarations}
Procedure OnFormPositionMessage (var MSG: TMessage); The message WM_FORM_INFO;
Public
{Public declarations}
end;

Var
Form1: TForm1;

Implementation

{$R *. DFM}

Procedure TForm1. Button1Click (Sender: TObject);
Var
FM: TForm2;
The begin
Try
FM:=TForm2. Create (self);
FM. ShowModal;
The finally
FM. Free;
end;
end;

Procedure TForm1. OnFormPositionMessage (var MSG: TMessage);
Var
Pos: TFormPosition;
The begin
Pos:=PFormPosition (MSG. WParam) ^;
Self. Caption:=Format (' mouseY mouseX: % d: % d ', [pos. MouseX, pos. MouseY]);
//display more content to add
end;

End.


Child form code
 
The unit Unit2.

Interface

USES the
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs.

Const
WM_FORM_INFO=WM_USER + 100;

Type
PFormPosition=^ TFormPosition;
TFormPosition=record
MouseX: integer;
MouseY: integer;
FormTop: integer;
FormLeft: integer;
NowTime: TDateTime;
end;

Type
TForm2=class (TForm)
Procedure FormMouseMove (Sender: TObject; Shift: TShiftState; X, Y: Integer);
Private
{Private declarations}
Public
{Public declarations}
end;

Var
Form2: TForm2;

Implementation

{$R *. DFM}

Procedure TForm2. FormMouseMove (Sender: TObject; nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related