Date: 02-16-2022
Return to Index
created by gbSnippets
'Credit: Don Schullian http://www.powerbasic.com/support/pbforums/showthread.php?t=24709
'Compilable Example: (Jose Includes)
#Compiler PBWin 9, PBWin 10
#Compile EXE
#Dim All
%Unicode=1
#Include "win32api.inc"
%WM_Tray = %WM_User + 1
%Tray_Quit = %WM_User + 40
Global hDlg, hTrayMenu, g_hinst As Dword
Function PBMain() As Long
Local xEvents As Long
Menu New PopUp To htraymenu
Menu Add String, htraymenu, "quit", %tray_quit, %MF_Enabled
Dialog New Pixels, %HWND_Desktop, "", 0, 0, 0, 0, 0, %WS_Ex_Topmost Or %WS_Ex_ToolWindow To hdlg
Dialog Show Modeless hdlg Call DlgProc ' start the tray program
Dialog Show State hdlg, %SW_Hide ' hide it
Do : Dialog DoEvents To xevents : Loop Until xevents = 0 'message pump until quit was clicked
End Function
CallBack Function DlgProc () As Long
Static tn As notifyicondata, shown As Long
Local pt As PointAPI
Select Case CbMsg
Case %WM_InitDialog
tn.cbsize = SizeOf(tn)
tn.hwnd = hDlg
tn.uid = GetModuleHandle(ByVal %NULL) 'g_hinst
tn.uflags = %nif_icon Or %nif_message Or %nif_tip
tn.ucallbackmessage = %WM_Tray
tn.hicon = loadicon(%null,ByVal Mak(Long, %idi_application,0))
tn.sztip = "gbClipOpen"
Shell_NotifyIcon %nim_add, tn
Case %WM_Destroy
Shell_NotifyIcon %nim_delete, tn
Case %WM_Tray
Select Case Cb.LParam
Case %WM_RButtonDown
GetCursorPos pt
TrackPopupMenu hTrayMenu, %TPM_BottomAlign Or %TPM_RightAlign, pt.x, pt.y, 0, hDlg, ByVal %null
PostMessage hDlg, %WM_Null, 0, 0
Case %WM_LButtonDblClk
RunMainCode
End Select
Case %WM_Command
Select Case Cb.Ctl
Case %Tray_Quit 'context menu item from tray icon
Dialog End hDlg
End Select
End Select
End Function
Sub RunMainCode
Local ClipBoardText$, iReturn&, tempFileName As AsciiZ * %Max_Path
Clipboard Get Text To ClipBoardText$
tempFileName = EXE.Path$ + "gbclipopenrun_temp.bas"
Open tempFileName For Output As #1
Print #1, ClipBoardText$
Close #1
iReturn& = ShellExecute(hDlg, "Open", tempFileName, $Nul, $Nul, %SW_ShowNormal)
' ProcessID& = Shell("c:\pbwin90\bin\pbedit.exe " + $Dq + tempFileName$ + $Dq, 1)
End Sub
'gbs_00697
'Date: 03-10-2012
http://www.garybeene.com/sw/gbsnippets.htm