Skip to content

Instantly share code, notes, and snippets.

@legendmohe
Last active August 29, 2015 14:11
Show Gist options
  • Save legendmohe/2792edf52165bc2c2a39 to your computer and use it in GitHub Desktop.
Save legendmohe/2792edf52165bc2c2a39 to your computer and use it in GitHub Desktop.
#SingleInstance Force
#Persistent
Gui +LastFound
hWnd := WinExist()
DllCall( "RegisterShellHookWindow", UInt,hWnd )
MsgNum := DllCall( "RegisterWindowMessage", Str,"SHELLHOOK" )
OnMessage( MsgNum, "ShellMessage" )
g_front_flag := "[@]"
g_nofront_flag := "[--]"
g_wait_key_timeout := 1000
g_target_win_class := "IMWindowClass"
g_im_array := []
WinGet, id, list,,, Program Manager
Loop, %id%
{
hWnd := id%A_Index%
WinGetClass, class, ahk_id %hWnd%
if(class = g_target_win_class) {
WinGetTitle, title, ahk_id %hWnd%
StringLeft, flag, title, % StrLen(g_front_flag)
if (flag = g_front_flag) {
g_im_array[hWnd] := g_front_flag
continue
}
StringLeft, flag, title, % StrLen(g_nofront_flag)
if(flag = g_nofront_flag) {
g_im_array[hWnd] := g_nofront_flag
continue
}
WinSetTitle, ahk_id %hWnd%, , %g_front_flag%%title%
g_im_array[hWnd] := g_front_flag
}
}
Menu, Tray, Icon, %A_AhkPath%, -160
return
#v::
hWnd := WinActive( "A" )
; WinGetPos, oX, oY, oWidth, oHeight, ahk_id %hWnd%
; msgbox x%oX% y%oY% w%oWidth% h%oHeight%
DllCall( "FlashWindow", UInt,hWnd, Int,True )
return
^Enter::
^NumpadEnter::
hWnd := WinActive( "A" )
WinGetClass, class, ahk_id %hWnd%
if(class = g_target_win_class) {
Send, {Enter}
WinMinimize, ahk_id %hWnd%
}else {
Send, ^{Enter}
}
return
#y::
hWnd := WinActive( "A" )
WinGetClass, class, ahk_id %hWnd%
if(class = g_target_win_class) {
WinGetTitle, title, ahk_id %hWnd%
if (g_im_array[hWnd] = "") {
g_im_array[hWnd] := g_front_flag
}
if(g_im_array[hWnd] = g_front_flag){
StringTrimLeft, title, title, % StrLen(g_front_flag)
WinSetTitle, ahk_id %hWnd%, , %g_nofront_flag%%title%
g_im_array[hWnd] := g_nofront_flag
}else if(g_im_array[hWnd] = g_nofront_flag){
StringTrimLeft, title, title, % StrLen(g_nofront_flag)
WinSetTitle, ahk_id %hWnd%, , %g_front_flag%%title%
g_im_array[hWnd] := g_front_flag
}else {
WinSetTitle, ahk_id %hWnd%, , %g_front_flag%%title%
}
}
return
RemoveToolTip:
SetTimer, RemoveToolTip, Off
ToolTip
return
show_tooltip(content, interval)
{
ToolTip, %content%
SetTimer, RemoveToolTip, %interval%
}
waitUtilIdle() {
global g_wait_key_timeout
old_idle := A_TimeIdlePhysical
while A_TimeIdlePhysical - old_idle < g_wait_key_timeout
{
if A_TimeIdlePhysical < 100
{
old_idle := 0
}
sleep, 100
}
return false
}
smartActivate(tid) {
WinGetPos, oX, oY, oWidth, oHeight, ahk_id %tid%
WinGet, id, list,,, Program Manager
begin_check := false
Loop, %id%
{
index := id - A_Index + 1
this_id := id%index%
WinGetTitle, title, ahk_id %this_id%
if(tid = this_id && begin_check = false){
; msgbox % title
begin_check := true
}else if(begin_check = true) {
; msgbox found! %title%
if(isCover(oX, oY, oWidth, oHeight, this_id)){
WinActivate, ahk_id %tid%
break
}else {
; WinGetTitle, title, ahk_id %tid%
; StringLeft, title, title, 45
; tip_content := "new message:`n" . title . " ..."
; show_tooltip(tip_content, 3000)
}
}
}
}
isCover(oX, oY, oWidth, oHeight, win_id) {
WinGetPos, X, Y, Width, Height, ahk_id %win_id%
if(oX >= X + Width || oX + oWidth <= X) {
return false
}
if(oY >= Y + Height || oY + oHeight <= Y) {
return false
}
return true
}
ShellMessage( wParam,lParam ) {
global g_front_flag, g_nofront_flag, g_im_array, g_target_win_class
sleep, 100
If ( wParam = 0x8006 || wParam = 0xf ) ; 0x8006 is 32774 as shown in Spy!
{
WinGetClass, class, ahk_id %lParam%
; MsgBox, The active window's class is "%class%".
if(class = g_target_win_class) {
waitUtilIdle()
hWnd := WinActive( "A" )
if(hWnd = lParam)
{
return
}
WinGetTitle, title, ahk_id %lParam%
while StrLen(title) < 4
{
WinGetTitle, title, ahk_id %lParam%
sleep, 100
}
if(g_im_array[lParam] = g_front_flag) {
; WinActivate, ahk_id %lParam%
smartActivate(lParam)
}else if(g_im_array[lParam] = g_nofront_flag) {
}else {
WinSetTitle, ahk_id %lParam%, , %g_front_flag%%title%
; WinActivate, ahk_id %lParam%
smartActivate(lParam)
}
}
}else if (wParam = 0x1) { ; HSHELL_WINDOWCREATED
WinGetClass, class, ahk_id %lParam%
if(class = g_target_win_class) {
title := ""
while StrLen(title) < 4
{
WinGetTitle, title, ahk_id %lParam%
sleep, 100
}
WinSetTitle, ahk_id %lParam%, , %g_front_flag%%title%
g_im_array[lParam] := g_front_flag
}
}
else if (wParam = 0x2) { ; HSHELL_WINDOWDESTROYED
WinGetClass, class, ahk_id %lParam%
if(class = g_target_win_class) {
g_im_array.remove(lParam)
}
}
else if (wParam = 0x4 || wParam = 0x6) { ; HSHELL_WINDOWACTIVATED and HSHELL_REDRAW
WinGetClass, class, ahk_id %lParam%
if(class = g_target_win_class) {
WinGetTitle, title, ahk_id %lParam%
while StrLen(title) < 4
{
WinGetTitle, title, ahk_id %lParam%
sleep, 100
}
if(g_im_array[lParam] = g_front_flag){
StringLeft, flag, title, % StrLen(g_front_flag)
if (flag = g_front_flag) {
return
}
WinSetTitle, ahk_id %lParam%, , %g_front_flag%%title%
}else if(g_im_array[lParam] = g_nofront_flag){
StringLeft, flag, title, % StrLen(g_nofront_flag)
if (flag = g_nofront_flag) {
return
}
WinSetTitle, ahk_id %lParam%, , %g_nofront_flag%%title%
}else {
WinSetTitle, ahk_id %lParam%, , %g_front_flag%%title%
g_im_array[lParam] := g_front_flag
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment