Move Left...

Hello, I have a HWND how can I set the left.

e.g
Form1.Left:= 100;
MyHWND.Left:= 100;

Thanks.
LVL 2
-Karamja-Asked:
Who is Participating?
 
LMuadDIbConnect With a Mentor Commented:
use API "MoveWindow"

example:

procedure TForm1.Button1Click(Sender: TObject);
var
  FWnd: HWND;
  iLeft ,iTop,iWidth,iHeight : integer;
begin
  FWnd := form1.Handle;
  iLeft := 0; { or whatever }
  iTop:= 0;
  iWidth:= 100;
  iHeight := 100;
  MoveWindow(FWnd, iLeft ,iTop,iWidth,iHeight,true) ;
end;
0
 
Colin_DawsonCommented:
You need to use the GetWindowPos and SetWindow pos API calls.

Call GetWindowPos to get all the position information for the window, then use SetWindowPos to move the window.  Changing the left parameter to 100 of course ;-)

0
 
-Karamja-Author Commented:
Thanks for the reply,

I dont want to beable to resize the window, Just move.
Would there be a way to get the current, Width & Height?
0
 
Colin_DawsonConnect With a Mentor Commented:
oops, there's no get windowPos.
 Replace Handle with your HWND and this will work.


var
  lpRect: TRect;
begin
  GetWindowRect(Handle,lpRect);

  MoveWindow(Handle,100,
    lpRect.Top,
    lpRect.Right-lpRect.Left,
    lpRect.Bottom-lpRect.Top,
    True);
end;
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.