Solved

Hot spots  to trigger a program

Posted on 2000-03-09
5
183 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
ID: 2603208
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
ID: 2603571
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
ID: 2605038
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
ID: 2605226
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
ID: 2605233
Great thanks for the help and info.

Scott
0

Featured Post

Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

809 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