AndyS01 Posted August 15, 2020 Share Posted August 15, 2020 I have a function that opens Notepad and sets its window title. However, the title reverts to whatever its default was when the Notepad window gets focus. To reproduce, run my script and do not move the cursor or type anything. Note that the Notepad window has a title of "abc 123". Now, move the mouse over the Notepad window. The title reverts to the default "Untitled - Notepad". Note: This behavior is also produced when running the F1 Help example script WinSetTitle.au3. Just move the mouse during the 2 second delay. My test script: expandcollapse popupGlobal $_Hwnd = 0 _OpenNotepad("abc 123") Func _OpenNotepad($sTitle) Local $pNotepad , $ret = 0 If $_Hwnd = 0 And WinExists($sTitle) Then $_Hwnd = WinGetHandle($sTitle) If IsHWnd($_Hwnd) Then ; Another session already started, so use it If WinExists($_Hwnd) Then $ret = 2 ; The session is still active EndIf EndIf If ($ret = 0) Then Local $exe, $class ; Start Notepad and save its window handle $exe = "Notepad" $class = "[CLASS:Notepad]" $pNotepad = Run($exe) WinWait($class) $_Hwnd = WinGetHandle($class) If $pNotepad = WinGetProcess($_Hwnd) Then Local $rrr1, $rrr2 $rrr1 = WinActivate($_Hwnd) $rrr2 = WinSetTitle($_Hwnd, "", String($sTitle)) ConsoleWrite("+++: $rrr1 = " & $rrr1 & ", $rrr2 = " & $rrr2 & @CRLF) Else $ret = 3 EndIf EndIf Return SetError($ret, 0, 0) EndFunc ;=>_OpenNotepad Link to comment Share on other sites More sharing options...
TheXman Posted August 15, 2020 Share Posted August 15, 2020 (edited) Yes, I experienced this a while back because I use the debug.au3 UDF a lot and send the output to notepad (Option 5). It appears that in Windows 10, Notepad sets the window title to the file name. As you've said, WinSetTitle() will change the title but as soon as Notepad regains focus, it reverts back to the file name. Another difference is that in Win10, as opposed to Win7, the title will have an "*" in it to when the data has been modified. Win7 did not do this. That causes issues in some of the older code that deals with Notepad because the title may no longer match (like in the debug.au3 UDF). Edited August 15, 2020 by TheXman CryptoNG UDF: Cryptography API: Next Gen jq UDF: Powerful and Flexible JSON Processor | jqPlayground: An Interactive JSON Processor Xml2Json UDF: Transform XML to JSON | HttpApi UDF: HTTP Server API | Roku Remote: Example Script About Me How To Ask Good Questions On Technical And Scientific Forums (Detailed) | How to Ask Good Technical Questions (Brief) "Any fool can know. The point is to understand." -Albert Einstein "If you think you're a big fish, it's probably because you only swim in small ponds." ~TheXman Link to comment Share on other sites More sharing options...
AndyS01 Posted August 15, 2020 Author Share Posted August 15, 2020 Do you know of a work-around? I have my environment set up so I have a single Notepad window that I leave up for multiple compile&runs so I don't have to kill Notepad between each run. Link to comment Share on other sites More sharing options...
AndyS01 Posted August 16, 2020 Author Share Posted August 16, 2020 Temporarily, I force $sTitle to "Untitled - Notepad", but that's not a real fix. Has this been reported to Microsoft? Link to comment Share on other sites More sharing options...
BrewManNH Posted August 16, 2020 Share Posted August 16, 2020 Use the handle of the instance of Notepad you want, and not its title. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
TheXman Posted August 16, 2020 Share Posted August 16, 2020 47 minutes ago, AndyS01 said: Do you know of a work-around? This is my little routine for writing log messages to notepad. It is pretty self-explanatory given all of the comments. Func _WriteNotepadLogLine($sMsg = "") Const $TITLE_NOTEPAD = "[RegExpTitle:Untitled - Notepad]" Static $hWndNotepad = -1 ;If we don't have a handle to notepad yet If $hWndNotepad = -1 Then ;If there isn't an existing instance of notepad running, launch one If Not WinExists($TITLE_NOTEPAD) Then Run("Notepad.exe") ;Get handle to notepad window $hWndNotepad = WinWait($TITLE_NOTEPAD, "", 3) If Not $hWndNotepad Then Exit MsgBox($MB_ICONERROR, "ERROR", "Unable to find Notepad window.") EndIf ;Write to Notepad If WinExists($hWndNotepad) Then ControlCommand($hWndNotepad, "", "Edit1", "EditPaste", $sMsg & @CRLF) EndFunc 42 minutes ago, AndyS01 said: Has this been reported to Microsoft? I don't think the new behavior is a bug. I think it is working as designed. The "*" to denote modification is pretty common these days. Notepad using the file name as the title isn't necessarily a bad thing. New notepad instances are always titled "Untitled - Notepad" so it is pretty easy to identify when it is first launched. So grabbing the handle is pretty simple. As BrewManNH suggested, using a handle to Notepad is much more reliable than a title, especially if there happens to be more than one instance of unsaved notepads open. CryptoNG UDF: Cryptography API: Next Gen jq UDF: Powerful and Flexible JSON Processor | jqPlayground: An Interactive JSON Processor Xml2Json UDF: Transform XML to JSON | HttpApi UDF: HTTP Server API | Roku Remote: Example Script About Me How To Ask Good Questions On Technical And Scientific Forums (Detailed) | How to Ask Good Technical Questions (Brief) "Any fool can know. The point is to understand." -Albert Einstein "If you think you're a big fish, it's probably because you only swim in small ponds." ~TheXman Link to comment Share on other sites More sharing options...
AndyS01 Posted August 16, 2020 Author Share Posted August 16, 2020 I made those changes and it worked. Thank you. But if I wanted to change the title of this Notepad window, how could I do it? I think that it's really a bug, especially since the WinSetTitle.au3 in the Examples folder fails as well. Link to comment Share on other sites More sharing options...
TheXman Posted August 16, 2020 Share Posted August 16, 2020 (edited) You're welcome! 43 minutes ago, AndyS01 said: But if I wanted to change the title of this Notepad window, how could I do it? Since Notepad's window title in Win10 is tied to the file name, the only way I can think of at the moment to reliably set the title to some arbitrary value and make it survive the "regaining of focus issue", would be to save the file and name it what you want the title to be. 43 minutes ago, AndyS01 said: I think that it's really a bug, especially since the WinSetTitle.au3 in the Examples folder fails as well. So you think AutoIt example scripts should dictate the design/operation of Microsoft applications? The reason that the example as well as other UDFs that rely on the old way the Notepad worked do not work the same with Windows 10's Notepad, is most likely due to them being unaware of the issue, it not being a high enough priority, or that it has been resolved but not released yet. If it's that important to you, you should enter a Bug Tracker ticket. Edited August 16, 2020 by TheXman CryptoNG UDF: Cryptography API: Next Gen jq UDF: Powerful and Flexible JSON Processor | jqPlayground: An Interactive JSON Processor Xml2Json UDF: Transform XML to JSON | HttpApi UDF: HTTP Server API | Roku Remote: Example Script About Me How To Ask Good Questions On Technical And Scientific Forums (Detailed) | How to Ask Good Technical Questions (Brief) "Any fool can know. The point is to understand." -Albert Einstein "If you think you're a big fish, it's probably because you only swim in small ponds." ~TheXman Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now