Spoiler
{
;freo's Stacked Table Previewer v1.16
;XTlex's UPGRADE
;Only works in Vista/Windows7 with aero enabled
;Features:
;Shows thumbnails of all stacked tables in a preview window
;Adds and removes tables as they are opened and closed
;Click on the thumbnail to activate the table in the stack
;Displays number of open tables in the preview window title (in the caption)
;Highlights the active/previous active tables green/pink in the thumbnail (Color and border width can be changed in the user defined settings)
;UPGRADE:
;Configuration Menu
;Click on the thumbnail as if it was the table (Fold, Call, Raise, Sitout, you name it!)
;Table Numeration for easier access
;Hotkey for manually reorganize tables when reducing tables
#SingleInstance Force
#NoEnv
DetectHiddenWindows,On
SetTitleMatchMode, 2
setwindelay 0
OnMessage(0x201,"clickevent")
OnMessage(0x46, "WM_WINDOWPOSCHANGING")
;------------------------------------------------------------------------------------------------------------------
;User defined settings
pokersite=ps ;Pokersite ID - ps for Pokerstars, cu for Customised (you'll need to change cu settings further down)
hostwindoww:=1230 ;Host preview window width, internal dim
hostwindowh:=568 ;Host preview window height, internal dim
hostwindowx:=4 ;Host preview window x position on screen
hostwindowy:=4 ;Host preview window y position on screen
activebordersize:=4 ;Width of the colored border for showing active and last active tables
activebordercolor=00FF00 ;Color of the highlight border for the active window
lactivebordercolor=FF00FF ;Color of the highlight border for the last active window
chosenhotkeydefault=^!x ;Hotkey to manually reorganize previews (Ctrl+Alt+x)
refreshratedefault:=3 ;Number of seconds to wait between refreshes
;------------------------------------------------------------------------------------------------------------------
}
if (pokersite = "ps") {
ptablebasew=624 ;Poker table base resolution width (For stars)
ptablebaseh=430 ;Poker table base resolution height (For stars)
windowtitle=ahk_class PokerStarsTableFrameClass ;Window title to match to find tables - Pokerstars
windowtitle2=Table ahk_class #32770 ;Window title of the closing table message
windowtitleexclude= ;Window title to exclude
windowtitleexclude2=PokerStars Lobby ;Window title to exclude
} else if (pokersite = "cu") { ;Change these settings for a custom site/application
ptablebasew=483 ;custom site/application base resolution width
ptablebaseh=353 ;custom site/application base resolution height
windowtitle= ;Window title to match to find tables
windowtitle2= ;Window title of the closing table message
windowtitleexclude= ;Window title to exclude
windowtitleexclude2= ;Window title to exclude
}
{
;VARIABLES
SysGet, borderxa, 45 ;Size of the x window 3D border
Sysget, borderya, 46 ;Size of the y window 3D border
Sysget, captionha, 4 ;Size of the caption
Sysget, borderxb, 5 ;Size of the x window normal border
Sysget, borderyb, 6 ;Size of the y window normal border
Sysget, borderxX, 32 ;SM_CXSIZEFRAME
borderx := borderxa + borderxb ;Total size of the x border
bordery := borderya + borderyb ;Total size of the y border
captionh := captionha + bordery ;Total size of the caption
hostwindoww2:=hostwindoww+borderx+borderx ;Host preview window width, external dim
hostwindowh2:=hostwindowh+bordery+captionh ;Host preview window height, external dim
clientareah := hostwindowh ;Height of the area thumbnail windows can be placed in
clientareaw := hostwindoww ;Width of the area thumbnail windows can be placed in
clientareax := hostwindowx + borderx
clientareay := hostwindowy + captionh
ptablehwratio := (ptablebaseh) / (ptablebasew) ;Ratio used for scaling thumbnail window size
lastactive:=0
thisactive:=0
borderguix:=clientareax
borderguiy:=clientareay
chosenhotkeysave:=chosenhotkeydefault ;hotkey to manually reorganize previews
refreshratesave:=refreshratedefault
refreshratereal:=refreshratesave*1000 ;refreshrate for mainloop
refreshratereal2:=refreshratesave*200 ;refreshrate for 2ndloop
idZ:=id:=0
GroupAdd, XTgroup, %windowtitle%,,,%windowtitleexclude%
GroupAdd, XTgroup, %windowtitle2%,,,%windowtitleexclude2%
hotkey, %chosenhotkeysave%, chosenhotkey
;GUIs
;Create preview window
Gui, 99: +LastFound +LabelForm1_
Gui, 99: Color, 0
;WinSet, TransColor, 0
target := WinExist()
Gui, 99: Show, w%hostwindoww% h%hostwindowh% x%hostwindowx% y%hostwindowy%, 00 Tables Previewed
;Create GUi's for colored border
;Gui 1 for active table
Gui, 1:+LastFound +Owner99
Gui, 1:Color, %activebordercolor%
Gui, 1:-Caption -Border
activegui:=WinExist()
;Gui 2 for last active table
Gui, 2:+LastFound +Owner99
Gui, 2:Color, %lactivebordercolor%
Gui, 2:-Caption -Border
lactivegui:=WinExist()
;DebugMode GUI
;gui, 13:+alwaysontop
;gui, 13:-caption -border
;gui, 13:color, 0xFF0000
;gui, 13:show, w10 h10 x1 y1, Porp
;Configuration Page
gui, 72:+Owner99 -resize -minimizebox
gui, 72:font, s14 w700 cRed
gui, 72:add, text, center w300 h30 x1 y1, Configuration Page
gui, 72:font, s12 w400 cBlack
gui, 72:add, text, cBlue x10 y45 w280 h20, Manually reorganize previews:
gui, 72:add, text, cBlue x10 y110 w280 h20 vrefreshrateID0, RefreshRate:
gui, 72:add, text, center w10 h20 vrefresh, 1
gui, 72:add, text, center w10 h20 vrefresh2, 5
gui, 72:font, s8
gui, 72:add, hotkey, x10 y70 vchosenhotkey Limit1, %chosenhotkeydefault%
gui, 72:add, slider, x20 y130 vrefreshrateID tooltip tickinterval1 Buddy1refresh Buddy2refresh2 range1-5, %refreshratedefault%
gui, 72:add, button, x30 y210 gButton72, SAVE
gui, 72:add, button, x100 y210 gDefault72, DEFAULT
gui, 72:show, hide w300 h240 x%clientareax% y%clientareay%, Configuration Page
;Configuration Page Icon
gui, 73:+LastFound +Owner99
gui, 73:-caption -border
gui, 73:color, %activebordercolor%
g73:=WinExist()
g73x:=hostwindowx+hostwindoww-30
g73y:=hostwindowy+20
gui, 73:show, w40 h40 x%g73x% y%g73y%
winset, Region, 5-5 w30 h30 E, ahk_id %g73%
;GUI to anchor 75 and 77
gui, 74:show, hide
;Real Table active border
gui, 75:+LastFound +Owner74
gui, 75:-caption -border +alwaysontop
gui, 75:color, %activebordercolor%
XT0:=WinExist()
;Numeration Mask
gui, 76:+LastFound +Owner99
MaskK:=WinExist()
gui, 76:color, 0
winset, transcolor, 0, ahk_id %MaskK%
gui, 76:-caption -border
gui, 76:font, s20 w700 verdana
loop, 98 {
gui, 76: add, text, vNumera%a_index% c00FF00 x1 y5100, %a_index%
}
gui, 76: show, w%hostwindoww% h%hostwindowh% x%clientareax% y%clientareay%, Mask
;Real Table Numeration
gui, 77:+LastFound +Owner74
MesasS:=WinExist()
gui, 77:color, 0
winset, transcolor, 0, ahk_id %MesasS%
gui, 77:-caption -border +alwaysontop
gui, 77:font, s20 w700 verdana
gui, 77:add, text, x2 y0 c00FF00 vContagem, 00
gui, 77:show, x1 y5001 w70 h40 NA, Mesas
;DLL calls
DllCall("LoadLibrary", "str", "dwmapi.dll") ;Load dwmapi.dll for handling thumbnails
DllCall( "RegisterShellHookWindow", UInt,target) ;DLL hook for detecting window activations (for colored active table borders)
MsgNum := DllCall( "RegisterWindowMessage", Str,"SHELLHOOK" )
OnMessage( MsgNum, "ShellMessage" )
}
;Create Empty variables for storing thumbnail links
Loop, 98 {
source%A_Index%_hnd:=0
source%A_Index%_thumb:=0
source%A_Index%_wide:=0
}
MainLoop:
{
setTimer, MainLoop, %refreshratereal%
setTimer, 2ndLoop, %refreshratereal2%
skip:=0
;Get Tables List
WinGet, id, list, ahk_group XTgroup
if (id>idZ)
idZ:=id
;Find any closed tables
Loop, 98 {
abc:=source%a_index%_hnd
IfWinNotExist, ahk_id %abc%
{
source%A_Index%_hnd:=0
source%A_Index%_thumb:=0
source%A_Index%_wide:=0
}
}
;Unregister existing thumbs
Loop, 98 {
unregisterthumbnail(source%A_Index%_thumb)
}
;Register new thumbs
Loop, %id% {
kk:=id%a_index%
flag:=0
loop, 98 {
if (kk = source%a_index%_hnd) {
k:=a_index
break
}
if (source%a_index%_hnd=0 and flag=0) {
k:=a_index
flag:=1
}
}
tablesw := numtablesw(idZ)
childwinw := Floor(calcwinsize(tablesw, idZ))
childwinh := Floor(childwinw * ptablehwratio)
addchild(k, kk)
}
WinSetTitle, ahk_id %target%, ,%id% Tables Previewed
gui, 76:show, hide
gui, 76:show, NA
skip:=1
}
Return
2ndLoop:
if (skip=1) {
gui, 72:submit, nohide
guicontrol, 72:, refreshrateID0, RefreshRate: %refreshrateID%s
drawborder(1,thisactive)
drawborder(2,lastactive)
winget, XTlex, ID, A
kjkj:=0
loop, 98 {
kjkj++
if (XTlex=source%a_index%_hnd)
break
}
if (kjkj<98) {
drawExtras(XTlex)
} else {
Gui, 77:-alwaysontop
Gui, 75:-alwaysontop
winset, Top,, ahk_id %XTlex%
}
}
return
;Function to register the thumbnail to the GUI
registerthumbnail(target, source, thumbnum) {
Global
VarSetCapacity(thumbnail,4,0)
DllCall("dwmapi\DwmRegisterThumbnail",UInt,target,UInt,source,UInt, &thumbnail)
thumbnail:=Numget(thumbnail,0,true)
source%thumbnum%_hnd:=source
source%thumbnum%_thumb:=thumbnail
updatethumbnail(source, thumbnum, thumbnail)
}
updatethumbnail(source, thumbnum, thumbnail) {
/*
Function sets thumbnail properties and displays
DWM_TNP_RECTDESTINATION (0x00000001)
Indicates a value for rcDestination has been specified.
DWM_TNP_RECTSOURCE (0x00000002)
Indicates a value for rcSource has been specified.
DWM_TNP_OPACITY (0x00000004)
Indicates a value for opacity has been specified.
DWM_TNP_VISIBLE (0x00000008)
Indicates a value for fVisible has been specified.
DWM_TNP_SOURCECLIENTAREAONLY (0x00000010)
Indicates a value for fSourceClientAreaOnly has been specified.
*/
Global
dwFlags:=0X1 | 0x10
opacity:=150
fVisible:=1
fSourceClientAreaOnly:=1
;Determine where to position thumbnail based on its number
rownum := Ceil(thumbnum / tablesw)
colnum := Mod(thumbnum - 1,tablesw)+1
newx := ((colnum - 1) * childwinw)
newy := ((rownum - 1) * childwinh)
neww := newx + childwinw
newh := newy + childwinh
new3x:=newx+1+activebordersize
new3y:=newy-5+activebordersize
guicontrol, 76: move, Numera%thumbnum%, x%new3x% y%new3y%
WinGetPos,wx,wy,ww,wh,ahk_id %source%
;struct _DWM_THUMBNAIL_PROPERTIES
VarSetCapacity(dskThumbProps,45,0)
NumPut(dwFlags,dskThumbProps,0,"UInt")
NumPut(newx,dskThumbProps,4,"Int") ;x coord in relation to the target
NumPut(newy,dskThumbProps,8,"Int") ;y coord in relation to the target
NumPut(neww,dskThumbProps,12,"Int") ;x coord of bottom-right of the thumb in relation to the target
NumPut(newh,dskThumbProps,16,"Int") ;y coord of bottom-right of the thumb in relation to the target
;NumPut(0,dskThumbProps,20,"Int") ;x coord of source to start capture of image
;NumPut(0,dskThumbProps,24,"Int") ;y coord of source to start capture of image
;NumPut(ww-borderx,dskThumbProps,28,"Int") ;x coord of source to end capture of image
;NumPut(wh-captionh,dskThumbProps,32,"Int") ;y coord of source to end capture of image
;NumPut(opacity,dskThumbProps,36,"UChar")
;NumPut(fVisible,dskThumbProps,37,"Int")
NumPut(fSourceClientAreaOnly,dskThumbProps,41,"Int")
DllCall("dwmapi\DwmUpdateThumbnailProperties","UInt",thumbnail,"UInt",&dskThumbProps)
source%thumbnum%_wide:=ww
}
unregisterthumbnail(unthumbnail) {
DllCall("dwmapi.dll\DwmUnregisterThumbnail", "UInt", unthumbnail)
}
;Function to determine the optimal number of tables wide to show in preview window
numtablesw(totaltables) {
if(totaltables>1) {
global clientareah
global clientareaw
global ptablehwratio
wsize := 0
wnum := 0
Loop,%totaltables% { ;The loop value will equal the number of tables per row
thiswsize := floor(calcwinsize(A_Index, totaltables))
if (thiswsize >= wsize) {
wsize := thiswsize
wnum := A_Index
}
}
return, %wnum%
} Else return, 1
}
;Calculates child window size based on number of tables per row
calcwinsize(tblperrow, totaltables) {
global clientareaw
global clientareah
global ptablehwratio
calcwsize := clientareaw / tblperrow
calcrownum := ceil(totaltables / tblperrow)
if ((clientareah / calcrownum) < (ptablehwratio * calcwsize))
calcwsize := (1 / ptablehwratio) * (clientareah / calcrownum)
Return, calcwsize
}
;Adds child window to the preview pane
addchild(usenum, previewid) {
Global childwinw
Global childwinh
Global hostwindoww
Global hostwindowh
Global target
if (usenum > 0) { ;If usenum is 0 it is not part of the initial load of existing windows
registerthumbnail(target, previewid, usenum)
Return
}
}
;Function to determine what happens when a thumbnail is clicked
clickevent(wparam) {
local id2,win,mousex,mousey,thisslot,thisrow,thiscol,xl,xr,yt,yb
coordmode,mouse,relative
mousegetpos,mousex,mousey,id2
mousex-=borderx
mousey-=captionh
if (a_gui=73) {
gui, 72:show, x%borderguix% y%borderguiy%
gosub, Saved72
}
if (id2=target) {
if (id>0) {
;Calculate slot number
thisrow:=Ceil((mousey+1) / childwinh)
thiscol:=Ceil((mousex+1) / childwinw)
thisslot:=((thisrow-1)*tablesw)+thiscol
win:=source%thisslot%_hnd
WinGetPos, newnew, newnew2, tablew, tableh, ahk_id %win%
tablew-=borderxX*2-2 ;14
tableh-=borderxX*2-bordery ;13
tableh-=captionh
getcoordsinv(thisslot,thisrow,thiscol,tablew,tableh,mousex,mousey,MX,MY)
MX:=MX+borderxX ;8
MY:=MY+borderxX+captionh-bordery ;30
winactivate, ahk_id%win%
controlclick, x%MX% y%MY%, ahk_id%win% ,,,,NA
; MX:=MX+newnew
; MY:=MY+newnew2
; winmove, Porp,,%MX%,%MY%
}
}
}
getcoordsinv(calcslot,thisrow,thiscol,tablew,tableh,rectx,recty,ByRef thisx,ByRef thisy) {
Global
thisx:= ((thiscol-1) * childwinw)
thisy:= ((thisrow - 1) * childwinh)
thisx:=(rectx-thisx)*tablew/childwinw
thisy:=(recty-thisy)*tableh/childwinh
return
}
;Function for docking the border gui's to the preview window
WM_WINDOWPOSCHANGING(wParam, lParam) {
Global
if (A_Gui = 99) && !(NumGet(lParam+24) & 0x2) ; SWP_NOMOVE=0x2
{
; Since WM_WINDOWPOSCHANGING happens *before* the window moves,
; we must get the new position from the WINDOWPOS pointed to by lParam.
borderguix := NumGet(lParam+8,0,"int")
borderguiy := NumGet(lParam+12,0,"int")
x76:=borderguix+borderx
y76:=borderguiy+captionh
winmove, ahk_id %MaskK%,, %x76%, %y76%
x73:=borderguix+hostwindoww-30
y73:=borderguiy+20
winmove, ahk_id %g73%,, %x73%, %y73%
If(thisactive>0)
Gui, 1:Show, X%borderguix% Y%borderguiy% NA
if(lastactive>0)
Gui, 2:Show, X%borderguix% Y%borderguiy% NA
}
}
;Function for detecting window activations for setting border colors
ShellMessage( wParam,lParam ) {
Global
If ((wParam = 4 or wParam = 32772) And WinExist( "ahk_id " lParam )) ; HSHELL_WINDOWACTIVATED = 4, HSHELL_RUDEAPPACTIVATED = 32772
{
matchcnt:=0
Loop, 98 {
matchcnt++
if (source%matchcnt%_hnd = lParam)
break
}
if (matchcnt < 98)
drawExtras(lparam)
if (matchcnt < 98 and thisactive != lParam) {
lastactive:=thisactive
thisactive:=lParam
drawborder(1,thisactive)
drawborder(2,lastactive)
}
}
}
drawborder(guinum, active) {
Global
if (active) {
slotnumb:=0
Loop, 98 {
slotnumb++
if (source%slotnumb%_hnd = active)
break
}
;Get the thumbnail outer edge coords
thisrow:=Ceil(slotnumb/tablesw)
thiscol:=Mod(slotnumb - 1,tablesw)+1
xl:= (thiscol-1) * childwinw +borderx
xr:= (thiscol) * childwinw +borderx
yt:= (thisrow-1) * childwinh +captionh
yb:= (thisrow) * childwinh +captionh
if(guinum=1)
thisgui:=activegui
else
thisgui:=lactivegui
xli:=xl+activebordersize
xri:=xr-activebordersize
yti:=yt+activebordersize
ybi:=yb-activebordersize
WinSet, Region, %xl%-%yt% %xr%-%yt% %xr%-%yb% %xl%-%yb% %xl%-%yt% %xli%-%yti% %xri%-%yti% %xri%-%ybi% %xli%-%ybi% %xli%-%yti%, ahk_id %thisgui%
Gui, %guinum%:Show, x%borderguix% y%borderguiy% W%hostwindoww2% H%hostwindowh2% NA
}
}
drawExtras(XTlex) {
Global
wingetpos, XT1, XT2, XT3, XT4, ahk_id %XTlex%
loop, 98 {
if (XTlex = source%A_Index%_hnd) {
XTlex2:=a_index
break
}
}
XT15:=XT3-activebordersize
XT16:=XT4-activebordersize
WinSet, Region, 0-0 %XT3%-0 %XT3%-%XT4% 0-%XT4% 0-0 %activebordersize%-%activebordersize% %XT15%-%activebordersize% %XT15%-%XT16% %activebordersize%-%XT16% %activebordersize%-%activebordersize%, ahk_id %XT0%
gui, 75:show, w%XT3% h%XT4% x%XT1% y%XT2% NA
gui, 75:+alwaysontop
XT15:=XT1+activebordersize
XT16:=XT2+activebordersize-4
GuiControl, 77:text, Contagem, %XTlex2%
winmove, ahk_id %MesasS%,, %XT15%, %XT16%
Gui, 77:+alwaysontop
}
Form1_Close:
ExitApp
return
chosenhotkey:
{
flag2:=0
idZ:=0
loop, 97 {
if (flag2=1)
break
flag2:=0
loop, 98 {
kkk:=a_index+1
guicontrol, 76: move, Numera%a_index%, x1 y5100
if (source%a_index%_hnd=0 and a_index<98) {
source%a_index%_hnd:=source%kkk%_hnd
source%a_index%_wide:=source%kkk%_wide
source%a_index%_thumb:=source%kkk%_thumb
source%kkk%_hnd:=0
source%kkk%_wide:=0
source%kkk%_thumb:=0
}
if (source%a_index%_hnd=0 and flag2=0)
flag2:=1
if (source%a_index%_hnd!=0 and flag2=1)
flag2:=2
}
}
}
return
Button72:
{
gui, 72:submit, nohide
if (chosenhotkeysave)
hotkey, %chosenhotkeysave%, chosenhotkey, OFF
if (chosenhotkey)
hotkey, %chosenhotkey%, chosenhotkey, ON
chosenhotkeysave:=chosenhotkey
refreshratesave:=refreshrateID
refreshratereal:=refreshratesave*1000
refreshratereal2:=refreshratesave*200
}
return
Default72:
guicontrol, 72:, chosenhotkey, %chosenhotkeydefault%
guicontrol, 72:, refreshrateID, %refreshratedefault%
return
Saved72:
guicontrol, 72:, chosenhotkey, %chosenhotkeysave%
guicontrol, 72:, refreshrateID, %refreshratesave%
return