Put a mark on a window and remove when window closes (in case it is reopened later)

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
bazkeys
Posts: 98
Joined: 20 Jan 2021, 21:58

Put a mark on a window and remove when window closes (in case it is reopened later)

Post by bazkeys » 18 Jan 2022, 22:38

I'm looking to put a small mark on a window, by mark I mean for example a small blob of color, letter X, anything that signifies to me an action has taken place, in addition if the window got closed and reopened with the same id, I would want the mark not to be there.
I'm not sure how to do either part of this at the moment. I'm going to look into it myself further, but would appreciate any help.

User avatar
boiler
Posts: 16772
Joined: 21 Dec 2014, 02:44

Re: Put a mark on a window and remove when window closes (in case it is reopened later)

Post by boiler » 18 Jan 2022, 23:17

There are a couple of ways I’ve made indicators that certain windows have been acted upon. One is by changing the text of the window title. Another is to change the window’s icon in the title bar. You could change it to an X or a blob of color or whatever. Would either of those work for you?

swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: Put a mark on a window and remove when window closes (in case it is reopened later)

Post by swagfag » 18 Jan 2022, 23:41

what does closed and reopened with the same id mean?

windows are assigned new hwnds upon creation by the window manager by whatever method it implements. the odds of a window u closed and reopened reusing the same hwnd it was previously assigned are astronomically low

bazkeys
Posts: 98
Joined: 20 Jan 2021, 21:58

Re: Put a mark on a window and remove when window closes (in case it is reopened later)

Post by bazkeys » 19 Jan 2022, 07:37

boiler wrote: There are a couple of ways I’ve made indicators that certain windows have been acted upon. One is by changing the text of the window title. Another is to change the window’s icon in the title bar. You could change it to an X or a blob of color or whatever. Would either of those work for you?
@boiler
Thanks for your reply boiler.
Changing the icon might work for me, any pointers on how to do that.
As an aside, I saw some examples with Winslet, region subcommand used to draw shapes within Notepad, it looked interesting, but seems more like a transformation, rather than a simple way to mark a window.

@swagfag
Thanks for your reply. Yes, I meant hwnd. I think I have seen instances where the hwnd gets used again, anyway, guess it's not the important part.

User avatar
boiler
Posts: 16772
Joined: 21 Dec 2014, 02:44

Re: Put a mark on a window and remove when window closes (in case it is reopened later)

Post by boiler » 19 Jan 2022, 08:33

bazkeys wrote: Changing the icon might work for me, any pointers on how to do that.
Like this:

Code: Select all

IconFile := "PathToMyIcon.ico" ; can be relative to the script's working directory or absoulte
WinID := WinExist("ahk_exe notepad.exe") ; replace with WinTitle of desired window
hIcon := DllCall( "LoadImage", "UInt", 0, "Str", IconFile, "UInt", 1, "UInt", 0, "UInt", 0, "UInt", 0x10)
SendMessage, 0x80, 0, hIcon,, ahk_id %WinID% ; affects small icon such as title bar
SendMessage, 0x80, 1, hIcon,, ahk_id %WinID% ; affects big icon such as Alt+Tab menu

bazkeys wrote: As an aside, I saw some examples with Winslet, region subcommand used to draw shapes within Notepad, it looked interesting, but seems more like a transformation, rather than a simple way to mark a window.
Yes, it is a transformation. It could be used to mark a window if you wanted, such as rounding its corners or something. If it's not a fixed window size, you'll need to get the size of the window and then dynamically build the details of the shape you're drawing based on it, which would be kind of a pain for simply marking a window. The icon seems much easier to me.

bazkeys wrote: Yes, I meant hwnd. I think I have seen instances where the hwnd gets used again, anyway, guess it's not the important part.
You have almost surely never seen instances where it is used again. If you saw the same hwnd, it was because the window was never really closed and re-created. It was just hidden and the same window was shown again. The program doesn't make the choice as to what its hwnd is going to be. Windows assigns an hwnd to new windows, and there is almost zero chance you saw the same one again and even less of a chance that it happened to be re-used on that same window the next time it was created.

bazkeys
Posts: 98
Joined: 20 Jan 2021, 21:58

Re: Put a mark on a window and remove when window closes (in case it is reopened later)

Post by bazkeys » 19 Jan 2022, 22:21

@boiler
Thanks for the code snippet, it works, but not for all windows (perhaps protected ones), so I'm still in need of something that will mark the window under the mouse when I press a hotkey for example.
boiler wrote:
19 Jan 2022, 08:33
You have almost surely never seen instances where it is used again. If you saw the same hwnd, it was because the window was never really closed and re-created. It was just hidden and the same window was shown again. The program doesn't make the choice as to what its hwnd is going to be. Windows assigns an hwnd to new windows, and there is almost zero chance you saw the same one again and even less of a chance that it happened to be re-used on that same window the next time it was created.
Thanks for the info, yeah, I think the window was just hidden and used again.

User avatar
boiler
Posts: 16772
Joined: 21 Dec 2014, 02:44

Re: Put a mark on a window and remove when window closes (in case it is reopened later)

Post by boiler » 19 Jan 2022, 22:38

You could use my other suggestion and change the title of the window. As a demo, this script toggles a circle on and off the beginning of the active window's title when you press Ctrl+Tab:

Code: Select all

^Tab::
	WinGetActiveTitle, Title
	if InStr(Title, "⬤")
		WinSetTitle, A,, % StrReplace(Title, "⬤")
	else
		WinSetTitle, A,, % "⬤" Title
return

bazkeys
Posts: 98
Joined: 20 Jan 2021, 21:58

Re: Put a mark on a window and remove when window closes (in case it is reopened later)

Post by bazkeys » 19 Jan 2022, 23:56

@boiler

thanks once again for the suggestion and code snippet, but I don't actually want to change the title, and also the title can get updated by the app itself, so it would lose that mark then.
Edit: Again it doesn't work for certain windows also.

Is there no easy way to just put a slash, blob or color, x, or basically anything to mark the window in autohotkey, I'm obviously no expert, but seems like it should be a fairly straightforward thing to do?

User avatar
boiler
Posts: 16772
Joined: 21 Dec 2014, 02:44

Re: Put a mark on a window and remove when window closes (in case it is reopened later)

Post by boiler » 20 Jan 2022, 05:36

You can create a small GUI that would just be a blob of color and use Dock to attach it to another window. Is that "easy"? That's up to you.

bazkeys
Posts: 98
Joined: 20 Jan 2021, 21:58

Re: Put a mark on a window and remove when window closes (in case it is reopened later)

Post by bazkeys » 05 Mar 2022, 20:27

@boiler Thanks and apologies for not thanking sooner, just got distracted by other stuff and haven't been on the forum for a while. I currently don't need to do this, but it's good to know anyway in case I need to try again in the future.

Post Reply

Return to “Ask for Help (v1)”