AutoHotkey Community

It is currently May 26th, 2012, 4:16 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 6 posts ] 
Author Message
PostPosted: August 14th, 2008, 1:13 pm 
Offline

Joined: January 6th, 2008, 8:09 pm
Posts: 39
Location: Gdi+ v1.1
Hi.

I wrote this some time ago, and I thought, that maybe I could share it, although it's not finished.

It's just a copy of the Windows Vista window preview, which shows up, when a taskbar button is hovered. The limitation of the script is that some apps need to be "seen" before, to draw them correctly. It also can't show minimized apps or grouped apps.

To run the script, you'll need COM Standard Library and ACC Standard Library by Sean (http://www.autohotkey.com/forum/viewtopic.php?t=24234). You can edit it as much as you like.

Code:
#Include ACC.ahk
#Include COM.ahk
#NoTrayIcon

ExcludeList:="Mozilla Firefox"  ;Seperate with a |

SetBatchLines, -1
SetWinDelay, -1
SetTitleMatchMode, 3
SetTitleMatchMode, Fast

ACC_Init()
Shown:=0
Stop:=0
WasMinimized=
LastWin=

SysGet, MonitorWorkArea, MonitorWorkArea, 1
WorkAreaH:=MonitorWorkAreaBottom

CoordMode, Mouse, Screen
OnExit, Close

Gui, +AlwaysOnTop +LastFound -Caption +Owner +E0x20
Gui, Show, w200 h200

GUI_ID:=WinExist()

WinSet, Transparent, 1, ahk_id %GUI_ID%

Sleep, 100

PrintWindow:=DllCall("GetProcAddress",UInt,DllCall

("GetModuleHandle",Str,"user32"),Str,"PrintWindow")
StretchBlt:=DllCall("GetProcAddress",UInt,DllCall

("GetModuleHandle",Str,"gdi32"),Str,"StretchBlt")
gdi32:=DllCall("LoadLibrary",Str,"gdi32.dll")

hdc_TMP:=DLLCall("GetDC", UInt, GUI_ID )
hdc_PreviewTMP := DllCall("CreateCompatibleDC", UInt,hdc_TMP)
hbm_PreviewTMP := DllCall("CreateCompatibleBitmap", UInt,hdc_TMP, Int,1024, Int,768)
selobj:=DllCall("SelectObject", UInt,hdc_PreviewTMP, UInt,hbm_PreviewTMP)


Gui, Hide

Hotkey, LButton, LButtonDown
Hotkey, LButton up, LButtonUp

Hotkey, LButton, Off
Hotkey, LButton up, Off

SetTimer, Loopp, 100

Return

Loopp:
  MouseGetPos, X, Y, Title, Control

  if(Title=WinExist("ahk_class Shell_TrayWnd"))
    if(Control="ToolbarWindow323")
    {
      Stop:=0
      if(Shown=X)
        Stop:=1
      if(Stop=0)
      {
        If Not   pacc := ACC_AccessibleObjectFromPoint()
          Return
        If   paccChild:=acc_Child(pacc, _idChild_)
          sResult   := acc_Name(paccChild),   COM_Release(paccChild)
        Else
          sResult := acc_Name(pacc, _idChild_)
        COM_Release(pacc)
        if(sResult=LastWin)
          Stop:=1
        if(Stop=0)
        {
          IfWinExist, %sResult%
          {
            Win:=WinExist()
            WinGet, Minimized, MinMax, ahk_id %Win%
            if(Minimized>-1)
            {
              Loop, parse, ExcludeList, |
                if(InStr(sResult, A_LoopField))
                  Return
              Hotkey, LButton, On
              Hotkey, LButton up, On
              WinGetPos,,, w, h, ahk_id %Win%
              scale:=200/w
              w2:=200
              h2:=h*scale
              y:=WorkAreaH-h2
              x2:=X-100
              Gui, Show, NoActivate x%x2% y%y% w%w2% h%h2%
              WinSet, Transparent, 1, ahk_id %GUI_ID%
              Shown:=X
              LastWin:=sResult
              GetWindow(sResult, w, h, hdc_PreviewTMP, hdm_PreviewTMP, hdc_TMP, x2, y, w2, h2)
              Sleep, 50
              if(WasMinimized=sResult)
              {
                WasMinimized=
                WinSet, Redraw, , %sResult%
              }
              WinSet, Transparent, 150, ahk_id %GUI_ID%
              if(clickeddown=1)
              {
                Click up
                Sleep, 25
                Click up
                clickeddown:=0
              }
              Hotkey, LButton, Off
              Hotkey, LButton up, Off
            }Else{
              WinSet, Transparent, 1, ahk_id %GUI_ID%
              Gui, Hide
              Shown:=0
              Stop:=0
              WasMinimized:=sResult
              LastWin=
            }
          }Else{
            WinSet, Transparent, 1, ahk_id %GUI_ID%
            Gui, Hide
            Shown:=0
            Stop:=0
            LastWin=
          }
        }
      }
    }Else{
      if(Shown<>0)
      {
        WinSet, Transparent, 1, ahk_id %GUI_ID%
        Gui, Hide
        Shown:=0
        Stop:=0
        LastWin=
      }
    }
  Else{
    if(Shown<>0)
    {
      WinSet, Transparent, 1, ahk_id %GUI_ID%
      Gui, Hide
      Shown:=0
      Stop:=0
      LastWin=
    }
  }
Return

GetWindow(Win, w, h, hdc_PreviewTMP, hdm_PreviewTMP, hdc_TMP, x2, y, w2, h2)
{
  global PrintWindow, StretchBlt
  DllCall(PrintWindow, UInt, WinExist(Win) , UInt,hdc_PreviewTMP, UInt, 0)
  DllCall(StretchBlt, UInt,hdc_TMP, Int,0, Int,0, Int,w2, Int,h2, UInt,hdc_PreviewTMP, Int,0, Int,0,

Int,w, Int,h, UInt,0xCC0020)
}

LButtonDown:
Sleep, 150
clickeddown:=1
Click down
Return

LButtonUp:
Sleep, 200
clickeddown:=0
Click up
Return

Close:
COM_Release(psv)
ACC_Term()
DllCall("DeleteObject", UInt, selobj)
DllCall("DeleteDC", UInt, hdc_PreviewTMP)
DllCall("DeleteDC", UInt, hdc_TMP)
DllCall("FreeLibrary",UInt,gdi32)
ExitApp

_________________
My first app: Note
(Please, vote if you like my apps!)

None of my apps took me more than a day to create... After this time I get bored with it (maybe except the note one)...


Last edited by jk7800 on November 10th, 2008, 4:24 pm, edited 3 times in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 14th, 2008, 3:24 pm 
Offline

Joined: November 8th, 2004, 12:46 am
Posts: 1271
Hi jk7800, I tried this script on 2k and it only shows transparent black windows.

_________________
"Anything worth doing is worth doing slowly." - Mae West
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 15th, 2008, 2:48 am 
Offline

Joined: January 12th, 2008, 7:45 pm
Posts: 131
Serenity wrote:
Hi jk7800, I tried this script on 2k and it only shows transparent black windows.


Works for me, 2k Doesn't support transparency, instead of a transparent picture w2k renders a solid black color....


Nice Script, but it seems kinda buggy when you move the mouse through many windows, or when you're at the desktop, I didn't look through this problem properly...


Code:
#Include ACC.ahk
#Include COM.ahk

SetBatchLines, -1
SetWinDelay, -1
SetTitleMatchMode, 3
SetTitleMatchMode, Fast

ACC_Init()
Shown:=0
Stop:=0
WasMinimized=
LastWin=

SysGet, MonitorWorkArea, MonitorWorkArea, 1
WorkAreaH:=MonitorWorkAreaBottom

CoordMode, Mouse, Screen
OnExit, Close

Gui, +AlwaysOnTop +LastFound -Caption +Owner +E0x20
Gui, Show, w200 h200

GUI_ID:=WinExist()

;WinSet, Transparent, 1, ahk_id %GUI_ID%

Sleep, 100

hdc_TMP:=DLLCall("GetDC", UInt, GUI_ID )
hdc_PreviewTMP := DllCall("gdi32.dll\CreateCompatibleDC", UInt,hdc_TMP)
hbm_PreviewTMP := DllCall("gdi32.dll\CreateCompatibleBitmap", UInt,hdc_TMP, Int,1024, Int,768)
selobj:=DllCall("gdi32.dll\SelectObject", UInt,hdc_PreviewTMP, UInt,hbm_PreviewTMP)


Gui, Hide

SetTimer, Loopp, 100

Return

Loopp:
  MouseGetPos, X, Y, Title, Control

  if(Title=WinExist("ahk_class Shell_TrayWnd"))
    if(Control="ToolbarWindow323")
    {
      Stop:=0
      if(Shown=X)
        Stop:=1
      if(Stop=0)
      {
        If Not   pacc := ACC_AccessibleObjectFromPoint()
          Return
        If   paccChild:=acc_Child(pacc, _idChild_)
          sResult   := acc_Name(paccChild),   COM_Release(paccChild)
        Else
          sResult := acc_Name(pacc, _idChild_)
        COM_Release(pacc)
        if(sResult=LastWin)
          Stop:=1
        if(Stop=0)
        {
;          DllCall("gdi32.dll\RestoreDC", UInt,hdc_TMP, Int,Clear)
          IfWinExist, %sResult%
          {
            Win:=WinExist()
            WinGet, Minimized, MinMax, ahk_id %Win%
            if(Minimized>-1)
            {
              WinGetPos,,, w, h, ahk_id %Win%
              scale:=200/w
              w2:=200
              h2:=h*scale
              y:=WorkAreaH-h2
              x2:=X-100
              if(WasMinimized=sResult)
              {
                WasMinimized=
                Return
              }
              Gui, Show, NoActivate x%x2% y%y% w%w2% h%h2%
              ;WinSet, Transparent, 1, ahk_id %GUI_ID%
              Shown:=X
              LastWin:=sResult
              GetWindow(sResult, w, h, hdc_PreviewTMP, hdm_PreviewTMP, hdc_TMP, x2, y, w2, h2)
              ;WinSet, Transparent, 150, ahk_id %GUI_ID%
            }Else{
              ;WinSet, Transparent, 1, ahk_id %GUI_ID%
              Gui, Hide
              Shown:=0
              Stop:=0
              WasMinimized:=sResult
              LastWin=
            }
          }Else{
            ;WinSet, Transparent, 1, ahk_id %GUI_ID%
            Gui, Hide
            Shown:=0
            Stop:=0
            LastWin=
          }
        }
      }
    }Else{
      if(Shown<>0)
      {
        ;WinSet, Transparent, 1, ahk_id %GUI_ID%
        Gui, Hide
        Shown:=0
        Stop:=0
        LastWin=
      }
    }
  Else{
    if(Shown<>0)
    {
      ;WinSet, Transparent, 1, ahk_id %GUI_ID%
      Gui, Hide
      Shown:=0
      Stop:=0
      LastWin=
    }
  }
Return

GetWindow(Win, w, h, hdc_PreviewTMP, hdm_PreviewTMP, hdc_TMP, x2, y, w2, h2)
{
  DllCall("PrintWindow", UInt, WinExist(Win) , UInt,hdc_PreviewTMP, UInt, 0)
  DllCall("gdi32.dll\StretchBlt", UInt,hdc_TMP, Int,0, Int,0, Int,w2, Int,h2, UInt,hdc_PreviewTMP, Int,0, Int,0, Int,w, Int,h, UInt,0xCC0020)
}

Close:
COM_Release(psv)
ACC_Term()
DllCall("gdi32.dll\DeleteObject", UInt, selobj)
DllCall("gdi32.dll\DeleteDC", UInt, hdc_PreviewTMP)
DllCall("gdi32.dll\DeleteDC", UInt, hdc_TMP)
ExitApp

I commented out the winset transparent lines quickly, didn't bother to test it at all, should work on w2k as it doesn't use transparency..


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 15th, 2008, 4:16 am 
Offline

Joined: November 8th, 2004, 12:46 am
Posts: 1271
300W wrote:
I commented out the winset transparent lines quickly, didn't bother to test it at all, should work on w2k as it doesn't use transparency..


Thanks, I tried that already and got solid black windows instead.

_________________
"Anything worth doing is worth doing slowly." - Mae West
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 25th, 2008, 6:46 pm 
Offline

Joined: January 6th, 2008, 8:09 pm
Posts: 39
Location: Gdi+ v1.1
I know, that this thread is a bit old, but I had no time during last month to answer. If you are still wondering, why the script does not work on win 2000, it's because the PrintWindow function is only available in windows xp and higher. If you still want to use the script, download the user32.dll for windows xp, rename it (e.g. user32_xp.dll), place it in the scripts folder and change this line:
Code:
DllCall("PrintWindow"

to
Code:
DllCall("user32_xp.dll\PrintWindow",

Maybe it will work...

I have updated the script, because of often redraw problems (they were a bit annoying to me...)

_________________
My first app: Note
(Please, vote if you like my apps!)

None of my apps took me more than a day to create... After this time I get bored with it (maybe except the note one)...


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 15th, 2009, 10:31 am 
Offline

Joined: January 15th, 2008, 12:20 pm
Posts: 14
No, it doesn't... gdi32.dll is also making problem..


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: G. Sperotto, Yahoo [Bot] and 13 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group