Sign in to follow this  
Followers 0
rliiack

Clearing image on desktop

13 posts in this topic

For example I use the _GDIPlus_GraphicsDrawImageRectRect function to draw an image on the desktop. Is it possible to erase or clear the image after drawing it?


My Projects:Smart Icons

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Method 1

DllCall('shell32.dll', 'none', 'SHChangeNotify', 'long', 0x08000000, 'uint', 0, 'ptr', 0, 'ptr', 0)

Method 2

_SendMessage(_WinAPI_FindWindow('Progman', 'Program Manager'), 0x0111, 0x7103, 0)

Method 3

_WinAPI_ShowWindow(_WinAPI_FindWindow('Progman', 'Program Manager'), @SW_HIDE)
_WinAPI_ShowWindow(_WinAPI_FindWindow('Progman', 'Program Manager'), @SW_SHOW)
Edited by Yashied

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

However, is there any way to update the screen without it flashing?

Edited by rliiack

My Projects:Smart Icons

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

#Include <FontConstants.au3>
#Include <WinAPI.au3>
#Include <WindowsConstants.au3>

; Paint on Desktop

$tRECT = DllStructCreate($tagRect)
DllStructSetData($tRECT, 1, 5)
DllStructSetData($tRECT, 2, 5)
DllStructSetData($tRECT, 3, 250)
DllStructSetData($tRECT, 4, 50)

$hDC = _WinAPI_GetDC(0)
$hFont = _WinAPI_CreateFont(50, 0, 0, 0, 400, 0, 0, 0, $DEFAULT_CHARSET, $OUT_DEFAULT_PRECIS, $CLIP_DEFAULT_PRECIS, $DEFAULT_QUALITY, 0, 'Arial')
$hOldFont = _WinAPI_SelectObject($hDC, $hFont)
_WinAPI_SetTextColor($hDC, 0x0000FF)
_WinAPI_SetBkMode($hDC, $TRANSPARENT)
_WinAPI_DrawText($hDC, 'Hello world!', $tRect, $DT_CENTER)
_WinAPI_SelectObject($hDC, $hOldFont)
_WinAPI_DeleteObject($hFont)
_WinAPI_ReleaseDC(0, $hDC)

MsgBox(0, '', 'Press OK to clear Desktop.')

; Clear the painting area

$hWnd = ControlGetHandle(_WinAPI_FindWindow('Progman', 'Program Manager'), '', '[CLASS:SysListView32;INSTANCE:1]')
_WinAPI_InvalidateRect($hWnd, $tRect, 1)

Edited by Yashied

Share this post


Link to post
Share on other sites

Not sure what does _WinAPI_SelectObject($hDC, $hOldFont) do. How come the Hello closes after I haven't pressed OK? I did a if statement, but it acts the same too.

#Include <FontConstants.au3>
#Include <WinAPI.au3>
#Include <WindowsConstants.au3> ; Paint on Desktop
$tRECT = DllStructCreate($tagRect)
DllStructSetData($tRECT, 1, 5)
DllStructSetData($tRECT, 2, 5)
DllStructSetData($tRECT, 3, 250)
DllStructSetData($tRECT, 4, 50)
$hDC = _WinAPI_GetDC(0)
$hFont = _WinAPI_CreateFont(50, 0, 0, 0, 400, 0, 0, 0, $DEFAULT_CHARSET, $OUT_DEFAULT_PRECIS, $CLIP_DEFAULT_PRECIS, $DEFAULT_QUALITY, 0, 'Arial')
$hOldFont = _WinAPI_SelectObject($hDC, $hFont)
_WinAPI_SetTextColor($hDC, 0x0000FF)
_WinAPI_SetBkMode($hDC, $TRANSPARENT)
_WinAPI_DrawText($hDC, 'Hello world!', $tRect, $DT_CENTER)
_WinAPI_SelectObject($hDC, $hOldFont)

$msg=MsgBox(0, '', 'Press OK to clear Desktop.') ; Clear the painting area
$hWnd = ControlGetHandle(_WinAPI_FindWindow('Progman', 'Program Manager'), '', '[CLASS:SysListView32;INSTANCE:1]')
If $msg=1 Then
_WinAPI_DeleteObject($hFont)
_WinAPI_ReleaseDC(0, $hDC)
_WinAPI_InvalidateRect($hWnd, $tRect, 1)
EndIf

My Projects:Smart Icons

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

This part is need to draw "Hello world!" only. I took it from the help file. Do not pay attention to it.

$tRECT = DllStructCreate($tagRect)
DllStructSetData($tRECT, 1, 5)
DllStructSetData($tRECT, 2, 5)
DllStructSetData($tRECT, 3, 250)
DllStructSetData($tRECT, 4, 50)

$hDC = _WinAPI_GetDC(0)
$hFont = _WinAPI_CreateFont(50, 0, 0, 0, 400, 0, 0, 0, $DEFAULT_CHARSET, $OUT_DEFAULT_PRECIS, $CLIP_DEFAULT_PRECIS, $DEFAULT_QUALITY, 0, 'Arial')
$hOldFont = _WinAPI_SelectObject($hDC, $hFont)
_WinAPI_SetTextColor($hDC, 0x0000FF)
_WinAPI_SetBkMode($hDC, $TRANSPARENT)
_WinAPI_DrawText($hDC, 'Hello world!', $tRect, $DT_CENTER)
_WinAPI_SelectObject($hDC, $hOldFont)
_WinAPI_DeleteObject($hFont)
_WinAPI_ReleaseDC(0, $hDC)

The next part will be update the whole Desktop.

$hWnd = ControlGetHandle(_WinAPI_FindWindow('Progman', 'Program Manager'), '', '[CLASS:SysListView32;INSTANCE:1]')
_WinAPI_InvalidateRect($hWnd, 0, 1)

But it will flicker, and so I reduced the update area to as needed (see $tRect).

$hWnd = ControlGetHandle(_WinAPI_FindWindow('Progman', 'Program Manager'), '', '[CLASS:SysListView32;INSTANCE:1]')
_WinAPI_InvalidateRect($hWnd, $tRect, 1)

This is exactly what does Windows when you, for example, move a windows on the Desktop. Updated only required area.

Edited by Yashied

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

It looks nice :) but when I implement it, it gives me an error.

#include <GDIPlus.au3>
#include <ScreenCapture.au3>
#Include <WinAPI.au3>
     $hHandle=ControlGetHandle("[CLASS:Progman]", "", "[CLASS:SysListView32;INSTANCE:1]")
     $graphics=_GDIPlus_GraphicsCreateFromHWND($hHandle)

     $hbitmap = _ScreenCapture_Capture("",0,0,100,100, False)
     $bitmap=_GDIPlus_BitmapCreateFromHBITMAP($hbitmap)
     $height=_GDIPlus_ImageGetHeight($bitmap)
     $width=_GDIPlus_ImageGetWidth($bitmap)
     _GDIPlus_GraphicsDrawImageRectRect($graphics,$bitmap,0,0,$width,$height,0,0,200,200)
     Const $tagRect="0;0;100;100"
     _WinAPI_InvalidateRect($hHandle, $tagRect, 1)

(12,31) : ERROR: $tagRect previously declared as a 'Const'

Const $tagRect="0;0;100;100"

Thanks

Edited by rliiack

My Projects:Smart Icons

Share this post


Link to post
Share on other sites

:)

#Include <GDIPlus.au3>
#Include <ScreenCapture.au3>
#Include <WinAPI.au3>

_GDIPlus_Startup()
$hWnd = ControlGetHandle("[CLASS:Progman]", "", "[CLASS:SysListView32;INSTANCE:1]")
$hGraphics = _GDIPlus_GraphicsCreateFromHWND($hWnd)
$hBitmap = _ScreenCapture_Capture("", 0, 0, 100, 100, False)
$hImage = _GDIPlus_BitmapCreateFromHBITMAP($hBitmap)
_WinAPI_DeleteObject($hBitmap)
$iHeight = _GDIPlus_ImageGetHeight($hImage)
$iWidth = _GDIPlus_ImageGetWidth($hImage)
_GDIPlus_GraphicsDrawImageRectRect($hGraphics, $hImage, 0, 0, $iWidth, $iHeight, 0, 0, 200, 200)
_GDIPlus_ImageDispose($hImage)
_GDIPlus_Shutdown()

MsgBox(0, "", "OK?")

$tRect = DllStructCreate($tagRECT)
DllStructSetData($tRect, 1, 0)
DllStructSetData($tRect, 2, 0)
DllStructSetData($tRect, 3, 200)
DllStructSetData($tRect, 4, 200)

_WinAPI_InvalidateRect($hWnd, $tRect, 1)

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

It's basically a icon magnifier that magnifies icon. The first time I am doing it wasn't really what I wanted Here and it sucks too. So I am doing it again to fix a few things.

Right now I come up with this:

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <SliderConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <GuiListView.au3>
#include <Array.au3>
#include <GDIPlus.au3>
#include <ScreenCapture.au3>
#Include <WinAPI.au3>
HotKeySet("{ESC}","Quit")

Global $finalDistance, $msg, $desktop, $iconNumber, $x, $y, $pos, $oPos, $iconPos, $iconPos2, $min, $minIndexPos, $hHandle, $save2, $input2, $checkBox2, $volume2

Global $iFD = 0
Global $pFD = 0
Global $pSC_X1 = 0
Global $pSC_Y1 = 0
Global $OS = @OSVersion

If $OS = "WIN_XP" Then
    Global $oZoomHeight=76
    Global $oZoomWidth=76
    Global $zoomHeight=142
    Global $zoomWidth=142

ElseIf $OS = "WIN_VISTA" Then

     Global $oZoomHeight=86
     Global $oZoomWidth=86
     Global $zoomHeight=172
     Global $zoomWidth=172
EndIf

opt("GUIOnEventMode",1)
$SI = GUICreate("Smart Icons Control Panel", 625, 445, 192, 124)
GUISetFont(20, 800, 0, "Australian Sunrise")
$soundOptions = GUICtrlCreateGroup("Sound Options", 88, 16, 473, 137, -1, $WS_EX_TRANSPARENT)
GUICtrlSetFont(-1, 30, 800, 0, "Australian Sunrise")
$volume = GUICtrlCreateSlider(112, 88, 257, 48)
GUICtrlSetLimit ($volume, 100, 0)
GUICtrlSetData($volume,80)
$checkBox=GUICtrlCreateCheckbox("", 408, 88, 17, 25)
$mute = GUICtrlCreateLabel("Mute", 432, 88, 65, 35)
GUICtrlSetFont(-1, 20, 800, 0, "Times New Roman")
$magnifyingSize = GUICtrlCreateGroup("Magnifying Size", 88, 168, 473, 145)
GUICtrlSetFont(-1, 30, 800, 0, "Australian Sunrise")
$input=GUICtrlCreateInput("", 144, 240, 137, 50)
GUICtrlSetFont(-1, 35, 800, 0, "Australian Sunrise")
GUICtrlSetData($input,2)
$xLabel = GUICtrlCreateLabel("X", 288, 256, 23, 35)
GUICtrlSetFont(-1, 20, 800, 0, "Times New Roman")
$Save = GUICtrlCreateButton("Save", 360, 232, 153, 65, $WS_GROUP)
GUICtrlSetFont(-1, 25, 800, 0, "Australian Sunrise")
$Quit = GUICtrlCreateButton("Quit", 216, 344, 217, 81, $WS_GROUP)
GUICtrlSetFont(-1, 35, 800, 0, "Australian Sunrise")
GUISetState(@SW_SHOW)
GUICtrlSetOnEvent($Quit, "Quit")

;~ If $OS = "WIN_XP" Then
;~ $hHandle=GUICreate("Smart Icon",142,142,-1,-1, $WS_SIZEBOX + $WS_SYSMENU + $WS_MINIMIZEBOX)
;~ GUISetState(@SW_SHOW)

;~ ElseIf $OS = "WIN_VISTA" Then
;~ $hHandle=GUICreate("Smart Icon",172,192,-1,-1, $WS_SIZEBOX + $WS_SYSMENU + $WS_MINIMIZEBOX)
;~ GUISetState(@SW_SHOW)
;~ EndIf

    $hHandle = ControlGetHandle(_WinAPI_FindWindow('Progman', 'Program Manager'), '', '[CLASS:SysListView32;INSTANCE:1]')

_GDIPlus_Startup()

While 1
$input2=GUICtrlRead($input)
$checkBox2=GUICtrlRead($checkBox)
$volume2=GUICtrlRead($volume)
SoundSetWaveVolume($volume2)
GUICtrlSetOnEvent($Save, "save")

getMousePosition()
getIconPositions()

Global $distance[$iconNumber]
Global $distance2[$iconNumber]
For $i=0 To UBound($iconPos) -1
    $distance[$i]=((($iconPos2[$i][0]-$x)*($iconPos2[$i][0]-$x))+(($iconPos2[$i][1]-$y)*($iconPos2[$i][1]-$y)))^(1/2)
Next
For $i=0 To UBound($distance) -1
    If  $distance[$i]<=100 Then
        $distance2[$i]=$distance[$i]
    EndIf
Next

Local $hit=_GUICtrlListView_HitTest($desktop,-1,-1)



accessArrayData()

If ($finalDistance[$minIndexPos][0]<300 And $finalDistance[$minIndexPos][0]>0) Or $hit[2]=True Then
    $graphics=_GDIPlus_GraphicsCreateFromHWND($hHandle)

If $oPos <> $finalDistance[$minIndexPos][1] Then
; $minIndexPos is an integer
     ; $finalDistance is a 2D array
     ;$iconPos is a 2D array
     $iFD = $finalDistance[$minIndexPos][1]
     $iSC_X1 = $iconPos[$iFD][0]
     $iSC_Y1 = $iconPos[$iFD][1]
     $iDT_X2 = $iconPos[$iFD][0] + 86
     $iDT_Y2 = $iconPos[$iFD][1] + 86

     $tRect = DllStructCreate($tagRECT)
     DllStructSetData($tRect, 1, $pSC_X1)
     DllStructSetData($tRect, 2, $pSC_Y1)
     DllStructSetData($tRect, 3, $pSC_X1+$zoomWidth)
     DllStructSetData($tRect, 4, $psc_Y1+$zoomHeight)
     _WinAPI_InvalidateRect($hHandle, $tRect, 1)

     Sleep(50)

     $hbitmap = _ScreenCapture_Capture("", $iSC_X1, $iSC_Y1, $iDT_X2, $iDT_Y2, False)

     Sleep(300)
EndIf

$oPos=$iFD
$pFD = $finalDistance[$minIndexPos][1]
$pSC_X1 = $iconPos[$pFD][0]
$pSC_Y1 = $iconPos[$pFD][1]

    $bitmap=_GDIPlus_BitmapCreateFromHBITMAP($hbitmap)

    $height=_GDIPlus_ImageGetHeight($bitmap)
    $width=_GDIPlus_ImageGetWidth($bitmap)
    _GDIPlus_GraphicsDrawImageRectRect($graphics,$bitmap,0,0,$width,$height,$iSC_X1,$iSC_Y1,$zoomWidth,$zoomHeight)

    If $checkBox2=$GUI_UNCHECKED Then
    SoundPlay(@WindowsDir & "\media\tada.wav",1)
    EndIf

    _WinAPI_DeleteObject($hbitmap)
    _WinAPI_DeleteObject($bitmap)
EndIf
WEnd

_GDIPlus_Shutdown()




Func getMousePosition()
$pos=MouseGetPos()
$x=$pos[0]
$y=$pos[1]
EndFunc





Func getIconPositions()
    $desktop=ControlGetHandle("[CLASS:Progman]","","[CLASS:SysListView32;INSTANCE:1]")
    $iconNumber=_GUICtrlListView_GetItemCount($desktop)
    If $iconNumber>0 Then
         Global $iconPos[$iconNumber][2]
         Global $iconPos2[$iconNumber][2]
     For $i=0 To UBound($iconPos) -1
         If $OS = "WIN_XP" Then
              $iconPos[$i][0]=_GUICtrlListView_GetItemPositionX($desktop, $i)-22
              $iconPos[$i][1]=_GUICtrlListView_GetItemPositionY($desktop, $i)
              $iconPos2[$i][0]=_GUICtrlListView_GetItemPositionX($desktop, $i)+38
              $iconPos2[$i][1]=_GUICtrlListView_GetItemPositionY($desktop, $i)+31

        ElseIf $OS = "WIN_VISTA" Then
              $iconPos[$i][0]=_GUICtrlListView_GetItemPositionX($desktop, $i)
              $iconPos[$i][1]=_GUICtrlListView_GetItemPositionY($desktop, $i)
              $iconPos2[$i][0]=_GUICtrlListView_GetItemPositionX($desktop, $i)+38
              $iconPos2[$i][1]=_GUICtrlListView_GetItemPositionY($desktop, $i)+34.5
        EndIf
    Next
    Else
        MsgBox(64,"Error","No icons on desktop.", 3)
        Exit
    EndIf
EndFunc




Func Quit()
_SendMessage(_WinAPI_FindWindow('Progman', 'Program Manager'), 0x0111, 0x7103, 0)
   Exit
EndFunc





Func accessArrayData()
     Local $counter=0
     Local $counter2=0
     Global $finalDistance[UBound($distance2)][2]

    for $i=0 To UBound($distance2) -1
        If $distance2[$i]>0 Then
             $finalDistance[$counter][0]=$distance2[$i]
             $finalDistance[$counter][1]=$i
             $counter=$counter+1
         EndIf
     Next

    _ArraySort($finalDistance,1,0,0,0)

    If $finalDistance[0][0]=0 Then
        $counter2=0
    Else
    for $i=0 To UBound($finalDistance) -1
        If $finalDistance[$i][0]>0 Then
            $counter2=$counter2+1
        EndIf
    Next
    $counter2-=1
    EndIf

    $min=$finalDistance[$counter2][0]
    $minIndexPos=_ArraySearch($finalDistance,$min)
EndFunc




Func save()
    If $input2=1 Then
        $zoomHeight=$oZoomHeight
        $zoomWidth=$oZoomWidth
    Else
        $zoomHeight=$oZoomHeight*$input2
        $zoomWidth=$oZoomWidth*$input2
    EndIf
EndFunc

Can you try it and see what bugs I have?

Thank you for all your help!

Edited by rliiack

My Projects:Smart Icons

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

Ironically misrepresented that you do not need to draw on the Desktop, better to create your own window and "conjure" in it. Below is a simple example "Magnify x4". Here is something to think about, but on the whole idea should be clear. And no any flicker.

:)

#Include <WinAPIEx.au3>
#Include <WindowsConstants.au3>

Opt('MustDeclareVars', 1)

Global $hParent, $hForm, $Pos, $hBitmap = 0, $Go = 1, $XPrev = MouseGetPos(0), $YPrev = MouseGetPos(1)

HotKeySet('{ESC}', '_Quit')

$hParent = GUICreate('', -1, -1, -1, -1, -1, $WS_EX_TOOLWINDOW)
$hForm = GUICreate('', 200, 200, $XPrev + 25, $YPrev + 25, BitOR($WS_DISABLED, $WS_POPUPWINDOW), BitOR($WS_EX_LAYERED, $WS_EX_TOPMOST), $hParent)
GUISetState(@SW_SHOWNOACTIVATE, $hForm)

While 1
    GUIGetMsg()
    $Pos = MouseGetPos()
    If ($Go) Or ($Pos[0] <> $XPrev) Or ($Pos[1] <> $YPrev) Then
        WinMove($hForm, '', $Pos[0] + 25, $Pos[1] + 25)
        _Capture($Pos[0] - 25, $Pos[1] - 25, 50, 50)
        $XPrev = $Pos[0]
        $YPrev = $Pos[1]
        $Go = 0
    EndIf
WEnd

Func _Capture($iX, $iY, $iWidth, $iHeight)

    Local $tRect, $hDC, $hMemDC, $hScreenshort = _ScreenCapture($iX, $iY, $iWidth, $iHeight)

    _WinAPI_FreeObject($hBitmap)
    $hBitmap = _WinAPI_FitToBitmap($hScreenshort, 200, 200)
    _WinAPI_FreeObject($hScreenshort)
    $hDC = _WinAPI_GetDC($hForm)
    $hMemDC = _WinAPI_CreateCompatibleDC($hDC)
    _WinAPI_SelectObject($hMemDC, $hBitmap)
    _WinAPI_SelectObject($hMemDC, _WinAPI_GetStockObject($NULL_BRUSH))
    _WinAPI_SelectObject($hMemDC, _WinAPI_GetStockObject($DC_PEN))
    _WinAPI_SetDCPenColor($hMemDC, 0xA00000)
    $tRect = _WinAPI_CreateRect(0, 0, 200, 200)
    _WinAPI_Rectangle($hMemDC, $tRect)
    _WinAPI_ReleaseDC($hForm, $hDC)
    _WinAPI_DeleteDC($hMemDC)
    _SetBitmap($hForm, $hBitmap, 255)
EndFunc   ;==>_Capture

Func _Quit()
    Exit
EndFunc   ;==>_Quit

Func _ScreenCapture($iX, $iY, $iWidth, $iHeight)

    Local $hWnd, $hDC, $hMemDC, $hBitmap

    $hWnd = _WinAPI_GetDesktopWindow()
    $hDC = _WinAPI_GetDC($hWnd)
    $hMemDC = _WinAPI_CreateCompatibleDC($hDC)
    $hBitmap = _WinAPI_CreateCompatibleBitmap($hDC, $iWidth, $iHeight)
    _WinAPI_SelectObject($hMemDC, $hBitmap)
    _WinAPI_BitBlt($hMemDC, 0, 0, $iWidth, $iHeight, $hDC, $iX, $iY, $MERGECOPY)
    _WinAPI_ReleaseDC($hWnd, $hDC)
    _WinAPI_DeleteDC($hMemDC)
    Return $hBitmap
EndFunc   ;==>_ScreenCapture

Func _SetBitmap($hWnd, $hBitmap, $iOpacity)

    Local $hDC, $hMemDC, $hSv, $pBlend, $tBlend, $pSize, $tSize, $pSource, $tSource

    $hDC = _WinAPI_GetDC($hWnd)
    $hMemDC = _WinAPI_CreateCompatibleDC($hDC)
    $hSv = _WinAPI_SelectObject($hMemDC, $hBitmap)
    $tSize = _WinAPI_GetBitmapDimension($hBitmap)
    $pSize = DllStructGetPtr($tSize)
    $tSource = DllStructCreate($tagPOINT)
    $pSource = DllStructGetPtr($tSource)
    $tBlend = DllStructCreate($tagBLENDFUNCTION)
    $pBlend = DllStructGetPtr($tBlend)
    DllStructSetData($tBlend, 'Alpha', $iOpacity)
    DllStructSetData($tBlend, 'Format', 0)
    _WinAPI_UpdateLayeredWindow($hWnd, $hDC, 0, $pSize, $hMemDC, $pSource, 0, $pBlend, $ULW_ALPHA)
    _WinAPI_ReleaseDC($hWnd, $hDC)
    _WinAPI_SelectObject($hMemDC, $hSv)
    _WinAPI_DeleteDC($hMemDC)
EndFunc   ;==>_SetBitmap

WinAPIEx.au3

Edited by Yashied

Share this post


Link to post
Share on other sites

#13 ·  Posted (edited)

It's basically a icon magnifier that magnifies icon. The first time I am doing it wasn't really what I wanted Here and it sucks too. So I am doing it again to fix a few things.

Right now I come up with this:

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <SliderConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <GuiListView.au3>
#include <Array.au3>
#include <GDIPlus.au3>
#include <ScreenCapture.au3>
#Include <WinAPI.au3>
HotKeySet("{ESC}","Quit")

Global $finalDistance, $msg, $desktop, $iconNumber, $x, $y, $pos, $oPos, $iconPos, $iconPos2, $min, $minIndexPos, $hHandle, $save2, $input2, $checkBox2, $volume2

Global $iFD = 0
Global $pFD = 0
Global $pSC_X1 = 0
Global $pSC_Y1 = 0
Global $OS = @OSVersion

If $OS = "WIN_XP" Then
    Global $oZoomHeight=76
    Global $oZoomWidth=76
    Global $zoomHeight=142
    Global $zoomWidth=142

ElseIf $OS = "WIN_VISTA" Then

     Global $oZoomHeight=86
     Global $oZoomWidth=86
     Global $zoomHeight=172
     Global $zoomWidth=172
EndIf

opt("GUIOnEventMode",1)
$SI = GUICreate("Smart Icons Control Panel", 625, 445, 192, 124)
GUISetFont(20, 800, 0, "Australian Sunrise")
$soundOptions = GUICtrlCreateGroup("Sound Options", 88, 16, 473, 137, -1, $WS_EX_TRANSPARENT)
GUICtrlSetFont(-1, 30, 800, 0, "Australian Sunrise")
$volume = GUICtrlCreateSlider(112, 88, 257, 48)
GUICtrlSetLimit ($volume, 100, 0)
GUICtrlSetData($volume,80)
$checkBox=GUICtrlCreateCheckbox("", 408, 88, 17, 25)
$mute = GUICtrlCreateLabel("Mute", 432, 88, 65, 35)
GUICtrlSetFont(-1, 20, 800, 0, "Times New Roman")
$magnifyingSize = GUICtrlCreateGroup("Magnifying Size", 88, 168, 473, 145)
GUICtrlSetFont(-1, 30, 800, 0, "Australian Sunrise")
$input=GUICtrlCreateInput("", 144, 240, 137, 50)
GUICtrlSetFont(-1, 35, 800, 0, "Australian Sunrise")
GUICtrlSetData($input,2)
$xLabel = GUICtrlCreateLabel("X", 288, 256, 23, 35)
GUICtrlSetFont(-1, 20, 800, 0, "Times New Roman")
$Save = GUICtrlCreateButton("Save", 360, 232, 153, 65, $WS_GROUP)
GUICtrlSetFont(-1, 25, 800, 0, "Australian Sunrise")
$Quit = GUICtrlCreateButton("Quit", 216, 344, 217, 81, $WS_GROUP)
GUICtrlSetFont(-1, 35, 800, 0, "Australian Sunrise")
GUISetState(@SW_SHOW)
GUICtrlSetOnEvent($Quit, "Quit")

;~ If $OS = "WIN_XP" Then
;~ $hHandle=GUICreate("Smart Icon",142,142,-1,-1, $WS_SIZEBOX + $WS_SYSMENU + $WS_MINIMIZEBOX)
;~ GUISetState(@SW_SHOW)

;~ ElseIf $OS = "WIN_VISTA" Then
;~ $hHandle=GUICreate("Smart Icon",172,192,-1,-1, $WS_SIZEBOX + $WS_SYSMENU + $WS_MINIMIZEBOX)
;~ GUISetState(@SW_SHOW)
;~ EndIf

    $hHandle = ControlGetHandle(_WinAPI_FindWindow('Progman', 'Program Manager'), '', '[CLASS:SysListView32;INSTANCE:1]')

_GDIPlus_Startup()

While 1
$input2=GUICtrlRead($input)
$checkBox2=GUICtrlRead($checkBox)
$volume2=GUICtrlRead($volume)
SoundSetWaveVolume($volume2)
GUICtrlSetOnEvent($Save, "save")

getMousePosition()
getIconPositions()

Global $distance[$iconNumber]
Global $distance2[$iconNumber]
For $i=0 To UBound($iconPos) -1
    $distance[$i]=((($iconPos2[$i][0]-$x)*($iconPos2[$i][0]-$x))+(($iconPos2[$i][1]-$y)*($iconPos2[$i][1]-$y)))^(1/2)
Next
For $i=0 To UBound($distance) -1
    If  $distance[$i]<=100 Then
        $distance2[$i]=$distance[$i]
    EndIf
Next

Local $hit=_GUICtrlListView_HitTest($desktop,-1,-1)



accessArrayData()

If ($finalDistance[$minIndexPos][0]<300 And $finalDistance[$minIndexPos][0]>0) Or $hit[2]=True Then
    $graphics=_GDIPlus_GraphicsCreateFromHWND($hHandle)

If $oPos <> $finalDistance[$minIndexPos][1] Then
; $minIndexPos is an integer
     ; $finalDistance is a 2D array
     ;$iconPos is a 2D array
     $iFD = $finalDistance[$minIndexPos][1]
     $iSC_X1 = $iconPos[$iFD][0]
     $iSC_Y1 = $iconPos[$iFD][1]
     $iDT_X2 = $iconPos[$iFD][0] + 86
     $iDT_Y2 = $iconPos[$iFD][1] + 86

     $tRect = DllStructCreate($tagRECT)
     DllStructSetData($tRect, 1, $pSC_X1)
     DllStructSetData($tRect, 2, $pSC_Y1)
     DllStructSetData($tRect, 3, $pSC_X1+$zoomWidth)
     DllStructSetData($tRect, 4, $psc_Y1+$zoomHeight)
     _WinAPI_InvalidateRect($hHandle, $tRect, 1)

     Sleep(50)

     $hbitmap = _ScreenCapture_Capture("", $iSC_X1, $iSC_Y1, $iDT_X2, $iDT_Y2, False)

     Sleep(300)
EndIf

$oPos=$iFD
$pFD = $finalDistance[$minIndexPos][1]
$pSC_X1 = $iconPos[$pFD][0]
$pSC_Y1 = $iconPos[$pFD][1]

    $bitmap=_GDIPlus_BitmapCreateFromHBITMAP($hbitmap)

    $height=_GDIPlus_ImageGetHeight($bitmap)
    $width=_GDIPlus_ImageGetWidth($bitmap)
    _GDIPlus_GraphicsDrawImageRectRect($graphics,$bitmap,0,0,$width,$height,$iSC_X1,$iSC_Y1,$zoomWidth,$zoomHeight)

    If $checkBox2=$GUI_UNCHECKED Then
    SoundPlay(@WindowsDir & "\media\tada.wav",1)
    EndIf

    _WinAPI_DeleteObject($hbitmap)
    _WinAPI_DeleteObject($bitmap)
EndIf
WEnd

_GDIPlus_Shutdown()




Func getMousePosition()
$pos=MouseGetPos()
$x=$pos[0]
$y=$pos[1]
EndFunc





Func getIconPositions()
    $desktop=ControlGetHandle("[CLASS:Progman]","","[CLASS:SysListView32;INSTANCE:1]")
    $iconNumber=_GUICtrlListView_GetItemCount($desktop)
    If $iconNumber>0 Then
         Global $iconPos[$iconNumber][2]
         Global $iconPos2[$iconNumber][2]
     For $i=0 To UBound($iconPos) -1
         If $OS = "WIN_XP" Then
              $iconPos[$i][0]=_GUICtrlListView_GetItemPositionX($desktop, $i)-22
              $iconPos[$i][1]=_GUICtrlListView_GetItemPositionY($desktop, $i)
              $iconPos2[$i][0]=_GUICtrlListView_GetItemPositionX($desktop, $i)+38
              $iconPos2[$i][1]=_GUICtrlListView_GetItemPositionY($desktop, $i)+31

        ElseIf $OS = "WIN_VISTA" Then
              $iconPos[$i][0]=_GUICtrlListView_GetItemPositionX($desktop, $i)
              $iconPos[$i][1]=_GUICtrlListView_GetItemPositionY($desktop, $i)
              $iconPos2[$i][0]=_GUICtrlListView_GetItemPositionX($desktop, $i)+38
              $iconPos2[$i][1]=_GUICtrlListView_GetItemPositionY($desktop, $i)+34.5
        EndIf
    Next
    Else
        MsgBox(64,"Error","No icons on desktop.", 3)
        Exit
    EndIf
EndFunc




Func Quit()
_SendMessage(_WinAPI_FindWindow('Progman', 'Program Manager'), 0x0111, 0x7103, 0)
   Exit
EndFunc





Func accessArrayData()
     Local $counter=0
     Local $counter2=0
     Global $finalDistance[UBound($distance2)][2]

    for $i=0 To UBound($distance2) -1
        If $distance2[$i]>0 Then
             $finalDistance[$counter][0]=$distance2[$i]
             $finalDistance[$counter][1]=$i
             $counter=$counter+1
         EndIf
     Next

    _ArraySort($finalDistance,1,0,0,0)

    If $finalDistance[0][0]=0 Then
        $counter2=0
    Else
    for $i=0 To UBound($finalDistance) -1
        If $finalDistance[$i][0]>0 Then
            $counter2=$counter2+1
        EndIf
    Next
    $counter2-=1
    EndIf

    $min=$finalDistance[$counter2][0]
    $minIndexPos=_ArraySearch($finalDistance,$min)
EndFunc




Func save()
    If $input2=1 Then
        $zoomHeight=$oZoomHeight
        $zoomWidth=$oZoomWidth
    Else
        $zoomHeight=$oZoomHeight*$input2
        $zoomWidth=$oZoomWidth*$input2
    EndIf
EndFunc

Can you try it and see what bugs I have?

Thank you for all your help!

Hello, is there any way to make my magnified images appear faster?

:)

Edited by rliiack

My Projects:Smart Icons

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0