Sign in to follow this  
Followers 0
Ebenezer

Could someone have a look at this ?

5 posts in this topic

Hi everyone

I'm trying to send the application window to the tray. This works fine if I use the doubleclick on the tray icon. However using the minimize-button on the window itself will send it to the taskbar instead, even though both should lead to the same commands.

Could someone have a look and verify if it is a general problem or just my computer acting up ?

Thanks guys :) , E.

#include <constants.au3>
#include <GUIConstants.au3>
#include <GuiListView.au3>

Opt("GUIOnEventMode", 1)
Opt( "TrayOnEventMode", 1)
Opt("TrayAutoPause", 0)
Opt("TrayMenuMode", 1)

Global Const $WM_NOTIFY = 0x004E

Global Const $NM_FIRST = 0
Global Const $NM_LAST = (-99)
Global Const $NM_OUTOFMEMORY = ($NM_FIRST - 1)
Global Const $NM_CLICK = ($NM_FIRST - 2)
Global Const $NM_DBLCLK = ($NM_FIRST - 3)

$Inifile = "Config.Ini"
$Datadump = "Hashesarchive.Ini"

#region - GUI

$MainWindow = GUICreate("Testing222", (@DesktopWidth-40), (@DesktopHeight-105), 20, 20, -1, $WS_EX_TOPMOST)

   #region - Link Storage
   
  ; Context Menu
    Dim $vCategories_Array[3]
   
    $Storage_Categories = GUICtrlCreateListView("Categories", 30, 50, 100, (@DesktopHeight-185))
    GUICtrlSetStyle(-1, BitOr($LVS_REPORT, $LVS_SINGLESEL, $LVS_SHOWSELALWAYS), $LVS_EX_FULLROWSELECT)
    $vCategories_Array[0] =  GUICtrlCreateListViewItem("- Show Clipboard", $Storage_Categories)
    $vCategories_Array[1] =  GUICtrlCreateListViewItem("- Show All Saved", $Storage_Categories)
    $vCategories_Array[2] =  GUICtrlCreateListViewItem("General", $Storage_Categories)
    
    $vCategories_Names_Array = IniReadSection($Inifile, "Categories")
    If @error <> 1 Then
        ReDim $vCategories_Array[(3+$vCategories_Names_Array[0][0])]
        For $i = 3 To $vCategories_Names_Array[0][0]+2
            $vCategories_Array[$i] = GUICtrlCreateListViewItem($vCategories_Names_Array[($i-2)][0], $Storage_Categories)
        Next
    EndIf
   
  ;Categories Context Menu
    $Con_Storage_Categories = GUICtrlCreateContextMenu($Storage_Categories)
    $Con_Storage_Categories_Create = GUICtrlCreateMenuitem("New Group", $Con_Storage_Categories)
    $Con_Storage_Categories_Delete = GUICtrlCreateMenuitem("Delete Group", $Con_Storage_Categories)
   
  ;Main Linklist
    $NewItems_Storage = GUICtrlCreateListView("Filename|Filesize|Hash", 150, 50, (@DesktopWidth-220), (@DesktopHeight-185), $LVS_SHOWSELALWAYS)
    _GUICtrlListViewSetColumnWidth($NewItems_Storage, 1, 85)
    _GUICtrlListViewSetColumnWidth($NewItems_Storage, 2, 200)
    _GUICtrlListViewSetColumnWidth($NewItems_Storage, 0, (@DesktopWidth-585))
   
  ;Linklist ContextMenu
    $Context_NewItems = GUICtrlCreateContextMenu($NewItems_Storage)
    $Con_NewItems_Download = GUICtrlCreateMenuitem("Download Selected", $Context_NewItems)
    $Con_NewItems_Filter = GUICtrlCreateMenuitem("Filter Selected", $Context_NewItems)
   
   
   
   
   #endregion
   
   #endregion
   
   
   
   #region - Event Triggers
   
  ;Register WM_NOTIFY  events
   GUIRegisterMsg($WM_NOTIFY, "WM_Notify_Events")
   GUISetOnEvent($GUI_EVENT_MINIMIZE, "trayLClick")
   TraySetOnEvent($TRAY_EVENT_PRIMARYDOUBLE, "trayLClick")
   GUISetOnEvent($GUI_EVENT_DROPPED, "ProcessDropEvent")
   GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked")
   GUICtrlSetOnEvent($Con_NewItems_Download, "DownloadMultiple")
   GUICtrlSetOnEvent($Con_NewItems_Filter, "FilterMultiple")
   GUICtrlSetOnEvent($Con_Storage_Categories_Create, "CreateGroup")
   GUICtrlSetOnEvent($Con_Storage_Categories_Delete, "GetSelectedCategory")
  ;Additional Events under WM_Notify_Events
   
   #endregion
   
   #region - Clipboard Hook
   
   Global Const $WM_DRAWCLIPBOARD = 0x0308
   Global Const $WM_CHANGECBCHAIN = 0x030D
   Global $origHWND
   
   $origHWND = DLLCall("user32.dll","hwnd","SetClipboardViewer","hwnd",$MainWindow)
   $origHWND = $origHWND[0]
   
   GUIRegisterMsg($WM_DRAWCLIPBOARD,"OnClipBoardChange")
   GUIRegisterMsg($WM_CHANGECBCHAIN,"OnClipBoardViewerChange")
   
   #endregion
   
   
   
  ;~ Minimize()
   
   While 1
   Sleep(20000)
   WEnd
   
   
   #region - Transfer to Edonkey
   
   Func ListView_DoubleClick()
    $vItem = _GUICtrlListViewGetSelectedIndices($NewItems_Storage)
   
    If $vItem <> -1 Then
        $Name = _GUICtrlListViewGetItemText($NewItems_Storage, $vItem, 0)
        $Size = _GUICtrlListViewGetItemText($NewItems_Storage, $vItem, 1)
        $Hash = _GUICtrlListViewGetItemText($NewItems_Storage, $vItem, 2)
        $Link = "ed2k://|file|"&$Name&"|"&$Size&"|"&$Hash&"|"
        RunWait("rundll32.exe url.dll,FileProtocolHandler " & $Link, @WorkingDir)
        IniWrite($Datadump, "Filters", $Hash, $Size)
        _GUICtrlListViewDeleteItemsSelected($NewItems_Storage)
    EndIf
    
   EndFunc ;==>ListView_DoubleClick
   
   Func DownloadMultiple()
    
    $vNumberOfSelected = _GUICtrlListViewGetSelectedCount($NewItems_Storage)
    
    If $vNumberOfSelected <> 0 AND $vNumberOfSelected <> -1 Then
        Dim $vIndex[$vNumberOfSelected]
        Dim $vDowns[$vNumberOfSelected][3]
        
        $vIndex = _GUICtrlListViewGetSelectedIndices($NewItems_Storage, 1, $MainWindow)
  ;erst holen       
        For $i = 1 To $vNumberOfSelected
            $Name = _GUICtrlListViewGetItemText($NewItems_Storage, $vIndex[$i], 0, $MainWindow)
            $Size = _GUICtrlListViewGetItemText($NewItems_Storage, $vIndex[$i], 1, $MainWindow)
            $Hash = _GUICtrlListViewGetItemText($NewItems_Storage, $vIndex[$i], 2, $MainWindow)
            $Link = "ed2k://|file|"&$Name&"|"&$Size&"|"&$Hash&"|"
            $vDowns[($i-1)][0] = $Link
            $vDowns[($i-1)][1] = $Hash
            $vDowns[($i-1)][2] = $Size
            
        Next
    EndIf
    
  ;dann übertragen
    For $i = 1 To $vNumberOfSelected
        RunWait("rundll32.exe url.dll,FileProtocolHandler " & $vDowns[($i-1)][0], @WorkingDir)
        Sleep(1000)
        IniWrite($Datadump, "Filters", $vDowns[($i-1)][1], $vDowns[($i-1)][2])
    Next
    
    _GUICtrlListViewDeleteItemsSelected($NewItems_Storage, $MainWindow)
    
   EndFunc
   
   #endregion
   
   
   
   
   
   
   
   #region - Management Functions
   
func trayLClick()
   dim $state

   $state = winGetState( $MainWindow )
   if bitAnd( $state, 0x02) = 0x02 then
      guiSetState( @SW_HIDE, $MainWindow)
   else
      guiSetState( @SW_SHOW, $MainWindow)
   endif
endfunc
   
   Func CLOSEClicked()
   ; send notification that we no longer will be in clipboard hook queue
    DLLCall("user32.dll","int","ChangeClipboardChain","hwnd",$MainWindow,"hwnd",$origHWND)
    Exit
   EndFunc
   
   Func Minimize()
;~      Opt("TrayIconHide", 0);show tray icon
    GuiSetState(@SW_HIDE, $MainWindow)
   EndFunc
   
;~  Func Maximize()
;~      GuiSetState(@SW_RESTORE, $MainWindow);show GUI
;~      Opt("TrayIconHide", 1);hide tray icon
;~  EndFunc
   
   Func WM_Notify_Events($hWndGUI, $MsgID, $wParam, $lParam)
    #forceref $hWndGUI, $MsgID, $wParam
    Local $tagNMHDR, $event, $hwndFrom, $code
    $tagNMHDR = DllStructCreate("int;int;int", $lParam);NMHDR (hwndFrom, idFrom, code)
    If @error Then Return
    $event = DllStructGetData($tagNMHDR, 3)
    Select
    Case $wParam = $NewItems_Storage
        Select
            Case $event = $NM_CLICK
  ;~                 ListView_Click ()
            Case $event = $NM_DBLCLK
                ListView_DoubleClick ()
            EndSelect
    EndSelect
    $tagNMHDR = 0
    $event = 0
    $lParam = 0
   EndFunc ;==>WM_Notify_Events
   
   Func FilterMultiple()
    $vNumberOfSelected = _GUICtrlListViewGetSelectedCount($NewItems_Storage)
    
    If $vNumberOfSelected <> 0 AND $vNumberOfSelected <> -1 Then
        Dim $vIndex[$vNumberOfSelected]
        
        $vIndex = _GUICtrlListViewGetSelectedIndices($NewItems_Storage, 1)
        
        For $i = 1 To UBound($vIndex)-1
            $Name = _GUICtrlListViewGetItemText($NewItems_Storage, $vIndex[$i], 0)
            $Size = _GUICtrlListViewGetItemText($NewItems_Storage, $vIndex[$i], 1)
            $Hash = _GUICtrlListViewGetItemText($NewItems_Storage, $vIndex[$i], 2)
            IniWrite($Datadump, "Filters", $Hash, $Size)
        Next
        
        _GUICtrlListViewDeleteItemsSelected($NewItems_Storage)
    EndIf
   EndFunc
   
   #endregion
   
   
   
   #region - Clipboard Management
   
   Func OnClipBoardChange($hWnd, $Msg, $wParam, $lParam)
  ; do what you need when clipboard changes
    ProcessClipboard()
  ; send notification about clipboard change to next clipviewer
    dllcall("user32.dll","int","SendMessage","hWnd",$origHWND,"int",$WM_DRAWCLIPBOARD,"int",$wParam,"int",$lParam)
   EndFunc
   
   Func ProcessClipboard()
    
    $Temp = ClipGet()
    $NumberofItems = NumberOfResults($Temp, "ed2k://")
    
    If $NumberofItems > 0 Then
        _GUICtrlListViewDeleteAllItems($NewItems_Storage)
    
        For $i = 1 To $NumberofItems
            $ItemStart = StringInStr($Temp, "ed2k://", 1, $i)
            $Name = SucheBegriff($Temp, $ItemStart, "|", 2, "|", 1)
            $Size = SucheBegriff($Temp, $ItemStart, "|", 3, "|", 1)
            $Hash = SucheBegriff($Temp, $ItemStart, "|", 4, "|", 1)
            $Link = "ed2k://|file|"&$Name&"|"&$Size&"|"&$Hash&"|"
            
            If IniRead($Datadump, "Filters", $Hash, -1) = -1 Then
                GUICtrlCreateListViewItem($Name & "|" & $Size & "|" & $Hash, $NewItems_Storage)
            EndIf
        Next
        trayLClick()
    EndIf
    
   EndFunc
   
   Func OnClipBoardViewerChange($hWnd, $Msg, $wParam, $lParam)
  ; if our remembered previous clipviewer is removed then we must remember new next clipviewer
  ; else send notification about clipviewr change to next clipviewer
    If $wParam = $origHWND Then
        $origHWND = $lParam
    Else
        dllcall("user32.dll","int","SendMessage","hWnd",$origHWND,"int",$WM_CHANGECBCHAIN,"hwnd",$wParam,"hwnd",$lParam)
    EndIf
   EndFunc
   
   #endregion
   
   
   
   
   
   #region - Category Management for Tab1
   
   Func ProcessDropEvent()
    MsgBox(0, "From", @GUI_DragId)
    MsgBox(0, "To", @GUI_DropId)
    MsgBox(0, "To", @GUI_DragFile)
   EndFunc
   
   Func GetSelectedCategory()
    $vTemp = GuiGetCursorInfo($MainWindow)
    MsgBox(0, "", $vTemp[4])
  ;~    $vCoordinatesMain = ControlGetPos("", "", $MainWindow)
  ;~    $vCoordinates = ControlGetPos("", "", $MainWindow)
   EndFunc
    
   Func CreateGroup()
    $vName = InputBox("Create New Group", "Please enter a name for the new group")
    
    If $vName <> "" Then
        ReDim $vCategories_Array[(UBound($vCategories_Array)+1)]
        $vCategories_Array[(UBound($vCategories_Array)-1)] = GUICtrlCreateListViewItem($vName, $Storage_Categories)
        IniWrite($Inifile, "Categories", $vName, -1)
    EndIf
   EndFunc
   
   
   #endregion
   
   
   
   
   
   
   
   
   
   #region - Search Functions
   
   Func NumberOfResults($StringToSearch, $vSuchbegriff_Start)                       ;Wie viele Items auf der Seite. Wird unten gebraucht, damit der Array in seinen Grenzen arbeitet
   For $y = 1 to 2500
    $pos = StringInStr ($StringToSearch, $vSuchbegriff_Start, 1, $y)
         If $pos = 0 Then ; StringInStr() failed
             ExitLoop
         EndIf
     Next
   Return($y-1)
   EndFunc
   
   Func SucheBegriff($Searchedstring_Temp, $vStartpos, $vSuchbegriff_Start, $StartCount, $vSuchbegriff_Stopp, $StoppCount)
    
   #CS 
    Suchen nach dem xten ($count) jeweiligen Wert im String (Searchedstring)  
   #CE
    $Grenze_links = _Searchfromplace($Searchedstring_Temp, $vSuchbegriff_Start, $vStartpos, $StartCount) + StringLen($vSuchbegriff_Start)
    $Grenze_rechts = _Searchfromplace($Searchedstring_Temp, $vSuchbegriff_Stopp, $Grenze_links, $StoppCount)
    $Lenghtcount = $Grenze_rechts - $Grenze_links
    
    Return(StringMid($Searchedstring_Temp, $Grenze_links, $Lenghtcount))
   EndFunc
   
   Func _Searchfromplace($Searchedstring_Temp, $Searchstring, $start, $Count)
    
   #CS  
        Sucht das xte Auftreten eines Terms nach der angegebenen Position und gibt die Position im Gesamtstring aus.
        OK
   #CE
    $Searchedstring_Temp_Lenght = StringLen($Searchedstring_Temp)
    
    $Searchedstring_Temp = StringTrimLeft ( $Searchedstring_Temp, $start )
        
    $Add_to_count = ($Searchedstring_Temp_Lenght - (StringLen($Searchedstring_Temp)))
    $Position_Searchstring = StringInStr($Searchedstring_Temp, $Searchstring, 1, $Count)
    Return($Position_Searchstring + $Add_to_count)
   EndFunc
   
   #endregion

Share this post


Link to post
Share on other sites



Something like this?

While 1
    Sleep(50)
    If BitAND(WinGetState($MainWindow), 16) Then
        GUISetState(@SW_HIDE, $MainWindow)
        GUISetState(@SW_RESTORE, $MainWindow)
    EndIf
WEnd

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

What version of AutoIt?

I'm still running 3.1.1.113 on this XP SP2 machine--so I had to remove the lines containing GUIRegisterMsg and @GUI_DragId--but minimizing to tray worked fine for me.


Use Mozilla | Take a look at My Disorganized AutoIt stuff | Very very old: AutoBuilder 11 Jan 2005 prototype I need to update my sig!

Share this post


Link to post
Share on other sites

As far as my uneducated eye can make out (helpfile info) i'm running v3.1.1.114 (beta)

Just to make things more visual :D - I do this:

Posted Image

and get this:

Posted Image

Any other way of minimize works fine (ie clicking on the taskbar-entry or doubleclicking the tray icon)

@jdeb

Just tried your code - solved it perfectly - many thanks :( .

Could you explain to me WHY it did? As far as i can see it does the same thing I tried, just more often. Trying to learn here :)

Share this post


Link to post
Share on other sites

What version of AutoIt?

I'm still running 3.1.1.113 on this XP SP2 machine--so I had to remove the lines containing GUIRegisterMsg and @GUI_DragId--but minimizing to tray worked fine for me.

Looks like GUIRegisterMsg () is the cause of this issue..

I am running 3.1.1.122 and when i comment the GUIRegisterMsg () things work fine for me too.. :)


Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

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