Sign in to follow this  
Followers 0

Overide Maximum Window Height?

4 posts in this topic

#1 ·  Posted (edited)

I'm trying to create a keyboard macro that will toggle the currently active window between maximized mode and fullscreen mode.

The way it works is to offset the position of the window just far enough off the screen to only the window content shows without the title bar or menu showing.

The window width gets changed fine but the bottom of the window is still some 10-20 pixels from the bottom of the screen.

The problem is that windows has a maximum window size and I heed just a bit more height than that size. From the AutoIt help file entry for WinMove:

If width and height are large, the window will go no larger than approximately [12+@DesktopWidth] x [12+@DesktopHeight] pixels.

What I want to know is if there is ANY way to overide this maximum in the registry or some way to temporarily trick windows into thinking I'm running a larger resolution whilst I change the window size.

Failing that, could I use AutiIt to remove the caption and borders of the window somehow? Presumably if I did that I would still have to live with a menu bar at the top though. What I really want is a script that lets me make any application I choose fullscreen.

For reference, here is the function so far - couldn't get much simpler really:

Func macro_fullscreen()
  Dim $hwnd,$size,$posx,$posy,$sizex,$sizey
 ; $posy = -25; with menu bar still visible
  $posy = -44; with menu bar hidden too
  $posx = -5
  $sizex = 10 + @DesktopWidth
  $sizey = 20 + @DesktopHeight - $posy
  $hwnd = WinGetHandle("", "")
  $size = WinGetPos("")
  if (($size[0]>$posx) And ($size[1] > $posy)) Then

PS. I've only tried it with the clasic windows XP theme running at 1280x1024. You may need to do some trial-and-error tweaking if you want to run it with a different setup.

Edited by eviloverlord

Share this post

Link to post
Share on other sites

#2 ·  Posted (edited)

Ok, looks like I was on the wrong track. I've been reading that setting the window style properties WS_BORDER and WS_CAPTION off then resizing the window to desktop size will make the window fullscreen like I need.

Problem is how to set those style flags in realtime for a running non-autoit application window, knowing only it's window handle.

Currently, I'm trying the following:

Func macro_fullscreen()
  Const $GWL_STYLE = -16
  Const $WS_BORDER = Dec("H800000")
  Const $WS_CAPTION = Dec("HC00000")
  Const $WS_MAXIMIZED = Dec("H1000000")
  $hwnd = WinGetHandle("", "")
  msgbox (0,"hwnd",$hwnd,3)
  $winlong = DllCall("user32.dll","long","GetWindowLong","hwnd",$hwnd,"int",$GWL_STYLE)
  msgbox (0,"old",$winlong)
  $winlong = BitXOR($winlong,$WS_BORDER,$WS_CAPTION); Toggle the border and caption flags
  msgbox (0,"new",$winlong)
;$result = DllCall("user32.dll","long","SetWindowLong","hwnd",$hwnd,"int",$GWL_STYLE,"long",$winlong)
  WinMove($hwnd,"",0,0,@DesktopWidth,@DesktopHeight); maximize the window - could change this to use WS_MAXIMIZED later

You'll notice that the 2nd DllCall is commented out because otherwise it will mess up the properties of the active window as it isn't doing what I think it should be.

The first message box shows the window handle. This seems to be getting correctly set.

The 2nd message box shows the old window style. This does not seem to get retrieved at all.

The 3rd message box shows the result of toggling the two style flags I need to change. Needless to say this won't work until the first DllCall succeeds.

Could someone more familiar with DllCall possibly give me an idea where I'm going wrong here? The syntax for my GetWindowLong call must be wrong somehow but it seems to match the MSDN syntax.

Edited by eviloverlord

Share this post

Link to post
Share on other sites

#4 ·  Posted (edited)

this might help with the non-autoit AnyGUI

Excellent! Many thanks gafrost. :think:

Looking over that code I see I that it seems to return an array of which I should access the zeroth element. Why is anyone's guess since I expected a long.

Anyway, for the benefit of anyone who wants to make active windows fullscreen, here's the code:

#include <GUIConstants.au3>
Func macro_fullscreen()
; Make the active window fullscreen.
  Const $GWL_STYLE  = -16
  Const $GWL_EXSTYLE  = -16
  Const $SWP_NOMOVE = 0x0002
  Const $SWP_NOSIZE = 0x0001
  Const $SWP_NOZORDER = 0x0004
  Const $SWP_FRAMECHANGED = 0x0020
  $hwnd = WinGetHandle("", "")
  if ($hwnd<>0) Then
  ; Toggle windows styles
    $winlong = DllCall("user32.dll","long","GetWindowLong","hwnd",$hwnd,"int",$GWL_STYLE)
    $winlong = BitXOR($winlong[0],$WS_CAPTION, $WS_BORDER, $WS_THICKFRAME); Toggle the border, frame and caption flags
    $result = DllCall("user32.dll","long","SetWindowLong","hwnd",$hwnd,"int",$GWL_STYLE,"long",$winlong)
  ; Toggle extended styles
    $winlong = DllCall("user32.dll","long","GetWindowLong","hwnd",$hwnd,"int",$GWL_EXSTYLE)
    $winlong = BitXOR($winlong[0],0);
    $result = DllCall("user32.dll","long","SetWindowLong","hwnd",$hwnd,"int",$GWL_EXSTYLE,"long",$winlong)
  ; Maximize and refresh display
    DllCall("user32.dll", "long", "SetWindowPos", "hwnd", $hwnd, "hwnd", $hwnd, "int", 0, "int", 0, "int", @DesktopWidth, "int", @DesktopHeight, "long", BitOR($SWP_NOZORDER, $SWP_FRAMECHANGED))
    msgbox(0,"Error","Failed to get active window handle")

When you call the function a 2nd time it will change the window from fullscreen mode to maximized mode.

Now all I need to do is work out how to hide the menu bar.

Edited by eviloverlord

Share this post

Link to post
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
Sign in to follow this  
Followers 0