Раздел посвящен программированию с использованием Power Basic.
-
jangle
-
- Википедик
-
-
- Сообщения: 3013
- Зарегистрирован: 03.06.2005 (Пт) 12:02
- Откуда: Нидерланды
jangle » 30.01.2007 (Вт) 22:14
- Код: Выделить всё
#Compile Exe
#Include "WIN32API.INC"
%WM_TRAYICON = %WM_USER + 400 'user-defined message for tray response
%IDT_SHOW = %WM_USER + 402 'tray menu command
%IDT_EXIT = %WM_USER + 408 'tray menu command
%IDC_LABEL = %WM_USER + 420 'label control id
%IDC_OPT1 = %WM_USER + 431 'option control id
%IDC_OPT2 = %WM_USER + 432 'option control id
Declare CallBack Function DlgProc() As Long
'¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
' Create dialog and controls, etc
'¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
Function PBMain () As Long
Local hDlg As Long
Dialog New 0, "Tray sample",,, 120, 50, _
%WS_CAPTION Or %WS_MINIMIZEBOX Or %WS_SYSMENU, 0 To hDlg
Control Add Label, hDlg, %IDC_LABEL, "Minimize to see result..", 5, 30, 40, 20
Control Add Option, hDlg, %IDC_OPT1, "Minimize to tray ", 5, 5, 80, 10, %WS_GROUP Or %WS_TABSTOP
Control Add Option, hDlg, %IDC_OPT2, "Minimize to taskbar ", 5, 15, 80, 10
Control Set Option hDlg, %IDC_OPT1, %IDC_OPT1, %IDC_OPT2
Control Add Button, hDlg, %IDCANCEL, "&Quit", 65, 32, 50, 14
Dialog Show Modal hDlg Call DlgProc
End Function
'¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
' Main callback
'¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
CallBack Function DlgProc() As Long
Select Case CbMsg
Case %WM_INITDIALOG
Local lRes As Long, hPopup As Long, pt As POINTAPI
Static ti As NOTIFYICONDATA
Case %WM_COMMAND
Select Case CbCtl
Case %IDT_SHOW 'From tray menu - Show program was selected
Shell_NotifyIcon %NIM_DELETE, ti 'remove tray icon
ShowWindow CbHndl, %SW_SHOW 'show prog
Case %IDT_EXIT 'From tray menu - Exit program was selected
Shell_NotifyIcon %NIM_DELETE, ti 'remove tray icon
Dialog End CbHndl 'end prog
Case %IDCANCEL
If CbCtlMsg = %BN_CLICKED Then Dialog End CbHndl
End Select
Case %WM_TRAYICON
Select Case LoWrd(CbLParam)
Case %WM_LBUTTONDOWN 'left-click on tray icon
If IsWindowVisible(CbHndl) = %FALSE Then
Shell_NotifyIcon %NIM_DELETE, ti 'remove tray icon
ShowWindow CbHndl, %SW_SHOW 'show prog
End If
Case %WM_RBUTTONDOWN 'right-click on tray icon
If IsWindowVisible(CbHndl) = %FALSE Then
SetForegroundWindow CbHndl 'Set window to foreground and activate
GetCursorPos pt 'Get cursor pos on screen
Menu New PopUp To hPopup 'create and show popup menu
Menu Add String, hPopup, "Show Tray sample", %IDT_SHOW, %MF_ENABLED
Menu Add String, hPopup, "-", 0, 0
Menu Add String, hPopup, "E&xit Tray sample", %IDT_EXIT, %MF_ENABLED
TrackPopupMenu hPopup, %TPM_LEFTALIGN Or %TPM_RIGHTBUTTON, _
pt.x, pt.y, 0, CbHndl, ByVal 0
Postmessage CbHndl, %WM_NULL, 0, 0
DestroyMenu hPopup
End If
End Select
Case %WM_DESTROY
Case %WM_SYSCOMMAND ' see if minimize button was pressed,
If (LoWrd(CbWParam) And %SC_MINIMIZE) = %SC_MINIMIZE Then
Control Get Check CbHndl, %IDC_OPT1 To lRes
If lRes Then 'if minimize to tray is selected
'fill structure and add tray icon
ti.cbSize = SizeOf(ti)
ti.hWnd = CbHndl
ti.uID = GetModuleHandle("")
ti.uFlags = %NIF_ICON Or %NIF_MESSAGE Or %NIF_TIP
ti.uCallbackMessage = %WM_TRAYICON
ti.hIcon = LoadIcon(0, ByVal %IDI_WINLOGO)
ti.szTip = "Tray sample"
Shell_NotifyIcon %NIM_ADD, ti
DestroyIcon ti.hIcon
ShowWindow CbHndl, %SW_HIDE 'hide prog so it doesn't appear in the task bar.
Function = 1 : Exit Function
End If
End If
End Select
End Function
Вернуться в Power Basic
Кто сейчас на конференции
Сейчас этот форум просматривают: нет зарегистрированных пользователей и гости: 46