Maximising a window with a matching MyWinTitle Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
JKnight_xbt33
Posts: 135
Joined: 18 Sep 2019, 02:06

Maximising a window with a matching MyWinTitle

15 Nov 2019, 14:47

Howdy broskis and broskas, Noob here.

I have two windows with the same ahk_class so I needed to a way differentiate the two and maximise one of them.

My script has a message box that outputs the ahk_id and Win title.

Message box shows one of the windows has the Win title "Custom Filter -Occurence List - Q-Pulse"

I want to maximise this specific window.

I tried to make a script based on what I could find online but its not working. Is there a way to maximise this window in my script below?

Appreciated and thanks for your help!
J
--------------------------------------------------------------------------------------------------------

Code: Select all

#UseHook On


WinGet, MyWindows, List, ahk_class WindowsForms10.Window.8.app.0.2eed1ca_r9_ad1
Loop, % MyWindows

{

    ThisWindow := MyWindows%A_Index%

    WinActivate, ahk_id %ThisWindow%

    WinGetTitle, MyWinTitle, ahk_id %ThisWindow%

    MsgBox, 64, Window Activated, % "Win ID: " ThisWindow "`nTitle: " MyWinTitle   

              If MyWinTitle = Custom Filter - Occurence List - Q-Pulse

              {

              WinMaximize, Custom Filter -Occurence List - Q-Pulse   ; This line of code was supposed to maximise the window with that title. TBH I made this line up, so i dont even know if its correct syntax. 

              }

              else WinMinimize, %ThisWindow%   ; Also made this one up. Its to minimise all other windows which dont share the same title

}

 return
Rohwedder
Posts: 7648
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: Maximising a window with a matching MyWinTitle

16 Nov 2019, 01:48

Hallo,
try:

Code: Select all

#UseHook On
WinGet, MyWindows, List, ahk_class WindowsForms10.Window.8.app.0.2eed1ca_r9_ad1
Loop, % MyWindows
{
	ThisWindow := MyWindows%A_Index%
	WinActivate, ahk_id %ThisWindow%
	WinGetTitle, MyWinTitle, ahk_id %ThisWindow%
	MsgBox, 64, Window Activated, % "Win ID: " ThisWindow "`nTitle: " MyWinTitle
	If MyWinTitle = Custom Filter - Occurence List - Q-Pulse
		WinMaximize, ahk_id %ThisWindow% ; This line of code was supposed to maximise the window with that title
	else
		WinMinimize, ahk_id %ThisWindow%  ; Also made this one up. Its to minimise all other windows which dont share the same title
}
return
User avatar
dd900
Posts: 121
Joined: 27 Oct 2013, 16:03

Re: Maximising a window with a matching MyWinTitle

17 Nov 2019, 11:04

Well since you already know what the WinTitle is I see no reason for the WinGet or the Loop. One of the commands here should Maximize the window.

Code: Select all

SetTitleMatchMode, 2
DetectHiddenWindows, On

winTitle := "Custom Filter - Occurence List - Q-Pulse"
winClass := "ahk_class WindowsForms10.Window.8.app.0.2eed1ca_r9_ad1"

WinMaximize, % winTitle
WinMaximize, % winTitle " " winClass
DllCall("ShowWindow", A_PtrSize ? "Ptr" : "UInt", WinExist(winTitle), "Int", 3)

Code: Select all

SetTitleMatchMode, 2
DetectHiddenWindows, On

winTitle := "Custom Filter - Occurence List - Q-Pulse"
winClass := "ahk_class WindowsForms10.Window.8.app.0.2eed1ca_r9_ad1"
WinGet, MyWindows, List, % winClass ; If you want ALL windows leave the 4th Param blank

Loop, % MyWindows
{
	ThisWindow := MyWindows%A_Index%
	
	WinActivate, % "ahk_id " ThisWindow
	WinGetTitle, MyWinTitle, % "ahk_id " ThisWindow
	
	MsgBox, 64, Window Activated, % "Win ID: " ThisWindow "`nTitle: " MyWinTitle
	
	if (MyWinTitle = winTitle) {
		;WinMaximize, % "ahk_id " ThisWindow
		DllCall("ShowWindow", A_PtrSize ? "Ptr" : "UInt", ThisWindow, "Int", 3) ; Maximize
	} else {
		;WinMinimize, % "ahk_id " ThisWindow
		DllCall("ShowWindow", A_PtrSize ? "Ptr" : "UInt", ThisWindow, "Int", 6) ; Minimize
	}
}

return
JKnight_xbt33
Posts: 135
Joined: 18 Sep 2019, 02:06

Re: Maximising a window with a matching MyWinTitle

18 Nov 2019, 07:26

So I tried all scripts from both dd900 and Rohwedder.
I removed this line for the message box (I dont need it): MsgBox, 64, Window Activated, % "Win ID: " ThisWindow "`nTitle: " MyWinTitle


Results:
Both scripts maximised and then quickly minimised both of the windows.

This is the Custom Filter search window
custom filter search.png
custom filter search.png (220.87 KiB) Viewed 2124 times
This is the Launchpad window
launchpad.png
launchpad.png (175 KiB) Viewed 2124 times
)

I was hoping either of the scripts would maximise the Custom Filter search window and keep it maximised while leaving the Launchpad window minimised.


My suspicions

Because both windows share the same ahk_class perhaps this is what is causing the script to just quickly minimise without leaving custom filter maximised.

My question
Could I include the class NN of the Custom Filter Search in the script, maybe that will differentiate it further from the launchpad window?

Thanks again for your help.
Appreciated.
User avatar
dd900
Posts: 121
Joined: 27 Oct 2013, 16:03

Re: Maximising a window with a matching MyWinTitle

18 Nov 2019, 17:16

Well if you know both wintitles then we definitely should't need a loop. What does this do?

Code: Select all

winTitle := "Custom Filter - Occurence List - Q-Pulse"
winTitle2 := "LaunchPad <Knight, James>"
winClass := "ahk_class WindowsForms10.Window.8.app.0.2eed1ca_r9_ad1"

hWnd1 := WinExist(winTitle) ; Get Custom Filter window hWnd
hWnd2 := WinExist(winTitle2) ; Get LaunchPad window hWnd

DllCall("ShowWindow", A_PtrSize ? "Ptr" : "UInt", hWnd2, "Int", 6) ; Minimize LaunchPad window
DllCall("ShowWindow", A_PtrSize ? "Ptr" : "UInt", hWnd1, "Int", 3) ; Maximize Custom Filter window
ExitApp
JKnight_xbt33
Posts: 135
Joined: 18 Sep 2019, 02:06

Re: Maximising a window with a matching MyWinTitle

19 Nov 2019, 04:43

Thanks for your script dd900 ,
I tried your script and unfortunately nothing happened. There was no response or movement from the windows. They both stayed minimised to the taskbar.


My suspicions


AHK doesn't recognise/Dll call windows titles which are not office programs. For example I am sure the script would work with notepad or MS word.

In fact my original (minimise/maximise) script worked with windows programmes.


My question

Is there a small line to add or small way that AHK could recognise non-windows app titles?


Thanks again for your help, its been a learning experience.
J
JKnight_xbt33
Posts: 135
Joined: 18 Sep 2019, 02:06

Re: Maximising a window with a matching MyWinTitle

19 Nov 2019, 04:59

Hi dd900,
Update your script works perfectly!!! :) Thankyou


my schoolboy error


I typed out the windows title for the custom filter occurrence list not realising I was missing an r in occurrence.
The window title should have read: Occurrence List rather than Occurence List


what I've learnt

For custom scripts always copy and paste title, class and other descriptors straight from windows spy.

Many thanks and appreciated Rohwedder and dd900 for your help on this thread.

I am sure all your scripts/solutions will now work.

Shoutout to Rohwedder as your script was also very easy and effecient to understand.

J
JKnight_xbt33
Posts: 135
Joined: 18 Sep 2019, 02:06

Re: Maximising a window with a matching MyWinTitle

19 Nov 2019, 10:12

forgot to ask
in the original post i had an else/if statement to minimise launchpad if custom filter exist but to maximise launchpad if custom filter exists

I modified dd900 script to include an else/if statement but this didn't work

@dd900 how would properly use the else/if statement modified from your script below to maximise the launchpad window if custom filter doesnt exist?

Again many thanks, hoping this is my last post on this thread :D

Code: Select all

winTitle := "Custom Filter - Occurrence List - Q-Pulse"
winTitle2 := "LaunchPad <Knight, James>"
winClass := "ahk_class WindowsForms10.Window.8.app.0.2eed1ca_r9_ad1"

hWnd1 := WinExist(winTitle) ; Get Custom Filter window hWnd
hWnd2 := WinExist(winTitle2) ; Get LaunchPad window hWnd

if (MyWinTitle = winTitle)
       {
        DllCall("ShowWindow", A_PtrSize ? "Ptr" : "UInt", hWnd2, "Int", 6) ; Minimize LaunchPad window
       DllCall("ShowWindow", A_PtrSize ? "Ptr" : "UInt", hWnd1, "Int", 3) ; Maximize Custom Filter window
        ControlClick, WindowsForms10.EDIT.app.0.2eed1ca_r9_ad11, ahk_class WindowsForms10.Window.8.app.0.2eed1ca_r9_ad1, , left, 1,
		Sleep, 100
		send ^{end}^+{home}
		Sleep, 100
		Send {Del}
	}
		
else if (MyWinTitle = winTitle2)

	    {
		DllCall("ShowWindow", A_PtrSize ? "Ptr" : "UInt", hWnd2, "Int", 3) ; Maximize LaunchPad window
		ControlClick, WindowsForms10.EDIT.app.0.2eed1ca_r9_ad12, ahk_class WindowsForms10.Window.8.app.0.2eed1ca_r9_ad1, , left, 1,
		Sleep, 100
		send ^{end}^+{home}
		Sleep, 100
		Send {Del}
	    }
return
User avatar
dd900
Posts: 121
Joined: 27 Oct 2013, 16:03

Re: Maximising a window with a matching MyWinTitle  Topic is solved

19 Nov 2019, 21:59

No problem.

Code: Select all

winTitle := "Custom Filter - Occurrence List - Q-Pulse"
winTitle2 := "LaunchPad <Knight, James>"
winClass := "ahk_class WindowsForms10.Window.8.app.0.2eed1ca_r9_ad1"
editControl := "WindowsForms10.EDIT.app.0.2eed1ca_r9_ad"

hWnd1 := WinExist(winTitle) ; Get Custom Filter window hWnd
hWnd2 := WinExist(winTitle2) ; Get LaunchPad window hWnd
ptrS := A_PtrSize ? "Ptr" : "UInt"

if (hWnd1) {
	if (hWnd2)
		DllCall("ShowWindow", ptrS, hWnd2, "Int", 6) ; Minimize LaunchPad window
	DllCall("ShowWindow", ptrS, hWnd1, "Int", 3) ; Maximize Custom Filter window
	Sleep, 100
	ControlClick, % editControl "11", % "ahk_id " hWnd1
} else {
	DllCall("ShowWindow", ptrS, hWnd2, "Int", 3) ; Maximize LaunchPad window
	Sleep, 100
	ControlClick, % editControl "12", % "ahk_id " hWnd2
}

Sleep, 100
Send, ^{end}
Sleep, 100
Send, ^+{home}
Sleep, 100
Send, {Del}
return
JKnight_xbt33
Posts: 135
Joined: 18 Sep 2019, 02:06

Re: Maximising a window with a matching MyWinTitle

20 Nov 2019, 03:41

Amazing, just amazing :dance:

Thanks dd900

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Joey5, just me and 226 guests