Failed to activate Sticky Notes on WIN10x64 using AHKx64Unicode

Get help with using AutoHotkey and its commands and hotkeys
pythonker
Posts: 1
Joined: 11 May 2016, 07:28

Failed to activate Sticky Notes on WIN10x64 using AHKx64Unicode

08 Nov 2018, 23:06

[Moderator's note (lexikos): Topic moved from Bug Reports.]

Hi! I am new here, and I want to share a finding which bugs me a lot.

I want to activate Sticky Notes on WIN10x64 using AHKx64Unicode script, then I check with Spy and find this program has empty title.
So, I use following functions to check the existance of Sticky Notes, but strange thing is their results are not the same.

Code: Select all

id_win := ControlExist("Windows.UI.Core.CoreWindow1", "Sticky Notes")
if ( id_win ) 
{
	msgbox, %id_win% ; NOT OK
}
	
id_win2 := ControlExist2("Windows.UI.Core.CoreWindow1", "Sticky Notes")
if ( id_win2 ) 
{
	msgbox, %id_win2% ; OK
}
	
	
ControlExist( Control = "", WinTitle = "", WinText = "", ExcludeTitle = "", ExcludeText = "" )
{
	ControlGet out, Hwnd, , %Control%, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
	Return ! ErrorLevel
}

ControlExist2( Control = "", WinTitle = "", WinText = "", ExcludeTitle = "", ExcludeText = "" )
{
	WinGet, id_win, ID,, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
	ControlGet out, Hwnd, , %Control%, ahk_id %id_win%
	Return ! ErrorLevel
}
Noesis
Posts: 294
Joined: 26 Apr 2014, 07:57

Re: Failed to activate Sticky Notes on WIN10x64 using AHKx64Unicode

10 Nov 2018, 01:05

The results aren't the same because you're using "Sticky Notes" as the WinTitle in the first example, it should be the WinText (you left out a comma in the call "sticky notes should be the third argument).

Your second function shouldn't work (as it's been defined) since the same issue should occur as above, however since you have an extra comma (after ID) in the WinGet statement, it means the actual WinTitle argument is always blank or null while the variable named WinTitle in the ControlExist2 function, is actually being passed in the WinText position which makes it appear to work, (remember though none of the variable names actually match what they are meant to do, hence I say it shouldn't work as it's been defined).

It also doesn't matter that Sticky Notes doesn't have a title (i.e an actual Window Title) as the the WinTitle argument doesn't NEED it if you include the class and/or exe. In this case, sticky notes has a class "ApplicationFrameWindow", while the executable is "Explorer.EXE". Since this class & exe combination could be used elsewhere, add in the "Sticky Notes" as a the WinText parameter for a normal WinActivate command (or if you are actually only after it's id, use WinExist() instead). (Note the Sticky Notes text shows up in 3 places in window spy, yes it's control text but it's also in the bottom two boxes, i.e. Visible Text & All Text, so you don't need to use the control to check for it but you could, only bear in mind the control ID will still be different to the Window ID as all ID's are unique. So you could use:

Code: Select all

 ;to simply activate the window you could use
Winactivate ahk_class ApplicationFrameWindow ahk_exe Explorer.EXE, Sticky Notes
 ;or to get the Window ID, 
MsgBox %  WinExist("ahk_class ApplicationFrameWindow ahk_exe Explorer.EXE", "Sticky Notes")

Return to “Ask For Help”

Who is online

Users browsing this forum: Bing [Bot], colt, Sabestian Caine and 53 guests