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

Notify Context Menu

 
Post new topic   Reply to topic    KiXforms Forum Index -> Starters Code Clinic
View previous topic :: View next topic  
Author Message
enahsyemotp
KiXforms Regular
KiXforms Regular


Joined: 22 Sep 2010
Posts: 40
Location: Tulsa, OK

PostPosted: Wed Mar 09, 2011 10:33 pm    Post subject: Notify Context Menu Reply with quote

Just curious if this old notify context menu issue ever got resolved?? It works as expected the first time you right-click on the sys tray icon. But after that first click, every click is detected as a mousebutton of 2 (right button). Am I using an outdated method?

Windows XP Home
kixforms classic 2.46.55.0

I found some old posts about the issue...but thought it had been resolved with one of the dev builds before .55?
(http://www.kixforms.org/forum/viewtopic.php?t=1462)

Code:
$System = CreateObject("Kixtart.System")

$Form1 = $System.Form()
$Form1.Resizable = 0
$Form1.MaximizeBox = 0
$Form1.OnClose = "Closing()"

$Form1.Menu = $System.MainMenu()
$Form1.Menu.Style = 0
$Form1.Menu.ImageList = $System.BuiltinImageList()

$Form1.FileMenu = $Form1.Menu.MenuItems.Add("File")

$Form1.TrayMenu = $Form1.FileMenu.MenuItems.Add("Minimize to Tray")
$Form1.TrayMenu.ImageIndex = 65
$Form1.TrayMenu.OnClick = "SetTray()"

$Form1.CloseMenu = $Form1.FileMenu.MenuItems.Add("Close")
$Form1.CloseMenu.ImageIndex = 9
$Form1.CloseMenu.OnClick = "Closing()"

$NotifyMenu = $System.ContextMenu()
$NotifyMenuClose = $NotifyMenu.MenuItems.Add("Open")
$NotifyMenuClose.OnClick = "OpenFromTray()"
$NotifyMenuClose = $NotifyMenu.MenuItems.Add("Close")
$NotifyMenuClose.OnClick = "Closing()"

$Form1.Show
$Form1.SetFocus()
SetTray()

While $Form1.Running or $Form1.Visible
   $Nul = Execute($Form1.DoEvents)
Loop
Exit 0

Function SetTray()
   If $Form1.TrayMenu.Checked
      $Form1.TrayMenu.Checked=0
      $Form1.TrayMenu.ImageIndex=65
      $Form1.OnResize = ""
      $NotifyIcon = ""
      $Form1.Running = 0
   Else
      $Form1.TrayMenu.Checked=1
      $Form1.TrayMenu.ImageIndex=64
      $Form1.OnResize = "MinimizeToTray()"
      $NotifyIcon = $System.NotifyIcon()
      $NotifyIcon.Icon = $Form1.Icon
      $NotifyIcon.Text = $Form1.Text
      $NotifyIcon.Visible = "True"
      $NotifyIcon.OnDoubleClick = "OpenFromTray()"
      $NotifyIcon.OnMouseDown = "TrayClicked()"
      $Form1.Running = 1
   Endif
EndFunction

Function MinimizeToTray()
   If $Form1.WindowState = 1
      $Form1.Hide()
   Endif
EndFunction

Function OpenFromTray()
   If Not $Form1.Visible Or $Form1.WindowState = 1
      $Form1.WindowState = 0
      $Form1.Show()
      $Form1.Activate()
   Endif
EndFunction

Function TrayClicked()
   If $NotifyIcon.MouseButton=2
      $NotifyMenu.Show($notifyicon.mousex,$notifyicon.mousey)
   EndIf
EndFunction

Function Closing()
   $Form1.Hide()
   $Form1.Running = 0
EndFunction
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: Wed Mar 30, 2011 1:53 am    Post subject: Reply with quote

Hi Shane,
I have not visited in a long time, but here is an example of how to use the notify icon with KiXforms.Classic;
Code:

Break On

$System = CreateObject("Kixtart.System")
If Not $System
   $nul= MessageBox("KiXforms Not Initiated. This Script Will Now Close.","Error",16)
   Quit()
EndIf

$Form = $System.Form()

$Form.Text = "NotifyIcon Example"
$Form.Icon = $System.BuiltinIcons(0)
$Form.OnResize = "Form_Resize()"

$FileMenu = $Form.Menu.MenuItems.Add("File")

$HideMenu = $FileMenu.MenuItems.Add("Hide")
$HideMenu.OnClick = "Form_Hide()"

$ExitMenu = $FileMenu.MenuItems.Add("Exit")
$ExitMenu.OnClick = "ExitMenu_Click()"

$NotifyIcon = $System.NotifyIcon()
$NotifyIcon.Icon = $Form.Icon
$NotifyIcon.Text = $Form.Text
$NotifyIcon.Visible = "True"
$NotifyIcon.OnDoubleClick = "NotifyIcon_DoubleClick()"
$NotifyIcon.OnMouseDown = "NotifyIcon_MouseDown()"

$RightContextMenu = $System.ContextMenu()

$RightContextMenu.Open = $RightContextMenu.MenuItems.Add("Open")
$RightContextMenu.Open.Onclick = "NotifyIcon_DoubleClick()"

$RightContextMenu.Exit = $RightContextMenu.MenuItems.Add("Exit")
$RightContextMenu.Exit.Onclick = "ExitMenu_Click()"

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

Exit 1

Function NotifyIcon_MouseDown()
   If $NotifyIcon.mousebutton = 2
      $RightContextMenu.Show($NotifyIcon.MouseX,$NotifyIcon.MouseY)
   EndIf
EndFunction

Function NotifyIcon_DoubleClick()
   If Not $Form.Visible Or $Form.WindowState = 1
      $Form.WindowState = 0
      $Form.Show()
      $Form.Activate()
   EndIf
EndFunction

Function Form_Hide()
   If $Form.WindowState = 0
      $Form.Hide()
   EndIf
Endfunction

Function Form_Resize()
   If $Form.WindowState = 1
      $Form.Hide()
   EndIf
EndFunction

Function ExitMenu_Click()
   $Form.Running = 0
EndFunction

here is an example of how to use the notify icon with KiXforms.Net;
Code:

Break On

Dim $SO
$SO=SetOption("NoMacrosInStrings", "ON")
$SO=SetOption("NoVarsInStrings", "ON")
$SO=SetOption("Explicit", "ON")

Global $System,$Form,$ContextMenu,$OpenMenu,$ExitMenu,$NotifyIcon,$FormRunning
Dim $Icon,$nul

;Create 'Kixforms.System' Object.
$System = CreateObject("Kixforms.System")

;Verify the 'Kixforms.System' Object was created if not, notify and exit.
If Not $System
   $nul= MessageBox("KiXforms.Net Not Initiated."+@CRLF+
   "Please verify KiXforms.Net is installed."+@CRLF+
   "This Script Will Now Close.","Error",16)
   Quit()
EndIf

$Form = $System.Form()
$Form.Closing = "ClosingForm()"
$Form.FormBorderStyle = $System.FormBorderStyle_FixedToolWindow
$Form.ShowInTaskbar = 0 ;False
$Form.StartPosition = $System.FormStartPosition_CenterScreen
$Form.Size = $System.Size(400,300) ;(Width,Height)
$Form.Text = "Notify Icon Example..."

$ContextMenu = $System.ContextMenu()
$OpenMenu = $ContextMenu.MenuItems.Add($System.MenuItem("Open"))
$OpenMenu.Click = "OpenMenu_Click()"
$OpenMenu.Enabled = 0
$ExitMenu = $ContextMenu.MenuItems.Add($System.MenuItem("Exit"))
$ExitMenu.Click = "Exit_Form()"

$NotifyIcon = $System.NotifyIcon()
$NotifyIcon.ContextMenu = $ContextMenu
$NotifyIcon.DoubleClick = "OpenMenu_Click()"
$NotifyIcon.Icon = $System.Icon.FromBitmap(Icon())
;$NotifyIcon.Icon = $System.Icon.FromFile("K:\Kix Scripts\Shell32 Icons\160.ico")
$NotifyIcon.Visible = -1 ;True
$nul = $Form.Controls.Add($NotifyIcon)

$Form.Show  ;Displays the Form

$FormRunning = 1
While $FormRunning = 1
   $Nul = Execute($Form.DoEvents())
Loop
Exit 0

Function Exit_Form()
   $NotifyIcon.Visible = 0 ;False
   ;$FormRunning = 0
   Quit()
EndFunction

Function ClosingForm()
   $Form.ClosingEventArgs.Cancel = -1 ;True
   OpenMenu_Click()
EndFunction

Function OpenMenu_Click()
   If $OpenMenu.Enabled = 0 ;False
      $Form.Hide
      $OpenMenu.Enabled = -1 ;True
   Else
      $Form.Show
      $OpenMenu.Enabled = 0 ;False
   EndIf
EndFunction

Function Icon()
$Icon = "
Qk02EAAAAAAAADYAAAAoAAAAIAAAACAAAAABACAAAAAAAAAAAADEDgAAxA4AAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD/AAAA/wAAAP8AAAD/AAAA/wAAAP8AAAD/AAAA/wAA
AP8AAAD/AAAA/wAAAP8AAAD/AAAA/wAAAP8AAAD/AAAA/wAAAP8AAAD/AAAA/wAAAP8AAAD/
AAAA/wAAAP8AAAD/AAAA/wAAAP8AAAD/AAAA/wAAAP8AAAD/AAAA/4CAgP+AgID/gICA/4CA
gP+AgID/gICA/4CAgP+AgID/gICA/4CAgP+AgID/gICA/4CAgP+AgID/gICA/4CAgP+AgID/
gICA/4CAgP+AgID/gICA/4CAgP+AgID/gICA/4CAgP+AgID/gICA/4CAgP+AgID/gICA/4CA
gP8AAAD/gICA/8DAwP/AwMD/wMDA/8DAwP/AwMD/wMDA/8DAwP/AwMD/wMDA/8DAwP/AwMD/
wMDA/8DAwP/AwMD/wMDA/8DAwP/AwMD/wMDA/8DAwP/AwMD/wMDA/8DAwP/AwMD/wMDA/8DA
wP/AwMD/wMDA/8DAwP/AwMD/gICA/wAAAP+AgID/wMDA/4CAgP//////////////////////
////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////8DAwP+AgID/AAAA/4CAgP/AwMD/
gICA////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
wMDA/4CAgP8AAAD/gICA/8DAwP+AgID/////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
///////////////////////////AwMD/gICA/wAAAP+AgID/wMDA/4CAgP//////////////
////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////8DAwP+AgID/AAAA/4CA
gP/AwMD/gICA////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
////////wMDA/4CAgP8AAAD/gICA/8DAwP+AgID/////////////////////////////////
////////////////////////////////////////////////////////////////////////
///////////////////////////////////AwMD/gICA/wAAAP+AgID/wMDA/4CAgP//////
////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////8DAwP+AgID/
AAAA/4CAgP/AwMD/gICA////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
////////////////wMDA/4CAgP8AAAD/gICA/8DAwP+AgID/////////////////////////
////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////AwMD/gICA/wAAAP+AgID/wMDA/4CA
gP//////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////8DA
wP+AgID/AAAA/4CAgP/AwMD/gICA////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
////////////////////////wMDA/4CAgP8AAAD/gICA/8DAwP+AgID/////////////////
////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////AwMD/gICA/wAAAP+AgID/
wMDA/4CAgP//////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
/////8DAwP+AgID/AAAA/4CAgP/AwMD/gICA////////////////////////////////////
////////////////////////////////////////////////////////////////////////
////////////////////////////////wMDA/4CAgP8AAAD/gICA/8DAwP+AgID/////////
////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////AwMD/gICA/wAA
AP+AgID/wMDA/4CAgP//////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
/////////////8DAwP+AgID/AAAA/4CAgP/AwMD/gICA////////////////////////////
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////wMDA/4CAgP8AAAD/gICA/8DAwP+AgID/
////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////AwMD/
gICA/wAAAP+AgID/wMDA/4CAgP+AgID/gICA/4CAgP+AgID/gICA/4CAgP+AgID/gICA/4CA
gP+AgID/gICA/4CAgP+AgID/gICA/4CAgP+AgID/gICA/4CAgP+AgID/gICA/4CAgP+AgID/
gICA/4CAgP+AgID/gICA/8DAwP+AgID/AAAA/4CAgP/AwMD/wMDA/8DAwP/AwMD/wMDA/8DA
wP/AwMD/wMDA/8DAwP/AwMD/wMDA/8DAwP/AwMD/wMDA/8DAwP/AwMD/wMDA/8DAwP/AwMD/
wMDA/8DAwP/AwMD/wMDA/8DAwP/AwMD/wMDA/8DAwP/AwMD/wMDA/4CAgP8AAAD/gICA/8DA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AAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=="
$Icon = $System.Bitmap.FromBase64String($Icon)
EndFunction

_________________
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
Display posts from previous:   
Post new topic   Reply to topic    KiXforms Forum Index -> Starters Code Clinic 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