Migrating delphi Win32 code to Win64 with Delphi code, especially when using event handlers or an function taking a TPoint parameter: in Win32 this showed correct values for the point’s x and y coordinates, but in Win64 reading x and y gave ‘junk’ values or some time same as value pass to it.
In my case TDM_Point(Msg.lParam) Msg.lParam do have value {3997726 } and after casting to TPoint variable P contain { x=30,y=61} in win32 bit and in win64 Msg.lParam do have value {3997726 } as same in win32 but after casting to TPoint variable P contain {x=3997723,y=0} )
Conditional defined as follows:
{$IFDEF WIN32}
TDM_Point = TSmallPoint;
{$ELSE}
TDM_Point = TPoint;
{$ENDIF}
Sample code as follows :
Function process
begin
If Form.Handle = Msg.hWnd Then
begin
Control := SearchControl ( Form, TDM_Point(Msg.lParam) );
//Msg is type of tagMSG
end
end
Function Form.SearchControl ( Parent : tWinControl; P : TDM_Point ) : tControl;
Var
Index : Integer;
Control : tControl;
Rect : tRect;
tmpPoint : TPoint;
Begin
//code
end
Msg value is set by value return by Process Message
[UIPermission(SecurityAction.LinkDemand, Window=UIPermissionWindow.AllWindows)]
procedure TApplication.HandleMessage;
var
Msg: TMsg;
begin
if not ProcessMessage(Msg) then Idle(Msg);
end;
Value is set as follows :
If Drawing Then
Begin
{$IFNDEF WIN32}
{ Map coordinates to parent of chosen control,
or to form in no control is chosen }
If EditControls.Count > 0 Then
MapWindowPoints ( Msg.hWnd,
tControl(EditControls.Objects[0]).Parent.Handle,
Msg.lParam, 1 )
Else
MapWindowPoints ( Msg.hWnd, fEditForm.Handle,
Msg.lParam, 1 );
{$ELSE}
x:=GetSystemMetrics(SM_CXFRAME);
if abs((Msg.Pt.X-fEditForm.left-x) - TDM_Point(Msg.lParam).X) > 0 then
TDM_Point(Msg.lParam).X:=Msg.Pt.X-fEditForm.left-x;
x:=GetSystemMetrics(SM_CYCAPTION)+GetSystemMetrics(SM_CYFRAME);
if abs((Msg.Pt.Y-fEditForm.top-x) - TDM_Point(Msg.lParam).Y) > 0 then
TDM_Point(Msg.lParam).Y:=Msg.Pt.Y-fEditForm.top-x;
{$ENDIF}
Start.X := TDM_Point(Msg.lParam).X;
Start.Y := TDM_Point(Msg.lParam).Y;
Last := Start;
SetSelection;
SetClipRect;
End;
please find the call stack below. we did not prepare any message. this is prepared by system when we click on label control of the form.
top two functions of call stack are our functions,in which we get the msg value from processmessage of vcl.forms