Jump to content

Help with a AHK to AutoIT Conversion


Recommended Posts

I use a 3 monitor setup at work and remote into other servers on the regular.  

For the longest I used only one monitor for RDP and that was terrible because when I do a support session from that RDP session I have no space left to use for documents.

I recently enabled the "use all monitors" feature and now the RDP session spans all 3 monitors, ends up that is not much better as I usually have a ticket or other important information on my host computer so I end up having to minimize and restore the RDP session over and over to get the details I want.

The real solution for me is going to be a RDP session with 2 monitors and leaving my 3rd untouched.  Looks like there is no "real" way to do this.  But I did find a work around using AHK.

ere is my work around for my 3x1 setup to use 2 monitors with a similar experience:

edit the RDP file for the resolution I'm looking for.  Turn off multi monitor and turn off smart screen sizing (not really required)

screen mode id:i:1
use multimon:i:0
desktopwidth:i:3840
desktopheight:i:1080
smart sizing:i:0
Next I use auto hot key to make the app appear like a full screen, borderless app.  Windows+F11 resizes the window to desktop 2 and 3 and removes the border.  Win+f12 restores the border for easy move.

Just FYI, the RDP client is odd in that it captures all key strokes so I had to use the class name of the window to target it.  You cannot have the app active.  Just select the desktop or another app and then hit win+F11 or win+F12.  Also, make sure the window is not maximized.

Here is the ahk script:
#f11::
WinSet, Style, -0xCF0000, ahk_class TscShellContainerClass
WinMove ahk_class TscShellContainerClass,, 0,0,3840,1080
return
#f12::
WinSet, Style, +0xCF0000, ahk_class TscShellContainerClass
return

So I looked and I know we have WinSetState() and WinMove() but I cant see how to recreate t he Set Style portion, where the window border is removed.  I know we have GUI functions for that, but how to do that for a normal window?

This is the closest I have found so far I think:

Func _API_SetWindowLongPtr($hWnd, $iIndex, $iValue)
  Local $aResult
  $aResult = DllCall("User32.dll", "int", "SetWindowLongPtr", "hwnd", $hWnd, "int", $iIndex, "int", $iValue)
  Return $aResult[0]
EndFunc

And used these pages for reference: 

https://msdn.microsoft.com/en-us/library/ms644898.aspx

https://msdn.microsoft.com/en-us/library/ms632600.aspx

My testing script

 

#RequireAdmin
$hWnd = WinGetHandle("Untitled - Notepad", "")

_API_SetWindowLongPtr($hWnd, -16, "0x00040000L")

Func _API_SetWindowLongPtr($hWnd, $iIndex, $iValue)
  Local $aResult
  $aResult = DllCall("User32.dll", "int", "SetWindowLongPtr", "hwnd", $hWnd, "int", $iIndex, "int", $iValue)
  Return $aResult[0]
EndFunc

However no luck so far, not sure what I am doing wrong.

Link to comment
Share on other sites

Hello. AutoIt does not use "L" suffix.

 

#include <WinAPI.au3>
#RequireAdmin
Global Const $WS_SIZEBOX = 0x00040000
Global Const $GWL_STYLE = -16

Local $hWnd = WinGetHandle("Untitled - Notepad", "")
_WinAPI_SetWindowLong($hWnd, $GWL_STYLE, $WS_SIZEBOX)

Saludos

Edited by Danyfirex
Link to comment
Share on other sites

I don't know what you're trying to achieve but I think is WS_OVERLAPPED.

Check Window Styles link you posted above.

Saludos

Link to comment
Share on other sites

Well, made progress but still stuck.

Seems no matter what style I apply I just lose the title and all the buttons on the window, it becomes static in the background and nothing on the window can be interacted with any longer.

 

Edit: looks like I needed to append it to the current style.

This is pretty much working the way I wanted it too.

 

#Include <WinAPI.au3>
#Include <WindowsConstants.au3>
HotKeySet("{F11}", "Borderless")
HotKeySet("{F10}", "Bordered")
HotKeySet("{F9}", "Minimize")

GLOBAL $hWnd = WinGetHandle("[CLASS:TscShellContainerClass]")
GLOBAL $Style = _WinAPI_GetWindowLong($hWnd, $GWL_STYLE)



;_WinAPI_SetWindowLong($hWnd, $GWL_STYLE, $WS_OVERLAPPEDWINDOW)
;_WinAPI_SetWindowLong($hWnd, $GWL_STYLE, BitOr($Style, $WS_OVERLAPPEDWINDOW))

While 1
    Sleep(10)
WEnd

Func Borderless()
_WinAPI_SetWindowLong($hWnd, $GWL_STYLE, BitXOR($Style, 0xCF0000))
WinMove($hWnd, "", -1920, 0, (1920*2), 1080)
EndFunc

Func Bordered()
_WinAPI_SetWindowLong($hWnd, $GWL_STYLE, $Style)
WinMove($hWnd, "", -1920, 0, (1920*2), 1080)
EndFunc

Func Minimize()
    WinSetState($hWnd, "", @SW_MINIMIZE)
EndFunc

 

Edited by ViciousXUSMC
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...