Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate

script to fullscreen any app?


  • Please log in to reply
13 replies to this topic
mackal2
  • Guests
  • Last active:
  • Joined: --
Hi all,

I am fairly sure that AHK can do this, but being an AHK newbie, I don't really know where to start, let alone know what the best way to do this is. What I want is to create a key combination that will allow me to maximize the currently active application so that it appears in fullscreen; that is, you only see the client area of the window, with the window title bar, borders, etc, hidden, and the taskbar out of view. Essentially I am trying to achieve the effect of apps such as Dark Room (http://they.misled.us/dark-room), but with an arbitrary application---well, I specifically want to replicate this effect with my favourite text editor, Vim...

Any help in getting the ball rolling would be greatly appreciated.

toralf
  • Moderators
  • 4035 posts
  • Last active: Aug 20 2014 04:23 PM
  • Joined: 31 Jan 2005
You can maximize windows pretty easily with WinMaximize or WinMove.
But it is more difficult to make a window bigger then the screen resolution. (Try to drag a window larger then it, by moving it first partly out of the screen to the lower right, then drag it bigger. It stops to get bigger at around screen resolution.)
Best solution would be to serach if that app supports full screen mode. Like F11 in Internet Explorer.
At the end you could try to use WinSet. Either hide parts of the window, but I'm not sure if you can then make the window larger. Or by sending Style,N or ExStyle,N. Maybe there is a Style that does what you want.
Ciao
toralf
 
I use the latest AHK version (1.1.15+)
Please ask questions in forum on ahkscript.org. Why?
For online reference please use these Docs.

Helpy
  • Guests
  • Last active:
  • Joined: --
You can WinMove to get the title bar and borders out of screen.
Example, with semi-random offsets:
Run Notepad.exe, , , npPID
WinWait ahk_pid %npPID%
WinMove ahk_pid %npPID%, , -5, -40, A_ScreenWidth + 40, A_ScreenHeight + 50


SKAN
  • Administrators
  • 9115 posts
  • Last active:
  • Joined: 26 Dec 2005
Run, %A_Windir%\Notepad.exe,,Min, PID
WinWait, ahk_pid %PID%
ID := WinExist("ahk_pid " PID)

WinMove, ahk_id %ID%,, 0,0
WinSet, Style, -0xC00000, ahk_id %ID% ; Remove Titlebar : WS_CAPTION
WinSet, Style, -0x40000 , ahk_id %ID% ; Remove Borders  : WS_SIZEBOX
WinSet, AlwaysOnTop , On, ahk_id %ID% 
WinMaximize, ahk_id %ID%

:)

Helpy
  • Guests
  • Last active:
  • Joined: --
It is clever as it is independent of decoration (caption, borders) size.
I don't see why you use ID instead of PID, both work fine, don't they?

Lexikos
  • Administrators
  • 9844 posts
  • AutoHotkey Foundation
  • Last active:
  • Joined: 17 Oct 2006

It is clever as it is independent of decoration (caption, borders) size.
I don't see why you use ID instead of PID, both work fine, don't they?

Using ID instead of PID makes the script more easily adaptable - for example, instead of:
ID := WinExist("ahk_pid " PID)
you could put
ID := WinActive("A")
to work with the active window. Of course, in this case you may as well replace "ahk_id %ID%" with "A"...

That's how I see it, anyway.

SKAN
  • Administrators
  • 9115 posts
  • Last active:
  • Joined: 26 Dec 2005

I don't see why you use ID instead of PID, both work fine, don't they?


They would. It is just my habit of using ahk_pid only for Process related operations. For Window/control related commands, I always use ahk_id even it costs me an extra line. :)

Also

In the code I had given, I know Notepad has only one GUI. There might be cases where the process can have more than two windows and the one that has focus will be returned.

You can test it with the following code:

PID := DllCall("GetCurrentProcessId")
Gui, 1:Show, x0   y0 w400 h100 , GUI 1
Gui, 2:Show, x420 y0 w400 h100 , GUI 2
Return
 
^F2::MsgBox, % WinExist( "ahk_pid " PID )
#x::ExitApp

So it is safe to fetch the ahk_id of the correct window and use it,

like: ^F2::MsgBox, % WinExist( "GUI 1 ahk_pid " PID )

Experimenting a bit on it, I find that if a process has an additional hidden GUI and DetectHidden windows is on, then ahk_pid might even report the ID of the hidden GUI.

#Persistent
DetectHiddenWindows, On
PID := DllCall("GetCurrentProcessId")
WinShow, % "ahk_id " WinExist( "ahk_pid " PID )

ID := WinActive("A")


It is less reliable! There is a minimal chance that someother app could take the focus resulting with undesired window ID.

:)

Lexikos
  • Administrators
  • 9844 posts
  • AutoHotkey Foundation
  • Last active:
  • Joined: 17 Oct 2006

It is less reliable! There is a minimal chance that someother app could take the focus resulting with undesired window ID.

If you mean it is less reliable to use WinActive after launching Notepad, I understand. My intention was to demonstrate how to use the active window, instead of a newly launched notepad.

In the code I had given, I know Notepad has only one GUI. There might be cases where the process can have more than two windows and the one that has focus will be returned.

IMHO, it's generally more useful to be able to "fullscreen any app" than to launch a specific app into fullscreen. If you're working with the active window, it doesn't matter how many windows the process has.

Btw, it isn't necessary to call WinSet,Style more than once when removing multiple styles:
WinSet, Style, -0xC40000, ahk_id %ID%
; Remove Titlebar : WS_CAPTION=0xC00000 and Borders : WS_SIZEBOX=0x40000
But I suppose having seperate command-calls is clearer, and easier to modify for those not familiar with styles.

It is just my habit of using ahk_pid only for Process related operations.

I have a habit of using the Last Found Window feature as much as possible. For example, you can do away with "ID":
Run, %A_Windir%\Notepad.exe,,Min, PID
WinWait, ahk_pid %PID%
WinExist("ahk_pid " PID)
; alternatively, replace the above THREE lines with:
WinActive("A")
; to fullscreen the active window

WinMove, 0,0  ; I'm not sure what the purpose of this line is...
WinSet, Style, -0xC40000 ; Remove Titlebar and Borders (WS_CAPTION | WS_SIZEBOX)
WinSet, AlwaysOnTop , On ; This doesn't seem quite necessary either, see below.
WinMaximize
Personally, I'd leave out AlwaysOnTop, so that the user can switch to another app while a window is "fullscreen." It seems that removing WS_SIZEBOX|WS_CAPTION and maximizing notepad causes it to hide the taskbar even when it isn't always-on-top (on Windows XP, at least.) When fullscreen notepad loses the focus, the taskbar returns...

Edit: Window positioning is a bit off if the window was already maximized, probably because the position is reported as -4,-4.

Grumpy
  • Guests
  • Last active:
  • Joined: --
Thanks, Skan, it makes sense... :-D

SKAN
  • Administrators
  • 9115 posts
  • Last active:
  • Joined: 26 Dec 2005

Thanks, Skan, it makes sense... :-D


I replied to Helpy and it is Grumpy who is thanking me :O :D

Grumpy
  • Guests
  • Last active:
  • Joined: --
Because I too was enlightened by your thinking, oh dear guru...

Ace_NoOne
  • Members
  • 299 posts
  • Last active: May 02 2008 08:19 AM
  • Joined: 10 Oct 2005
Just in case: The discussion on (and code for) this can be found over at the DonationCoder.com forums.

Also, when I find the time, I might use these methods in my Screen Switcher script...
Improving my world, one script at a time.
Join the AutoHotkey IRC channel: irc.freenode.net #autohotkey

mazy
  • Members
  • 1 posts
  • Last active: Feb 17 2008 01:36 PM
  • Joined: 04 Jan 2008
Nice topic! I've been dealing with similar problem some time ago and this is what I came with:

; ------------------------------------------------------------------------------
; active app full screen mode toggle
;   prerequisite: window has to be maximized

#1::
WinGet, acw_m, MinMax, A
if (acw_m = 1) {
	WinActive("A")
  WinGet, acw_s, Style
	if (acw_s & 0xC00000)
	{
		WinSet, Style, -0xC40000
		WinMove, , , 0, 0, %A_ScreenWidth%, %A_ScreenHeight%
	} else {
		WinSet, Style, +0xC40000
	}
}
return
As you can see, I made it work only on maximized active windows. I still have one problem: I have vertical taskbar on the left side of screen. Some applications, when made fullscreen using this script, offset their main menu popup menus horizontally to avoid the taskbar (even though it isn't visible as it is covered by the fullscreen window).

I tried to hide the taskbar, however that didn't help. Any ideas?

anjan_oleti
  • Guests
  • Last active:
  • Joined: --
I landed up with the following code after checking this topic and Winsupermaximize
#SingleInstance ignore

#`::TitleGo()

TitleGo() {
	global
	WinActive("A")
	WinGet, winId, ID

	if (isTitleGone_%winId% = 1) {
		WinSet, Style, +0x800000
		isTitleGone_%winId% = 0
	} else {
		WinSet, Style, -0x800000
		isTitleGone_%winId% = 1
	}
}

Now, I would like to modify the code in such a manner that, when the hotkey is pressed, the title bar of all open windows and any window that may be opened later will have the titlebar hidden..

And again when the hotkey is pressed, titlebar of all the windows are shown as usual.

Thanks in advance :)