KiXforms Forum Index KiXforms
The Forum for the KiXforms Community
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
 Quick Links 
Site News
Downloads
Documentation
Donations
Script Archive
Tracking Systems

NorifyIcon() and Right click context menus

 
Post new topic   Reply to topic    KiXforms Forum Index -> Advanced Scripting
View previous topic :: View next topic  
Author Message
acmp
KiXforms Dabbler
KiXforms Dabbler


Joined: 22 Mar 2007
Posts: 12

PostPosted: Thu Apr 12, 2007 2:56 pm    Post subject: NorifyIcon() and Right click context menus Reply with quote

Sorry for resurrecting this, I really want a right click menu that works on a notifyicon but just can't get it working.

I've had a search around and have found 3 threads that all seem to resolve the issue, then break it again. and they are all from 2005.


Yes I have the latest build of KF.

Yes I can get the $NotifyIcon.mousebutton to work once then it locks to the value and that is that.

So, has this ever been properly resolved? If so how do you do it? If not, will/can it be fixed as right click context menus for notifyicons sounds very promising.

My goal is to add a context menu with some basic options such as restore and close (plus some other bits) to a notifyicon.
Back to top
View user's profile Send private message
benny69
KiXforms Advocate
KiXforms Advocate


Joined: 30 Oct 2003
Posts: 567
Location: Lincoln, Ne

PostPosted: Thu Apr 12, 2007 11:45 pm    Post subject: Reply with quote

The question you ask sounds like you want a right click context menu on the notify icon, all three of the examples that I posted in the links you show, work just fine. Am I mis understanding your question?
_________________
Wait don't order yet,... get KiXforms Designer .NET 2.0 (Beta)
KiXforms Designer .NET 2.0 (Beta)
Back to top
View user's profile Send private message Send e-mail
acmp
KiXforms Dabbler
KiXforms Dabbler


Joined: 22 Mar 2007
Posts: 12

PostPosted: Fri Apr 13, 2007 7:08 am    Post subject: Reply with quote

no you're not misunderstanding my question, that is exactly what I'm after.

The thing is that I seem to be suffering the 'once you right click, every click is a right click' problem.

So when I launch the code I can double left click to restore the app or right click to get a menu. But after that first right click every click is seen as a right click

Code:
$mb=$form.mousebutton


$mb always returns 2

If it helps I'm running on XP Pro SP2, all up to date. KF DLL 2.46.55.0

It is quite possible that I have simply missed an important bit from the posts, but I really can't get this working.
Back to top
View user's profile Send private message
acmp
KiXforms Dabbler
KiXforms Dabbler


Joined: 22 Mar 2007
Posts: 12

PostPosted: Fri Apr 13, 2007 9:08 am    Post subject: Reply with quote

Benny69,

for clarification, in the thread http://www.kixforms.org/forum/viewtopic.php?t=774&postdays=0&postorder=asc&start=30 (page 3 hopefully) your post dated Wed Jan 19, 2005 5:08 pm has come code that I've been playing with. The fallout from this is that it didn't work as the functionality was not present in the dll. Shawn says hell add it if it is wanted. you and others asked for it to be added.

Later a new dev build is posted.

Bottom of page 4 Shawn posts some code that looks OK. The left and right clicks are separated OK on the form, but for the icon Initially left click does nothing then you right click and get a context menu. After that left clicking the notify icon also gives the 'right click' context menu.

That was the last bit of code and I just can't see how this is corrected.

What I'm after is the app to minimise to the system tray (done that) double click to restore the app (done that) right click the notify icon to get a context menu (can't do that)

If I'm missing something and this can be done then a code snippet or pointer tn the right direction would be nice.
Back to top
View user's profile Send private message
benny69
KiXforms Advocate
KiXforms Advocate


Joined: 30 Oct 2003
Posts: 567
Location: Lincoln, Ne

PostPosted: Fri Apr 13, 2007 12:45 pm    Post subject: Reply with quote

would you post the code you are working with so i can test.
_________________
Wait don't order yet,... get KiXforms Designer .NET 2.0 (Beta)
KiXforms Designer .NET 2.0 (Beta)
Back to top
View user's profile Send private message Send e-mail
acmp
KiXforms Dabbler
KiXforms Dabbler


Joined: 22 Mar 2007
Posts: 12

PostPosted: Fri Apr 13, 2007 4:19 pm    Post subject: Reply with quote

Bennie, here's the code...
It is dependant on the hard coded file path (currently c:\kixstuff) and it works a lot better with an ini file called 'app launch.ini' in the c:\kixstuff folder.

the ini format is:

[name of app including extension]
info=[a short description]
more[more information]

if a section is not there then a no info message is displayed.

Code:
Break On
$nul=SetConsole("hide")
$System = CreateObject("Kixtart.System")

;KD START
;************* Form **************
$Form = $System.Form()
$Form.Height = 200
$Form.Left = 17
$Form.Text = "App Launch"
$Form.Top = 20
$Form.Width = 277
$Form.MaximizeBox = "False"
$Form.FormBorderStyle = 1

$Form.OnResize = "OnResize()"
$Form.Icon = $System.BuiltinIcons(62)
$Form.NotifyIcon = $System.NotifyIcon()
$Form.NotifyIcon.Icon = $Form.Icon
$Form.NotifyIcon.Text = $Form.Text
$Form.NotifyIcon.Visible = True
$Form.NotifyIcon.OnDoubleClick = "OnDoubleClick()"
$form.notifyicon.onmousedown="MenuClick()"
;**************************************

;************* btGo **************
$btGo = $Form.Controls.Button("Launch", 180, 15, 75, 23)
$btgo.onclick="btgo"
;**************************************

;************* btQuit **************
$btQuit = $Form.Controls.Button("Exit", 180, 90, 75, 23)
$btQuit.Cancel = "True"
$btquit.onclick="OnExit"
;**************************************

;************* lb1 **************
$lb1 = $Form.Controls.ListBox("ListBox1", 15, 15, 150, 95)
$lb1.ToolTipText = "Pick one"
$lb1.onclick="what"
$lb1.ondoubleclick="btgo"
;**************************************

;************* lblVer ****************
$lblVer=$form.Controls.Label ("Version",190,150,70,15)
$lblVer.fontsize="6"
;**************************************

;************* lblInfo ****************
$lblinfo=$form.Controls.Label ("Info",15,120,250,40)
$lblinfo.onclick="moreinfo"
;**************************************

;************* menu *******************
;make menu item
$Menu = $System.ContextMenu()
;Add Launch submenu branch
$Menu.Launch = $Menu.MenuItems.Add("Launch")
;add open and exit menu options
$Menu.Open = $Menu.MenuItems.Add("Open")
$Menu.Open.Onclick = "OnDoubleClick()"
$Menu.Exit = $Menu.MenuItems.Add("Exit")
$Menu.Exit.Onclick = "OnExit()"
;**************************************

;KD END
$Form.Running = 1

makelist
$lb1.ListIndex=0
$base="c:\kixstuff\"
$spec="*.kix"
$basespec=$base+$spec
$lblVer.text="version "+$ver

ondoubleclick
what
Play "c:\windows\media\Windows Information Bar.wav"

While $Form.Running
   $=Execute($Form.DoEvents())
Loop
Exit 1

Function btGo()
   $nos=$lb1.ListIndex
   $Form.Visible ="false"
   $Form.WindowState = $System.FormWindowState.Minimized
   ;Play "c:\windows\media\Windows Information Bar.wav"
   $ext=Right($filelist[$nos],4)
   Select
      Case $ext=".kix"
         $nul=SetConsole("show")
         ?$base+$filelist[$nos]
         ?$info
         ?
         Call($base+$filelist[$nos])
         $nul=SetConsole("hide")
      Case $ext=".exe"
         Run($base+$filelist[$nos])
      Case 1
         Shell "%COMSPEC% /c "+Chr(34)+$base+$filelist[$nos]+Chr(34)   
   EndSelect
EndFunction

Function what()
;fill in some info about the file from an ini file
   $nos=$lb1.ListIndex
   $info=ReadProfileString("c:\kixstuff\App Launch.ini",$filelist[$nos],"info")
   If $info <> ""
      $lblInfo.text=$info
   Else
      $lblInfo.text="Sorry, no information available"
   EndIf
EndFunction

Function makelist()
;get contents of the folder, make an array and populate the list box
   $file=Dir("c:\kixstuff\*.*")
      While @error=0
         If $file <> "" AND Left($file,10) <> "App Launch" AND $file <> "." AND $file <> ".."
            If $filelist=""
               $filelist=$file
            Else
               $filelist=$filelist+Chr(10)+$file
            EndIf
         EndIf
         $file=Dir("")
      Loop
   $filelist=Split($filelist,Chr(10))
   $filelist=asort($filelist)
   $i=0 ;counter for context menu use
   For Each $item In $filelist
      $lb1.additem($item)
      ;Add Launch menu items and set the onclick function
      $Menu.Launch.Open=$menu.Launch.MenuItems.Add($item)
      $Menu.Launch.Open.Onclick = "LaunchClick($i)"
      $i=$i+1
   Next
EndFunction

Function LaunchClick($index)
;set the listbox index and then behave as though we clicked it.
   $lb1.listindex=$index
   what
   btgo
EndFunction

Function moreinfo()
;get extended info from the ini file
   $msg=ReadProfileString("c:\kixstuff\App Launch.ini",$filelist[$nos],"more")
   If $msg <> ""
      $=MessageBox($filelist[$nos]+@crlf+$msg,'App Launch Centre: '+$filelist[$nos],64)
   EndIf
EndFunction

Function MenuClick()
;display the context menu
   $Menu.Show($form.NotifyIcon.MouseX,$form.NotifyIcon.MouseY)
EndFunction

Function OnDoubleClick()
;dclick the icon to restore the form
 If NOT $Form.Visible OR $Form.WindowState = $System.FormWindowState.Minimized
  $Form.WindowState = $System.FormWindowState.Normal
  $Form.Show()
  $Form.Activate()
 EndIf
EndFunction

Function OnResize()
;hide the form when minimised
 If $Form.WindowState = $System.FormWindowState.Minimized
  $Form.Hide()
 EndIf
EndFunction

Function OnExit()
   $Form.Running = 0
EndFunction

Function ASort($array, OPTIONAL $order)
    ; sort order: 0 = ascending, 1 = decending
    Dim $index, $x, $y, $tmp, $changed
    $Asort=$array
    $order=0+$order
    Do
        $changed=0
        For $index = 0 to Ubound($asort)-1
            $x=$asort[$index]
            $y=$asort[$index+1]
            If ($x > $y AND 1-$order) OR ($x < $y AND $order)
                $tmp=$x
                $asort[$index]=$y
                $asort[$index+1]=$tmp
                $changed=1
            EndIf
        Next
    Until $changed=0
EndFunction   


I'm not the most organised coder so I may have broken some good practice rules like option explicit, don't shoot me.
Back to top
View user's profile Send private message
benny69
KiXforms Advocate
KiXforms Advocate


Joined: 30 Oct 2003
Posts: 567
Location: Lincoln, Ne

PostPosted: Sun Apr 15, 2007 1:07 pm    Post subject: Reply with quote

ok I have made a small change, I changed:
Code:

Call $base+$filelist[$nos]

To:
Code:

Run '%SystemRoot%\System32\kix32.exe "'+$base+$filelist[$nos]+'"'

The call was killing your script. After changing this it seems to be working correctly, test it and let me know.

Code:

Break On
;$nul=SetConsole("hide")
$System = CreateObject("Kixtart.System")

;KD START
;************* Form **************
$Form = $System.Form()
$Form.Height = 200
$Form.Left = 17
$Form.Text = "App Launch"
$Form.Top = 20
$Form.Width = 277
$Form.MaximizeBox = "False"
$Form.FormBorderStyle = 1
$Form.OnResize = "OnResize()"
$Form.Icon = $System.BuiltinIcons(62)

$Form.NotifyIcon = $System.NotifyIcon()
$Form.NotifyIcon.Icon = $Form.Icon
$Form.NotifyIcon.Text = $Form.Text
$Form.NotifyIcon.Visible = "True"
$Form.NotifyIcon.OnDoubleClick = "OnDoubleClick()"
$form.notifyicon.onmousedown="MenuClick()"
;**************************************

;************* btGo **************
$btGo = $Form.Controls.Button("Launch", 180, 15, 75, 23)
$btgo.onclick="btgo()"
;**************************************

;************* btQuit **************
$btQuit = $Form.Controls.Button("Exit", 180, 90, 75, 23)
$btQuit.Cancel = "True"
$btquit.onclick="OnExit()"
;**************************************

;************* lb1 **************
$lb1 = $Form.Controls.ListBox("ListBox1", 15, 15, 150, 95)
$lb1.ToolTipText = "Pick one"
$lb1.onclick="what"
$lb1.ondoubleclick="btgo()"
;**************************************

;************* lblVer ****************
$lblVer=$form.Controls.Label ("Version",190,150,70,15)
$lblVer.fontsize="6"
;**************************************

;************* lblInfo ****************
$lblinfo=$form.Controls.Label ("Info",15,120,250,40)
$lblinfo.onclick="moreinfo()"
;**************************************

;************* menu *******************
;make menu item
$Menu = $System.ContextMenu()
;Add Launch submenu branch
$Menu.Launch = $Menu.MenuItems.Add("Launch")
;add open and exit menu options
$Menu.Open = $Menu.MenuItems.Add("Open")
$Menu.Open.Onclick = "OnDoubleClick()"
$Menu.Exit = $Menu.MenuItems.Add("Exit")
$Menu.Exit.Onclick = "OnExit()"
;**************************************

;KD END
$Form.Running = 1

makelist
$lb1.ListIndex=0
$base="c:\kixstuff\"
$spec="*.kix"
$basespec=$base+$spec
$lblVer.text="version "+$ver

ondoubleclick()
what()
Play "c:\windows\media\Windows Information Bar.wav"

While $Form.Running=1
   $=Execute($Form.DoEvents())
Loop
Exit 1

Function btGo()
   $nos=$lb1.ListIndex
   $Form.Visible ="false"
   $Form.WindowState = $System.FormWindowState.Minimized
   Play "c:\windows\media\Windows Information Bar.wav"
   $ext=Right($filelist[$nos],4)
   Select
      Case $ext=".kix"
         $nul=SetConsole("show")
         ? $base+$filelist[$nos]
         ? $info
         ?
         Run '%SystemRoot%\System32\wkix32.exe "'+$base+$filelist[$nos]+'"'
         $nul=SetConsole("hide")
      Case $ext=".exe"
         Run $base+$filelist[$nos]
      Case 1
         Shell "%COMSPEC% /c "+Chr(34)+$base+$filelist[$nos]+Chr(34)   
   EndSelect
EndFunction

Function what()
;fill in some info about the file from an ini file
   $nos=$lb1.ListIndex
   $info=ReadProfileString("c:\kixstuff\App Launch.ini",$filelist[$nos],"info")
   If $info <> ""
      $lblInfo.text=$info
   Else
      $lblInfo.text="Sorry, no information available"
   EndIf
EndFunction

Function makelist()
;get contents of the folder, make an array and populate the list box
   $file=Dir("c:\kixstuff\*.*")
      While @error=0
         If $file <> "" And Left($file,10) <> "App Launch" And $file <> "." And $file <> ".."
            If $filelist=""
               $filelist=$file
            Else
               $filelist=$filelist+Chr(10)+$file
            EndIf
         EndIf
         $file=Dir("")
      Loop
   $filelist=Split($filelist,Chr(10))
   $filelist=asort($filelist)
   $i=0 ;counter for context menu use
   For Each $item in $filelist
      $lb1.additem($item)
      ;Add Launch menu items and set the onclick function
      $Menu.Launch.Open=$menu.Launch.MenuItems.Add($item)
      $Menu.Launch.Open.Onclick = "LaunchClick($i)"
      $i=$i+1
   Next
EndFunction

Function LaunchClick($index)
;set the listbox index and then behave as though we clicked it.
   $lb1.listindex=$index
   what()
   btgo()
EndFunction

Function moreinfo()
;get extended info from the ini file
   $msg=ReadProfileString("c:\kixstuff\App Launch.ini",$filelist[$nos],"more")
   If $msg <> ""
      $=MessageBox($filelist[$nos]+@crlf+$msg,'App Launch Centre: '+$filelist[$nos],64)
   EndIf
EndFunction

Function MenuClick()
;display the context menu
   $Menu.Show($form.NotifyIcon.MouseX,$form.NotifyIcon.MouseY)
EndFunction

Function OnDoubleClick()
;dclick the icon to restore the form
 If Not $Form.Visible Or $Form.WindowState = $System.FormWindowState.Minimized
  $Form.WindowState = $System.FormWindowState.Normal
  $Form.Show()
  $Form.Activate()
 EndIf
EndFunction

Function OnResize()
;hide the form when minimised
 If $Form.WindowState = $System.FormWindowState.Minimized
  $Form.Hide()
 EndIf
EndFunction

Function OnExit()
   $Form.Running = 0
EndFunction

Function ASort($array, OPTIONAL $order)
    ; sort order: 0 = ascending, 1 = decending
    Dim $index, $x, $y, $tmp, $changed
    $Asort=$array
    $order=0+$order
    Do
        $changed=0
        For $index = 0 to UBound($asort)-1
            $x=$asort[$index]
            $y=$asort[$index+1]
            If ($x > $y And 1-$order) Or ($x < $y And $order)
                $tmp=$x
                $asort[$index]=$y
                $asort[$index+1]=$tmp
                $changed=1
            EndIf
        Next
    Until $changed=0
EndFunction

_________________
Wait don't order yet,... get KiXforms Designer .NET 2.0 (Beta)
KiXforms Designer .NET 2.0 (Beta)


Last edited by benny69 on Mon Apr 16, 2007 12:00 am; edited 2 times in total
Back to top
View user's profile Send private message Send e-mail
acmp
KiXforms Dabbler
KiXforms Dabbler


Joined: 22 Mar 2007
Posts: 12

PostPosted: Sun Apr 15, 2007 6:33 pm    Post subject: Reply with quote

It's odd that the call was a problem, ho hum.

I'll try your change tomorrow.

What I'm really after though is to get the context menu working for a right click.

Code:
$form.notifyicon.onmousedown="MenuClick()"

...

Function MenuClick()
;display the context menu
   $Menu.Show($form.NotifyIcon.MouseX,$form.NotifyIcon.MouseY)
EndFunction


When I used the
Code:
if $form.notifyicon.mousebutton ="2"

method then it worked for the first click only then any click is interpreted as a right click.
Back to top
View user's profile Send private message
benny69
KiXforms Advocate
KiXforms Advocate


Joined: 30 Oct 2003
Posts: 567
Location: Lincoln, Ne

PostPosted: Mon Apr 16, 2007 12:05 am    Post subject: Reply with quote

I think I know what you are talking about, the shell would produce the same effect so I have modified my previous post to reflect a change from Shell to Run. The Shell would would force your code to wait untill the executed script or program was closed. Changing it to Run will allow multiple scripts or programs to be run. Try the now modified code, I think it will give you the results you are looking for.
_________________
Wait don't order yet,... get KiXforms Designer .NET 2.0 (Beta)
KiXforms Designer .NET 2.0 (Beta)
Back to top
View user's profile Send private message Send e-mail
Sealeopard
KiXforms Aficionado
KiXforms Aficionado


Joined: 05 Mar 2003
Posts: 436
Location: Boston, MA

PostPosted: Mon Apr 16, 2007 1:15 am    Post subject: Reply with quote

Why not use the ProcessStartInfo class ?
_________________
Jens

'There are two kinds of vessels, submarines and targets.'
Back to top
View user's profile Send private message Send e-mail MSN Messenger
benny69
KiXforms Advocate
KiXforms Advocate


Joined: 30 Oct 2003
Posts: 567
Location: Lincoln, Ne

PostPosted: Mon Apr 16, 2007 2:01 am    Post subject: Reply with quote

you might but that is only in KF.net, it is not in kf.classic.
_________________
Wait don't order yet,... get KiXforms Designer .NET 2.0 (Beta)
KiXforms Designer .NET 2.0 (Beta)
Back to top
View user's profile Send private message Send e-mail
acmp
KiXforms Dabbler
KiXforms Dabbler


Joined: 22 Mar 2007
Posts: 12

PostPosted: Mon Apr 16, 2007 7:32 am    Post subject: Reply with quote

benny69 wrote:
I think I know what you are talking about, the shell would produce the same effect so I have modified my previous post to reflect a change from Shell to Run. The Shell would would force your code to wait untill the executed script or program was closed. Changing it to Run will allow multiple scripts or programs to be run. Try the now modified code, I think it will give you the results you are looking for.


Benny69, I'm not sure how this will help with a right click context menu. I get how it could improve the basic script performance.

Is it worth while changing to kf.net? will my existing code work without modification and will the right click context menu work? If an upgrade to .net fixes things then I'm happy to do it.
Back to top
View user's profile Send private message
acmp
KiXforms Dabbler
KiXforms Dabbler


Joined: 22 Mar 2007
Posts: 12

PostPosted: Thu Apr 26, 2007 10:36 am    Post subject: Reply with quote

I made a change!

I have updated
Code:
      Case 1
         Shell "%COMSPEC% /c "+Chr(34)+$base+$filelist[$nos]+Chr(34)   

to
Code:
Case 1
         Runl "%COMSPEC% /c "+Chr(34)+$base+$filelist[$nos]+Chr(34)


This made a fantastic difference in speed. A .lnk to a spreadsheet used to take around 30 seconds to open, now it's about 1 or 2.

I'm just adding an update the list function now. Just got to get my head around the menu syntax...
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    KiXforms Forum Index -> Advanced Scripting All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group