MMhhh.. You're right . It should be done by combining data about visibility of the maximize/minimize box and the border type of the window but I can't help you. I don't know anything about ahk. If I've time I'll read something about it to help you.
See you later