|
-
Jul 29th, 2000, 08:19 AM
#1
Thread Starter
New Member
I've got a problem with creating a program that I need.
The program is supposed to be able to detect whenever I push the 0-9 buttons on the numlockpad and if numlock is activated it will do nothing about it, else it'll start a program (shortcuts to my favourite programs).
But the problem is that I'm having trouble getting the program to notice them from another program, anyone who can help me with this ??
I'm also wondering if anyone knows how to get the program to run at the start an then go down to the system bar (unsure if that's what it's called but I'm meaning that it'll go down to the right corner together with all the other icons). Would be grateful if anyone could help me with this since I've not done that much programming and none in this perticular area.
-
Jul 29th, 2000, 09:00 AM
#2
To recognize keypresses system wide, use something like the GetAsyncKeyState() API, i.e.
In a Form with a Timer Control:
Code:
Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
Private Sub Form_Load()
Timer1.Interval = 10
End Sub
Private Sub Timer1_Timer()
Dim lKey As Long
Dim bLaunched As Boolean
'Check if keys are pressed...
For lKey = 0 To 9
If GetAsyncKeyState(vbKeyNumpad0 + lKey) Then
'Launch application here...
Caption = lKey
bLaunched = True
'Wait for Key to be released...
While GetAsyncKeyState(vbKeyNumpad0 + lKey)
DoEvents
Wend
End If
Next
If Not bLaunched And Caption <> "Waiting..." Then
'Action (if any) if none of the keys are pressed...
Caption = "Waiting..."
End If
End Sub
To put an Icon in the System Tray use something like:
In a Module...
Code:
Private Type NOTIFYICONDATA
cbSize As Long
hwnd As Long
uID As Long
uFlags As Long
uCallbackMessage As Long
hIcon As Long
szTip As String * 64
End Type
Private Declare Function Shell_NotifyIcon Lib "shell32.dll" Alias "Shell_NotifyIconA" (ByVal dwMessage As Long, lpData As NOTIFYICONDATA) As Long
Private Const NIF_ICON = &H2
Private Const NIF_MESSAGE = &H1
Private Const NIF_TIP = &H4
Private Const NIM_ADD = &H0
Private Const NIM_DELETE = &H2
Private Const NIM_MODIFY = &H1
Private Const WM_MOUSEMOVE = &H200
Public Const WM_LBUTTONDBLCLK = &H203
Public Const WM_LBUTTONDOWN = &H201
Public Const WM_RBUTTONDOWN = &H204
Private tTrayIcon As NOTIFYICONDATA
Public Sub DisplayTrayIcon(ByVal TargetHwnd As Long, ByVal Caption As String, TrayIcon As Variant)
'Add a System Tray Icon
With tTrayIcon
.hIcon = TrayIcon
.hwnd = TargetHwnd
.szTip = Caption & Chr(0)
.uID = 1
.uCallbackMessage = WM_MOUSEMOVE
.uFlags = NIF_ICON Or NIF_MESSAGE Or NIF_TIP
.cbSize = Len(tTrayIcon)
End With
Shell_NotifyIcon NIM_ADD, tTrayIcon
End Sub
Public Sub RemoveTrayIcon()
'Remove the System Tray Icon
Shell_NotifyIcon NIM_DELETE, tTrayIcon
End Sub
Public Sub ChangeTrayIcon(TrayIcon As Variant)
'Change the System Tray Icon Image
tTrayIcon.hIcon = TrayIcon
tTrayIcon.cbSize = Len(tTrayIcon)
Shell_NotifyIcon NIM_MODIFY, tTrayIcon
End Sub
Public Sub ChangeTrayTip(ByVal Caption As String)
'Change the System Tray Icon's Caption/ToolTip
tTrayIcon.szTip = Caption & Chr(0)
tTrayIcon.cbSize = Len(tTrayIcon)
Shell_NotifyIcon NIM_MODIFY, tTrayIcon
End Sub
In a Form with a Picturebox...
Create a Menu called mnuPopup and mark it Invisible.
Create a SubItem mnuExit...
Code:
Private Sub Form_Load()
Picture1.Visible = False
DisplayTrayIcon Picture1.hwnd, "You Application Name", Icon
End Sub
Private Sub Form_Resize()
'Don't show the Form when Minimized
DoEvents
If WindowState = vbMinimized Then Hide
End Sub
Private Sub Form_Unload(Cancel As Integer)
RemoveTrayIcon
End Sub
Private Sub mnuExit_Click()
Unload Me
End Sub
Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
'Recieves a Message when the Mouse moves over the Tray Icon
Select Case ScaleX(X, vbTwips, vbPixels)
Case WM_RBUTTONDOWN
PopupMenu mnuPopup
Case WM_LBUTTONDBLCLK
WindowState = vbNormal
Show
End Select
End Sub
-
Jul 29th, 2000, 09:02 AM
#3
New Member
Try this
Im not an expert, as i am also learning but try looking at these.
First of all, the only way to make your program recognise when you press these buttons even if the user is currently in another program is to use something called sub-classing. This means that you can press these numbers and ANY time while using windows and your program could pick up on it. Then again, the problem with using just the numbers would mean if you wanted to type a number into something, your program would think you wanted to start 1 of your programs and all hell would break loose anyway, to learn a bit about sub-classing, look here.
http://www.vb-world.net/mouse/hotkey/
The above program should help explain.
To put your program in the system tray, look here...
http://www.vbsquare.com/tips/tip178.html
hope these help.
If practice makes perfect...
and nobody's perfect...
why the hell practice?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|