Recent

Author Topic: WindowPos access violation (message LM_WINDOWPOSCHANGED)  (Read 2631 times)

elioenaishalom

  • New Member
  • *
  • Posts: 28
WindowPos access violation (message LM_WINDOWPOSCHANGED)
« on: April 19, 2014, 11:44:49 pm »
Please,
if you can help, thanks in advance.
I tried to control the MainForm position (top and left) through the procedure bellow.
Problem is : If the form move a pixel the app return Access violation, what am I doing wrong ?
Code: [Select]
{procedure WindowPosChanged(var Msg: TLMessage); message LM_WINDOWPOSCHANGED;}
procedure TMainForm.WindowPosChanged(var Msg: TLMessage);
var
  vx, vy: integer;
  P: ^WindowPos;
begin
  P := Pointer(Msg.LParam);
  Vx := P^.x;
  Vy := P^.y;
  StatusBar1.Panels[0].Text := IntToStr(Vx);
  StatusBar1.Panels[1].Text := IntToStr(Vy);
end;
(Lazarus 1.0.6 - Windows7)

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: WindowPos access violation (message LM_WINDOWPOSCHANGED)
« Reply #1 on: April 19, 2014, 11:57:21 pm »
Try to use the existing mechanisms as much as possible this way you are going to be fairly sure that the code will be supported in most /all platforms LCL can go so do something along the lines of
Quote
{procedure WindowPosChanged(var Msg: TLMWindowPosChanged); message LM_WINDOWPOSCHANGED;}
procedure TMainForm.WindowPosChanged(var Msg: TLMWindowPosChanged);
var
  vx, vy: integer;
begin
  Vx := Msg.WindowPos^.x;
  Vy := Msg.WindowPos^.y;
  StatusBar1.Panels[0].Text := IntToStr(Vx);
  StatusBar1.Panels[1].Text := IntToStr(Vy);
end;

That should work.
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

elioenaishalom

  • New Member
  • *
  • Posts: 28
Re: WindowPos access violation (message LM_WINDOWPOSCHANGED)
« Reply #2 on: April 20, 2014, 12:16:46 am »
Thanks for reply but I changed code and not worked (same error).

engkin

  • Hero Member
  • *****
  • Posts: 3112
Re: WindowPos access violation (message LM_WINDOWPOSCHANGED)
« Reply #3 on: April 20, 2014, 12:37:49 am »
Code: [Select]
procedure TMainForm.WindowPosChanged(var Msg: TLMessage);
var
  vx, vy: integer;
  P: ^WindowPos;
begin
  P := Pointer(Msg.LParam);

  if not assigned(p) then exit;

  Vx := P^.x;
  Vy := P^.y;
  StatusBar1.Panels[0].Text := IntToStr(Vx);
  StatusBar1.Panels[1].Text := IntToStr(Vy);
end;

Edit:
It comes from:
Code: [Select]
procedure TWinControl.SendMoveSizeMessages(SizeChanged, PosChanged: boolean);
..
  Perform(LM_WindowposChanged, 0, 0);
« Last Edit: April 20, 2014, 12:47:01 am by engkin »

elioenaishalom

  • New Member
  • *
  • Posts: 28
Re: WindowPos access violation (message LM_WINDOWPOSCHANGED)
« Reply #4 on: April 20, 2014, 12:47:51 am »
Works !!!

thanks very much.

 

TinyPortal © 2005-2018