Solved

Hot spots  to trigger a program

Posted on 2000-03-09
5
181 Views
Last Modified: 2010-05-02
How in vb6 do i create hot spots on the screen that can trigger my app?  What I mean is this say My app is running in the system tray and nothing is on the screen  if I move my mouse to one of the corners of the screen I want to activate my app and maximize it.  Ive seen this done with screensaves and a toolbar once.
0
Comment
Question by:ocsscott
  • 2
  • 2
5 Comments
 
LVL 32

Accepted Solution

by:
Erick37 earned 100 total points
Comment Utility
Try this:

Option Explicit
Const ZONE = 2 '2 pixel zone
Private Type POINTAPI
    x As Long
    y As Long
End Type
Private Declare Function GetCursorPos Lib "user32" _
    (lpPoint As POINTAPI) As Long
   
Private sx As Long, sy As Long
Dim pt As POINTAPI

Private Sub Command1_Click()
    Hide
    Timer1.Enabled = True
End Sub

Private Sub Form_Load()
    Timer1.Interval = 2000 '2 secs.
    Timer1.Enabled = False
    Command1.Caption = "Hide Me"
    'Get the screen size
    sx = Screen.Width / Screen.TwipsPerPixelX
    sy = Screen.Height / Screen.TwipsPerPixelY
End Sub

Private Sub Timer1_Timer()
    Call GetCursorPos(pt)
   
    'Test for lower right corner
    'If (pt.x > sx - ZONE) And (pt.y > sy - ZONE) Then
   
    'Test for upper left corner
    If (pt.x < ZONE) And (pt.y < ZONE) Then
        Show
        Timer1.Enabled = False
    End If
End Sub
0
 
LVL 12

Expert Comment

by:roverm
Comment Utility
Erick37 is correct, but to hide your app in the system tray you have to use the Shell_NotifyIcon API:

Public Declare Function Shell_NotifyIcon Lib "shell32.dll" Alias " Shell_NotifyIconA" (ByVal dwMessage As Long, lpData As NOTIFYICONDATA) As Long

D'Mzzl!
RoverM
0
 

Author Comment

by:ocsscott
Comment Utility
ok a question or 2 about this method.

1) since it uses a times and checks every 2 seconds or so does this use a lots of cpu?  My app is for a menu system and will be hidden in the system tray most of the time.

2) since my app will be minimized to the system tray do i need to do anything to keep it active or is a program in the system tray always active and recieving events and timer events?  thanks for the code I'll put it in and test it today and let you know.  thanks
0
 
LVL 32

Expert Comment

by:Erick37
Comment Utility
1) The CPU overhead is minimal, as the code only executes at the Timer event.  There would be a significant performance hit if you used a mouse hook scheme, and this would be hard to implement in VB.

2)  Yes, the code will still run as long as the form with the timer is loaded in memory.  The system tray icon will be used only to hide or show the application.
0
 

Author Comment

by:ocsscott
Comment Utility
Great thanks for the help and info.

Scott
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Mysql vs Oracle 10 118
Excel Formula to Pull Data from Text String 7 67
MsgBox 2 36
using web browser with BING 40 82
Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now