Delphi XE2 out for a while, inside more eye-catching things, in addition to vclstyle this skin-changing things, and the most people should be the eyes of the FMX is the thing. In case the blog has a vote on the use of the FMX experience. I still do not pay attention to, because technology this thing, every day in change, followed him to run, I hurt Ah! To this day, I looked at the box, and some people in the group said there was a question about how FMX could send messages under Windows, saying it couldn't be sent. In fact, the FMX is a cross-platform GUI class library, the message is just under Windows, so sending a message should not be considered generic. However, research should allow windows,linux to be integrated into a common library.
Just create a FMX application, put a few buttons on it, and then we'll track it, first look at application, and we can find his implementation in the Fmx.forms unit, and the implementation of his and VCL application is not a thing. Send a message, then first we should think of a few commonly used function processmessages,handlemessage, follow up to see it until, then can find Handlemessage implementation
function TApplication.HandleMessage:Boolean;
Begin
Result: = Platform.handlemessage;
If not Result then
Idle;
End
There is a platform, it is obvious that this should be the operating period according to different system platform invoke different implementation mechanism, we are Windows platform, so run to his source directory to look at, Can find a very obvious name FMX.Platform.Win, right, in this implementation. Look at the implementation of Tplatformwin this thing, I think if familiar with Win32 programming, this should be very clear. No more, and then we look at the creation of the form find fmx.forms in the CreateHandle this thing, and the above handlemessage a similar realization
Procedure Tcommoncustomform.createhandle;
Begin
Fhandle: = Platform.createwindow (self);
If tfmxformstate.fsrecreating in FormState then
Platform.setwindowrect (self, RECTF (left, top, left + Width, top + Height));
End
are related to the platform platform. However, the FMX of this package structure is quite reasonable, look at the code so that people can be at a glance, do not say nonsense, and then to see the implementation of the Tplatformwin CreateWindow. The implementation of this is almost the same as our vcl, and then our main thing is to look at his last face with a
Result: = Newfmxhandle;
Fhwndmap.add (Result, Wnd); Such an implementation, that is, the return of the CreateHandle after the form handle is not created, but the FMX managed by a handle index. So here we are until the handle of the FMX form is not the window handle but an index that FMX manages. As for how to get the real handle of the window, at the beginning of the FMX.Platform.Win, a function is provided that can be implemented. function Fmxhandletohwnd (fmxhandle:tfmxhandle): HWND; This is the index to get the real Win32 window handle. These are all finished, then we can begin to elaborate, the FMX of this message mechanism, the first to play our brains to think, under Windows, you do anything to pass through the message. So the FMX certainly has a message circulating, this is necessary. But many people said, the FMX message can't send, why, oh this is the most important, I have said before, first of all, this Win32 handle, you change out of the words, then you must be the message is sent successfully, otherwise, certainly failed. Then we look at the simplest one mouse click message, the mouse point button on the form will trigger the Click event, then the mouse message of this button is how to circulate, we first find the button of the base class, keep up, you can find the control of FMX is his own set of ways to achieve, But I didn't see Win32 's message. Encapsulation function, at this time we are in the brain to think about, FMX control from top to bottom no longer through the WIN32 to create a standard method, and the FMX control does not have a handle, then we should be able to think of, FMX's full set of control messages are implemented through his parent form as a mediator, so we directly find the MouseDown process in the form implementation of FMX and see how he implements it.
Procedure Tcommoncustomform.mousedown (Button:tmousebutton; Shift:tshiftstate; X, Y:single);
Var
p:tpointf;
R:TRECTF;
Obj:icontrol;
Sg:isizegrip;
I:integer;
Begin
{Translate coord}
Fmousepos: = PointF (X, Y);
Fdownpos: = Fmousepos;
{Event}
OBJ: = IControl (Objectatpoint (ClientToScreen (Fmousepos)));
if (Obj <> nil) Then
Begin
if (IInterface (OBJ). QueryInterface (Isizegrip, SG) = 0) Then
Startwindowresize
Else
Begin
P: = Obj.screentolocal (ClientToScreen (PointF (fmousepos.x, Fmousepos.y)));
Obj.mousedown (Button, Shift, p.x, P.Y);
if (Obj.dragmode = tdragmode.dmautomatic) Then
Obj.beginautodrag;
End
End
End
It is very clear that he will get the FMX control of the mouse down position, and then if the control is obtained by invoking the MouseDown method of the control, so here, it should be clear to know that the FMX message is passed through form as a medium, then, We can send the message by using the form to turn our message, so we first trigger the OnClick event of a button with a message. Put 2 buttons, then send a message to the form, send a down message and then send an up message, which constitutes a click event
SendMessage (Fmxhandletohwnd (Handle), Wm_lbuttondown,mk_lbutton,makelong (trunc (button1.position.x + 3), trunc ( BUTTON1.POSITION.Y + 3)));
SendMessage (Fmxhandletohwnd (Handle), Wm_lbuttonup,mk_lbutton,makelong (trunc (button1.position.x + 3), trunc ( BUTTON1.POSITION.Y + 3)));
And then trigger it, we'll find that it doesn't seem to trigger the onclick event, and guess it failed? And we're looking for the mouseup process of the controls.
Procedure Tcontrol.mouseup (Button:tmousebutton; Shift:tshiftstate; X, Y:single);
Begin
ReleaseCapture;
If Assigned (fonmouseup) Then
Fonmouseup (self, Button, Shift, X, Y);
If fpressed and not (Fdoubleclick) and Pointinrect (PointF (X, Y), Localrect) Then
Begin
fpressed: = False;
Click;
End
fpressed: = False;
Fdoubleclick: = False;
End
There is a judgment Pointinrect (PointF (X, Y), Localrect), it is possible to know that this object only triggers the OnClick event when the cursor is in the mouse control position. This, you can think of a way to use a timer control in the timer's OnTimer to add the above message to send the code, and then run the mouse to move the button, wait a minute will trigger the button's OnClick event.
I think here, everyone should know how to send a message to the FMX! In a word, simulation!
The message processing process for FMX in FMX.Platform.Win
function WndProc (hwnd:hwnd; umsg:uint; wparam:wparam; lparam:lparam): LRESULT; stdcall;
Function!
Http://www.cnblogs.com/DxSoft/archive/2011/09/27/2192795.html
A little bit of research on the FMX of Delphi XE2