0

Using the next answer I am trying to programmatically reposition a citrix window, somehow the window does not move.

I assume the process name that holds the Citrix window is one of the next processes that were added in Process.GetProcesses() after I started Citrix: Receiver, wfica32, pnamain, concentr, wfcrun32.

any help why the window does not move?

IntPtr hWnd = IntPtr.Zero;
var p1 = Process.GetProcesses().Where(p => p.Id != 0 && p.ProcessName == _processToRepositionWindowName).FirstOrDefault();
if (p1 != null && p1.MainWindowHandle != IntPtr.Zero)
{
     hWnd = p1.MainWindowHandle;
     //tried both options
     //hWnd = p1.Handle; 
}
else
{
      hWnd = FindWindow(_processToRepositionWindowName, null);
      if(hWnd == IntPtr.Zero)
      {
           hWnd = FindWindow(null, _processToRepositionWindowName);
      }
}

if (hWnd != IntPtr.Zero)
{
     var i = SetWindowPos(hWnd, IntPtr.Zero, windowXLocation, windowYLocation, 0, 0, SWP_NOSIZE | SWP_NOZORDER | 0x0040);
}
Avishay
  • 197
  • 9
  • the var i gets a result of 'true' when I use _processToRepositionWindowName="wfica32" and its 'MainWindowHandle' which means the moving operation was a success but still the window stay at same positioin – Avishay May 30 '18 at 05:48

1 Answers1

0

I have had the same issue a couple times (And not only with Citrix windows...).

You need to send an EnterSizeMove message before calling SetWindowPos. Ideally, you need to close with a ExitSizeMove message (Although I have skipped this last step a couple times).

I code in Java, but the issue is the same in any language:

User32.instance.SendMessageA(hwnd, User32.WM_ENTERSIZEMOVE, 0, 0);
User32.instance.SetWindowPos(hwnd, hwndTopMost, x, y, 0, 0, flags);
User32.instance.SendMessageA(hwnd, User32.WM_EXITSIZEMOVE, 0, 0);

I came to this solution from an AutoHotKey forum.

RtmY
  • 7,115
  • 6
  • 51
  • 64