Page 1 of 1

How to extract texts displayed in MsgBox without the markers?

Posted: 06 Apr 2020, 11:40
by llinfeng
Can I add some option to MsgBox, so that I can Copy (with ctrl+v) from its message box ONLY the input that I have fed to it? For now, I am using Vim macros to clean up the markers around the real contents of interest. A typical clipboard content obtained by pressing ctrl+v in a MsgBox window:
---------------------------
ahk_master.ahk
---------------------------
"XXXXXX___This_Line_is_of_interest_XXXXXX"
---------------------------
OK
---------------------------

From the documentation page for MsgBox, there is a tip mentioning: "Tip: Pressing ctrl+c while a MsgBox window is active will copy its text to the clipboard. This applies to all MsgBoxes, not just those produced by AutoHotkey." ==> Yet, as shown above, the copied contents are formatted with window_title and an OK button, along with a few horizontal divider lines. The following subroutine can reproduce the message above. (I would like to keep the "OK" button to make sure the MsgBox won't go away before I get a chance to *copy* from it for its text.)

Code: Select all

test_clipboard:
    StrOfInterest="XXXXXX___This_Line_is_of_interest_XXXXXX"
    MsgBox, %StrOfInterest%
return
Background: I find a potential problem with updating the clipboard using some existing variables. The characters with GBK encoding (Chinese characters) are "clipped" wrongly. The variables themselves were displayed normally when rendered through MsgBox. Yet, pasting from ClipBoard with ctrl+v after refreshing the clipboard with Clipboard := var_content shall replace all the GBK-encoded characters with one or two question mark(s). Since the problem appears to be with GBK-characters only, I have posted here and here in the Chinese forum.

Re: How to extract texts displayed in MsgBox without the markers?

Posted: 06 Apr 2020, 12:03
by Chunjee
I am interested in this as well. Don't see the need for all the extra formatting

Re: How to extract texts displayed in MsgBox without the markers?

Posted: 06 Apr 2020, 12:25
by boiler
Have this script running, and it will automatically clean up the Clipboard when you copy that format from a MsgBox.

Code: Select all

#Persistent
OnClipboardChange("CleanMsgBox")
return

CleanMsgBox() {
	if WinActive("ahk_class #32770")
		Clipboard := RegExReplace(Clipboard, "s)\v*---------------------------.*?---------------------------\v*")
}
I suppose you are already doing something like this with your Vim macros, but it sounds like you are looking for an AHK solution. There won't be one that changes what gets copied to the MsgBox with a code or option because it's not an AHK issue. MsgBoxes produced by other programs will also add the title and button info along with separator lines because it's an OS-level issue.

Re: How to extract texts displayed in MsgBox without the markers?

Posted: 06 Apr 2020, 12:57
by GEV
You can try
WinGetText
instead of the clipboard.