Two Plus Two Publishing LLC
Two Plus Two Publishing LLC
 

Go Back   Two Plus Two Poker Forums > > >

Notices

Free Software Discussion of Free / Freeware / Donationware / Open Source poker software and Free Graphics mods

Reply
 
Thread Tools Display Modes
Old 11-16-2010, 02:44 AM   #26
dabomb75
veteran
 
dabomb75's Avatar
 
Join Date: Apr 2009
Location: Dreaming of being an FPP Pro
Posts: 2,343
Re: AHK Script: Stars Stacked Table Previewer

Wow this script looks awesome. Once I start playing again and mess around with the script for a little while I'll definitely ship you a small donation.

If this can combine well with TOI then my poker setup will be the nuts
dabomb75 is offline   Reply With Quote
Old 11-16-2010, 03:27 AM   #27
Max1mums
old hand
 
Join Date: Aug 2009
Location: From Russia with code
Posts: 1,672
Re: AHK Script: Stars Stacked Table Previewer

Furio, there are 2 entries of "Winget,list,list" in the script but i didn't notice 2nd entry, they should be the same, my mistake.
Max1mums is offline   Reply With Quote
Old 11-16-2010, 03:35 AM   #28
_dave_
_Pooh_Bah_
 
Join Date: Feb 2005
Location: UK (or what remains of it)
Posts: 12,945
Re: AHK Script: Stars Stacked Table Previewer

Quote:
Originally Posted by Max1mums View Post
Furio, there are 2 entries of "Winget,list,list" in the script but i didn't notice 2nd entry, they should be the same, my mistake.
I edited your above post with this fix, I think.
_dave_ is offline   Reply With Quote
Old 11-16-2010, 03:39 AM   #29
freo
enthusiast
 
Join Date: Nov 2008
Posts: 90
Re: AHK Script: Stars Stacked Table Previewer

Heres my latest version with table activation included, which is a modified version of what Max1mus did. Opening and closing tables should work correctly as well.
Code:
; freo's Stacked Table Previewer for PokerStars v1.01
; Shows thumbnails of all stacked tables in a preview window
; Only works in Vista/Windows7 with aero enabled
; 'clay973' on PS for donations


#SingleInstance Force
#NoEnv

DetectHiddenWindows,On
SetTitleMatchMode, 2

OnMessage(0x201,"clickevent")
;------------------------------------------------------------------------------------------------------------------
;User defined settings
hostwindoww=800         ;Host preview window width             
hostwindowh=600        ;Host preview window height
hostwindowx=400         ;Host preview window x position on screen
hostwindowy=0           ;Host preview window y position on screen
ptablebasew=483         ;Poker table base resolution (For stars this is the smallest table resolution (483 x 353)
ptablebaseh=353
refreshrate=3000        ;Number of seconds to wait between refreshes (1000 = 1 second)
closeareaperc=0.1       ;The percent of the preview window size to use as the close window area on the top right hand side.
;------------------------------------------------------------------------------------------------------------------

hModule := DllCall("LoadLibrary", "str", "dwmapi.dll")       ;Load dwmapi.dll for handling thumbnails
ptablehwratio := ptablebaseh / ptablebasew                  ;Ratio used for scaling thumbnail window size
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
borderx := borderxa + borderxb                               ;Total size of the x border
bordery := borderya + borderyb                               ;Total size of the y border
captionh := captionha + borderyb                             ;Total size of the caption
clientareah := hostwindowh - bordery - captionh              ;Height of the area thumbnail windows can be placed in
clientareaw := hostwindoww - borderx - borderx               ;Width of the area thumbnail windows can be placed in

;Create preview window
Gui, 99: +LastFound +LabelForm1_                            
target := WinExist()
Gui, 99: Show, w%hostwindoww% h%hostwindowh% x%hostwindowx% y%hostwindowy%, Table Preview

;Create Empty variables for storing thumbnail links
Loop, 98
{
    source%A_Index%_hnd:=0
    source%A_Index%_thumb:=0
    source%A_Index%_wide:=0
    source%A_Index%_zoom:=0
}

;Show existing tables
WinGet, list, list, Logged In as, ,PokerStars Lobby        ;Get list of open tables
;WinGet, list, list, Windows Internet Explorer              ;For testing. Shows internet explorer windows instead of poker tables
    
;Need to filter out false windows that have no controls
tblcount:=0
Loop, %list%
{
    thisid:=list%A_Index%
    ;WinGet,ctrllist,ControlList,ahk_id %thisid%
    WinGetTitle,thistitle,ahk_id %thisid%
    If (ctrllist != "") and (thisid > 0)
    {
        tblcount+=1
        tblcount%tblcount%:=list%A_Index%
    }    
}

currentcnt:=tblcount                           

;Calculate child window size and number per row
tablesw := numtablesw(currentcnt)
childwinw := Floor(calcwinsize(tablesw, currentcnt))
childwinh := Floor(childwinw * ptablehwratio)

;Create child windows for tables already open
Loop, %tblcount%
{
    thisid:=tblcount%A_Index%
    addchild(A_Index, thisid)
}

;Infinite loop to monitor table opens, closes & resizes.
Loop,
{    
    Sleep, %refreshrate%
    
    wasredrawn:=0
    
    ;Find any closed tables
    Loop, 98
    {
        thishnd:=source%A_Index%_hnd
        if (thishnd > 0)
        {
            IfWinNotExist, ahk_id %thishnd%
            {
                source%A_Index%_hnd:=0
                source%A_Index%_thumb:=0
                source%A_Index%_wide:=0
                source%A_Index%_zoom:=0
            }
        }
    }
        
    ;Get new list of tables
    WinGet, list, list, Logged In as, ,PokerStars Lobby        ;Get list of open tables
    ;WinGet, list, list, Windows Internet Explorer               ;For testing. Shows internet explorer windows instead of poker tables
    
    ;Need to filter out false windows that have no controls
    tblcount:=0
    Loop, %list%
    {
        thisid:=list%A_Index%
        WinGet,ctrllist,ControlList,ahk_id %thisid%
        WinGetTitle,thistitle,Title,ahk_id %thisid%
        If (ctrllist != "") and (thisid > 0)
        {
            tblcount+=1
            tblcount%tblcount%:=list%A_Index%
        }    
    }    
    
    ;Find any new tables
    Loop, %tblcount%
    {
        thishnd:=tblcount%A_Index%
        found:=0
        Loop,98
        {
            if (source%A_Index%_hnd = thishnd)
            {
                found:=1
                break            
            }
        }
        
        ;New table found
        if (found = 0)
        {
            ;Find first avail slot
            newslot:=0
            Loop,98
            {
                if (source%A_Index%_hnd = 0)
                {
                    newslot:=A_Index
                    break                    
                }
            }

            ;Determine whether an existing slot is available or a recalculation is required as its a new slot.
            if (newslot <= currentcnt)         ;Existing slot taken, no recalc required
            {
                addchild(newslot, thishnd)
            }
            else                                ;Need to recalculate to determine if new rows or columns are required
            {
                currentcnt += 1
                oldcols:=tablesw
                oldw:=childwinw
                tablesw := numtablesw(currentcnt)
                childwinw := Floor(calcwinsize(tablesw, currentcnt))
                childwinh := Floor(childwinw * ptablehwratio)
                if (oldcols = tablesw) and (oldw = childwinw)       ;Still a slot left at the end of the current config
                    addchild(newslot, thishnd)
                else                                                ;Need to redraw all thumbnails with diff config
                {
                    Loop, 98
                    {
                        unregisterthumbnail(source%A_Index%_thumb)            ;Unregister existing thumbs                         
                    }
                    
                    Loop, %tblcount%
                    {
                        if(A_Index < tblcount)
                        {
                            thisid:=source%A_Index%_hnd
                            addchild(A_Index, thisid)
                        }
                        else
                        {
                            thisid:=tblcount%A_Index%
                            addchild(A_Index, thishnd)
                        }
                    }
                    wasredrawn:=1
                }
            }
        }
    }
    
    ;Check if any tables have been resized and if so, redraw
    if (wasredrawn = 0)                 
    {
        Loop, %tblcount%
        {
            retable:=source%A_Index%_hnd
            WinGetPos,wx,wy,ww,wh,ahk_id %retable%
            if (ww != source%A_Index%_wide)
            {
                unregisterthumbnail(source%A_Index%_thumb)
                addchild(A_Index, retable)
            }
        }
    }
}

Return


;Function to register the thumbnail to the GUI
registerthumbnail(target, source, thumbnum)
{
    Global    
    
    VarSetCapacity(thumbnail,4,0)
    hr1:=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)
}

;Function sets thumbnail properties and displays
updatethumbnail(source, thumbnum, thumbnail)
{    
    /*
    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 | 0x2 | 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)
    newx := ((colnum) * childwinw)
    newy := ((rownum - 1) * childwinh)
    neww := newx + childwinw
    newh := newy + childwinh
    
    WinGetPos,wx,wy,ww,wh,ahk_id %source%
    
    VarSetCapacity(dskThumbProps,45,0)
    ;struct _DWM_THUMBNAIL_PROPERTIES
    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 of the thumb in relation to the target
    NumPut(newh,dskThumbProps,16,"Int")                   ;y coord of the right edge of the thumb in relation to the target
    NumPut(0,dskThumbProps,20,"Int")                      ;x coord of target to start thumb
    NumPut(0,dskThumbProps,24,"Int")                      ;y coord of target to start thumb
    NumPut(ww,dskThumbProps,28,"Int")                    ;width of the thumb in relation to the source
    NumPut(wh,dskThumbProps,32,"Int")                    ;height of the thumb in relation to the source
    NumPut(opacity,dskThumbProps,36,"UChar")
    NumPut(fVisible,dskThumbProps,37,"Int")
    NumPut(fSourceClientAreaOnly,dskThumbProps,41,"Int")
    hr2:=DllCall("dwmapi\DwmUpdateThumbnailProperties","UInt",thumbnail,"UInt",&dskThumbProps) 
    source%thumbnum%_wide:=ww
    if (newh/wh > neww/ww)
        source%thumbnum%_zoom:=neww/ww
    else    
        source%thumbnum%_zoom:=newh/wh
}


unregisterthumbnail(unthumbnail)
{
    ur1:=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
        
        ;The loop value will equal the number of tables per row
        Loop,%totaltables%
        {            
            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
    }
}

clickevent(wparam)
{
    local id,win,mousex,mousey,thumbx,thumby,thisrow,thiscol,thisslot,realw,thisx,thisy,thisw,zoom,closesize,xa,xb,ya,yb
    coordmode,mouse,relative
    mousegetpos,mousex,mousey,id
    if (id=target)
    {
        thumbx:=borderxb+borderxa
        thumby:=captionh
        
        ;Calculate slot number
        thisrow:=Ceil((mousey - thumby) / childwinh)
        thiscol:=Ceil((mousex - thumbx) / childwinw)
        
        thisslot:=((thisrow-1)*tablesw)+thiscol
        win:=source%thisslot%_hnd
        
        ;Activate the window
        if (win >0)
            winactivate,ahk_id%win%
        
    }
}
return

Form1_Close:
	ExitApp
return
Still working on the closing of the table from the thumbnail.
freo is offline   Reply With Quote
Old 11-16-2010, 10:02 AM   #30
freo
enthusiast
 
Join Date: Nov 2008
Posts: 90
Re: AHK Script: Stars Stacked Table Previewer

Here the latest version with "Leave Table" support. Click the "Leave Table" icon on the thumbnail, and table will close (You get the standard "Do you want to leave" popup).

Also tweaked the optimization so there is greater preview window space usage.
Code:
; freo's Stacked Table Previewer for PokerStars v1.0
; Shows thumbnails of all stacked tables in a preview window
; Only works in Vista/Windows7 with aero enabled
; 'clay973' on PS for donations


#SingleInstance Force
#NoEnv

DetectHiddenWindows,On
SetTitleMatchMode, 2

OnMessage(0x201,"clickevent")
;------------------------------------------------------------------------------------------------------------------
;User defined settings
hostwindoww=800         ;Host preview window width             
hostwindowh=900        ;Host preview window height
hostwindowx=850         ;Host preview window x position on screen
hostwindowy=0           ;Host preview window y position on screen
ptablebasew=483         ;Poker table base resolution width(For stars this is the smallest table resolution (483 x 353)
ptablebaseh=353         ;Poker table base resolution height(For stars this is the smallest table resolution (483 x 353)
closexl=418             ;Left x position of leave table button in relation to the resolution set against ptablebasew & ptablebaseh 
closexr=481             ;Right x position of leave table button in relation to the resolution set against ptablebasew & ptablebaseh 
closeyt=24              ;Top y position of leave table button in relation to the resolution set against ptablebasew & ptablebaseh 
closeyb=42              ;Bottom y position of leave table button in relation to the resolution set against ptablebasew & ptablebaseh 
refreshrate=3000        ;Number of seconds to wait between refreshes (1000 = 1 second)
windowtitle=Logged In as                     ;Window title to match to find tables - Pokerstars
windowtitleexclude=PokerStars Lobby           ;Window title to exclude - Pokerstars
;windowtitle=Windows Internet Explorer           ;Window title to match to find tables - Internet Explorer
;windowtitleexclude=                             ;Window title to exclude - Internet Explorer
;------------------------------------------------------------------------------------------------------------------

hModule := DllCall("LoadLibrary", "str", "dwmapi.dll")       ;Load dwmapi.dll for handling thumbnails
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
borderx := borderxa + borderxb                               ;Total size of the x border
bordery := borderya + borderyb                               ;Total size of the y border
captionh := captionha + borderyb                             ;Total size of the caption
clientareah := hostwindowh - bordery - captionh              ;Height of the area thumbnail windows can be placed in
clientareaw := hostwindoww - borderx - borderx               ;Width of the area thumbnail windows can be placed in
ptablehwratio := (ptablebaseh-captionha) / ptablebasew                  ;Ratio used for scaling thumbnail window size

;Create preview window
Gui, 99: +LastFound +LabelForm1_                            
target := WinExist()
Gui, 99: Show, w%hostwindoww% h%hostwindowh% x%hostwindowx% y%hostwindowy%, Table Preview

;Create Empty variables for storing thumbnail links
Loop, 98
{
    source%A_Index%_hnd:=0
    source%A_Index%_thumb:=0
    source%A_Index%_wide:=0
}

;Show existing tables
WinGet, list, list, %windowtitle%, ,%windowtitleexclude%

;Need to filter out false windows that have no controls
tblcount:=0
Loop, %list%
{
    thisid:=list%A_Index%
    WinGet,ctrllist,ControlList,ahk_id %thisid%
    If (ctrllist != "") and (thisid > 0)
    {
        tblcount++
        tblcount%tblcount%:=list%A_Index%
    }    
}

currentcnt:=tblcount                           

;Calculate child window size and number per row
tablesw := numtablesw(currentcnt)
childwinw := Floor(calcwinsize(tablesw, currentcnt))
childwinh := Floor(childwinw * ptablehwratio)

;Create child windows for tables already open
Loop, %tblcount%
{
    thisid:=tblcount%A_Index%
    addchild(A_Index, thisid)
}

;Infinite loop to monitor table opens, closes & resizes.
Loop,
{    
    Sleep, %refreshrate%
    
    wasredrawn:=0
    
    ;Find any closed tables
    Loop, 98
    {
        thishnd:=source%A_Index%_hnd
        if (thishnd > 0)
        {
            IfWinNotExist, ahk_id %thishnd%
            {
                source%A_Index%_hnd:=0
                source%A_Index%_thumb:=0
                source%A_Index%_wide:=0
            }
        }
    }
        
    ;Get new list of tables
    WinGet, list, list, %windowtitle%, ,%windowtitleexclude% 
    
    ;Need to filter out false windows that have no controls
    tblcount:=0
    Loop, %list%
    {
        thisid:=list%A_Index%
        WinGet,ctrllist,ControlList,ahk_id %thisid%
        If (ctrllist != "") and (thisid > 0)
        {
            tblcount+=1
            tblcount%tblcount%:=list%A_Index%
        }    
    }    
    
    ;Find any new tables
    Loop, %tblcount%
    {
        thishnd:=tblcount%A_Index%
        found:=0
        Loop,98
        {
            if (source%A_Index%_hnd = thishnd)
            {
                found:=1
                break            
            }
        }
        
        ;New table found
        if (found = 0)
        {
            ;Find first avail slot
            newslot:=0
            Loop,98
            {
                if (source%A_Index%_hnd = 0)
                {
                    newslot:=A_Index
                    break                    
                }
            }

            ;Determine whether an existing slot is available or a recalculation is required as its a new slot.
            if (newslot <= currentcnt)         ;Existing slot taken, no recalc required
            {
                addchild(newslot, thishnd)
            }
            else                                ;Need to recalculate to determine if new rows or columns are required
            {
                currentcnt += 1
                oldcols:=tablesw
                oldw:=childwinw
                tablesw := numtablesw(currentcnt)
                childwinw := Floor(calcwinsize(tablesw, currentcnt))
                childwinh := Floor(childwinw * ptablehwratio)
                if (oldcols = tablesw) and (oldw = childwinw)       ;Still a slot left at the end of the current config
                    addchild(newslot, thishnd)
                else                                                ;Need to redraw all thumbnails with diff config
                {
                    Loop, 98
                    {
                        unregisterthumbnail(source%A_Index%_thumb)            ;Unregister existing thumbs                         
                    }
                    
                    Loop, %tblcount%
                    {
                        if(A_Index < tblcount)
                        {
                            thisid:=source%A_Index%_hnd
                            addchild(A_Index, thisid)
                        }
                        else
                        {
                            thisid:=tblcount%A_Index%
                            addchild(A_Index, thishnd)
                        }
                    }
                    wasredrawn:=1
                }
            }
        }
    }
    
    ;Check if any tables have been resized and if so, redraw
    if (wasredrawn = 0)                 
    {
        Loop, %tblcount%
        {
            retable:=source%A_Index%_hnd
            WinGetPos,wx,wy,ww,wh,ahk_id %retable%
            if (ww != source%A_Index%_wide)
            {
                unregisterthumbnail(source%A_Index%_thumb)
                addchild(A_Index, retable)
            }
        }
    }
}

Return


;Function to register the thumbnail to the GUI
registerthumbnail(target, source, thumbnum)
{
    Global    
    
    VarSetCapacity(thumbnail,4,0)
    hr1:=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)
}

;Function sets thumbnail properties and displays
updatethumbnail(source, thumbnum, thumbnail)
{    
    /*
    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 | 0x2 | 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)
    newx := ((colnum) * childwinw)
    newy := ((rownum - 1) * childwinh) 
    neww := newx + childwinw
    newh := newy + childwinh
    
    WinGetPos,wx,wy,ww,wh,ahk_id %source%
    
    VarSetCapacity(dskThumbProps,45,0)
    ;struct _DWM_THUMBNAIL_PROPERTIES
    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 of the thumb in relation to the target
    NumPut(newh,dskThumbProps,16,"Int")                   ;y coord of the right edge of the thumb in relation to the target
    NumPut(0,dskThumbProps,20,"Int")                      ;x coord of target to start thumb
    NumPut(0,dskThumbProps,24,"Int")                      ;y coord of target to start thumb
    NumPut(ww-borderx,dskThumbProps,28,"Int")                    ;width of the thumb in relation to the source
    NumPut(wh-captionh,dskThumbProps,32,"Int")                    ;height of the thumb in relation to the source
    NumPut(opacity,dskThumbProps,36,"UChar")
    NumPut(fVisible,dskThumbProps,37,"Int")
    NumPut(fSourceClientAreaOnly,dskThumbProps,41,"Int")
    hr2:=DllCall("dwmapi\DwmUpdateThumbnailProperties","UInt",thumbnail,"UInt",&dskThumbProps) 
    source%thumbnum%_wide:=ww-(borderx*2)
   
}


unregisterthumbnail(unthumbnail)
{
    ur1:=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
        
        ;The loop value will equal the number of tables per row
        Loop,%totaltables%
        {            
            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
    }
}

clickevent(wparam)
{
    local id,win,mousex,mousey,thumbx,thumby,thisrow,thiscol,thisslot,realw,thisx,thisy,thisw,zoom,closesize,xl,xr,yt,yb
    coordmode,mouse,relative
    mousegetpos,mousex,mousey,id
    if (id=target)
    {
        thumbx:=borderxb+borderxa
        thumby:=captionh
        
        ;Calculate slot number
        thisrow:=Ceil((mousey - thumby) / childwinh)
        thiscol:=Ceil((mousex - thumbx) / childwinw)
        
        thisslot:=((thisrow-1)*tablesw)+thiscol
        win:=source%thisslot%_hnd
        
        ;Calculate leave table button area
        realw:=source%thisslot%_wide
        thisx:= ((thiscol-1) * childwinw)+thumbx    ;correct
        xl:=floor((childwinw*((closexl-borderxa)/(ptablebasew-borderxa-borderxb)) + thisx))   
        xr:=floor((childwinw*((closexr-borderxa)/(ptablebasew-borderxa-borderxb)) + thisx)) 
        thisy:= ((thisrow - 1) * childwinh)+captionh+borderyb                                 
        yt:=floor((childwinh*((closeyt-captionh)/(ptablebaseh-captionh-borderyb)) + thisy))
        yb:=floor((childwinh*((closeyb-captionh)/(ptablebaseh-captionh-borderyb)) + thisy))        
        
        if (mousex>=xl and mousex<=xr and mousey>=yt and mousey<=yb)    ;Close table
            winclose,ahk_id%win%
        else
        {        
            ;Activate the window
            if (win >0)
                winactivate,ahk_id%win%
        }
    }
}
return

Form1_Close:
	ExitApp
return
Let me know how it goes
freo is offline   Reply With Quote
Old 11-16-2010, 03:10 PM   #31
DaycareInferno
Carpal \'Tunnel
 
DaycareInferno's Avatar
 
Join Date: Jun 2007
Posts: 18,279
Re: AHK Script: Stars Stacked Table Previewer

the main reason that i would use the close table is to close tables on stars where i don't get a seat in time and something else jumps on top of it. the way it is now, only tables you're seated at stay in the previewer, so you can't do that.
DaycareInferno is offline   Reply With Quote
Old 11-16-2010, 03:41 PM   #32
_dave_
_Pooh_Bah_
 
Join Date: Feb 2005
Location: UK (or what remains of it)
Posts: 12,945
Re: AHK Script: Stars Stacked Table Previewer

With Max1mum's changes to PokerStarsTableFrameClass, unseated tables should show up in the previewer.

maybe try:
Code:
windowtitle := "ahk_class PokerStarsTableFrameClass"
windowtitleexclude := ""
in the new configuration variables. not sure if quotes are required, i try to use them always. so if you copy this also copy the changes from a single = to := (allows use of quotes)
_dave_ is offline   Reply With Quote
Old 11-16-2010, 05:49 PM   #33
TimStone
See my staking forum thread
 
TimStone's Avatar
 
Join Date: Jan 2009
Location: all across Asia
Posts: 7,822
Re: AHK Script: Stars Stacked Table Previewer

as being said awesome script...

started using it yesterday...

is there a possibility to somehow hightlite tables where u volutarily invested money in the pot... i play 24 tables stacked and that would be very helpful imo... maybe that these tables get a red border or so... i don't really know wat is possible with ahk and stuff...
TimStone is offline   Reply With Quote
Old 11-16-2010, 05:50 PM   #34
BillytheKidd
grinder
 
Join Date: Apr 2006
Posts: 573
Re: AHK Script: Stars Stacked Table Previewer

everytime I get comfortable with my setup, someone makes something better...

looks really cool
BillytheKidd is offline   Reply With Quote
Old 11-16-2010, 06:23 PM   #35
freo
enthusiast
 
Join Date: Nov 2008
Posts: 90
Re: AHK Script: Stars Stacked Table Previewer

The change _dave_ made is correct. Thanks to MaxImum for the tip on using the control type. Below is the latest which will also preview tables you are not seated at. You can also click "Leave Table" in the preview to close it.
Code:
; freo's Stacked Table Previewer for PokerStars v1.1
; Shows thumbnails of all stacked tables in a preview window
; Only works in Vista/Windows7 with aero enabled
; 'clay973' on PS for donations


#SingleInstance Force
#NoEnv

DetectHiddenWindows,On
SetTitleMatchMode, 2

OnMessage(0x201,"clickevent")
;------------------------------------------------------------------------------------------------------------------
;User defined settings
hostwindoww=800         ;Host preview window width             
hostwindowh=900        ;Host preview window height
hostwindowx=850         ;Host preview window x position on screen
hostwindowy=0           ;Host preview window y position on screen
ptablebasew=483         ;Poker table base resolution width(For stars this is the smallest table resolution (483 x 353)
ptablebaseh=353         ;Poker table base resolution height(For stars this is the smallest table resolution (483 x 353)
closexl=418             ;Left x position of leave table button in relation to the resolution set against ptablebasew & ptablebaseh 
closexr=481             ;Right x position of leave table button in relation to the resolution set against ptablebasew & ptablebaseh 
closeyt=24              ;Top y position of leave table button in relation to the resolution set against ptablebasew & ptablebaseh 
closeyb=42              ;Bottom y position of leave table button in relation to the resolution set against ptablebasew & ptablebaseh 
refreshrate=3000        ;Number of seconds to wait between refreshes (1000 = 1 second)
windowtitle=ahk_class PokerStarsTableFrameClass  ;Window title to match to find tables - Pokerstars (use control type)
;windowtitle=Logged In as                     ;Window title to match to find tables - Pokerstars
;windowtitleexclude=PokerStars Lobby           ;Window title to exclude - Pokerstars
;windowtitle=Windows Internet Explorer           ;Window title to match to find tables - Internet Explorer
windowtitleexclude=                             ;Window title to exclude - Internet Explorer
;------------------------------------------------------------------------------------------------------------------

hModule := DllCall("LoadLibrary", "str", "dwmapi.dll")       ;Load dwmapi.dll for handling thumbnails
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
borderx := borderxa + borderxb                               ;Total size of the x border
bordery := borderya + borderyb                               ;Total size of the y border
captionh := captionha + borderyb                             ;Total size of the caption
clientareah := hostwindowh - bordery - captionh              ;Height of the area thumbnail windows can be placed in
clientareaw := hostwindoww - borderx - borderx               ;Width of the area thumbnail windows can be placed in
ptablehwratio := (ptablebaseh-captionha) / ptablebasew                  ;Ratio used for scaling thumbnail window size

;Create preview window
Gui, 99: +LastFound +LabelForm1_                            
target := WinExist()
Gui, 99: Show, w%hostwindoww% h%hostwindowh% x%hostwindowx% y%hostwindowy%, Table Preview

;Create Empty variables for storing thumbnail links
Loop, 98
{
    source%A_Index%_hnd:=0
    source%A_Index%_thumb:=0
    source%A_Index%_wide:=0
}

;Show existing tables
WinGet, list, list, %windowtitle%, ,%windowtitleexclude%

;Need to filter out false windows that have no controls
tblcount:=0
Loop, %list%
{
    thisid:=list%A_Index%
    ;WinGet,ctrllist,ControlList,ahk_id %thisid%
    ;If (ctrllist != "") and (thisid > 0)
    ;{
        tblcount++
        tblcount%tblcount%:=list%A_Index%
    ;}    
}

currentcnt:=tblcount                           

;Calculate child window size and number per row
tablesw := numtablesw(currentcnt)
childwinw := Floor(calcwinsize(tablesw, currentcnt))
childwinh := Floor(childwinw * ptablehwratio)

;Create child windows for tables already open
Loop, %tblcount%
{
    thisid:=tblcount%A_Index%
    addchild(A_Index, thisid)
}

;Infinite loop to monitor table opens, closes & resizes.
Loop,
{    
    Sleep, %refreshrate%
    
    wasredrawn:=0
    
    ;Find any closed tables
    Loop, 98
    {
        thishnd:=source%A_Index%_hnd
        if (thishnd > 0)
        {
            IfWinNotExist, ahk_id %thishnd%
            {
                source%A_Index%_hnd:=0
                source%A_Index%_thumb:=0
                source%A_Index%_wide:=0
            }
        }
    }
        
    ;Get new list of tables
    WinGet, list, list, %windowtitle%, ,%windowtitleexclude% 
    
    ;Need to filter out false windows that have no controls
    tblcount:=0
    Loop, %list%
    {
        thisid:=list%A_Index%
        ;WinGet,ctrllist,ControlList,ahk_id %thisid%
        ;If (ctrllist != "") and (thisid > 0)
        ;{
            tblcount+=1
            tblcount%tblcount%:=list%A_Index%
        ;}    
    }    
    
    ;Find any new tables
    Loop, %tblcount%
    {
        thishnd:=tblcount%A_Index%
        found:=0
        Loop,98
        {
            if (source%A_Index%_hnd = thishnd)
            {
                found:=1
                break            
            }
        }
        
        ;New table found
        if (found = 0)
        {
            ;Find first avail slot
            newslot:=0
            Loop,98
            {
                if (source%A_Index%_hnd = 0)
                {
                    newslot:=A_Index
                    break                    
                }
            }

            ;Determine whether an existing slot is available or a recalculation is required as its a new slot.
            if (newslot <= currentcnt)         ;Existing slot taken, no recalc required
            {
                addchild(newslot, thishnd)
            }
            else                                ;Need to recalculate to determine if new rows or columns are required
            {
                currentcnt += 1
                oldcols:=tablesw
                oldw:=childwinw
                tablesw := numtablesw(currentcnt)
                childwinw := Floor(calcwinsize(tablesw, currentcnt))
                childwinh := Floor(childwinw * ptablehwratio)
                if (oldcols = tablesw) and (oldw = childwinw)       ;Still a slot left at the end of the current config
                    addchild(newslot, thishnd)
                else                                                ;Need to redraw all thumbnails with diff config
                {
                    Loop, 98
                    {
                        unregisterthumbnail(source%A_Index%_thumb)            ;Unregister existing thumbs                         
                    }
                    
                    Loop, %tblcount%
                    {
                        if(A_Index < tblcount)
                        {
                            thisid:=source%A_Index%_hnd
                            addchild(A_Index, thisid)
                        }
                        else
                        {
                            thisid:=tblcount%A_Index%
                            addchild(A_Index, thishnd)
                        }
                    }
                    wasredrawn:=1
                }
            }
        }
    }
    
    ;Check if any tables have been resized and if so, redraw
    if (wasredrawn = 0)                 
    {
        Loop, %tblcount%
        {
            retable:=source%A_Index%_hnd
            WinGetPos,wx,wy,ww,wh,ahk_id %retable%
            if (ww != source%A_Index%_wide)
            {
                unregisterthumbnail(source%A_Index%_thumb)
                addchild(A_Index, retable)
            }
        }
    }
}

Return


;Function to register the thumbnail to the GUI
registerthumbnail(target, source, thumbnum)
{
    Global    
    
    VarSetCapacity(thumbnail,4,0)
    hr1:=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)
}

;Function sets thumbnail properties and displays
updatethumbnail(source, thumbnum, thumbnail)
{    
    /*
    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 | 0x2 | 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)
    newx := ((colnum) * childwinw)
    newy := ((rownum - 1) * childwinh) 
    neww := newx + childwinw
    newh := newy + childwinh
    
    WinGetPos,wx,wy,ww,wh,ahk_id %source%
    
    VarSetCapacity(dskThumbProps,45,0)
    ;struct _DWM_THUMBNAIL_PROPERTIES
    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 of the thumb in relation to the target
    NumPut(newh,dskThumbProps,16,"Int")                   ;y coord of the right edge of the thumb in relation to the target
    NumPut(0,dskThumbProps,20,"Int")                      ;x coord of target to start thumb
    NumPut(0,dskThumbProps,24,"Int")                      ;y coord of target to start thumb
    NumPut(ww-borderx,dskThumbProps,28,"Int")                    ;width of the thumb in relation to the source
    NumPut(wh-captionh,dskThumbProps,32,"Int")                    ;height of the thumb in relation to the source
    NumPut(opacity,dskThumbProps,36,"UChar")
    NumPut(fVisible,dskThumbProps,37,"Int")
    NumPut(fSourceClientAreaOnly,dskThumbProps,41,"Int")
    hr2:=DllCall("dwmapi\DwmUpdateThumbnailProperties","UInt",thumbnail,"UInt",&dskThumbProps) 
    source%thumbnum%_wide:=ww-(borderx*2)
   
}


unregisterthumbnail(unthumbnail)
{
    ur1:=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
        
        ;The loop value will equal the number of tables per row
        Loop,%totaltables%
        {            
            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
    }
}

clickevent(wparam)
{
    local id,win,mousex,mousey,thumbx,thumby,thisrow,thiscol,thisslot,realw,thisx,thisy,thisw,zoom,closesize,xl,xr,yt,yb
    coordmode,mouse,relative
    mousegetpos,mousex,mousey,id
    if (id=target)
    {
        thumbx:=borderxb+borderxa
        thumby:=captionh
        
        ;Calculate slot number
        thisrow:=Ceil((mousey - thumby) / childwinh)
        thiscol:=Ceil((mousex - thumbx) / childwinw)
        
        thisslot:=((thisrow-1)*tablesw)+thiscol
        win:=source%thisslot%_hnd
        
        ;Calculate leave table button area
        realw:=source%thisslot%_wide
        thisx:= ((thiscol-1) * childwinw)+thumbx    ;correct
        xl:=floor((childwinw*((closexl-borderxa)/(ptablebasew-borderxa-borderxb)) + thisx))   
        xr:=floor((childwinw*((closexr-borderxa)/(ptablebasew-borderxa-borderxb)) + thisx)) 
        thisy:= ((thisrow - 1) * childwinh)+captionh+borderyb                                 
        yt:=floor((childwinh*((closeyt-captionh)/(ptablebaseh-captionh-borderyb)) + thisy))
        yb:=floor((childwinh*((closeyb-captionh)/(ptablebaseh-captionh-borderyb)) + thisy))        
        
        if (mousex>=xl and mousex<=xr and mousey>=yt and mousey<=yb)    ;Close table
            winclose,ahk_id%win%
        else
        {        
            ;Activate the window
            if (win >0)
                winactivate,ahk_id%win%
        }
    }
}
return

Form1_Close:
	ExitApp
return
freo is offline   Reply With Quote
Old 11-16-2010, 06:28 PM   #36
freo
enthusiast
 
Join Date: Nov 2008
Posts: 90
Re: AHK Script: Stars Stacked Table Previewer

Quote:
Originally Posted by TimStone View Post
as being said awesome script...

started using it yesterday...

is there a possibility to somehow hightlite tables where u volutarily invested money in the pot... i play 24 tables stacked and that would be very helpful imo... maybe that these tables get a red border or so... i don't really know wat is possible with ahk and stuff...
Drawing the red border shouldnt be a problem. I just have to have a think about how to tell if you are VPIP'ing.
freo is offline   Reply With Quote
Old 11-16-2010, 07:57 PM   #37
TimStone
See my staking forum thread
 
TimStone's Avatar
 
Join Date: Jan 2009
Location: all across Asia
Posts: 7,822
Re: AHK Script: Stars Stacked Table Previewer

Quote:
Originally Posted by freo View Post
Drawing the red border shouldnt be a problem. I just have to have a think about how to tell if you are VPIP'ing.
probably red boarder just in line with the active table for me would work as well so that i sometimes can follow the results in the preview window... should be easier to implement when the VPIP thing is too much of a hassle...

thanks so much so far...
TimStone is offline   Reply With Quote
Old 11-17-2010, 04:07 AM   #38
Furio
centurion
 
Furio's Avatar
 
Join Date: Sep 2007
Location: London
Posts: 154
Re: AHK Script: Stars Stacked Table Previewer

Thanks for the updates. Sent a small donation.

I use this on FTP and it worked before but now I cannot find where to add the full tilt recognition line in the new script. Can you point me in the right direction?
Furio is offline   Reply With Quote
Old 11-17-2010, 04:34 AM   #39
freo
enthusiast
 
Join Date: Nov 2008
Posts: 90
Re: AHK Script: Stars Stacked Table Previewer

Quote:
Originally Posted by Furio View Post
Thanks for the updates. Sent a small donation.

I use this on FTP and it worked before but now I cannot find where to add the full tilt recognition line in the new script. Can you point me in the right direction?
You need to change the line below to the Full Tilt window class name. I'm at work at the moment so cannot check for sure what that name is but I just read it was "QWidget". Can anyone here help with that? Or you can find it yourself using Active Window that comes with autohotkey.

But anyway, first try QWidget:

change this line:
windowtitle=ahk_class PokerStarsTableFrameClass

to this:
windowtitle=ahk_class QWidget


Let me know how that goes. Also, you may know this already but it would probably work better if you set the Full Tilt table sizes up correctly which are these settings (Pokerstars settings at the moment):
ptablebasew=whatever
ptablebaseh=whatever

Then if you want the close table to work you'll also need to set these which tell the script where in the thumbnail to look for a click to close. These setting are in relation to the window sizes set in the 2 settings above.
closexl=whatever
closexr=whatever
closeyt=whatever
closeyb=whatever

I'll look at incorporating the Full Tilt settings into the script when I get a chance.
freo is offline   Reply With Quote
Old 11-17-2010, 04:45 AM   #40
freo
enthusiast
 
Join Date: Nov 2008
Posts: 90
Re: AHK Script: Stars Stacked Table Previewer

Quote:
Originally Posted by Furio View Post
Thanks for the updates. Sent a small donation.
Many thanks. Appreciate it.
freo is offline   Reply With Quote
Old 11-17-2010, 05:01 AM   #41
Furio
centurion
 
Furio's Avatar
 
Join Date: Sep 2007
Location: London
Posts: 154
Re: AHK Script: Stars Stacked Table Previewer

QWidget worked fine (apart from including the lobby but this is no a big issue. I tried to use windowspy to see what i could exclude but failed).

The issue I have atm is that there are gaps in the layout. I redid the minsize for FTP and it still has gaps in the layout. The gaps have a small grey rectangle in the left top corner with a small red dot in the centre.
Furio is offline   Reply With Quote
Old 11-17-2010, 05:08 AM   #42
freo
enthusiast
 
Join Date: Nov 2008
Posts: 90
Re: AHK Script: Stars Stacked Table Previewer

Not too sure about that, i'm off to play some live poker but will check out how it works with FTP when I get home if its not too late.

Were you getting that problem with the prior version?
freo is offline   Reply With Quote
Old 11-17-2010, 05:23 AM   #43
Furio
centurion
 
Furio's Avatar
 
Join Date: Sep 2007
Location: London
Posts: 154
Re: AHK Script: Stars Stacked Table Previewer

Quote:
Originally Posted by freo View Post
Were you getting that problem with the prior version?
Nope, so I assume it is something to do with the table closing being added maybe.
Furio is offline   Reply With Quote
Old 11-17-2010, 09:15 AM   #44
freo
enthusiast
 
Join Date: Nov 2008
Posts: 90
Re: AHK Script: Stars Stacked Table Previewer

Ok, heres the latest version with Full Tilt support.

If you play on pokerstars you just need to set
pokersite=ps

If you play on Full Tilt you need to set
pokersite=ft

The close feature works on Pokerstars by clicking the "Leave Table" icon in the thumbnail.

The close feature works on FullTilt by clicking the blue icons in the top right corner of the thumbnail (Options/Lobby/Stats)

Thanks again to Max1mums for the tips on filtering FTP windows.

Code:
; freo's Stacked Table Previewer for PokerStars v1.11
; Shows thumbnails of all stacked tables in a preview window
; Only works in Vista/Windows7 with aero enabled
; 'clay973' on PS for donations

;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
;Click the "Leave Table" icon on Pokerstars thumbnails or the Options/Lobby/Stats icons on FTP thumbnails to leave the table

#SingleInstance Force
#NoEnv

DetectHiddenWindows,On
SetTitleMatchMode, 2

OnMessage(0x201,"clickevent")
;------------------------------------------------------------------------------------------------------------------
;User defined settings
pokersite=ps           ;Pokersite ID - ps for Pokerstars : ft for Full Tilt : cu for customised (you'll need to change cu settings further down)
hostwindoww=800         ;Host preview window width             
hostwindowh=900        ;Host preview window height
hostwindowx=850         ;Host preview window x position on screen
hostwindowy=0           ;Host preview window y position on screen
refreshrate=3000        ;Number of seconds to wait between refreshes (1000 = 1 second)
;------------------------------------------------------------------------------------------------------------------

if pokersite = ps
{
    ptablebasew=483                                     ;Poker table base resolution width(For stars this is the smallest table resolution (483 x 353)
    ptablebaseh=353                                     ;Poker table base resolution height(For stars this is the smallest table resolution (483 x 353)
    
    ;Close settings - On Pokerstars this is the area of the Leave Table icon in the top right of the thumbnail
    closexl=418                                         ;Left x position of leave table button in relation to the resolution set against ptablebasew & ptablebaseh 
    closexr=481                                         ;Right x position of leave table button in relation to the resolution set against ptablebasew & ptablebaseh 
    closeyt=24                                          ;Top y position of leave table button in relation to the resolution set against ptablebasew & ptablebaseh 
    closeyb=42                                          ;Bottom y position of leave table button in relation to the resolution set against ptablebasew & ptablebaseh
    
    windowtitle=ahk_class PokerStarsTableFrameClass     ;Window title to match to find tables - Pokerstars (use window class (ahk_class prefixed))
    windowtitleexclude=                                 ;Window title to exclude 
}
else if pokersite = ft
{
    ptablebasew=480                                     ;Poker table base resolution width
    ptablebaseh=351                                     ;Poker table base resolution height
    
    ;Close settings - On Full Tilt this is the area of the blue Options/Lobby/Stats icons in the top right of the thumbnail
    closexl=427                                         ;Left x position of leave table button in relation to the resolution set against ptablebasew & ptablebaseh 
    closexr=478                                         ;Right x position of leave table button in relation to the resolution set against ptablebasew & ptablebaseh 
    closeyt=22                                          ;Top y position of leave table button in relation to the resolution set against ptablebasew & ptablebaseh 
    closeyb=52                                          ;Bottom y position of leave table button in relation to the resolution set against ptablebasew & ptablebaseh
    
    windowtitle=Logged In ahk_class QWidget             ;Window title to match to find tables - (use window class (ahk_class prefixed))
    windowtitleexclude=Full Tilt                        ;Window title to exclude  
}
else if pokersite = cu         ;Change these settings for a custom site/application
{
    ptablebasew=483                                     ;Poker table base resolution width(For stars this is the smallest table resolution (483 x 353)
    ptablebaseh=353                                     ;Poker table base resolution height(For stars this is the smallest table resolution (483 x 353)
    closexl=418                                         ;Left x position of leave table button in relation to the resolution set against ptablebasew & ptablebaseh 
    closexr=481                                         ;Right x position of leave table button in relation to the resolution set against ptablebasew & ptablebaseh 
    closeyt=24                                          ;Top y position of leave table button in relation to the resolution set against ptablebasew & ptablebaseh 
    closeyb=42                                          ;Bottom y position of leave table button in relation to the resolution set against ptablebasew & ptablebaseh
    windowtitle=ahk_class PokerStarsTableFrameClass     ;Window title to match to find tables - Pokerstars (use control type)
    windowtitleexclude=                                 ;Window title to exclude 
}

hModule := DllCall("LoadLibrary", "str", "dwmapi.dll")       ;Load dwmapi.dll for handling thumbnails
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
borderx := borderxa + borderxb                               ;Total size of the x border
bordery := borderya + borderyb                               ;Total size of the y border
captionh := captionha + borderyb                             ;Total size of the caption
clientareah := hostwindowh - bordery - captionh              ;Height of the area thumbnail windows can be placed in
clientareaw := hostwindoww - borderx - borderx               ;Width of the area thumbnail windows can be placed in
ptablehwratio := (ptablebaseh-captionha) / ptablebasew                  ;Ratio used for scaling thumbnail window size

;Create preview window
Gui, 99: +LastFound +LabelForm1_                            
target := WinExist()
Gui, 99: Show, w%hostwindoww% h%hostwindowh% x%hostwindowx% y%hostwindowy%, Table Preview

;Create Empty variables for storing thumbnail links
Loop, 98
{
    source%A_Index%_hnd:=0
    source%A_Index%_thumb:=0
    source%A_Index%_wide:=0
}

;Show existing tables
WinGet, list, list, %windowtitle%, ,%windowtitleexclude%
tblcount:=0
Loop, %list%
{
    tblcount++
    tblcount%tblcount%:=list%A_Index%    
}

currentcnt:=tblcount                           

;Calculate child window size and number per row
tablesw := numtablesw(currentcnt)
childwinw := Floor(calcwinsize(tablesw, currentcnt))
childwinh := Floor(childwinw * ptablehwratio)

;Create child windows for tables already open
Loop, %tblcount%
{
    thisid:=tblcount%A_Index%
    addchild(A_Index, thisid)
}

;Infinite loop to monitor table opens, closes & resizes.
Loop,
{    
    Sleep, %refreshrate%
    
    wasredrawn:=0
    
    ;Find any closed tables
    Loop, 98
    {
        thishnd:=source%A_Index%_hnd
        if (thishnd > 0)
        {
            IfWinNotExist, ahk_id %thishnd%
            {
                source%A_Index%_hnd:=0
                source%A_Index%_thumb:=0
                source%A_Index%_wide:=0
            }
        }
    }
        
    ;Get new list of tables
    WinGet, list, list, %windowtitle%, ,%windowtitleexclude% 
    tblcount:=0
    Loop, %list%
    {
        tblcount++
        tblcount%tblcount%:=list%A_Index%    
    }    
    
    ;Find any new tables
    Loop, %tblcount%
    {
        thishnd:=tblcount%A_Index%
        found:=0
        Loop,98
        {
            if (source%A_Index%_hnd = thishnd)
            {
                found:=1
                break            
            }
        }
        
        ;New table found
        if (found = 0)
        {
            ;Find first avail slot
            newslot:=0
            Loop,98
            {
                if (source%A_Index%_hnd = 0)
                {
                    newslot:=A_Index
                    break                    
                }
            }

            ;Determine whether an existing slot is available or a recalculation is required as its a new slot.
            if (newslot <= currentcnt)         ;Existing slot taken, no recalc required
            {
                addchild(newslot, thishnd)
            }
            else                                ;Need to recalculate to determine if new rows or columns are required
            {
                currentcnt += 1
                oldcols:=tablesw
                oldw:=childwinw
                tablesw := numtablesw(currentcnt)
                childwinw := Floor(calcwinsize(tablesw, currentcnt))
                childwinh := Floor(childwinw * ptablehwratio)
                if (oldcols = tablesw) and (oldw = childwinw)       ;Still a slot left at the end of the current config
                    addchild(newslot, thishnd)
                else                                                ;Need to redraw all thumbnails with diff config
                {
                    Loop, 98
                    {
                        unregisterthumbnail(source%A_Index%_thumb)            ;Unregister existing thumbs                         
                    }
                    
                    Loop, %tblcount%
                    {
                        if(A_Index < tblcount)
                        {
                            thisid:=source%A_Index%_hnd
                            addchild(A_Index, thisid)
                        }
                        else
                        {
                            thisid:=tblcount%A_Index%
                            addchild(A_Index, thishnd)
                        }
                    }
                    wasredrawn:=1
                }
            }
        }
    }
    
    ;Check if any tables have been resized and if so, redraw
    if (wasredrawn = 0)                 
    {
        Loop, %tblcount%
        {
            retable:=source%A_Index%_hnd
            WinGetPos,wx,wy,ww,wh,ahk_id %retable%
            if (ww != source%A_Index%_wide)
            {
                unregisterthumbnail(source%A_Index%_thumb)
                addchild(A_Index, retable)
            }
        }
    }
}

Return


;Function to register the thumbnail to the GUI
registerthumbnail(target, source, thumbnum)
{
    Global    
    
    VarSetCapacity(thumbnail,4,0)
    hr1:=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)
}

;Function sets thumbnail properties and displays
updatethumbnail(source, thumbnum, thumbnail)
{    
    /*
    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 | 0x2 | 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)
    newx := ((colnum) * childwinw)
    newy := ((rownum - 1) * childwinh) 
    neww := newx + childwinw
    newh := newy + childwinh
    
    WinGetPos,wx,wy,ww,wh,ahk_id %source%
    
    VarSetCapacity(dskThumbProps,45,0)
    ;struct _DWM_THUMBNAIL_PROPERTIES
    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 of the thumb in relation to the target
    NumPut(newh,dskThumbProps,16,"Int")                   ;y coord of the right edge of the thumb in relation to the target
    NumPut(0,dskThumbProps,20,"Int")                      ;x coord of target to start thumb
    NumPut(0,dskThumbProps,24,"Int")                      ;y coord of target to start thumb
    NumPut(ww-borderx,dskThumbProps,28,"Int")                    ;width of the thumb in relation to the source
    NumPut(wh-captionh,dskThumbProps,32,"Int")                    ;height of the thumb in relation to the source
    NumPut(opacity,dskThumbProps,36,"UChar")
    NumPut(fVisible,dskThumbProps,37,"Int")
    NumPut(fSourceClientAreaOnly,dskThumbProps,41,"Int")
    hr2:=DllCall("dwmapi\DwmUpdateThumbnailProperties","UInt",thumbnail,"UInt",&dskThumbProps) 
    source%thumbnum%_wide:=ww-(borderx*2)
   
}


unregisterthumbnail(unthumbnail)
{
    ur1:=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
        
        ;The loop value will equal the number of tables per row
        Loop,%totaltables%
        {            
            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
    }
}

clickevent(wparam)
{
    local id,win,mousex,mousey,thumbx,thumby,thisrow,thiscol,thisslot,realw,thisx,thisy,thisw,zoom,closesize,xl,xr,yt,yb
    coordmode,mouse,relative
    mousegetpos,mousex,mousey,id
    if (id=target)
    {
        thumbx:=borderxb+borderxa
        thumby:=captionh
        
        ;Calculate slot number
        thisrow:=Ceil((mousey - thumby) / childwinh)
        thiscol:=Ceil((mousex - thumbx) / childwinw)
        
        thisslot:=((thisrow-1)*tablesw)+thiscol
        win:=source%thisslot%_hnd
        
        ;Calculate leave table button area
        realw:=source%thisslot%_wide
        thisx:= ((thiscol-1) * childwinw)+thumbx    ;correct
        xl:=floor((childwinw*((closexl-borderxa)/(ptablebasew-borderxa-borderxb)) + thisx))   
        xr:=floor((childwinw*((closexr-borderxa)/(ptablebasew-borderxa-borderxb)) + thisx)) 
        thisy:= ((thisrow - 1) * childwinh)+captionh+borderyb                                 
        yt:=floor((childwinh*((closeyt-captionh)/(ptablebaseh-captionh-borderyb)) + thisy))
        yb:=floor((childwinh*((closeyb-captionh)/(ptablebaseh-captionh-borderyb)) + thisy))        
        
        if (mousex>=xl and mousex<=xr and mousey>=yt and mousey<=yb)    ;Close table
            winclose,ahk_id%win%
        else
        {        
            ;Activate the window
            if (win >0)
                winactivate,ahk_id%win%
        }
    }
}
return

Form1_Close:
	ExitApp
return

Last edited by freo; 11-17-2010 at 09:41 AM.
freo is offline   Reply With Quote
Old 11-17-2010, 09:29 AM   #45
Furio
centurion
 
Furio's Avatar
 
Join Date: Sep 2007
Location: London
Posts: 154
Re: AHK Script: Stars Stacked Table Previewer

Quote:
Originally Posted by freo View Post
Ok, heres the latest version with Full Tilt support.
Seems to work perfectly tyvm
Furio is offline   Reply With Quote
Old 11-18-2010, 10:46 AM   #46
freo
enthusiast
 
Join Date: Nov 2008
Posts: 90
Re: AHK Script: Stacked Table Previewer

Latest version:

- Highlights the active table green in the thumbnail (Color and border width can be changed in the user defined settings)
- Highlights the previous active table pink (Color and border width can be changed in the user defined settings)
- Displays number of open tables in the preview window title (in the caption)

Have tested in both PS and FT, but let me know how it goes.
Code:
; freo's Stacked Table Previewer v1.11
; Only works in Vista/Windows7 with aero enabled
; 'clay973' on PS for donations

;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
;Click the "Leave Table" icon on Pokerstars thumbnails or the Options/Lobby/Stats icons on FTP thumbnails to leave the table
;Displays number of open tables in the preview window title (in the caption)
;Highlights the active table green in the thumbnail (Color and border width can be changed in the user defined settings)
;Highlights the previous active table pink (Color and border width can be changed in the user defined settings)

#SingleInstance Force
#NoEnv

DetectHiddenWindows,On
SetTitleMatchMode, 2

OnMessage(0x201,"clickevent")
OnMessage(0x46, "WM_WINDOWPOSCHANGING")

;------------------------------------------------------------------------------------------------------------------
;User defined settings
pokersite=ps                    ;Pokersite ID - ps for Pokerstars : ft for Full Tilt : cu for customised (you'll need to change cu settings further down)
hostwindoww=800                ;Host preview window width             
hostwindowh=900                 ;Host preview window height
hostwindowx=800                 ;Host preview window x position on screen
hostwindowy=0                  ;Host preview window y position on screen
refreshrate=3000                ;Number of seconds to wait between refreshes (1000 = 1 second)
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 boredr for the last active window

;------------------------------------------------------------------------------------------------------------------

if pokersite = ps
{
    ptablebasew=483                                     ;Poker table base resolution width(For stars this is the smallest table resolution (483 x 353)
    ptablebaseh=353                                     ;Poker table base resolution height(For stars this is the smallest table resolution (483 x 353)
    
    ;Close settings - On Pokerstars this is the area of the Leave Table icon in the top right of the thumbnail
    closexl=418                                         ;Left x position of leave table button in relation to the resolution set against ptablebasew & ptablebaseh 
    closexr=481                                         ;Right x position of leave table button in relation to the resolution set against ptablebasew & ptablebaseh 
    closeyt=24                                          ;Top y position of leave table button in relation to the resolution set against ptablebasew & ptablebaseh 
    closeyb=42                                          ;Bottom y position of leave table button in relation to the resolution set against ptablebasew & ptablebaseh
    
    windowtitle=ahk_class PokerStarsTableFrameClass     ;Window title to match to find tables - Pokerstars (use window class (ahk_class prefixed))
    windowtitleexclude=                                 ;Window title to exclude 
}
else if pokersite = ft
{
    ptablebasew=480                                     ;Poker table base resolution width
    ptablebaseh=351                                     ;Poker table base resolution height
    
    ;Close settings - On Full Tilt this is the area of the blue Options/Lobby/Stats icons in the top right of the thumbnail
    closexl=427                                         ;Left x position of leave table button in relation to the resolution set against ptablebasew & ptablebaseh 
    closexr=478                                         ;Right x position of leave table button in relation to the resolution set against ptablebasew & ptablebaseh 
    closeyt=22                                          ;Top y position of leave table button in relation to the resolution set against ptablebasew & ptablebaseh 
    closeyb=52                                          ;Bottom y position of leave table button in relation to the resolution set against ptablebasew & ptablebaseh
    
    windowtitle=Logged In ahk_class QWidget             ;Window title to match to find tables - (use window class (ahk_class prefixed))
    windowtitleexclude=Full Tilt                        ;Window title to exclude  
}
else if pokersite = cu         ;Change these settings for a custom site/application
{
    ptablebasew=483                                     ;Poker table base resolution width(For stars this is the smallest table resolution (483 x 353)
    ptablebaseh=353                                     ;Poker table base resolution height(For stars this is the smallest table resolution (483 x 353)
    closexl=418                                         ;Left x position of leave table button in relation to the resolution set against ptablebasew & ptablebaseh 
    closexr=481                                         ;Right x position of leave table button in relation to the resolution set against ptablebasew & ptablebaseh 
    closeyt=24                                          ;Top y position of leave table button in relation to the resolution set against ptablebasew & ptablebaseh 
    closeyb=42                                          ;Bottom y position of leave table button in relation to the resolution set against ptablebasew & ptablebaseh
    windowtitle=My win ahk_class AutoHotkeyGUI          ;Window title to match to find tables - Pokerstars (use control type)
    windowtitleexclude=                                 ;Window title to exclude 
}

hModule := DllCall("LoadLibrary", "str", "dwmapi.dll")       ;Load dwmapi.dll for handling thumbnails
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
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
clientareah := hostwindowh - bordery - captionh              ;Height of the area thumbnail windows can be placed in
clientareaw := hostwindoww - borderx - borderx               ;Width of the area thumbnail windows can be placed in
clientareax := hostwindowx + borderx
clientareay := hostwindowy + captionh
ptablehwratio := (ptablebaseh-captionha) / ptablebasew                  ;Ratio used for scaling thumbnail window size
lastactive:=0
thisactive:=0
borderguix:=clientareax
borderguiy:=clientareay

;Create preview window
Gui, 99: +LastFound +LabelForm1_                            
target := WinExist()

;Test calls
;DLL hook for detecting window activations (for colored active table borders)
DllCall( "RegisterShellHookWindow", UInt,target) 
MsgNum := DllCall( "RegisterWindowMessage", Str,"SHELLHOOK" )
OnMessage( MsgNum, "ShellMessage" )

;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()


;Create Empty variables for storing thumbnail links
Loop, 98
{
    source%A_Index%_hnd:=0
    source%A_Index%_thumb:=0
    source%A_Index%_wide:=0
}

;Show existing tables
WinGet, list, list, %windowtitle%, ,%windowtitleexclude%
tblcount:=0
Loop, %list%
{
    tblcount++
    tblcount%tblcount%:=list%A_Index%    
}

currentcnt:=tblcount                           

;Calculate child window size and number per row
tablesw := numtablesw(currentcnt)
childwinw := Floor(calcwinsize(tablesw, currentcnt))
childwinh := Floor(childwinw * ptablehwratio)

;Create child windows for tables already open
Loop, %tblcount%
{
    thisid:=tblcount%A_Index%
    addchild(A_Index, thisid)
}

Gui, 99: Show, w%hostwindoww% h%hostwindowh% x%hostwindowx% y%hostwindowy%, %tblcount% Tables Previewed

;Infinite loop to monitor table opens, closes & resizes.
Loop,
{    
    Sleep, %refreshrate%
    
    wasredrawn:=0
    
    ;Find any closed tables
    Loop, 98
    {
        thishnd:=source%A_Index%_hnd
        if (thishnd > 0)
        {
            IfWinNotExist, ahk_id %thishnd%
            {
                source%A_Index%_hnd:=0
                source%A_Index%_thumb:=0
                source%A_Index%_wide:=0
            }
        }
    }
        
    ;Get new list of tables
    WinGet, list, list, %windowtitle%, ,%windowtitleexclude% 
    tblcount:=0
    Loop, %list%
    {
        tblcount++
        tblcount%tblcount%:=list%A_Index%    
    }    
    
    ;Find any new tables
    Loop, %tblcount%
    {
        thishnd:=tblcount%A_Index%
        found:=0
        Loop,98
        {
            if (source%A_Index%_hnd = thishnd)
            {
                found:=1
                break            
            }
        }
        
        ;New table found
        if (found = 0)
        {
            ;Find first avail slot
            newslot:=0
            Loop,98
            {
                if (source%A_Index%_hnd = 0)
                {
                    newslot:=A_Index
                    break                    
                }
            }

            ;Determine whether an existing slot is available or a recalculation is required as its a new slot.
            if (newslot <= currentcnt)         ;Existing slot taken, no recalc required
            {
                addchild(newslot, thishnd)
            }
            else                                ;Need to recalculate to determine if new rows or columns are required
            {
                currentcnt += 1
                oldcols:=tablesw
                oldw:=childwinw
                tablesw := numtablesw(currentcnt)
                childwinw := Floor(calcwinsize(tablesw, currentcnt))
                childwinh := Floor(childwinw * ptablehwratio)
                if (oldcols = tablesw) and (oldw = childwinw)       ;Still a slot left at the end of the current config
                    addchild(newslot, thishnd)
                else                                                ;Need to redraw all thumbnails with diff config
                {
                    Loop, 98
                    {
                        unregisterthumbnail(source%A_Index%_thumb)            ;Unregister existing thumbs                         
                    }
                    
                    Loop, %tblcount%
                    {
                        if(A_Index < tblcount)
                        {
                            thisid:=source%A_Index%_hnd
                            addchild(A_Index, thisid)
                        }
                        else
                        {
                            thisid:=tblcount%A_Index%
                            addchild(A_Index, thishnd)
                        }
                    }
                    wasredrawn:=1
                }
            }
        }
    }
    
    ;Check if any tables have been resized and if so, redraw
    if (wasredrawn = 0)                 
    {
        Loop, %tblcount%
        {
            retable:=source%A_Index%_hnd
            WinGetPos,wx,wy,ww,wh,ahk_id %retable%
            if (ww != source%A_Index%_wide)
            {
                unregisterthumbnail(source%A_Index%_thumb)
                addchild(A_Index, retable)
            }
        }
    }
    WinSetTitle, ahk_id %target%, ,%tblcount% Tables Previewed
}

Return


;Function to register the thumbnail to the GUI
registerthumbnail(target, source, thumbnum)
{
    Global    
    
    VarSetCapacity(thumbnail,4,0)
    hr1:=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)
}

;Function sets thumbnail properties and displays
updatethumbnail(source, thumbnum, thumbnail)
{    
    /*
    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 | 0x2 | 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)
    newx := ((colnum) * childwinw)
    newy := ((rownum - 1) * childwinh) 
    neww := newx + childwinw
    newh := newy + childwinh
    
    WinGetPos,wx,wy,ww,wh,ahk_id %source%
    
    VarSetCapacity(dskThumbProps,45,0)
    ;struct _DWM_THUMBNAIL_PROPERTIES
    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 of the thumb in relation to the target
    NumPut(newh,dskThumbProps,16,"Int")                   ;y coord of the right edge of the thumb in relation to the target
    NumPut(0,dskThumbProps,20,"Int")                      ;x coord of target to start thumb
    NumPut(0,dskThumbProps,24,"Int")                      ;y coord of target to start thumb
    NumPut(ww-borderx,dskThumbProps,28,"Int")                    ;width of the thumb in relation to the source
    NumPut(wh-captionh,dskThumbProps,32,"Int")                    ;height of the thumb in relation to the source
    NumPut(opacity,dskThumbProps,36,"UChar")
    NumPut(fVisible,dskThumbProps,37,"Int")
    NumPut(fSourceClientAreaOnly,dskThumbProps,41,"Int")
    hr2:=DllCall("dwmapi\DwmUpdateThumbnailProperties","UInt",thumbnail,"UInt",&dskThumbProps) 
    source%thumbnum%_wide:=ww-(borderx*2)
   
}


unregisterthumbnail(unthumbnail)
{
    ur1:=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
        
        ;The loop value will equal the number of tables per row
        Loop,%totaltables%
        {            
            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 id,win,mousex,mousey,thisslot,thisrow,thiscol,xl,xr,yt,yb
    coordmode,mouse,relative
    mousegetpos,mousex,mousey,id
    if (id=target)
    {
        ;Calculate slot number
        thisrow:=Ceil((mousey - captionh) / childwinh)
        thiscol:=Ceil((mousex - borderx) / childwinw)
        thisslot:=((thisrow-1)*tablesw)+thiscol
        getcoords(thisslot,thisrow,thiscol,closexl,closexr,closeyt,closeyb,xl,xr,yt,yb)
        win:=source%thisslot%_hnd
        ;Action to take
        if (mousex>=(xl-1) and mousex<=(xr-1) and mousey>=(yt+1) and mousey<=(yb+1))    ;Close table
            winclose,ahk_id%win%
        else
        {        
            if (win >0)                                                 ;Activate the window
                winactivate,ahk_id%win%
        }
    }
}

;Calculates the four coordinates of a rectangle in a thumbnail
getcoords(calcslot,thisrow,thiscol,rectxl,rectxr,rectyt,rectyb,ByRef thisxl,ByRef thisxr,ByRef thisyt,ByRef thisyb)
{
    Global    
    
    ;Calculate coords
    realw:=source%calcslot%_wide
    thisx:= ((thiscol-1) * childwinw)+borderx
    thisy:= ((thisrow - 1) * childwinh)+captionh ;+bordery 
    thisxl:=floor((childwinw*((rectxl-borderx)/(ptablebasew-borderx))) + thisx)
    thisxr:=floor((childwinw*((rectxr-borderx)/(ptablebasew-borderx))) + thisx) 
    thisyt:=floor((childwinh*((rectyt-captionh)/(ptablebaseh-captionh-bordery))) + thisy)
    thisyb:=floor((childwinh*((rectyb-captionh)/(ptablebaseh-captionh-bordery))) + thisy) 
    
    return
}

;Function for docking the border gui's to the preview window
WM_WINDOWPOSCHANGING(wParam, lParam) 
{ 
    Global captionh,borderx,thisactive,lastactive, borderguix, borderguiy
    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") + borderx
        borderguiy := NumGet(lParam+12,0,"int") + captionh
        
        ; Move - but don't activate - Border Gui's 
        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
    {    
        ;If the activated window is in the list set the active and last active window
        matchcnt:=0
        Loop, 98 
        {
            matchcnt++
            if(source%matchcnt%_hnd = lParam)
                break
        }    
        if (matchcnt < 98 and thisactive != lParam)
        {
            ;Set and display active table border gui's
            drawborder(1,matchcnt)
            lastactive:=thisactive
            thisactive:=lParam  
            if(lastactive > 0)
            {
                matchcnt:=0
                Loop, 98 
                {
                    matchcnt++
                    if(source%matchcnt%_hnd = lastactive)
                        break
                } 
                drawborder(2,matchcnt)
            }
        }
    }
}

drawborder(guinum, slotnumb)
{
    Global
    ;Get the thumbnail outer edge coords
    thisrow:=Ceil(slotnumb/tablesw)
    thiscol:=Mod(slotnumb - 1,tablesw)+1
    getcoords(slotnumb,thisrow,thiscol,borderx,ptablebasew-borderx,captionh,ptablebaseh-bordery,xl,xr,yt,yb)
    
    if(guinum=1)
        thisgui:=activegui
    else
        thisgui:=lactivegui
    
    xl-=borderx
    xr-=borderx
    yt-=captionh
    yb-=captionh    
    
    xli:=xl+activebordersize
    xri:=xr-activebordersize
    yti:=yt+activebordersize
    ybi:=yb-activebordersize
    neww:=xr-xl
    newh:=yb-yt
        
    ;Draw the border gui
    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%hostwindoww% H%hostwindowh% NA
}

Form1_Close:
	ExitApp
return
freo is offline   Reply With Quote
Old 11-18-2010, 12:17 PM   #47
marcof3
grinder
 
Join Date: Oct 2006
Posts: 408
Re: AHK Script: Stacked Table Previewer

hmm i suppose that there are no way to implement an all-in filter right?

That or an highlight for the tables where we are all-in
marcof3 is offline   Reply With Quote
Old 11-18-2010, 03:26 PM   #48
TomoDaK
Pooh-Bah
 
TomoDaK's Avatar
 
Join Date: Feb 2008
Location: Minneapolis, MN
Posts: 5,837
Re: AHK Script: Stacked Table Previewer

This is the ****ing nuts

Tyvm for the effort freo
TomoDaK is offline   Reply With Quote
Old 11-18-2010, 04:33 PM   #49
Matixboy
enthusiast
 
Join Date: Nov 2006
Posts: 91
Re: AHK Script: Stacked Table Previewer

Is there anyway to make it so a large X or highlight border pops up on the tables after it is below a set number of active players at the table?

Btw, this is very cool so far. Thanks!
Matixboy is offline   Reply With Quote
Old 11-18-2010, 08:14 PM   #50
freo
enthusiast
 
Join Date: Nov 2008
Posts: 90
Re: AHK Script: Stacked Table Previewer

Quote:
Originally Posted by marcof3 View Post
hmm i suppose that there are no way to implement an all-in filter right?

That or an highlight for the tables where we are all-in
Quote:
Originally Posted by Matixboy View Post
Is there anyway to make it so a large X or highlight border pops up on the tables after it is below a set number of active players at the table?
Both of these requests are a bit more complex, as getting live game info is tricky, but i'll see what I can do.

Quote:
Originally Posted by TomoDaK View Post
This is the ****ing nuts

Tyvm for the effort freo
freo is offline   Reply With Quote

Reply
      

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Forum Jump


All times are GMT -4. The time now is 11:43 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
Copyright © 2008-2017, Two Plus Two Interactive
 
 
Poker Players - Streaming Live Online