AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

real expose clone
Goto page Previous  1, 2, 3 ... 14, 15, 16
 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions
View previous topic :: View next topic  
Author Message
Guest






PostPosted: Tue Apr 22, 2008 3:16 am    Post subject: Reply with quote

holomind wrote:
Expose-Clone with hardware-acceleration will be comming in the future, its not impossible any more.

It was possible for ages, even DirectX/3D was/is possible.
Back to top
holomind



Joined: 11 Mar 2006
Posts: 297
Location: Munich, Germany

PostPosted: Tue Apr 22, 2008 9:42 am    Post subject: Reply with quote

Anonymous wrote:
holomind wrote:
Expose-Clone with hardware-acceleration will be comming in the future, its not impossible any more.

It was possible for ages, even DirectX/3D was/is possible.


Whats your point ? Show me how to do it in Pure AHK with DllCalls. Or do you mean i should write it in C or C++ ? No , thanks.

If you follow my comments in this forum you will recognize, that programming DirectX or opengl is not easy. But thinbasic makes it easier and much more understandable. Code is simply much shorter to open windows or Call GL-Functions. I also chose OpenGL over Directx, because its "Open" like in OpenSource and Platformindependent. Which means i can Port the GL functions to Linux or Osx if i wanted. (but they have such tools already).

Anonymous, if you are so smart, you could show some code of yours to proof your comments.
Back to top
View user's profile Send private message Visit poster's website
n-l-i-d
Guest





PostPosted: Thu Apr 24, 2008 12:36 pm    Post subject: Reply with quote

@holomind: This posting might interest you: [SOLVED] OpenGL DllCalls(?)
Back to top
IN2ITive



Joined: 15 Apr 2008
Posts: 17

PostPosted: Fri May 09, 2008 2:23 am    Post subject: Reply with quote

Hi:

Looking for a little help to expand the exposer clone...any hints would be greatly appreciated. Here is what I want:
1) The expose works great, and the realtime thumbnails really help my automation lab. What i am looking for is a way when the mouse cursor is over a window while in expose mode that a tooltip (or progress) displays the windows title of the window. I would like it only displayed once while in a window(I wouldn't want it each time you moved the mouse within a window). Once you move to a new window then the tooltip/progressbar would display the new window's title. I would love for the tooltip/progress text to be displayed just above the present mouse cursor.

The reason i need this is because with many windows it is hard to tell what window you are actually hovered over.
The tooltip/progress text would show the user the window they are on before we invoke the middle mouse click to zoom into that window.

Thanks.
Back to top
View user's profile Send private message
holomind



Joined: 11 Mar 2006
Posts: 297
Location: Munich, Germany

PostPosted: Fri May 09, 2008 12:15 pm    Post subject: Reply with quote

Hi,

Here is an updated "experimental" version with zoom of hovered windows, and tooltip for the windowtitle. also some experiments with InvalidateRect to repair some artefacts of Printwindow. Now only the hovered window is repainted. the full redraw (backbuffer) is not yet right.

Code:
; v1.20080509 -- expose.ahk - Thumbnails of windows over the working area

OnExit handle_exit
#SingleInstance Force
#NoEnv
SetBatchLines -1
SetWinDelay 0               ; larger values also fail under heavy load, changing windows
Process Priority,,Above Normal
CoordMode Mouse, Relative

Main:
  Gosub, Read_Keymapping
  Gosub, Read_Config
  Gosub, Detect_Screensize
  Gosub, Create_Gui
  Gosub, Create_Buffers
  ; wait for key/mouse
Return

Read_Keymapping:
  Hotkey, #TAB    ,  Window_Choose
  Hotkey, MButton ,  Window_Choose
  Hotkey, IfWinActive , »Expose«
  Hotkey, #TAB    ,  Window_Activate
  Hotkey, IfWinActive , »Expose«
  Hotkey, MButton ,  Window_Activate
  Hotkey, IfWinActive , »Expose«
  Hotkey, LButton ,  Window_Activate
  Hotkey, IfWinActive , »Expose«
  Hotkey, Esc     ,  hide_gui
  Hotkey, +MButton , handle_exit ; panik-key
Return

Read_Config:
  min_w                = 110  ; min width of windows to be shown
  min_h                = 110  ; min height of windows to be shown (hides taskbar etc)
  scale_thumb_space    = 1    ; scale thumbnails to best fit to box?
  live_redraw          = 1    ; 1/0 = Yes/No
  time_gap             = 50   ; ms, time left for others after each thumbnail draw
  thumb_border          = 1   ; 1 for gap between thumbnail  s
  animate_in_delay     = 10
  animate_in_steps       = 5
  animate_out_delay    = 5
  animate_out_steps    = 5
  show_taskbar          = 1
  ;fade_in_steps       = 5
  ;fade_in_delay       = 5
  ;fade_out_steps      = 5
  ;fade_out_delay      = 50
  quality_low          = 3 ; allowed: 1 (terrible) , 3 (accepatable) 4 (good = slow)
  quality_high         = 4 ; allowed: 1 (terrible) , 3 (accepatable) 4 (good = slow)
  BackGroundColor      = 004E98
  count := 0
Return

Window_Hidden() {
   global
   Return w < min_w or h < min_h or title ="»Expose«" or title ="" or title ="SF_Pwnd" or title="SF_Label"
}

Detect_ScreenSize:
  Th=0
  Tw=0
  Ty=0
  Tx=0
  if show_taskbar
   WinGetPos,Tx,Ty,Tw,Th,ahk_class Shell_TrayWnd,,,
  WorkArea_Top    :=      ( Tw > Th  and  Tx = 0  and  Ty = 0) * Th
  WorkArea_Left   :=      ( Tw < Th  and  Tx = 0  and  Ty = 0) * Tw
  WorkArea_Height := A_ScreenHeight - ( Tw > Th  ) * Th
  WorkArea_Width  := A_ScreenWidth  - ( Tw < Th  ) * Tw
Return

Create_Gui:
  Gui +AlwaysOnTop -Caption  +Toolwindow +Owner +LastFound
  ;Gui Color, %BackGroundColor%
  Gui Show, Hide  w%WorkArea_Width% h%WorkArea_Height% x%WorkArea_Left% y%WorkArea_Top%, »Expose«
  ;Gui, Add, Pic, x0 y0 w%WorkArea_Width% h%WorkArea_Height%, c:\test.bmp
  DetectHiddenWindows ON
  WinGet Expose_ID , ID, »Expose«
  WinGet Desktop_ID, ID, Program Manager
  DetectHiddenWindows OFF
Return

Create_Buffers:
  hdc_frontbuffer  := GetDC( Expose_ID )

  hdc_printwindow := CreateCompatibleDC(    hdc_frontbuffer)
  hbm_printwindow := CreateCompatibleBitmap(hdc_frontbuffer,WorkArea_Width,WorkArea_Height)
  hbm_old         := SelectObject(          hdc_printwindow,hbm_printwindow)

  hdc_thumbnails  := CreateCompatibleDC(    hdc_frontbuffer)
  hbm_thumbnails  := CreateCompatibleBitmap(hdc_frontbuffer,WorkArea_Width,WorkArea_Height)
  hbm_old         := SelectObject(          hdc_thumbnails,hbm_thumbnails)

  hdc_backbuffer  := CreateCompatibleDC(    hdc_frontbuffer)
  hbm_backbuffer  := CreateCompatibleBitmap(hdc_frontbuffer,WorkArea_Width,WorkArea_Height)
  hbm_old         := SelectObject(          hdc_backbuffer,hbm_backbuffer)

  hdc_desktop     := CreateCompatibleDC(    hdc_frontbuffer)
  hbm_desktop     := CreateCompatibleBitmap(hdc_frontbuffer,WorkArea_Width,WorkArea_Height)
  hbm_old         := SelectObject(          hdc_desktop,hbm_desktop)

  Gui Show
  PaintDesktop( hdc_frontbuffer ) ; 0=window, 1=Child(no toolbars)
  BitBlt(hdc_desktop     , 0, 0, WorkArea_Width, WorkArea_Height
      ,  hdc_frontbuffer , 0, 0 ,0xCC0020) ; SRCCOPY
  BitBlt(hdc_thumbnails  , 0, 0, WorkArea_Width, WorkArea_Height
      ,  hdc_frontbuffer , 0, 0 ,0xCC0020) ; SRCCOPY
  Gui Hide

Return

Window_Choose:
   WinGet ActiveID, ID, A
   SetTimer Window_Choose_Thread, 0       ; new thread to make thumbnail draws interruptible
Return
Window_Choose_Thread:
   Stop_Drawing  =
   yield         := time_gap        ; yield time to other tasks after each thumbnail drawn
   SetTimer Window_Choose_Thread, OFF     ; run once
   tooltip,
   GoSub Window_Info           ; list window IDs, sizes, etc.
   Gosub Animate_In
   GoSub Draw_Thumbnails
Return

Window_Activate:
   Stop_Drawing = 1
   MouseGetPos X, Y
   pos := 1 + X*cols//WorkArea_Width + Y*rows//WorkArea_Height * cols 
   task_id := task_ids_%pos%
   If (pos <= num_win and X >= 0 and X <= WorkArea_Width and Y >= 0 and Y <= WorkArea_Height)
   {
      Gosub Animate_Out
         WinActivate(task_id)                 ; activate selected window
      Gosub fade_out
   }
Gui_Hide()
Return

WinActivate(ID) {
   WinGet ,ActiveID2, ID, A
   if ActiveID2 <> ID
       WinActivate ahk_id %ID%
}

Window_Info:
   WinGet ids, list,,,Program Manager      ; all active windows-tasks (processes)
   task_info =
   num_win = 0
   Loop %ids% {
      task_id := ids%A_Index%              ; id of this window
      WinGetClass class, ahk_id %task_id%
      WinGetTitle title, ahk_id %task_id%
      WinGetPos,,, w, h, ahk_id %task_id%
      If Window_Hidden()                 ; small windows not shown (e.g. taskbar)
         Continue
      num_win++
      task_info := task_info class "|" ids%A_Index% "|" w "|" h ","
   }
   StringTrimRight task_info, task_info, 1
   Sort task_info, D,                      ; keep positions of thumbnails
   cols := ceil(sqrt(num_win))
   rows := ceil(sqrt(num_win))
   If (cols*(rows-1) >= num_win)           ; minimize table size
       rows--
   thumb_w := WorkArea_Width  // cols
   thumb_h := WorkArea_Height // rows
   ratio_of_screen := WorkArea_Width / WorkArea_Height * rows / cols
   Loop Parse, task_info, `,               ; task_info has been set up in get_wins()
   {
      StringSplit z, A_LoopField, |        ; separate ID, w, h
      task_ids_%A_Index% := z2             ; needed for activation
      if ( z2 = ActiveID )
      pos = %A_Index%
     w%A_Index% := z3                     ; w
      h%A_Index% := z4                     ; h
      ratio_of_win := z3 / z4              ; w/h
      If ( scale_thumb_space  )  {
         If (ratio_of_win < ratio_of_screen) { ; tall window
            thumb_h%A_Index% := thumb_h - thumb_border
            thumb_w%A_Index% := Floor(thumb_w * ratio_of_win / ratio_of_screen) - thumb_border
         } Else {                              ; wide window
            thumb_w%A_Index% := thumb_w - thumb_border
            thumb_h%A_Index% := Floor(thumb_h * ratio_of_screen / ratio_of_win) - thumb_border
         }
      } Else {
         thumb_w%A_Index% := z3//cols - 2*thumb_border
         thumb_h%A_Index% := z4//cols - 2*thumb_border  ; cols >= rows, keep aspect ratio of window
      }
     if ( thumb_w%A_Index% > w%A_Index% or thumb_h%A_Index% > h%A_Index% )
     {
        thumb_w%A_Index% := w%A_Index%
         thumb_h%A_Index% := h%A_Index%
      }
   }
Return

Draw_Thumbnails:
    If Stop_Drawing
           Return

   WinGet ids_count, list,,,Program Manager      ; all active windows-tasks (processes)
     SetStretchBltMode(hdc_thumbnails,quality_high) ; 3: Lower quality at 1st draw
       SetStretchBltMode(hdc_frontbuffer,quality_high) ; 3: Lower quality at 1st draw
   
   if ( old_ids_count <> ids_count )
      gosub Window_Info   ; detect if windows were added in expose mode
   
   ; layout changed full refresh (start with empty desktop)
   if ( cols <> old_cols or rows <> old_rows)
       BitBlt( hdc_frontbuffer, 0, 0, WorkArea_Width, WorkArea_Height
           , hdc_desktop, 0, 0 , 0xCC0020) ; SRCCOPY
   
   ; clear "now empty" places , only needed when less, more are filled automatically
   gaps := old_num_win - num_win
    if ( gaps )
   {
     loop %gaps%
     {
           a_index2 := num_win + gaps
      pos_x := thumb_w * Mod(A_Index2-1,cols)
      pos_y := thumb_h * ((A_Index2-1)//cols)
 
       BitBlt( hdc_thumbnails, pos_x, pos_y, thumb_w, thumb_h
                 , hdc_desktop,    pos_x, pos_y ,0xCC0020) ;
   
           BitBlt( hdc_frontbuffer, pos_x, pos_y, thumb_w, thumb_h
                 , hdc_thumbnails,  pos_x, pos_y ,0xCC0020) ;
      }   
   }

    old_ids_count := ids_count 
    old_rows := rows
    old_cols := cols
   old_num_win := num_win

    Loop %num_win%  {                       ; task_ids, dims have been set up in win_list
      Sleep %yield%                        ; CPU cycles to other tasks @ frequent redraw
      If Stop_Drawing
         Break
   


      pos_x := thumb_w * Mod(A_Index-1,cols)
      pos_y := thumb_h * ((A_Index-1)//cols) 
     
      PrintWindow( task_ids_%A_Index%, hdc_printwindow, 0) ; 0=window, 1=Child(no toolbars)
      DllCall( "InvalidateRect", Uint, task_ids_%A_Index% , Uint, 0 , Uint, 1  ) ;

      BitBlt( hdc_thumbnails, pos_x , pos_y, thumb_w, thumb_h
            , hdc_desktop   , pos_x , pos_y ,0xCC0020) ; Clear slot . (could load Image here ?)
   
      ; prevent flicker with backbuffer , store it in hdc_thumbnails for later reuse!
      StretchBlt( hdc_thumbnails , pos_x + ( thumb_w - thumb_w%A_Index% ) // 2
                            , pos_y + ( thumb_h - thumb_h%A_Index% ) // 2      
                            , thumb_w%A_Index%
                          , thumb_h%A_Index%
             ,hdc_printwindow, 0, 0, w%A_Index% , h%A_Index% ,0xCC0020) ; SRCCOPY
 
        BitBlt( hdc_frontbuffer, pos_x , pos_y , thumb_w , thumb_h
             ,hdc_thumbnails,  pos_x , pos_y ,0xCC0020) ; Clear slot . (could load Image here ?)
   }

      ; detect current mouse = hover-position
   MouseGetPos Xh, Yh
   old_pos2 := 1 + Xh*cols//WorkArea_Width + Yh*rows//WorkArea_Height * cols 

   If live_redraw           ; redraw thumbnails until Break is set
         Gosub draw_active
Return

draw_active:

   ; detect current mouse = hover-position
   MouseGetPos Xh, Yh
   pos2 := 1 + Xh*cols//WorkArea_Width + Yh*rows//WorkArea_Height * cols 

   scale = 1.5
      pos_x := thumb_w * Mod(pos2-1,cols)
      pos_y := thumb_h * ((pos2-1)//cols) 
     
      PrintWindow( task_ids_%pos2%, hdc_printwindow, 0) ; 0=window, 1=Child(no toolbars)
      DllCall( "InvalidateRect", Uint, task_ids_%pos2% , Uint, 0 , Uint, 1  ) ;

    ; prevent flicker with backbuffer , store it in hdc_thumbnails for later reuse!
      StretchBlt( hdc_frontbuffer , pos_x + ( thumb_w - thumb_w%pos2% *scale ) // 2
                            , pos_y + ( thumb_h - thumb_h%pos2% *scale ) // 2      
                            , thumb_w%pos2% * scale
                          , thumb_h%pos2% * scale
             ,hdc_printwindow, 0, 0, w%pos2% , h%pos2% ,0xCC0020) ; SRCCOPY

winid := task_ids_%pos2%
WinGetTitle title, ahk_id %winid%

tooltip, %title% ; + %old_pos2% + %pos2%

    if (  old_pos2 <> pos2 )
    {
      old_pos2 := pos2
      gosub draw_thumbnails
    }
     old_pos2 := pos2

    if live_redraw
      Gosub draw_active
return

Animate_In:
    if !animate_in_steps
        return

    SetStretchBltMode(hdc_backbuffer, quality_low) ; 3: Lower quality at 1st draw
   
   A_index2 := pos
    pos_x := thumb_w * Mod(A_Index2-1,cols)
    pos_y := thumb_h * ((A_Index2-1)//cols)
 
    PrintWindow(task_ids_%A_Index2%,hdc_printwindow,0)
    DllCall( "InvalidateRect", Uint, task_ids_%A_Index2% , Uint, 0 , Uint, 1  ) ;
 
    task_id := task_ids_%A_Index2%
   WinGetPos, diff_x, diff_y, diff_w, diff_h , ahk_id %task_id%

    diff_x := diff_x - ( pos_x + (thumb_w - thumb_w%A_Index2% ) // 2 ) - WorkArea_Left
   diff_y := diff_y - ( pos_y + (thumb_h - thumb_h%A_Index2% ) // 2 ) - WorkArea_Top
     diff_w := diff_w - ( thumb_w%A_Index2% )
   diff_h := diff_h - ( thumb_h%A_Index2% )
    
   Loop %animate_in_steps%
   {
       sleep %animate_in_delay%
          zoom := 1 - ( A_Index / animate_in_steps )
      
        BitBlt( hdc_backbuffer, 0, 0, WorkArea_Width, WorkArea_Height
           , hdc_thumbnails, 0, 0 , 0xCC0020) ; SRCCOPY
   
      if ( zoom = 0 )
         SetStretchBltMode(hdc_backbuffer, quality_high) ; 3: Lower quality at 1st draw
      StretchBlt( hdc_backbuffer , pos_x + (thumb_w - thumb_w%A_Index2% ) // 2 + diff_x * zoom      
                           , pos_y + (thumb_h - thumb_h%A_Index2% ) // 2 + diff_y * zoom      
                           , thumb_w%A_Index2% + diff_w * zoom   
                           , thumb_h%A_Index2% + diff_h * zoom
                   , hdc_printwindow, 0, 0, w%A_Index2%, h%A_Index2% ,0xCC0020) ; SRCCOPY
      if ( zoom = 0 )
         SetStretchBltMode(hdc_backbuffer, quality_low) ; 3: Lower quality at 1st draw
      Gui_Show()
      BitBlt(hdc_frontbuffer, 0, 0 ,WorkArea_Width ,WorkArea_Height
              ,hdc_backbuffer , 0, 0 ,0xCC0020) ; SRCCOPY
   }
   old_cols := cols ; prevent full refresh on next draw
    old_rows := rows
Return

; should be reverse of animate in ? combine them ...
Animate_Out:
   if !animate_out_steps
         return

   A_index2 := pos
    pos_x := thumb_w * Mod(A_Index2-1,cols)
    pos_y := thumb_h * ((A_Index2-1)//cols)
 
    If (!(pos <= num_win and X >= 0 and X <= WorkArea_Width and Y >= 0 and Y <= WorkArea_Height))
       return

   ;SetStretchBltMode(hdc_frontbuffer,quality_low) ;
    PrintWindow( task_ids_%A_Index2%, hdc_printwindow ,0) ; get selected window
      DllCall( "InvalidateRect", Uint, task_ids_%A_Index2% , Uint, 0 , Uint, 1  ) ;
   
   ; clear
     BitBlt( hdc_backbuffer, pos_x, pos_y, thumb_w, thumb_h
          , hdc_desktop   , pos_x, pos_y, 0xCC0020) ; clear with desktopimage

   task_id := task_ids_%A_Index2%
   WinGetPos, diff_x, diff_y, diff_w, diff_h , ahk_id %task_id%

    diff_x := diff_x - ( pos_x + (thumb_w - thumb_w%A_Index2% ) // 2 ) - WorkArea_Left
   diff_y := diff_y - ( pos_y + (thumb_h - thumb_h%A_Index2% ) // 2 ) - WorkArea_Top
   diff_w := diff_w - ( thumb_w%A_Index2% )
   diff_h := diff_h - ( thumb_h%A_Index2% )

   SetStretchBltMode(hdc_backbuffer,quality_low) ; 3: Lower quality at 1st draw
    Loop %animate_out_steps%
   {
       sleep %animate_out_delay%
          zoom := ( A_Index / animate_out_steps )
        
      ; you can comment this line to get bit speed, acceptable
      BitBlt( hdc_backbuffer, 0, 0, WorkArea_Width, WorkArea_Height
              , hdc_thumbnails, 0, 0, 0xCC0020) ; SRCCOPY
      
      StretchBlt( hdc_backbuffer, pos_x + (thumb_w - thumb_w%A_Index2% ) // 2 + diff_x * zoom
                           , pos_y + (thumb_h - thumb_h%A_Index2% ) // 2 + diff_y * zoom
                           , thumb_w%A_Index2% + diff_w * zoom
                           , thumb_h%A_Index2% + diff_h * zoom
                   ,hdc_printwindow, 0, 0, w%A_Index2%, h%A_Index2% ,0xCC0020) ; SRCCOPY
   
       BitBlt(hdc_frontbuffer, 0, 0, WorkArea_Width, WorkArea_Height
             ,  hdc_backbuffer, 0, 0 ,0xCC0020) ; SRCCOPY
     }
   
Return

fade_in:
   ; not used ?
Return

fade_out:
   ; fade last animate_out with real desktop
Return

Gui_Show() {
   global
   if Shown
      return
   Gui, Show
   Shown = 1
}

Gui_Hide() {
   global
   if !Shown
     return
   Gui, Hide
   Shown =
}

hide_gui:
   Stop_Drawing = 1
   Gui_Hide()
   WinActivate(ActiveID)                   ; activate last active window
Return

handle_exit:
   Gui Destroy
   ReleaseDC(hw_frame,hdc_frontbuffer) ; free lock?
   DeleteObject( hbm_printwindow)
   DeleteDC(     hdc_printwindow)
   DeleteObject( hbm_window)
   DeleteDC(     hdc_window)
   DeleteObject( hbm_backbuffer)
   DeleteDC(     hdc_backbuffer)
 ;  WinActivate ahk_id %ActiveID%           ; activate last active window
ExitApp

; --------------------------------------------------------------------------------------------------
; Library: no need to modify below

; Libary (could be put in extra file )
; #include <GDI.ahk>
; for documentation of commands see: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/gdi/wingdistart_9ezp.asp

; -- highlevel not direct dllcall mapping , simplifiers
CreateDCBuffer(ByRef hdc_from, ByRef hdc_to, ByRef hbm_to, w ,h ) {
   ; does not work, something wrong with ByRef and global
   hdc_to  := CreateCompatibleDC(hdc_from) ; buffer
   hbm_to  := CreateCompatibleBitmap(hdc_from,w,h)
   old     := SelectObject(hdc_to,hbm_to)
}

; -- mfc wrapper
GetDC( hw ) {
   return DLLCall("GetDC", UInt, hw )
}

CreateDC( driver,device,output,mode  ) {
   return DLLCall("GetDC", UInt, driver, UInt, device, UInt, output, UInt, mode )
}

SetStretchBltMode( hdc , value ) {
     return DllCall("gdi32.dll\SetStretchBltMode", UInt,hdc, "int",value)
}

CreateCompatibleDC( hdc ) {
   return DllCall("gdi32.dll\CreateCompatibleDC", UInt,hdc)
}

CreateCompatibleBitmap( hdc , w, h ) {
     return DllCall("gdi32.dll\CreateCompatibleBitmap", UInt,hdc, Int,w, Int,h)
}

SelectObject( hdc , hbm ) {
   return DllCall("gdi32.dll\SelectObject", UInt,hdc, UInt,hbm)
}

DeleteObject( hbm ) {
   return DllCall("gdi32.dll\DeleteObject", UInt,hbm)   
}

DeleteDC( hdc ) {
   return DllCall("gdi32.dll\DeleteDC", UInt,hdc )
}

ReleaseDC( hwnd, hdc ) {
   return DllCall("gdi32.dll\ReleaseDC", UInt,hwnd,UInt,hdc )
}

PrintWindow( window_id , hdc , mode ) {
   return DllCall("PrintWindow", UInt, window_id , UInt,hdc, UInt, mode)
}

StretchBlt( hdc_dest , x1, y1, w1, h1, hdc_source , x2, y2, w2, h2 , mode) {
   return DllCall("gdi32.dll\StretchBlt"
          , UInt,hdc_dest  , Int,x1, Int,y1, Int,w1, Int,h1
             , UInt,hdc_source, Int,x2, Int,y2, Int,w2, Int,h2
          , UInt,mode)
}

BitBlt( hdc_dest, x1, y1, w1, h1 , hdc_source, x2, y2 , mode ) {
   return DllCall("gdi32.dll\BitBlt"
          , UInt,hdc_dest   , Int, x1, Int, y1, Int, w1, Int, h1
             , UInt,hdc_source    , Int, x2, Int, y2
          , UInt, mode)
}

PaintDesktop(  hdc ) {
   return DllCall("PaintDesktop", UInt, hdc )
}

; constants
; see: http://www.adaptiveintelligence.net/Developers/Reference/Win32API/GDIConstants.aspx
; #SRCCOPY = 0xCC0020
[/code]
Back to top
View user's profile Send private message Visit poster's website
IN2ITive



Joined: 15 Apr 2008
Posts: 17

PostPosted: Fri May 09, 2008 3:35 pm    Post subject: Reply with quote

Hi Holomind:

You are quick! Thanks for the update there. Again, as I have stated this script is used everyday at my work, just because it makes the automation developers lives easier.

I copied your new version and without any modifications I noticed the following:
The tooltip stays on even after escaping expose mode by using the ESC character. A few seconds after exiting expose mode the script crashes, sometimes displaying the message about the crash, sometimes just shutting down with no indication.
I saw a few times that if I had 4 windows to draw (just an example) that it would start to draw, would make it to the second thumbnail, then the screen would go blank (not black but a white screen), then it would try again, get to the second one again, and do the same thing. Almost like it was stuck in a loop. After a couple of iterations of this the script would crash.
Back to top
View user's profile Send private message
holomind



Joined: 11 Mar 2006
Posts: 297
Location: Munich, Germany

PostPosted: Fri May 09, 2008 9:24 pm    Post subject: Reply with quote

hi, i also noticed the crashes, perhaps this comes from invalidate-rect or some stackoverflow due to recursive gosubs ??

here is now a much improved version which shows tooltip of the current window-title on hover. also only the hover-window is updated in live-preview.

and another big feature as requested some while ago is the possibility to zoom the hovered window.

usage: after you start the expose gui with middleclick, you can enable and disable zoom-preview with rightclick (on/off) , with mousewheel you can change the zoomlevel (0-200%) . the state is remembered until you next middleclick.

modify time_gap if the script is too slow, or if you want more direct preview-rereshes. (50 to 200 are good values)

enjoy, holomind

Code:
;v1.20080509 -- expose.ahk - Thumbnails of windows over the working area

OnExit handle_exit
#SingleInstance Force
#NoEnv
SetBatchLines -1
SetWinDelay 0               ; larger values also fail under heavy load, changing windows
Process Priority,,Above Normal
CoordMode Mouse, Relative

Main:
  Gosub, Read_Keymapping
  Gosub, Read_Config
  Gosub, Detect_Screensize
  Gosub, Create_Gui
  Gosub, Create_Buffers
  ; wait for key/mouse
Return

Read_Keymapping:
  Hotkey, #TAB    ,  Window_Choose
  Hotkey, MButton ,  Window_Choose

  Hotkey, IfWinActive , »Expose«
  Hotkey, #TAB    ,  Window_Activate
  Hotkey, MButton ,  Window_Activate
  Hotkey, LButton ,  Window_Activate
  HotKey, RButton ,  Window_Preview
  Hotkey, Esc     ,  hide_gui
  Hotkey, WheelUp ,  Handle_Zoom
  Hotkey, WheelDown, Handle_Zoom
  Hotkey, +MButton , handle_exit ; panik-key
Return

Read_Config:
  min_w                = 110  ; min width of windows to be shown
  min_h                = 110  ; min height of windows to be shown (hides taskbar etc)
  scale_thumb_space    = 1    ; scale thumbnails to best fit to box?
  live_redraw          = 1    ; 1/0 = Yes/No
  time_gap             = 100   ; ms, time left for others after each thumbnail draw
  thumb_border          = 1   ; 1 for gap between thumbnail  s
  animate_in_delay     = 5
  animate_in_steps       = 5
  animate_out_delay    = 5
  animate_out_steps    = 5
  show_taskbar          = 1
  ;fade_in_steps       = 5
  ;fade_in_delay       = 5
  ;fade_out_steps      = 5
  ;fade_out_delay      = 50
  quality_low          = 3 ; allowed: 1 (terrible) , 3 (accepatable) 4 (good = slow)
  quality_high         = 4 ; allowed: 1 (terrible) , 3 (accepatable) 4 (good = slow)
  BackGroundColor      = 004E98
  count := 0
  zoom_preview = 0.8
  do_zoom := 0  ; // off at first
Return

Window_Hidden() {
   global
   Return w < min_w or h < min_h or title ="»Expose«" or title =""
}

Handle_Zoom:
   If (zoom_preview < 4 and ( A_ThisHotKey = "WheelUp" or A_ThisHotKey = "^+Up" ))
      zoom_preview += 0.1         ; sqrt(sqrt(2))
   If (zoom_preview >  -1 and ( A_ThisHotKey = "WheelDown" or A_ThisHotKey = "^+Down" ))
      zoom_preview -= 0.1
   TrayTip,,% "Zoom = " Round(100*(1+zoom_preview)) "%"
Return

In(x,a,b) {                      ; closest number to x in [a,b]
   IfLess x,%a%, Return a
   IfLess b,%x%, Return b
   Return x
}


Detect_ScreenSize:
  Th=0
  Tw=0
  Ty=0
  Tx=0
  if show_taskbar
   WinGetPos,Tx,Ty,Tw,Th,ahk_class Shell_TrayWnd,,,
  WorkArea_Top    :=      ( Tw > Th  and  Tx = 0  and  Ty = 0) * Th
  WorkArea_Left   :=      ( Tw < Th  and  Tx = 0  and  Ty = 0) * Tw
  WorkArea_Height := A_ScreenHeight - ( Tw > Th  ) * Th
  WorkArea_Width  := A_ScreenWidth  - ( Tw < Th  ) * Tw
Return

Create_Gui:
  Gui +AlwaysOnTop -Caption  +Toolwindow +Owner +LastFound
  ;Gui Color, %BackGroundColor%
  Gui Show, Hide  w%WorkArea_Width% h%WorkArea_Height% x%WorkArea_Left% y%WorkArea_Top%, »Expose«
  ;Gui, Add, Pic, x0 y0 w%WorkArea_Width% h%WorkArea_Height%, c:\test.bmp
  DetectHiddenWindows ON
  WinGet Expose_ID , ID, »Expose«
  WinGet Desktop_ID, ID, Program Manager
  DetectHiddenWindows OFF
Return

Create_Buffers:
  hdc_frontbuffer  := GetDC( Expose_ID )

  hdc_printwindow := CreateCompatibleDC(    hdc_frontbuffer)
  hbm_printwindow := CreateCompatibleBitmap(hdc_frontbuffer,WorkArea_Width,WorkArea_Height)
  hbm_old         := SelectObject(          hdc_printwindow,hbm_printwindow)

  hdc_thumbnails  := CreateCompatibleDC(    hdc_frontbuffer)
  hbm_thumbnails  := CreateCompatibleBitmap(hdc_frontbuffer,WorkArea_Width,WorkArea_Height)
  hbm_old         := SelectObject(          hdc_thumbnails,hbm_thumbnails)

  hdc_backbuffer  := CreateCompatibleDC(    hdc_frontbuffer)
  hbm_backbuffer  := CreateCompatibleBitmap(hdc_frontbuffer,WorkArea_Width,WorkArea_Height)
  hbm_old         := SelectObject(          hdc_backbuffer,hbm_backbuffer)

  hdc_desktop     := CreateCompatibleDC(    hdc_frontbuffer)
  hbm_desktop     := CreateCompatibleBitmap(hdc_frontbuffer,WorkArea_Width,WorkArea_Height)
  hbm_old         := SelectObject(          hdc_desktop,hbm_desktop)

  Gui Show
  PaintDesktop( hdc_frontbuffer ) ; 0=window, 1=Child(no toolbars)
  BitBlt(hdc_desktop     , 0, 0, WorkArea_Width, WorkArea_Height
      ,  hdc_frontbuffer , 0, 0 ,0xCC0020) ; SRCCOPY
  BitBlt(hdc_thumbnails  , 0, 0, WorkArea_Width, WorkArea_Height
      ,  hdc_frontbuffer , 0, 0 ,0xCC0020) ; SRCCOPY
  Gui Hide

Return

Window_Choose:
   WinGet ActiveID, ID, A
   SetTimer Window_Choose_Thread, 0       ; new thread to make thumbnail draws interruptible
Return
Window_Choose_Thread:
   Stop_Drawing  =
   yield         := time_gap        ; yield time to other tasks after each thumbnail drawn
   SetTimer Window_Choose_Thread, OFF     ; run once
   GoSub Window_Info           ; list window IDs, sizes, etc.
   Gosub Animate_In
   GoSub Draw_Thumbnails
Return

Window_Activate:
   Stop_Drawing = 1
   MouseGetPos X, Y
   pos := 1 + X*cols//WorkArea_Width + Y*rows//WorkArea_Height * cols 
   task_id := task_ids_%pos%

 If (pos <= num_win and X >= 0 and X <= WorkArea_Width and Y >= 0 and Y <= WorkArea_Height)
   {
      Gosub Animate_Out
         WinActivate(task_id)                 ; activate selected window
      Gosub fade_out
   }
Gui_Hide()

Return

WinActivate(ID) {
   WinGet ,ActiveID2, ID, A
   if ActiveID2 <> ID
       WinActivate ahk_id %ID%
}

Window_Info:
   WinGet ids, list,,,Program Manager      ; all active windows-tasks (processes)
   task_info =
   num_win = 0
   Loop %ids% {
      task_id := ids%A_Index%              ; id of this window
      WinGetClass class, ahk_id %task_id%
      WinGetTitle title, ahk_id %task_id%
      WinGetPos,,, w, h, ahk_id %task_id%
      If Window_Hidden()                 ; small windows not shown (e.g. taskbar)
         Continue
      num_win++
      task_info := task_info class "|" ids%A_Index% "|" w "|" h ","
   }
   StringTrimRight task_info, task_info, 1
   Sort task_info, D,                      ; keep positions of thumbnails
   cols := ceil(sqrt(num_win))
   rows := ceil(sqrt(num_win))
   If (cols*(rows-1) >= num_win)           ; minimize table size
       rows--
   thumb_w := WorkArea_Width  // cols
   thumb_h := WorkArea_Height // rows
   ratio_of_screen := WorkArea_Width / WorkArea_Height * rows / cols
   Loop Parse, task_info, `,               ; task_info has been set up in get_wins()
   {
      StringSplit z, A_LoopField, |        ; separate ID, w, h
      task_ids_%A_Index% := z2             ; needed for activation
      if ( z2 = ActiveID )
      pos = %A_Index%
     w%A_Index% := z3                     ; w
      h%A_Index% := z4                     ; h
      ratio_of_win := z3 / z4              ; w/h
      If ( scale_thumb_space  )  {
         If (ratio_of_win < ratio_of_screen) { ; tall window
            thumb_h%A_Index% := thumb_h - thumb_border
            thumb_w%A_Index% := Floor(thumb_w * ratio_of_win / ratio_of_screen) - thumb_border
         } Else {                              ; wide window
            thumb_w%A_Index% := thumb_w - thumb_border
            thumb_h%A_Index% := Floor(thumb_h * ratio_of_screen / ratio_of_win) - thumb_border
         }
      } Else {
         thumb_w%A_Index% := z3//cols - 2*thumb_border
         thumb_h%A_Index% := z4//cols - 2*thumb_border  ; cols >= rows, keep aspect ratio of window
      }
     if ( thumb_w%A_Index% > w%A_Index% or thumb_h%A_Index% > h%A_Index% )
     {
        thumb_w%A_Index% := w%A_Index%
         thumb_h%A_Index% := h%A_Index%
      }
   }
Return

Draw_Thumbnails:
    If ( Stop_Drawing )
   {
      tooltip,
           Return
   }
   WinGet ids_count, list,,,Program Manager      ; all active windows-tasks (processes)
     SetStretchBltMode(hdc_thumbnails,quality_high) ; 3: Lower quality at 1st draw
   
   if ( old_ids_count <> ids_count )
      gosub Window_Info   ; detect if windows were added in expose mode
   
   ; layout changed full refresh (start with empty desktop)
   if ( cols <> old_cols or rows <> old_rows)
       BitBlt( hdc_frontbuffer, 0, 0, WorkArea_Width, WorkArea_Height
           , hdc_desktop, 0, 0 , 0xCC0020) ; SRCCOPY
       BitBlt( hdc_thumbnails, 0, 0, WorkArea_Width, WorkArea_Height
           , hdc_desktop, 0, 0 , 0xCC0020) ; SRCCOPY
   
   ; clear "now empty" places , only needed when less, more are filled automatically
   gaps := old_num_win - num_win
    if ( gaps )
   {
     loop %gaps%
     {
        a_index2 := num_win + gaps
       pos_x := thumb_w * Mod(A_Index2-1,cols)
       pos_y := thumb_h * ((A_Index2-1)//cols)
 
       BitBlt( hdc_thumbnails, pos_x, pos_y, thumb_w, thumb_h
              , hdc_desktop,    pos_x, pos_y ,0xCC0020) ;
   
        BitBlt( hdc_frontbuffer, pos_x, pos_y, thumb_w, thumb_h
              , hdc_thumbnails,  pos_x, pos_y ,0xCC0020) ;
      }   
   }

    old_ids_count := ids_count 
    old_rows := rows
    old_cols := cols
   old_num_win := num_win

    Loop %num_win%  {                       ; task_ids, dims have been set up in win_list
     ;  Sleep %yield%                        ; CPU cycles to other tasks @ frequent redraw
      If Stop_Drawing
         Break
   
      pos_x := thumb_w * Mod(A_Index-1,cols)
      pos_y := thumb_h * ((A_Index-1)//cols)
     
      PrintWindow( task_ids_%A_Index%, hdc_printwindow, 0) ; 0=window, 1=Child(no toolbars)
   
      BitBlt( hdc_thumbnails, pos_x , pos_y, thumb_w, thumb_h
            , hdc_desktop   , pos_x , pos_y ,0xCC0020) ; Clear slot . (could load Image here ?)
   
      ; prevent flicker with backbuffer , store it in hdc_thumbnails for later reuse!
      StretchBlt( hdc_thumbnails , pos_x + ( thumb_w - thumb_w%A_Index% ) // 2
                            , pos_y + ( thumb_h - thumb_h%A_Index% ) // 2      
                            , thumb_w%A_Index%
                          , thumb_h%A_Index%
             ,hdc_printwindow, 0, 0, w%A_Index%, h%A_Index% ,0xCC0020) ; SRCCOPY
 
        BitBlt( hdc_frontbuffer, pos_x , pos_y , thumb_w, thumb_h
             ,hdc_thumbnails,  pos_x , pos_y ,0xCC0020) ; Clear slot . (could load Image here ?)
   }
 
   MouseGetPos X, Y
      pos := 1 + X*cols//WorkArea_Width + Y*rows//WorkArea_Height * cols 
 
   winid := task_ids_%pos%
   WinGetTitle title, ahk_id %winid%

   tooltip, %title% ; + %old_pos2% + %pos%

     
    If live_redraw           ; redraw thumbnails until Break is set
         Gosub draw_active
Return

Window_Preview:

   do_zoom := 1 - do_zoom ; toggle state
BitBlt(hdc_frontbuffer, 0, 0, WorkArea_Width, WorkArea_Height
             ,  hdc_thumbnails, 0, 0 ,0xCC0020) ; SRCCOPY
    ;  gosub draw_active
return

draw_active:

  zoom :=  zoom_preview

  sleep %yield%                        ; CPU cycles to other tasks @ frequent redraw
       If ( Stop_Drawing )
   {
      tooltip,
           Return
   }
      MouseGetPos X, Y
      pos := 1 + X*cols//WorkArea_Width + Y*rows//WorkArea_Height * cols 
 
   winid := task_ids_%pos%

      pos_x := thumb_w * Mod(pos -1,cols)
      pos_y := thumb_h * ((pos -1)//cols)
 
       A_Index2 := pos
   task_id := task_ids_%A_Index2%
   
   diff_x := WorkArea_Left
   diff_y := WorkArea_Top
   diff_w := WorkArea_Width
        diff_h := WorkArea_Height


   WinGetPos, diff_x, diff_y, diff_w, diff_h , ahk_id %task_id%
   diff_x := X - diff_w // 2 ; -  ( WorkArea_Width - WorkArea_Left ) // 2

   diff_y := Y - diff_h // 2 ; - ( WorkArea_Height - WorkArea_Top ) // 2
   

      ;  if ( pos_x + diff_x + (diff_w//2) *zoom > Work_AreaWidth )
      ;    diff_x := Work_AreaWidth - ( (diff_w//2) *zoom)
       
   if diff_x < 1
           diff_x :=1

   if diff_y < 1
          diff_y := 1

;   if ( diff_y + thumb_h * zoom > Work_AreaHeight )
;          diff_y := Work_AreaHeight - thumb_h * zoom

       diff_x := diff_x - ( pos_x + (thumb_w - thumb_w%A_Index2% ) // 2 ) - WorkArea_Left
   diff_y := diff_y - ( pos_y + (thumb_h - thumb_h%A_Index2% ) // 2 ) - WorkArea_Top
   diff_w := diff_w - ( thumb_w%A_Index2% )
   diff_h := diff_h - ( thumb_h%A_Index2% )

   
      ; you can comment this line to get bit speed, acceptable
      BitBlt( hdc_backbuffer, 0, 0, WorkArea_Width, WorkArea_Height
              , hdc_thumbnails, 0, 0, 0xCC0020) ; SRCCOPY
 PrintWindow( task_ids_%A_Index2%, hdc_printwindow, 0) ; 0=window, 1=Child(no toolbars)
   SetStretchBltMode(hdc_backbuffer,quality_high) ; 3: Lower quality at 1st draw
   SetStretchBltMode(hdc_frontbuffer,quality_high) ; 3: Lower quality at 1st draw
   
     if ( do_zoom = 1 ) {   
   
      StretchBlt( hdc_backbuffer, pos_x + (thumb_w - thumb_w%A_Index2% ) // 2 + diff_x * zoom
                           , pos_y + (thumb_h - thumb_h%A_Index2% ) // 2 + diff_y * zoom
                           , thumb_w%A_Index2% + diff_w * zoom
                           , thumb_h%A_Index2% + diff_h * zoom
                   ,hdc_printwindow, 0, 0, w%A_Index2%, h%A_Index2% ,0xCC0020) ; SRCCOPY
     BitBlt(hdc_frontbuffer, 0, 0, WorkArea_Width, WorkArea_Height
             ,  hdc_backbuffer, 0, 0 ,0xCC0020) ; SRCCOPY
    
   }
else  {
     StretchBlt( hdc_thumbnails , pos_x + ( thumb_w - thumb_w%A_Index2% ) // 2
                            , pos_y + ( thumb_h - thumb_h%A_Index2% ) // 2      
                            , thumb_w%A_Index2%
                          , thumb_h%A_Index2%
             ,hdc_printwindow, 0, 0, w%A_Index2%, h%A_Index2% ,0xCC0020) ; SRCCOPY
     StretchBlt( hdc_frontbuffer , pos_x + ( thumb_w - thumb_w%A_Index2% ) // 2
                            , pos_y + ( thumb_h - thumb_h%A_Index2% ) // 2      
                            , thumb_w%A_Index2%
                          , thumb_h%A_Index2%
             ,hdc_thumbnails,  pos_x + ( thumb_w - thumb_w%A_Index2% ) // 2
                            , pos_y + ( thumb_h - thumb_h%A_Index2% ) // 2      
                            , thumb_w%A_Index2%
                          , thumb_h%A_Index2%  ,0xCC0020) ; SRCCOPY
     }

   
   MouseGetPos X, Y

      pos := 1 + X*cols//WorkArea_Width + Y*rows//WorkArea_Height * cols 
 
   winid := task_ids_%pos%
   WinGetTitle title, ahk_id %winid%

   tooltip, %title% ; + %old_pos2% + %pos%

   
     If live_redraw           ; redraw thumbnails until Break is set
         Gosub draw_active

return

Animate_In:
    if !animate_in_steps
        return

    SetStretchBltMode(hdc_backbuffer, quality_low) ; 3: Lower quality at 1st draw
   
   A_index2 := pos
    pos_x := thumb_w * Mod(A_Index2-1,cols)
    pos_y := thumb_h * ((A_Index2-1)//cols)
 
    PrintWindow(task_ids_%A_Index2%,hdc_printwindow,0)
 
    task_id := task_ids_%A_Index2%
   WinGetPos, diff_x, diff_y, diff_w, diff_h , ahk_id %task_id%

    diff_x := diff_x - ( pos_x + (thumb_w - thumb_w%A_Index2% ) // 2 ) - WorkArea_Left
   diff_y := diff_y - ( pos_y + (thumb_h - thumb_h%A_Index2% ) // 2 ) - WorkArea_Top
     diff_w := diff_w - ( thumb_w%A_Index2% )
   diff_h := diff_h - ( thumb_h%A_Index2% )
    
   Loop %animate_in_steps%
   {
       sleep %animate_in_delay%
          zoom := 1 - ( A_Index / animate_in_steps )
      
        BitBlt( hdc_backbuffer, 0, 0, WorkArea_Width, WorkArea_Height
           , hdc_thumbnails, 0, 0 , 0xCC0020) ; SRCCOPY
   
      if ( zoom = 0 )
         SetStretchBltMode(hdc_backbuffer, quality_high) ; 3: Lower quality at 1st draw
      StretchBlt( hdc_backbuffer , pos_x + (thumb_w - thumb_w%A_Index2% ) // 2 + diff_x * zoom      
                           , pos_y + (thumb_h - thumb_h%A_Index2% ) // 2 + diff_y * zoom      
                           , thumb_w%A_Index2% + diff_w * zoom   
                           , thumb_h%A_Index2% + diff_h * zoom
                   , hdc_printwindow, 0, 0, w%A_Index2%, h%A_Index2% ,0xCC0020) ; SRCCOPY
      if ( zoom = 0 )
         SetStretchBltMode(hdc_backbuffer, quality_low) ; 3: Lower quality at 1st draw
      Gui_Show()
      BitBlt(hdc_frontbuffer, 0, 0 ,WorkArea_Width ,WorkArea_Height
              ,hdc_backbuffer , 0, 0 ,0xCC0020) ; SRCCOPY
   }
   old_cols := cols ; prevent full refresh on next draw
    old_rows := rows
Return

; should be reverse of animate in ? combine them ...
Animate_Out:
   if !animate_out_steps
         return

   A_index2 := pos
    pos_x := thumb_w * Mod(A_Index2-1,cols)
    pos_y := thumb_h * ((A_Index2-1)//cols)
 
    If (!(pos <= num_win and X >= 0 and X <= WorkArea_Width and Y >= 0 and Y <= WorkArea_Height))
       return

   ;SetStretchBltMode(hdc_frontbuffer,quality_low) ;
    PrintWindow( task_ids_%A_Index2%, hdc_printwindow ,0) ; get selected window
   
   ; clear
     BitBlt( hdc_backbuffer, pos_x, pos_y, thumb_w, thumb_h
          , hdc_desktop   , pos_x, pos_y, 0xCC0020) ; clear with desktopimage

   task_id := task_ids_%A_Index2%
   WinGetPos, diff_x, diff_y, diff_w, diff_h , ahk_id %task_id%

    diff_x := diff_x - ( pos_x + (thumb_w - thumb_w%A_Index2% ) // 2 ) - WorkArea_Left
   diff_y := diff_y - ( pos_y + (thumb_h - thumb_h%A_Index2% ) // 2 ) - WorkArea_Top
   diff_w := diff_w - ( thumb_w%A_Index2% )
   diff_h := diff_h - ( thumb_h%A_Index2% )

   SetStretchBltMode(hdc_backbuffer,quality_low) ; 3: Lower quality at 1st draw
    Loop %animate_out_steps%
   {
       sleep %animate_out_delay%
          zoom := ( A_Index / animate_out_steps )
        
      ; you can comment this line to get bit speed, acceptable
      BitBlt( hdc_backbuffer, 0, 0, WorkArea_Width, WorkArea_Height
              , hdc_thumbnails, 0, 0, 0xCC0020) ; SRCCOPY
      
      StretchBlt( hdc_backbuffer, pos_x + (thumb_w - thumb_w%A_Index2% ) // 2 + diff_x * zoom
                           , pos_y + (thumb_h - thumb_h%A_Index2% ) // 2 + diff_y * zoom
                           , thumb_w%A_Index2% + diff_w * zoom
                           , thumb_h%A_Index2% + diff_h * zoom
                   ,hdc_printwindow, 0, 0, w%A_Index2%, h%A_Index2% ,0xCC0020) ; SRCCOPY
   
       BitBlt(hdc_frontbuffer, 0, 0, WorkArea_Width, WorkArea_Height
             ,  hdc_backbuffer, 0, 0 ,0xCC0020) ; SRCCOPY
     }
   
Return

fade_in:
   ; not used ?
Return

fade_out:
   ; fade last animate_out with real desktop
Return

Gui_Show() {
   global
   if Shown
      return
   Gui, Show
   Shown = 1
}

Gui_Hide() {
   global
   tooltip,
   if !Shown
     return
   Gui, Hide
   Shown =
}

hide_gui:
   Stop_Drawing = 1
   Gui_Hide()
   WinActivate(ActiveID)                   ; activate last active window
Return

handle_exit:
   Gui Destroy
   ReleaseDC(hw_frame,hdc_frontbuffer) ; free lock?
   DeleteObject( hbm_printwindow)
   DeleteDC(     hdc_printwindow)
   DeleteObject( hbm_window)
   DeleteDC(     hdc_window)
   DeleteObject( hbm_backbuffer)
   DeleteDC(     hdc_backbuffer)
 ;  WinActivate ahk_id %ActiveID%           ; activate last active window
ExitApp

; --------------------------------------------------------------------------------------------------
; Library: no need to modify below

; Libary (could be put in extra file )
; #include <GDI.ahk>
; for documentation of commands see: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/gdi/wingdistart_9ezp.asp

; -- highlevel not direct dllcall mapping , simplifiers
CreateDCBuffer(ByRef hdc_from, ByRef hdc_to, ByRef hbm_to, w ,h ) {
   ; does not work, something wrong with ByRef and global
   hdc_to  := CreateCompatibleDC(hdc_from) ; buffer
   hbm_to  := CreateCompatibleBitmap(hdc_from,w,h)
   old     := SelectObject(hdc_to,hbm_to)
}

; -- mfc wrapper
GetDC( hw ) {
   return DLLCall("GetDC", UInt, hw )
}

CreateDC( driver,device,output,mode  ) {
   return DLLCall("GetDC", UInt, driver, UInt, device, UInt, output, UInt, mode )
}

SetStretchBltMode( hdc , value ) {
     return DllCall("gdi32.dll\SetStretchBltMode", UInt,hdc, "int",value)
}

CreateCompatibleDC( hdc ) {
   return DllCall("gdi32.dll\CreateCompatibleDC", UInt,hdc)
}

CreateCompatibleBitmap( hdc , w, h ) {
     return DllCall("gdi32.dll\CreateCompatibleBitmap", UInt,hdc, Int,w, Int,h)
}

SelectObject( hdc , hbm ) {
   return DllCall("gdi32.dll\SelectObject", UInt,hdc, UInt,hbm)
}

DeleteObject( hbm ) {
   return DllCall("gdi32.dll\DeleteObject", UInt,hbm)   
}

DeleteDC( hdc ) {
   return DllCall("gdi32.dll\DeleteDC", UInt,hdc )
}

ReleaseDC( hwnd, hdc ) {
   return DllCall("gdi32.dll\ReleaseDC", UInt,hwnd,UInt,hdc )
}

PrintWindow( window_id , hdc , mode ) {
   return DllCall("PrintWindow", UInt, window_id , UInt,hdc, UInt, mode)
}

StretchBlt( hdc_dest , x1, y1, w1, h1, hdc_source , x2, y2, w2, h2 , mode) {
   return DllCall("gdi32.dll\StretchBlt"
          , UInt,hdc_dest  , Int,x1, Int,y1, Int,w1, Int,h1
             , UInt,hdc_source, Int,x2, Int,y2, Int,w2, Int,h2
          , UInt,mode)
}

BitBlt( hdc_dest, x1, y1, w1, h1 , hdc_source, x2, y2 , mode ) {
   return DllCall("gdi32.dll\BitBlt"
          , UInt,hdc_dest   , Int, x1, Int, y1, Int, w1, Int, h1
             , UInt,hdc_source    , Int, x2, Int, y2
          , UInt, mode)
}

PaintDesktop(  hdc ) {
   return DllCall("PaintDesktop", UInt, hdc )
}

; constants
; see: http://www.adaptiveintelligence.net/Developers/Reference/Win32API/GDIConstants.aspx
; #SRCCOPY = 0xCC0020



Back to top
View user's profile Send private message Visit poster's website
IN2ITive



Joined: 15 Apr 2008
Posts: 17

PostPosted: Sat May 10, 2008 4:01 am    Post subject: Reply with quote

Thanks again holomind...I will test this code when i get into work on Monday...have a great weekend! (ps i may dial in on the weekend to give it a go Smile
Back to top
View user's profile Send private message
IN2ITive



Joined: 15 Apr 2008
Posts: 17

PostPosted: Sun May 11, 2008 6:24 pm    Post subject: Reply with quote

Well Holomind I tried it on my home pc and it is working very well. The zoom feature will definitely be a helpful addition for my work environment.

It definitely is more stable and it seems super fast on my home pc; I will give you additional feedback when I am at work tomorrow.

Thanks again, and enjoy the rest of your weekend!
Back to top
View user's profile Send private message
IN2ITive



Joined: 15 Apr 2008
Posts: 17

PostPosted: Mon May 12, 2008 3:00 pm    Post subject: Reply with quote

Tried it at work and it works very well. The only thing I noticed from Holomind's previous post is that the live preview is only on the hovered window. While this is a good feature for some things (and would be better performance-wise) it doesn't fit my need at work since the monitor is like a monitoring station; I would like to have quickly glance at the screen (my second pc) to see that the automation code is running on all virtual machines (which are in their own remote desktop window). It is a little more time consuming to hover over all of the windows.

I imagine it is a just a commented out piece of code as this was in there before. I will take a stab at it but if anyone else knows how to get the live previews back on for all windows it is appreciated.

Thanks again Holomind!
Back to top
View user's profile Send private message
Guest






PostPosted: Wed May 14, 2008 5:24 am    Post subject: Reply with quote

excellent! this is the only thing I miss from working in OSX.

Wondering if there is any way to have it show minimized windows as well?
Back to top
SomeGuy



Joined: 21 Apr 2008
Posts: 92
Location: somewhere

PostPosted: Wed May 14, 2008 5:31 am    Post subject: Reply with quote

i have my taskbar at the top of the screem auto-hiding and when in expose view it does not cover the normal taskbar area up (on the bottom of the screen)...very nice script though... Very Happy

edit: just saw the show taskbar option...
Back to top
View user's profile Send private message
IN2ITive



Joined: 15 Apr 2008
Posts: 17

PostPosted: Wed May 14, 2008 9:27 pm    Post subject: Reply with quote

Hi:

I haven't had much time to fool around and see if I can get the live previews back...I have noticed that the draw_active window is where the action occurs but that is it so far.

By the way, my boss was at my desk today I I happened to have all the automation VMs running and he nearly fell over! He couldn't believe that this was done with AHK and was thouroughly impressed by the work done in Holomind's script.

Anyway, also wanted to add a feature that may be nice...
When zooming, if you are on a window that is near the edge of the screen, when it zooms you don't see the whole window as it is cut off at the edge. Maybe the ability to toggle a key so that you can "move the window so that you can see everything. At this time the script does move with the cursor when the window is zoomed, but as soon as it detects a different window then it switches to a zoom of that window, which it should. But maybe a toggle key to state "don't draw the new window, just move the present window until the toggle is done".
Back to top
View user's profile Send private message
Rhys



Joined: 17 Apr 2007
Posts: 618
Location: Florida

PostPosted: Wed May 14, 2008 10:00 pm    Post subject: Reply with quote

Wow, this has come a long way, the new features are really nice.

It runs fairly well on my slow work computer with many open apps and a very high resolution.

Keep up the good work Cool
_________________
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions All times are GMT
Goto page Previous  1, 2, 3 ... 14, 15, 16
Page 16 of 16

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group