Solved

Hot spots  to trigger a program

Posted on 2000-03-09
5
188 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

[Webinar] Learn How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

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…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

717 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