How to hide the title bar of a program (for example Notepad) using autohotkey - autohotkey

I would like to completely hide the title bar of Notepad. That means that (1) if I switch to existing instances of Notepad, the titles gets hided, (2) if I open new instances of Notepad, the titles gets hided.
I have used the following but it does not work. Any help to correct the code or another solution is welcomed.
#IfWinActive, ahk_class Notepad
WinSet, Style, -0xC00000, A
return
#IfWinActive

#SingleInstance force
#warn
SetTimer, HN, 2500
return
r::Reload
x::ExitApp
HN:
If WinActive("ahk_class Notepad")
WinSet, Style, -0xC00000, A
return

the above code works for me, just tested on win10

It will work Only If Someone Assigns a Hotkey to execute the job... Meaning Something Should Trigger It Somewhere like in the below example.
Note: In the Script below, Both y and z, would perform the same job.
#SingleInstance force
#warn
r::Reload
x::ExitApp
#IfWinActive, ahk_class Notepad
y::WinSet, Style, -0xC00000, A
#IfWinActive
/*or*/
#IfWinActive, ahk_class Notepad
z::
WinSet, Style, -0xC00000, A
return
#IfWinActive
Below ones too can help you further in that direction
If WinActive...
IfWinActive...

Related

I cant seem to remove a window from alt-tab list

I confirmed this bit of code a few months and set it aside for when I will need it. I need to exclude a program from alt-tab list, for examples sake, I am using notepad:
WinSet, ExStyle, ^0x80, notepad
Notedpad is still present in alt-tab. I could have sworn this used to work.
Did windows 11 new alt-tab break compatibility? or am I doing it wrong?
Any help would be wonderfull.
You need a timer or a loop to perform an action, each time a window appears:
#Persistent
SetTimer, exclude_program_from_alt_tab_list, 200
Return
exclude_program_from_alt_tab_list:
WinSet, ExStyle, 0x80, ahk_class Notepad ; Windows 11
Return

User Accounts window doesn't allow any hotkey

I want to create a hotkey when ahk_class #32770 windows are active, in my case, the User Accounts window opened by typing netplwiz in the Run. But, it seems that no hotkey works.
Here's what I did:
#NoEnv
#Warn
SendMode Input
SetWorkingDir %A_ScriptDir%
SetTitleMatchMode, 2 ; A window's title can contain WinTitle anywhere inside it to be a match.
#ifwinactive
#e::Run,%A_AppData%\Microsoft\Windows\Recent
;this doesn't work for ahk_class #32770, so I make the following workaround:
#if winactive("ahk_class #32770") or winactive("ahk_exe explorer.exe")
#e::Run,%A_AppData%\Microsoft\Windows\Recent
;but neither does this work. So I made the following test:
^p::msgbox,hi
;and it doesn't work.
Did I do something wrong, or any workaround?
It should work. End/Close the context with
#if or #ifwinactive as appropriate, if you have not.
Like in
#ifwinactive ahk_class #32770
#e::Run,%A_AppData%\Microsoft\Windows\Recent
#ifwinactive
#if winactive("ahk_class #32770")
#e::Run,%A_AppData%\Microsoft\Windows\Recent
#if

What is ahk_class? How can I use it for window matching?

The AutoHotkey Beginner Tutorial includes a sample script to demonstrate window specific hotkeys and hotstrings.
#IfWinActive ahk_class Notepad
::msg::You typed msg in Notepad
#IfWinActive
#IfWinActive untitled - Paint
::msg::You typed msg in MSPaint!
#IfWinActive
The second example is fairly self-explanatory: Check for a window named "untitled - Paint". It's the first example's use of ahk_class that has me confused.
I haven't been able to find any explanation of the variable in the AHK documentation. According to an AHK forum post, ahk_class is the name of a window as given by Windows Spy, the post didn't go into any more detail.
Would there be any difference between using ahk_class Notepad and Untitled - Notepad? Would the second example work if replaced with #IfWinActive ahk_class Paint?
What is ahk_class and how can I use it for window matching?
From https://autohotkey.com/docs/misc/WinTitle.htm#ahk_class
A window class is a set of attributes that the system uses as a template to create a window. In other words, the class name of the window identifies what type of window it is.
In other words you can use it to identify windows of the same type, if you open notepad the title will be Untitled - Notepad if you save it to temp.txt the title will become temp - Notepad. ahk_class on the other hand will always remain Notepad.
The second example will work if you replace it with #IfWinActive ahk_class MSPaintApp because that's the class of mspaint.
Usually you find ahk_class using Window Spy and then use it in your scripts. If you don't have Window Spy you can use the following hotkey:
#1::WinGetClass, Clipboard, A ; Will copy the ahk_class of the Active Window to clipboard
After you found it you can use it in any place you can use window title for example instead of writing WinActivate, Untitled - Notepad you can write WinActivate, ahk_class Notepad.
Check this article. Ahk_class is the class that is given to you when you use the WindowSpy tool. This tool should be in the same folder as your AutoHotkey executable.

Solution to a "dynamic"/"unstable" ahk_class name?

In AutoHotKey, ahk_class NAME has been a good identifier for programs. Typically, I now use it in the following two ways:
Simply calling the most recently called active instance:
; Pressing Win+Shift+X will bring up (or switch to) the Windows Journal
Application
#+x::
IfWinExist ahk_class JournalApp
WinActivate ahk_class JournalApp
else
Run C:\Program Files\Windows Journal\Journal.exe
return
Grouping windows with the same ahk_class and looping through them:
GroupAdd, FIRE, ahk_class MozillaWindowClass
; Pressing Win+3 will go through all open Firefox windows one by one.
#3::
IfWinExist ahk_class MozillaWindowClass
GroupActivate, FIRE, r
else
Run firefox
return
However, there are certain programs that do not have a stable ahk_class name. For example, the ArcMap.exe should
display the following information in the "Windows Spy" window of AHK:
>>>>>>>>>>( Window Title & Class )<<<<<<<<<<<
Untitled - ArcMap
ahk_class Afx:012F0000:b:00010003:00000006:001C0BB0
Any idea how could I refer to this application that has dynamic ahk_class?
I am aware that there is also something called ahk_exe. However, I did not find it compatible with the method GroupAdd,
GroupActivate or IfWinExist.
You definitely are on the right track trying to incorporate ahk_exe. GroupAdd (and every other command receiving a WinTitle parameter at that) is compatible with ahk_exe in AHK_L; this sample code works perfectly on my machine:
GroupAdd, notepad, ahk_exe notepad.exe
Run, notepad.exe
WinWaitActive, ahk_group notepad
Sleep, 1000
WinClose, ahk_group notepad
I suspect you're not using the most recent version of AHK. Get it here and have another try.

executing a script when at a specific classNN

How shouuld I tweak the following script so that the hotkey is activated not at ANY moment where I'm at the class shown (that is Outlook) but at a specific sub window ( the preview pane of the Inbox box (whose classNN is _WwG1 )) ?
#IfWinActive ahk_class rctrl_renwnd32
+!m::
ControlFocus, OutlookGrid1, ahk_class rctrl_renwnd32
if ErrorLevel ; i.e. it's not blank or zero.
MsgBox, You don't seem to be in context.
return
#IfWinActive
Make the hotkey look for active controls once it is activated. This way you can use the same hotkey for multiple commands, each command depending on the control. You can do this with several if/else statements to test for the subcontrols.
The hotkey only works in Outlook.
Each control has its own command
Each command is limited to that particular control
#ifwinactive, ahk_exe outlook.exe
{
+!m::
controlgetfocus, thiscontrol
if(thiscontrol = "_Wwg1"){
ControlFocus, OutlookGrid1, ahk_class rctrl_renwnd32
if ErrorLevel ; i.e. it's not blank or zero.
MsgBox, You seem to focused on %thiscontrol%
}else if(thiscontrol = "_Wsg2){
msgbox, you've discovered the second control!
}
return
}